diff options
author | Andrew Tridgell <tridge@samba.org> | 2011-09-20 06:06:26 +1000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2011-09-19 23:59:28 +0200 |
commit | be4f188128d631abe014a8182c22a03f4c09264a (patch) | |
tree | d5e25fd9327e62017ad5a1ae2e77d00d5de08790 /source4 | |
parent | fcfde9ac86b75176ceeb02dbb3faa05cd53a2716 (diff) | |
download | samba-be4f188128d631abe014a8182c22a03f4c09264a.tar.gz samba-be4f188128d631abe014a8182c22a03f4c09264a.tar.bz2 samba-be4f188128d631abe014a8182c22a03f4c09264a.zip |
s4-client: added close command in smbclient
this matches the existing open command, and also gives you error codes
on both open and close
useful for testing share mode locking
Autobuild-User: Andrew Tridgell <tridge@samba.org>
Autobuild-Date: Mon Sep 19 23:59:28 CEST 2011 on sn-devel-104
Diffstat (limited to 'source4')
-rw-r--r-- | source4/client/client.c | 66 |
1 files changed, 62 insertions, 4 deletions
diff --git a/source4/client/client.c b/source4/client/client.c index 2f353aec4e..c30d17d3eb 100644 --- a/source4/client/client.c +++ b/source4/client/client.c @@ -2131,18 +2131,75 @@ static int cmd_delprivileges(struct smbclient_context *ctx, const char **args) /**************************************************************************** +open a file ****************************************************************************/ static int cmd_open(struct smbclient_context *ctx, const char **args) { - char *mask; - + char *filename; + union smb_open io; + NTSTATUS status; + TALLOC_CTX *tmp_ctx; + if (!args[1]) { d_printf("open <filename>\n"); return 1; } - mask = talloc_asprintf(ctx, "%s%s", ctx->remote_cur_dir, args[1]); + tmp_ctx = talloc_new(ctx); + + filename = talloc_asprintf(tmp_ctx, "%s%s", ctx->remote_cur_dir, args[1]); + + io.generic.level = RAW_OPEN_NTCREATEX; + io.ntcreatex.in.root_fid.fnum = 0; + io.ntcreatex.in.flags = 0; + io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL; + io.ntcreatex.in.create_options = 0; + io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; + io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ; + io.ntcreatex.in.alloc_size = 0; + io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF; + io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS; + io.ntcreatex.in.security_flags = 0; + io.ntcreatex.in.fname = filename; + + status = smb_raw_open(ctx->cli->tree, tmp_ctx, &io); + talloc_free(tmp_ctx); + + if (NT_STATUS_IS_OK(status)) { + d_printf("Opened file with fnum %u\n", (unsigned)io.ntcreatex.out.file.fnum); + } else { + d_printf("Opened failed: %s\n", nt_errstr(status)); + } + + return 0; +} - smbcli_open(ctx->cli->tree, mask, O_RDWR, DENY_ALL); +/**************************************************************************** +close a file +****************************************************************************/ +static int cmd_close(struct smbclient_context *ctx, const char **args) +{ + union smb_close io; + NTSTATUS status; + uint16_t fnum; + + if (!args[1]) { + d_printf("close <fnum>\n"); + return 1; + } + + fnum = atoi(args[1]); + + ZERO_STRUCT(io); + io.generic.level = RAW_CLOSE_CLOSE; + io.close.in.file.fnum = fnum; + + status = smb_raw_close(ctx->cli->tree, &io); + + if (NT_STATUS_IS_OK(status)) { + d_printf("Closed file OK\n"); + } else { + d_printf("Close failed: %s\n", nt_errstr(status)); + } return 0; } @@ -2694,6 +2751,7 @@ static struct {"mput",cmd_mput,"<mask> put all matching files",{COMPL_REMOTE,COMPL_NONE}}, {"newer",cmd_newer,"<file> only mget files newer than the specified local file",{COMPL_LOCAL,COMPL_NONE}}, {"open",cmd_open,"<mask> open a file",{COMPL_REMOTE,COMPL_NONE}}, + {"close",cmd_close,"<fnum> close a file",{COMPL_NONE,COMPL_NONE}}, {"privileges",cmd_privileges,"<user> show privileges for a user",{COMPL_NONE,COMPL_NONE}}, {"print",cmd_print,"<file name> print a file",{COMPL_NONE,COMPL_NONE}}, {"printmode",cmd_printmode,"<graphics or text> set the print mode",{COMPL_NONE,COMPL_NONE}}, |