]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libsmb: add cli_setpathinfo_ext()
authorRalph Boehme <slow@samba.org>
Sun, 1 Dec 2019 08:01:13 +0000 (09:01 +0100)
committerJeremy Allison <jra@samba.org>
Fri, 6 Dec 2019 00:17:36 +0000 (00:17 +0000)
This takes a struct timespec instead of just time_t as cli_setpathinfo_basic()
does. This is needed to pass sentinel values -1 in the smbclient utime command.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=7771

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/libsmb/clirap.c
source3/libsmb/clirap.h

index 9fcda53573cac57dd7adeb5c719a52359863c8ce..3f361fb79ac46a733110fb6e254d283eca281508 100644 (file)
@@ -791,6 +791,70 @@ NTSTATUS cli_setpathinfo_basic(struct cli_state *cli, const char *fname,
                               (uint8_t *)data, data_len);
 }
 
+NTSTATUS cli_setpathinfo_ext(struct cli_state *cli, const char *fname,
+                            const struct timespec *create_time,
+                            const struct timespec *access_time,
+                            const struct timespec *write_time,
+                            const struct timespec *change_time,
+                            uint16_t mode)
+{
+       unsigned int data_len = 0;
+       char data[40];
+       char *p;
+
+       p = data;
+
+       /*
+        * Add the create, last access, modification, and status change times
+        */
+       put_long_date_full_timespec(TIMESTAMP_SET_NT_OR_BETTER, p, create_time);
+       p += 8;
+
+       put_long_date_full_timespec(TIMESTAMP_SET_NT_OR_BETTER, p, access_time);
+       p += 8;
+
+       put_long_date_full_timespec(TIMESTAMP_SET_NT_OR_BETTER, p, write_time);
+       p += 8;
+
+       put_long_date_full_timespec(TIMESTAMP_SET_NT_OR_BETTER, p, change_time);
+       p += 8;
+
+       if (mode == (uint16_t)-1 || mode == FILE_ATTRIBUTE_NORMAL) {
+               /* No change. */
+               mode = 0;
+       } else if (mode == 0) {
+               /* Clear all existing attributes. */
+               mode = FILE_ATTRIBUTE_NORMAL;
+       }
+
+       /* Add attributes */
+       SIVAL(p, 0, mode);
+
+       p += 4;
+
+       /* Add padding */
+       SIVAL(p, 0, 0);
+       p += 4;
+
+       data_len = PTR_DIFF(p, data);
+
+       if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
+               DATA_BLOB in_data = data_blob_const(data, data_len);
+               /*
+                * Split out SMB2 here as we need to select
+                * the correct info type and level.
+                */
+               return cli_smb2_setpathinfo(cli,
+                               fname,
+                               1, /* SMB2_SETINFO_FILE */
+                               SMB_FILE_BASIC_INFORMATION - 1000,
+                               &in_data);
+       }
+
+       return cli_setpathinfo(cli, SMB_FILE_BASIC_INFORMATION, fname,
+                              (uint8_t *)data, data_len);
+}
+
 /****************************************************************************
  Send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level.
 ****************************************************************************/
index 9140fb68f6a55484c8f719d7467a21287033f035..b259feffd70b7ce37f7e4a30ce8c2d8a8235e0e7 100644 (file)
@@ -64,6 +64,12 @@ NTSTATUS cli_setpathinfo_basic(struct cli_state *cli, const char *fname,
                               time_t write_time,
                               time_t change_time,
                               uint16_t mode);
+NTSTATUS cli_setpathinfo_ext(struct cli_state *cli, const char *fname,
+                            const struct timespec *create_time,
+                            const struct timespec *access_time,
+                            const struct timespec *write_time,
+                            const struct timespec *change_time,
+                            uint16_t mode);
 struct tevent_req *cli_qpathinfo2_send(TALLOC_CTX *mem_ctx,
                                       struct tevent_context *ev,
                                       struct cli_state *cli,