Initializing case based parameters during share switch in create_conn_struct_tos_cwd()

Jeremy Allison jra at samba.org
Tue Jan 12 19:48:43 UTC 2021


On Tue, Jan 12, 2021 at 11:13:28AM -0800, Jeremy Allison via samba-technical wrote:
>>
>>The case_sensitive and short_case_preserve were null because we were not
>>initializing these values in conn struct to the share configuration that we
>>were switching to. We are using below settings for the share:
>>
>>case sensitive = no
>>preserve case = yes
>>short preserve case = yes
>>default case = lower
>>
>>I used the code changes that are in the below patch and now we return the
>>folder name in the referral as is. Could you please review this patch and
>>let me know if it is fine?
>>
>>Thanks,
>>Shilpa
>
>Thanks Shilpa, this does look correct. It sets up the
>dfs share in the same way as the case options are created
>in source3/smbd/service.c:make_connection_snum().
>
>I think the best fix here would be to factor this code
>out into a function called by both make_connection_snum()
>and create_conn_struct_as_root() so we know they are
>setting things up identically.

Here's what I ended up with if you want to test.

Thanks !
-------------- next part --------------
From 7d39c4d3ef4f440424eb88dcd0a5844f5e4dcca6 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Tue, 12 Jan 2021 11:39:51 -0800
Subject: [PATCH 1/2] s3: smbd: Factor out setting up case parameters for a
 share to a function - conn_setup_case_options().

Will allow it to be reused in the msdfs temporary share code.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14612

Signed-off-by: Jeremy Allison <jra at samba.org>
---
 source3/smbd/conn.c    | 19 +++++++++++++++++++
 source3/smbd/proto.h   |  1 +
 source3/smbd/service.c | 11 +----------
 3 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/source3/smbd/conn.c b/source3/smbd/conn.c
index 003926c97f6..044242d5697 100644
--- a/source3/smbd/conn.c
+++ b/source3/smbd/conn.c
@@ -232,3 +232,22 @@ void conn_free(connection_struct *conn)
 
 	conn_free_internal(conn);
 }
+
+/*
+ * Correctly initialize a share with case options.
+ */
+void conn_setup_case_options(connection_struct *conn)
+{
+	int snum = conn->params->service;
+
+	if (lp_case_sensitive(snum) == Auto) {
+		/* We will be setting this per packet. Set to be case
+		* insensitive for now. */
+		conn->case_sensitive = false;
+	} else {
+		conn->case_sensitive = (bool)lp_case_sensitive(snum);
+	}
+
+	conn->case_preserve = lp_preserve_case(snum);
+	conn->short_case_preserve = lp_short_preserve_case(snum);
+}
diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h
index 7d6f8eda607..879ec71ae94 100644
--- a/source3/smbd/proto.h
+++ b/source3/smbd/proto.h
@@ -156,6 +156,7 @@ connection_struct *conn_new(struct smbd_server_connection *sconn);
 bool conn_idle_all(struct smbd_server_connection *sconn, time_t t);
 void conn_clear_vuid_caches(struct smbd_server_connection *sconn, uint64_t vuid);
 void conn_free(connection_struct *conn);
+void conn_setup_case_options(connection_struct *conn);
 void conn_force_tdis(
 	struct smbd_server_connection *sconn,
 	bool (*check_fn)(struct connection_struct *conn,
diff --git a/source3/smbd/service.c b/source3/smbd/service.c
index b1ea0ea6a88..afdea38b016 100644
--- a/source3/smbd/service.c
+++ b/source3/smbd/service.c
@@ -557,16 +557,7 @@ static NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
 		      ( lp_enable_asu_support() && strequal(dev,"ADMIN$")) );
 
 	/* Case options for the share. */
-	if (lp_case_sensitive(snum) == Auto) {
-		/* We will be setting this per packet. Set to be case
-		 * insensitive for now. */
-		conn->case_sensitive = False;
-	} else {
-		conn->case_sensitive = (bool)lp_case_sensitive(snum);
-	}
-
-	conn->case_preserve = lp_preserve_case(snum);
-	conn->short_case_preserve = lp_short_preserve_case(snum);
+	conn_setup_case_options(conn);
 
 	conn->encrypt_level = lp_server_smb_encrypt(snum);
 	if (conn->encrypt_level > SMB_ENCRYPTION_OFF) {
-- 
2.27.0


From 5c11f165a04e7686856edee572c5a0fe7c4fcca3 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Tue, 12 Jan 2021 11:44:44 -0800
Subject: [PATCH 2/2] s3: smbd: Add call to conn_setup_case_options() to
 create_conn_struct_as_root().

Ensures temporary DFS share doesn't leave the case parameters set
as zero (i.e.:

conn->case sensitive = 0
conn->share_case_preserve = 0
and default case is lower

which can cause problems doing a DFS_GET_REFERRALS request).

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14612

Signed-off-by: Jeremy Allison <jra at samba.org>
---
 source3/smbd/msdfs.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c
index 7b5ea251501..dc07727f007 100644
--- a/source3/smbd/msdfs.c
+++ b/source3/smbd/msdfs.c
@@ -317,6 +317,8 @@ static NTSTATUS create_conn_struct_as_root(TALLOC_CTX *ctx,
 		vfs_user = get_current_username();
 	}
 
+	conn_setup_case_options(conn);
+
 	set_conn_connectpath(conn, connpath);
 
 	/*
-- 
2.27.0



More information about the samba-technical mailing list