]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbclient: use cli_setpathinfo_ext() in utimes command
authorRalph Boehme <slow@samba.org>
Sun, 1 Dec 2019 08:01:20 +0000 (09:01 +0100)
committerJeremy Allison <jra@samba.org>
Fri, 6 Dec 2019 00:17:36 +0000 (00:17 +0000)
This allows correct processing of sentinel date values.

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/client/client.c

index ccbfba0b53fc733dc57c41a6e42eea80fbecc47a..cca88bd7893e5c0b33ee182ff13b822cf0273b62 100644 (file)
@@ -39,6 +39,7 @@
 #include "libsmb/nmblib.h"
 #include "include/ntioctl.h"
 #include "../libcli/smb/smbXcli_base.h"
+#include "lib/util/time_basic.h"
 
 #ifndef REGISTER
 #define REGISTER 0
@@ -5189,16 +5190,22 @@ static int cmd_show_connect( void )
  *
  * Update the file times with the ones provided.
  */
-static int set_remote_times(const char *filename, time_t create_time,
-                       time_t access_time, time_t write_time,
-                       time_t change_time)
+static int set_remote_times(const char *filename,
+                           struct timespec *create_time,
+                           struct timespec *access_time,
+                           struct timespec *write_time,
+                           struct timespec *change_time)
 {
        extern struct cli_state *cli;
        NTSTATUS status;
 
-       status = cli_setpathinfo_basic(cli, filename, create_time,
-                                       access_time, write_time,
-                                       change_time, -1);
+       status = cli_setpathinfo_ext(cli,
+                               filename,
+                               create_time,
+                               access_time,
+                               write_time,
+                               change_time,
+                               -1);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("cli_setpathinfo_basic failed: %s\n",
                         nt_errstr(status));
@@ -5219,7 +5226,8 @@ static int cmd_utimes(void)
        const extern char *cmd_ptr;
        char *buf;
        char *fname = NULL;
-       time_t times[4] = {0, 0, 0, 0};
+       struct timespec times[4] = {{0}};
+       struct timeval_buf tbuf[4];
        int time_count = 0;
        int err = 0;
        bool ok;
@@ -5256,10 +5264,11 @@ static int cmd_utimes(void)
                time_count < 4) {
                const char *s = buf;
                struct tm tm = {0,};
+               time_t t;
                char *ret;
 
                if (strlen(s) == 2 && strcmp(s, "-1") == 0) {
-                       times[time_count] = 0;
+                       times[time_count] = make_omit_timespec();
                        time_count++;
                        continue;
                } else {
@@ -5278,7 +5287,8 @@ static int cmd_utimes(void)
                }
 
                /* Convert tm to a time_t */
-               times[time_count] = mktime(&tm);
+               t = mktime(&tm);
+               times[time_count] = (struct timespec){.tv_sec = t};
                time_count++;
        }
 
@@ -5293,12 +5303,12 @@ static int cmd_utimes(void)
        }
 
        DEBUG(10, ("times\nCreate: %sAccess: %s Write: %sChange: %s\n",
-               talloc_strdup(ctx, ctime(&times[0])),
-               talloc_strdup(ctx, ctime(&times[1])),
-               talloc_strdup(ctx, ctime(&times[2])),
-               talloc_strdup(ctx, ctime(&times[3]))));
+                  timespec_string_buf(&times[0], false, &tbuf[0]),
+                  timespec_string_buf(&times[1], false, &tbuf[1]),
+                  timespec_string_buf(&times[2], false, &tbuf[2]),
+                  timespec_string_buf(&times[3], false, &tbuf[3])));
 
-       set_remote_times(fname, times[0], times[1], times[2], times[3]);
+       set_remote_times(fname, &times[0], &times[1], &times[2], &times[3]);
 out:
        talloc_free(ctx);
        return err;