From a1fcbb805fdd81e8502b2af028f08f08f1dd1d6b Mon Sep 17 00:00:00 2001 From: Luk Claes Date: Fri, 17 May 2013 20:13:50 +0200 Subject: [PATCH 01/17] s3/libsmb: Use smbXcli_conn_use_unicode instead of smb1 specific test Signed-off-by: Luk Claes Reviewed-by: Stefan Metzmacher Reviewed-by: Michael Adam --- source3/libsmb/clidfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c index 57126e6..e311ada 100644 --- a/source3/libsmb/clidfs.c +++ b/source3/libsmb/clidfs.c @@ -622,7 +622,7 @@ static bool cli_dfs_check_error(struct cli_state *cli, NTSTATUS expected, { /* only deal with DS when we negotiated NT_STATUS codes and UNICODE */ - if (!(smb1cli_conn_capabilities(cli->conn) & CAP_UNICODE)) { + if (!(smbXcli_conn_use_unicode(cli->conn))) { return false; } if (!(smb1cli_conn_capabilities(cli->conn) & CAP_STATUS32)) { -- 1.7.9.5 From bf88a5c74f01a28810bd30bf06f6a570c7040b75 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 13 Sep 2013 09:10:42 +0200 Subject: [PATCH 02/17] s3:libsmb: make use of smb1cli_tcon_set_values() Bug: https://bugzilla.samba.org/show_bug.cgi?id=10200 Signed-off-by: Stefan Metzmacher --- source3/libsmb/cliconnect.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c index 7bf4187..ad3570b 100644 --- a/source3/libsmb/cliconnect.c +++ b/source3/libsmb/cliconnect.c @@ -2584,7 +2584,14 @@ static void cli_tcon_andx_done(struct tevent_req *subreq) smb1cli_session_protect_session_key(cli->smb1.session); } - cli_state_set_tid(cli, SVAL(inhdr, HDR_TID)); + smb1cli_tcon_set_values(state->cli->smb1.tcon, + SVAL(inhdr, HDR_TID), + optional_support, + 0, /* maximal_access */ + 0, /* guest_maximal_access */ + NULL, /* service */ + NULL); /* fs_type */ + tevent_req_done(req); } @@ -2718,7 +2725,15 @@ static void cli_tree_connect_raw_done(struct tevent_req *subreq) if (tevent_req_nterror(req, status)) { return; } - cli_state_set_tid(state->cli, tid); + + smb1cli_tcon_set_values(state->cli->smb1.tcon, + tid, + 0, /* optional_support */ + 0, /* maximal_access */ + 0, /* guest_maximal_access */ + NULL, /* service */ + NULL); /* fs_type */ + tevent_req_done(req); } -- 1.7.9.5 From c39134d2886c9d18126e62fbd0b17ee2bf4fec33 Mon Sep 17 00:00:00 2001 From: Luk Claes Date: Fri, 17 May 2013 20:41:45 +0200 Subject: [PATCH 03/17] libcli/smb: Introduce smbXcli_conn_dfs_supported Bug: https://bugzilla.samba.org/show_bug.cgi?id=10200 Signed-off-by: Luk Claes Reviewed-by: Stefan Metzmacher --- libcli/smb/smbXcli_base.c | 9 +++++++++ libcli/smb/smbXcli_base.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/libcli/smb/smbXcli_base.c b/libcli/smb/smbXcli_base.c index 27ac2a8..03e96d4 100644 --- a/libcli/smb/smbXcli_base.c +++ b/libcli/smb/smbXcli_base.c @@ -2461,6 +2461,15 @@ bool smbXcli_conn_has_async_calls(struct smbXcli_conn *conn) || (talloc_array_length(conn->pending) != 0)); } +bool smbXcli_conn_dfs_supported(struct smbXcli_conn *conn) +{ + if(conn->protocol >= PROTOCOL_SMB2_02) { + return (smb2cli_conn_server_capabilities(conn) & SMB2_CAP_DFS); + } + + return (smb1cli_conn_capabilities(conn) & CAP_DFS); +} + bool smb2cli_conn_req_possible(struct smbXcli_conn *conn, uint32_t *max_dyn_len) { uint16_t credits = 1; diff --git a/libcli/smb/smbXcli_base.h b/libcli/smb/smbXcli_base.h index 3d93427..93dec59 100644 --- a/libcli/smb/smbXcli_base.h +++ b/libcli/smb/smbXcli_base.h @@ -43,6 +43,8 @@ void smbXcli_conn_disconnect(struct smbXcli_conn *conn, NTSTATUS status); bool smbXcli_conn_has_async_calls(struct smbXcli_conn *conn); +bool smbXcli_conn_dfs_supported(struct smbXcli_conn *conn); + enum protocol_types smbXcli_conn_protocol(struct smbXcli_conn *conn); bool smbXcli_conn_use_unicode(struct smbXcli_conn *conn); -- 1.7.9.5 From 152402682a94d32f013a0993cd1031eb11e59b66 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 13 Sep 2013 11:07:32 +0200 Subject: [PATCH 04/17] libcli/smb: add smbXcli_tcon_is_dfs_share() Bug: https://bugzilla.samba.org/show_bug.cgi?id=10200 Signed-off-by: Stefan Metzmacher --- libcli/smb/smbXcli_base.c | 26 ++++++++++++++++++++++++++ libcli/smb/smbXcli_base.h | 1 + 2 files changed, 27 insertions(+) diff --git a/libcli/smb/smbXcli_base.c b/libcli/smb/smbXcli_base.c index 03e96d4..797f578 100644 --- a/libcli/smb/smbXcli_base.c +++ b/libcli/smb/smbXcli_base.c @@ -167,6 +167,8 @@ struct smbXcli_session { }; struct smbXcli_tcon { + bool is_smb1; + struct { uint16_t tcon_id; uint16_t optional_support; @@ -5025,6 +5027,27 @@ struct smbXcli_tcon *smbXcli_tcon_create(TALLOC_CTX *mem_ctx) return tcon; } +bool smbXcli_tcon_is_dfs_share(struct smbXcli_tcon *tcon) +{ + if (tcon == NULL) { + return false; + } + + if (tcon->is_smb1) { + if (tcon->smb1.optional_support & SMB_SHARE_IN_DFS) { + return true; + } + + return false; + } + + if (tcon->smb2.capabilities & SMB2_SHARE_CAP_DFS) { + return true; + } + + return false; +} + uint16_t smb1cli_tcon_current_id(struct smbXcli_tcon *tcon) { return tcon->smb1.tcon_id; @@ -5032,6 +5055,7 @@ uint16_t smb1cli_tcon_current_id(struct smbXcli_tcon *tcon) void smb1cli_tcon_set_id(struct smbXcli_tcon *tcon, uint16_t tcon_id) { + tcon->is_smb1 = true; tcon->smb1.tcon_id = tcon_id; } @@ -5043,6 +5067,7 @@ bool smb1cli_tcon_set_values(struct smbXcli_tcon *tcon, const char *service, const char *fs_type) { + tcon->is_smb1 = true; tcon->smb1.tcon_id = tcon_id; tcon->smb1.optional_support = optional_support; tcon->smb1.maximal_access = maximal_access; @@ -5081,6 +5106,7 @@ void smb2cli_tcon_set_values(struct smbXcli_tcon *tcon, uint32_t capabilities, uint32_t maximal_access) { + tcon->is_smb1 = false; tcon->smb2.tcon_id = tcon_id; tcon->smb2.type = type; tcon->smb2.flags = flags; diff --git a/libcli/smb/smbXcli_base.h b/libcli/smb/smbXcli_base.h index 93dec59..7fab374 100644 --- a/libcli/smb/smbXcli_base.h +++ b/libcli/smb/smbXcli_base.h @@ -299,6 +299,7 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session, NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session); struct smbXcli_tcon *smbXcli_tcon_create(TALLOC_CTX *mem_ctx); +bool smbXcli_tcon_is_dfs_share(struct smbXcli_tcon *tcon); uint16_t smb1cli_tcon_current_id(struct smbXcli_tcon *tcon); void smb1cli_tcon_set_id(struct smbXcli_tcon *tcon, uint16_t tcon_id); bool smb1cli_tcon_set_values(struct smbXcli_tcon *tcon, -- 1.7.9.5 From d5a0bb46e81f8a8f058b1c86cfd5889fe2d70566 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 27 Sep 2013 05:02:09 +0200 Subject: [PATCH 05/17] libcli/smb: add smbXcli_tcon_{set,get}_fs_attributes() This are the attributes returned from the FileFsAttributeInformation request. Bug: https://bugzilla.samba.org/show_bug.cgi?id=10200 Signed-off-by: Stefan Metzmacher --- libcli/smb/smbXcli_base.c | 14 ++++++++++++++ libcli/smb/smbXcli_base.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/libcli/smb/smbXcli_base.c b/libcli/smb/smbXcli_base.c index 797f578..6fcedb0 100644 --- a/libcli/smb/smbXcli_base.c +++ b/libcli/smb/smbXcli_base.c @@ -168,6 +168,7 @@ struct smbXcli_session { struct smbXcli_tcon { bool is_smb1; + uint32_t fs_attributes; struct { uint16_t tcon_id; @@ -5027,6 +5028,17 @@ struct smbXcli_tcon *smbXcli_tcon_create(TALLOC_CTX *mem_ctx) return tcon; } +void smbXcli_tcon_set_fs_attributes(struct smbXcli_tcon *tcon, + uint32_t fs_attributes) +{ + tcon->fs_attributes = fs_attributes; +} + +uint32_t smbXcli_tcon_get_fs_attributes(struct smbXcli_tcon *tcon) +{ + return tcon->fs_attributes; +} + bool smbXcli_tcon_is_dfs_share(struct smbXcli_tcon *tcon) { if (tcon == NULL) { @@ -5068,6 +5080,7 @@ bool smb1cli_tcon_set_values(struct smbXcli_tcon *tcon, const char *fs_type) { tcon->is_smb1 = true; + tcon->fs_attributes = 0; tcon->smb1.tcon_id = tcon_id; tcon->smb1.optional_support = optional_support; tcon->smb1.maximal_access = maximal_access; @@ -5107,6 +5120,7 @@ void smb2cli_tcon_set_values(struct smbXcli_tcon *tcon, uint32_t maximal_access) { tcon->is_smb1 = false; + tcon->fs_attributes = 0; tcon->smb2.tcon_id = tcon_id; tcon->smb2.type = type; tcon->smb2.flags = flags; diff --git a/libcli/smb/smbXcli_base.h b/libcli/smb/smbXcli_base.h index 7fab374..5fe4018 100644 --- a/libcli/smb/smbXcli_base.h +++ b/libcli/smb/smbXcli_base.h @@ -299,6 +299,9 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session, NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session); struct smbXcli_tcon *smbXcli_tcon_create(TALLOC_CTX *mem_ctx); +void smbXcli_tcon_set_fs_attributes(struct smbXcli_tcon *tcon, + uint32_t fs_attributes); +uint32_t smbXcli_tcon_get_fs_attributes(struct smbXcli_tcon *tcon); bool smbXcli_tcon_is_dfs_share(struct smbXcli_tcon *tcon); uint16_t smb1cli_tcon_current_id(struct smbXcli_tcon *tcon); void smb1cli_tcon_set_id(struct smbXcli_tcon *tcon, uint16_t tcon_id); -- 1.7.9.5 From 3a542c05ae5cba7717a1e3ff8c3107763f15004c Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 18 Sep 2013 03:31:33 +0200 Subject: [PATCH 06/17] libcli/smb: add FLAGS2_DFS_PATHNAMES for SMB1 operations against dfs shares Bug: https://bugzilla.samba.org/show_bug.cgi?id=10200 Signed-off-by: Stefan Metzmacher --- libcli/smb/smbXcli_base.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libcli/smb/smbXcli_base.c b/libcli/smb/smbXcli_base.c index 6fcedb0..153361f 100644 --- a/libcli/smb/smbXcli_base.c +++ b/libcli/smb/smbXcli_base.c @@ -1272,6 +1272,12 @@ struct tevent_req *smb1cli_req_create(TALLOC_CTX *mem_ctx, if (tcon) { tid = tcon->smb1.tcon_id; + + if (smbXcli_conn_dfs_supported(conn) && + smbXcli_tcon_is_dfs_share(tcon)) + { + additional_flags2 |= FLAGS2_DFS_PATHNAMES; + } } state->smb1.recv_cmd = 0xFF; -- 1.7.9.5 From 4480e0c93154cda1e49072fac770d458e1f01c2d Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 27 Sep 2013 05:30:03 +0200 Subject: [PATCH 07/17] libcli/smb: move Filesystem Attributes defines to smb_constants.h Bug: https://bugzilla.samba.org/show_bug.cgi?id=10200 Signed-off-by: Stefan Metzmacher --- libcli/smb/smb_constants.h | 19 +++++++++++++++++++ source3/include/smb.h | 19 ------------------- source4/libcli/raw/smb.h | 14 -------------- 3 files changed, 19 insertions(+), 33 deletions(-) diff --git a/libcli/smb/smb_constants.h b/libcli/smb/smb_constants.h index e1d888f..b38c489 100644 --- a/libcli/smb/smb_constants.h +++ b/libcli/smb/smb_constants.h @@ -364,6 +364,25 @@ enum csc_policy { #define OPLOCK_BREAK_TO_NONE 0 #define OPLOCK_BREAK_TO_LEVEL_II 1 +/* Filesystem Attributes. */ +#define FILE_CASE_SENSITIVE_SEARCH 0x00000001 +#define FILE_CASE_PRESERVED_NAMES 0x00000002 +#define FILE_UNICODE_ON_DISK 0x00000004 +/* According to cifs9f, this is 4, not 8 */ +/* Acconding to testing, this actually sets the security attribute! */ +#define FILE_PERSISTENT_ACLS 0x00000008 +#define FILE_FILE_COMPRESSION 0x00000010 +#define FILE_VOLUME_QUOTAS 0x00000020 +#define FILE_SUPPORTS_SPARSE_FILES 0x00000040 +#define FILE_SUPPORTS_REPARSE_POINTS 0x00000080 +#define FILE_SUPPORTS_REMOTE_STORAGE 0x00000100 +#define FS_LFN_APIS 0x00004000 +#define FILE_VOLUME_IS_COMPRESSED 0x00008000 +#define FILE_SUPPORTS_OBJECT_IDS 0x00010000 +#define FILE_SUPPORTS_ENCRYPTION 0x00020000 +#define FILE_NAMED_STREAMS 0x00040000 +#define FILE_READ_ONLY_VOLUME 0x00080000 + /* ioctl codes */ #define IOCTL_QUERY_JOB_INFO 0x530060 diff --git a/source3/include/smb.h b/source3/include/smb.h index 0d07f71..9dd49d5 100644 --- a/source3/include/smb.h +++ b/source3/include/smb.h @@ -513,25 +513,6 @@ Offset Data length. #define RENAME_FLAG_RENAME 0x104 #define RENAME_FLAG_COPY 0x105 -/* Filesystem Attributes. */ -#define FILE_CASE_SENSITIVE_SEARCH 0x00000001 -#define FILE_CASE_PRESERVED_NAMES 0x00000002 -#define FILE_UNICODE_ON_DISK 0x00000004 -/* According to cifs9f, this is 4, not 8 */ -/* Acconding to testing, this actually sets the security attribute! */ -#define FILE_PERSISTENT_ACLS 0x00000008 -#define FILE_FILE_COMPRESSION 0x00000010 -#define FILE_VOLUME_QUOTAS 0x00000020 -#define FILE_SUPPORTS_SPARSE_FILES 0x00000040 -#define FILE_SUPPORTS_REPARSE_POINTS 0x00000080 -#define FILE_SUPPORTS_REMOTE_STORAGE 0x00000100 -#define FS_LFN_APIS 0x00004000 -#define FILE_VOLUME_IS_COMPRESSED 0x00008000 -#define FILE_SUPPORTS_OBJECT_IDS 0x00010000 -#define FILE_SUPPORTS_ENCRYPTION 0x00020000 -#define FILE_NAMED_STREAMS 0x00040000 -#define FILE_READ_ONLY_VOLUME 0x00080000 - /* ChangeNotify flags. */ #define FILE_NOTIFY_CHANGE_FILE_NAME 0x001 #define FILE_NOTIFY_CHANGE_DIR_NAME 0x002 diff --git a/source4/libcli/raw/smb.h b/source4/libcli/raw/smb.h index 279ada1..38aefb6 100644 --- a/source4/libcli/raw/smb.h +++ b/source4/libcli/raw/smb.h @@ -251,20 +251,6 @@ #define RENAME_FLAG_RENAME 0x104 #define RENAME_FLAG_COPY 0x105 -/* Filesystem Attributes. */ -#define FILE_CASE_SENSITIVE_SEARCH 0x01 -#define FILE_CASE_PRESERVED_NAMES 0x02 -#define FILE_UNICODE_ON_DISK 0x04 -/* According to cifs9f, this is 4, not 8 */ -/* Acconding to testing, this actually sets the security attribute! */ -#define FILE_PERSISTENT_ACLS 0x08 -/* These entries added from cifs9f --tsb */ -#define FILE_FILE_COMPRESSION 0x10 -#define FILE_VOLUME_QUOTAS 0x20 -/* I think this is wrong. JRA #define FILE_DEVICE_IS_MOUNTED 0x20 */ -#define FILE_VOLUME_SPARSE_FILE 0x40 -#define FILE_VOLUME_IS_COMPRESSED 0x8000 - /* ChangeNotify flags. */ #define FILE_NOTIFY_CHANGE_FILE_NAME 0x00000001 #define FILE_NOTIFY_CHANGE_DIR_NAME 0x00000002 -- 1.7.9.5 From 0d46af48454b28530e9859b52d603f8eeb374c2d Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 27 Sep 2013 05:31:07 +0200 Subject: [PATCH 08/17] libcli/smb: add FLAG_CASELESS_PATHNAMES based on FILE_CASE_SENSITIVE_SEARCH to smb1 requests Bug: https://bugzilla.samba.org/show_bug.cgi?id=10200 Signed-off-by: Stefan Metzmacher --- libcli/smb/smbXcli_base.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libcli/smb/smbXcli_base.c b/libcli/smb/smbXcli_base.c index 153361f..176f596 100644 --- a/libcli/smb/smbXcli_base.c +++ b/libcli/smb/smbXcli_base.c @@ -1273,6 +1273,13 @@ struct tevent_req *smb1cli_req_create(TALLOC_CTX *mem_ctx, if (tcon) { tid = tcon->smb1.tcon_id; + if (tcon->fs_attributes & FILE_CASE_SENSITIVE_SEARCH) { + clear_flags |= FLAG_CASELESS_PATHNAMES; + } else { + /* Default setting, case insensitive. */ + additional_flags |= FLAG_CASELESS_PATHNAMES; + } + if (smbXcli_conn_dfs_supported(conn) && smbXcli_tcon_is_dfs_share(tcon)) { -- 1.7.9.5 From c3a221699a5a2af5c7aa124cee478fa92c3ff6fe Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 18 Sep 2013 03:50:42 +0200 Subject: [PATCH 09/17] libcli/smb: add SMB2_HDR_FLAG_DFS for SMB2 Create operations on dfs shares Bug: https://bugzilla.samba.org/show_bug.cgi?id=10200 Signed-off-by: Stefan Metzmacher --- libcli/smb/smb2cli_create.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libcli/smb/smb2cli_create.c b/libcli/smb/smb2cli_create.c index 3f8d672..9cb94b1 100644 --- a/libcli/smb/smb2cli_create.c +++ b/libcli/smb/smb2cli_create.c @@ -63,6 +63,8 @@ struct tevent_req *smb2cli_create_send( uint8_t *dyn; size_t dyn_len; size_t max_dyn_len; + uint32_t additional_flags = 0; + uint32_t clear_flags = 0; req = tevent_req_create(mem_ctx, &state, struct smb2cli_create_state); @@ -130,6 +132,12 @@ struct tevent_req *smb2cli_create_send( data_blob_free(&blob); } + if (smbXcli_conn_dfs_supported(conn) && + smbXcli_tcon_is_dfs_share(tcon)) + { + additional_flags |= SMB2_HDR_FLAG_DFS; + } + /* * We use max_dyn_len = 0 * as we don't explicitly ask for any output length. @@ -140,7 +148,7 @@ struct tevent_req *smb2cli_create_send( max_dyn_len = 0; subreq = smb2cli_req_send(state, ev, conn, SMB2_OP_CREATE, - 0, 0, /* flags */ + additional_flags, clear_flags, timeout_msec, tcon, session, -- 1.7.9.5 From b0b457f337ca1472175bdfb7ead12bf4224cdefb Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 27 Sep 2013 05:11:45 +0200 Subject: [PATCH 10/17] s3:libsmb: call smbXcli_tcon_{get,set}_fs_attributes() from cli_set_case_sensitive() Bug: https://bugzilla.samba.org/show_bug.cgi?id=10200 Signed-off-by: Stefan Metzmacher --- source3/libsmb/clientgen.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/source3/libsmb/clientgen.c b/source3/libsmb/clientgen.c index 821a134..e717bb2 100644 --- a/source3/libsmb/clientgen.c +++ b/source3/libsmb/clientgen.c @@ -426,6 +426,23 @@ uint16_t cli_state_set_uid(struct cli_state *cli, uint16_t uid) bool cli_set_case_sensitive(struct cli_state *cli, bool case_sensitive) { bool ret = cli->case_sensitive; + uint32_t fs_attrs; + struct smbXcli_tcon *tcon; + + if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) { + tcon = cli->smb2.tcon; + } else { + tcon = cli->smb1.tcon; + } + + fs_attrs = smbXcli_tcon_get_fs_attributes(tcon); + if (case_sensitive) { + fs_attrs |= FILE_CASE_SENSITIVE_SEARCH; + } else { + fs_attrs &= ~FILE_CASE_SENSITIVE_SEARCH; + } + smbXcli_tcon_set_fs_attributes(tcon, fs_attrs); + cli->case_sensitive = case_sensitive; return ret; } -- 1.7.9.5 From 0c07457bc9471d5ca96d7988c8ab4177686b22f3 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 27 Sep 2013 05:34:12 +0200 Subject: [PATCH 11/17] s3:libsmb: don't pass down FLAG_CASELESS_PATHNAMES and FLAGS2_DFS_PATHNAMES anymore They're now handled at the smbXcli_conn and smbXcli_tcon layer. Bug: https://bugzilla.samba.org/show_bug.cgi?id=10200 Signed-off-by: Stefan Metzmacher --- source3/libsmb/async_smb.c | 22 ---------------------- source3/libsmb/clitrans.c | 21 --------------------- 2 files changed, 43 deletions(-) diff --git a/source3/libsmb/async_smb.c b/source3/libsmb/async_smb.c index ed68a5d..8d5c3d4 100644 --- a/source3/libsmb/async_smb.c +++ b/source3/libsmb/async_smb.c @@ -76,17 +76,6 @@ struct tevent_req *cli_smb_req_create(TALLOC_CTX *mem_ctx, } *state->ptr = state; - if (cli->case_sensitive) { - clear_flags |= FLAG_CASELESS_PATHNAMES; - } else { - /* Default setting, case insensitive. */ - additional_flags |= FLAG_CASELESS_PATHNAMES; - } - - if ((smb1cli_conn_capabilities(cli->conn) & CAP_DFS) && cli->dfsroot) { - additional_flags2 |= FLAGS2_DFS_PATHNAMES; - } - state->req = smb1cli_req_create(state, ev, cli->conn, smb_command, additional_flags, clear_flags, additional_flags2, clear_flags2, @@ -134,17 +123,6 @@ struct tevent_req *cli_smb_send(TALLOC_CTX *mem_ctx, } *state->ptr = state; - if (cli->case_sensitive) { - clear_flags |= FLAG_CASELESS_PATHNAMES; - } else { - /* Default setting, case insensitive. */ - additional_flags |= FLAG_CASELESS_PATHNAMES; - } - - if ((smb1cli_conn_capabilities(cli->conn) & CAP_DFS) && cli->dfsroot) { - additional_flags2 |= FLAGS2_DFS_PATHNAMES; - } - state->req = smb1cli_req_send(state, ev, cli->conn, smb_command, additional_flags, clear_flags, additional_flags2, clear_flags2, diff --git a/source3/libsmb/clitrans.c b/source3/libsmb/clitrans.c index 08fda5f..5462134 100644 --- a/source3/libsmb/clitrans.c +++ b/source3/libsmb/clitrans.c @@ -73,16 +73,6 @@ struct tevent_req *cli_trans_send( return NULL; } *state->ptr = state; - if (cli->case_sensitive) { - clear_flags |= FLAG_CASELESS_PATHNAMES; - } else { - /* Default setting, case insensitive. */ - additional_flags |= FLAG_CASELESS_PATHNAMES; - } - - if ((smb1cli_conn_capabilities(cli->conn) & CAP_DFS) && cli->dfsroot) { - additional_flags2 |= FLAGS2_DFS_PATHNAMES; - } state->req = smb1cli_trans_send(state, ev, cli->conn, cmd, @@ -169,17 +159,6 @@ NTSTATUS cli_trans(TALLOC_CTX *mem_ctx, struct cli_state *cli, uint16_t additional_flags2 = 0; uint16_t clear_flags2 = 0; - if (cli->case_sensitive) { - clear_flags |= FLAG_CASELESS_PATHNAMES; - } else { - /* Default setting, case insensitive. */ - additional_flags |= FLAG_CASELESS_PATHNAMES; - } - - if ((smb1cli_conn_capabilities(cli->conn) & CAP_DFS) && cli->dfsroot) { - additional_flags2 |= FLAGS2_DFS_PATHNAMES; - } - status = smb1cli_trans(mem_ctx, cli->conn, trans_cmd, additional_flags, clear_flags, -- 1.7.9.5 From b197f0d6869f7fdeff8b6e8d826629efe18e1eb7 Mon Sep 17 00:00:00 2001 From: Luk Claes Date: Fri, 17 May 2013 20:46:24 +0200 Subject: [PATCH 12/17] s3/libsmb: Use smbXcli_conn_dfs_supported instead of test on CAP_DFS Bug: https://bugzilla.samba.org/show_bug.cgi?id=10200 Signed-off-by: Luk Claes Reviewed-by: Michael Adam Reviewed-by: Stefan Metzmacher --- source3/libsmb/clidfs.c | 2 +- source3/libsmb/libsmb_server.c | 2 +- source3/libsmb/libsmb_stat.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c index e311ada..83bfdcf 100644 --- a/source3/libsmb/clidfs.c +++ b/source3/libsmb/clidfs.c @@ -234,7 +234,7 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx, here before trying to connect to the original share. cli_check_msdfs_proxy() will fail if it is a normal share. */ - if ((smb1cli_conn_capabilities(c->conn) & CAP_DFS) && + if (smbXcli_conn_dfs_supported(c->conn) && cli_check_msdfs_proxy(ctx, c, sharename, &newserver, &newshare, force_encrypt, diff --git a/source3/libsmb/libsmb_server.c b/source3/libsmb/libsmb_server.c index 35b31d8..357dc28 100644 --- a/source3/libsmb/libsmb_server.c +++ b/source3/libsmb/libsmb_server.c @@ -497,7 +497,7 @@ SMBC_server_internal(TALLOC_CTX *ctx, here before trying to connect to the original share. cli_check_msdfs_proxy() will fail if it is a normal share. */ - if ((smb1cli_conn_capabilities(c->conn) & CAP_DFS) && + if (smbXcli_conn_dfs_supported(c->conn) && cli_check_msdfs_proxy(ctx, c, share, &newserver, &newshare, /* FIXME: cli_check_msdfs_proxy() does diff --git a/source3/libsmb/libsmb_stat.c b/source3/libsmb/libsmb_stat.c index fbbd887..dc59f9c 100644 --- a/source3/libsmb/libsmb_stat.c +++ b/source3/libsmb/libsmb_stat.c @@ -469,7 +469,7 @@ SMBC_fstatvfs_ctx(SMBCCTX *context, } /* See if DFS is supported */ - if ((smb1cli_conn_capabilities(cli->conn) & CAP_DFS) && cli->dfsroot) { + if (smbXcli_conn_dfs_supported(cli->conn) && cli->dfsroot) { flags |= SMBC_VFS_FEATURE_DFS; } -- 1.7.9.5 From 6161aa6fbff8e1ebd3282ece28f619d6bf9b7171 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 27 Sep 2013 05:44:33 +0200 Subject: [PATCH 13/17] s3/libsmb: make use of smbXcli_tcon_is_dfs_share() Bug: https://bugzilla.samba.org/show_bug.cgi?id=10200 Signed-off-by: Stefan Metzmacher --- source3/libsmb/clidfs.c | 18 ++++++++++++++++-- source3/libsmb/libsmb_stat.c | 11 ++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c index 83bfdcf..2e4a3b8 100644 --- a/source3/libsmb/clidfs.c +++ b/source3/libsmb/clidfs.c @@ -822,6 +822,8 @@ NTSTATUS cli_resolve_path(TALLOC_CTX *ctx, SMB_STRUCT_STAT sbuf; uint32 attributes; NTSTATUS status; + struct smbXcli_tcon *root_tcon = NULL; + struct smbXcli_tcon *target_tcon = NULL; if ( !rootcli || !path || !targetcli ) { return NT_STATUS_INVALID_PARAMETER; @@ -829,7 +831,13 @@ NTSTATUS cli_resolve_path(TALLOC_CTX *ctx, /* Don't do anything if this is not a DFS root. */ - if ( !rootcli->dfsroot) { + if (smbXcli_conn_protocol(rootcli->conn) >= PROTOCOL_SMB2_02) { + root_tcon = rootcli->smb2.tcon; + } else { + root_tcon = rootcli->smb1.tcon; + } + + if (!smbXcli_tcon_is_dfs_share(root_tcon)) { *targetcli = rootcli; *pp_targetpath = talloc_strdup(ctx, path); if (!*pp_targetpath) { @@ -1029,8 +1037,14 @@ NTSTATUS cli_resolve_path(TALLOC_CTX *ctx, done: + if (smbXcli_conn_protocol((*targetcli)->conn) >= PROTOCOL_SMB2_02) { + target_tcon = (*targetcli)->smb2.tcon; + } else { + target_tcon = (*targetcli)->smb1.tcon; + } + /* If returning true ensure we return a dfs root full path. */ - if ((*targetcli)->dfsroot) { + if (smbXcli_tcon_is_dfs_share(target_tcon)) { dfs_path = talloc_strdup(ctx, *pp_targetpath); if (!dfs_path) { return NT_STATUS_NO_MEMORY; diff --git a/source3/libsmb/libsmb_stat.c b/source3/libsmb/libsmb_stat.c index dc59f9c..94449e0 100644 --- a/source3/libsmb/libsmb_stat.c +++ b/source3/libsmb/libsmb_stat.c @@ -364,6 +364,13 @@ SMBC_fstatvfs_ctx(SMBCCTX *context, unsigned long flags = 0; uint32 fs_attrs = 0; struct cli_state *cli = file->srv->cli; + struct smbXcli_tcon *tcon; + + if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) { + tcon = cli->smb2.tcon; + } else { + tcon = cli->smb1.tcon; + } /* Initialize all fields (at least until we actually use them) */ memset(st, 0, sizeof(*st)); @@ -469,7 +476,9 @@ SMBC_fstatvfs_ctx(SMBCCTX *context, } /* See if DFS is supported */ - if (smbXcli_conn_dfs_supported(cli->conn) && cli->dfsroot) { + if (smbXcli_conn_dfs_supported(cli->conn) && + smbXcli_tcon_is_dfs_share(tcon)) + { flags |= SMBC_VFS_FEATURE_DFS; } -- 1.7.9.5 From 5d67cd749e1656f2c4cd0a473f26b9379ee2c642 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sun, 13 Oct 2013 16:54:18 +0200 Subject: [PATCH 14/17] s3:libsmb: add SMB2/3 support to cli_dfs_get_referral() Bug: https://bugzilla.samba.org/show_bug.cgi?id=10200 Signed-off-by: Stefan Metzmacher --- source3/libsmb/clidfs.c | 73 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c index 2e4a3b8..ff48719 100644 --- a/source3/libsmb/clidfs.c +++ b/source3/libsmb/clidfs.c @@ -645,9 +645,7 @@ NTSTATUS cli_dfs_get_referral(TALLOC_CTX *ctx, size_t *num_refs, size_t *consumed) { - unsigned int data_len = 0; unsigned int param_len = 0; - uint16_t setup[1]; uint16_t recv_flags2; uint8_t *param = NULL; uint8_t *rdata = NULL; @@ -664,8 +662,6 @@ NTSTATUS cli_dfs_get_referral(TALLOC_CTX *ctx, *num_refs = 0; *refs = NULL; - SSVAL(setup, 0, TRANSACT2_GET_DFS_REFERRAL); - param = talloc_array(talloc_tos(), uint8_t, 2); if (!param) { status = NT_STATUS_NO_MEMORY; @@ -683,20 +679,63 @@ NTSTATUS cli_dfs_get_referral(TALLOC_CTX *ctx, param_len = talloc_get_size(param); path_ucs = (smb_ucs2_t *)¶m[2]; - status = cli_trans(talloc_tos(), cli, SMBtrans2, - NULL, 0xffff, 0, 0, - setup, 1, 0, - param, param_len, 2, - NULL, 0, CLI_BUFFER_SIZE, - &recv_flags2, - NULL, 0, NULL, /* rsetup */ - NULL, 0, NULL, - &rdata, 4, &data_len); - if (!NT_STATUS_IS_OK(status)) { - goto out; - } + if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) { + DATA_BLOB in_input_buffer; + DATA_BLOB in_output_buffer = data_blob_null; + DATA_BLOB out_input_buffer = data_blob_null; + DATA_BLOB out_output_buffer = data_blob_null; + + in_input_buffer.data = param; + in_input_buffer.length = param_len; + + status = smb2cli_ioctl(cli->conn, + cli->timeout, + cli->smb2.session, + cli->smb2.tcon, + UINT64_MAX, /* in_fid_persistent */ + UINT64_MAX, /* in_fid_volatile */ + FSCTL_DFS_GET_REFERRALS, + 0, /* in_max_input_length */ + &in_input_buffer, + CLI_BUFFER_SIZE, /* in_max_output_length */ + &in_output_buffer, + SMB2_IOCTL_FLAG_IS_FSCTL, + talloc_tos(), + &out_input_buffer, + &out_output_buffer); + if (!NT_STATUS_IS_OK(status)) { + goto out; + } - endp = (char *)rdata + data_len; + if (out_output_buffer.length < 4) { + status = NT_STATUS_INVALID_NETWORK_RESPONSE; + goto out; + } + + recv_flags2 = FLAGS2_UNICODE_STRINGS; + rdata = out_output_buffer.data; + endp = (char *)rdata + out_output_buffer.length; + } else { + unsigned int data_len = 0; + uint16_t setup[1]; + + SSVAL(setup, 0, TRANSACT2_GET_DFS_REFERRAL); + + status = cli_trans(talloc_tos(), cli, SMBtrans2, + NULL, 0xffff, 0, 0, + setup, 1, 0, + param, param_len, 2, + NULL, 0, CLI_BUFFER_SIZE, + &recv_flags2, + NULL, 0, NULL, /* rsetup */ + NULL, 0, NULL, + &rdata, 4, &data_len); + if (!NT_STATUS_IS_OK(status)) { + goto out; + } + + endp = (char *)rdata + data_len; + } consumed_ucs = SVAL(rdata, 0); num_referrals = SVAL(rdata, 2); -- 1.7.9.5 From 22474ea1ff8589a0e6146c4ccfbf9dd36165aa53 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 18 Sep 2013 09:40:08 +0200 Subject: [PATCH 15/17] s3:libsmb: remove unused cli_state->dfsroot Bug: https://bugzilla.samba.org/show_bug.cgi?id=10200 Signed-off-by: Stefan Metzmacher --- source3/include/client.h | 1 - source3/libsmb/cliconnect.c | 6 ------ 2 files changed, 7 deletions(-) diff --git a/source3/include/client.h b/source3/include/client.h index f6a4a81..babcfb8 100644 --- a/source3/include/client.h +++ b/source3/include/client.h @@ -76,7 +76,6 @@ struct cli_state { uint32_t server_posix_capabilities; /* What the client requested. */ uint32_t requested_posix_capabilities; - bool dfsroot; bool backup_intent; /* The list of pipes currently open on this connection. */ diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c index ad3570b..81bc028 100644 --- a/source3/libsmb/cliconnect.c +++ b/source3/libsmb/cliconnect.c @@ -2570,16 +2570,10 @@ static void cli_tcon_andx_done(struct tevent_req *subreq) * Avoids issues when connecting to Win9x boxes sharing files */ - cli->dfsroot = false; - if ((wct > 2) && (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_LANMAN2)) { optional_support = SVAL(vwv+2, 0); } - if (optional_support & SMB_SHARE_IN_DFS) { - cli->dfsroot = true; - } - if (optional_support & SMB_EXTENDED_SIGNATURES) { smb1cli_session_protect_session_key(cli->smb1.session); } -- 1.7.9.5 From 33d634698748b6166a8462f58e1289d2fff297e0 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 27 Sep 2013 05:45:21 +0200 Subject: [PATCH 16/17] s3:libsmb: remove unused cli_state->case_sensitive Bug: https://bugzilla.samba.org/show_bug.cgi?id=10200 Signed-off-by: Stefan Metzmacher --- source3/include/client.h | 2 -- source3/libsmb/clientgen.c | 9 ++++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/source3/include/client.h b/source3/include/client.h index babcfb8..35fa2f1 100644 --- a/source3/include/client.h +++ b/source3/include/client.h @@ -89,8 +89,6 @@ struct cli_state { bool use_oplocks; /* should we use oplocks? */ - bool case_sensitive; /* False by default. */ - /* Where (if anywhere) this is mounted under DFS. */ char *dfs_mountpoint; diff --git a/source3/libsmb/clientgen.c b/source3/libsmb/clientgen.c index e717bb2..8a38810 100644 --- a/source3/libsmb/clientgen.c +++ b/source3/libsmb/clientgen.c @@ -177,7 +177,6 @@ struct cli_state *cli_state_create(TALLOC_CTX *mem_ctx, cli->raw_status = NT_STATUS_INTERNAL_ERROR; cli->map_dos_errors = true; /* remove this */ cli->timeout = CLIENT_TIMEOUT; - cli->case_sensitive = false; /* Set the CLI_FORCE_DOSERR environment variable to test client routines using DOS errors instead of STATUS32 @@ -425,7 +424,7 @@ uint16_t cli_state_set_uid(struct cli_state *cli, uint16_t uid) bool cli_set_case_sensitive(struct cli_state *cli, bool case_sensitive) { - bool ret = cli->case_sensitive; + bool ret; uint32_t fs_attrs; struct smbXcli_tcon *tcon; @@ -436,6 +435,11 @@ bool cli_set_case_sensitive(struct cli_state *cli, bool case_sensitive) } fs_attrs = smbXcli_tcon_get_fs_attributes(tcon); + if (fs_attrs & FILE_CASE_SENSITIVE_SEARCH) { + ret = true; + } else { + ret = false; + } if (case_sensitive) { fs_attrs |= FILE_CASE_SENSITIVE_SEARCH; } else { @@ -443,7 +447,6 @@ bool cli_set_case_sensitive(struct cli_state *cli, bool case_sensitive) } smbXcli_tcon_set_fs_attributes(tcon, fs_attrs); - cli->case_sensitive = case_sensitive; return ret; } -- 1.7.9.5 From f42e7f359e2257f83035b4825b15dc4f3c963a56 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 27 Sep 2013 06:06:32 +0200 Subject: [PATCH 17/17] s3:libsmb: call smbXcli_tcon_set_fs_attributes() directly We should try to set all attributes we got and not just FILE_CASE_SENSITIVE_SEARCH. Bug: https://bugzilla.samba.org/show_bug.cgi?id=10200 Signed-off-by: Stefan Metzmacher --- source3/libsmb/libsmb_server.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/source3/libsmb/libsmb_server.c b/source3/libsmb/libsmb_server.c index 357dc28..9d87f42 100644 --- a/source3/libsmb/libsmb_server.c +++ b/source3/libsmb/libsmb_server.c @@ -256,6 +256,7 @@ SMBC_server_internal(TALLOC_CTX *ctx, NTSTATUS status; char *newserver, *newshare; int flags = 0; + struct smbXcli_tcon *tcon = NULL; ZERO_STRUCT(c); *in_cache = false; @@ -528,6 +529,12 @@ SMBC_server_internal(TALLOC_CTX *ctx, DEBUG(4,(" tconx ok\n")); + if (smbXcli_conn_protocol(c->conn) >= PROTOCOL_SMB2_02) { + tcon = c->smb2.tcon; + } else { + tcon = c->smb1.tcon; + } + /* Determine if this share supports case sensitivity */ if (is_ipc) { DEBUG(4, ("IPC$ so ignore case sensitivity\n")); @@ -555,10 +562,7 @@ SMBC_server_internal(TALLOC_CTX *ctx, (fs_attrs & FILE_CASE_SENSITIVE_SEARCH ? "True" : "False"))); - cli_set_case_sensitive(c, - (fs_attrs & FILE_CASE_SENSITIVE_SEARCH - ? True - : False)); + smbXcli_tcon_set_fs_attributes(tcon, fs_attrs); } if (context->internal->smb_encryption_level) { -- 1.7.9.5