[PATCH] Start moving lp_posix_pathnames out of utility functions.

Jeremy Allison jra at samba.org
Fri Dec 11 23:07:30 UTC 2015


From the "I broke it so I should help fix it" department :-).

Here is a patchset that ends up removing lp_posix_pathnames()
from ms_has_wild(), where it had no business being.

If we're ever to make SMB2 unix extensions a reality
we need to have a handle-based posix pathname flag
for SMB2 processing, not grubbing around with a global
hidden behind a function (that can be left for the SMB1
code :-).

Ultimate goal is to add a 'bool posix_paths' flag
to the struct smbd_smb2_request struct.

Volker, let me know if this works for you ?

Please review and push if you're happy.

Cheers,

	Jeremy
-------------- next part --------------
From f6fbe3d80d6b247e7148813dcf021b87369aa859 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Fri, 11 Dec 2015 14:33:22 -0800
Subject: [PATCH 1/9] s3: smbd: Moving lp_posix_pathnames() out of the
 lower-level code.

Ensure we set posix_pathnames early.

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

diff --git a/source3/smbd/filename.c b/source3/smbd/filename.c
index 555658d..4b40df3 100644
--- a/source3/smbd/filename.c
+++ b/source3/smbd/filename.c
@@ -229,7 +229,8 @@ NTSTATUS unix_convert(TALLOC_CTX *ctx,
 	char *stream = NULL;
 	bool component_was_mangled = False;
 	bool name_has_wildcard = False;
-	bool posix_pathnames = false;
+	bool posix_pathnames = (lp_posix_pathnames() ||
+				(ucf_flags & UCF_POSIX_PATHNAMES));
 	bool allow_wcard_last_component =
 	    (ucf_flags & UCF_ALWAYS_ALLOW_WCARD_LCOMP);
 	bool save_last_component = ucf_flags & UCF_SAVE_LCOMP;
@@ -348,9 +349,6 @@ NTSTATUS unix_convert(TALLOC_CTX *ctx,
 		}
 	}
 
-	posix_pathnames = (lp_posix_pathnames() ||
-				(ucf_flags & UCF_POSIX_PATHNAMES));
-
 	/*
 	 * Strip off the stream, and add it back when we're done with the
 	 * base_name.
-- 
2.6.0.rc2.230.g3dd15c0


From 8fc428fb4fc04c82d42fa3b2dd2cb6341e836848 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Fri, 11 Dec 2015 14:36:33 -0800
Subject: [PATCH 2/9] s3: smbd: Moving lp_posix_pathnames() out of the
 lower-level code.

Prepare to remove lp_posix_pathnames() out of ms_has_wild().
Check before calls to ms_has_wild().

Fix determine_path_error().

Signed-off-by: Jeremy Allison <jra at samba.org>
---
 source3/smbd/filename.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/source3/smbd/filename.c b/source3/smbd/filename.c
index 4b40df3..826162b 100644
--- a/source3/smbd/filename.c
+++ b/source3/smbd/filename.c
@@ -55,9 +55,11 @@ static bool mangled_equal(const char *name1,
 ****************************************************************************/
 
 static NTSTATUS determine_path_error(const char *name,
-			bool allow_wcard_last_component)
+			bool allow_wcard_last_component,
+			bool posix_pathnames)
 {
 	const char *p;
+	bool name_has_wild = false;
 
 	if (!allow_wcard_last_component) {
 		/* Error code within a pathname. */
@@ -74,7 +76,11 @@ static NTSTATUS determine_path_error(const char *name,
 
 	p = strchr(name, '/');
 
-	if (!p && (ms_has_wild(name) || ISDOT(name))) {
+	if (!posix_pathnames) {
+		name_has_wild = ms_has_wild(name);
+	}
+
+	if (!p && (name_has_wild || ISDOT(name))) {
 		/* Error code at the end of a pathname. */
 		return NT_STATUS_OBJECT_NAME_INVALID;
 	} else {
@@ -300,7 +306,8 @@ NTSTATUS unix_convert(TALLOC_CTX *ctx,
 			status = NT_STATUS_OBJECT_NAME_INVALID;
 		} else {
 			status =determine_path_error(&orig_path[2],
-			    allow_wcard_last_component);
+			    allow_wcard_last_component,
+			    posix_pathnames);
 		}
 		goto err;
 	}
@@ -626,7 +633,8 @@ NTSTATUS unix_convert(TALLOC_CTX *ctx,
 				status = NT_STATUS_OBJECT_NAME_INVALID;
 			} else {
 				status = determine_path_error(end+1,
-						allow_wcard_last_component);
+						allow_wcard_last_component,
+						posix_pathnames);
 			}
 			goto fail;
 		}
-- 
2.6.0.rc2.230.g3dd15c0


From 18bbe7b1f6e0470008eb44bc10af84ad62f77a1e Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Fri, 11 Dec 2015 14:38:49 -0800
Subject: [PATCH 3/9] s3: smbd: Moving lp_posix_pathnames() out of the
 lower-level code.

Prepare to remove lp_posix_pathnames() out of ms_has_wild().
Check before calls to ms_has_wild().

Fixup check_parent_exists().

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

diff --git a/source3/smbd/filename.c b/source3/smbd/filename.c
index 826162b..39b351b 100644
--- a/source3/smbd/filename.c
+++ b/source3/smbd/filename.c
@@ -128,6 +128,7 @@ static NTSTATUS check_parent_exists(TALLOC_CTX *ctx,
 	const char *last_component = NULL;
 	NTSTATUS status;
 	int ret;
+	bool parent_fname_has_wild = false;
 
 	ZERO_STRUCT(parent_fname);
 	if (!parent_dirname(ctx, smb_fname->base_name,
@@ -136,6 +137,10 @@ static NTSTATUS check_parent_exists(TALLOC_CTX *ctx,
 		return NT_STATUS_NO_MEMORY;
 	}
 
+	if (!posix_pathnames) {
+		parent_fname_has_wild = ms_has_wild(parent_fname.base_name);
+	}
+
 	/*
 	 * If there was no parent component in
 	 * smb_fname->base_name of the parent name
@@ -143,7 +148,7 @@ static NTSTATUS check_parent_exists(TALLOC_CTX *ctx,
 	 * optimization.
 	 */
 	if ((smb_fname->base_name == last_component) ||
-			ms_has_wild(parent_fname.base_name)) {
+			parent_fname_has_wild) {
 		return NT_STATUS_OK;
 	}
 
-- 
2.6.0.rc2.230.g3dd15c0


From bfb372301ffdc737b8c6b3544d55b91a9f2c5069 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Fri, 11 Dec 2015 14:41:38 -0800
Subject: [PATCH 4/9] s3: smbd: Moving lp_posix_pathnames() out of the
 lower-level code.

Prepare to remove lp_posix_pathnames() out of ms_has_wild().
Check before calls to ms_has_wild().

Fixup unix_convert().

Signed-off-by: Jeremy Allison <jra at samba.org>
---
 source3/smbd/filename.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/source3/smbd/filename.c b/source3/smbd/filename.c
index 39b351b..1174b59 100644
--- a/source3/smbd/filename.c
+++ b/source3/smbd/filename.c
@@ -448,11 +448,14 @@ NTSTATUS unix_convert(TALLOC_CTX *ctx,
 	 * is true.
 	 */
 
-	name_has_wildcard = ms_has_wild(smb_fname->base_name);
-	if (name_has_wildcard && !allow_wcard_last_component) {
-		/* Wildcard not valid anywhere. */
-		status = NT_STATUS_OBJECT_NAME_INVALID;
-		goto fail;
+	if (!posix_pathnames) {
+		/* POSIX pathnames have no wildcards. */
+		name_has_wildcard = ms_has_wild(smb_fname->base_name);
+		if (name_has_wildcard && !allow_wcard_last_component) {
+			/* Wildcard not valid anywhere. */
+			status = NT_STATUS_OBJECT_NAME_INVALID;
+			goto fail;
+		}
 	}
 
 	DEBUG(5,("unix_convert begin: name = %s, dirpath = %s, start = %s\n",
@@ -647,7 +650,9 @@ NTSTATUS unix_convert(TALLOC_CTX *ctx,
 		/* The name cannot have a wildcard if it's not
 		   the last component. */
 
-		name_has_wildcard = ms_has_wild(start);
+		if (!posix_pathnames) {
+			name_has_wildcard = ms_has_wild(start);
+		}
 
 		/* Wildcards never valid within a pathname. */
 		if (name_has_wildcard && end) {
-- 
2.6.0.rc2.230.g3dd15c0


From 3432a70545f93bcafe6c3af956176b29245eff35 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Fri, 11 Dec 2015 14:45:37 -0800
Subject: [PATCH 5/9] s3: smbd: Moving lp_posix_pathnames() out of the
 lower-level code.

Prepare to remove lp_posix_pathnames() out of ms_has_wild().
Check before calls to ms_has_wild().

Fixup reply_ntrename().

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

diff --git a/source3/smbd/nttrans.c b/source3/smbd/nttrans.c
index 19c7153..098d88b 100644
--- a/source3/smbd/nttrans.c
+++ b/source3/smbd/nttrans.c
@@ -1548,7 +1548,7 @@ void reply_ntrename(struct smb_request *req)
 		goto out;
 	}
 
-	if (ms_has_wild(oldname)) {
+	if (!lp_posix_pathnames() && ms_has_wild(oldname)) {
 		reply_nterror(req, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
 		goto out;
 	}
-- 
2.6.0.rc2.230.g3dd15c0


From c9eae9eb35870fc8c5e0621efdf1f71c09a043f0 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Fri, 11 Dec 2015 14:49:44 -0800
Subject: [PATCH 6/9] s3: smbd: Moving lp_posix_pathnames() out of the
 lower-level code.

Prepare to remove lp_posix_pathnames() out of ms_has_wild().
Check before calls to ms_has_wild().

Fix open_file().

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

diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index 9cd415b..796544e 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -809,6 +809,7 @@ static NTSTATUS open_file(files_struct *fsp,
 			wild = smb_fname->base_name;
 		}
 		if ((local_flags & O_CREAT) && !file_existed &&
+		    !(fsp->posix_flags & FSP_POSIX_FLAGS_OPEN) &&
 		    ms_has_wild(wild))  {
 			return NT_STATUS_OBJECT_NAME_INVALID;
 		}
-- 
2.6.0.rc2.230.g3dd15c0


From e716904cf9a1620345cc22a3a1c68d5ebd4f2646 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Fri, 11 Dec 2015 14:51:58 -0800
Subject: [PATCH 7/9] s3: smbd: Moving lp_posix_pathnames() out of the
 lower-level code.

Prepare to remove lp_posix_pathnames() out of ms_has_wild().
Check before calls to ms_has_wild().

Fixup reply_search().

Don't think any client makes this call with POSIX extensions
on, but this keeps the same old behavior.

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

diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index 3fad39b..9234978 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -1749,7 +1749,9 @@ void reply_search(struct smb_request *req)
 		 * For a 'continue' search we have no string. So
 		 * check from the initial saved string.
 		 */
-		mask_contains_wcard = ms_has_wild(mask);
+		if (!lp_posix_pathnames()) {
+			mask_contains_wcard = ms_has_wild(mask);
+		}
 		dirtype = dptr_attr(sconn, dptr_num);
 	}
 
-- 
2.6.0.rc2.230.g3dd15c0


From 35028e99f70888b27abf2f570bf6daa0ecdc046e Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Fri, 11 Dec 2015 14:53:30 -0800
Subject: [PATCH 8/9] s3: smbd: Moving lp_posix_pathnames() out of the
 lower-level code.

Prepare to remove lp_posix_pathnames() out of ms_has_wild().
Check before calls to ms_has_wild().

Fix smbd_smb2_query_directory_send().

No SMB2 client uses unix extensions yet, but this is a placeholder
for when we move the POSIX pathnames bit into the SMB2 request
when moving to handle based code.

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

diff --git a/source3/smbd/smb2_query_directory.c b/source3/smbd/smb2_query_directory.c
index 81f2e17..73f2d63 100644
--- a/source3/smbd/smb2_query_directory.c
+++ b/source3/smbd/smb2_query_directory.c
@@ -325,7 +325,9 @@ static struct tevent_req *smbd_smb2_query_directory_send(TALLOC_CTX *mem_ctx,
 		dptr_CloseDir(fsp);
 	}
 
-	wcard_has_wild = ms_has_wild(in_file_name);
+	if (!lp_posix_pathnames()) {
+		wcard_has_wild = ms_has_wild(in_file_name);
+	}
 
 	/* Ensure we've canonicalized any search path if not a wildcard. */
 	if (!wcard_has_wild) {
-- 
2.6.0.rc2.230.g3dd15c0


From c29d907e98f37a9d5348b5bb461d39394ad81538 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Fri, 11 Dec 2015 14:55:10 -0800
Subject: [PATCH 9/9] s3: smbd: Moving lp_posix_pathnames() out of the
 lower-level code.

Remove lp_posix_pathnames() out of ms_has_wild().

NB. The usage of ms_has_wild() inside set_namearray()
should *never* have been looking at lp_posix_pathnames()
anyway, as this is a config option that needs to look
at wildcards. This was probably an old (but never
triggered) bug.

Signed-off-by: Jeremy Allison <jra at samba.org>
---
 source3/lib/util.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/source3/lib/util.c b/source3/lib/util.c
index 420fe91..1d04318 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -1611,11 +1611,6 @@ bool ms_has_wild(const char *s)
 {
 	char c;
 
-	if (lp_posix_pathnames()) {
-		/* With posix pathnames no characters are wild. */
-		return False;
-	}
-
 	while ((c = *s++)) {
 		switch (c) {
 		case '*':
-- 
2.6.0.rc2.230.g3dd15c0



More information about the samba-technical mailing list