diff options
author | Volker Lendecke <vl@samba.org> | 2008-11-23 23:13:11 +0100 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2008-11-24 11:39:03 +0100 |
commit | c25f5c778acd7918551a6234d749854a0e8ea562 (patch) | |
tree | ed498f12cc1e9f31034de34d56cb7ee588e25425 | |
parent | cb4f8573ba5fe7164be8adee8af7fbec9ec18ab0 (diff) | |
download | samba-c25f5c778acd7918551a6234d749854a0e8ea562.tar.gz samba-c25f5c778acd7918551a6234d749854a0e8ea562.tar.bz2 samba-c25f5c778acd7918551a6234d749854a0e8ea562.zip |
Convert delete_driver_files to use create_conn_struct
Jerry, please check!
-rw-r--r-- | source3/include/proto.h | 5 | ||||
-rw-r--r-- | source3/printing/nt_printing.c | 62 | ||||
-rw-r--r-- | source3/rpc_server/srv_spoolss_nt.c | 10 |
3 files changed, 41 insertions, 36 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h index d3cc8c9f12..853d827f2b 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -4821,8 +4821,9 @@ WERROR get_a_printer_driver(NT_PRINTER_DRIVER_INFO_LEVEL *driver, uint32 level, uint32 free_a_printer_driver(NT_PRINTER_DRIVER_INFO_LEVEL driver, uint32 level); bool printer_driver_in_use ( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3 ); bool printer_driver_files_in_use ( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info ); -WERROR delete_printer_driver( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3, struct current_user *user, - uint32 version, bool delete_files ); +WERROR delete_printer_driver(struct pipes_struct *rpc_pipe, + NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3, + uint32 version, bool delete_files ); WERROR nt_printing_setsec(const char *sharename, SEC_DESC_BUF *secdesc_ctr); bool nt_printing_getsec(TALLOC_CTX *ctx, const char *sharename, SEC_DESC_BUF **secdesc_ctr); void map_printer_permissions(SEC_DESC *sd); diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c index fc73cb55d2..244b3aee03 100644 --- a/source3/printing/nt_printing.c +++ b/source3/printing/nt_printing.c @@ -5196,49 +5196,44 @@ bool printer_driver_files_in_use ( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info ) this. ****************************************************************************/ -static bool delete_driver_files( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3, struct current_user *user ) +static bool delete_driver_files(struct pipes_struct *rpc_pipe, + NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3) { int i = 0; char *s; const char *file; connection_struct *conn; - DATA_BLOB null_pw; NTSTATUS nt_status; - fstring res_type; SMB_STRUCT_STAT st; + char *oldcwd; + fstring printdollar; + int printdollar_snum; + bool ret = false; if ( !info_3 ) return False; DEBUG(6,("delete_driver_files: deleting driver [%s] - version [%d]\n", info_3->name, info_3->cversion)); - /* - * 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. - */ + fstrcpy(printdollar, "print$"); - 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(); + printdollar_snum = find_service(printdollar); + if (printdollar_snum == -1) { + return false; + } - if ( !conn ) { - DEBUG(0,("delete_driver_files: Unable to connect\n")); - return False; + nt_status = create_conn_struct(talloc_tos(), &conn, printdollar_snum, + lp_pathname(printdollar_snum), + rpc_pipe->server_info, &oldcwd); + if (!NT_STATUS_IS_OK(nt_status)) { + DEBUG(0,("delete_driver_files: create_conn_struct " + "returned %s\n", nt_errstr(nt_status))); + return false; } if ( !CAN_WRITE(conn) ) { DEBUG(3,("delete_driver_files: Cannot delete print driver when [print$] is read-only\n")); - return False; - } - - /* Save who we are - we are temporarily becoming the connection user. */ - - if ( !become_user(conn, conn->vuid) ) { - DEBUG(0,("delete_driver_files: Can't become user!\n")); - return False; + goto fail; } /* now delete the files; must strip the '\print$' string from @@ -5299,9 +5294,15 @@ static bool delete_driver_files( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3, struct } } - unbecome_user(); - - return true; + goto done; + fail: + ret = false; + done: + if (conn != NULL) { + vfs_ChDir(conn, oldcwd); + conn_free_internal(conn); + } + return ret; } /**************************************************************************** @@ -5309,8 +5310,9 @@ static bool delete_driver_files( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3, struct previously looked up. ***************************************************************************/ -WERROR delete_printer_driver( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3, struct current_user *user, - uint32 version, bool delete_files ) +WERROR delete_printer_driver(struct pipes_struct *rpc_pipe, + NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3, + uint32 version, bool delete_files ) { char *key = NULL; const char *arch; @@ -5360,7 +5362,7 @@ WERROR delete_printer_driver( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3, struct cur */ if ( delete_files ) - delete_driver_files( info_3, user ); + delete_driver_files(rpc_pipe, info_3); DEBUG(5,("delete_printer_driver: driver delete successful [%s]\n", key)); SAFE_FREE(key); diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index b032ce2aad..46aed7ce65 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2070,7 +2070,8 @@ WERROR _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER /* if we get to here, we now have 2 driver info structures to remove */ /* remove the Win2k driver first*/ - status_win2k = delete_printer_driver(info_win2k.info_3, &p->pipe_user, 3, False ); + status_win2k = delete_printer_driver( + p, info_win2k.info_3, 3, False ); free_a_printer_driver( info_win2k, 3 ); /* this should not have failed---if it did, report to client */ @@ -2082,7 +2083,7 @@ WERROR _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER } } - status = delete_printer_driver(info.info_3, &p->pipe_user, version, False); + status = delete_printer_driver(p, info.info_3, version, False); /* if at least one of the deletes succeeded return OK */ @@ -2205,7 +2206,8 @@ WERROR _spoolss_deleteprinterdriverex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIV /* if we get to here, we now have 2 driver info structures to remove */ /* remove the Win2k driver first*/ - status_win2k = delete_printer_driver(info_win2k.info_3, &p->pipe_user, 3, delete_files); + status_win2k = delete_printer_driver( + p, info_win2k.info_3, 3, delete_files); free_a_printer_driver( info_win2k, 3 ); /* this should not have failed---if it did, report to client */ @@ -2215,7 +2217,7 @@ WERROR _spoolss_deleteprinterdriverex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIV } } - status = delete_printer_driver(info.info_3, &p->pipe_user, version, delete_files); + status = delete_printer_driver(p, info.info_3, version, delete_files); if ( W_ERROR_IS_OK(status) || W_ERROR_IS_OK(status_win2k) ) status = WERR_OK; |