From 783ab0480b7c1454a95cdb414d3277a8fa543e9a Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 23 Nov 2008 22:46:08 +0100 Subject: [PATCH] Convert move_driver_to_download_area to use create_conn_struct 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 | 5 +-- source3/printing/nt_printing.c | 56 ++++++++++++----------------- source3/rpc_server/srv_spoolss_nt.c | 3 +- 3 files changed, 28 insertions(+), 36 deletions(-) diff --git a/source3/include/proto.h b/source3/include/proto.h index a024d683f3..abb65ac654 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -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); diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c index 11370272a2..71d906cb41 100644 --- a/source3/printing/nt_printing.c +++ b/source3/printing/nt_printing.c @@ -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; diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 59c1323a0f..cc958aa8a6 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -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; } -- 2.34.1