Convert move_driver_to_download_area to use create_conn_struct
authorVolker Lendecke <vl@samba.org>
Sun, 23 Nov 2008 21:46:08 +0000 (22:46 +0100)
committerVolker Lendecke <vl@samba.org>
Mon, 24 Nov 2008 10:39:03 +0000 (11:39 +0100)
This removes a use of struct current_user and the vuid

The become_user() here is unnecessary, within the spoolss handling code we have
switched to the authenticated pipe user anyway.

Jerry, please check!

source3/include/proto.h
source3/printing/nt_printing.c
source3/rpc_server/srv_spoolss_nt.c

index a024d683f349a45c7bec66e4e790129105d80134..abb65ac654c53c50f228bf0d97fd7382946b69a5 100644 (file)
@@ -4775,8 +4775,9 @@ int get_ntdrivers(fstring **list, const char *architecture, uint32 version);
 const char *get_short_archi(const char *long_archi);
 WERROR clean_up_driver_struct(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract,
                                                          uint32 level, struct current_user *user);
-WERROR move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract, uint32 level, 
-                                 struct current_user *user, WERROR *perr);
+WERROR move_driver_to_download_area(struct pipes_struct *p,
+                                   NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract,
+                                   uint32 level, WERROR *perr);
 int pack_devicemode(NT_DEVICEMODE *nt_devmode, uint8 *buf, int buflen);
 uint32 del_a_printer(const char *sharename);
 NT_DEVICEMODE *construct_nt_devicemode(const fstring default_devicename);
index 11370272a24eb86014f7b8725b80a33215c71245..71d906cb4137964ff9fa55f7ca8a3304209c7524 100644 (file)
@@ -1796,8 +1796,9 @@ static char* ffmt(unsigned char *c){
 
 /****************************************************************************
 ****************************************************************************/
-WERROR move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract, uint32 level, 
-                                 struct current_user *user, WERROR *perr)
+WERROR move_driver_to_download_area(struct pipes_struct *p,
+                                   NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract,
+                                   uint32 level, WERROR *perr)
 {
        NT_PRINTER_DRIVER_INFO_LEVEL_3 *driver;
        NT_PRINTER_DRIVER_INFO_LEVEL_3 converted_driver;
@@ -1805,14 +1806,15 @@ WERROR move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract
        char *new_dir = NULL;
        char *old_name = NULL;
        char *new_name = NULL;
-       DATA_BLOB null_pw;
-       connection_struct *conn;
+       connection_struct *conn = NULL;
        NTSTATUS nt_status;
-       fstring res_type;
        SMB_STRUCT_STAT st;
        int i;
        TALLOC_CTX *ctx = talloc_tos();
        int ver = 0;
+       char *oldcwd;
+       fstring printdollar;
+       int printdollar_snum;
 
        *perr = WERR_OK;
 
@@ -1831,38 +1833,24 @@ WERROR move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract
                return WERR_UNKNOWN_PRINTER_DRIVER;
        }
 
-       /*
-        * Connect to the print$ share under the same account as the user connected to the rpc pipe.
-        * Note we must be root to do this.
-        */
-
-       null_pw = data_blob_null;
-       fstrcpy(res_type, "A:");
-       become_root();
-       conn = make_connection_with_chdir("print$", null_pw, res_type, user->vuid, &nt_status);
-       unbecome_root();
+       fstrcpy(printdollar, "print$");
 
-       if (conn == NULL) {
-               DEBUG(0,("move_driver_to_download_area: Unable to connect\n"));
-               *perr = ntstatus_to_werror(nt_status);
+       printdollar_snum = find_service(printdollar);
+       if (printdollar_snum == -1) {
+               *perr = WERR_NO_SUCH_SHARE;
                return WERR_NO_SUCH_SHARE;
        }
 
-       /*
-        * Save who we are - we are temporarily becoming the connection user.
-        */
-
-       if (!become_user(conn, conn->vuid)) {
-               DEBUG(0,("move_driver_to_download_area: Can't become user!\n"));
-               return WERR_ACCESS_DENIED;
+       nt_status = create_conn_struct(talloc_tos(), &conn, printdollar_snum,
+                                      lp_pathname(printdollar_snum),
+                                      p->server_info, &oldcwd);
+       if (!NT_STATUS_IS_OK(nt_status)) {
+               DEBUG(0,("move_driver_to_download_area: create_conn_struct "
+                        "returned %s\n", nt_errstr(nt_status)));
+               *perr = ntstatus_to_werror(nt_status);
+               return *perr;
        }
 
-       /* WE ARE NOW RUNNING AS USER conn->vuid !!!!! */
-
-       /*
-        * make the directories version and version\driver_name
-        * under the architecture directory.
-        */
        DEBUG(5,("Creating first directory\n"));
        new_dir = talloc_asprintf(ctx,
                                "%s/%d",
@@ -2092,8 +2080,10 @@ WERROR move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract
 
   err_exit:
 
-       close_cnum(conn, user->vuid);
-       unbecome_user();
+       if (conn != NULL) {
+               vfs_ChDir(conn, oldcwd);
+               conn_free_internal(conn);
+       }
 
        if (W_ERROR_EQUAL(*perr, WERR_OK)) {
                return WERR_OK;
index 59c1323a0f863f35566e00db7cb946cae89268b2..cc958aa8a6db5a0091d96386131a522f9dbed761 100644 (file)
@@ -7860,7 +7860,8 @@ WERROR _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u,
                goto done;
 
        DEBUG(5,("Moving driver to final destination\n"));
-       if( !W_ERROR_IS_OK(err = move_driver_to_download_area(driver, level, &p->pipe_user, &err)) ) {
+       if( !W_ERROR_IS_OK(err = move_driver_to_download_area(p, driver, level,
+                                                             &err)) ) {
                goto done;
        }