libsmb: Pass "struct timespec" to SMBC_setatr()
authorVolker Lendecke <vl@samba.org>
Thu, 26 Mar 2020 11:29:13 +0000 (12:29 +0100)
committerRalph Boehme <slow@samba.org>
Wed, 8 Apr 2020 14:46:40 +0000 (14:46 +0000)
Prepare to set higher-precision timestamps. No change in behaviour so
far: The {.tv_nsec=SAMBA_UTIME_OMIT} implicitly sets .tv_sec=0, and
SMBC_setatr() only looks at .tv_sec

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/include/libsmb_internal.h
source3/libsmb/libsmb_dir.c
source3/libsmb/libsmb_file.c
source3/libsmb/libsmb_xattr.c

index d23b33c43b9b5eda5337c39e8e9fcc3787868ce9..be88e8e300d3dee9eb18417528f975495f851d05 100644 (file)
@@ -411,10 +411,10 @@ SMBC_getatr(SMBCCTX * context,
 
 bool
 SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
-            time_t create_time,
-            time_t access_time,
-            time_t write_time,
-            time_t change_time,
+            struct timespec create_time,
+            struct timespec access_time,
+            struct timespec write_time,
+            struct timespec change_time,
             uint16_t mode);
 
 off_t
index 00d2a878e8464e37048c25564103a3c815fe8a5b..fe236f41f0cc62e792d53094c035c4ee6c45b7dd 100644 (file)
@@ -2051,6 +2051,7 @@ SMBC_utimes_ctx(SMBCCTX *context,
         time_t write_time;
        uint16_t port = 0;
        TALLOC_CTX *frame = talloc_stackframe();
+       bool ok;
 
        if (!context || !context->internal->initialized) {
 
@@ -2126,8 +2127,16 @@ SMBC_utimes_ctx(SMBCCTX *context,
                return -1;      /* errno set by SMBC_server */
        }
 
-        if (!SMBC_setatr(context, srv, path,
-                         0, access_time, write_time, 0, 0)) {
+       ok = SMBC_setatr(
+               context,
+               srv,
+               path,
+               (struct timespec) { .tv_nsec = SAMBA_UTIME_OMIT },
+               (struct timespec) { .tv_sec = access_time },
+               (struct timespec) { .tv_sec = write_time },
+               (struct timespec) { .tv_nsec = SAMBA_UTIME_OMIT },
+               0);
+       if (!ok) {
                TALLOC_FREE(frame);
                 return -1;      /* errno set by SMBC_setatr */
         }
index f0a16c61a83a987c7b7bcaa9a419f874e50d4448..7e8916e61b53dfa620662f43300fc1078727bcfd 100644 (file)
@@ -588,10 +588,10 @@ all_failed:
  */
 bool
 SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
-            time_t create_time,
-            time_t access_time,
-            time_t write_time,
-            time_t change_time,
+            struct timespec create_time,
+            struct timespec access_time,
+            struct timespec write_time,
+            struct timespec change_time,
             uint16_t mode)
 {
         uint16_t fd;
@@ -606,10 +606,10 @@ SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
          */
         if (srv->no_pathinfo ||
             !NT_STATUS_IS_OK(cli_setpathinfo_basic(srv->cli, path,
-                                                  create_time,
-                                                  access_time,
-                                                  write_time,
-                                                  change_time,
+                                                  create_time.tv_sec,
+                                                  access_time.tv_sec,
+                                                  write_time.tv_sec,
+                                                  change_time.tv_sec,
                                                   mode))) {
 
                 /*
@@ -634,9 +634,9 @@ SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
 
                 /* Set the new attributes */
                 ret = NT_STATUS_IS_OK(cli_setattrE(srv->cli, fd,
-                                   change_time,
-                                   access_time,
-                                   write_time));
+                                   change_time.tv_sec,
+                                   access_time.tv_sec,
+                                   write_time.tv_sec));
 
                 /* Close the file */
                 cli_close(srv->cli, fd);
index 9e3f542b9241320146c4876265aca8dac6726081..059233b4f091c9d7c917d83bf91fb457a30a3bb6 100644 (file)
@@ -1796,17 +1796,26 @@ SMBC_setxattr_ctx(SMBCCTX *context,
                 /* get a DOS Attribute Descriptor with current attributes */
                 dad = dos_attr_query(context, talloc_tos(), path, srv);
                 if (dad) {
+                       bool ok;
+
                         /* Overwrite old with new, using what was provided */
                         dos_attr_parse(context, dad, srv, namevalue);
 
                         /* Set the new DOS attributes */
-                        if (! SMBC_setatr(context, srv, path,
-                                          dad->create_time,
-                                          dad->access_time,
-                                          dad->write_time,
-                                          dad->change_time,
-                                          dad->mode)) {
-
+                       ok = SMBC_setatr(
+                               context,
+                               srv,
+                               path,
+                               (struct timespec) {
+                                       .tv_sec = dad->create_time },
+                               (struct timespec) {
+                                       .tv_sec = dad->access_time },
+                               (struct timespec) {
+                                       .tv_sec = dad->write_time },
+                               (struct timespec) {
+                                       .tv_sec = dad->change_time },
+                               dad->mode);
+                       if (!ok) {
                                 /* cause failure if NT failed too */
                                 dad = NULL; 
                         }
@@ -1951,12 +1960,19 @@ SMBC_setxattr_ctx(SMBCCTX *context,
                                 dos_attr_parse(context, dad, srv, namevalue);
 
                                 /* Set the new DOS attributes */
-                                ret2 = SMBC_setatr(context, srv, path,
-                                                   dad->create_time,
-                                                   dad->access_time,
-                                                   dad->write_time,
-                                                   dad->change_time,
-                                                   dad->mode);
+                               ret2 = SMBC_setatr(
+                                       context,
+                                       srv,
+                                       path,
+                                       (struct timespec) {
+                                               .tv_sec = dad->create_time },
+                                       (struct timespec) {
+                                               .tv_sec = dad->access_time },
+                                       (struct timespec) {
+                                               .tv_sec = dad->write_time },
+                                       (struct timespec) {
+                                               .tv_sec = dad->change_time },
+                                       dad->mode);
 
                                 /* ret2 has True (success) / False (failure) */
                                 if (ret2) {