deleteprinterdriverex does not delete files

Jeremy Allison jra at samba.org
Sun May 2 19:08:07 GMT 2004


On Mon, Apr 26, 2004 at 03:02:28PM +0200, Martin Zielinski wrote:
> Hello list,
> since upgrading from 3.0.2a to 3.0.3rc1 the deleteprinterdriverex call
> does no longer delete the driver files on my system.
> 
> It seems to me, that the unix_convert() function in filename.c is responsible 
> for it.
> I'm not aware of the changes from  Alexander Bokovoy, but after re-adding the 
> unix_format(name)-  unix_clean_name(name)- and trim_char(name,'/','/')- calls 
> into the unix_convert - function, it's working again.
> 
> I added this debug output to smbd/reply.c can_delete() just before
> 	if (SMB_VFS_LSTAT(conn,fname,&sbuf) != 0) { :
> 
> 	DEBUG(0,("LSTAT: \"%s\"\n", fname));
> Output:
> 	./\W32X86\3\PSCRIPT5.DLL

Martin,

Attached is a proposed fix for this. Can you test it out
and let me know if this fixes the problem, if so I'll
commit it to svn.

Cheers,

	Jeremy.
-------------- next part --------------
Index: printing/nt_printing.c
===================================================================
--- printing/nt_printing.c	(revision 451)
+++ printing/nt_printing.c	(working copy)
@@ -368,6 +368,19 @@
 }
 
 /*******************************************************************
+ Function to allow filename parsing "the old way".
+********************************************************************/
+
+static BOOL driver_unix_convert(char *name,connection_struct *conn,
+		char *saved_last_component, BOOL *bad_path, SMB_STRUCT_STAT *pst)
+{
+	unix_format(name);
+	unix_clean_name(name);
+	trim_string(name,"/","/");
+	return unix_convert(name, conn, saved_last_component, bad_path, pst);
+}
+
+/*******************************************************************
  tdb traversal function for counting printers.
 ********************************************************************/
 
@@ -987,7 +1000,7 @@
 	/* Get file version info (if available) for previous file (if it exists) */
 	pstrcpy(filepath, old_file);
 
-	unix_convert(filepath,conn,NULL,&bad_path,&stat_buf);
+	driver_unix_convert(filepath,conn,NULL,&bad_path,&stat_buf);
 
 	fsp = open_file_shared(conn, filepath, &stat_buf,
 						   SET_OPEN_MODE(DOS_OPEN_RDONLY),
@@ -1016,7 +1029,7 @@
 
 	/* Get file version info (if available) for new file */
 	pstrcpy(filepath, new_file);
-	unix_convert(filepath,conn,NULL,&bad_path,&stat_buf);
+	driver_unix_convert(filepath,conn,NULL,&bad_path,&stat_buf);
 
 	fsp = open_file_shared(conn, filepath, &stat_buf,
 						   SET_OPEN_MODE(DOS_OPEN_RDONLY),
@@ -1132,7 +1145,7 @@
 	 * deriver the cversion. */
 	slprintf(driverpath, sizeof(driverpath)-1, "%s/%s", architecture, driverpath_in);
 
-	unix_convert(driverpath,conn,NULL,&bad_path,&st);
+	driver_unix_convert(driverpath,conn,NULL,&bad_path,&st);
 
 	fsp = open_file_shared(conn, driverpath, &st,
 						   SET_OPEN_MODE(DOS_OPEN_RDONLY),
@@ -1403,6 +1416,8 @@
 	pstring inbuf;
 	pstring outbuf;
 	fstring res_type;
+	BOOL bad_path;
+	SMB_STRUCT_STAT st;
 	int ver = 0;
 	int i;
 
@@ -1454,6 +1469,7 @@
 	 */
 	DEBUG(5,("Creating first directory\n"));
 	slprintf(new_dir, sizeof(new_dir)-1, "%s/%d", architecture, driver->cversion);
+	driver_unix_convert(new_dir, conn, NULL, &bad_path, &st);
 	mkdir_internal(conn, new_dir);
 
 	/* For each driver file, archi\filexxx.yyy, if there is a duplicate file
@@ -1480,6 +1496,7 @@
 		slprintf(old_name, sizeof(old_name)-1, "%s/%s", new_dir, driver->driverpath);	
 		if (ver != -1 && (ver=file_version_is_newer(conn, new_name, old_name)) > 0) {
 			NTSTATUS status;
+			driver_unix_convert(new_name, conn, NULL, &bad_path, &st);
 			status = rename_internals(conn, new_name, old_name, 0, True);
 			if (!NT_STATUS_IS_OK(status)) {
 				DEBUG(0,("move_driver_to_download_area: Unable to rename [%s] to [%s]\n",
@@ -1488,9 +1505,10 @@
 				unlink_internals(conn, 0, new_name);
 				ver = -1;
 			}
+		} else {
+			driver_unix_convert(new_name, conn, NULL, &bad_path, &st);
+			unlink_internals(conn, 0, new_name);
 		}
-		else
-			unlink_internals(conn, 0, new_name);
 	}
 
 	if (driver->datafile && strlen(driver->datafile)) {
@@ -1499,6 +1517,7 @@
 			slprintf(old_name, sizeof(old_name)-1, "%s/%s", new_dir, driver->datafile);	
 			if (ver != -1 && (ver=file_version_is_newer(conn, new_name, old_name)) > 0) {
 				NTSTATUS status;
+				driver_unix_convert(new_name, conn, NULL, &bad_path, &st);
 				status = rename_internals(conn, new_name, old_name, 0, True);
 				if (!NT_STATUS_IS_OK(status)) {
 					DEBUG(0,("move_driver_to_download_area: Unable to rename [%s] to [%s]\n",
@@ -1507,9 +1526,10 @@
 					unlink_internals(conn, 0, new_name);
 					ver = -1;
 				}
+			} else {
+				driver_unix_convert(new_name, conn, NULL, &bad_path, &st);
+				unlink_internals(conn, 0, new_name);
 			}
-			else
-				unlink_internals(conn, 0, new_name);
 		}
 	}
 
@@ -1520,6 +1540,7 @@
 			slprintf(old_name, sizeof(old_name)-1, "%s/%s", new_dir, driver->configfile);	
 			if (ver != -1 && (ver=file_version_is_newer(conn, new_name, old_name)) > 0) {
 				NTSTATUS status;
+				driver_unix_convert(new_name, conn, NULL, &bad_path, &st);
 				status = rename_internals(conn, new_name, old_name, 0, True);
 				if (!NT_STATUS_IS_OK(status)) {
 					DEBUG(0,("move_driver_to_download_area: Unable to rename [%s] to [%s]\n",
@@ -1528,9 +1549,10 @@
 					unlink_internals(conn, 0, new_name);
 					ver = -1;
 				}
+			} else {
+				driver_unix_convert(new_name, conn, NULL, &bad_path, &st);
+				unlink_internals(conn, 0, new_name);
 			}
-			else
-				unlink_internals(conn, 0, new_name);
 		}
 	}
 
@@ -1542,6 +1564,7 @@
 			slprintf(old_name, sizeof(old_name)-1, "%s/%s", new_dir, driver->helpfile);	
 			if (ver != -1 && (ver=file_version_is_newer(conn, new_name, old_name)) > 0) {
 				NTSTATUS status;
+				driver_unix_convert(new_name, conn, NULL, &bad_path, &st);
 				status = rename_internals(conn, new_name, old_name, 0, True);
 				if (!NT_STATUS_IS_OK(status)) {
 					DEBUG(0,("move_driver_to_download_area: Unable to rename [%s] to [%s]\n",
@@ -1550,9 +1573,10 @@
 					unlink_internals(conn, 0, new_name);
 					ver = -1;
 				}
+			} else {
+				driver_unix_convert(new_name, conn, NULL, &bad_path, &st);
+				unlink_internals(conn, 0, new_name);
 			}
-			else
-				unlink_internals(conn, 0, new_name);
 		}
 	}
 
@@ -1573,6 +1597,7 @@
 				slprintf(old_name, sizeof(old_name)-1, "%s/%s", new_dir, driver->dependentfiles[i]);	
 				if (ver != -1 && (ver=file_version_is_newer(conn, new_name, old_name)) > 0) {
 					NTSTATUS status;
+					driver_unix_convert(new_name, conn, NULL, &bad_path, &st);
 					status = rename_internals(conn, new_name, old_name, 0, True);
 					if (!NT_STATUS_IS_OK(status)) {
 						DEBUG(0,("move_driver_to_download_area: Unable to rename [%s] to [%s]\n",
@@ -1581,9 +1606,10 @@
 						unlink_internals(conn, 0, new_name);
 						ver = -1;
 					}
+				} else {
+					driver_unix_convert(new_name, conn, NULL, &bad_path, &st);
+					unlink_internals(conn, 0, new_name);
 				}
-				else
-					unlink_internals(conn, 0, new_name);
 			}
 		NextDriver: ;
 		}
@@ -4410,6 +4436,8 @@
 	DATA_BLOB null_pw;
 	NTSTATUS nt_status;
 	fstring res_type;
+	BOOL bad_path;
+	SMB_STRUCT_STAT  st;
 
 	if ( !info_3 )
 		return False;
@@ -4445,6 +4473,7 @@
 	
 	if ( *info_3->driverpath ) {
 		if ( (s = strchr( &info_3->driverpath[1], '\\' )) != NULL ) {
+			driver_unix_convert(s, conn, NULL, &bad_path, &st);
 			DEBUG(10,("deleting driverfile [%s]\n", s));
 			unlink_internals(conn, 0, s);
 		}
@@ -4452,6 +4481,7 @@
 		
 	if ( *info_3->configfile ) {
 		if ( (s = strchr( &info_3->configfile[1], '\\' )) != NULL ) {
+			driver_unix_convert(s, conn, NULL, &bad_path, &st);
 			DEBUG(10,("deleting configfile [%s]\n", s));
 			unlink_internals(conn, 0, s);
 		}
@@ -4459,6 +4489,7 @@
 	
 	if ( *info_3->datafile ) {
 		if ( (s = strchr( &info_3->datafile[1], '\\' )) != NULL ) {
+			driver_unix_convert(s, conn, NULL, &bad_path, &st);
 			DEBUG(10,("deleting datafile [%s]\n", s));
 			unlink_internals(conn, 0, s);
 		}
@@ -4466,6 +4497,7 @@
 	
 	if ( *info_3->helpfile ) {
 		if ( (s = strchr( &info_3->helpfile[1], '\\' )) != NULL ) {
+			driver_unix_convert(s, conn, NULL, &bad_path, &st);
 			DEBUG(10,("deleting helpfile [%s]\n", s));
 			unlink_internals(conn, 0, s);
 		}
@@ -4480,6 +4512,7 @@
 			/* bypass the "\print$" portion of the path */
 			
 			if ( (file = strchr( info_3->dependentfiles[i]+1, '\\' )) != NULL ) {
+				driver_unix_convert(s, conn, NULL, &bad_path, &st);
 				DEBUG(10,("deleting dependent file [%s]\n", file));
 				unlink_internals(conn, 0, file );
 			}
@@ -4987,4 +5020,3 @@
 
 	return ok;
 }
-


More information about the samba-technical mailing list