diff options
author | Richard Sharpe <realrichardsharpe@gmail.com> | 2017-10-16 13:51:51 -0700 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2017-10-19 00:55:24 +0200 |
commit | 0030ce900afcb6a4297c4a4dcf95bce51930d235 (patch) | |
tree | 76d990d7e2f9db7d333800ead490ece85deb05b4 /source3/client | |
parent | 962a1b32201fce0a49c6be55943d4fbb57ed781e (diff) | |
download | samba-0030ce900afcb6a4297c4a4dcf95bce51930d235.tar.gz |
s3:Add a utimes command to smbclient so we can set the Windows times.
Add an update to the smbclient man page.
Signed-off-by: Richard Sharpe <realrichardsharpe@gmail.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3/client')
-rw-r--r-- | source3/client/client.c | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/source3/client/client.c b/source3/client/client.c index 5ef9ad52151..df16496ff86 100644 --- a/source3/client/client.c +++ b/source3/client/client.c @@ -4941,6 +4941,126 @@ static int cmd_show_connect( void ) } /** + * set_remote_times - set times of a remote file + * @filename: path to the file name + * @create_time: New create time + * @access_time: New access time + * @write_time: New write time + * @change_time: New metadata change time + * + * 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) +{ + extern struct cli_state *cli; + NTSTATUS status; + + status = cli_setpathinfo_basic(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)); + return 1; + } + + return 0; +} + +/** + * cmd_utimes - interactive command to set the four times + * + * Read a filename and four times from the client command line and update + * the file times. A value of -1 for a time means don't change. + */ +static int cmd_utimes(void) +{ + const extern char *cmd_ptr; + char *buf; + char *fname = NULL; + time_t times[4] = {0, 0, 0, 0}; + int time_count = 0; + int err = 0; + bool ok; + TALLOC_CTX *ctx = talloc_new(NULL); + if (ctx == NULL) { + return 1; + } + + ok = next_token_talloc(ctx, &cmd_ptr, &buf, NULL); + if (!ok) { + d_printf("utimes <filename> <create-time> <access-time> " + "<write-time> <change-time>\n"); + d_printf("Dates should be in YY:MM:DD-HH:MM:SS format " + "or -1 for no change\n"); + err = 1; + goto out; + } + + fname = talloc_asprintf(ctx, + "%s%s", + client_get_cur_dir(), + buf); + if (fname == NULL) { + err = 1; + goto out; + } + + while (next_token_talloc(ctx, &cmd_ptr, &buf, NULL) && + time_count < 4) { + const char *s = buf; + struct tm tm = {0,}; + char *ret; + + if (strlen(s) == 2 && strcmp(s, "-1") == 0) { + times[time_count] = 0; + time_count++; + continue; + } else { + ret = strptime(s, "%y:%m:%d-%H:%M:%S", &tm); + } + + /* We could not match all the chars, so print error */ + if (ret == NULL || *ret != 0) { + d_printf("Invalid date format: %s\n", s); + d_printf("utimes <filename> <create-time> " + "<access-time> <write-time> <change-time>\n"); + d_printf("Dates should be in YY:MM:DD-HH:MM:SS format " + "or -1 for no change\n"); + err = 1; + goto out; + } + + /* Convert tm to a time_t */ + times[time_count] = mktime(&tm); + time_count++; + } + + if (time_count < 4) { + d_printf("Insufficient dates: %d\n", time_count); + d_printf("utimes <filename> <create-time> <access-time> " + "<write-time> <change-time>\n"); + d_printf("Dates should be in YY:MM:DD-HH:MM:SS format " + "or -1 for no change\n"); + err = 1; + goto out; + } + + DEBUG(10, ("times\nCreate: %sAccess: %s Write: %sChange: %s\n", + talloc_strdup(ctx, ctime(×[0])), + talloc_strdup(ctx, ctime(×[1])), + talloc_strdup(ctx, ctime(×[2])), + talloc_strdup(ctx, ctime(×[3])))); + + set_remote_times(fname, times[0], times[1], times[2], times[3]); +out: + talloc_free(ctx); + return err; +} + +/** * set_remote_attr - set DOS attributes of a remote file * @filename: path to the file name * @new_attr: attribute bit mask to use @@ -5254,6 +5374,8 @@ static struct { {"tcon",cmd_tcon,"connect to a share" ,{COMPL_NONE,COMPL_NONE}}, {"tdis",cmd_tdis,"disconnect from a share",{COMPL_NONE,COMPL_NONE}}, {"tid",cmd_tid,"show or set the current tid (tree-id)",{COMPL_NONE,COMPL_NONE}}, + {"utimes", cmd_utimes,"<file name> <create_time> <access_time> <mod_time> " + "<ctime> set times", {COMPL_REMOTE,COMPL_NONE}}, {"logoff",cmd_logoff,"log off (close the session)",{COMPL_NONE,COMPL_NONE}}, {"..",cmd_cd_oneup,"change the remote directory (up one level)",{COMPL_REMOTE,COMPL_NONE}}, |