From dc3a1c013493a712700f06caad304248a47c337b 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 (cherry picked from commit d9d5744bc3dd7e18ac6dc23917d903d5e991ab8d) --- 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 28fb5e38c7b389db9a7c9b7778a742d6c9f84c84 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 Reviewed-by: Michael Adam (cherry picked from commit a2b38e0bc94d329963cdad76e6861d3234ede8d4) --- 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 7ec3b56..da29213 100644 --- a/source3/libsmb/cliconnect.c +++ b/source3/libsmb/cliconnect.c @@ -2589,7 +2589,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); } @@ -2723,7 +2730,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 8b3491501f925e91ebd1b41d91c7bceaa59c7724 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 Reviewed-by: Michael Adam (cherry picked from commit 24e7be87d17910c1f4170ecd5fe2d2a8b1419ba5) --- 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 14d4cc3..84f5dfd 100644 --- a/libcli/smb/smbXcli_base.c +++ b/libcli/smb/smbXcli_base.c @@ -2460,6 +2460,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 2d06d8d4da111fd74e2c73f245d4a5cd8bc27a57 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 Reviewed-by: Michael Adam (cherry picked from commit e0fe97c543b2845e3515ffc2c638e4252164beed) --- 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 84f5dfd..616e373 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; @@ -5023,6 +5025,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; @@ -5030,6 +5053,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; } @@ -5041,6 +5065,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; @@ -5079,6 +5104,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 000e9fdcc55c309773fb7903d7d83ec6e3c8a47a 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() These are the attributes returned from the FileFsAttributeInformation request. Bug: https://bugzilla.samba.org/show_bug.cgi?id=10200 Signed-off-by: Stefan Metzmacher Reviewed-by: Michael Adam (cherry picked from commit 1c4e95cbd88e6122c1e2fb07b119abf225c94fff) --- 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 616e373..e9cec7c 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; @@ -5025,6 +5026,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) { @@ -5066,6 +5078,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; @@ -5105,6 +5118,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 5984950c4e619cf98701c6c3ed42dbb465e6e9ea 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 Reviewed-by: Michael Adam (cherry picked from commit 44224cd40fcec262085423577de9eede27a4a22a) --- 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 e9cec7c..3d74404 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 ee3111013b28e29a5604e2a927af615623136fbf 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 Reviewed-by: Michael Adam (cherry picked from commit e6eb6b9e9494d1c8db311e5b967b0da4d75c45aa) --- 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 6dd7b28..8a3ef72 100644 --- a/libcli/smb/smb_constants.h +++ b/libcli/smb/smb_constants.h @@ -363,6 +363,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 e1ab344..64ea568 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 9996a064b210b4410af3888c1f4fb8227fb74153 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 Reviewed-by: Michael Adam (cherry picked from commit b16b469f3fa3766c19ca30f377cc7de6782c05e6) --- 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 3d74404..25fbabd 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 16b0368cb8703ae92a3696cda7c9495c6bd6e4b1 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 Reviewed-by: Michael Adam (cherry picked from commit 60f16bacdc242a8512df352dcdd625661e4b25ad) --- 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 65973d8436b6e475a881b6247391a66d05b5d1ca 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 Reviewed-by: Michael Adam (cherry picked from commit 226dde2879ff8b4b366bf3d9f44f59e7fdc343c0) --- 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 f64f9b352cc3517c22ed3ce0138783e57f9a633e 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 Reviewed-by: Michael Adam (cherry picked from commit 451b11251f7f3a517f94c5d57dab327a30bab52f) --- 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 9b12dac03021b62c3b88bb9adcab39bee1004e75 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 (cherry picked from commit 114e33717df8b49239ac08399a379a8363d33b85) --- 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 7a20c30..76ed190 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 fdead2113a60c1ac6aaaea6134be362c1066cff3 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 Reviewed-by: Michael Adam (cherry picked from commit 37f0e3722cea3ff433d2c95d697e38693c676ae0) --- 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 5faec8badb03bf3a98a58652e15cb1867730056b 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 Reviewed-by: Michael Adam (cherry picked from commit c5c717fe3157224a8aba48a30bace889e7956d31) --- 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 c6659a7ee3e24b41380ef7904aff0ae14294caae 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 Reviewed-by: Michael Adam (cherry picked from commit e20c66d78099bcf5d965bd9d59669fe393481517) --- 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 09f9660..1e08272 100644 --- a/source3/include/client.h +++ b/source3/include/client.h @@ -77,7 +77,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 da29213..13e7704 100644 --- a/source3/libsmb/cliconnect.c +++ b/source3/libsmb/cliconnect.c @@ -2575,16 +2575,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 799222a8a8ec9a2ac522d52955291feaec0b346d 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 Reviewed-by: Michael Adam (cherry picked from commit 307abd61df586baac6cb0bef4272c633c526a7bf) --- 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 1e08272..6c20843 100644 --- a/source3/include/client.h +++ b/source3/include/client.h @@ -90,8 +90,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 6409c6d39568ab2355458aebba77e26840e0db5f 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 Reviewed-by: Michael Adam Autobuild-User(master): Michael Adam Autobuild-Date(master): Thu Oct 17 19:02:03 CEST 2013 on sn-devel-104 (cherry picked from commit 2474455b7f924ae19ea8897d5e506076f7e77419) --- 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 76ed190..9e4ea5c 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