From be4f188128d631abe014a8182c22a03f4c09264a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 20 Sep 2011 06:06:26 +1000 Subject: 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 Autobuild-Date: Mon Sep 19 23:59:28 CEST 2011 on sn-devel-104 --- source4/client/client.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 4 deletions(-) (limited to 'source4/client') 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 \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 \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," put all matching files",{COMPL_REMOTE,COMPL_NONE}}, {"newer",cmd_newer," only mget files newer than the specified local file",{COMPL_LOCAL,COMPL_NONE}}, {"open",cmd_open," open a file",{COMPL_REMOTE,COMPL_NONE}}, + {"close",cmd_close," close a file",{COMPL_NONE,COMPL_NONE}}, {"privileges",cmd_privileges," show privileges for a user",{COMPL_NONE,COMPL_NONE}}, {"print",cmd_print," print a file",{COMPL_NONE,COMPL_NONE}}, {"printmode",cmd_printmode," set the print mode",{COMPL_NONE,COMPL_NONE}}, -- cgit