From: Volker Lendecke Date: Thu, 26 Mar 2020 11:29:13 +0000 (+0100) Subject: libsmb: Pass "struct timespec" to SMBC_setatr() X-Git-Tag: ldb-2.2.0~948 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e4aa9a970a483ea16aa5b5bc9f7bbf542a4eeecd;p=thirdparty%2Fsamba.git libsmb: Pass "struct timespec" to SMBC_setatr() 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 Reviewed-by: Ralph Boehme --- diff --git a/source3/include/libsmb_internal.h b/source3/include/libsmb_internal.h index d23b33c43b9..be88e8e300d 100644 --- a/source3/include/libsmb_internal.h +++ b/source3/include/libsmb_internal.h @@ -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 diff --git a/source3/libsmb/libsmb_dir.c b/source3/libsmb/libsmb_dir.c index 00d2a878e84..fe236f41f0c 100644 --- a/source3/libsmb/libsmb_dir.c +++ b/source3/libsmb/libsmb_dir.c @@ -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 */ } diff --git a/source3/libsmb/libsmb_file.c b/source3/libsmb/libsmb_file.c index f0a16c61a83..7e8916e61b5 100644 --- a/source3/libsmb/libsmb_file.c +++ b/source3/libsmb/libsmb_file.c @@ -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); diff --git a/source3/libsmb/libsmb_xattr.c b/source3/libsmb/libsmb_xattr.c index 9e3f542b924..059233b4f09 100644 --- a/source3/libsmb/libsmb_xattr.c +++ b/source3/libsmb/libsmb_xattr.c @@ -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) {