s3-spoolss: prefix print$ path on driver file deletion
authorDavid Disseldorp <ddiss@samba.org>
Wed, 11 Jan 2012 18:50:36 +0000 (19:50 +0100)
committerDavid Disseldorp <ddiss@samba.org>
Fri, 20 Jan 2012 16:43:34 +0000 (17:43 +0100)
Driver file paths stored in the registry do not include the server path
prefix. delete_driver_files() incorrectly assumes such a prefix.

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

Signed-off-by: Andreas Schneider <asn@samba.org>
source3/printing/nt_printing.c

index a8fde257c4ca7d539befe09c7a7b8940af347f0b..70346b24edc5a528a1ba6cb864326becb1bdbc8e 100644 (file)
@@ -1474,20 +1474,30 @@ bool printer_driver_files_in_use(TALLOC_CTX *mem_ctx,
 }
 
 static NTSTATUS driver_unlink_internals(connection_struct *conn,
-                                       const char *name)
+                                       const char *short_arch,
+                                       int vers,
+                                       const char *fname)
 {
+       TALLOC_CTX *tmp_ctx = talloc_new(conn);
        struct smb_filename *smb_fname = NULL;
-       NTSTATUS status;
+       char *print_dlr_path;
+       NTSTATUS status = NT_STATUS_NO_MEMORY;
+
+       print_dlr_path = talloc_asprintf(tmp_ctx, "%s/%d/%s",
+                                        short_arch, vers, fname);
+       if (print_dlr_path == NULL) {
+               goto err_out;
+       }
 
-       status = create_synthetic_smb_fname(talloc_tos(), name, NULL, NULL,
-           &smb_fname);
+       status = create_synthetic_smb_fname(tmp_ctx, print_dlr_path,
+                                           NULL, NULL, &smb_fname);
        if (!NT_STATUS_IS_OK(status)) {
-               return status;
+               goto err_out;
        }
 
        status = unlink_internals(conn, NULL, 0, smb_fname, false);
-
-       TALLOC_FREE(smb_fname);
+err_out:
+       talloc_free(tmp_ctx);
        return status;
 }
 
@@ -1500,9 +1510,7 @@ static NTSTATUS driver_unlink_internals(connection_struct *conn,
 bool delete_driver_files(const struct auth_session_info *session_info,
                         const struct spoolss_DriverInfo8 *r)
 {
-       int i = 0;
-       char *s;
-       const char *file;
+       const char *short_arch;
        connection_struct *conn;
        NTSTATUS nt_status;
        char *oldcwd;
@@ -1554,55 +1562,40 @@ bool delete_driver_files(const struct auth_session_info *session_info,
                goto err_out;
        }
 
-       /* now delete the files; must strip the '\print$' string from
-          fron of path                                                */
+       short_arch = get_short_archi(r->architecture);
+       if (short_arch == NULL) {
+               DEBUG(0, ("bad architecture %s\n", r->architecture));
+               ret = false;
+               goto err_out;
+       }
+
+       /* now delete the files */
 
        if (r->driver_path && r->driver_path[0]) {
-               if ((s = strchr(&r->driver_path[1], '\\')) != NULL) {
-                       file = s;
-                       DEBUG(10,("deleting driverfile [%s]\n", s));
-                       driver_unlink_internals(conn, file);
-               }
+               DEBUG(10,("deleting driverfile [%s]\n", r->driver_path));
+               driver_unlink_internals(conn, short_arch, r->version, r->driver_path);
        }
 
        if (r->config_file && r->config_file[0]) {
-               if ((s = strchr(&r->config_file[1], '\\')) != NULL) {
-                       file = s;
-                       DEBUG(10,("deleting configfile [%s]\n", s));
-                       driver_unlink_internals(conn, file);
-               }
+               DEBUG(10,("deleting configfile [%s]\n", r->config_file));
+               driver_unlink_internals(conn, short_arch, r->version, r->config_file);
        }
 
        if (r->data_file && r->data_file[0]) {
-               if ((s = strchr(&r->data_file[1], '\\')) != NULL) {
-                       file = s;
-                       DEBUG(10,("deleting datafile [%s]\n", s));
-                       driver_unlink_internals(conn, file);
-               }
+               DEBUG(10,("deleting datafile [%s]\n", r->data_file));
+               driver_unlink_internals(conn, short_arch, r->version, r->data_file);
        }
 
        if (r->help_file && r->help_file[0]) {
-               if ((s = strchr(&r->help_file[1], '\\')) != NULL) {
-                       file = s;
-                       DEBUG(10,("deleting helpfile [%s]\n", s));
-                       driver_unlink_internals(conn, file);
-               }
+               DEBUG(10,("deleting helpfile [%s]\n", r->help_file));
+               driver_unlink_internals(conn, short_arch, r->version, r->help_file);
        }
 
-       /* check if we are done removing files */
-
        if (r->dependent_files) {
+               int i = 0;
                while (r->dependent_files[i] && r->dependent_files[i][0]) {
-                       char *p;
-
-                       /* bypass the "\print$" portion of the path */
-
-                       if ((p = strchr(r->dependent_files[i]+1, '\\')) != NULL) {
-                               file = p;
-                               DEBUG(10,("deleting dependent file [%s]\n", file));
-                               driver_unlink_internals(conn, file);
-                       }
-
+                       DEBUG(10,("deleting dependent file [%s]\n", r->dependent_files[i]));
+                       driver_unlink_internals(conn, short_arch, r->version, r->dependent_files[i]);
                        i++;
                }
        }