1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-10 21:49:28 +03:00

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 <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
This commit is contained in:
Volker Lendecke
2020-03-26 12:29:13 +01:00
committed by Ralph Boehme
parent b89ab75cd6
commit e4aa9a970a
4 changed files with 55 additions and 30 deletions

View 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

View 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 */
}

View 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);

View 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) {