libsmb: Respect the full timeval for smbc_utimes()
authorVolker Lendecke <vl@samba.org>
Mon, 30 Mar 2020 19:43:51 +0000 (21:43 +0200)
committerRalph Boehme <slow@samba.org>
Wed, 8 Apr 2020 14:46:40 +0000 (14:46 +0000)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
selftest/knownfail.d/libsmbclient.utimes [deleted file]
source3/libsmb/libsmb_dir.c

diff --git a/selftest/knownfail.d/libsmbclient.utimes b/selftest/knownfail.d/libsmbclient.utimes
deleted file mode 100644 (file)
index 4b7db2e..0000000
+++ /dev/null
@@ -1 +0,0 @@
-samba4.libsmbclient.utimes.*
index fe236f41f0cc62e792d53094c035c4ee6c45b7dd..581dd6b9c1cb9663caedf847330ee82ed8ae6068 100644 (file)
@@ -34,6 +34,7 @@
 #include "../libcli/smb/smbXcli_base.h"
 #include "../libcli/security/security.h"
 #include "lib/util/tevent_ntstatus.h"
+#include "lib/util/time_basic.h"
 
 /*
  * Routine to open a directory
@@ -2047,8 +2048,7 @@ SMBC_utimes_ctx(SMBCCTX *context,
        char *password = NULL;
        char *workgroup = NULL;
        char *path = NULL;
-        time_t access_time;
-        time_t write_time;
+       struct timespec access_time, write_time;
        uint16_t port = 0;
        TALLOC_CTX *frame = talloc_stackframe();
        bool ok;
@@ -2067,31 +2067,19 @@ SMBC_utimes_ctx(SMBCCTX *context,
        }
 
         if (tbuf == NULL) {
-                access_time = write_time = time(NULL);
+                access_time = write_time = timespec_current();
         } else {
-                access_time = tbuf[0].tv_sec;
-                write_time = tbuf[1].tv_sec;
+               access_time = convert_timeval_to_timespec(tbuf[0]);
+                write_time = convert_timeval_to_timespec(tbuf[1]);
         }
 
         if (DEBUGLVL(4)) {
-                char *p;
-                char atimebuf[32];
-                char mtimebuf[32];
-
-                strncpy(atimebuf, ctime(&access_time), sizeof(atimebuf) - 1);
-                atimebuf[sizeof(atimebuf) - 1] = '\0';
-                if ((p = strchr(atimebuf, '\n')) != NULL) {
-                        *p = '\0';
-                }
-
-                strncpy(mtimebuf, ctime(&write_time), sizeof(mtimebuf) - 1);
-                mtimebuf[sizeof(mtimebuf) - 1] = '\0';
-                if ((p = strchr(mtimebuf, '\n')) != NULL) {
-                        *p = '\0';
-                }
+               struct timeval_buf abuf, wbuf;
 
                 dbgtext("smbc_utimes(%s, atime = %s mtime = %s)\n",
-                        fname, atimebuf, mtimebuf);
+                        fname,
+                       timespec_string_buf(&access_time, false, &abuf),
+                       timespec_string_buf(&write_time, false, &wbuf));
         }
 
        if (SMBC_parse_path(frame,
@@ -2132,8 +2120,8 @@ SMBC_utimes_ctx(SMBCCTX *context,
                srv,
                path,
                (struct timespec) { .tv_nsec = SAMBA_UTIME_OMIT },
-               (struct timespec) { .tv_sec = access_time },
-               (struct timespec) { .tv_sec = write_time },
+               access_time,
+               write_time,
                (struct timespec) { .tv_nsec = SAMBA_UTIME_OMIT },
                0);
        if (!ok) {