From 2a15c70603bb23a68a2e3de0b00bfd98508f78e0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 21 Jul 2017 12:41:11 -0700 Subject: 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 Reviewed-by: Ralph Boehme --- source3/libsmb/cli_smb2_fnum.c | 70 ++++++++++++++++++++++++++++++++++++++++++ source3/libsmb/cli_smb2_fnum.h | 5 +++ source3/libsmb/clirap.c | 14 +++++++++ 3 files changed, 89 insertions(+) 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 @@ -1645,6 +1645,75 @@ NTSTATUS cli_smb2_qpathinfo_streams(struct cli_state *cli, return status; } +/*************************************************************** + 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); } -- cgit v1.2.1