svn commit: samba r20671 - in branches/SAMBA_3_0_24/source: printing rpc_server smbd

jra at samba.org jra at samba.org
Thu Jan 11 00:10:19 GMT 2007


Author: jra
Date: 2007-01-11 00:10:09 +0000 (Thu, 11 Jan 2007)
New Revision: 20671

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=20671

Log:
This version of the pathname code passes volkers
modified gentest to 1000 iterations.
Jeremy.

Modified:
   branches/SAMBA_3_0_24/source/printing/nt_printing.c
   branches/SAMBA_3_0_24/source/rpc_server/srv_srvsvc_nt.c
   branches/SAMBA_3_0_24/source/smbd/filename.c
   branches/SAMBA_3_0_24/source/smbd/msdfs.c
   branches/SAMBA_3_0_24/source/smbd/nttrans.c
   branches/SAMBA_3_0_24/source/smbd/reply.c
   branches/SAMBA_3_0_24/source/smbd/trans2.c


Changeset:
Modified: branches/SAMBA_3_0_24/source/printing/nt_printing.c
===================================================================
--- branches/SAMBA_3_0_24/source/printing/nt_printing.c	2007-01-10 22:31:42 UTC (rev 20670)
+++ branches/SAMBA_3_0_24/source/printing/nt_printing.c	2007-01-11 00:10:09 UTC (rev 20671)
@@ -662,7 +662,7 @@
 	unix_format(name);
 	unix_clean_name(name);
 	trim_string(name,"/","/");
-	unix_convert(name, conn, saved_last_component, pst);
+	unix_convert(conn, name, False, saved_last_component, pst);
 }
 
 /*******************************************************************

Modified: branches/SAMBA_3_0_24/source/rpc_server/srv_srvsvc_nt.c
===================================================================
--- branches/SAMBA_3_0_24/source/rpc_server/srv_srvsvc_nt.c	2007-01-10 22:31:42 UTC (rev 20670)
+++ branches/SAMBA_3_0_24/source/rpc_server/srv_srvsvc_nt.c	2007-01-11 00:10:09 UTC (rev 20671)
@@ -1825,7 +1825,7 @@
 	became_user = True;
 
 	unistr2_to_ascii(filename, &q_u->uni_file_name, sizeof(filename));
-	nt_status = unix_convert(filename, conn, NULL, &st);
+	nt_status = unix_convert(conn, filename, False, NULL, &st);
 	if (!NT_STATUS_IS_OK(nt_status)) {
 		DEBUG(3,("_srv_net_file_query_secdesc: bad pathname %s\n", filename));
 		r_u->status = WERR_ACCESS_DENIED;
@@ -1939,7 +1939,7 @@
 	became_user = True;
 
 	unistr2_to_ascii(filename, &q_u->uni_file_name, sizeof(filename));
-	nt_status = unix_convert(filename, conn, NULL, &st);
+	nt_status = unix_convert(conn, filename, False, NULL, &st);
 	if (!NT_STATUS_IS_OK(nt_status)) {
 		DEBUG(3,("_srv_net_file_set_secdesc: bad pathname %s\n", filename));
 		r_u->status = WERR_ACCESS_DENIED;

Modified: branches/SAMBA_3_0_24/source/smbd/filename.c
===================================================================
--- branches/SAMBA_3_0_24/source/smbd/filename.c	2007-01-10 22:31:42 UTC (rev 20670)
+++ branches/SAMBA_3_0_24/source/smbd/filename.c	2007-01-11 00:10:09 UTC (rev 20671)
@@ -76,13 +76,18 @@
 case in reply_mv (so far). If saved_last_component == 0 then nothing
 is returned there.
 
+If last_component_wcard is true then a MS wildcard was detected and
+should be allowed in the last component of the path only.
+
 On exit from unix_convert, if *pst was not null, then the file stat
 struct will be returned if the file exists and was found, if not this
 stat struct will be filled with zeros (and this can be detected by checking
 for nlinks = 0, which can never be true for any file).
 ****************************************************************************/
 
-NTSTATUS unix_convert(pstring name,connection_struct *conn,
+NTSTATUS unix_convert(connection_struct *conn,
+			pstring name,
+			BOOL allow_wcard_last_component,
 			char *saved_last_component, 
 			SMB_STRUCT_STAT *pst)
 {
@@ -255,23 +260,8 @@
 
 		if (ISDOT(start)) {
 			if (end) {
-				/* We're terminating here so we
-				 * can be a little slower and get
-				 * the error code right. Windows
-				 * treats the last part of the pathname
-				 * separately I think, so if the last
-				 * component is a wildcard then we treat
-				 * this ./ as "end of component" */
-
-				const char *p = strchr(end+1, '/');
-
-				if (!p && ms_has_wild(end+1)) {
-					/* Error code at the end of a pathname. */
-					return NT_STATUS_OBJECT_NAME_INVALID;
-				} else {
-					/* Error code within a pathname. */
-					return NT_STATUS_OBJECT_PATH_NOT_FOUND;
-				}
+				/* Error code within a pathname. */
+				return NT_STATUS_OBJECT_PATH_NOT_FOUND;
 			} else {
 				/* Error code at the end of a pathname. */
 				return NT_STATUS_OBJECT_NAME_INVALID;
@@ -283,6 +273,12 @@
 
 		name_has_wildcard = ms_has_wild(start);
 
+		/* Wildcard not valid anywhere. */
+		if (name_has_wildcard && !allow_wcard_last_component) {
+			return NT_STATUS_OBJECT_NAME_INVALID;
+		}
+
+		/* Wildcards never valid within a pathname. */
 		if (name_has_wildcard && end) {
 			return NT_STATUS_OBJECT_NAME_INVALID;
 		}

Modified: branches/SAMBA_3_0_24/source/smbd/msdfs.c
===================================================================
--- branches/SAMBA_3_0_24/source/smbd/msdfs.c	2007-01-10 22:31:42 UTC (rev 20670)
+++ branches/SAMBA_3_0_24/source/smbd/msdfs.c	2007-01-11 00:10:09 UTC (rev 20671)
@@ -349,7 +349,7 @@
 
 	DEBUG(10,("resolve_dfs_path: Conn path = %s req_path = %s\n", conn->connectpath, dp->reqpath));
 
-	status = unix_convert(dp->reqpath,conn,NULL,&sbuf);
+	status = unix_convert(conn, dp->reqpath, False, NULL, &sbuf);
 	/* Should we terminate on status != NT_STATUS_OK ???? */
 
 	/* JRA... should we strlower the last component here.... ? */

Modified: branches/SAMBA_3_0_24/source/smbd/nttrans.c
===================================================================
--- branches/SAMBA_3_0_24/source/smbd/nttrans.c	2007-01-10 22:31:42 UTC (rev 20670)
+++ branches/SAMBA_3_0_24/source/smbd/nttrans.c	2007-01-11 00:10:09 UTC (rev 20671)
@@ -627,7 +627,7 @@
 		
 	set_posix_case_semantics(conn, file_attributes);
 		
-	status = unix_convert(fname,conn,NULL,&sbuf);
+	status = unix_convert(conn, fname, False, NULL, &sbuf);
 	if (!NT_STATUS_IS_OK(status)) {
 		restore_case_semantics(conn, file_attributes);
 		END_PROFILE(SMBntcreateX);
@@ -1254,7 +1254,7 @@
     
 	RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
 
-	status = unix_convert(fname,conn,NULL,&sbuf);
+	status = unix_convert(conn, fname, False, NULL, &sbuf);
 	if (!NT_STATUS_IS_OK(status)) {
 		restore_case_semantics(conn, file_attributes);
 		return ERROR_NT(status);
@@ -1572,15 +1572,10 @@
 	ZERO_STRUCT(sbuf1);
 	ZERO_STRUCT(sbuf2);
 
-	/* No wildcards. */
-	if (ms_has_wild(newname) || ms_has_wild(oldname)) {
-		return NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
-	}
-
 	if (!CAN_WRITE(conn))
 		return NT_STATUS_MEDIA_WRITE_PROTECTED;
 
-	status = unix_convert(oldname,conn,last_component_oldname,&sbuf1);
+	status = unix_convert(conn, oldname, False, last_component_oldname, &sbuf1);
 	if (!NT_STATUS_IS_OK(status)) {
 		return status;
 	}
@@ -1599,7 +1594,7 @@
 		return NT_STATUS_NO_SUCH_FILE;
 	}
 
-	status = unix_convert(newname,conn,last_component_newname,&sbuf2);
+	status = unix_convert(conn, newname, False, last_component_newname, &sbuf2);
 	if (!NT_STATUS_IS_OK(status)) {
 		return status;
 	}

Modified: branches/SAMBA_3_0_24/source/smbd/reply.c
===================================================================
--- branches/SAMBA_3_0_24/source/smbd/reply.c	2007-01-10 22:31:42 UTC (rev 20670)
+++ branches/SAMBA_3_0_24/source/smbd/reply.c	2007-01-11 00:10:09 UTC (rev 20671)
@@ -44,15 +44,18 @@
  set.
 ****************************************************************************/
 
-NTSTATUS check_path_syntax_internal(pstring destname, const pstring srcname, BOOL windows_path, BOOL *p_contains_wcard)
+NTSTATUS check_path_syntax_internal(pstring destname,
+					const pstring srcname,
+					BOOL windows_path, BOOL
+					*p_last_component_contains_wcard)
 {
 	char *d = destname;
 	const char *s = srcname;
 	NTSTATUS ret = NT_STATUS_OK;
 	BOOL start_of_name_component = True;
 
-	if (p_contains_wcard) {
-		*p_contains_wcard = False;
+	if (p_last_component_contains_wcard) {
+		*p_last_component_contains_wcard = False;
 	}
 
 	while (*s) {
@@ -70,6 +73,10 @@
 			}
 
 			start_of_name_component = True;
+			/* New component. */
+			if (p_last_component_contains_wcard) {
+				*p_last_component_contains_wcard = False;
+			}
 			continue;
 		}
 
@@ -125,10 +132,8 @@
 					case '<':
 					case '>':
 					case '"':
-						if (p_contains_wcard) {
-							*p_contains_wcard = True;
-						} else {
-							return NT_STATUS_OBJECT_NAME_INVALID;
+						if (p_last_component_contains_wcard) {
+							*p_last_component_contains_wcard = True;
 						}
 						break;
 					default:
@@ -181,7 +186,8 @@
 
 /****************************************************************************
  Ensure we check the path in *exactly* the same way as W2K for regular pathnames.
- Wildcards allowed.
+ Wildcards allowed - p_contains_wcard returns true if the last component contained
+ a wildcard.
 ****************************************************************************/
 
 NTSTATUS check_path_syntax_wcard(pstring destname, const pstring srcname, BOOL *p_contains_wcard)
@@ -623,7 +629,7 @@
 
 	RESOLVE_DFSPATH(name, conn, inbuf, outbuf);
 
-	status = unix_convert(name,conn,NULL,&sbuf);
+	status = unix_convert(conn, name, False, NULL, &sbuf);
 	if (!NT_STATUS_IS_OK(status)) {
 		END_PROFILE(SMBchkpth);
 		return ERROR_NT(status);
@@ -703,7 +709,7 @@
 		mtime = 0;
 		ok = True;
 	} else {
-		status = unix_convert(fname,conn,NULL,&sbuf);
+		status = unix_convert(conn, fname, False, NULL,&sbuf);
 		if (!NT_STATUS_IS_OK(status)) {
 			END_PROFILE(SMBgetatr);
 			return ERROR_NT(status);
@@ -773,7 +779,7 @@
 
 	RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
   
-	status = unix_convert(fname,conn,NULL,&sbuf);
+	status = unix_convert(conn, fname, False, NULL, &sbuf);
 	if (!NT_STATUS_IS_OK(status)) {
 		END_PROFILE(SMBsetatr);
 		return ERROR_NT(status);
@@ -939,7 +945,7 @@
 
 		pstrcpy(directory,path);
 		pstrcpy(dir2,path);
-		nt_status = unix_convert(directory,conn,NULL,&sbuf);
+		nt_status = unix_convert(conn, directory, mask_contains_wcard, NULL, &sbuf);
 		if (!NT_STATUS_IS_OK(nt_status)) {
 			END_PROFILE(SMBsearch);
 			return ERROR_NT(nt_status);
@@ -1178,7 +1184,7 @@
 
 	RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
 
-	status = unix_convert(fname,conn,NULL,&sbuf);
+	status = unix_convert(conn, fname, False, NULL, &sbuf);
 	if (!NT_STATUS_IS_OK(status)) {
 		END_PROFILE(SMBopen);
 		return ERROR_NT(status);
@@ -1296,7 +1302,7 @@
 
 	RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
 
-	status = unix_convert(fname,conn,NULL,&sbuf);
+	status = unix_convert(conn, fname, False, NULL, &sbuf);
 	if (!NT_STATUS_IS_OK(status)) {
 		END_PROFILE(SMBopenX);
 		return ERROR_NT(status);
@@ -1468,7 +1474,7 @@
 
 	RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
 
-	status = unix_convert(fname,conn,NULL,&sbuf);
+	status = unix_convert(conn, fname, False, NULL, &sbuf);
 	if (!NT_STATUS_IS_OK(status)) {
 		END_PROFILE(SMBcreate);
 		return ERROR_NT(status);
@@ -1558,7 +1564,7 @@
 
 	RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
 
-	status = unix_convert(fname,conn,NULL,&sbuf);
+	status = unix_convert(conn, fname, False, NULL, &sbuf);
 	if (!NT_STATUS_IS_OK(status)) {
 		END_PROFILE(SMBctemp);
 		return ERROR_NT(status);
@@ -1694,7 +1700,7 @@
 
 	fattr = dos_mode(conn,fname,&sbuf);
 
-	if (dirtype == FILE_ATTRIBUTE_NORMAL) {
+	if (dirtype & FILE_ATTRIBUTE_NORMAL) {
 		dirtype = aDIR|aARCH|aRONLY;
 	}
 
@@ -1797,7 +1803,7 @@
 	
 	*directory = *mask = 0;
 	
-	status = unix_convert(name,conn,NULL,&sbuf);
+	status = unix_convert(conn, name, has_wild, NULL, &sbuf);
 	if (!NT_STATUS_IS_OK(status)) {
 		return status;
 	}
@@ -1841,7 +1847,7 @@
 		struct smb_Dir *dir_hnd = NULL;
 		const char *dname;
 		
-		if (((dirtype & SAMBA_ATTRIBUTES_MASK) == aDIR) && ms_has_wild(mask)) {
+		if ((dirtype & SAMBA_ATTRIBUTES_MASK) == aDIR) {
 			return NT_STATUS_OBJECT_NAME_INVALID;
 		}
 
@@ -3568,7 +3574,7 @@
 
 	RESOLVE_DFSPATH(directory, conn, inbuf, outbuf);
 
-	status = unix_convert(directory,conn,NULL,&sbuf);
+	status = unix_convert(conn, directory, False, NULL, &sbuf);
 	if (!NT_STATUS_IS_OK(status)) {
 		END_PROFILE(SMBmkdir);
 		return ERROR_NT(status);
@@ -3770,7 +3776,7 @@
 
 	RESOLVE_DFSPATH(directory, conn, inbuf, outbuf)
 
-	status = unix_convert(directory,conn, NULL,&sbuf);
+	status = unix_convert(conn, directory, False, NULL, &sbuf);
 	if (!NT_STATUS_IS_OK(status)) {
 		END_PROFILE(SMBrmdir);
 		return ERROR_NT(status);
@@ -3958,7 +3964,7 @@
 
 	ZERO_STRUCT(sbuf);
 
-	status = unix_convert(newname,conn,newname_last_component,&sbuf);
+	status = unix_convert(conn, newname, False, newname_last_component, &sbuf);
 	if (!NT_STATUS_IS_OK(status)) {
 		return status;
 	}
@@ -4082,12 +4088,12 @@
 	ZERO_STRUCT(sbuf1);
 	ZERO_STRUCT(sbuf2);
 
-	status = unix_convert(name,conn,last_component_src,&sbuf1);
+	status = unix_convert(conn, name, has_wild, last_component_src, &sbuf1);
 	if (!NT_STATUS_IS_OK(status)) {
 		return status;
 	}
 
-	status = unix_convert(newname,conn,last_component_dest,&sbuf2);
+	status = unix_convert(conn, newname, True, last_component_dest, &sbuf2);
 	if (!NT_STATUS_IS_OK(status)) {
 		return status;
 	}
@@ -4595,13 +4601,13 @@
 	RESOLVE_DFSPATH_WCARD(name, conn, inbuf, outbuf);
 	RESOLVE_DFSPATH_WCARD(newname, conn, inbuf, outbuf);
 
-	status = unix_convert(name,conn,NULL,&sbuf1);
+	status = unix_convert(conn, name, path_contains_wcard1, NULL, &sbuf1);
 	if (!NT_STATUS_IS_OK(status)) {
 		END_PROFILE(SMBcopy);
 		return ERROR_NT(status);
 	}
 
-	status = unix_convert(newname,conn,NULL,&sbuf2);
+	status = unix_convert(conn, newname, path_contains_wcard2, NULL, &sbuf2);
 	if (!NT_STATUS_IS_OK(status)) {
 		END_PROFILE(SMBcopy);
 		return ERROR_NT(status);

Modified: branches/SAMBA_3_0_24/source/smbd/trans2.c
===================================================================
--- branches/SAMBA_3_0_24/source/smbd/trans2.c	2007-01-10 22:31:42 UTC (rev 20670)
+++ branches/SAMBA_3_0_24/source/smbd/trans2.c	2007-01-11 00:10:09 UTC (rev 20671)
@@ -800,7 +800,7 @@
 
 	/* XXXX we need to handle passed times, sattr and flags */
 
-	status = unix_convert(fname,conn,NULL,&sbuf);
+	status = unix_convert(conn, fname, False, NULL, &sbuf);
 	if (!NT_STATUS_IS_OK(status)) {
 		return ERROR_NT(status);
 	}
@@ -1718,7 +1718,7 @@
 
 	RESOLVE_DFSPATH_WCARD(directory, conn, inbuf, outbuf);
 
-	ntstatus = unix_convert(directory,conn,NULL,&sbuf);
+	ntstatus = unix_convert(conn, directory, mask_contains_wcard, NULL, &sbuf);
 	if (!NT_STATUS_IS_OK(ntstatus)) {
 		return ERROR_NT(ntstatus);
 	}
@@ -2930,7 +2930,7 @@
 
 		RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
 
-		status = unix_convert(fname,conn,NULL,&sbuf);
+		status = unix_convert(conn, fname, False, NULL, &sbuf);
 		if (!NT_STATUS_IS_OK(status)) {
 			return ERROR_NT(status);
 		}
@@ -3676,16 +3676,11 @@
 	ZERO_STRUCT(sbuf1);
 	ZERO_STRUCT(sbuf2);
 
-	status = unix_convert(oldname,conn,last_component_oldname,&sbuf1);
+	status = unix_convert(conn, oldname, False, last_component_oldname, &sbuf1);
 	if (!NT_STATUS_IS_OK(status)) {
 		return status;
 	}
 
-	/* No wildcards. */
-	if (ms_has_wild(oldname)) {
-		return NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
-	}
-
 	/* source must already exist. */
 	if (!VALID_STAT(sbuf1)) {
 		return NT_STATUS_OBJECT_NAME_NOT_FOUND;
@@ -3695,16 +3690,11 @@
 		return NT_STATUS_ACCESS_DENIED;
 	}
 
-	status = unix_convert(newname,conn,last_component_newname,&sbuf2);
+	status = unix_convert(conn, newname, False, last_component_newname, &sbuf2);
 	if (!NT_STATUS_IS_OK(status)) {
 		return status;
 	}
 
-	/* No wildcards. */
-	if (ms_has_wild(newname)) {
-		return NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
-	}
-
 	/* Disallow if newname already exists. */
 	if (VALID_STAT(sbuf2)) {
 		return NT_STATUS_OBJECT_NAME_COLLISION;
@@ -3822,7 +3812,7 @@
 		if (!NT_STATUS_IS_OK(status)) {
 			return ERROR_NT(status);
 		}
-		status = unix_convert(fname,conn,NULL,&sbuf);
+		status = unix_convert(conn, fname, False, NULL, &sbuf);
 		if (!NT_STATUS_IS_OK(status)) {
 			return ERROR_NT(status);
 		}
@@ -4791,7 +4781,7 @@
 
 	DEBUG(3,("call_trans2mkdir : name = %s\n", directory));
 
-	status = unix_convert(directory,conn,NULL,&sbuf);
+	status = unix_convert(conn, directory, False, NULL, &sbuf);
 	if (!NT_STATUS_IS_OK(status)) {
 		return ERROR_NT(status);
 	}



More information about the samba-cvs mailing list