From a2c51a88cca77accdcd6660bdbdeccad63b8ee6a Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 22 Apr 2010 10:59:27 +0200 Subject: s3-spoolss: Migrated spoolss_OpenPrinter to create defaults with winreg_create_printer. Signed-off-by: Jim McDonough --- source3/rpc_server/srv_spoolss_nt.c | 98 +++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 80e7c2e950..9691905109 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -428,15 +428,19 @@ static bool set_printer_hnd_printertype(Printer_entry *Printer, const char *hand XcvDataPort() interface. ****************************************************************************/ -static bool set_printer_hnd_name(Printer_entry *Printer, const char *handlename) +static bool set_printer_hnd_name(TALLOC_CTX *mem_ctx, + struct auth_serversupplied_info *server_info, + Printer_entry *Printer, + const char *handlename) { int snum; int n_services=lp_numservices(); - char *aprinter, *printername; + char *aprinter; + const char *printername; const char *servername; fstring sname; bool found = false; - NT_PRINTER_INFO_LEVEL *printer = NULL; + struct spoolss_PrinterInfo2 *info2 = NULL; WERROR result; DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename, @@ -449,27 +453,24 @@ static bool set_printer_hnd_name(Printer_entry *Printer, const char *handlename) *aprinter = '\0'; aprinter++; } - } else { - servername = global_myname(); - } - - /* save the servername to fill in replies on this handle */ - - if ( !is_myname_or_ipaddr( servername ) ) - return false; + if (!is_myname_or_ipaddr(servername)) { + return false; + } - fstrcpy( Printer->servername, servername ); + fstrcpy(Printer->servername, servername); + } - if ( Printer->printer_type == SPLHND_SERVER ) + if (Printer->printer_type == SPLHND_SERVER) { return true; + } - if ( Printer->printer_type != SPLHND_PRINTER ) + if (Printer->printer_type != SPLHND_PRINTER) { return false; + } - DEBUGADD(5, ("searching for [%s]\n", aprinter )); + DEBUGADD(5, ("searching for [%s]\n", aprinter)); /* check for the Port Monitor Interface */ - if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) { Printer->printer_type = SPLHND_PORTMON_TCP; fstrcpy(sname, SPL_XCV_MONITOR_TCPMON); @@ -486,65 +487,59 @@ static bool set_printer_hnd_name(Printer_entry *Printer, const char *handlename) that calls out to map_username() */ /* do another loop to look for printernames */ - - for (snum=0; !found && snuminfo_2->printername[2], '\\')) ) { - DEBUG(0,("set_printer_hnd_name: info2->printername in wrong format! [%s]\n", - printer->info_2->printername)); - free_a_printer( &printer, 2); - continue; + printername = strrchr(info2->printername, '\\'); + if (printername == NULL) { + printername = info2->printername; + } else { + printername++; } - printername++; - - if ( strequal(printername, aprinter) ) { - free_a_printer( &printer, 2); + if (strequal(printername, aprinter)) { found = true; break; } DEBUGADD(10, ("printername: %s\n", printername)); - free_a_printer( &printer, 2); + TALLOC_FREE(info2); } - free_a_printer( &printer, 2); - if ( !found ) { DEBUGADD(4,("Printer not found\n")); return false; @@ -589,7 +584,7 @@ static bool open_printer_hnd(pipes_struct *p, struct policy_handle *hnd, return false; } - if (!set_printer_hnd_name(new_printer, name)) { + if (!set_printer_hnd_name(p->mem_ctx, p->server_info, new_printer, name)) { close_printer_handle(p, hnd); return false; } @@ -1446,6 +1441,8 @@ WERROR _spoolss_OpenPrinterEx(pipes_struct *p, DEBUGADD(3,("checking name: %s\n", r->in.printername)); if (!open_printer_hnd(p, r->out.handle, r->in.printername, 0)) { + DEBUG(0,("_spoolss_OpenPrinterEx: Cannot open a printer handle " + " for printer %s\n", r->in.printername)); ZERO_STRUCTP(r->out.handle); return WERR_INVALID_PARAM; } @@ -1617,6 +1614,11 @@ WERROR _spoolss_OpenPrinterEx(pipes_struct *p, DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER) ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" )); + winreg_create_printer(p->mem_ctx, + p->server_info, + Printer->servername, + lp_const_servicename(snum)); + break; default: -- cgit