diff options
author | Jeremy Allison <jra@samba.org> | 2017-07-21 12:41:11 -0700 |
---|---|---|
committer | Ralph Boehme <slow@samba.org> | 2017-07-25 17:43:15 +0200 |
commit | 2a15c70603bb23a68a2e3de0b00bfd98508f78e0 (patch) | |
tree | 6f09b8170187a7c94186975683f5954b251f97e6 | |
parent | 812006fa8f26004609901b0ddef1c3ed05eff35e (diff) | |
download | samba-2a15c70603bb23a68a2e3de0b00bfd98508f78e0.tar.gz |
s3: libsmb: Add cli_smb2_setpathinfo(), to be called by cli_setpathinfo_basic().
Fix to prevent libsmbclient from accidently making SMB1 calls inside an SMB2
connection.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12913
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
-rw-r--r-- | source3/libsmb/cli_smb2_fnum.c | 70 | ||||
-rw-r--r-- | source3/libsmb/cli_smb2_fnum.h | 5 | ||||
-rw-r--r-- | source3/libsmb/clirap.c | 14 |
3 files changed, 89 insertions, 0 deletions
diff --git a/source3/libsmb/cli_smb2_fnum.c b/source3/libsmb/cli_smb2_fnum.c index 6967555797a..32c7c21bd6d 100644 --- a/source3/libsmb/cli_smb2_fnum.c +++ b/source3/libsmb/cli_smb2_fnum.c @@ -1646,6 +1646,75 @@ NTSTATUS cli_smb2_qpathinfo_streams(struct cli_state *cli, } /*************************************************************** + Wrapper that allows SMB2 to set SMB_FILE_BASIC_INFORMATION on + a pathname. + Synchronous only. +***************************************************************/ + +NTSTATUS cli_smb2_setpathinfo(struct cli_state *cli, + const char *name, + uint8_t in_info_type, + uint8_t in_file_info_class, + const DATA_BLOB *p_in_data) +{ + NTSTATUS status; + uint16_t fnum = 0xffff; + struct smb2_hnd *ph = NULL; + TALLOC_CTX *frame = talloc_stackframe(); + + if (smbXcli_conn_has_async_calls(cli->conn)) { + /* + * Can't use sync call while an async call is in flight + */ + status = NT_STATUS_INVALID_PARAMETER; + goto fail; + } + + if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) { + status = NT_STATUS_INVALID_PARAMETER; + goto fail; + } + + status = get_fnum_from_path(cli, + name, + FILE_WRITE_ATTRIBUTES, + &fnum); + + if (!NT_STATUS_IS_OK(status)) { + goto fail; + } + + status = map_fnum_to_smb2_handle(cli, + fnum, + &ph); + if (!NT_STATUS_IS_OK(status)) { + goto fail; + } + + status = smb2cli_set_info(cli->conn, + cli->timeout, + cli->smb2.session, + cli->smb2.tcon, + in_info_type, + in_file_info_class, + p_in_data, /* in_input_buffer */ + 0, /* in_additional_info */ + ph->fid_persistent, + ph->fid_volatile); + fail: + + if (fnum != 0xffff) { + cli_smb2_close_fnum(cli, fnum); + } + + cli->raw_status = status; + + TALLOC_FREE(frame); + return status; +} + + +/*************************************************************** Wrapper that allows SMB2 to set pathname attributes. Synchronous only. ***************************************************************/ @@ -1752,6 +1821,7 @@ NTSTATUS cli_smb2_setatr(struct cli_state *cli, return status; } + /*************************************************************** Wrapper that allows SMB2 to set file handle times. Synchronous only. diff --git a/source3/libsmb/cli_smb2_fnum.h b/source3/libsmb/cli_smb2_fnum.h index 190ec59971b..8e240c6bc5b 100644 --- a/source3/libsmb/cli_smb2_fnum.h +++ b/source3/libsmb/cli_smb2_fnum.h @@ -114,6 +114,11 @@ NTSTATUS cli_smb2_qpathinfo_streams(struct cli_state *cli, TALLOC_CTX *mem_ctx, unsigned int *pnum_streams, struct stream_struct **pstreams); +NTSTATUS cli_smb2_setpathinfo(struct cli_state *cli, + const char *name, + uint8_t in_info_type, + uint8_t in_file_info_class, + const DATA_BLOB *p_in_data); NTSTATUS cli_smb2_setatr(struct cli_state *cli, const char *fname, uint16_t attr, diff --git a/source3/libsmb/clirap.c b/source3/libsmb/clirap.c index f897df63053..e80dfc92a77 100644 --- a/source3/libsmb/clirap.c +++ b/source3/libsmb/clirap.c @@ -29,6 +29,7 @@ #include "libsmb/clirap.h" #include "trans2.h" #include "../libcli/smb/smbXcli_base.h" +#include "cli_smb2_fnum.h" #define PIPE_LANMAN "\\PIPE\\LANMAN" @@ -751,6 +752,19 @@ NTSTATUS cli_setpathinfo_basic(struct cli_state *cli, const char *fname, data_len = PTR_DIFF(p, data); + if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) { + DATA_BLOB in_data = data_blob_const(data, data_len); + /* + * Split out SMB2 here as we need to select + * the correct info type and level. + */ + return cli_smb2_setpathinfo(cli, + fname, + 1, /* SMB2_SETINFO_FILE */ + SMB_FILE_BASIC_INFORMATION - 1000, + &in_data); + } + return cli_setpathinfo(cli, SMB_FILE_BASIC_INFORMATION, fname, (uint8_t *)data, data_len); } |