From 49fcb300de40d6da8682b485fd2c51236bcbb3dd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 31 Jul 2000 20:41:51 +0000 Subject: Added John Reilly's enumports/addprinter/delprinter scripting code plus the fix for the Win9x printer drivers. Changed command names to add "command" string on the end for some consistancy with the other scripting commands. Added '%P' option to tdbpack/unpack to store long comment string. Made port name be "Samba Printer Port" if no enum port script given. Fixed prs_uint32_pre code to cope with null args. Jeremy. (This used to be commit 902ada63799cf27924c72e24e7593a8c9fb5eba9) --- source3/rpc_server/srv_spoolss_nt.c | 296 +++++++++++++++++++++++++++--------- 1 file changed, 227 insertions(+), 69 deletions(-) (limited to 'source3/rpc_server') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index c9d81e1cba..b675175544 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -28,6 +28,10 @@ extern int DEBUGLEVEL; extern pstring global_myname; +#ifndef SAMBA_PRINTER_PORT_NAME +#define SAMBA_PRINTER_PORT_NAME "Samba Printer Port" +#endif + #ifndef MAX_OPEN_PRINTER_EXS #define MAX_OPEN_PRINTER_EXS 50 #endif @@ -217,6 +221,45 @@ static BOOL delete_printer_handle(POLICY_HND *hnd) return False; } + if (*lp_deleteprinter_cmd()) { + + pid_t local_pid = sys_getpid(); + char *cmd = lp_deleteprinter_cmd(); + char *path; + pstring tmp_file; + pstring command; + int ret; + int i; + + if (*lp_pathname(lp_servicenumber(PRINTERS_NAME))) + path = lp_pathname(lp_servicenumber(PRINTERS_NAME)); + else + path = tmpdir(); + + /* Printer->dev.handlename equals portname equals sharename */ + slprintf(command, sizeof(command), "%s \"%s\"", cmd, + Printer->dev.handlename); + slprintf(tmp_file, sizeof(tmp_file), "%s/smbcmd.%d", path, local_pid); + + unlink(tmp_file); + DEBUG(10,("Running [%s > %s]\n", command,tmp_file)); + ret = smbrun(command, tmp_file, False); + if (ret != 0) { + unlink(tmp_file); + return False; + } + DEBUGADD(10,("returned [%d]\n", ret)); + DEBUGADD(10,("Unlinking output file [%s]\n", tmp_file)); + unlink(tmp_file); + + if ( ( i = lp_servicenumber( Printer->dev.handlename ) ) >= 0 ) { + lp_remove_service( i ); + lp_killservice( i ); + return True; + } else + return False; + } + return True; } @@ -3204,7 +3247,7 @@ static uint32 update_printer(POLICY_HND *handle, uint32 level, */ if (!check_printer_ok(printer->info_2, snum)) { - result = ERROR_ACCESS_DENIED; + result = ERROR_INVALID_PARAMETER; goto done; } @@ -3914,46 +3957,71 @@ static void fill_port_2(PORT_INFO_2 *port, char *name) ****************************************************************************/ static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { - int n_services=lp_numservices(); - int snum; - int i=0; - PORT_INFO_1 *ports=NULL; + int i=0; - for (snum=0; snum %s]\n", command,tmp_file)); + ret = smbrun(command, tmp_file, False); + DEBUG(10,("Returned [%d]\n", ret)); + if (ret != 0) { + unlink(tmp_file); + // Is this the best error to return here? + return ERROR_ACCESS_DENIED; + } - if((ports=(PORT_INFO_1 *)malloc( (*returned+1) * sizeof(PORT_INFO_1) )) == NULL) - return ERROR_NOT_ENOUGH_MEMORY; - - for (snum=0; snum %s]\n", command,tmp_file)); + ret = smbrun(command, tmp_file, False); + DEBUGADD(10,("returned [%d]\n", ret)); + if (ret != 0) { + unlink(tmp_file); + // Is this the best error to return here? + return ERROR_ACCESS_DENIED; + } - if((ports=(PORT_INFO_2 *)malloc( (*returned+1) * sizeof(PORT_INFO_2) )) == NULL) - return ERROR_NOT_ENOUGH_MEMORY; - - for (snum=0; snuminfo_2->printername, printer->info_2->sharename, + printer->info_2->portname, printer->info_2->drivername, + printer->info_2->location, driverlocation); + + unlink(tmp_file); + DEBUG(10,("Running [%s > %s]\n", command,tmp_file)); + ret = smbrun(command, tmp_file, False); + DEBUGADD(10,("returned [%d]\n", ret)); + + if ( ret != 0 ) { + unlink(tmp_file); + free_a_printer(&printer,2); + return False; + } + + numlines = 0; + qlines = file_lines_load(tmp_file, &numlines); + DEBUGADD(10,("Lines returned = [%d]\n", numlines)); + DEBUGADD(10,("Line[0] = [%s]\n", qlines[0])); + DEBUGADD(10,("Unlinking port file [%s]\n", tmp_file)); + unlink(tmp_file); + + if(numlines) { + // Set the portname to what the script says the portname should be + strncpy(printer->info_2->portname, qlines[0], sizeof(printer->info_2->portname)); + + // Send SIGHUP to process group... is there a better way? + kill(0, SIGHUP); + add_all_printers(); + } + + file_lines_free(qlines); + return True; +} + /**************************************************************************** ****************************************************************************/ static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name, @@ -4091,7 +4247,6 @@ static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name, { NT_PRINTER_INFO_LEVEL *printer = NULL; fstring name; - fstring share_name; int snum; if ((printer = (NT_PRINTER_INFO_LEVEL *)malloc(sizeof(NT_PRINTER_INFO_LEVEL))) == NULL) { @@ -4104,11 +4259,14 @@ static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name, /* convert from UNICODE to ASCII - this allocates the info_2 struct inside *printer.*/ convert_printer_info(info, printer, 2); - unistr2_to_ascii(share_name, &info->info_2->sharename, sizeof(share_name)-1); + if (*lp_addprinter_cmd() ) + if ( !add_printer_hook(printer) ) + return ERROR_ACCESS_DENIED; - slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname, share_name); + slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname, + printer->info_2->sharename); - if ((snum = print_queue_snum(share_name)) == -1) { + if ((snum = print_queue_snum(printer->info_2->sharename)) == -1) { free_a_printer(&printer,2); return ERROR_ACCESS_DENIED; } @@ -4119,7 +4277,7 @@ static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name, if (!check_printer_ok(printer->info_2, snum)) { free_a_printer(&printer,2); - return ERROR_ACCESS_DENIED; + return ERROR_INVALID_PARAMETER; } /* write the ASCII on disk */ @@ -4130,7 +4288,7 @@ static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name, if (!open_printer_hnd(handle, name)) { /* Handle open failed - remove addition. */ - del_a_printer(share_name); + del_a_printer(printer->info_2->sharename); free_a_printer(&printer,2); return ERROR_ACCESS_DENIED; } -- cgit