From 6a6749d81e892bb06bfdc0fefdc428e5e6599f71 Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Mon, 7 Feb 2000 16:17:59 +0000 Subject: First commit of the spoolss code to the HEAD branch. still needs a lot of cleaning/debuging. J.F. (This used to be commit bd9d4cdde9193c120c6f4e8cf72f87cd67a9387e) --- source3/rpc_server/srv_spoolss_nt.c | 3434 +++++++++++++++++++++++++++++++++++ 1 file changed, 3434 insertions(+) create mode 100644 source3/rpc_server/srv_spoolss_nt.c (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c new file mode 100644 index 0000000000..db48fa42ff --- /dev/null +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -0,0 +1,3434 @@ +/* + * Unix SMB/Netbios implementation. + * Version 1.9. + * RPC Pipe client / server routines + * Copyright (C) Andrew Tridgell 1992-2000, + * Copyright (C) Luke Kenneth Casson Leighton 1996-2000, + * Copyright (C) Jean François Micouleau 1998-2000. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +#include "includes.h" +#include "nterr.h" + +extern int DEBUGLEVEL; +extern pstring global_myname; + +#ifndef MAX_OPEN_PRINTER_EXS +#define MAX_OPEN_PRINTER_EXS 50 +#endif + +#define PRINTER_HANDLE_IS_PRINTER 0 +#define PRINTER_HANDLE_IS_PRINTSERVER 1 + +/* structure to store the printer handles */ +/* and a reference to what it's pointing to */ +/* and the notify info asked about */ +/* that's the central struct */ +static struct +{ + BOOL open; + BOOL ok; + BOOL document_started; + BOOL page_started; + uint32 current_jobid; + uint32 document_fd; + uint32 document_lastwritten; + pstring document_name; + pstring job_name; + POLICY_HND printer_hnd; + BOOL printer_type; + union + { + fstring printername; + fstring printerservername; + } dev; + uint32 type; + uint32 access; + uint32 number_of_notify; + SPOOL_NOTIFY_OPTION_TYPE notify_info[MAX_PRINTER_NOTIFY+MAX_JOB_NOTIFY]; +} Printer[MAX_OPEN_PRINTER_EXS]; + +#define VALID_HANDLE(pnum) (((pnum) >= 0) && ((pnum) < MAX_OPEN_PRINTER_EXS)) +#define OPEN_HANDLE(pnum) (VALID_HANDLE(pnum) && Printer[pnum].open) + +/**************************************************************************** + initialise printer handle states... +****************************************************************************/ +void init_printer_hnd(void) +{ + int i; + for (i = 0; i < MAX_OPEN_PRINTER_EXS; i++) + { + Printer[i].open = False; + } +} + +/**************************************************************************** + create a unique printer handle +****************************************************************************/ +static void create_printer_hnd(POLICY_HND *hnd) +{ + static uint32 prt_hnd_low = 0; + static uint32 prt_hnd_high = 0; + + if (hnd == NULL) return; + + /* i severely doubt that prt_hnd_high will ever be non-zero... */ + prt_hnd_low++; + if (prt_hnd_low == 0) prt_hnd_high++; + + SIVAL(hnd->data, 0 , 0x0); /* first bit must be null */ + SIVAL(hnd->data, 4 , prt_hnd_low ); /* second bit is incrementing */ + SIVAL(hnd->data, 8 , prt_hnd_high); /* second bit is incrementing */ + SIVAL(hnd->data, 12, time(NULL)); /* something random */ + SIVAL(hnd->data, 16, getpid()); /* something more random */ +} + +/**************************************************************************** + find printer index by handle +****************************************************************************/ +static int find_printer_index_by_hnd(const POLICY_HND *hnd) +{ + int i; + + for (i = 0; i < MAX_OPEN_PRINTER_EXS; i++) + { + if (memcmp(&(Printer[i].printer_hnd), hnd, sizeof(*hnd)) == 0) + { + DEBUG(4,("Found printer handle[%x] ", i)); + dump_data(4, hnd->data, sizeof(hnd->data)); + return i; + } + } + DEBUG(3,("Whoops, Printer handle not found: ")); + dump_data(4, hnd->data, sizeof(hnd->data)); + return -1; +} + +/**************************************************************************** + clear an handle +****************************************************************************/ +static void clear_handle(POLICY_HND *hnd) +{ + bzero(hnd->data, POLICY_HND_SIZE); +} + +/**************************************************************************** + close printer index by handle +****************************************************************************/ +static BOOL close_printer_handle(POLICY_HND *hnd) +{ + int pnum = find_printer_index_by_hnd(hnd); + + if (pnum == -1) + { + DEBUG(3,("Error closing printer handle (pnum=%x)\n", pnum)); + return False; + } + + Printer[pnum].open=False; + clear_handle(hnd); + + return True; +} + +/**************************************************************************** + return the snum of a printer corresponding to an handle +****************************************************************************/ +static BOOL get_printer_snum(const POLICY_HND *hnd, int *number) +{ + int snum; + int pnum = find_printer_index_by_hnd(hnd); + int n_services=lp_numservices(); + + if (!OPEN_HANDLE(pnum)) { + DEBUG(3,("Error getting printer - take a nap quickly !\n")); + return False; + } + + switch (Printer[pnum].printer_type) { + case PRINTER_HANDLE_IS_PRINTER: + DEBUG(4,("short name:%s\n", Printer[pnum].dev.printername)); + for (snum=0;snumdata, sizeof(hnd->data)); + return True; + } + } + DEBUG(1,("ERROR - open_printer_hnd: out of Printers Handles!\n")); + return False; +} + +/**************************************************************************** + set printer handle type. +****************************************************************************/ +static BOOL set_printer_hnd_accesstype(POLICY_HND *hnd, uint32 access_required) +{ + int pnum = find_printer_index_by_hnd(hnd); + + if (OPEN_HANDLE(pnum)) { + DEBUG(4,("Setting printer access=%x (pnum=%x)\n", access_required, pnum)); + Printer[pnum].access = access_required; + return True; + } + else { + DEBUG(4,("Error setting printer type=%x (pnum=%x)", access_required, pnum)); + return False; + } + return False; +} + +/**************************************************************************** + . +****************************************************************************/ +static BOOL printer_entry_is_valid(POLICY_HND *hnd) +{ + int pnum = find_printer_index_by_hnd(hnd); + + if (!OPEN_HANDLE(pnum)) + return False; + + if (Printer[pnum].ok == False) + return False; + + return True; +} + +/**************************************************************************** + set printer handle type. + check if it's \\server or \\server\printer +****************************************************************************/ +static BOOL set_printer_hnd_printertype(POLICY_HND *hnd, char *printername) +{ + int pnum = find_printer_index_by_hnd(hnd); + + if (!OPEN_HANDLE(pnum)) { + DEBUGADD(4,("Error setting printer name %s (pnum=%x)", printername, pnum)); + return False; + } + + DEBUG(3,("Setting printer type=%s (pnum=%x)\n", printername, pnum)); + + if ( strlen(printername) < 3 ) { + DEBUGADD(4,("A print server must have at least 1 char ! %s\n", printername)); + Printer[pnum].ok=False; + return False; + } + + /* it's a print server */ + if (!strchr(printername+2, '\\')) { + DEBUGADD(4,("Printer is a print server\n")); + Printer[pnum].printer_type = PRINTER_HANDLE_IS_PRINTSERVER; + Printer[pnum].ok=True; + + return True; + } + /* it's a printer */ + else { + DEBUGADD(4,("Printer is a printer\n")); + Printer[pnum].printer_type = PRINTER_HANDLE_IS_PRINTER; + Printer[pnum].ok=True; + return True; + } + + return False; +} + +/**************************************************************************** + set printer handle printername. +****************************************************************************/ +static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) +{ + int pnum = find_printer_index_by_hnd(hnd); + char *back; + NT_PRINTER_INFO_LEVEL printer; + int snum; + int n_services=lp_numservices(); + uint32 marche; + + if (!OPEN_HANDLE(pnum)) + { + DEBUG(0,("Error setting printer name=%s (pnum=%x)\n", printername, pnum)); + return False; + } + + DEBUG(4,("Setting printer name=%s (len=%d) (pnum=%x)\n", printername, strlen(printername), pnum)); + + switch (Printer[pnum].printer_type) { + case PRINTER_HANDLE_IS_PRINTSERVER: + ZERO_STRUCT(Printer[pnum].dev.printerservername); + strncpy(Printer[pnum].dev.printerservername, printername, strlen(printername)); + return True; + break; + + case PRINTER_HANDLE_IS_PRINTER: + back=strchr(printername+2, '\\'); + back=back+1; + DEBUGADD(5,("searching for %s (len=%d)\n", back,strlen(back))); + /* + * store the Samba share name in it + * in back we have the long printer name + * need to iterate all the snum and do a + * get_a_printer each time to find the printer + * faster to do it here than later. + */ + for (snum=0;snumprintername) == strlen(back) ) + && ( !strncasecmp(printer.info_2->printername, back, strlen(back))) + ) { + DEBUGADD(4,("Printer found: %s[%x]\n",lp_servicename(snum),snum)); + ZERO_STRUCT(Printer[pnum].dev.printername); + strncpy(Printer[pnum].dev.printername, lp_servicename(snum), strlen(lp_servicename(snum))); + free_a_printer(printer, 2); + return True; + break; + } + free_a_printer(printer, 2); + } + } + return False; + break; + + default: + return False; + break; + } +} + +/******************************************************************** + ********************************************************************/ +static BOOL handle_is_printserver(const POLICY_HND *handle) +{ + int pnum=find_printer_index_by_hnd(handle); + + if (!OPEN_HANDLE(pnum)) + return False; + + if (Printer[pnum].printer_type != PRINTER_HANDLE_IS_PRINTSERVER) + return False; + + return True; +} + +/******************************************************************** + * spoolss_open_printer + * + * called from the spoolss dispatcher + ********************************************************************/ +uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, + const PRINTER_DEFAULT *printer_default, + uint32 user_switch, SPOOL_USER_CTR user_ctr, + POLICY_HND *handle) +{ + BOOL printer_open = False; + fstring name; + fstring datatype; + + clear_handle(handle); + + if (printername == NULL) + return NT_STATUS_ACCESS_DENIED; + + /* some sanity check because you can open a printer or a print server */ + /* aka: \\server\printer or \\server */ + unistr2_to_ascii(name, printername, sizeof(name)-1); + + DEBUGADD(3,("checking name: %s\n",name)); + + create_printer_hnd(handle); + + open_printer_hnd(handle); + + set_printer_hnd_printertype(handle, name); + + set_printer_hnd_printername(handle, name); + +/* + if (printer_default->datatype_ptr != NULL) + { + unistr2_to_ascii(datatype, printer_default->datatype, sizeof(datatype)-1); + set_printer_hnd_datatype(handle, datatype); + } + else + set_printer_hnd_datatype(handle, ""); +*/ + + set_printer_hnd_accesstype(handle, printer_default->access_required); + + if (!printer_entry_is_valid(handle)) + { + close_printer_handle(handle); + return NT_STATUS_ACCESS_DENIED; + } + + return NT_STATUS_NO_PROBLEMO; +} + +static BOOL convert_printer_info(const SPOOL_PRINTER_INFO_LEVEL *uni, + NT_PRINTER_INFO_LEVEL *printer, + uint32 level) +{ + switch (level) + { + case 2: + { + uni_2_asc_printer_info_2(uni->info_2, + &(printer->info_2)); + break; + } + default: + break; + } + + + + return True; +} + +static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL *uni, + NT_PRINTER_DRIVER_INFO_LEVEL *printer, + uint32 level) +{ + switch (level) + { + case 3: + { + printer->info_3=NULL; + uni_2_asc_printer_driver_3(uni->info_3, &(printer->info_3)); + break; + } + default: + break; + } + + + + return True; +} + +static BOOL convert_devicemode(DEVICEMODE devmode, NT_DEVICEMODE *nt_devmode) +{ + unistr_to_ascii(nt_devmode->devicename, + devmode.devicename.buffer, + 31); + + unistr_to_ascii(nt_devmode->formname, + devmode.formname.buffer, + 31); + + nt_devmode->specversion=devmode.specversion; + nt_devmode->driverversion=devmode.driverversion; + nt_devmode->size=devmode.size; + nt_devmode->driverextra=devmode.driverextra; + nt_devmode->fields=devmode.fields; + nt_devmode->orientation=devmode.orientation; + nt_devmode->papersize=devmode.papersize; + nt_devmode->paperlength=devmode.paperlength; + nt_devmode->paperwidth=devmode.paperwidth; + nt_devmode->scale=devmode.scale; + nt_devmode->copies=devmode.copies; + nt_devmode->defaultsource=devmode.defaultsource; + nt_devmode->printquality=devmode.printquality; + nt_devmode->color=devmode.color; + nt_devmode->duplex=devmode.duplex; + nt_devmode->yresolution=devmode.yresolution; + nt_devmode->ttoption=devmode.ttoption; + nt_devmode->collate=devmode.collate; + + nt_devmode->logpixels=devmode.logpixels; + nt_devmode->bitsperpel=devmode.bitsperpel; + nt_devmode->pelswidth=devmode.pelswidth; + nt_devmode->pelsheight=devmode.pelsheight; + nt_devmode->displayflags=devmode.displayflags; + nt_devmode->displayfrequency=devmode.displayfrequency; + nt_devmode->icmmethod=devmode.icmmethod; + nt_devmode->icmintent=devmode.icmintent; + nt_devmode->mediatype=devmode.mediatype; + nt_devmode->dithertype=devmode.dithertype; + nt_devmode->reserved1=devmode.reserved1; + nt_devmode->reserved2=devmode.reserved2; + nt_devmode->panningwidth=devmode.panningwidth; + nt_devmode->panningheight=devmode.panningheight; + + if (nt_devmode->driverextra != 0) + { + /* if we had a previous private delete it and make a new one */ + if (nt_devmode->private != NULL) + free(nt_devmode->private); + nt_devmode->private=(uint8 *)malloc(nt_devmode->driverextra * sizeof(uint8)); + memcpy(nt_devmode->private, devmode.private, nt_devmode->driverextra); + } + + + return True; +} + +/******************************************************************** + * api_spoolss_closeprinter + ********************************************************************/ +uint32 _spoolss_closeprinter(POLICY_HND *handle) +{ + if (!close_printer_handle(handle)) + return NT_STATUS_INVALID_HANDLE; + + return NT_STATUS_NO_PROBLEMO; +} + +/******************************************************************** + ********************************************************************/ +static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **data, uint32 *needed) +{ + int i; + + if (!strcmp(value, "BeepEnabled")) + { + *type = 0x4; + *data = (uint8 *)malloc( 4*sizeof(uint8) ); + SIVAL(data, 0, 0x01); + *needed = 0x4; + return True; + } + + if (!strcmp(value, "EventLog")) + { + *type = 0x4; + *data = (uint8 *)malloc( 4*sizeof(uint8) ); + SIVAL(data, 0, 0x1B); + *needed = 0x4; + return True; + } + + if (!strcmp(value, "NetPopup")) + { + *type = 0x4; + *data = (uint8 *)malloc( 4*sizeof(uint8) ); + SIVAL(data, 0, 0x01); + *needed = 0x4; + return True; + } + + if (!strcmp(value, "MajorVersion")) + { + *type = 0x4; + *data = (uint8 *)malloc( 4*sizeof(uint8) ); + SIVAL(data, 0, 0x02); + *needed = 0x4; + return True; + } + + if (!strcmp(value, "DefaultSpoolDirectory")) + { + pstring directory="You are using a Samba server"; + *type = 0x1; + *needed = 2*(strlen(directory)+1); + *data = (uint8 *)malloc(*needed *sizeof(uint8)); + ZERO_STRUCTP(*data); + + /* it's done by hand ready to go on the wire */ + for (i=0; i *out_size) + return ERROR_INSUFFICIENT_BUFFER; + else + return NT_STATUS_NO_PROBLEMO; +} + +/******************************************************************** + * _spoolss_rffpcnex + * ReplyFindFirstPrinterChangeNotifyEx + * + * jfmxxxx: before replying OK: status=0 + * should do a rpc call to the workstation asking ReplyOpenPrinter + * have to code it, later. + * + * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe + * called from api_spoolss_rffpcnex + ********************************************************************/ +uint32 _spoolss_rffpcnex(const POLICY_HND *handle, + uint32 flags, uint32 options, + const UNISTR2 *localmachine, + uint32 printerlocal, + SPOOL_NOTIFY_OPTION *option) +{ + int i,j,k; + + /* store the notify value in the printer struct */ + + i=find_printer_index_by_hnd(handle); + + if (i == -1) + { + return NT_STATUS_INVALID_HANDLE; + } + + Printer[i].number_of_notify=option->count; + + DEBUG(3,("Copying %x notify option info\n",Printer[i].number_of_notify)); + + for (j=0;jtype[j].count; + Printer[i].notify_info[j].type=option->type[j].type ; + + DEBUG(4,("Copying %x info fields of type %x\n", + Printer[i].notify_info[j].count, + Printer[i].notify_info[j].type)); + for(k=0;ktype[j].fields[k]; + } + } + + return 0x0; +} + +/******************************************************************* + * fill a notify_info_data with the servername + ********************************************************************/ +static void spoolss_notify_server_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + pstring temp_name; + + snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname); + + data->notify_data.data.length=strlen(temp_name); + ascii_to_unistr(data->notify_data.data.string, temp_name, sizeof(data->notify_data.data.string)-1); +} + +/******************************************************************* + * fill a notify_info_data with the servicename + * jfmxxxx: it's incorrect should be long_printername + ********************************************************************/ +static void spoolss_notify_printer_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ +/* + data->notify_data.data.length=strlen(lp_servicename(snum)); + ascii_to_unistr(data->notify_data.data.string, lp_servicename(snum), sizeof(data->notify_data.data.string)-1); +*/ + data->notify_data.data.length=strlen(printer->info_2->printername); + ascii_to_unistr(data->notify_data.data.string, + printer->info_2->printername, + sizeof(data->notify_data.data.string)-1); +} + +/******************************************************************* + * fill a notify_info_data with the servicename + ********************************************************************/ +static void spoolss_notify_share_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + data->notify_data.data.length=strlen(lp_servicename(snum)); + ascii_to_unistr(data->notify_data.data.string, + lp_servicename(snum), + sizeof(data->notify_data.data.string)-1); +} + +/******************************************************************* + * fill a notify_info_data with the port name + ********************************************************************/ +static void spoolss_notify_port_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + /* even if it's strange, that's consistant in all the code */ + + data->notify_data.data.length=strlen(lp_servicename(snum)); + ascii_to_unistr(data->notify_data.data.string, + lp_servicename(snum), + sizeof(data->notify_data.data.string)-1); +} + +/******************************************************************* + * fill a notify_info_data with the printername + * jfmxxxx: it's incorrect, should be lp_printerdrivername() + * but it doesn't exist, have to see what to do + ********************************************************************/ +static void spoolss_notify_driver_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + data->notify_data.data.length=strlen(printer->info_2->drivername); + ascii_to_unistr(data->notify_data.data.string, + printer->info_2->drivername, + sizeof(data->notify_data.data.string)-1); +} + +/******************************************************************* + * fill a notify_info_data with the comment + ********************************************************************/ +static void spoolss_notify_comment(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + data->notify_data.data.length=strlen(lp_comment(snum)); + ascii_to_unistr(data->notify_data.data.string, + lp_comment(snum), + sizeof(data->notify_data.data.string)-1); +} + +/******************************************************************* + * fill a notify_info_data with the comment + * jfm:xxxx incorrect, have to create a new smb.conf option + * location = "Room 1, floor 2, building 3" + ********************************************************************/ +static void spoolss_notify_location(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + data->notify_data.data.length=strlen(printer->info_2->location); + ascii_to_unistr(data->notify_data.data.string, + printer->info_2->location, + sizeof(data->notify_data.data.string)-1); +} + +/******************************************************************* + * fill a notify_info_data with the device mode + * jfm:xxxx don't to it for know but that's a real problem !!! + ********************************************************************/ +static void spoolss_notify_devmode(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ +} + +/******************************************************************* + * fill a notify_info_data with the separator file name + * jfm:xxxx just return no file could add an option to smb.conf + * separator file = "separator.txt" + ********************************************************************/ +static void spoolss_notify_sepfile(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + data->notify_data.data.length=strlen(printer->info_2->sepfile); + ascii_to_unistr(data->notify_data.data.string, + printer->info_2->sepfile, + sizeof(data->notify_data.data.string)-1); +} + +/******************************************************************* + * fill a notify_info_data with the print processor + * jfm:xxxx return always winprint to indicate we don't do anything to it + ********************************************************************/ +static void spoolss_notify_print_processor(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + data->notify_data.data.length=strlen(printer->info_2->printprocessor); + ascii_to_unistr(data->notify_data.data.string, + printer->info_2->printprocessor, + sizeof(data->notify_data.data.string)-1); +} + +/******************************************************************* + * fill a notify_info_data with the print processor options + * jfm:xxxx send an empty string + ********************************************************************/ +static void spoolss_notify_parameters(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + data->notify_data.data.length=strlen(printer->info_2->parameters); + ascii_to_unistr(data->notify_data.data.string, + printer->info_2->parameters, + sizeof(data->notify_data.data.string)-1); +} + +/******************************************************************* + * fill a notify_info_data with the data type + * jfm:xxxx always send RAW as data type + ********************************************************************/ +static void spoolss_notify_datatype(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + data->notify_data.data.length=strlen(printer->info_2->datatype); + ascii_to_unistr(data->notify_data.data.string, + printer->info_2->datatype, + sizeof(data->notify_data.data.string)-1); +} + +/******************************************************************* + * fill a notify_info_data with the security descriptor + * jfm:xxxx send an null pointer to say no security desc + * have to implement security before ! + ********************************************************************/ +static void spoolss_notify_security_desc(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + data->notify_data.data.length=0; + data->notify_data.data.string[0]=0x00; +} + +/******************************************************************* + * fill a notify_info_data with the attributes + * jfm:xxxx a samba printer is always shared + ********************************************************************/ +static void spoolss_notify_attributes(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + data->notify_data.value[0] = PRINTER_ATTRIBUTE_SHARED \ + | PRINTER_ATTRIBUTE_NETWORK \ + | PRINTER_ATTRIBUTE_RAW_ONLY ; +} + +/******************************************************************* + * fill a notify_info_data with the priority + ********************************************************************/ +static void spoolss_notify_priority(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + data->notify_data.value[0] = printer->info_2->priority; +} + +/******************************************************************* + * fill a notify_info_data with the default priority + ********************************************************************/ +static void spoolss_notify_default_priority(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + data->notify_data.value[0] = printer->info_2->default_priority; +} + +/******************************************************************* + * fill a notify_info_data with the start time + ********************************************************************/ +static void spoolss_notify_start_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + data->notify_data.value[0] = printer->info_2->starttime; +} + +/******************************************************************* + * fill a notify_info_data with the until time + ********************************************************************/ +static void spoolss_notify_until_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + data->notify_data.value[0] = printer->info_2->untiltime; +} + +/******************************************************************* + * fill a notify_info_data with the status + ********************************************************************/ +static void spoolss_notify_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + int count; + print_queue_struct *q=NULL; + print_status_struct status; + + bzero(&status,sizeof(status)); + + count=get_printqueue(snum, NULL, &q, &status); + + data->notify_data.value[0]=(uint32) status.status; + if (q) free(q); +} + +/******************************************************************* + * fill a notify_info_data with the number of jobs queued + ********************************************************************/ +static void spoolss_notify_cjobs(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + print_queue_struct *q=NULL; + print_status_struct status; + + bzero(&status,sizeof(status)); + + data->notify_data.value[0]=get_printqueue(snum, NULL, &q, &status); + if (q) free(q); +} + +/******************************************************************* + * fill a notify_info_data with the average ppm + ********************************************************************/ +static void spoolss_notify_average_ppm(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + /* always respond 8 pages per minutes */ + /* a little hard ! */ + data->notify_data.value[0] = printer->info_2->averageppm; +} + +/******************************************************************* + * fill a notify_info_data with + ********************************************************************/ +static void spoolss_notify_username(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + data->notify_data.data.length=strlen(queue->user); + ascii_to_unistr(data->notify_data.data.string, queue->user, sizeof(data->notify_data.data.string)-1); +} + +/******************************************************************* + * fill a notify_info_data with + ********************************************************************/ +static void spoolss_notify_job_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + data->notify_data.value[0]=queue->status; +} + +/******************************************************************* + * fill a notify_info_data with + ********************************************************************/ +static void spoolss_notify_job_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + data->notify_data.data.length=strlen(queue->file); + ascii_to_unistr(data->notify_data.data.string, queue->file, sizeof(data->notify_data.data.string)-1); +} + +/******************************************************************* + * fill a notify_info_data with + ********************************************************************/ +static void spoolss_notify_job_status_string(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + data->notify_data.data.length=strlen("En attente"); + ascii_to_unistr(data->notify_data.data.string, "En attente", sizeof(data->notify_data.data.string)-1); +} + +/******************************************************************* + * fill a notify_info_data with + ********************************************************************/ +static void spoolss_notify_job_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + data->notify_data.value[0]=0x0; +} + +/******************************************************************* + * fill a notify_info_data with + ********************************************************************/ +static void spoolss_notify_job_size(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + data->notify_data.value[0]=queue->size; +} + +/******************************************************************* + * fill a notify_info_data with + ********************************************************************/ +static void spoolss_notify_job_position(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + data->notify_data.value[0]=queue->job; +} + +#define END 65535 + +struct s_notify_info_data_table notify_info_data_table[] = +{ +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SERVER_NAME, "PRINTER_NOTIFY_SERVER_NAME", POINTER, spoolss_notify_server_name }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINTER_NAME, "PRINTER_NOTIFY_PRINTER_NAME", POINTER, spoolss_notify_printer_name }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SHARE_NAME, "PRINTER_NOTIFY_SHARE_NAME", POINTER, spoolss_notify_share_name }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PORT_NAME, "PRINTER_NOTIFY_PORT_NAME", POINTER, spoolss_notify_port_name }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DRIVER_NAME, "PRINTER_NOTIFY_DRIVER_NAME", POINTER, spoolss_notify_driver_name }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_COMMENT, "PRINTER_NOTIFY_COMMENT", POINTER, spoolss_notify_comment }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_LOCATION, "PRINTER_NOTIFY_LOCATION", POINTER, spoolss_notify_location }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DEVMODE, "PRINTER_NOTIFY_DEVMODE", POINTER, spoolss_notify_devmode }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SEPFILE, "PRINTER_NOTIFY_SEPFILE", POINTER, spoolss_notify_sepfile }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINT_PROCESSOR, "PRINTER_NOTIFY_PRINT_PROCESSOR", POINTER, spoolss_notify_print_processor }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PARAMETERS, "PRINTER_NOTIFY_PARAMETERS", POINTER, spoolss_notify_parameters }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DATATYPE, "PRINTER_NOTIFY_DATATYPE", POINTER, spoolss_notify_datatype }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_SECURITY_DESCRIPTOR", POINTER, spoolss_notify_security_desc }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_ATTRIBUTES, "PRINTER_NOTIFY_ATTRIBUTES", ONE_VALUE, spoolss_notify_attributes }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRIORITY, "PRINTER_NOTIFY_PRIORITY", ONE_VALUE, spoolss_notify_priority }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DEFAULT_PRIORITY, "PRINTER_NOTIFY_DEFAULT_PRIORITY", ONE_VALUE, spoolss_notify_default_priority }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_START_TIME, "PRINTER_NOTIFY_START_TIME", ONE_VALUE, spoolss_notify_start_time }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_UNTIL_TIME, "PRINTER_NOTIFY_UNTIL_TIME", ONE_VALUE, spoolss_notify_until_time }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_STATUS, "PRINTER_NOTIFY_STATUS", ONE_VALUE, spoolss_notify_status }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_STATUS_STRING, "PRINTER_NOTIFY_STATUS_STRING", POINTER, NULL }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_CJOBS, "PRINTER_NOTIFY_CJOBS", ONE_VALUE, spoolss_notify_cjobs }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_AVERAGE_PPM, "PRINTER_NOTIFY_AVERAGE_PPM", ONE_VALUE, spoolss_notify_average_ppm }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_PAGES, "PRINTER_NOTIFY_TOTAL_PAGES", POINTER, NULL }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PAGES_PRINTED, "PRINTER_NOTIFY_PAGES_PRINTED", POINTER, NULL }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_BYTES, "PRINTER_NOTIFY_TOTAL_BYTES", POINTER, NULL }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_BYTES_PRINTED, "PRINTER_NOTIFY_BYTES_PRINTED", POINTER, NULL }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINTER_NAME, "JOB_NOTIFY_PRINTER_NAME", POINTER, spoolss_notify_printer_name }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_MACHINE_NAME, "JOB_NOTIFY_MACHINE_NAME", POINTER, spoolss_notify_server_name }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_PORT_NAME, "JOB_NOTIFY_PORT_NAME", POINTER, spoolss_notify_port_name }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_USER_NAME, "JOB_NOTIFY_USER_NAME", POINTER, spoolss_notify_username }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_NOTIFY_NAME, "JOB_NOTIFY_NOTIFY_NAME", POINTER, spoolss_notify_username }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_DATATYPE, "JOB_NOTIFY_DATATYPE", POINTER, spoolss_notify_datatype }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINT_PROCESSOR, "JOB_NOTIFY_PRINT_PROCESSOR", POINTER, spoolss_notify_print_processor }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_PARAMETERS, "JOB_NOTIFY_PARAMETERS", POINTER, spoolss_notify_parameters }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_DRIVER_NAME, "JOB_NOTIFY_DRIVER_NAME", POINTER, spoolss_notify_driver_name }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_DEVMODE, "JOB_NOTIFY_DEVMODE", POINTER, spoolss_notify_devmode }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_STATUS, "JOB_NOTIFY_STATUS", ONE_VALUE, spoolss_notify_job_status }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_STATUS_STRING, "JOB_NOTIFY_STATUS_STRING", POINTER, spoolss_notify_job_status_string }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_SECURITY_DESCRIPTOR, "JOB_NOTIFY_SECURITY_DESCRIPTOR", POINTER, NULL }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_DOCUMENT, "JOB_NOTIFY_DOCUMENT", POINTER, spoolss_notify_job_name }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_PRIORITY, "JOB_NOTIFY_PRIORITY", ONE_VALUE, spoolss_notify_priority }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_POSITION, "JOB_NOTIFY_POSITION", ONE_VALUE, spoolss_notify_job_position }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_SUBMITTED, "JOB_NOTIFY_SUBMITTED", POINTER, NULL }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_START_TIME, "JOB_NOTIFY_START_TIME", ONE_VALUE, spoolss_notify_start_time }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_UNTIL_TIME, "JOB_NOTIFY_UNTIL_TIME", ONE_VALUE, spoolss_notify_until_time }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_TIME, "JOB_NOTIFY_TIME", ONE_VALUE, spoolss_notify_job_time }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_PAGES, "JOB_NOTIFY_TOTAL_PAGES", ONE_VALUE, NULL }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_PAGES_PRINTED, "JOB_NOTIFY_PAGES_PRINTED", ONE_VALUE, NULL }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_BYTES, "JOB_NOTIFY_TOTAL_BYTES", ONE_VALUE, spoolss_notify_job_size }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_BYTES_PRINTED, "JOB_NOTIFY_BYTES_PRINTED", ONE_VALUE, NULL }, +{ END, END, "", END, NULL } +}; + +/******************************************************************* +return the size of info_data structure +********************************************************************/ +static uint32 size_of_notify_info_data(uint16 type, uint16 field) +{ + int i=0; + + while (notify_info_data_table[i].type != END) + { + if ( (notify_info_data_table[i].type == type ) && + (notify_info_data_table[i].field == field ) ) + { + return (notify_info_data_table[i].size); + continue; + } + i++; + } + return (65535); +} + +/******************************************************************* +return the type of notify_info_data +********************************************************************/ +static BOOL type_of_notify_info_data(uint16 type, uint16 field) +{ + int i=0; + + while (notify_info_data_table[i].type != END) + { + if ( (notify_info_data_table[i].type == type ) && + (notify_info_data_table[i].field == field ) ) + { + if (notify_info_data_table[i].size == POINTER) + { + return (False); + } + else + { + return (True); + } + continue; + } + i++; + } + return (False); +} + +/**************************************************************************** +****************************************************************************/ +static int search_notify(uint16 type, uint16 field, int *value) +{ + int j; + BOOL found; + + DEBUG(4,("\tsearch_notify: in\n")); + for (j=0, found=False; found==False && notify_info_data_table[j].type != END ; j++) + { + if ( (notify_info_data_table[j].type == type ) && + (notify_info_data_table[j].field == field ) ) + { + found=True; + } + } + *value=--j; + + if ( found && (notify_info_data_table[j].fn != NULL) ) + { + DEBUG(4,("\tsearch_notify: out TRUE\n")); + return (True); + } + else + { + DEBUG(4,("\tsearch_notify: out FALSE\n")); + return (False); + } +} + +/**************************************************************************** +****************************************************************************/ +static void construct_info_data(SPOOL_NOTIFY_INFO_DATA *info_data, uint16 type, uint16 field, int id) +{ + DEBUG(4,("\tconstruct_info_data: in\n")); + info_data->type = type; + info_data->field = field; + info_data->id = id; + info_data->size = size_of_notify_info_data(type, field); + info_data->enc_type = type_of_notify_info_data(type, field); + DEBUG(4,("\tconstruct_info_data: out\n")); +} + + +/******************************************************************* + * + * fill a notify_info struct with info asked + * + ********************************************************************/ +static void construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int pnum, + int snum, int i, uint32 id) +{ + + int k,j; + uint16 type; + uint16 field; + + SPOOL_NOTIFY_INFO_DATA *info_data; + print_queue_struct *queue=NULL; + NT_PRINTER_INFO_LEVEL printer; + + DEBUG(4,("construct_notify_printer_info\n")); + + info_data=&(info->data[info->count]); + + type = Printer[pnum].notify_info[i].type; + + DEBUGADD(4,("Notify number %d -> number of notify info: %d\n",i,Printer[pnum].notify_info[i].count)); + + if (!get_a_printer(&printer, 2, lp_servicename(snum))) + { + + for(k=0; kcount++; + info_data=&(info->data[info->count]); + } + } + + free_a_printer(printer, 2); + } +} + +/******************************************************************* + * + * fill a notify_info struct with info asked + * + ********************************************************************/ +static void construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_INFO *info, + int pnum, int snum, int i, uint32 id) +{ + + int k,j; + uint16 type; + uint16 field; + + SPOOL_NOTIFY_INFO_DATA *info_data; + NT_PRINTER_INFO_LEVEL printer; + + DEBUG(4,("construct_notify_jobs_info\n")); + info_data=&(info->data[info->count]); + + type = Printer[pnum].notify_info[i].type; + + DEBUGADD(4,("Notify number %d -> number of notify info: %d\n",i,Printer[pnum].notify_info[i].count)); + + if (!get_a_printer(&printer, 2, lp_servicename(snum))) + { + for(k=0; kcount++; + info_data=&(info->data[info->count]); + } + } + free_a_printer(printer, 2); + } +} + + +/******************************************************************* + * + * enumerate all printers on the printserver + * fill a notify_info struct with info asked + * + ********************************************************************/ +static uint32 printserver_notify_info(const POLICY_HND *hnd, + SPOOL_NOTIFY_INFO *info) +{ + int snum; + int pnum=find_printer_index_by_hnd(hnd); + int n_services=lp_numservices(); + int i=0; + uint32 id=1; + info->count=0; + + if (pnum == -1) + { + return NT_STATUS_INVALID_HANDLE; + } + + DEBUG(4,("Enumerating printers\n")); + + for (i=0; icount=0; + + if (pnum == -1 || !get_printer_snum(hnd, &snum) ) + { + return NT_STATUS_INVALID_HANDLE; + } + + for (i=0; iprintername); + + init_unistr(&(printer->printername), chaine); + + slprintf(chaine,sizeof(chaine)-1,"\\\\%s", servername); + init_unistr(&(printer->servername), chaine); + + printer->cjobs = count; + printer->attributes = PRINTER_ATTRIBUTE_SHARED \ + | PRINTER_ATTRIBUTE_NETWORK \ + | PRINTER_ATTRIBUTE_RAW_ONLY ; + printer->unknown0 = 0x1; /* pointer */ + printer->unknown1 = 0x000A07CE; /* don't known */ + printer->unknown2 = 0x00020005; + printer->unknown3 = 0x0006000D; + printer->unknown4 = 0x02180026; + printer->unknown5 = 0x09; + printer->unknown6 = 0x36; + printer->majorversion = 0x0004; /* NT 4 */ + printer->buildversion = 0x0565; /* build 1381 */ + printer->unknown7 = 0x1; + printer->unknown8 = 0x0; + printer->unknown9 = 0x2; + printer->unknown10 = 0x3; + printer->unknown11 = 0x0; + printer->unknown12 = 0x0; + printer->unknown13 = 0x0; + printer->unknown14 = 0x1; + printer->unknown15 = 0x024a; /*586 Pentium ? */ + printer->unknown16 = 0x0; + printer->unknown17 = 0x423ed444; + printer->unknown18 = 0x0; + printer->status = status.status; + printer->unknown20 = 0x0; + printer->unknown21 = 0x0648; + printer->unknown22 = 0x0; + printer->unknown23 = 0x5; + + safe_free(queue); + + free_a_printer(ntprinter, 2); + return (True); +} + +/******************************************************************** + * construct_printer_info_1 + * fill a printer_info_1 struct + ********************************************************************/ +static BOOL construct_printer_info_1(PRINTER_INFO_1 *printer,int snum, pstring servername) +{ + pstring chaine; + NT_PRINTER_INFO_LEVEL ntprinter; + + if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) != 0) + { + return (False); + } + + printer->flags=PRINTER_ENUM_NAME; + + /* the description and the name are of the form \\server\share */ + slprintf(chaine,sizeof(chaine)-1,"\\\\%s\\%s,%s,%s",servername, + ntprinter.info_2->printername, + ntprinter.info_2->drivername, + lp_comment(snum)); + init_unistr(&(printer->description), chaine); + + slprintf(chaine,sizeof(chaine)-1,"\\\\%s\\%s", servername, ntprinter.info_2->printername); + init_unistr(&(printer->name), chaine); + + init_unistr(&(printer->comment), lp_comment(snum)); + + free_a_printer(ntprinter, 2); + return (True); +} + +/**************************************************************************** +****************************************************************************/ +static void construct_dev_mode(DEVICEMODE *devmode, int snum, char *servername) +{ + char adevice[32]; + char aform[32]; + NT_PRINTER_INFO_LEVEL printer; + NT_DEVICEMODE *ntdevmode; + + DEBUG(7,("construct_dev_mode\n")); + + bzero(&(devmode->devicename), 2*sizeof(adevice)); + bzero(&(devmode->formname), 2*sizeof(aform)); + + DEBUGADD(8,("getting printer characteristics\n")); + + get_a_printer(&printer, 2, lp_servicename(snum)); + ntdevmode=(printer.info_2)->devmode; + + DEBUGADD(8,("loading DEVICEMODE\n")); + snprintf(adevice, sizeof(adevice), "\\\\%s\\%s", global_myname, + printer.info_2->printername); + init_unistr(&(devmode->devicename), adevice); + + snprintf(aform, sizeof(aform), ntdevmode->formname); + init_unistr(&(devmode->formname), aform); + + devmode->specversion = ntdevmode->specversion; + devmode->driverversion = ntdevmode->driverversion; + devmode->size = ntdevmode->size; + devmode->driverextra = ntdevmode->driverextra; + devmode->fields = ntdevmode->fields; + + devmode->orientation = ntdevmode->orientation; + devmode->papersize = ntdevmode->papersize; + devmode->paperlength = ntdevmode->paperlength; + devmode->paperwidth = ntdevmode->paperwidth; + devmode->scale = ntdevmode->scale; + devmode->copies = ntdevmode->copies; + devmode->defaultsource = ntdevmode->defaultsource; + devmode->printquality = ntdevmode->printquality; + devmode->color = ntdevmode->color; + devmode->duplex = ntdevmode->duplex; + devmode->yresolution = ntdevmode->yresolution; + devmode->ttoption = ntdevmode->ttoption; + devmode->collate = ntdevmode->collate; + devmode->icmmethod = ntdevmode->icmmethod; + devmode->icmintent = ntdevmode->icmintent; + devmode->mediatype = ntdevmode->mediatype; + devmode->dithertype = ntdevmode->dithertype; + + if (ntdevmode->private != NULL) + { + devmode->private=(uint8 *)malloc(devmode->driverextra*sizeof(uint8)); + memcpy(devmode->private, ntdevmode->private, devmode->driverextra); + } + + free_a_printer(printer, 2); +} + +/******************************************************************** + * construct_printer_info_2 + * fill a printer_info_2 struct + ********************************************************************/ +static BOOL construct_printer_info_2(PRINTER_INFO_2 *printer, int snum, pstring servername) +{ + pstring chaine; + int count; + DEVICEMODE *devmode; + NT_PRINTER_INFO_LEVEL ntprinter; + + print_queue_struct *queue=NULL; + print_status_struct status; + bzero(&status, sizeof(status)); + count=get_printqueue(snum, NULL, &queue, &status); + + if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0 ) + { + return (False); + } + + snprintf(chaine, sizeof(chaine)-1, "\\\\%s", servername); + init_unistr(&(printer->servername), chaine); /* servername*/ + + snprintf(chaine, sizeof(chaine)-1, "\\\\%s\\%s", servername, ntprinter.info_2->printername); + init_unistr(&(printer->printername), chaine); /* printername*/ + + init_unistr(&(printer->sharename), lp_servicename(snum)); /* sharename */ + + init_unistr(&(printer->portname), lp_servicename(snum)); /* port */ + init_unistr(&(printer->drivername), ntprinter.info_2->drivername); /* drivername */ + + init_unistr(&(printer->comment), ntprinter.info_2->comment); /* comment */ + init_unistr(&(printer->location), ntprinter.info_2->location); /* location */ + init_unistr(&(printer->sepfile), ntprinter.info_2->sepfile); /* separator file */ + init_unistr(&(printer->printprocessor), ntprinter.info_2->printprocessor);/* print processor */ + init_unistr(&(printer->datatype), ntprinter.info_2->datatype); /* datatype */ + init_unistr(&(printer->parameters), ntprinter.info_2->parameters); /* parameters (of print processor) */ + + printer->attributes = PRINTER_ATTRIBUTE_SHARED \ + | PRINTER_ATTRIBUTE_NETWORK \ + | PRINTER_ATTRIBUTE_RAW_ONLY ; /* attributes */ + + printer->priority = ntprinter.info_2->priority; /* priority */ + printer->defaultpriority = ntprinter.info_2->default_priority; /* default priority */ + printer->starttime = ntprinter.info_2->starttime; /* starttime */ + printer->untiltime = ntprinter.info_2->untiltime; /* untiltime */ + printer->status = status.status; /* status */ + printer->cjobs = count; /* jobs */ + printer->averageppm = ntprinter.info_2->averageppm; /* average pages per minute */ + + devmode=(DEVICEMODE *)malloc(sizeof(DEVICEMODE)); + ZERO_STRUCTP(devmode); + construct_dev_mode(devmode, snum, servername); + printer->devmode=devmode; + + safe_free(queue); + free_a_printer(ntprinter, 2); + return (True); +} + +/******************************************************************** + * enum_printer_info_1 + * glue between spoolss_enumprinters and construct_printer_info_1 + ********************************************************************/ +static BOOL enum_printer_info_1(PRINTER_INFO_1 **printer, int snum, int number) +{ + pstring servername; + + *printer=(PRINTER_INFO_1 *)malloc(sizeof(PRINTER_INFO_1)); + DEBUG(4,("Allocated memory for ONE PRINTER_INFO_1 at [%p]\n", *printer)); + pstrcpy(servername, global_myname); + if (!construct_printer_info_1(*printer, snum, servername)) + { + free(*printer); + return (False); + } + else + { + return (True); + } +} + +/******************************************************************** + * enum_printer_info_2 + * glue between spoolss_enumprinters and construct_printer_info_2 + ********************************************************************/ +static BOOL enum_printer_info_2(PRINTER_INFO_2 **printer, int snum, int number) +{ + pstring servername; + + *printer=(PRINTER_INFO_2 *)malloc(sizeof(PRINTER_INFO_2)); + DEBUG(4,("Allocated memory for ONE PRINTER_INFO_2 at [%p]\n", *printer)); + pstrcpy(servername, global_myname); + if (!construct_printer_info_2(*printer, snum, servername)) + { + free(*printer); + return (False); + } + else + { + return (True); + } +} + +/******************************************************************** + * spoolss_enumprinters + * + * called from api_spoolss_enumprinters (see this to understand) + ********************************************************************/ +static void enum_all_printers_info_1(PRINTER_INFO_1 ***printers, uint32 *number) +{ + int snum; + int n_services=lp_numservices(); + *printers=NULL; + *number=0; + + for (snum=0;snumprinter.printers_1, returned ); + /*else + enum_one_printer_info_1(&r_u);*/ + break; + } + case 2: + if (flags == PRINTER_ENUM_NAME || + flags == PRINTER_ENUM_NETWORK ) + { + /*if (is_a_printerserver(servername))*/ + enum_all_printers_info_2(&ctr->printer.printers_2, returned ); + /*else + enum_one_printer_info_2(&r_u);*/ + break; + } + case 3: /* doesn't exist */ + return NT_STATUS_INVALID_INFO_CLASS; + case 4: /* can't, always on local machine */ + break; + case 5: + return NT_STATUS_INVALID_INFO_CLASS; + + } + DEBUG(4,("%d printers enumerated\n", *returned)); + (*offered) = buffer->size; + + return 0x0; +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_getprinter( POLICY_HND *handle, + uint32 level, + PRINTER_INFO *ctr, + uint32 *offered, + uint32 *needed) +{ + int snum; + pstring servername; + + pstrcpy(servername, global_myname); + + if (!get_printer_snum(handle,&snum)) + { + return NT_STATUS_INVALID_HANDLE; + } + + DEBUG(0,("_spoolss_getprinter: offered and needed params ignored\n")); + + switch (level) + { + case 0: + { + PRINTER_INFO_0 *printer; + + printer=(PRINTER_INFO_0*)malloc(sizeof(PRINTER_INFO_0)); + construct_printer_info_0(printer, snum, servername); + ctr->printer.info0=printer; + + return 0x0; + } + case 1: + { + PRINTER_INFO_1 *printer; + + printer=(PRINTER_INFO_1*)malloc(sizeof(PRINTER_INFO_1)); + construct_printer_info_1(printer, snum, servername); + ctr->printer.info1=printer; + + return 0x0; + } + case 2: + { + PRINTER_INFO_2 *printer; + + printer=(PRINTER_INFO_2*)malloc(sizeof(PRINTER_INFO_2)); + construct_printer_info_2(printer, snum, servername); + ctr->printer.info2=printer; + + return 0x0; + } + default: + { + break; + } + } + + return NT_STATUS_INVALID_INFO_CLASS; +} + +/******************************************************************** + * construct_printer_driver_info_1 + * fill a construct_printer_driver_info_1 struct + ********************************************************************/ +static void fill_printer_driver_info_1(DRIVER_INFO_1 *info, + NT_PRINTER_DRIVER_INFO_LEVEL driver, + pstring servername, fstring architecture) +{ + init_unistr( &(info->name), driver.info_3->name); +} + +static void construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, + pstring servername, fstring architecture) +{ + NT_PRINTER_INFO_LEVEL printer; + NT_PRINTER_DRIVER_INFO_LEVEL driver; + + get_a_printer(&printer, 2, lp_servicename(snum) ); + get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture); + + fill_printer_driver_info_1(info, driver, servername, architecture); + + free_a_printer_driver(driver, 3); + free_a_printer(printer, 2); +} + +/******************************************************************** + * construct_printer_driver_info_2 + * fill a printer_info_2 struct + ********************************************************************/ +static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, + NT_PRINTER_DRIVER_INFO_LEVEL driver, + pstring servername, fstring architecture) +{ + pstring where; + pstring temp_driverpath; + pstring temp_datafile; + pstring temp_configfile; + fstring short_archi; + + get_short_archi(short_archi,architecture); + + snprintf(where,sizeof(where)-1,"\\\\%s\\print$\\%s\\", servername, short_archi); + + info->version=driver.info_3->cversion; + + init_unistr( &(info->name), driver.info_3->name ); + init_unistr( &(info->architecture), architecture ); + + snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "%s%s", where, + driver.info_3->driverpath); + init_unistr( &(info->driverpath), temp_driverpath ); + + snprintf(temp_datafile, sizeof(temp_datafile)-1, "%s%s", where, + driver.info_3->datafile); + init_unistr( &(info->datafile), temp_datafile ); + + snprintf(temp_configfile, sizeof(temp_configfile)-1, "%s%s", where, + driver.info_3->configfile); + init_unistr( &(info->configfile), temp_configfile ); +} + +/******************************************************************** + * construct_printer_driver_info_2 + * fill a printer_info_2 struct + ********************************************************************/ +static void construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, + pstring servername, fstring architecture) +{ + NT_PRINTER_INFO_LEVEL printer; + NT_PRINTER_DRIVER_INFO_LEVEL driver; + + get_a_printer(&printer, 2, lp_servicename(snum) ); + get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture); + + fill_printer_driver_info_2(info, driver, servername, architecture); + + free_a_printer_driver(driver, 3); + free_a_printer(printer, 2); +} + +/******************************************************************** + * copy a strings array and convert to UNICODE + ********************************************************************/ +static void init_unistr_array(UNISTR ***uni_array, char **char_array, char *where) +{ + int i=0; + char *v; + pstring line; + + DEBUG(6,("init_unistr_array\n")); + + for (v=char_array[i]; *v!='\0'; v=char_array[i]) + { + DEBUGADD(6,("i:%d:", i)); + DEBUGADD(6,("%s:%d:", v, strlen(v))); + + *uni_array=(UNISTR **)Realloc(*uni_array, sizeof(UNISTR *)*(i+1)); + DEBUGADD(7,("realloc:[%p],", *uni_array)); + + (*uni_array)[i]=(UNISTR *)malloc( sizeof(UNISTR) ); + DEBUGADD(7,("alloc:[%p],", (*uni_array)[i])); + + snprintf(line, sizeof(line)-1, "%s%s", where, v); + init_unistr( (*uni_array)[i], line ); + DEBUGADD(7,("copy\n")); + + i++; + } + DEBUGADD(7,("last one\n")); + + *uni_array=(UNISTR **)Realloc(*uni_array, sizeof(UNISTR *)*(i+1)); + (*uni_array)[i]=0x0000; + DEBUGADD(6,("last one:done\n")); +} + +/******************************************************************** + * construct_printer_info_3 + * fill a printer_info_3 struct + ********************************************************************/ +static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, + NT_PRINTER_DRIVER_INFO_LEVEL driver, + pstring servername, fstring architecture) +{ + pstring where; + pstring temp_driverpath; + pstring temp_datafile; + pstring temp_configfile; + pstring temp_helpfile; + fstring short_archi; + + get_short_archi(short_archi, architecture); + + snprintf(where,sizeof(where)-1,"\\\\%s\\print$\\%s\\", servername, short_archi); + + info->version=driver.info_3->cversion; + + init_unistr( &(info->name), driver.info_3->name ); + init_unistr( &(info->architecture), architecture ); + + snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "%s%s", where, driver.info_3->driverpath); + init_unistr( &(info->driverpath), temp_driverpath ); + + snprintf(temp_datafile, sizeof(temp_datafile)-1, "%s%s", where, driver.info_3->datafile); + init_unistr( &(info->datafile), temp_datafile ); + + snprintf(temp_configfile, sizeof(temp_configfile)-1, "%s%s", where, driver.info_3->configfile); + init_unistr( &(info->configfile), temp_configfile ); + + snprintf(temp_helpfile, sizeof(temp_helpfile)-1, "%s%s", where, driver.info_3->helpfile); + init_unistr( &(info->helpfile), temp_helpfile ); + + init_unistr( &(info->monitorname), driver.info_3->monitorname ); + init_unistr( &(info->defaultdatatype), driver.info_3->defaultdatatype ); + + info->dependentfiles=NULL; + init_unistr_array(&(info->dependentfiles), driver.info_3->dependentfiles, where); +} + +/******************************************************************** + * construct_printer_info_3 + * fill a printer_info_3 struct + ********************************************************************/ +static void construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, + pstring servername, fstring architecture) +{ + NT_PRINTER_INFO_LEVEL printer; + NT_PRINTER_DRIVER_INFO_LEVEL driver; + + get_a_printer(&printer, 2, lp_servicename(snum) ); + get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture); + + fill_printer_driver_info_3(info, driver, servername, architecture); + + free_a_printer_driver(driver, 3); + free_a_printer(printer, 2); +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_getprinterdriver2( const POLICY_HND *handle, + const UNISTR2 *uni_arch, + uint32 level, + DRIVER_INFO *ctr, + uint32 *offered, + uint32 *needed) +{ + pstring servername; + fstring architecture; + int snum; + DRIVER_INFO_1 *info1=NULL; + DRIVER_INFO_2 *info2=NULL; + DRIVER_INFO_3 *info3=NULL; + + pstrcpy(servername, global_myname); + + if (!get_printer_snum(handle,&snum)) + { + return NT_STATUS_INVALID_HANDLE; + } + + unistr2_to_ascii(architecture, uni_arch, sizeof(architecture) ); + + DEBUG(1,("spoolss_getprinterdriver2:[%d]\n", level)); + + switch (level) + { + case 1: + { + info1=(DRIVER_INFO_1 *)malloc(sizeof(DRIVER_INFO_1)); + construct_printer_driver_info_1(info1, snum, servername, architecture); + ctr->driver.info1=info1; + + return 0x0; + } + case 2: + { + info2=(DRIVER_INFO_2 *)malloc(sizeof(DRIVER_INFO_2)); + construct_printer_driver_info_2(info2, snum, servername, architecture); + ctr->driver.info2=info2; + + return 0x0; + } + case 3: + { + info3=(DRIVER_INFO_3 *)malloc(sizeof(DRIVER_INFO_3)); + construct_printer_driver_info_3(info3, snum, servername, architecture); + ctr->driver.info3=info3; + + return 0x0; + } + default: + { + break; + } + } + return NT_STATUS_INVALID_INFO_CLASS; +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_startpageprinter(const POLICY_HND *handle) +{ + int pnum = find_printer_index_by_hnd(handle); + + if (OPEN_HANDLE(pnum)) + { + Printer[pnum].page_started=True; + return 0x0; + } + + DEBUG(3,("Error in startpageprinter printer handle (pnum=%x)\n",pnum)); + return NT_STATUS_INVALID_HANDLE; +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_endpageprinter(const POLICY_HND *handle) +{ + int pnum = find_printer_index_by_hnd(handle); + + if (OPEN_HANDLE(pnum)) + { + Printer[pnum].page_started=False; + return 0x0; + } + + DEBUG(3,("Error in endpageprinter printer handle (pnum=%x)\n",pnum)); + return NT_STATUS_INVALID_HANDLE; +} + + +/******************************************************************** + * api_spoolss_getprinter + * called from the spoolss dispatcher + * + ********************************************************************/ +uint32 _spoolss_startdocprinter( const POLICY_HND *handle, uint32 level, + DOC_INFO *docinfo, uint32 *jobid) +{ + DOC_INFO_1 *info_1 = &docinfo->doc_info_1; + + pstring fname; + pstring tempname; + pstring datatype; + int fd = -1; + int snum; + int pnum; + + pnum = find_printer_index_by_hnd(handle); + + if (!VALID_HANDLE(pnum)) + { + return NT_STATUS_INVALID_HANDLE; + } + + /* + * a nice thing with NT is it doesn't listen to what you tell it. + * when asked to send _only_ RAW datas, it tries to send datas + * in EMF format. + * + * So I add checks like in NT Server ... + * + * lkclXXXX jean-francois, i love this kind of thing. oh, well, + * there's a bug in NT client-side code, so we'll fix it in the + * server-side code. *nnnnnggggh!* + */ + + if (info_1->p_datatype != 0) + { + unistr2_to_ascii(datatype, &(info_1->docname), sizeof(datatype)); + if (strcmp(datatype, "RAW") != 0) + { + (*jobid)=0; + return STATUS_1804; + } + } + + /* get the share number of the printer */ + if (!get_printer_snum(handle, &snum)) + { + return NT_STATUS_INVALID_HANDLE; + } + + /* Create a temporary file in the printer spool directory + * and open it + */ + + slprintf(tempname,sizeof(tempname)-1, "%s/smb_print.XXXXXX",lp_pathname(snum)); + pstrcpy(fname, (char *)mktemp(tempname)); + + fd=open(fname, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR ); + DEBUG(4,("Temp spool file created: [%s]\n", fname)); + + Printer[pnum].current_jobid=fd; + pstrcpy(Printer[pnum].document_name,fname); + + unistr2_to_ascii(Printer[pnum].job_name, + &info_1->docname, + sizeof(Printer[pnum].job_name)); + + Printer[pnum].document_fd=fd; + Printer[pnum].document_started=True; + (*jobid) = Printer[pnum].current_jobid; + + return 0x0; +} + +/******************************************************************** + * api_spoolss_getprinter + * called from the spoolss dispatcher + * + ********************************************************************/ +uint32 _spoolss_enddocprinter(const POLICY_HND *handle) +{ + int pnum; + int snum; + pstring filename; + pstring filename1; + pstring job_name; + pstring syscmd; + char *tstr; + + *syscmd=0; + + pnum = find_printer_index_by_hnd(handle); + + if (!OPEN_HANDLE(pnum)) + { + DEBUG(3,("Error in enddocprinter handle (pnum=%x)\n",pnum)); + return NT_STATUS_INVALID_HANDLE; + } + Printer[pnum].document_started=False; + close(Printer[pnum].document_fd); + DEBUG(4,("Temp spool file closed, printing now ...\n")); + + pstrcpy(filename1, Printer[pnum].document_name); + pstrcpy(job_name, Printer[pnum].job_name); + + if (!get_printer_snum(handle,&snum)) + { + return NT_STATUS_INVALID_HANDLE; + } + + /* copy the command into the buffer for extensive meddling. */ + StrnCpy(syscmd, lp_printcommand(snum), sizeof(pstring) - 1); + + /* look for "%s" in the string. If there is no %s, we cannot print. */ + if (!strstr(syscmd, "%s") && !strstr(syscmd, "%f")) + { + DEBUG(2,("WARNING! No placeholder for the filename in the print command for service %s!\n", SERVICE(snum))); + } + + if (strstr(syscmd,"%s")) + { + pstrcpy(filename,filename1); + pstring_sub(syscmd, "%s", filename); + } + + pstring_sub(syscmd, "%f", filename1); + + /* Does the service have a printername? If not, make a fake and empty + * printer name. That way a %p is treated sanely if no printer + * name was specified to replace it. This eventuality is logged. + */ + + tstr = lp_printername(snum); + if (tstr == NULL || tstr[0] == '\0') + { + DEBUG(3,( "No printer name - using %s.\n", SERVICE(snum))); + tstr = SERVICE(snum); + } + + pstring_sub(syscmd, "%p", tstr); + + /* If the lpr command support the 'Job' option replace here */ + pstring_sub(syscmd, "%j", job_name); + + if ( *syscmd != '\0') + { + int ret = smbrun(syscmd, NULL, False); + DEBUG(3,("Running the command `%s' gave %d\n", syscmd, ret)); + if (ret < 0) + { + lpq_reset(snum); + return NT_STATUS_ACCESS_DENIED; + } + } + else + { + DEBUG(0,("Null print command?\n")); + lpq_reset(snum); + return NT_STATUS_ACCESS_DENIED; + } + + lpq_reset(snum); + + return 0x0; +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_writeprinter( const POLICY_HND *handle, + uint32 buffer_size, + const uint8 *buffer, + uint32 *buffer_written) +{ + int pnum; + int fd; + + pnum = find_printer_index_by_hnd(handle); + + if (!OPEN_HANDLE(pnum)) + { + DEBUG(3,("Error in writeprinter handle (pnum=%x)\n",pnum)); + return NT_STATUS_INVALID_HANDLE; + } + + fd = Printer[pnum].document_fd; + (*buffer_written) = write(fd, buffer, buffer_size); + Printer[pnum].document_lastwritten = (*buffer_written); + + return 0x0; +} + +/******************************************************************** + * api_spoolss_getprinter + * called from the spoolss dispatcher + * + ********************************************************************/ +static uint32 control_printer(const POLICY_HND *handle, uint32 command) +{ + int pnum; + int snum; + pnum = find_printer_index_by_hnd(handle); + + if ( pnum == -1 || !get_printer_snum(handle, &snum) ) + { + return NT_STATUS_INVALID_HANDLE; + } + + switch (command) + { + case PRINTER_CONTROL_PAUSE: + /* pause the printer here */ + status_printqueue(NULL, snum, LPSTAT_STOPPED); + return 0x0; + + case PRINTER_CONTROL_RESUME: + case PRINTER_CONTROL_UNPAUSE: + /* UN-pause the printer here */ + status_printqueue(NULL, snum, LPSTAT_OK); + return 0x0; + case PRINTER_CONTROL_PURGE: + /* Envoi des dragées FUCA dans l'imprimante */ + break; + } + + return NT_STATUS_INVALID_INFO_CLASS; +} + +/******************************************************************** + * called by spoolss_api_setprinter + * when updating a printer description + ********************************************************************/ +static uint32 update_printer(const POLICY_HND *handle, uint32 level, + const SPOOL_PRINTER_INFO_LEVEL *info, + const DEVICEMODE *devmode) +{ + int pnum; + int snum; + NT_PRINTER_INFO_LEVEL printer; + NT_DEVICEMODE *nt_devmode; + uint32 status = 0x0; + + nt_devmode=NULL; + + DEBUG(8,("update_printer\n")); + + if (level!=2) + { + DEBUG(0,("Send a mail to samba-bugs@samba.org\n")); + DEBUGADD(0,("with the following message: update_printer: level!=2\n")); + return NT_STATUS_INVALID_INFO_CLASS; + } + + pnum = find_printer_index_by_hnd(handle); + if ( pnum == -1 || !get_printer_snum(handle, &snum) ) + { + return NT_STATUS_INVALID_HANDLE; + } + get_a_printer(&printer, level, lp_servicename(snum)); + + DEBUGADD(8,("Converting info_2 struct\n")); + convert_printer_info(info, &printer, level); + + if ((info->info_2)->devmode_ptr != 0) + { + /* we have a valid devmode + convert it and link it*/ + + /* the nt_devmode memory is already alloced + * while doing the get_a_printer call + * but the devmode private part is not + * it's done by convert_devicemode + */ + DEBUGADD(8,("Converting the devicemode struct\n")); + nt_devmode=printer.info_2->devmode; + + init_devicemode(nt_devmode); + + convert_devicemode(*devmode, nt_devmode); + } + else + { + if (printer.info_2->devmode != NULL) + { + free(printer.info_2->devmode); + } + printer.info_2->devmode=NULL; + } + + if (status == 0x0) + { + status = add_a_printer(printer, level); + } + if (status == 0x0) + { + status = free_a_printer(printer, level); + } + + return status; +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_setprinter( const POLICY_HND *handle, + uint32 level, + const SPOOL_PRINTER_INFO_LEVEL *info, + const DEVICEMODE *devmode, + uint32 sec_buf_size, + const char *sec_buf, + uint32 command) +{ + int pnum = find_printer_index_by_hnd(handle); + + if (!OPEN_HANDLE(pnum)) + { + return NT_STATUS_INVALID_HANDLE; + } + /* check the level */ + switch (level) + { + case 0: return control_printer(handle, command); + case 2: return update_printer(handle, level, info, devmode); + } + + return NT_STATUS_INVALID_INFO_CLASS; +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_fcpn( const POLICY_HND *handle) +{ + return 0x0; +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_addjob( const POLICY_HND *handle, uint32 level, + const BUFFER *buffer, + uint32 buf_size) +{ + return 0x0; +} + +/**************************************************************************** +****************************************************************************/ +static void fill_job_info_1(JOB_INFO_1 *job_info, print_queue_struct *queue, + int position, int snum) +{ + pstring temp_name; + + struct tm *t; + time_t unixdate = time(NULL); + + t=gmtime(&unixdate); + snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname); + + job_info->jobid=queue->job; + init_unistr(&(job_info->printername), lp_servicename(snum)); + init_unistr(&(job_info->machinename), temp_name); + init_unistr(&(job_info->username), queue->user); + init_unistr(&(job_info->document), queue->file); + init_unistr(&(job_info->datatype), "RAW"); + init_unistr(&(job_info->text_status), ""); + job_info->status=queue->status; + job_info->priority=queue->priority; + job_info->position=position; + job_info->totalpages=0; + job_info->pagesprinted=0; + + make_systemtime(&(job_info->submitted), t); +} + +/**************************************************************************** +****************************************************************************/ +static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, + int position, int snum) +{ + pstring temp_name; + DEVICEMODE *devmode; + NT_PRINTER_INFO_LEVEL ntprinter; + pstring chaine; + + struct tm *t; + time_t unixdate = time(NULL); + + if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0 ) + { + return (False); + } + + t=gmtime(&unixdate); + snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname); + + job_info->jobid=queue->job; + + snprintf(chaine, sizeof(chaine)-1, "\\\\%s\\%s", global_myname, ntprinter.info_2->printername); + init_unistr(&(job_info->printername), chaine); + + init_unistr(&(job_info->machinename), temp_name); + init_unistr(&(job_info->username), queue->user); + init_unistr(&(job_info->document), queue->file); + init_unistr(&(job_info->notifyname), queue->user); + init_unistr(&(job_info->datatype), "RAW"); + init_unistr(&(job_info->printprocessor), "winprint"); + init_unistr(&(job_info->parameters), ""); + init_unistr(&(job_info->text_status), ""); + +/* and here the security descriptor */ + + job_info->status=queue->status; + job_info->priority=queue->priority; + job_info->position=position; + job_info->starttime=0; + job_info->untiltime=0; + job_info->totalpages=0; + job_info->size=queue->size; + make_systemtime(&(job_info->submitted), t); + job_info->timeelapsed=0; + job_info->pagesprinted=0; + + devmode=(DEVICEMODE *)malloc(sizeof(DEVICEMODE)); + ZERO_STRUCTP(devmode); + construct_dev_mode(devmode, snum, global_myname); + job_info->devmode=devmode; + + free_a_printer(ntprinter, 2); + return (True); +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_enumjobs( const POLICY_HND *handle, + uint32 reqfirstjob, + uint32 reqnumofjobs, + uint32 level, + JOB_INFO_CTR *ctr, + uint32 *buf_size, + uint32 *numofjobs) +{ + int snum; + int count; + int i; + print_queue_struct *queue=NULL; + print_status_struct prt_status; + + DEBUG(4,("spoolss_enumjobs\n")); + + ZERO_STRUCT(prt_status); + + if (!get_printer_snum(handle, &snum)) + { + return NT_STATUS_INVALID_HANDLE; + } + + count = get_printqueue(snum, NULL, &queue, &prt_status); + (*numofjobs) = 0; + + DEBUG(4,("count:[%d], status:[%d], [%s]\n", + count, prt_status.status, prt_status.message)); + + switch (level) + { + case 1: + { + for (i=0; ijob.job_info_1, + job_info_1); + + fill_job_info_1(ctr->job.job_info_1[i], + &(queue[i]), i, snum); + } + safe_free(queue); + return 0x0; + } + case 2: + { + for (i=0; ijob.job_info_2, + job_info_2); + + fill_job_info_2(ctr->job.job_info_2[i], + &(queue[i]), i, snum); + } + safe_free(queue); + return 0x0; + } + } + + safe_free(queue); + + return NT_STATUS_INVALID_INFO_CLASS; +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_schedulejob( const POLICY_HND *handle, uint32 jobid) +{ + return 0x0; +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_setjob( const POLICY_HND *handle, + uint32 jobid, + uint32 level, + JOB_INFO *ctr, + uint32 command) + +{ + int snum; + print_queue_struct *queue=NULL; + print_status_struct prt_status; + int i=0; + BOOL found=False; + int count; + + bzero(&prt_status,sizeof(prt_status)); + + if (!get_printer_snum(handle, &snum)) + { + return NT_STATUS_INVALID_HANDLE; + } + + count=get_printqueue(snum, NULL, &queue, &prt_status); + + while ( (idriver.info1=driver_info_1; + break; + } + case 2: + { + DRIVER_INFO_2 *driver_info_2=NULL; + driver_info_2=(DRIVER_INFO_2 *)malloc(count*sizeof(DRIVER_INFO_2)); + + for (i=0; idriver.info2=driver_info_2; + break; + } + case 3: + { + DRIVER_INFO_3 *driver_info_3=NULL; + driver_info_3=(DRIVER_INFO_3 *)malloc(count*sizeof(DRIVER_INFO_3)); + + for (i=0; idriver.info3=driver_info_3; + break; + } + default: + { + return NT_STATUS_INVALID_INFO_CLASS; + } + } + return 0x0; + +} + +/**************************************************************************** +****************************************************************************/ +static void fill_form_1(FORM_1 *form, nt_forms_struct *list, int position) +{ + form->flag=list->flag; + init_unistr(&(form->name), list->name); + form->width=list->width; + form->length=list->length; + form->left=list->left; + form->top=list->top; + form->right=list->right; + form->bottom=list->bottom; +} + +/**************************************************************************** +****************************************************************************/ +static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size) +{ + prs_struct *ps; + uint32 extra_space; + + ps=&(buffer->prs); + + /* damn, I'm doing the reverse operation of prs_grow() :) */ + extra_space = buffer_size - prs_data_size(ps); + + if (!prs_grow(ps, extra_space)) + return False; + + buffer->string_at_end=buffer_size; + + return True; +} + +/**************************************************************************** +****************************************************************************/ +uint32 _new_spoolss_enumforms( const POLICY_HND *handle, uint32 level, + NEW_BUFFER *buffer, uint32 offered, + uint32 *needed, uint32 *numofforms) +{ + nt_forms_struct *list=NULL; + FORM_1 *forms_1; + int buffer_size=0; + int i; + + + DEBUG(4,("_new_spoolss_enumforms\n")); + DEBUGADD(5,("Offered buffer size [%d]\n", offered)); + DEBUGADD(5,("Info level [%d]\n", level)); + + *numofforms = get_ntforms(&list); + DEBUGADD(5,("Number of forms [%d]\n", *numofforms)); + + switch (level) { + case 1: + forms_1=(FORM_1 *)malloc(*numofforms * sizeof(FORM_1)); + + /* construct the list of form structures */ + for (i=0; i<*numofforms; i++) + { + DEBUGADD(6,("Filling form number [%d]\n",i)); + fill_form_1(&(forms_1[i]), &(list[i]), i); + } + + /* check the required size. */ + for (i=0; i<*numofforms; i++) + { + DEBUGADD(6,("adding form [%d]'s size\n",i)); + buffer_size += spoolss_size_form_1(&(forms_1[i])); + } + + *needed=buffer_size; + + if (!alloc_buffer_size(buffer, buffer_size)) + return ERROR_INSUFFICIENT_BUFFER; + + /* fill the buffer with the form structures */ + for (i=0; i<*numofforms; i++) + { + DEBUGADD(6,("adding form [%d] to buffer\n",i)); + new_smb_io_form_1("", buffer, &(forms_1[i]), 0); + } + + safe_free(list); + + if (*needed > offered) + return ERROR_INSUFFICIENT_BUFFER; + else + return NT_STATUS_NO_PROBLEMO; + + default: + safe_free(list); + return NT_STATUS_INVALID_INFO_CLASS; + } + +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_enumforms( const POLICY_HND *handle, + uint32 level, + FORM_1 **forms_1, + uint32 *offered, + uint32 *numofforms) +{ + int count; + int i; + nt_forms_struct *list=NULL; + (*forms_1)=NULL; + + DEBUG(4,("spoolss_enumforms\n")); + + count = get_ntforms(&list); + (*numofforms) = count; + + DEBUGADD(5,("Offered buffer size [%d]\n", *offered)); + DEBUGADD(5,("Number of forms [%d]\n", *numofforms)); + DEBUGADD(5,("Info level [%d]\n", level)); + + switch (level) + { + case 1: + { + (*forms_1)=(FORM_1 *)malloc(count*sizeof(FORM_1)); + for (i=0; iport_name), name); + init_unistr(&(port->monitor_name), "Moniteur Local"); + init_unistr(&(port->description), "Local Port"); +#define PORT_TYPE_WRITE 1 + port->port_type=PORT_TYPE_WRITE; + port->reserved=0x0; +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_enumports( const UNISTR2 *name, + uint32 level, + PORT_INFO_CTR *ctr, + uint32 *offered, + uint32 *numofports) +{ + int n_services=lp_numservices(); + int snum; + + DEBUG(4,("spoolss_enumports\n")); + + (*numofports) = 0; + + switch (level) + { + case 2: + { + PORT_INFO_2 *ports_2=NULL; + ports_2=(PORT_INFO_2 *)malloc(n_services*sizeof(PORT_INFO_2)); + for (snum=0; snumport.info_2=ports_2; + return 0x0; + } + } + + return NT_STATUS_INVALID_INFO_CLASS; +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_addprinterex( const UNISTR2 *uni_srv_name, + uint32 level, + const SPOOL_PRINTER_INFO_LEVEL *info, + uint32 unk0, + uint32 unk1, + uint32 unk2, + uint32 unk3, + uint32 user_level, + const SPOOL_USER_LEVEL *user, + POLICY_HND *handle) +{ + NT_PRINTER_INFO_LEVEL printer; + fstring ascii_name; + fstring server_name; + fstring share_name; + UNISTR2 *portname; + SPOOL_PRINTER_INFO_LEVEL_2 *info2; + uint32 status = 0x0; + + if (!open_printer_hnd(handle)) + { + return NT_STATUS_ACCESS_DENIED; + } + + /* NULLify info_2 here */ + /* don't put it in convert_printer_info as it's used also with non-NULL values */ + printer.info_2=NULL; + + /* convert from UNICODE to ASCII */ + convert_printer_info(info, &printer, level); + + /* write the ASCII on disk */ + status = add_a_printer(printer, level); + if (status != 0x0) + { + close_printer_handle(handle); + return status; + } + + info2=info->info_2; + portname=&(info2->portname); + + StrnCpy(server_name, global_myname, strlen(global_myname) ); + unistr2_to_ascii(share_name, portname, sizeof(share_name)-1); + + slprintf(ascii_name, sizeof(ascii_name)-1, "\\\\%s\\%s", + server_name, share_name); + + if (!set_printer_hnd_printertype(handle, ascii_name) || + !set_printer_hnd_printername(handle, ascii_name)) + { + close_printer_handle(handle); + return NT_STATUS_ACCESS_DENIED; + } + + return 0x0; +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_addprinterdriver( const UNISTR2 *server_name, + uint32 level, + const SPOOL_PRINTER_DRIVER_INFO_LEVEL *info) +{ + NT_PRINTER_DRIVER_INFO_LEVEL driver; + convert_printer_driver_info(info, &driver, level); + return add_a_printer_driver(driver, level); +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_getprinterdriverdirectory( const UNISTR2 *name, + const UNISTR2 *uni_environment, + uint32 level, + DRIVER_DIRECTORY_CTR *ctr, + uint32 *offered) +{ + pstring chaine; + pstring long_archi; + pstring archi; + + unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)-1); + get_short_archi(archi, long_archi); + + slprintf(chaine,sizeof(chaine)-1,"\\\\%s\\print$\\%s", + global_myname, archi); + + DEBUG(4,("printer driver directory: [%s]\n", chaine)); + + init_unistr(&(ctr->driver.info_1.name), chaine); + + return 0x0; +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, + uint32 idx, + uint32 *valuesize, + UNISTR *uni_value, + uint32 *realvaluesize, + uint32 *type, + uint32 *datasize, + uint8 **data, + uint32 *realdatasize) +{ + NT_PRINTER_INFO_LEVEL printer; + + fstring value; + + uint32 param_index; + uint32 biggest_valuesize; + uint32 biggest_datasize; + uint32 data_len; + uint32 status = 0x0; + + int pnum = find_printer_index_by_hnd(handle); + int snum; + + ZERO_STRUCT(printer); + (*data)=NULL; + + DEBUG(5,("spoolss_enumprinterdata\n")); + + if (!OPEN_HANDLE(pnum)) + { + return NT_STATUS_INVALID_HANDLE; + } + if (!get_printer_snum(handle, &snum)) + { + return NT_STATUS_INVALID_HANDLE; + } + status = get_a_printer(&printer, 2, lp_servicename(snum)); + + if (status != 0x0) + { + return status; + } + + /* The NT machine wants to know the biggest size of value and data */ + if ( ((*valuesize)==0) && ((*datasize)==0) ) + { + DEBUGADD(6,("Activating NT mega-hack to find sizes\n")); + + (*valuesize)=0; + (*realvaluesize)=0; + (*type)=0; + (*datasize)=0; + (*realdatasize)=0; + status=0; + + param_index=0; + biggest_valuesize=0; + biggest_datasize=0; + + while (get_specific_param_by_index(printer, 2, param_index, value, data, type, &data_len)) + { + if (strlen(value) > biggest_valuesize) biggest_valuesize=strlen(value); + if (data_len > biggest_datasize) biggest_datasize=data_len; + + param_index++; + } + + /* I wrote it, I didn't designed the protocol */ + if (biggest_valuesize!=0) + { + SIVAL(&(value),0, 2*(biggest_valuesize+1) ); + } + (*data)=(uint8 *)malloc(4*sizeof(uint8)); + SIVAL((*data), 0, biggest_datasize ); + } + else + { + /* + * the value len is wrong in NT sp3 + * that's the number of bytes not the number of unicode chars + */ + + if (get_specific_param_by_index(printer, 2, idx, value, data, type, &data_len)) + { + init_unistr(uni_value, value); + + /* the length are in bytes including leading NULL */ + (*realvaluesize)=2*(strlen(value)+1); + (*realdatasize)=data_len; + + status=0; + } + else + { + (*valuesize)=0; + (*realvaluesize)=0; + (*datasize)=0; + (*realdatasize)=0; + (*type)=0; + status=0x0103; /* ERROR_NO_MORE_ITEMS */ + } + } + + free_a_printer(printer, 2); + + return status; +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_setprinterdata( const POLICY_HND *handle, + const UNISTR2 *value, + uint32 type, + uint32 max_len, + const uint8 *data, + uint32 real_len, + uint32 numeric_data) +{ + NT_PRINTER_INFO_LEVEL printer; + NT_PRINTER_PARAM *param = NULL; + + int pnum=0; + int snum=0; + uint32 status = 0x0; + + DEBUG(5,("spoolss_setprinterdata\n")); + + pnum = find_printer_index_by_hnd(handle); + + if (!OPEN_HANDLE(pnum)) + { + return NT_STATUS_INVALID_HANDLE; + } + if (!get_printer_snum(handle, &snum)) + { + return NT_STATUS_INVALID_HANDLE; + } + + status = get_a_printer(&printer, 2, lp_servicename(snum)); + if (status != 0x0) + { + return status; + } + + convert_specific_param(¶m, value , type, data, real_len); + unlink_specific_param_if_exist(printer.info_2, param); + + if (!add_a_specific_param(printer.info_2, param)) + { + status = NT_STATUS_INVALID_PARAMETER; + } + else + { + status = add_a_printer(printer, 2); + } + free_a_printer(printer, 2); + + return status; +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_addform( const POLICY_HND *handle, + uint32 level, + const FORM *form) +{ + int pnum=0; + int count=0; + nt_forms_struct *list=NULL; + + DEBUG(5,("spoolss_addform\n")); + + pnum = find_printer_index_by_hnd(handle); + + if (!OPEN_HANDLE(pnum)) + { + return NT_STATUS_INVALID_HANDLE; + } + + count=get_ntforms(&list); + add_a_form(&list, form, &count); + write_ntforms(&list, count); + + safe_free(list); + + return 0x0; +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_setform( const POLICY_HND *handle, + const UNISTR2 *uni_name, + uint32 level, + const FORM *form) +{ + int pnum=0; + int count=0; + nt_forms_struct *list=NULL; + + DEBUG(5,("spoolss_setform\n")); + + pnum = find_printer_index_by_hnd(handle); + if (!OPEN_HANDLE(pnum)) + { + return NT_STATUS_INVALID_HANDLE; + } + count=get_ntforms(&list); + update_a_form(&list, form, count); + write_ntforms(&list, count); + + safe_free(list); + + return 0x0; +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_enumprintprocessors(const UNISTR2 *name, + const UNISTR2 *environment, + uint32 level, + PRINTPROCESSOR_1 **info_1, + uint32 *offered, + uint32 *numofprintprocessors) +{ + DEBUG(5,("spoolss_enumprintprocessors\n")); + + /* + * Enumerate the print processors ... + * + * Just reply with "winprint", to keep NT happy + * and I can use my nice printer checker. + */ + + (*numofprintprocessors) = 0x1; + (*info_1) = (PRINTPROCESSOR_1 *)malloc(sizeof(PRINTPROCESSOR_1)); + + if ((*info_1) == NULL) + { + return NT_STATUS_NO_MEMORY; + } + + init_unistr(&((*info_1)->name), "winprint"); + + return 0x0; +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_enumprintmonitors( const UNISTR2 *name, + uint32 level, + PRINTMONITOR_1 **info_1, + uint32 *offered, + uint32 *numofprintmonitors) +{ + DEBUG(5,("spoolss_enumprintmonitors\n")); + + /* + * Enumerate the print monitors ... + * + * Just reply with "Local Port", to keep NT happy + * and I can use my nice printer checker. + */ + + (*numofprintmonitors) = 0x1; + (*info_1) = (PRINTMONITOR_1 *)malloc(sizeof(PRINTMONITOR_1)); + if ((*info_1) == NULL) + { + return NT_STATUS_NO_MEMORY; + } + + init_unistr(&((*info_1)->name), "Local Port"); + + return 0x0; +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_getjob( const POLICY_HND *handle, + uint32 jobid, + uint32 level, + PJOB_INFO *ctr, + uint32 *offered) +{ + int snum; + int count; + int i; + print_queue_struct *queue=NULL; + print_status_struct prt_status; + + DEBUG(4,("spoolss_getjob\n")); + + bzero(&prt_status,sizeof(prt_status)); + + if (!get_printer_snum(handle, &snum)) + { + return NT_STATUS_INVALID_HANDLE; + } + count=get_printqueue(snum, NULL, &queue, &prt_status); + + DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n", + count, prt_status.status, prt_status.message)); + + switch (level) + { + case 1: + { + JOB_INFO_1 *job_info_1=NULL; + job_info_1=(JOB_INFO_1 *)malloc(sizeof(JOB_INFO_1)); + + if (job_info_1 == NULL) + { + safe_free(queue); + return NT_STATUS_NO_MEMORY; + } + + for (i=0; ijob.job_info_1=job_info_1; + break; + } + case 2: + { + JOB_INFO_2 *job_info_2=NULL; + job_info_2=(JOB_INFO_2 *)malloc(sizeof(JOB_INFO_2)); + + if (job_info_2 == NULL) + { + safe_free(queue); + return NT_STATUS_NO_MEMORY; + } + + for (i=0; ijob.job_info_2=job_info_2; + break; + } + default: + { + safe_free(queue); + return NT_STATUS_INVALID_INFO_CLASS; + } + } + + safe_free(queue); + return 0x0; +} -- cgit From 07fd3b392d8b3dc5bc8c72584e31a7369b92ff13 Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Mon, 7 Feb 2000 18:06:54 +0000 Subject: Hum, I should remove my gloves when I'm in front of an xterm :) fixed a stupid bug in unistr2_to_ascii that I introduced fixed getprinterdata() (This used to be commit 2f544a807714024c0fe2ddc26e11c9ddcb47e81f) --- source3/rpc_server/srv_spoolss_nt.c | 45 ++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 21 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index db48fa42ff..d25281cea5 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -537,15 +537,17 @@ uint32 _spoolss_closeprinter(POLICY_HND *handle) /******************************************************************** ********************************************************************/ -static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **data, uint32 *needed) +static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **data, uint32 *needed, uint32 in_size) { int i; + + DEBUG(8,("getprinterdata_printer_server:%s\n", value)); if (!strcmp(value, "BeepEnabled")) { *type = 0x4; *data = (uint8 *)malloc( 4*sizeof(uint8) ); - SIVAL(data, 0, 0x01); + SIVAL(*data, 0, 0x01); *needed = 0x4; return True; } @@ -554,7 +556,7 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d { *type = 0x4; *data = (uint8 *)malloc( 4*sizeof(uint8) ); - SIVAL(data, 0, 0x1B); + SIVAL(*data, 0, 0x1B); *needed = 0x4; return True; } @@ -563,7 +565,7 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d { *type = 0x4; *data = (uint8 *)malloc( 4*sizeof(uint8) ); - SIVAL(data, 0, 0x01); + SIVAL(*data, 0, 0x01); *needed = 0x4; return True; } @@ -572,23 +574,23 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d { *type = 0x4; *data = (uint8 *)malloc( 4*sizeof(uint8) ); - SIVAL(data, 0, 0x02); + SIVAL(*data, 0, 0x02); *needed = 0x4; return True; } if (!strcmp(value, "DefaultSpoolDirectory")) { - pstring directory="You are using a Samba server"; + pstring string="You are using a Samba server"; *type = 0x1; - *needed = 2*(strlen(directory)+1); - *data = (uint8 *)malloc(*needed *sizeof(uint8)); + *needed = 2*(strlen(string)+1); + *data = (uint8 *)malloc( ((*needed > in_size) ? *needed:in_size) *sizeof(uint8)); ZERO_STRUCTP(*data); /* it's done by hand ready to go on the wire */ - for (i=0; i in_size) ? *needed:in_size) *sizeof(uint8)); ZERO_STRUCTP(*data); - for (i=0; iin_size)?len:in_size *sizeof(uint8) ); bzero(*data, sizeof(uint8)*len); - memcpy(*data, idata, len); + memcpy(*data, idata, (len>in_size)?len:in_size); *needed = len; if (idata) free(idata); @@ -659,7 +661,7 @@ uint32 _spoolss_getprinterdata(const POLICY_HND *handle, UNISTR2 *valuename, uint32 *needed) { fstring value; - BOOL found; + BOOL found=False; int pnum = find_printer_index_by_hnd(handle); /* @@ -675,6 +677,7 @@ uint32 _spoolss_getprinterdata(const POLICY_HND *handle, UNISTR2 *valuename, *needed=in_size; *type=4; + DEBUG(4,("_spoolss_getprinterdata\n")); if (!OPEN_HANDLE(pnum)) { *data=(uint8 *)malloc(4*sizeof(uint8)); @@ -684,9 +687,9 @@ uint32 _spoolss_getprinterdata(const POLICY_HND *handle, UNISTR2 *valuename, unistr2_to_ascii(value, valuename, sizeof(value)-1); if (handle_is_printserver(handle)) - found=getprinterdata_printer_server(value, type, data, needed); + found=getprinterdata_printer_server(value, type, data, needed, *out_size); else - found=getprinterdata_printer(handle, value, type, data, needed); + found=getprinterdata_printer(handle, value, type, data, needed, *out_size); if (found==False) { /* reply this param doesn't exist */ -- cgit From 8688933c7feb87179c178a30e4fc42970fe1da8f Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Tue, 15 Feb 2000 18:07:45 +0000 Subject: fix the reply of rpc_alter_context OpenPrinterEx is now decoding correctly the query most of the EnumXXX use the new_buffer struct. check the (un)marshalling return code. conclusion: still a long way to go. all the client code has to be rewritten, and I still wonder how to implement correctly the notify stuff. (This used to be commit 3d6d3863751787b08d40268c83221add1487a5c9) --- source3/rpc_server/srv_spoolss_nt.c | 1229 +++++++++++++++++++++++------------ 1 file changed, 815 insertions(+), 414 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index d25281cea5..2e80cbdbf6 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -200,11 +200,8 @@ static BOOL open_printer_hnd(POLICY_HND *hnd) { if (!Printer[i].open) { - Printer[i].open = True; - Printer[i].ok = True; - + Printer[i].open = True; memcpy(&(Printer[i].printer_hnd), hnd, sizeof(*hnd)); - DEBUG(4,("Opened printer handle[%x] ", i)); dump_data(4, hnd->data, sizeof(hnd->data)); return True; @@ -221,32 +218,14 @@ static BOOL set_printer_hnd_accesstype(POLICY_HND *hnd, uint32 access_required) { int pnum = find_printer_index_by_hnd(hnd); - if (OPEN_HANDLE(pnum)) { - DEBUG(4,("Setting printer access=%x (pnum=%x)\n", access_required, pnum)); - Printer[pnum].access = access_required; - return True; - } - else { + if (!OPEN_HANDLE(pnum)) { DEBUG(4,("Error setting printer type=%x (pnum=%x)", access_required, pnum)); return False; } - return False; -} - -/**************************************************************************** - . -****************************************************************************/ -static BOOL printer_entry_is_valid(POLICY_HND *hnd) -{ - int pnum = find_printer_index_by_hnd(hnd); - if (!OPEN_HANDLE(pnum)) - return False; - - if (Printer[pnum].ok == False) - return False; - - return True; + DEBUG(4,("Setting printer access=%x (pnum=%x)\n", access_required, pnum)); + Printer[pnum].access = access_required; + return True; } /**************************************************************************** @@ -266,23 +245,19 @@ static BOOL set_printer_hnd_printertype(POLICY_HND *hnd, char *printername) if ( strlen(printername) < 3 ) { DEBUGADD(4,("A print server must have at least 1 char ! %s\n", printername)); - Printer[pnum].ok=False; return False; } /* it's a print server */ if (!strchr(printername+2, '\\')) { DEBUGADD(4,("Printer is a print server\n")); - Printer[pnum].printer_type = PRINTER_HANDLE_IS_PRINTSERVER; - Printer[pnum].ok=True; - + Printer[pnum].printer_type = PRINTER_HANDLE_IS_PRINTSERVER; return True; } /* it's a printer */ else { DEBUGADD(4,("Printer is a printer\n")); Printer[pnum].printer_type = PRINTER_HANDLE_IS_PRINTER; - Printer[pnum].ok=True; return True; } @@ -295,11 +270,11 @@ static BOOL set_printer_hnd_printertype(POLICY_HND *hnd, char *printername) static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) { int pnum = find_printer_index_by_hnd(hnd); - char *back; NT_PRINTER_INFO_LEVEL printer; int snum; int n_services=lp_numservices(); - uint32 marche; + char *aprinter; + BOOL found=False; if (!OPEN_HANDLE(pnum)) { @@ -309,54 +284,66 @@ static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) DEBUG(4,("Setting printer name=%s (len=%d) (pnum=%x)\n", printername, strlen(printername), pnum)); - switch (Printer[pnum].printer_type) { - case PRINTER_HANDLE_IS_PRINTSERVER: + if (Printer[pnum].printer_type==PRINTER_HANDLE_IS_PRINTSERVER) { ZERO_STRUCT(Printer[pnum].dev.printerservername); strncpy(Printer[pnum].dev.printerservername, printername, strlen(printername)); return True; - break; + } - case PRINTER_HANDLE_IS_PRINTER: - back=strchr(printername+2, '\\'); - back=back+1; - DEBUGADD(5,("searching for %s (len=%d)\n", back,strlen(back))); - /* - * store the Samba share name in it - * in back we have the long printer name - * need to iterate all the snum and do a - * get_a_printer each time to find the printer - * faster to do it here than later. - */ - for (snum=0;snumprintername) == strlen(back) ) - && ( !strncasecmp(printer.info_2->printername, back, strlen(back))) - ) { - DEBUGADD(4,("Printer found: %s[%x]\n",lp_servicename(snum),snum)); - ZERO_STRUCT(Printer[pnum].dev.printername); - strncpy(Printer[pnum].dev.printername, lp_servicename(snum), strlen(lp_servicename(snum))); - free_a_printer(printer, 2); - return True; - break; - } - free_a_printer(printer, 2); - } - } + if (Printer[pnum].printer_type!=PRINTER_HANDLE_IS_PRINTER) return False; - break; - - default: + + aprinter=strchr(printername+2, '\\'); + aprinter++; + + DEBUGADD(5,("searching for [%s] (len=%d)\n", aprinter, strlen(aprinter))); + /* + * store the Samba share name in it + * in back we have the long printer name + * need to iterate all the snum and do a + * get_a_printer each time to find the printer + * faster to do it here than later. + */ + + for (snum=0;snumprintername) != strlen(aprinter) ) { + free_a_printer(printer, 2); + continue; + } + + if ( strncasecmp(printer.info_2->printername, aprinter, strlen(aprinter))) { + free_a_printer(printer, 2); + continue; + } + + found=True; + } + + if (found==False) + { + DEBUGADD(4,("Printer not found\n")); return False; - break; - } + } + + DEBUGADD(4,("Printer found: %s[%x]\n",lp_servicename(snum),snum)); + ZERO_STRUCT(Printer[pnum].dev.printername); + strncpy(Printer[pnum].dev.printername, lp_servicename(snum), strlen(lp_servicename(snum))); + free_a_printer(printer, 2); + + return True; } /******************************************************************** + Return True is the handle is a print server. ********************************************************************/ static BOOL handle_is_printserver(const POLICY_HND *handle) { @@ -371,6 +358,30 @@ static BOOL handle_is_printserver(const POLICY_HND *handle) return True; } +/**************************************************************************** + allocate more memory for a BUFFER. +****************************************************************************/ +static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size) +{ + prs_struct *ps; + uint32 extra_space; + + ps=&(buffer->prs); + + /* damn, I'm doing the reverse operation of prs_grow() :) */ + if (buffer_size < prs_data_size(ps)) + extra_space=0; + else + extra_space = buffer_size - prs_data_size(ps); + + if (!prs_grow(ps, extra_space)) + return False; + + buffer->string_at_end=prs_data_size(ps); + + return True; +} + /******************************************************************** * spoolss_open_printer * @@ -400,9 +411,15 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, open_printer_hnd(handle); - set_printer_hnd_printertype(handle, name); + if (!set_printer_hnd_printertype(handle, name)) { + close_printer_handle(handle); + return NT_STATUS_ACCESS_DENIED; + } - set_printer_hnd_printername(handle, name); + if (!set_printer_hnd_printername(handle, name)) { + close_printer_handle(handle); + return NT_STATUS_ACCESS_DENIED; + } /* if (printer_default->datatype_ptr != NULL) @@ -414,14 +431,11 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, set_printer_hnd_datatype(handle, ""); */ - set_printer_hnd_accesstype(handle, printer_default->access_required); - - if (!printer_entry_is_valid(handle)) - { + if (!set_printer_hnd_accesstype(handle, printer_default->access_required)) { close_printer_handle(handle); return NT_STATUS_ACCESS_DENIED; } - + return NT_STATUS_NO_PROBLEMO; } @@ -536,7 +550,8 @@ uint32 _spoolss_closeprinter(POLICY_HND *handle) } /******************************************************************** - ********************************************************************/ + GetPrinterData on a printer server Handle. +********************************************************************/ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **data, uint32 *needed, uint32 in_size) { int i; @@ -585,7 +600,7 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d *type = 0x1; *needed = 2*(strlen(string)+1); *data = (uint8 *)malloc( ((*needed > in_size) ? *needed:in_size) *sizeof(uint8)); - ZERO_STRUCTP(*data); + memset(*data, 0, (*needed > in_size) ? *needed:in_size); /* it's done by hand ready to go on the wire */ for (i=0; i in_size) ? *needed:in_size) *sizeof(uint8)); - ZERO_STRUCTP(*data); + memset(*data, 0, (*needed > in_size) ? *needed:in_size); for (i=0; iflags=PRINTER_ENUM_NAME; + printer->flags=PRINTER_ENUM_ICON8; /* the description and the name are of the form \\server\share */ - slprintf(chaine,sizeof(chaine)-1,"\\\\%s\\%s,%s,%s",servername, + + snprintf(chaine,sizeof(chaine)-1,"\\\\%s\\%s,%s,%s",servername, ntprinter.info_2->printername, ntprinter.info_2->drivername, lp_comment(snum)); init_unistr(&(printer->description), chaine); - slprintf(chaine,sizeof(chaine)-1,"\\\\%s\\%s", servername, ntprinter.info_2->printername); - init_unistr(&(printer->name), chaine); + snprintf(chaine2,sizeof(chaine)-1,"\\\\%s\\%s", servername, ntprinter.info_2->printername); + init_unistr(&(printer->name), chaine2); init_unistr(&(printer->comment), lp_comment(snum)); free_a_printer(ntprinter, 2); + return (True); } @@ -1648,29 +1668,26 @@ static BOOL construct_printer_info_2(PRINTER_INFO_2 *printer, int snum, pstring * enum_printer_info_1 * glue between spoolss_enumprinters and construct_printer_info_1 ********************************************************************/ -static BOOL enum_printer_info_1(PRINTER_INFO_1 **printer, int snum, int number) +static BOOL get_printer_info_1(PRINTER_INFO_1 **printer, int snum, int number) { pstring servername; *printer=(PRINTER_INFO_1 *)malloc(sizeof(PRINTER_INFO_1)); DEBUG(4,("Allocated memory for ONE PRINTER_INFO_1 at [%p]\n", *printer)); pstrcpy(servername, global_myname); - if (!construct_printer_info_1(*printer, snum, servername)) - { + if (!construct_printer_info_1(*printer, snum, servername)) { free(*printer); - return (False); + return False; } else - { - return (True); - } + return True; } /******************************************************************** * enum_printer_info_2 * glue between spoolss_enumprinters and construct_printer_info_2 ********************************************************************/ -static BOOL enum_printer_info_2(PRINTER_INFO_2 **printer, int snum, int number) +static BOOL get_printer_info_2(PRINTER_INFO_2 **printer, int snum, int number) { pstring servername; @@ -1693,26 +1710,100 @@ static BOOL enum_printer_info_2(PRINTER_INFO_2 **printer, int snum, int number) * * called from api_spoolss_enumprinters (see this to understand) ********************************************************************/ -static void enum_all_printers_info_1(PRINTER_INFO_1 ***printers, uint32 *number) +static BOOL enum_printer_info_1(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int snum; + int i; int n_services=lp_numservices(); - *printers=NULL; - *number=0; + PRINTER_INFO_1 *printer=NULL; +DEBUG(1,("enum_printer_info_1\n")); + for (snum=0; snum offered) { + *returned=0; + return ERROR_INSUFFICIENT_BUFFER; + } + else + return NT_STATUS_NO_PROBLEMO; +} + +/******************************************************************** + Spoolss_enumprinters. +********************************************************************/ +static BOOL enum_all_printers_info_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +{ + int snum; + int i; + int n_services=lp_numservices(); + PRINTER_INFO_1 *printers=NULL; + PRINTER_INFO_1 current_prt; + pstring servername; + + DEBUG(4,("enum_all_printers_info_1\n")); + + pstrcpy(servername, global_myname); + + for (snum=0; snum offered) { + *returned=0; + return ERROR_INSUFFICIENT_BUFFER; + } + else + return NT_STATUS_NO_PROBLEMO; } /******************************************************************** @@ -1720,26 +1811,90 @@ static void enum_all_printers_info_1(PRINTER_INFO_1 ***printers, uint32 *number) * * called from api_spoolss_enumprinters (see this to understand) ********************************************************************/ -static void enum_all_printers_info_2(PRINTER_INFO_2 ***printers, uint32 *number) +static BOOL enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int snum; + int i; int n_services=lp_numservices(); - *printers=NULL; - *number=0; + PRINTER_INFO_2 **printers=NULL; - for (snum=0;snum offered) { + *returned=0; + return ERROR_INSUFFICIENT_BUFFER; + } + else + return NT_STATUS_NO_PROBLEMO; +} + +/******************************************************************** + * handle enumeration of printers at level 1 + ********************************************************************/ +static uint32 enumprinters_level1( uint32 flags, fstring name, + NEW_BUFFER *buffer, uint32 offered, + uint32 *needed, uint32 *returned) +{ + if (flags && PRINTER_ENUM_NETWORK) + return enum_all_printers_info_1(buffer, offered, needed, returned); + + if (flags && PRINTER_ENUM_NAME) { + if (*name=='\0') + return enum_all_printers_info_1(buffer, offered, needed, returned); + else + return enum_printer_info_1(name, buffer, offered, needed, returned); + } + + if (flags && PRINTER_ENUM_REMOTE) + return enum_all_printers_info_1(buffer, offered, needed, returned); + + +} + +/******************************************************************** + * handle enumeration of printers at level 2 + ********************************************************************/ +static uint32 enumprinters_level2( uint32 flags, fstring servername, + NEW_BUFFER *buffer, uint32 offered, + uint32 *needed, uint32 *returned) +{ + return enum_all_printers_info_2(buffer, offered, needed, returned); +} + +/******************************************************************** + * handle enumeration of printers at level 5 + ********************************************************************/ +static uint32 enumprinters_level5( uint32 flags, fstring servername, + NEW_BUFFER *buffer, uint32 offered, + uint32 *needed, uint32 *returned) +{ +/* return enum_all_printers_info_5(buffer, offered, needed, returned);*/ + return NT_STATUS_NO_PROBLEMO; } /******************************************************************** @@ -1747,55 +1902,48 @@ static void enum_all_printers_info_2(PRINTER_INFO_2 ***printers, uint32 *number) * * called from api_spoolss_enumprinters (see this to understand) ********************************************************************/ -uint32 _spoolss_enumprinters( - uint32 flags, - const UNISTR2 *servername, - uint32 level, - const BUFFER *buffer, - uint32 buf_size, - uint32 *offered, - uint32 *needed, - PRINTER_INFO_CTR *ctr, - uint32 *returned) +uint32 _spoolss_enumprinters( uint32 flags, const UNISTR2 *servername, uint32 level, + NEW_BUFFER *buffer, uint32 offered, + uint32 *needed, uint32 *returned) { - DEBUG(4,("Enumerating printers\n")); + fstring name; + + DEBUG(4,("_spoolss_enumprinters\n")); - (*returned)=0; + *needed=0; + *returned=0; + + /* + * Level 1: + * flags==PRINTER_ENUM_NAME + * if name=="" then enumerates all printers + * if name!="" then enumerate the printer + * flags==PRINTER_ENUM_REMOTE + * name is NULL, enumerate printers + * Level 2: name!="" enumerates printers, name can't be NULL + * Level 3: doesn't exist + * Level 4: does a local registry lookup + * Level 5: same as Level 2 + */ - switch (level) - { - case 1: - if (flags == PRINTER_ENUM_NAME || - flags == PRINTER_ENUM_NETWORK ) - { - /*if (is_a_printerserver(servername))*/ - enum_all_printers_info_1(&ctr->printer.printers_1, returned ); - /*else - enum_one_printer_info_1(&r_u);*/ - break; - } - case 2: - if (flags == PRINTER_ENUM_NAME || - flags == PRINTER_ENUM_NETWORK ) - { - /*if (is_a_printerserver(servername))*/ - enum_all_printers_info_2(&ctr->printer.printers_2, returned ); - /*else - enum_one_printer_info_2(&r_u);*/ - break; - } - case 3: /* doesn't exist */ - return NT_STATUS_INVALID_INFO_CLASS; - case 4: /* can't, always on local machine */ - break; - case 5: - return NT_STATUS_INVALID_INFO_CLASS; - - } - DEBUG(4,("%d printers enumerated\n", *returned)); - (*offered) = buffer->size; + unistr2_to_ascii(name, servername, sizeof(name)-1); - return 0x0; + switch (level) { + case 1: + return enumprinters_level1(flags, name, buffer, offered, needed, returned); + break; + case 2: + return enumprinters_level2(flags, name, buffer, offered, needed, returned); + break; + case 5: + return enumprinters_level5(flags, name, buffer, offered, needed, returned); + break; + case 3: + case 4: + default: + return NT_STATUS_INVALID_LEVEL; + break; + } } /**************************************************************************** @@ -2562,86 +2710,135 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, } /**************************************************************************** + Enumjobs at level 1. ****************************************************************************/ -uint32 _spoolss_enumjobs( const POLICY_HND *handle, - uint32 reqfirstjob, - uint32 reqnumofjobs, - uint32 level, - JOB_INFO_CTR *ctr, - uint32 *buf_size, - uint32 *numofjobs) +static uint32 enumjobs_level1(print_queue_struct *queue, int snum, + NEW_BUFFER *buffer, uint32 offered, + uint32 *needed, uint32 *returned) { - int snum; - int count; + JOB_INFO_1 *info; int i; - print_queue_struct *queue=NULL; - print_status_struct prt_status; - - DEBUG(4,("spoolss_enumjobs\n")); - - ZERO_STRUCT(prt_status); - - if (!get_printer_snum(handle, &snum)) - { - return NT_STATUS_INVALID_HANDLE; - } - - count = get_printqueue(snum, NULL, &queue, &prt_status); - (*numofjobs) = 0; - DEBUG(4,("count:[%d], status:[%d], [%s]\n", - count, prt_status.status, prt_status.message)); + info=(JOB_INFO_1 *)malloc(*returned*sizeof(JOB_INFO_1)); - switch (level) + for (i=0; i<*returned; i++) { - case 1: - { - for (i=0; ijob.job_info_1, - job_info_1); - - fill_job_info_1(ctr->job.job_info_1[i], - &(queue[i]), i, snum); - } - safe_free(queue); - return 0x0; - } - case 2: - { - for (i=0; ijob.job_info_2, - job_info_2); - - fill_job_info_2(ctr->job.job_info_2[i], - &(queue[i]), i, snum); - } - safe_free(queue); - return 0x0; - } + fill_job_info_1(&(info[i]), &(queue[i]), i, snum); } + /* check the required size. */ + for (i=0; i<*returned; i++) + (*needed) += spoolss_size_job_info_1(&(info[i])); + + if (!alloc_buffer_size(buffer, *needed)) + return ERROR_INSUFFICIENT_BUFFER; + + /* fill the buffer with the structures */ + for (i=0; i<*returned; i++) + new_smb_io_job_info_1("", buffer, &(info[i]), 0); + + /* clear memory */ safe_free(queue); + safe_free(info); - return NT_STATUS_INVALID_INFO_CLASS; + if (*needed > offered) { + *returned=0; + return ERROR_INSUFFICIENT_BUFFER; + } + else + return NT_STATUS_NO_PROBLEMO; } /**************************************************************************** + Enumjobs at level 2. ****************************************************************************/ -uint32 _spoolss_schedulejob( const POLICY_HND *handle, uint32 jobid) +static uint32 enumjobs_level2(print_queue_struct *queue, int snum, + NEW_BUFFER *buffer, uint32 offered, + uint32 *needed, uint32 *returned) { - return 0x0; -} - -/**************************************************************************** -****************************************************************************/ + JOB_INFO_2 *info; + int i; + + info=(JOB_INFO_2 *)malloc(*returned*sizeof(JOB_INFO_2)); + + for (i=0; i<*returned; i++) + { + fill_job_info_2(&(info[i]), &(queue[i]), i, snum); + } + + /* check the required size. */ + for (i=0; i<*returned; i++) + (*needed) += spoolss_size_job_info_2(&(info[i])); + + if (!alloc_buffer_size(buffer, *needed)) + return ERROR_INSUFFICIENT_BUFFER; + + /* fill the buffer with the structures */ + for (i=0; i<*returned; i++) + new_smb_io_job_info_2("", buffer, &(info[i]), 0); + + /* clear memory */ + safe_free(queue); + safe_free(info); + + if (*needed > offered) { + *returned=0; + return ERROR_INSUFFICIENT_BUFFER; + } + else + return NT_STATUS_NO_PROBLEMO; +} + +/**************************************************************************** + Enumjobs. +****************************************************************************/ +uint32 _spoolss_enumjobs( POLICY_HND *handle, uint32 firstjob, uint32 numofjobs, uint32 level, + NEW_BUFFER *buffer, uint32 offered, + uint32 *needed, uint32 *returned) +{ + int snum; + print_queue_struct *queue=NULL; + print_status_struct prt_status; + + DEBUG(4,("_spoolss_enumjobs\n")); + + ZERO_STRUCT(prt_status); + + *needed=0; + *returned=0; + + if (!get_printer_snum(handle, &snum)) + { + return NT_STATUS_INVALID_HANDLE; + } + + *returned = get_printqueue(snum, NULL, &queue, &prt_status); + DEBUGADD(4,("count:[%d], status:[%d], [%s]\n", *returned, prt_status.status, prt_status.message)); + + switch (level) { + case 1: + return enumjobs_level1(queue, snum, buffer, offered, needed, returned); + break; + case 2: + return enumjobs_level2(queue, snum, buffer, offered, needed, returned); + break; + default: + return NT_STATUS_INVALID_LEVEL; + break; + } +} + + + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_schedulejob( const POLICY_HND *handle, uint32 jobid) +{ + return 0x0; +} + +/**************************************************************************** +****************************************************************************/ uint32 _spoolss_setjob( const POLICY_HND *handle, uint32 jobid, uint32 level, @@ -2705,86 +2902,166 @@ uint32 _spoolss_setjob( const POLICY_HND *handle, } /**************************************************************************** + Enumerates all printer drivers at level 1. ****************************************************************************/ -uint32 _spoolss_enumprinterdrivers( const UNISTR2 *name, - const UNISTR2 *environment, - uint32 level, - DRIVER_INFO *ctr, - uint32 *offered, - uint32 *numofdrivers) +static uint32 enumprinterdrivers_level1(fstring *list, fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { - NT_PRINTER_DRIVER_INFO_LEVEL driver; - int count; int i; - fstring *list; - fstring servername; - fstring architecture; + NT_PRINTER_DRIVER_INFO_LEVEL driver; + DRIVER_INFO_1 *driver_info_1=NULL; + driver_info_1=(DRIVER_INFO_1 *)malloc(*returned * sizeof(DRIVER_INFO_1)); - DEBUG(4,("spoolss_enumdrivers\n")); - fstrcpy(servername, global_myname); + for (i=0; i<*returned; i++) { + get_a_printer_driver(&driver, 3, list[i], architecture); + fill_printer_driver_info_1(&(driver_info_1[i]), driver, servername, architecture ); + free_a_printer_driver(driver, 3); + } + + /* check the required size. */ + for (i=0; i<*returned; i++) + { + DEBUGADD(6,("adding driver [%d]'s size\n",i)); + *needed += spoolss_size_printer_driver_info_1(&(driver_info_1[i])); + } - unistr2_to_ascii(architecture, environment, sizeof(architecture)); - count=get_ntdrivers(&list, architecture); + if (!alloc_buffer_size(buffer, *needed)) + return ERROR_INSUFFICIENT_BUFFER; - DEBUGADD(4,("we have: [%d] drivers on archi [%s]\n",count, architecture)); - for (i=0; i offered) + return ERROR_INSUFFICIENT_BUFFER; + else + return NT_STATUS_NO_PROBLEMO; +} + +/**************************************************************************** + Enumerates all printer drivers at level 2. +****************************************************************************/ +static uint32 enumprinterdrivers_level2(fstring *list, fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +{ + int i; + NT_PRINTER_DRIVER_INFO_LEVEL driver; + DRIVER_INFO_2 *driver_info_2=NULL; + driver_info_2=(DRIVER_INFO_2 *)malloc(*returned * sizeof(DRIVER_INFO_2)); + + for (i=0; i<*returned; i++) { + get_a_printer_driver(&driver, 3, list[i], architecture); + fill_printer_driver_info_2(&(driver_info_2[i]), driver, servername, architecture ); + free_a_printer_driver(driver, 3); } - (*numofdrivers)=count; + /* check the required size. */ + for (i=0; i<*returned; i++) + { + DEBUGADD(6,("adding driver [%d]'s size\n",i)); + *needed += spoolss_size_printer_driver_info_2(&(driver_info_2[i])); + } + + if (!alloc_buffer_size(buffer, *needed)) + return ERROR_INSUFFICIENT_BUFFER; + + /* fill the buffer with the form structures */ + for (i=0; i<*returned; i++) + { + DEBUGADD(6,("adding form [%d] to buffer\n",i)); + new_smb_io_printer_driver_info_2("", buffer, &(driver_info_2[i]), 0); + } + + safe_free(list); + + if (*needed > offered) + return ERROR_INSUFFICIENT_BUFFER; + else + return NT_STATUS_NO_PROBLEMO; +} + +/**************************************************************************** + Enumerates all printer drivers at level 3. +****************************************************************************/ +static uint32 enumprinterdrivers_level3(fstring *list, fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +{ + int i; + NT_PRINTER_DRIVER_INFO_LEVEL driver; + DRIVER_INFO_3 *driver_info_3=NULL; + driver_info_3=(DRIVER_INFO_3 *)malloc((*returned)*sizeof(DRIVER_INFO_3)); + + for (i=0; i<*returned; i++) { + get_a_printer_driver(&driver, 3, list[i], architecture); + fill_printer_driver_info_3(&(driver_info_3[i]), driver, servername, architecture ); + free_a_printer_driver(driver, 3); + } - switch (level) + /* check the required size. */ + for (i=0; i<*returned; i++) { - case 1: - { - DRIVER_INFO_1 *driver_info_1=NULL; - driver_info_1=(DRIVER_INFO_1 *)malloc(count*sizeof(DRIVER_INFO_1)); + DEBUGADD(6,("adding driver [%d]'s size\n",i)); + *needed += spoolss_size_printer_driver_info_3(&(driver_info_3[i])); + } - for (i=0; idriver.info1=driver_info_1; - break; - } - case 2: - { - DRIVER_INFO_2 *driver_info_2=NULL; - driver_info_2=(DRIVER_INFO_2 *)malloc(count*sizeof(DRIVER_INFO_2)); - - for (i=0; idriver.info2=driver_info_2; - break; - } - case 3: - { - DRIVER_INFO_3 *driver_info_3=NULL; - driver_info_3=(DRIVER_INFO_3 *)malloc(count*sizeof(DRIVER_INFO_3)); - - for (i=0; idriver.info3=driver_info_3; - break; - } - default: - { - return NT_STATUS_INVALID_INFO_CLASS; - } + if (!alloc_buffer_size(buffer, *needed)) + return ERROR_INSUFFICIENT_BUFFER; + + /* fill the buffer with the form structures */ + for (i=0; i<*returned; i++) + { + DEBUGADD(6,("adding form [%d] to buffer\n",i)); + new_smb_io_printer_driver_info_3("", buffer, &(driver_info_3[i]), 0); } - return 0x0; + safe_free(list); + + if (*needed > offered) + return ERROR_INSUFFICIENT_BUFFER; + else + return NT_STATUS_NO_PROBLEMO; +} + +/**************************************************************************** + Enumerates all printer drivers. +****************************************************************************/ +uint32 _spoolss_enumprinterdrivers( UNISTR2 *name, UNISTR2 *environment, uint32 level, + NEW_BUFFER *buffer, uint32 offered, + uint32 *needed, uint32 *returned) +{ + int i; + fstring *list; + fstring servername; + fstring architecture; + + DEBUG(4,("_spoolss_enumprinterdrivers\n")); + fstrcpy(servername, global_myname); + *needed=0; + *returned=0; + + unistr2_to_ascii(architecture, environment, sizeof(architecture)-1); + *returned=get_ntdrivers(&list, architecture); + + DEBUGADD(4,("we have: [%d] drivers in environment [%s]\n", *returned, architecture)); + for (i=0; i<*returned; i++) + DEBUGADD(5,("driver: [%s]\n", list[i])); + + switch (level) { + case 1: + return enumprinterdrivers_level1(list, servername, architecture, buffer, offered, needed, returned); + break; + case 2: + return enumprinterdrivers_level2(list, servername, architecture, buffer, offered, needed, returned); + break; + case 3: + return enumprinterdrivers_level3(list, servername, architecture, buffer, offered, needed, returned); + break; + default: + return NT_STATUS_INVALID_INFO_CLASS; + break; + } } /**************************************************************************** @@ -2801,26 +3078,6 @@ static void fill_form_1(FORM_1 *form, nt_forms_struct *list, int position) form->bottom=list->bottom; } -/**************************************************************************** -****************************************************************************/ -static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size) -{ - prs_struct *ps; - uint32 extra_space; - - ps=&(buffer->prs); - - /* damn, I'm doing the reverse operation of prs_grow() :) */ - extra_space = buffer_size - prs_data_size(ps); - - if (!prs_grow(ps, extra_space)) - return False; - - buffer->string_at_end=buffer_size; - - return True; -} - /**************************************************************************** ****************************************************************************/ uint32 _new_spoolss_enumforms( const POLICY_HND *handle, uint32 level, @@ -2832,7 +3089,6 @@ uint32 _new_spoolss_enumforms( const POLICY_HND *handle, uint32 level, int buffer_size=0; int i; - DEBUG(4,("_new_spoolss_enumforms\n")); DEBUGADD(5,("Offered buffer size [%d]\n", offered)); DEBUGADD(5,("Info level [%d]\n", level)); @@ -2886,43 +3142,9 @@ uint32 _new_spoolss_enumforms( const POLICY_HND *handle, uint32 level, /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_enumforms( const POLICY_HND *handle, - uint32 level, - FORM_1 **forms_1, - uint32 *offered, - uint32 *numofforms) +static void fill_port_1(PORT_INFO_1 *port, char *name) { - int count; - int i; - nt_forms_struct *list=NULL; - (*forms_1)=NULL; - - DEBUG(4,("spoolss_enumforms\n")); - - count = get_ntforms(&list); - (*numofforms) = count; - - DEBUGADD(5,("Offered buffer size [%d]\n", *offered)); - DEBUGADD(5,("Number of forms [%d]\n", *numofforms)); - DEBUGADD(5,("Info level [%d]\n", level)); - - switch (level) - { - case 1: - { - (*forms_1)=(FORM_1 *)malloc(count*sizeof(FORM_1)); - for (i=0; iport_name), name); } /**************************************************************************** @@ -2938,45 +3160,135 @@ static void fill_port_2(PORT_INFO_2 *port, char *name) } /**************************************************************************** + enumports level 1. ****************************************************************************/ -uint32 _spoolss_enumports( const UNISTR2 *name, - uint32 level, - PORT_INFO_CTR *ctr, - uint32 *offered, - uint32 *numofports) +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; - DEBUG(4,("spoolss_enumports\n")); + for (snum=0; snumport.info_2=ports_2; - return 0x0; - } + DEBUGADD(6,("adding port [%d]'s size\n", i)); + *needed += spoolss_size_port_info_1(&(ports[i])); + } + + if (!alloc_buffer_size(buffer, *needed)) + return ERROR_INSUFFICIENT_BUFFER; + + /* fill the buffer with the ports structures */ + for (i=0; i<*returned; i++) + { + DEBUGADD(6,("adding port [%d] to buffer\n", i)); + new_smb_io_port_1("", buffer, &(ports[i]), 0); + } + + safe_free(ports); + + if (*needed > offered) { + *returned=0; + return ERROR_INSUFFICIENT_BUFFER; + } + else + return NT_STATUS_NO_PROBLEMO; +} + + +/**************************************************************************** + enumports level 2. +****************************************************************************/ +static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +{ + int n_services=lp_numservices(); + int snum; + int i=0; + + PORT_INFO_2 *ports=NULL; + + for (snum=0; snum offered) { + *returned=0; + return ERROR_INSUFFICIENT_BUFFER; + } + else + return NT_STATUS_NO_PROBLEMO; +} + +/**************************************************************************** + enumports. +****************************************************************************/ +uint32 _spoolss_enumports( UNISTR2 *name, uint32 level, + NEW_BUFFER *buffer, uint32 offered, + uint32 *needed, uint32 *returned) +{ + DEBUG(4,("spoolss_enumports\n")); + + *returned=0; + *needed=0; + + switch (level) { + case 1: + return enumports_level_1(buffer, offered, needed, returned); + break; + case 2: + return enumports_level_2(buffer, offered, needed, returned); + break; + default: + return NT_STATUS_INVALID_INFO_CLASS; + break; + } } /**************************************************************************** @@ -3293,13 +3605,39 @@ uint32 _spoolss_setform( const POLICY_HND *handle, } /**************************************************************************** + enumprintprocessors level 1. ****************************************************************************/ -uint32 _spoolss_enumprintprocessors(const UNISTR2 *name, - const UNISTR2 *environment, - uint32 level, - PRINTPROCESSOR_1 **info_1, - uint32 *offered, - uint32 *numofprintprocessors) +static uint32 enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +{ + PRINTPROCESSOR_1 *info_1=NULL; + + info_1 = (PRINTPROCESSOR_1 *)malloc(sizeof(PRINTPROCESSOR_1)); + (*returned) = 0x1; + + init_unistr(&(info_1->name), "winprint"); + + *needed += spoolss_size_printprocessor_info_1(info_1); + + if (!alloc_buffer_size(buffer, *needed)) + return ERROR_INSUFFICIENT_BUFFER; + + smb_io_printprocessor_info_1("", buffer, info_1, 0); + + safe_free(info_1); + + if (*needed > offered) { + *returned=0; + return ERROR_INSUFFICIENT_BUFFER; + } + else + return NT_STATUS_NO_PROBLEMO; +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_enumprintprocessors(UNISTR2 *name, UNISTR2 *environment, uint32 level, + NEW_BUFFER *buffer, uint32 offered, + uint32 *needed, uint32 *returned) { DEBUG(5,("spoolss_enumprintprocessors\n")); @@ -3310,26 +3648,85 @@ uint32 _spoolss_enumprintprocessors(const UNISTR2 *name, * and I can use my nice printer checker. */ - (*numofprintprocessors) = 0x1; - (*info_1) = (PRINTPROCESSOR_1 *)malloc(sizeof(PRINTPROCESSOR_1)); + *returned=0; + *needed=0; - if ((*info_1) == NULL) - { - return NT_STATUS_NO_MEMORY; + switch (level) { + case 1: + return enumprintprocessors_level_1(buffer, offered, needed, returned); + break; + default: + return NT_STATUS_INVALID_INFO_CLASS; + break; } - init_unistr(&((*info_1)->name), "winprint"); +} - return 0x0; +/**************************************************************************** + enumprintmonitors level 1. +****************************************************************************/ +static uint32 enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +{ + PRINTMONITOR_1 *info_1=NULL; + + info_1 = (PRINTMONITOR_1 *)malloc(sizeof(PRINTMONITOR_1)); + (*returned) = 0x1; + + init_unistr(&(info_1->name), "Local Port"); + + *needed += spoolss_size_printmonitor_info_1(info_1); + + if (!alloc_buffer_size(buffer, *needed)) + return ERROR_INSUFFICIENT_BUFFER; + + smb_io_printmonitor_info_1("", buffer, info_1, 0); + + safe_free(info_1); + + if (*needed > offered) { + *returned=0; + return ERROR_INSUFFICIENT_BUFFER; + } + else + return NT_STATUS_NO_PROBLEMO; } /**************************************************************************** + enumprintmonitors level 2. ****************************************************************************/ -uint32 _spoolss_enumprintmonitors( const UNISTR2 *name, - uint32 level, - PRINTMONITOR_1 **info_1, - uint32 *offered, - uint32 *numofprintmonitors) +static uint32 enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +{ + PRINTMONITOR_2 *info_2=NULL; + + info_2 = (PRINTMONITOR_2 *)malloc(sizeof(PRINTMONITOR_2)); + (*returned) = 0x1; + + init_unistr(&(info_2->name), "Local Port"); + init_unistr(&(info_2->environment), "Windows NT X86"); + init_unistr(&(info_2->dll_name), "localmon.dll"); + + *needed += spoolss_size_printmonitor_info_2(info_2); + + if (!alloc_buffer_size(buffer, *needed)) + return ERROR_INSUFFICIENT_BUFFER; + + smb_io_printmonitor_info_2("", buffer, info_2, 0); + + safe_free(info_2); + + if (*needed > offered) { + *returned=0; + return ERROR_INSUFFICIENT_BUFFER; + } + else + return NT_STATUS_NO_PROBLEMO; +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_enumprintmonitors(UNISTR2 *name,uint32 level, + NEW_BUFFER *buffer, uint32 offered, + uint32 *needed, uint32 *returned) { DEBUG(5,("spoolss_enumprintmonitors\n")); @@ -3340,16 +3737,20 @@ uint32 _spoolss_enumprintmonitors( const UNISTR2 *name, * and I can use my nice printer checker. */ - (*numofprintmonitors) = 0x1; - (*info_1) = (PRINTMONITOR_1 *)malloc(sizeof(PRINTMONITOR_1)); - if ((*info_1) == NULL) - { - return NT_STATUS_NO_MEMORY; - } + *returned=0; + *needed=0; - init_unistr(&((*info_1)->name), "Local Port"); - - return 0x0; + switch (level) { + case 1: + return enumprintmonitors_level_1(buffer, offered, needed, returned); + break; + case 2: + return enumprintmonitors_level_2(buffer, offered, needed, returned); + break; + default: + return NT_STATUS_INVALID_INFO_CLASS; + break; + } } /**************************************************************************** -- cgit From 0e004212d25ebee5db7b27e017ddb1015f4c2a7e Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Mon, 21 Feb 2000 01:58:13 +0000 Subject: more rewrite ... comitting before starting on new functions. J.F. (This used to be commit f9c20801114f72b587a6e8c3177cbab13dbdcc28) --- source3/rpc_server/srv_spoolss_nt.c | 655 +++++++++++++++++++++++------------- 1 file changed, 418 insertions(+), 237 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 2e80cbdbf6..90a7b44aef 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -392,7 +392,6 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, uint32 user_switch, SPOOL_USER_CTR user_ctr, POLICY_HND *handle) { - BOOL printer_open = False; fstring name; fstring datatype; @@ -439,57 +438,41 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, return NT_STATUS_NO_PROBLEMO; } +/**************************************************************************** +****************************************************************************/ static BOOL convert_printer_info(const SPOOL_PRINTER_INFO_LEVEL *uni, - NT_PRINTER_INFO_LEVEL *printer, - uint32 level) + NT_PRINTER_INFO_LEVEL *printer, uint32 level) { - switch (level) - { + switch (level) { case 2: - { - uni_2_asc_printer_info_2(uni->info_2, - &(printer->info_2)); + uni_2_asc_printer_info_2(uni->info_2, &(printer->info_2)); break; - } default: break; } - - return True; } static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL *uni, - NT_PRINTER_DRIVER_INFO_LEVEL *printer, - uint32 level) + NT_PRINTER_DRIVER_INFO_LEVEL *printer, uint32 level) { - switch (level) - { + switch (level) { case 3: - { printer->info_3=NULL; uni_2_asc_printer_driver_3(uni->info_3, &(printer->info_3)); break; - } default: break; } - - return True; } static BOOL convert_devicemode(DEVICEMODE devmode, NT_DEVICEMODE *nt_devmode) { - unistr_to_ascii(nt_devmode->devicename, - devmode.devicename.buffer, - 31); - - unistr_to_ascii(nt_devmode->formname, - devmode.formname.buffer, - 31); + unistr_to_ascii(nt_devmode->devicename, devmode.devicename.buffer, 31); + unistr_to_ascii(nt_devmode->formname, devmode.formname.buffer, 31); nt_devmode->specversion=devmode.specversion; nt_devmode->driverversion=devmode.driverversion; @@ -524,7 +507,7 @@ static BOOL convert_devicemode(DEVICEMODE devmode, NT_DEVICEMODE *nt_devmode) nt_devmode->reserved2=devmode.reserved2; nt_devmode->panningwidth=devmode.panningwidth; nt_devmode->panningheight=devmode.panningheight; - + if (nt_devmode->driverextra != 0) { /* if we had a previous private delete it and make a new one */ @@ -533,7 +516,6 @@ static BOOL convert_devicemode(DEVICEMODE devmode, NT_DEVICEMODE *nt_devmode) nt_devmode->private=(uint8 *)malloc(nt_devmode->driverextra * sizeof(uint8)); memcpy(nt_devmode->private, devmode.private, nt_devmode->driverextra); } - return True; } @@ -1948,65 +1930,121 @@ uint32 _spoolss_enumprinters( uint32 flags, const UNISTR2 *servername, uint32 le /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_getprinter( POLICY_HND *handle, - uint32 level, - PRINTER_INFO *ctr, - uint32 *offered, - uint32 *needed) +static uint32 getprinter_level_0(pstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { - int snum; - pstring servername; + PRINTER_INFO_0 *printer=NULL; + + printer=(PRINTER_INFO_0*)malloc(sizeof(PRINTER_INFO_0)); + construct_printer_info_0(printer, snum, servername); - pstrcpy(servername, global_myname); + /* check the required size. */ + *needed += spoolss_size_printer_info_0(printer); - if (!get_printer_snum(handle,&snum)) - { - return NT_STATUS_INVALID_HANDLE; + if (!alloc_buffer_size(buffer, *needed)) + return ERROR_INSUFFICIENT_BUFFER; + + /* fill the buffer with the structures */ + new_smb_io_printer_info_0("", buffer, printer, 0); + + /* clear memory */ + safe_free(printer); + + if (*needed > offered) { + return ERROR_INSUFFICIENT_BUFFER; } + else + return NT_STATUS_NO_PROBLEMO; +} - DEBUG(0,("_spoolss_getprinter: offered and needed params ignored\n")); +/**************************************************************************** +****************************************************************************/ +static uint32 getprinter_level_1(pstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +{ + PRINTER_INFO_1 *printer=NULL; - switch (level) - { - case 0: - { - PRINTER_INFO_0 *printer; - - printer=(PRINTER_INFO_0*)malloc(sizeof(PRINTER_INFO_0)); - construct_printer_info_0(printer, snum, servername); - ctr->printer.info0=printer; - - return 0x0; - } - case 1: - { - PRINTER_INFO_1 *printer; - - printer=(PRINTER_INFO_1*)malloc(sizeof(PRINTER_INFO_1)); - construct_printer_info_1(printer, snum, servername); - ctr->printer.info1=printer; + printer=(PRINTER_INFO_1*)malloc(sizeof(PRINTER_INFO_1)); + construct_printer_info_1(printer, snum, servername); + + /* check the required size. */ + *needed += spoolss_size_printer_info_1(printer); - return 0x0; - } - case 2: - { - PRINTER_INFO_2 *printer; - - printer=(PRINTER_INFO_2*)malloc(sizeof(PRINTER_INFO_2)); - construct_printer_info_2(printer, snum, servername); - ctr->printer.info2=printer; + if (!alloc_buffer_size(buffer, *needed)) + return ERROR_INSUFFICIENT_BUFFER; - return 0x0; - } - default: - { - break; - } + /* fill the buffer with the structures */ + new_smb_io_printer_info_1("", buffer, printer, 0); + + /* clear memory */ + safe_free(printer); + + if (*needed > offered) { + return ERROR_INSUFFICIENT_BUFFER; } + else + return NT_STATUS_NO_PROBLEMO; +} - return NT_STATUS_INVALID_INFO_CLASS; +/**************************************************************************** +****************************************************************************/ +static uint32 getprinter_level_2(pstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +{ + PRINTER_INFO_2 *printer=NULL; + + printer=(PRINTER_INFO_2*)malloc(sizeof(PRINTER_INFO_2)); + construct_printer_info_2(printer, snum, servername); + + /* check the required size. */ + *needed += spoolss_size_printer_info_2(printer); + + if (!alloc_buffer_size(buffer, *needed)) + return ERROR_INSUFFICIENT_BUFFER; + + /* fill the buffer with the structures */ + new_smb_io_printer_info_2("", buffer, printer, 0); + + /* clear memory */ + safe_free(printer); + + if (*needed > offered) { + return ERROR_INSUFFICIENT_BUFFER; + } + else + return NT_STATUS_NO_PROBLEMO; } +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_getprinter(POLICY_HND *handle, uint32 level, + NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +{ + int snum; + pstring servername; + + *needed=0; + + pstrcpy(servername, global_myname); + + if (!get_printer_snum(handle, &snum)) + { + return NT_STATUS_INVALID_HANDLE; + } + + switch (level) { + case 0: + return getprinter_level_0(servername, snum, buffer, offered, needed); + break; + case 1: + return getprinter_level_1(servername,snum, buffer, offered, needed); + break; + case 2: + return getprinter_level_2(servername,snum, buffer, offered, needed); + break; + default: + return NT_STATUS_INVALID_LEVEL; + break; + } +} + /******************************************************************** * construct_printer_driver_info_1 * fill a construct_printer_driver_info_1 struct @@ -2187,63 +2225,129 @@ static void construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_getprinterdriver2( const POLICY_HND *handle, - const UNISTR2 *uni_arch, - uint32 level, - DRIVER_INFO *ctr, - uint32 *offered, - uint32 *needed) +static uint32 getprinterdriver2_level1(pstring servername, pstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +{ + DRIVER_INFO_1 *info=NULL; + + info=(DRIVER_INFO_1 *)malloc(sizeof(DRIVER_INFO_1)); + + construct_printer_driver_info_1(info, snum, servername, architecture); + + /* check the required size. */ + *needed += spoolss_size_printer_driver_info_1(info); + + if (!alloc_buffer_size(buffer, *needed)) + return ERROR_INSUFFICIENT_BUFFER; + + /* fill the buffer with the structures */ + new_smb_io_printer_driver_info_1("", buffer, info, 0); + + /* clear memory */ + safe_free(info); + + if (*needed > offered) { + return ERROR_INSUFFICIENT_BUFFER; + } + else + return NT_STATUS_NO_PROBLEMO; +} + +/**************************************************************************** +****************************************************************************/ +static uint32 getprinterdriver2_level2(pstring servername, pstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +{ + DRIVER_INFO_2 *info=NULL; + + info=(DRIVER_INFO_2 *)malloc(sizeof(DRIVER_INFO_2)); + + construct_printer_driver_info_2(info, snum, servername, architecture); + + /* check the required size. */ + *needed += spoolss_size_printer_driver_info_2(info); + + if (!alloc_buffer_size(buffer, *needed)) + return ERROR_INSUFFICIENT_BUFFER; + + /* fill the buffer with the structures */ + new_smb_io_printer_driver_info_2("", buffer, info, 0); + + /* clear memory */ + safe_free(info); + + if (*needed > offered) { + return ERROR_INSUFFICIENT_BUFFER; + } + else + return NT_STATUS_NO_PROBLEMO; +} + +/**************************************************************************** +****************************************************************************/ +static uint32 getprinterdriver2_level3(pstring servername, pstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +{ + DRIVER_INFO_3 *info=NULL; + + info=(DRIVER_INFO_3 *)malloc(sizeof(DRIVER_INFO_3)); + + construct_printer_driver_info_3(info, snum, servername, architecture); + + /* check the required size. */ + *needed += spoolss_size_printer_driver_info_3(info); + + if (!alloc_buffer_size(buffer, *needed)) + return ERROR_INSUFFICIENT_BUFFER; + + /* fill the buffer with the structures */ + new_smb_io_printer_driver_info_3("", buffer, info, 0); + + /* clear memory */ + safe_free(info); + + if (*needed > offered) { + return ERROR_INSUFFICIENT_BUFFER; + } + else + return NT_STATUS_NO_PROBLEMO; +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_getprinterdriver2(const POLICY_HND *handle, const UNISTR2 *uni_arch, uint32 level, uint32 unknown, + NEW_BUFFER *buffer, uint32 offered, + uint32 *needed, uint32 *unknown0, uint32 *unknown1) { pstring servername; fstring architecture; int snum; - DRIVER_INFO_1 *info1=NULL; - DRIVER_INFO_2 *info2=NULL; - DRIVER_INFO_3 *info3=NULL; + + DEBUG(4,("_spoolss_getprinterdriver2\n")); + + *needed=0; + *unknown0=0; + *unknown1=0; pstrcpy(servername, global_myname); + unistr2_to_ascii(architecture, uni_arch, sizeof(architecture)-1); - if (!get_printer_snum(handle,&snum)) + if (!get_printer_snum(handle, &snum)) { return NT_STATUS_INVALID_HANDLE; } - unistr2_to_ascii(architecture, uni_arch, sizeof(architecture) ); - - DEBUG(1,("spoolss_getprinterdriver2:[%d]\n", level)); - - switch (level) - { - case 1: - { - info1=(DRIVER_INFO_1 *)malloc(sizeof(DRIVER_INFO_1)); - construct_printer_driver_info_1(info1, snum, servername, architecture); - ctr->driver.info1=info1; - - return 0x0; - } - case 2: - { - info2=(DRIVER_INFO_2 *)malloc(sizeof(DRIVER_INFO_2)); - construct_printer_driver_info_2(info2, snum, servername, architecture); - ctr->driver.info2=info2; - - return 0x0; - } - case 3: - { - info3=(DRIVER_INFO_3 *)malloc(sizeof(DRIVER_INFO_3)); - construct_printer_driver_info_3(info3, snum, servername, architecture); - ctr->driver.info3=info3; - - return 0x0; - } - default: - { - break; - } + switch (level) { + case 1: + return getprinterdriver2_level1(servername, architecture, snum, buffer, offered, needed); + break; + case 2: + return getprinterdriver2_level2(servername, architecture, snum, buffer, offered, needed); + break; + case 3: + return getprinterdriver2_level3(servername, architecture, snum, buffer, offered, needed); + break; + default: + return NT_STATUS_INVALID_LEVEL; + break; } - return NT_STATUS_INVALID_INFO_CLASS; } /**************************************************************************** @@ -2617,10 +2721,9 @@ uint32 _spoolss_fcpn( const POLICY_HND *handle) /**************************************************************************** ****************************************************************************/ uint32 _spoolss_addjob( const POLICY_HND *handle, uint32 level, - const BUFFER *buffer, - uint32 buf_size) + NEW_BUFFER *buffer, uint32 offered) { - return 0x0; + return NT_STATUS_NO_PROBLEMO; } /**************************************************************************** @@ -3273,7 +3376,7 @@ uint32 _spoolss_enumports( UNISTR2 *name, uint32 level, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { - DEBUG(4,("spoolss_enumports\n")); + DEBUG(4,("_spoolss_enumports\n")); *returned=0; *needed=0; @@ -3293,30 +3396,23 @@ uint32 _spoolss_enumports( UNISTR2 *name, uint32 level, /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_addprinterex( const UNISTR2 *uni_srv_name, - uint32 level, +uint32 _spoolss_addprinterex( const UNISTR2 *uni_srv_name, uint32 level, const SPOOL_PRINTER_INFO_LEVEL *info, - uint32 unk0, - uint32 unk1, - uint32 unk2, - uint32 unk3, - uint32 user_level, - const SPOOL_USER_LEVEL *user, + uint32 unk0, uint32 unk1, uint32 unk2, uint32 unk3, + uint32 user_switch, const SPOOL_USER_CTR *user, POLICY_HND *handle) { NT_PRINTER_INFO_LEVEL printer; - fstring ascii_name; - fstring server_name; + fstring name; fstring share_name; - UNISTR2 *portname; - SPOOL_PRINTER_INFO_LEVEL_2 *info2; - uint32 status = 0x0; - - if (!open_printer_hnd(handle)) - { - return NT_STATUS_ACCESS_DENIED; - } + clear_handle(handle); + +/* + * FIX: JFM: we need to check the user here !!!! + * + * as the code is running as root, anybody can add printers to the server + */ /* NULLify info_2 here */ /* don't put it in convert_printer_info as it's used also with non-NULL values */ printer.info_2=NULL; @@ -3324,31 +3420,31 @@ uint32 _spoolss_addprinterex( const UNISTR2 *uni_srv_name, /* convert from UNICODE to ASCII */ convert_printer_info(info, &printer, level); - /* write the ASCII on disk */ - status = add_a_printer(printer, level); - if (status != 0x0) - { - close_printer_handle(handle); - return status; - } + unistr2_to_ascii(share_name, &((info->info_2)->portname), sizeof(share_name)-1); + + slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname, share_name); + + create_printer_hnd(handle); - info2=info->info_2; - portname=&(info2->portname); + open_printer_hnd(handle); - StrnCpy(server_name, global_myname, strlen(global_myname) ); - unistr2_to_ascii(share_name, portname, sizeof(share_name)-1); + if (!set_printer_hnd_printertype(handle, name)) { + close_printer_handle(handle); + return NT_STATUS_ACCESS_DENIED; + } - slprintf(ascii_name, sizeof(ascii_name)-1, "\\\\%s\\%s", - server_name, share_name); - - if (!set_printer_hnd_printertype(handle, ascii_name) || - !set_printer_hnd_printername(handle, ascii_name)) - { + if (!set_printer_hnd_printername(handle, name)) { close_printer_handle(handle); return NT_STATUS_ACCESS_DENIED; } - return 0x0; + /* write the ASCII on disk */ + if (add_a_printer(printer, level) != 0x0) { + close_printer_handle(handle); + return NT_STATUS_ACCESS_DENIED; + } + + return NT_STATUS_NO_PROBLEMO; } /**************************************************************************** @@ -3358,35 +3454,77 @@ uint32 _spoolss_addprinterdriver( const UNISTR2 *server_name, const SPOOL_PRINTER_DRIVER_INFO_LEVEL *info) { NT_PRINTER_DRIVER_INFO_LEVEL driver; + convert_printer_driver_info(info, &driver, level); - return add_a_printer_driver(driver, level); + + if (add_a_printer_driver(driver, level)!=0) + return NT_STATUS_ACCESS_DENIED; + + return NT_STATUS_NO_PROBLEMO; } /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_getprinterdriverdirectory( const UNISTR2 *name, - const UNISTR2 *uni_environment, - uint32 level, - DRIVER_DIRECTORY_CTR *ctr, - uint32 *offered) +static void fill_driverdir_1(DRIVER_DIRECTORY_1 *info, char *name) +{ + init_unistr(&(info->name), name); +} + +/**************************************************************************** +****************************************************************************/ +static uint32 getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environment, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { pstring chaine; pstring long_archi; - pstring archi; - + pstring short_archi; + DRIVER_DIRECTORY_1 *info=NULL; + + info=(DRIVER_DIRECTORY_1 *)malloc(sizeof(DRIVER_DIRECTORY_1)); + unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)-1); - get_short_archi(archi, long_archi); + get_short_archi(short_archi, long_archi); - slprintf(chaine,sizeof(chaine)-1,"\\\\%s\\print$\\%s", - global_myname, archi); + slprintf(chaine, sizeof(chaine)-1, "\\\\%s\\print$\\%s", global_myname, short_archi); DEBUG(4,("printer driver directory: [%s]\n", chaine)); - - init_unistr(&(ctr->driver.info_1.name), chaine); - return 0x0; + fill_driverdir_1(info, chaine); + + *needed += spoolss_size_driverdir_info_1(info); + + if (!alloc_buffer_size(buffer, *needed)) + return ERROR_INSUFFICIENT_BUFFER; + + new_smb_io_driverdir_1("", buffer, info, 0); + + safe_free(info); + + if (*needed > offered) + return ERROR_INSUFFICIENT_BUFFER; + else + return NT_STATUS_NO_PROBLEMO; } +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_getprinterdriverdirectory(UNISTR2 *name, UNISTR2 *uni_environment, uint32 level, + NEW_BUFFER *buffer, uint32 offered, + uint32 *needed) +{ + DEBUG(4,("_spoolss_getprinterdriverdirectory\n")); + + *needed=0; + + switch(level) { + case 1: + return getprinterdriverdir_level_1(name, uni_environment, buffer, offered, needed); + break; + default: + return NT_STATUS_INVALID_INFO_CLASS; + break; + } +} + /**************************************************************************** ****************************************************************************/ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, @@ -3755,84 +3893,127 @@ uint32 _spoolss_enumprintmonitors(UNISTR2 *name,uint32 level, /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_getjob( const POLICY_HND *handle, - uint32 jobid, - uint32 level, - PJOB_INFO *ctr, - uint32 *offered) +static uint32 getjob_level_1(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +{ + int i=0; + BOOL found=False; + JOB_INFO_1 *info_1=NULL; + info_1=(JOB_INFO_1 *)malloc(sizeof(JOB_INFO_1)); + + if (info_1 == NULL) { + safe_free(queue); + return NT_STATUS_NO_MEMORY; + } + + for (i=0; i offered) + return ERROR_INSUFFICIENT_BUFFER; + else + return NT_STATUS_NO_PROBLEMO; +} + + +/**************************************************************************** +****************************************************************************/ +static uint32 getjob_level_2(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +{ + int i=0; + BOOL found=False; + JOB_INFO_2 *info_2=NULL; + info_2=(JOB_INFO_2 *)malloc(sizeof(JOB_INFO_2)); + + if (info_2 == NULL) { + safe_free(queue); + return NT_STATUS_NO_MEMORY; + } + + for (i=0; i offered) + return ERROR_INSUFFICIENT_BUFFER; + else + return NT_STATUS_NO_PROBLEMO; +} + +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_getjob( POLICY_HND *handle, uint32 jobid, uint32 level, + NEW_BUFFER *buffer, uint32 offered, + uint32 *needed) { int snum; int count; - int i; print_queue_struct *queue=NULL; print_status_struct prt_status; - DEBUG(4,("spoolss_getjob\n")); + DEBUG(5,("spoolss_getjob\n")); - bzero(&prt_status,sizeof(prt_status)); + bzero(&prt_status, sizeof(prt_status)); + *needed=0; + if (!get_printer_snum(handle, &snum)) { return NT_STATUS_INVALID_HANDLE; } + count=get_printqueue(snum, NULL, &queue, &prt_status); DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n", count, prt_status.status, prt_status.message)); - - switch (level) - { - case 1: - { - JOB_INFO_1 *job_info_1=NULL; - job_info_1=(JOB_INFO_1 *)malloc(sizeof(JOB_INFO_1)); - - if (job_info_1 == NULL) - { - safe_free(queue); - return NT_STATUS_NO_MEMORY; - } - - for (i=0; ijob.job_info_1=job_info_1; - break; - } - case 2: - { - JOB_INFO_2 *job_info_2=NULL; - job_info_2=(JOB_INFO_2 *)malloc(sizeof(JOB_INFO_2)); - - if (job_info_2 == NULL) - { - safe_free(queue); - return NT_STATUS_NO_MEMORY; - } - - for (i=0; ijob.job_info_2=job_info_2; - break; - } - default: - { - safe_free(queue); - return NT_STATUS_INVALID_INFO_CLASS; - } + + switch (level) { + case 1: + return getjob_level_1(queue, count, snum, jobid, buffer, offered, needed); + break; + case 2: + return getjob_level_1(queue, count, snum, jobid, buffer, offered, needed); + break; + default: + safe_free(queue); + return NT_STATUS_INVALID_INFO_CLASS; + break; } - - safe_free(queue); - return 0x0; } + -- cgit From f3319f7963e04a9642d604e706a10df3cd96dd73 Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Thu, 24 Feb 2000 16:27:06 +0000 Subject: converted a couple of bzero() to memset() rewrote the printer notify code, so now it's compatible with SP5 and fully dynamic. No more limits on printers and job lists. removed the make_xxx() functions as they are not used and broken fixed a bug in the open handle function. J.F. (This used to be commit aa9054d14bc940f251639ab897d9f356814f5fc0) --- source3/rpc_server/srv_spoolss_nt.c | 469 ++++++++++++++++++++---------------- 1 file changed, 266 insertions(+), 203 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 90a7b44aef..cd0d0a8ab1 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -39,28 +39,31 @@ extern pstring global_myname; /* and a reference to what it's pointing to */ /* and the notify info asked about */ /* that's the central struct */ -static struct -{ - BOOL open; - BOOL ok; - BOOL document_started; - BOOL page_started; - uint32 current_jobid; - uint32 document_fd; - uint32 document_lastwritten; - pstring document_name; - pstring job_name; - POLICY_HND printer_hnd; - BOOL printer_type; - union - { - fstring printername; - fstring printerservername; - } dev; - uint32 type; - uint32 access; - uint32 number_of_notify; - SPOOL_NOTIFY_OPTION_TYPE notify_info[MAX_PRINTER_NOTIFY+MAX_JOB_NOTIFY]; +static struct { + BOOL open; + BOOL ok; + BOOL document_started; + BOOL page_started; + uint32 current_jobid; + uint32 document_fd; + uint32 document_lastwritten; + pstring document_name; + pstring job_name; + POLICY_HND printer_hnd; + BOOL printer_type; + union { + fstring printername; + fstring printerservername; + } dev; + uint32 type; + uint32 access; + struct { + uint32 flags; + uint32 options; + fstring localmachine; + uint32 printerlocal; + SPOOL_NOTIFY_OPTION *option; + } notify; } Printer[MAX_OPEN_PRINTER_EXS]; #define VALID_HANDLE(pnum) (((pnum) >= 0) && ((pnum) < MAX_OPEN_PRINTER_EXS)) @@ -110,13 +113,13 @@ static int find_printer_index_by_hnd(const POLICY_HND *hnd) { if (memcmp(&(Printer[i].printer_hnd), hnd, sizeof(*hnd)) == 0) { - DEBUG(4,("Found printer handle[%x] ", i)); - dump_data(4, hnd->data, sizeof(hnd->data)); + DEBUG(4,("Found printer handle[%x] \n", i)); + /*dump_data(4, hnd->data, sizeof(hnd->data));*/ return i; } } DEBUG(3,("Whoops, Printer handle not found: ")); - dump_data(4, hnd->data, sizeof(hnd->data)); + /*dump_data(4, hnd->data, sizeof(hnd->data));*/ return -1; } @@ -125,7 +128,7 @@ static int find_printer_index_by_hnd(const POLICY_HND *hnd) ****************************************************************************/ static void clear_handle(POLICY_HND *hnd) { - bzero(hnd->data, POLICY_HND_SIZE); + memset(hnd->data, 0, POLICY_HND_SIZE); } /**************************************************************************** @@ -142,6 +145,13 @@ static BOOL close_printer_handle(POLICY_HND *hnd) } Printer[pnum].open=False; + Printer[pnum].notify.flags=0; + Printer[pnum].notify.options=0; + Printer[pnum].notify.localmachine[0]='\0'; + Printer[pnum].notify.printerlocal=0; + safe_free(Printer[pnum].notify.option); + Printer[pnum].notify.option=NULL; + clear_handle(hnd); return True; @@ -204,6 +214,7 @@ static BOOL open_printer_hnd(POLICY_HND *hnd) memcpy(&(Printer[i].printer_hnd), hnd, sizeof(*hnd)); DEBUG(4,("Opened printer handle[%x] ", i)); dump_data(4, hnd->data, sizeof(hnd->data)); + Printer[i].notify.option=NULL; return True; } } @@ -334,6 +345,7 @@ static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) return False; } + snum--; DEBUGADD(4,("Printer found: %s[%x]\n",lp_servicename(snum),snum)); ZERO_STRUCT(Printer[pnum].dev.printername); strncpy(Printer[pnum].dev.printername, lp_servicename(snum), strlen(lp_servicename(snum))); @@ -635,7 +647,7 @@ static BOOL getprinterdata_printer(const POLICY_HND *handle, if (get_specific_param(printer, 2, value, &idata, type, &len)) { *data = (uint8 *)malloc( (len>in_size)?len:in_size *sizeof(uint8) ); - bzero(*data, sizeof(uint8)*len); + memset(*data, 0, sizeof(uint8)*len); memcpy(*data, idata, (len>in_size)?len:in_size); *needed = len; @@ -713,42 +725,26 @@ uint32 _spoolss_getprinterdata(const POLICY_HND *handle, UNISTR2 *valuename, * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe * called from api_spoolss_rffpcnex ********************************************************************/ -uint32 _spoolss_rffpcnex(const POLICY_HND *handle, - uint32 flags, uint32 options, - const UNISTR2 *localmachine, - uint32 printerlocal, - SPOOL_NOTIFY_OPTION *option) +uint32 _spoolss_rffpcnex(const POLICY_HND *handle, uint32 flags, uint32 options, + const UNISTR2 *localmachine, uint32 printerlocal, + SPOOL_NOTIFY_OPTION *option) { - int i,j,k; + int i; /* store the notify value in the printer struct */ i=find_printer_index_by_hnd(handle); if (i == -1) - { return NT_STATUS_INVALID_HANDLE; - } - - Printer[i].number_of_notify=option->count; - DEBUG(3,("Copying %x notify option info\n",Printer[i].number_of_notify)); + Printer[i].notify.flags=flags; + Printer[i].notify.options=options; + Printer[i].notify.printerlocal=printerlocal; + Printer[i].notify.option=option; + unistr2_to_ascii(Printer[i].notify.localmachine, localmachine, sizeof(Printer[i].notify.localmachine)-1); - for (j=0;jtype[j].count; - Printer[i].notify_info[j].type=option->type[j].type ; - - DEBUG(4,("Copying %x info fields of type %x\n", - Printer[i].notify_info[j].count, - Printer[i].notify_info[j].type)); - for(k=0;ktype[j].fields[k]; - } - } - - return 0x0; + return NT_STATUS_NO_PROBLEMO; } /******************************************************************* @@ -961,7 +957,7 @@ static void spoolss_notify_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_ print_queue_struct *q=NULL; print_status_struct status; - bzero(&status,sizeof(status)); + memset(&status, 0, sizeof(status)); count=get_printqueue(snum, NULL, &q, &status); @@ -977,7 +973,7 @@ static void spoolss_notify_cjobs(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_q print_queue_struct *q=NULL; print_status_struct status; - bzero(&status,sizeof(status)); + memset(&status, 0, sizeof(status)); data->notify_data.value[0]=get_printqueue(snum, NULL, &q, &status); if (q) free(q); @@ -1163,40 +1159,30 @@ static int search_notify(uint16 type, uint16 field, int *value) int j; BOOL found; - DEBUG(4,("\tsearch_notify: in\n")); for (j=0, found=False; found==False && notify_info_data_table[j].type != END ; j++) { if ( (notify_info_data_table[j].type == type ) && (notify_info_data_table[j].field == field ) ) - { found=True; - } } *value=--j; if ( found && (notify_info_data_table[j].fn != NULL) ) - { - DEBUG(4,("\tsearch_notify: out TRUE\n")); - return (True); - } + return True; else - { - DEBUG(4,("\tsearch_notify: out FALSE\n")); - return (False); - } + return False; } /**************************************************************************** ****************************************************************************/ static void construct_info_data(SPOOL_NOTIFY_INFO_DATA *info_data, uint16 type, uint16 field, int id) { - DEBUG(4,("\tconstruct_info_data: in\n")); info_data->type = type; info_data->field = field; + info_data->reserved = 0; info_data->id = id; info_data->size = size_of_notify_info_data(type, field); info_data->enc_type = type_of_notify_info_data(type, field); - DEBUG(4,("\tconstruct_info_data: out\n")); } @@ -1205,49 +1191,48 @@ static void construct_info_data(SPOOL_NOTIFY_INFO_DATA *info_data, uint16 type, * fill a notify_info struct with info asked * ********************************************************************/ -static void construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int pnum, - int snum, int i, uint32 id) +static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPOOL_NOTIFY_OPTION_TYPE *option_type, uint32 id) { - - int k,j; + int field_num,j; uint16 type; uint16 field; - SPOOL_NOTIFY_INFO_DATA *info_data; - print_queue_struct *queue=NULL; + SPOOL_NOTIFY_INFO_DATA *current_data; NT_PRINTER_INFO_LEVEL printer; + print_queue_struct *queue=NULL; DEBUG(4,("construct_notify_printer_info\n")); - info_data=&(info->data[info->count]); - - type = Printer[pnum].notify_info[i].type; + type=option_type->type; - DEBUGADD(4,("Notify number %d -> number of notify info: %d\n",i,Printer[pnum].notify_info[i].count)); + DEBUGADD(4,("Notify type: [%s], number of notify info: [%d] on printer: [%s]\n", + (option_type->type==PRINTER_NOTIFY_TYPE?"PRINTER_NOTIFY_TYPE":"JOB_NOTIFY_TYPE"), + option_type->count, lp_servicename(snum))); - if (!get_a_printer(&printer, 2, lp_servicename(snum))) + if (get_a_printer(&printer, 2, lp_servicename(snum))!=0) + { + return False; + } + + for(field_num=0; field_numcount; field_num++) { + field = option_type->fields[field_num]; + DEBUGADD(4,("notify [%d]: type [%x], field [%x]\n", field_num, type, field)); + + if (!search_notify(type, field, &j) ) + continue; - for(k=0; kdata=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA)); + current_data=&(info->data[info->count]); - if (search_notify(type, field, &j) ) - { - DEBUGADD(4,("j=[%d]:%s\n", j, notify_info_data_table[j].name)); - construct_info_data(info_data, type, field, id); - - DEBUGADD(4,("notify_info_data_table: in\n")); - notify_info_data_table[j].fn(snum, info_data, queue, &printer); - DEBUGADD(4,("notify_info_data_table: out\n")); - info->count++; - info_data=&(info->data[info->count]); - } - } - - free_a_printer(printer, 2); + construct_info_data(current_data, type, field, id); + notify_info_data_table[j].fn(snum, current_data, queue, &printer); + + info->count++; } + + free_a_printer(printer, 2); + return True; } /******************************************************************* @@ -1255,46 +1240,72 @@ static void construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int pnum, * fill a notify_info struct with info asked * ********************************************************************/ -static void construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_INFO *info, - int pnum, int snum, int i, uint32 id) +static BOOL construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_INFO *info, int snum, SPOOL_NOTIFY_OPTION_TYPE *option_type, uint32 id) { - - int k,j; + int field_num,j; uint16 type; uint16 field; - SPOOL_NOTIFY_INFO_DATA *info_data; + SPOOL_NOTIFY_INFO_DATA *current_data; NT_PRINTER_INFO_LEVEL printer; DEBUG(4,("construct_notify_jobs_info\n")); - info_data=&(info->data[info->count]); - type = Printer[pnum].notify_info[i].type; + type = option_type->type; - DEBUGADD(4,("Notify number %d -> number of notify info: %d\n",i,Printer[pnum].notify_info[i].count)); + DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n", + (option_type->type==PRINTER_NOTIFY_TYPE?"PRINTER_NOTIFY_TYPE":"JOB_NOTIFY_TYPE"), + option_type->count)); - if (!get_a_printer(&printer, 2, lp_servicename(snum))) + if (get_a_printer(&printer, 2, lp_servicename(snum))!=0) { - for(k=0; kcount; field_num++) + { + field = option_type->fields[field_num]; - if (search_notify(type, field, &j) ) - { - DEBUGADD(4,("j=[%d]:%s\n", j, notify_info_data_table[j].name)); - construct_info_data(info_data, type, field, id); - DEBUGADD(4,("notify_info_data_table: in\n")); - notify_info_data_table[j].fn(snum, info_data, queue, &printer); - DEBUGADD(4,("notify_info_data_table: out\n")); - info->count++; - info_data=&(info->data[info->count]); - } - } - free_a_printer(printer, 2); + if (!search_notify(type, field, &j) ) + continue; + + info->data=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA)); + current_data=&(info->data[info->count]); + + construct_info_data(current_data, type, field, id); + notify_info_data_table[j].fn(snum, current_data, queue, &printer); + info->count++; } + + free_a_printer(printer, 2); + + return True; } +/* + * JFM: The enumeration is not that simple, it's even non obvious. + * + * let's take an example: I want to monitor the PRINTER SERVER for + * the printer's name and the number of jobs currently queued. + * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure. + * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS. + * + * I have 3 printers on the back of my server. + * + * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA + * structures. + * Number Data Id + * 1 printer 1 name 1 + * 2 printer 1 cjob 1 + * 3 printer 2 name 2 + * 4 printer 2 cjob 2 + * 5 printer 3 name 3 + * 6 printer 3 name 3 + * + * that's the print server case, the printer case is even worse. + */ + + /******************************************************************* * @@ -1302,40 +1313,54 @@ static void construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_I * fill a notify_info struct with info asked * ********************************************************************/ -static uint32 printserver_notify_info(const POLICY_HND *hnd, - SPOOL_NOTIFY_INFO *info) +static uint32 printserver_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info) { int snum; int pnum=find_printer_index_by_hnd(hnd); int n_services=lp_numservices(); - int i=0; - uint32 id=1; + int i; + uint32 id; + SPOOL_NOTIFY_OPTION *option; + SPOOL_NOTIFY_OPTION_TYPE *option_type; + + DEBUG(4,("printserver_notify_info\n")); + + option=Printer[pnum].notify.option; + id=1; + info->version=2; + info->data=NULL; info->count=0; - if (pnum == -1) + for (i=0; icount; i++) { - return NT_STATUS_INVALID_HANDLE; + option_type=&(option->ctr.type[i]); + + if (option_type->type!=PRINTER_NOTIFY_TYPE) + continue; + + for (snum=0; snumversion:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count)); + DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n")); + + for (i=0; icount; i++) { - if ( Printer[pnum].notify_info[i].type == PRINTER_NOTIFY_TYPE ) - { - for (snum=0; snumdata[i].type, info->data[i].field, info->data[i].reserved, + info->data[i].id, info->data[i].size, info->data[i].enc_type)); } - DEBUG(4,("All printers enumerated\n")); - - return 0x0; + */ + + return NT_STATUS_NO_PROBLEMO; } /******************************************************************* @@ -1343,59 +1368,72 @@ static uint32 printserver_notify_info(const POLICY_HND *hnd, * fill a notify_info struct with info asked * ********************************************************************/ -static uint32 printer_notify_info(const POLICY_HND *hnd, - SPOOL_NOTIFY_INFO *info) +static uint32 printer_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info) { int snum; int pnum=find_printer_index_by_hnd(hnd); - int i=0, j; - uint32 id=0xFFFF; + int i; + uint32 id; + SPOOL_NOTIFY_OPTION *option; + SPOOL_NOTIFY_OPTION_TYPE *option_type; + int count,j; + print_queue_struct *queue=NULL; + print_status_struct status; + DEBUG(4,("printer_notify_info\n")); + + option=Printer[pnum].notify.option; + id=1; + info->version=2; + info->data=NULL; info->count=0; - if (pnum == -1 || !get_printer_snum(hnd, &snum) ) - { - return NT_STATUS_INVALID_HANDLE; - } + get_printer_snum(hnd, &snum); - for (i=0; icount; i++) { - switch ( Printer[pnum].notify_info[i].type ) - { - case PRINTER_NOTIFY_TYPE: - { - construct_notify_printer_info(info, pnum, snum, i, id); - id--; - break; - } - case JOB_NOTIFY_TYPE: - { - int count; - print_queue_struct *queue=NULL; - print_status_struct status; - bzero(&status, sizeof(status)); - count=get_printqueue(snum, NULL, &queue, &status); - for (j=0; jctr.type[i]); + + switch ( option_type->type ) { + case PRINTER_NOTIFY_TYPE: + if(construct_notify_printer_info(info, snum, option_type, id)) + id++; + break; + + case JOB_NOTIFY_TYPE: + memset(&status, 0, sizeof(status)); + count=get_printqueue(snum, NULL, &queue, &status); + for (j=0; jversion:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count)); + DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n")); + + for (i=0; icount; i++) + { + DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n", + i, info->data[i].type, info->data[i].field, info->data[i].reserved, + info->data[i].id, info->data[i].size, info->data[i].enc_type)); + } + */ + return NT_STATUS_NO_PROBLEMO; } /******************************************************************** * spoolss_rfnpcnex ********************************************************************/ -uint32 _spoolss_rfnpcnex( const POLICY_HND *handle, - uint32 change, - const SPOOL_NOTIFY_OPTION *option, - uint32 *count, - SPOOL_NOTIFY_INFO *info) +uint32 _spoolss_rfnpcnex( const POLICY_HND *handle, uint32 change, + SPOOL_NOTIFY_OPTION *option, SPOOL_NOTIFY_INFO *info) { int pnum=find_printer_index_by_hnd(handle); @@ -1404,21 +1442,32 @@ uint32 _spoolss_rfnpcnex( const POLICY_HND *handle, return NT_STATUS_INVALID_HANDLE; } - DEBUG(4,("Printer %x of type %x\n",pnum,Printer[pnum].printer_type)); + DEBUG(4,("Printer %x of type %x\n",pnum, Printer[pnum].printer_type)); + + /* jfm: the change value isn't used right now. + * we will honour it when + * a) we'll be able to send notification to the client + * b) we'll have a way to communicate between the spoolss process. + * + * same thing for option->flags + * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as + * I don't have a global notification system, I'm sending back all the + * informations even when _NOTHING_ has changed. + */ - /* lkxlXXXX - jfm, is this right? put a warning in for you to review! */ - DEBUG(0,("_spoolss_rfnpcnex: change, option and count ignored\n")); + /* just discard the SPOOL_NOTIFY_OPTION */ + if (option!=NULL) + safe_free(option->ctr.type); + + safe_free(option); - switch (Printer[pnum].printer_type) - { + switch (Printer[pnum].printer_type) { case PRINTER_HANDLE_IS_PRINTSERVER: - { return printserver_notify_info(handle, info); - } + break; case PRINTER_HANDLE_IS_PRINTER: - { return printer_notify_info(handle, info); - } + break; } return NT_STATUS_INVALID_INFO_CLASS; @@ -1436,7 +1485,7 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer,int snum, pstring s print_queue_struct *queue=NULL; print_status_struct status; - bzero(&status,sizeof(status)); + memset(&status, 0, sizeof(status)); if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) != 0) { @@ -1476,7 +1525,7 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer,int snum, pstring s printer->unknown14 = 0x1; printer->unknown15 = 0x024a; /*586 Pentium ? */ printer->unknown16 = 0x0; - printer->unknown17 = 0x423ed444; + printer->unknown17 = 0x423ed444; /* CacheChangeID */ printer->unknown18 = 0x0; printer->status = status.status; printer->unknown20 = 0x0; @@ -1536,8 +1585,8 @@ static void construct_dev_mode(DEVICEMODE *devmode, int snum, char *servername) DEBUG(7,("construct_dev_mode\n")); - bzero(&(devmode->devicename), 2*sizeof(adevice)); - bzero(&(devmode->formname), 2*sizeof(aform)); + memset(&(devmode->devicename), 0, 2*sizeof(adevice)); + memset(&(devmode->formname), 0, 2*sizeof(aform)); DEBUGADD(8,("getting printer characteristics\n")); @@ -1598,7 +1647,7 @@ static BOOL construct_printer_info_2(PRINTER_INFO_2 *printer, int snum, pstring print_queue_struct *queue=NULL; print_status_struct status; - bzero(&status, sizeof(status)); + memset(&status, 0, sizeof(status)); count=get_printqueue(snum, NULL, &queue, &status); if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0 ) @@ -2713,14 +2762,28 @@ uint32 _spoolss_setprinter( const POLICY_HND *handle, /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_fcpn( const POLICY_HND *handle) +uint32 _spoolss_fcpn(const POLICY_HND *handle) { - return 0x0; + int pnum = find_printer_index_by_hnd(handle); + + if (!OPEN_HANDLE(pnum)) + { + return NT_STATUS_INVALID_HANDLE; + } + + Printer[pnum].notify.flags=0; + Printer[pnum].notify.options=0; + Printer[pnum].notify.localmachine[0]='\0'; + Printer[pnum].notify.printerlocal=0; + safe_free(Printer[pnum].notify.option); + Printer[pnum].notify.option=NULL; + + return NT_STATUS_NO_PROBLEMO; } /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_addjob( const POLICY_HND *handle, uint32 level, +uint32 _spoolss_addjob(const POLICY_HND *handle, uint32 level, NEW_BUFFER *buffer, uint32 offered) { return NT_STATUS_NO_PROBLEMO; @@ -2956,7 +3019,7 @@ uint32 _spoolss_setjob( const POLICY_HND *handle, BOOL found=False; int count; - bzero(&prt_status,sizeof(prt_status)); + memset(&prt_status, 0, sizeof(prt_status)); if (!get_printer_snum(handle, &snum)) { @@ -3989,7 +4052,7 @@ uint32 _spoolss_getjob( POLICY_HND *handle, uint32 jobid, uint32 level, DEBUG(5,("spoolss_getjob\n")); - bzero(&prt_status, sizeof(prt_status)); + memset(&prt_status, 0, sizeof(prt_status)); *needed=0; -- cgit From 66018871c7eb1fedcdf8829b53038b6b484db6a3 Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Thu, 24 Feb 2000 23:01:24 +0000 Subject: made dynamic the Printer struct. No more limits :-) J.F. (This used to be commit b59233b3b61b17e85f5d5b44cc6f2ced9d27b497) --- source3/rpc_server/srv_spoolss_nt.c | 356 +++++++++++++++++------------------- 1 file changed, 169 insertions(+), 187 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index cd0d0a8ab1..da7eda5795 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -39,9 +39,11 @@ extern pstring global_myname; /* and a reference to what it's pointing to */ /* and the notify info asked about */ /* that's the central struct */ -static struct { +typedef struct _Printer{ + ubi_dlNode Next; + ubi_dlNode Prev; + BOOL open; - BOOL ok; BOOL document_started; BOOL page_started; uint32 current_jobid; @@ -64,21 +66,18 @@ static struct { uint32 printerlocal; SPOOL_NOTIFY_OPTION *option; } notify; -} Printer[MAX_OPEN_PRINTER_EXS]; +} Printer_entry; + +static ubi_dlList Printer_list; -#define VALID_HANDLE(pnum) (((pnum) >= 0) && ((pnum) < MAX_OPEN_PRINTER_EXS)) -#define OPEN_HANDLE(pnum) (VALID_HANDLE(pnum) && Printer[pnum].open) +#define OPEN_HANDLE(pnum) ((pnum!=NULL) && (pnum->open!=False)) /**************************************************************************** initialise printer handle states... ****************************************************************************/ void init_printer_hnd(void) { - int i; - for (i = 0; i < MAX_OPEN_PRINTER_EXS; i++) - { - Printer[i].open = False; - } + ubi_dlInitList(&Printer_list); } /**************************************************************************** @@ -105,22 +104,25 @@ static void create_printer_hnd(POLICY_HND *hnd) /**************************************************************************** find printer index by handle ****************************************************************************/ -static int find_printer_index_by_hnd(const POLICY_HND *hnd) +static Printer_entry *find_printer_index_by_hnd(const POLICY_HND *hnd) { - int i; + Printer_entry *find_printer; - for (i = 0; i < MAX_OPEN_PRINTER_EXS; i++) - { - if (memcmp(&(Printer[i].printer_hnd), hnd, sizeof(*hnd)) == 0) + find_printer = (Printer_entry *)ubi_dlFirst(&Printer_list); + + for(; find_printer; find_printer = (Printer_entry *)ubi_dlNext(find_printer)) { + + if (memcmp(&(find_printer->printer_hnd), hnd, sizeof(*hnd)) == 0) { - DEBUG(4,("Found printer handle[%x] \n", i)); + DEBUG(4,("Found printer handle \n")); /*dump_data(4, hnd->data, sizeof(hnd->data));*/ - return i; + return find_printer; } } + DEBUG(3,("Whoops, Printer handle not found: ")); /*dump_data(4, hnd->data, sizeof(hnd->data));*/ - return -1; + return NULL; } /**************************************************************************** @@ -136,24 +138,30 @@ static void clear_handle(POLICY_HND *hnd) ****************************************************************************/ static BOOL close_printer_handle(POLICY_HND *hnd) { - int pnum = find_printer_index_by_hnd(hnd); + Printer_entry *Printer = find_printer_index_by_hnd(hnd); - if (pnum == -1) + if (!OPEN_HANDLE(Printer)) { - DEBUG(3,("Error closing printer handle (pnum=%x)\n", pnum)); + DEBUG(3,("Error closing printer handle\n")); return False; } - Printer[pnum].open=False; - Printer[pnum].notify.flags=0; - Printer[pnum].notify.options=0; - Printer[pnum].notify.localmachine[0]='\0'; - Printer[pnum].notify.printerlocal=0; - safe_free(Printer[pnum].notify.option); - Printer[pnum].notify.option=NULL; + Printer->open=False; + Printer->notify.flags=0; + Printer->notify.options=0; + Printer->notify.localmachine[0]='\0'; + Printer->notify.printerlocal=0; + safe_free(Printer->notify.option); + Printer->notify.option=NULL; clear_handle(hnd); + ubi_dlRemThis(&Printer_list, Printer); + + safe_free(Printer); + + DEBUG(0,("[%d] entrys still in list\n", ubi_dlCount(&Printer_list))); + return True; } @@ -163,23 +171,23 @@ static BOOL close_printer_handle(POLICY_HND *hnd) static BOOL get_printer_snum(const POLICY_HND *hnd, int *number) { int snum; - int pnum = find_printer_index_by_hnd(hnd); + Printer_entry *Printer = find_printer_index_by_hnd(hnd); int n_services=lp_numservices(); - if (!OPEN_HANDLE(pnum)) { + if (!OPEN_HANDLE(Printer)) { DEBUG(3,("Error getting printer - take a nap quickly !\n")); return False; } - switch (Printer[pnum].printer_type) { + switch (Printer->printer_type) { case PRINTER_HANDLE_IS_PRINTER: - DEBUG(4,("short name:%s\n", Printer[pnum].dev.printername)); + DEBUG(4,("short name:%s\n", Printer->dev.printername)); for (snum=0;snumdev.printername ) ) && ( !strncasecmp(lp_servicename(snum), - Printer[pnum].dev.printername, + Printer->dev.printername, strlen( lp_servicename(snum) ))) ) { DEBUG(4,("Printer found: %s[%x]\n",lp_servicename(snum),snum)); *number=snum; @@ -204,22 +212,19 @@ static BOOL get_printer_snum(const POLICY_HND *hnd, int *number) ****************************************************************************/ static BOOL open_printer_hnd(POLICY_HND *hnd) { - int i; + Printer_entry *new_printer; - for (i = 0; i < MAX_OPEN_PRINTER_EXS; i++) - { - if (!Printer[i].open) - { - Printer[i].open = True; - memcpy(&(Printer[i].printer_hnd), hnd, sizeof(*hnd)); - DEBUG(4,("Opened printer handle[%x] ", i)); - dump_data(4, hnd->data, sizeof(hnd->data)); - Printer[i].notify.option=NULL; - return True; - } - } - DEBUG(1,("ERROR - open_printer_hnd: out of Printers Handles!\n")); - return False; + new_printer=(Printer_entry *)malloc(sizeof(Printer_entry)); + ZERO_STRUCTP(new_printer); + + new_printer->open = True; + new_printer->notify.option=NULL; + + memcpy(&(new_printer->printer_hnd), hnd, sizeof(*hnd)); + + ubi_dlAddHead( &Printer_list, (ubi_dlNode *)new_printer); + + return True; } /**************************************************************************** @@ -227,15 +232,15 @@ static BOOL open_printer_hnd(POLICY_HND *hnd) ****************************************************************************/ static BOOL set_printer_hnd_accesstype(POLICY_HND *hnd, uint32 access_required) { - int pnum = find_printer_index_by_hnd(hnd); + Printer_entry *Printer = find_printer_index_by_hnd(hnd); - if (!OPEN_HANDLE(pnum)) { - DEBUG(4,("Error setting printer type=%x (pnum=%x)", access_required, pnum)); + if (!OPEN_HANDLE(Printer)) { + DEBUG(4,("Error setting printer type=%x", access_required)); return False; } - DEBUG(4,("Setting printer access=%x (pnum=%x)\n", access_required, pnum)); - Printer[pnum].access = access_required; + DEBUG(4,("Setting printer access=%x\n", access_required)); + Printer->access = access_required; return True; } @@ -245,14 +250,14 @@ static BOOL set_printer_hnd_accesstype(POLICY_HND *hnd, uint32 access_required) ****************************************************************************/ static BOOL set_printer_hnd_printertype(POLICY_HND *hnd, char *printername) { - int pnum = find_printer_index_by_hnd(hnd); + Printer_entry *Printer = find_printer_index_by_hnd(hnd); - if (!OPEN_HANDLE(pnum)) { - DEBUGADD(4,("Error setting printer name %s (pnum=%x)", printername, pnum)); + if (!OPEN_HANDLE(Printer)) { + DEBUGADD(4,("Error setting printer name %s", printername)); return False; } - DEBUG(3,("Setting printer type=%s (pnum=%x)\n", printername, pnum)); + DEBUG(3,("Setting printer type=%s\n", printername)); if ( strlen(printername) < 3 ) { DEBUGADD(4,("A print server must have at least 1 char ! %s\n", printername)); @@ -262,13 +267,13 @@ static BOOL set_printer_hnd_printertype(POLICY_HND *hnd, char *printername) /* it's a print server */ if (!strchr(printername+2, '\\')) { DEBUGADD(4,("Printer is a print server\n")); - Printer[pnum].printer_type = PRINTER_HANDLE_IS_PRINTSERVER; + Printer->printer_type = PRINTER_HANDLE_IS_PRINTSERVER; return True; } /* it's a printer */ else { DEBUGADD(4,("Printer is a printer\n")); - Printer[pnum].printer_type = PRINTER_HANDLE_IS_PRINTER; + Printer->printer_type = PRINTER_HANDLE_IS_PRINTER; return True; } @@ -280,28 +285,28 @@ static BOOL set_printer_hnd_printertype(POLICY_HND *hnd, char *printername) ****************************************************************************/ static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) { - int pnum = find_printer_index_by_hnd(hnd); + Printer_entry *Printer = find_printer_index_by_hnd(hnd); NT_PRINTER_INFO_LEVEL printer; int snum; int n_services=lp_numservices(); char *aprinter; BOOL found=False; - if (!OPEN_HANDLE(pnum)) + if (!OPEN_HANDLE(Printer)) { - DEBUG(0,("Error setting printer name=%s (pnum=%x)\n", printername, pnum)); + DEBUG(0,("Error setting printer name=%s\n", printername)); return False; } - DEBUG(4,("Setting printer name=%s (len=%d) (pnum=%x)\n", printername, strlen(printername), pnum)); + DEBUG(4,("Setting printer name=%s (len=%d)\n", printername, strlen(printername))); - if (Printer[pnum].printer_type==PRINTER_HANDLE_IS_PRINTSERVER) { - ZERO_STRUCT(Printer[pnum].dev.printerservername); - strncpy(Printer[pnum].dev.printerservername, printername, strlen(printername)); + if (Printer->printer_type==PRINTER_HANDLE_IS_PRINTSERVER) { + ZERO_STRUCT(Printer->dev.printerservername); + strncpy(Printer->dev.printerservername, printername, strlen(printername)); return True; } - if (Printer[pnum].printer_type!=PRINTER_HANDLE_IS_PRINTER) + if (Printer->printer_type!=PRINTER_HANDLE_IS_PRINTER) return False; aprinter=strchr(printername+2, '\\'); @@ -347,8 +352,8 @@ static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) snum--; DEBUGADD(4,("Printer found: %s[%x]\n",lp_servicename(snum),snum)); - ZERO_STRUCT(Printer[pnum].dev.printername); - strncpy(Printer[pnum].dev.printername, lp_servicename(snum), strlen(lp_servicename(snum))); + ZERO_STRUCT(Printer->dev.printername); + strncpy(Printer->dev.printername, lp_servicename(snum), strlen(lp_servicename(snum))); free_a_printer(printer, 2); return True; @@ -359,12 +364,12 @@ static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) ********************************************************************/ static BOOL handle_is_printserver(const POLICY_HND *handle) { - int pnum=find_printer_index_by_hnd(handle); + Printer_entry *Printer=find_printer_index_by_hnd(handle); - if (!OPEN_HANDLE(pnum)) + if (!OPEN_HANDLE(Printer)) return False; - if (Printer[pnum].printer_type != PRINTER_HANDLE_IS_PRINTSERVER) + if (Printer->printer_type != PRINTER_HANDLE_IS_PRINTSERVER) return False; return True; @@ -631,15 +636,14 @@ static BOOL getprinterdata_printer(const POLICY_HND *handle, uint8 **data, uint32 *needed, uint32 in_size ) { NT_PRINTER_INFO_LEVEL printer; - int pnum=0; int snum=0; uint8 *idata=NULL; uint32 len; + Printer_entry *Printer = find_printer_index_by_hnd(handle); DEBUG(5,("getprinterdata_printer\n")); - pnum = find_printer_index_by_hnd(handle); - if (OPEN_HANDLE(pnum)) + if (OPEN_HANDLE(Printer)) { get_printer_snum(handle, &snum); get_a_printer(&printer, 2, lp_servicename(snum)); @@ -672,7 +676,7 @@ uint32 _spoolss_getprinterdata(const POLICY_HND *handle, UNISTR2 *valuename, { fstring value; BOOL found=False; - int pnum = find_printer_index_by_hnd(handle); + Printer_entry *Printer = find_printer_index_by_hnd(handle); /* * Reminder: when it's a string, the length is in BYTES @@ -689,7 +693,7 @@ uint32 _spoolss_getprinterdata(const POLICY_HND *handle, UNISTR2 *valuename, DEBUG(4,("_spoolss_getprinterdata\n")); - if (!OPEN_HANDLE(pnum)) { + if (!OPEN_HANDLE(Printer)) { *data=(uint8 *)malloc(4*sizeof(uint8)); return NT_STATUS_INVALID_HANDLE; } @@ -729,20 +733,18 @@ uint32 _spoolss_rffpcnex(const POLICY_HND *handle, uint32 flags, uint32 options, const UNISTR2 *localmachine, uint32 printerlocal, SPOOL_NOTIFY_OPTION *option) { - int i; - /* store the notify value in the printer struct */ - i=find_printer_index_by_hnd(handle); + Printer_entry *Printer=find_printer_index_by_hnd(handle); - if (i == -1) + if (!OPEN_HANDLE(Printer)) return NT_STATUS_INVALID_HANDLE; - Printer[i].notify.flags=flags; - Printer[i].notify.options=options; - Printer[i].notify.printerlocal=printerlocal; - Printer[i].notify.option=option; - unistr2_to_ascii(Printer[i].notify.localmachine, localmachine, sizeof(Printer[i].notify.localmachine)-1); + Printer->notify.flags=flags; + Printer->notify.options=options; + Printer->notify.printerlocal=printerlocal; + Printer->notify.option=option; + unistr2_to_ascii(Printer->notify.localmachine, localmachine, sizeof(Printer->notify.localmachine)-1); return NT_STATUS_NO_PROBLEMO; } @@ -1316,7 +1318,7 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_I static uint32 printserver_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info) { int snum; - int pnum=find_printer_index_by_hnd(hnd); + Printer_entry *Printer=find_printer_index_by_hnd(hnd); int n_services=lp_numservices(); int i; uint32 id; @@ -1325,7 +1327,7 @@ static uint32 printserver_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO * DEBUG(4,("printserver_notify_info\n")); - option=Printer[pnum].notify.option; + option=Printer->notify.option; id=1; info->version=2; info->data=NULL; @@ -1371,7 +1373,7 @@ static uint32 printserver_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO * static uint32 printer_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info) { int snum; - int pnum=find_printer_index_by_hnd(hnd); + Printer_entry *Printer=find_printer_index_by_hnd(hnd); int i; uint32 id; SPOOL_NOTIFY_OPTION *option; @@ -1382,7 +1384,7 @@ static uint32 printer_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info DEBUG(4,("printer_notify_info\n")); - option=Printer[pnum].notify.option; + option=Printer->notify.option; id=1; info->version=2; info->data=NULL; @@ -1435,14 +1437,12 @@ static uint32 printer_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info uint32 _spoolss_rfnpcnex( const POLICY_HND *handle, uint32 change, SPOOL_NOTIFY_OPTION *option, SPOOL_NOTIFY_INFO *info) { - int pnum=find_printer_index_by_hnd(handle); + Printer_entry *Printer=find_printer_index_by_hnd(handle); - if (pnum == -1 || !OPEN_HANDLE(pnum)) - { + if (!OPEN_HANDLE(Printer)) return NT_STATUS_INVALID_HANDLE; - } - DEBUG(4,("Printer %x of type %x\n",pnum, Printer[pnum].printer_type)); + DEBUG(4,("Printer type %x\n",Printer->printer_type)); /* jfm: the change value isn't used right now. * we will honour it when @@ -1461,7 +1461,7 @@ uint32 _spoolss_rfnpcnex( const POLICY_HND *handle, uint32 change, safe_free(option); - switch (Printer[pnum].printer_type) { + switch (Printer->printer_type) { case PRINTER_HANDLE_IS_PRINTSERVER: return printserver_notify_info(handle, info); break; @@ -2403,15 +2403,15 @@ uint32 _spoolss_getprinterdriver2(const POLICY_HND *handle, const UNISTR2 *uni_a ****************************************************************************/ uint32 _spoolss_startpageprinter(const POLICY_HND *handle) { - int pnum = find_printer_index_by_hnd(handle); + Printer_entry *Printer = find_printer_index_by_hnd(handle); - if (OPEN_HANDLE(pnum)) + if (OPEN_HANDLE(Printer)) { - Printer[pnum].page_started=True; + Printer->page_started=True; return 0x0; } - DEBUG(3,("Error in startpageprinter printer handle (pnum=%x)\n",pnum)); + DEBUG(3,("Error in startpageprinter printer handle\n")); return NT_STATUS_INVALID_HANDLE; } @@ -2419,16 +2419,17 @@ uint32 _spoolss_startpageprinter(const POLICY_HND *handle) ****************************************************************************/ uint32 _spoolss_endpageprinter(const POLICY_HND *handle) { - int pnum = find_printer_index_by_hnd(handle); + Printer_entry *Printer = find_printer_index_by_hnd(handle); - if (OPEN_HANDLE(pnum)) + if (!OPEN_HANDLE(Printer)) { - Printer[pnum].page_started=False; - return 0x0; + DEBUG(3,("Error in endpageprinter printer handle\n")); + return NT_STATUS_INVALID_HANDLE; } + + Printer->page_started=False; - DEBUG(3,("Error in endpageprinter printer handle (pnum=%x)\n",pnum)); - return NT_STATUS_INVALID_HANDLE; + return NT_STATUS_NO_PROBLEMO; } @@ -2447,11 +2448,9 @@ uint32 _spoolss_startdocprinter( const POLICY_HND *handle, uint32 level, pstring datatype; int fd = -1; int snum; - int pnum; - - pnum = find_printer_index_by_hnd(handle); + Printer_entry *Printer = find_printer_index_by_hnd(handle); - if (!VALID_HANDLE(pnum)) + if (!OPEN_HANDLE(Printer)) { return NT_STATUS_INVALID_HANDLE; } @@ -2494,16 +2493,14 @@ uint32 _spoolss_startdocprinter( const POLICY_HND *handle, uint32 level, fd=open(fname, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR ); DEBUG(4,("Temp spool file created: [%s]\n", fname)); - Printer[pnum].current_jobid=fd; - pstrcpy(Printer[pnum].document_name,fname); + Printer->current_jobid=fd; + pstrcpy(Printer->document_name, fname); - unistr2_to_ascii(Printer[pnum].job_name, - &info_1->docname, - sizeof(Printer[pnum].job_name)); + unistr2_to_ascii(Printer->job_name, &info_1->docname, sizeof(Printer->job_name)); - Printer[pnum].document_fd=fd; - Printer[pnum].document_started=True; - (*jobid) = Printer[pnum].current_jobid; + Printer->document_fd=fd; + Printer->document_started=True; + (*jobid) = Printer->current_jobid; return 0x0; } @@ -2515,29 +2512,28 @@ uint32 _spoolss_startdocprinter( const POLICY_HND *handle, uint32 level, ********************************************************************/ uint32 _spoolss_enddocprinter(const POLICY_HND *handle) { - int pnum; int snum; pstring filename; pstring filename1; pstring job_name; pstring syscmd; char *tstr; + Printer_entry *Printer=find_printer_index_by_hnd(handle); *syscmd=0; - pnum = find_printer_index_by_hnd(handle); - - if (!OPEN_HANDLE(pnum)) + if (!OPEN_HANDLE(Printer)) { - DEBUG(3,("Error in enddocprinter handle (pnum=%x)\n",pnum)); + DEBUG(3,("Error in enddocprinter handle\n")); return NT_STATUS_INVALID_HANDLE; } - Printer[pnum].document_started=False; - close(Printer[pnum].document_fd); + + Printer->document_started=False; + close(Printer->document_fd); DEBUG(4,("Temp spool file closed, printing now ...\n")); - pstrcpy(filename1, Printer[pnum].document_name); - pstrcpy(job_name, Printer[pnum].job_name); + pstrcpy(filename1, Printer->document_name); + pstrcpy(job_name, Printer->job_name); if (!get_printer_snum(handle,&snum)) { @@ -2607,20 +2603,18 @@ uint32 _spoolss_writeprinter( const POLICY_HND *handle, const uint8 *buffer, uint32 *buffer_written) { - int pnum; int fd; + Printer_entry *Printer = find_printer_index_by_hnd(handle); - pnum = find_printer_index_by_hnd(handle); - - if (!OPEN_HANDLE(pnum)) + if (!OPEN_HANDLE(Printer)) { - DEBUG(3,("Error in writeprinter handle (pnum=%x)\n",pnum)); + DEBUG(3,("Error in writeprinter handle\n")); return NT_STATUS_INVALID_HANDLE; } - fd = Printer[pnum].document_fd; + fd = Printer->document_fd; (*buffer_written) = write(fd, buffer, buffer_size); - Printer[pnum].document_lastwritten = (*buffer_written); + Printer->document_lastwritten = (*buffer_written); return 0x0; } @@ -2632,11 +2626,13 @@ uint32 _spoolss_writeprinter( const POLICY_HND *handle, ********************************************************************/ static uint32 control_printer(const POLICY_HND *handle, uint32 command) { - int pnum; int snum; - pnum = find_printer_index_by_hnd(handle); + Printer_entry *Printer = find_printer_index_by_hnd(handle); + + if (!OPEN_HANDLE(Printer)) + return NT_STATUS_INVALID_HANDLE; - if ( pnum == -1 || !get_printer_snum(handle, &snum) ) + if (!get_printer_snum(handle, &snum) ) { return NT_STATUS_INVALID_HANDLE; } @@ -2669,11 +2665,11 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, const SPOOL_PRINTER_INFO_LEVEL *info, const DEVICEMODE *devmode) { - int pnum; int snum; NT_PRINTER_INFO_LEVEL printer; NT_DEVICEMODE *nt_devmode; uint32 status = 0x0; + Printer_entry *Printer = find_printer_index_by_hnd(handle); nt_devmode=NULL; @@ -2686,11 +2682,12 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, return NT_STATUS_INVALID_INFO_CLASS; } - pnum = find_printer_index_by_hnd(handle); - if ( pnum == -1 || !get_printer_snum(handle, &snum) ) - { + if (!OPEN_HANDLE(Printer)) return NT_STATUS_INVALID_HANDLE; - } + + if (!get_printer_snum(handle, &snum) ) + return NT_STATUS_INVALID_HANDLE; + get_a_printer(&printer, level, lp_servicename(snum)); DEBUGADD(8,("Converting info_2 struct\n")); @@ -2744,17 +2741,20 @@ uint32 _spoolss_setprinter( const POLICY_HND *handle, const char *sec_buf, uint32 command) { - int pnum = find_printer_index_by_hnd(handle); + Printer_entry *Printer = find_printer_index_by_hnd(handle); - if (!OPEN_HANDLE(pnum)) - { + if (!OPEN_HANDLE(Printer)) return NT_STATUS_INVALID_HANDLE; - } + /* check the level */ switch (level) { - case 0: return control_printer(handle, command); - case 2: return update_printer(handle, level, info, devmode); + case 0: + return control_printer(handle, command); + break; + case 2: + return update_printer(handle, level, info, devmode); + break; } return NT_STATUS_INVALID_INFO_CLASS; @@ -2764,19 +2764,17 @@ uint32 _spoolss_setprinter( const POLICY_HND *handle, ****************************************************************************/ uint32 _spoolss_fcpn(const POLICY_HND *handle) { - int pnum = find_printer_index_by_hnd(handle); + Printer_entry *Printer= find_printer_index_by_hnd(handle); - if (!OPEN_HANDLE(pnum)) - { + if (!OPEN_HANDLE(Printer)) return NT_STATUS_INVALID_HANDLE; - } - Printer[pnum].notify.flags=0; - Printer[pnum].notify.options=0; - Printer[pnum].notify.localmachine[0]='\0'; - Printer[pnum].notify.printerlocal=0; - safe_free(Printer[pnum].notify.option); - Printer[pnum].notify.option=NULL; + Printer->notify.flags=0; + Printer->notify.options=0; + Printer->notify.localmachine[0]='\0'; + Printer->notify.printerlocal=0; + safe_free(Printer->notify.option); + Printer->notify.option=NULL; return NT_STATUS_NO_PROBLEMO; } @@ -3608,9 +3606,8 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 biggest_valuesize; uint32 biggest_datasize; uint32 data_len; - uint32 status = 0x0; - - int pnum = find_printer_index_by_hnd(handle); + uint32 status = 0x0; + Printer_entry *Printer = find_printer_index_by_hnd(handle); int snum; ZERO_STRUCT(printer); @@ -3618,20 +3615,16 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, DEBUG(5,("spoolss_enumprinterdata\n")); - if (!OPEN_HANDLE(pnum)) - { + if (!OPEN_HANDLE(Printer)) return NT_STATUS_INVALID_HANDLE; - } + if (!get_printer_snum(handle, &snum)) - { return NT_STATUS_INVALID_HANDLE; - } + status = get_a_printer(&printer, 2, lp_servicename(snum)); if (status != 0x0) - { return status; - } /* The NT machine wants to know the biggest size of value and data */ if ( ((*valuesize)==0) && ((*datasize)==0) ) @@ -3711,28 +3704,22 @@ uint32 _spoolss_setprinterdata( const POLICY_HND *handle, NT_PRINTER_INFO_LEVEL printer; NT_PRINTER_PARAM *param = NULL; - int pnum=0; int snum=0; uint32 status = 0x0; + Printer_entry *Printer=find_printer_index_by_hnd(handle); DEBUG(5,("spoolss_setprinterdata\n")); - pnum = find_printer_index_by_hnd(handle); - if (!OPEN_HANDLE(pnum)) - { + if (!OPEN_HANDLE(Printer)) return NT_STATUS_INVALID_HANDLE; - } + if (!get_printer_snum(handle, &snum)) - { return NT_STATUS_INVALID_HANDLE; - } status = get_a_printer(&printer, 2, lp_servicename(snum)); if (status != 0x0) - { return status; - } convert_specific_param(¶m, value , type, data, real_len); unlink_specific_param_if_exist(printer.info_2, param); @@ -3756,18 +3743,14 @@ uint32 _spoolss_addform( const POLICY_HND *handle, uint32 level, const FORM *form) { - int pnum=0; int count=0; nt_forms_struct *list=NULL; + Printer_entry *Printer = find_printer_index_by_hnd(handle); DEBUG(5,("spoolss_addform\n")); - pnum = find_printer_index_by_hnd(handle); - - if (!OPEN_HANDLE(pnum)) - { + if (!OPEN_HANDLE(Printer)) return NT_STATUS_INVALID_HANDLE; - } count=get_ntforms(&list); add_a_form(&list, form, &count); @@ -3785,14 +3768,13 @@ uint32 _spoolss_setform( const POLICY_HND *handle, uint32 level, const FORM *form) { - int pnum=0; int count=0; nt_forms_struct *list=NULL; + Printer_entry *Printer = find_printer_index_by_hnd(handle); DEBUG(5,("spoolss_setform\n")); - pnum = find_printer_index_by_hnd(handle); - if (!OPEN_HANDLE(pnum)) + if (!OPEN_HANDLE(Printer)) { return NT_STATUS_INVALID_HANDLE; } -- cgit From badee62bca8b81db7ede74ac8ea7710b14a07b4c Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Sat, 26 Feb 2000 22:22:24 +0000 Subject: rewrote enumprinterdata. still a bug in it but reproducing it hard and borring. I need a client test program urgently!!! rewrote setprinter, doesn't coredump anymore, and no memleak. J.F. (This used to be commit b76ae1f92f4f12b38c4245456cdd2db970724077) --- source3/rpc_server/srv_spoolss_nt.c | 213 +++++++++++++++++++----------------- 1 file changed, 110 insertions(+), 103 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index da7eda5795..3ab426e9c2 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -66,6 +66,10 @@ typedef struct _Printer{ uint32 printerlocal; SPOOL_NOTIFY_OPTION *option; } notify; + struct { + fstring machine; + fstring user; + } client; } Printer_entry; static ubi_dlList Printer_list; @@ -160,8 +164,6 @@ static BOOL close_printer_handle(POLICY_HND *hnd) safe_free(Printer); - DEBUG(0,("[%d] entrys still in list\n", ubi_dlCount(&Printer_list))); - return True; } @@ -2632,25 +2634,30 @@ static uint32 control_printer(const POLICY_HND *handle, uint32 command) if (!OPEN_HANDLE(Printer)) return NT_STATUS_INVALID_HANDLE; - if (!get_printer_snum(handle, &snum) ) - { + if (!get_printer_snum(handle, &snum) ) return NT_STATUS_INVALID_HANDLE; - } - switch (command) - { + switch (command) { case PRINTER_CONTROL_PAUSE: /* pause the printer here */ status_printqueue(NULL, snum, LPSTAT_STOPPED); return 0x0; - + break; case PRINTER_CONTROL_RESUME: case PRINTER_CONTROL_UNPAUSE: /* UN-pause the printer here */ status_printqueue(NULL, snum, LPSTAT_OK); return 0x0; + break; case PRINTER_CONTROL_PURGE: - /* Envoi des dragées FUCA dans l'imprimante */ + /* + * It's not handled by samba + * we need a smb.conf param to do + * lprm -P%p - on BSD + * lprm -P%p all on LPRNG + * I don't know on SysV + * we could do it by looping in the job's list... + */ break; } @@ -2675,9 +2682,8 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, DEBUG(8,("update_printer\n")); - if (level!=2) - { - DEBUG(0,("Send a mail to samba-bugs@samba.org\n")); + if (level!=2) { + DEBUG(0,("Send a mail to jfm@samba.org\n")); DEBUGADD(0,("with the following message: update_printer: level!=2\n")); return NT_STATUS_INVALID_INFO_CLASS; } @@ -2688,13 +2694,12 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, if (!get_printer_snum(handle, &snum) ) return NT_STATUS_INVALID_HANDLE; - get_a_printer(&printer, level, lp_servicename(snum)); + get_a_printer(&printer, 2, lp_servicename(snum)); DEBUGADD(8,("Converting info_2 struct\n")); convert_printer_info(info, &printer, level); - if ((info->info_2)->devmode_ptr != 0) - { + if ((info->info_2)->devmode_ptr != 0) { /* we have a valid devmode convert it and link it*/ @@ -2710,36 +2715,30 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, convert_devicemode(*devmode, nt_devmode); } - else - { + else { if (printer.info_2->devmode != NULL) - { free(printer.info_2->devmode); - } printer.info_2->devmode=NULL; } - if (status == 0x0) - { - status = add_a_printer(printer, level); - } - if (status == 0x0) - { - status = free_a_printer(printer, level); + if (add_a_printer(printer, 2)!=0) { + free_a_printer(printer, 2); + + /* I don't really know what to return here !!! */ + return NT_STATUS_INVALID_INFO_CLASS; } - return status; + free_a_printer(printer, 2); + + return NT_STATUS_NO_PROBLEMO; } /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_setprinter( const POLICY_HND *handle, - uint32 level, - const SPOOL_PRINTER_INFO_LEVEL *info, - const DEVICEMODE *devmode, - uint32 sec_buf_size, - const char *sec_buf, - uint32 command) +uint32 _spoolss_setprinter(const POLICY_HND *handle, uint32 level, + const SPOOL_PRINTER_INFO_LEVEL *info, + const DEVMODE_CTR devmode_ctr, + uint32 command) { Printer_entry *Printer = find_printer_index_by_hnd(handle); @@ -2747,13 +2746,12 @@ uint32 _spoolss_setprinter( const POLICY_HND *handle, return NT_STATUS_INVALID_HANDLE; /* check the level */ - switch (level) - { + switch (level) { case 0: return control_printer(handle, command); break; case 2: - return update_printer(handle, level, info, devmode); + return update_printer(handle, level, info, devmode_ctr.devmode); break; } @@ -3094,7 +3092,7 @@ static uint32 enumprinterdrivers_level1(fstring *list, fstring servername, fstri /* fill the buffer with the form structures */ for (i=0; i<*returned; i++) { - DEBUGADD(6,("adding form [%d] to buffer\n",i)); + DEBUGADD(6,("adding driver [%d] to buffer\n",i)); new_smb_io_printer_driver_info_1("", buffer, &(driver_info_1[i]), 0); } @@ -3135,7 +3133,7 @@ static uint32 enumprinterdrivers_level2(fstring *list, fstring servername, fstri /* fill the buffer with the form structures */ for (i=0; i<*returned; i++) { - DEBUGADD(6,("adding form [%d] to buffer\n",i)); + DEBUGADD(6,("adding driver [%d] to buffer\n",i)); new_smb_io_printer_driver_info_2("", buffer, &(driver_info_2[i]), 0); } @@ -3588,15 +3586,11 @@ uint32 _spoolss_getprinterdriverdirectory(UNISTR2 *name, UNISTR2 *uni_environmen /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, - uint32 idx, - uint32 *valuesize, - UNISTR *uni_value, - uint32 *realvaluesize, - uint32 *type, - uint32 *datasize, - uint8 **data, - uint32 *realdatasize) +uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 index, + uint32 in_value_len, uint32 in_data_len, + uint32 *out_max_value_len, uint16 **out_value, uint32 *out_value_len, + uint32 *out_type, + uint32 *out_max_data_len, uint8 **out_data, uint32 *out_data_len) { NT_PRINTER_INFO_LEVEL printer; @@ -3606,12 +3600,22 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 biggest_valuesize; uint32 biggest_datasize; uint32 data_len; - uint32 status = 0x0; Printer_entry *Printer = find_printer_index_by_hnd(handle); int snum; + uint8 *data=NULL; + uint32 type; ZERO_STRUCT(printer); - (*data)=NULL; + + *out_max_value_len=0; + *out_value=NULL; + *out_value_len=0; + + *out_type=0; + + *out_max_data_len=0; + *out_data=NULL; + *out_data_len=0; DEBUG(5,("spoolss_enumprinterdata\n")); @@ -3621,74 +3625,77 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, if (!get_printer_snum(handle, &snum)) return NT_STATUS_INVALID_HANDLE; - status = get_a_printer(&printer, 2, lp_servicename(snum)); - - if (status != 0x0) - return status; + if (get_a_printer(&printer, 2, lp_servicename(snum)) != 0x0) + return NT_STATUS_INVALID_HANDLE; - /* The NT machine wants to know the biggest size of value and data */ - if ( ((*valuesize)==0) && ((*datasize)==0) ) - { + /* + * The NT machine wants to know the biggest size of value and data + * + * cf: MSDN EnumPrinterData remark section + */ + if ( (in_value_len==0) && (in_data_len==0) ) { DEBUGADD(6,("Activating NT mega-hack to find sizes\n")); - (*valuesize)=0; - (*realvaluesize)=0; - (*type)=0; - (*datasize)=0; - (*realdatasize)=0; - status=0; - param_index=0; biggest_valuesize=0; biggest_datasize=0; - while (get_specific_param_by_index(printer, 2, param_index, value, data, type, &data_len)) - { + while (get_specific_param_by_index(printer, 2, param_index, value, &data, &type, &data_len)) { if (strlen(value) > biggest_valuesize) biggest_valuesize=strlen(value); - if (data_len > biggest_datasize) biggest_datasize=data_len; + if (data_len > biggest_datasize) biggest_datasize=data_len; + DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize, biggest_datasize)); + + safe_free(data); param_index++; } - - /* I wrote it, I didn't designed the protocol */ - if (biggest_valuesize!=0) - { - SIVAL(&(value),0, 2*(biggest_valuesize+1) ); - } - (*data)=(uint8 *)malloc(4*sizeof(uint8)); - SIVAL((*data), 0, biggest_datasize ); + + /* the value is an UNICODE string but realvaluesize is the length in bytes including the leading 0 */ + *out_value_len=2*(1+biggest_valuesize); + *out_data_len=biggest_datasize; + + DEBUG(6,("final values: [%d], [%d]\n", *out_value_len, *out_data_len)); + + free_a_printer(printer, 2); + return NT_STATUS_NO_PROBLEMO; } - else - { - /* - * the value len is wrong in NT sp3 - * that's the number of bytes not the number of unicode chars - */ - - if (get_specific_param_by_index(printer, 2, idx, value, data, type, &data_len)) - { - init_unistr(uni_value, value); - - /* the length are in bytes including leading NULL */ - (*realvaluesize)=2*(strlen(value)+1); - (*realdatasize)=data_len; - - status=0; - } - else - { - (*valuesize)=0; - (*realvaluesize)=0; - (*datasize)=0; - (*realdatasize)=0; - (*type)=0; - status=0x0103; /* ERROR_NO_MORE_ITEMS */ - } + + /* + * the value len is wrong in NT sp3 + * that's the number of bytes not the number of unicode chars + */ + + if (!get_specific_param_by_index(printer, 2, index, value, &data, &type, &data_len)) { + free_a_printer(printer, 2); + return 0x0103; /* ERROR_NO_MORE_ITEMS */ } + + /* + * the value is: + * - counted in bytes in the request + * - counted in UNICODE chars in the max reply + * - counted in bytes in the real size + * + * take a pause *before* coding not *during* coding + */ + + *out_max_value_len=in_value_len/2; + *out_value=(uint16 *)malloc(in_value_len*sizeof(uint8)); + ascii_to_unistr(*out_value, value, *out_max_value_len); + *out_value_len=2*(1+strlen(value)); + + *out_type=type; + + /* the data is counted in bytes */ + *out_max_data_len=in_data_len; + *out_data=(uint8 *)malloc(in_data_len*sizeof(uint8)); + memcpy(*out_data, data, data_len); + *out_data_len=data_len; + + safe_free(data); free_a_printer(printer, 2); - - return status; + return NT_STATUS_NO_PROBLEMO; } /**************************************************************************** -- cgit From fd3acf437acb923757e1b59b503c864b4d1c45cc Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Sat, 26 Feb 2000 23:01:02 +0000 Subject: added enumprintprocessordatatypes now NT is happy and the "always send data in RAW mode" is checked J.F. (This used to be commit d7bcfe17cee64a513595d7c44456e93e88f2448b) --- source3/rpc_server/srv_spoolss_nt.c | 49 +++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 3ab426e9c2..90a0ef6d60 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3849,7 +3849,56 @@ uint32 _spoolss_enumprintprocessors(UNISTR2 *name, UNISTR2 *environment, uint32 return NT_STATUS_INVALID_INFO_CLASS; break; } +} + +/**************************************************************************** + enumprintprocdatatypes level 1. +****************************************************************************/ +static uint32 enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +{ + PRINTPROCDATATYPE_1 *info_1=NULL; + + info_1 = (PRINTPROCDATATYPE_1 *)malloc(sizeof(PRINTPROCDATATYPE_1)); + (*returned) = 0x1; + + init_unistr(&(info_1->name), "RAW"); + + *needed += spoolss_size_printprocdatatype_info_1(info_1); + + if (!alloc_buffer_size(buffer, *needed)) + return ERROR_INSUFFICIENT_BUFFER; + + smb_io_printprocdatatype_info_1("", buffer, info_1, 0); + + safe_free(info_1); + + if (*needed > offered) { + *returned=0; + return ERROR_INSUFFICIENT_BUFFER; + } + else + return NT_STATUS_NO_PROBLEMO; +} +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_enumprintprocdatatypes(UNISTR2 *name, UNISTR2 *processor, uint32 level, + NEW_BUFFER *buffer, uint32 offered, + uint32 *needed, uint32 *returned) +{ + DEBUG(5,("_spoolss_enumprintprocdatatypes\n")); + + *returned=0; + *needed=0; + + switch (level) { + case 1: + return enumprintprocdatatypes_level_1(buffer, offered, needed, returned); + break; + default: + return NT_STATUS_INVALID_INFO_CLASS; + break; + } } /**************************************************************************** -- cgit From 78d7ba5ca021518ec5c088eb492b36710e556c31 Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Mon, 6 Mar 2000 11:13:40 +0000 Subject: changed prs_unistr to parse empty and non-empty strings the same way. fixed typo in SPOOLSS_SYNT some cleanup of unused functions wrote make_spoolss_enumprinter and make_spoolss_openprinterex for rpcclient as I'm trying to keep in sync the parsing code between HEAD and TNG. Will commit changes to TNG after lunch. J.F. (This used to be commit 025cdb345f6de287a41d4449b2662dbc5e762bf2) --- source3/rpc_server/srv_spoolss_nt.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 90a0ef6d60..9d465ca145 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -384,6 +384,7 @@ static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size) { prs_struct *ps; uint32 extra_space; + uint32 old_offset; ps=&(buffer->prs); @@ -392,10 +393,19 @@ static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size) extra_space=0; else extra_space = buffer_size - prs_data_size(ps); + + /* + * save the offset and move to the end of the buffer + * prs_grow() checks the extra_space against the offset + */ + old_offset=prs_offset(ps); + prs_set_offset(ps, prs_data_size(ps)); if (!prs_grow(ps, extra_space)) return False; + prs_set_offset(ps, old_offset); + buffer->string_at_end=prs_data_size(ps); return True; @@ -412,7 +422,6 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, POLICY_HND *handle) { fstring name; - fstring datatype; clear_handle(handle); @@ -962,9 +971,7 @@ static void spoolss_notify_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_ print_status_struct status; memset(&status, 0, sizeof(status)); - count=get_printqueue(snum, NULL, &q, &status); - data->notify_data.value[0]=(uint32) status.status; if (q) free(q); } @@ -978,7 +985,6 @@ static void spoolss_notify_cjobs(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_q print_status_struct status; memset(&status, 0, sizeof(status)); - data->notify_data.value[0]=get_printqueue(snum, NULL, &q, &status); if (q) free(q); } @@ -1869,6 +1875,8 @@ static BOOL enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint32 for (i=0; i<*returned; i++) (*needed) += spoolss_size_printer_info_2(printers[i]); + DEBUG(4,("we need [%d] bytes\n", *needed)); + if (!alloc_buffer_size(buffer, *needed)) return ERROR_INSUFFICIENT_BUFFER; @@ -1906,7 +1914,7 @@ static uint32 enumprinters_level1( uint32 flags, fstring name, if (flags && PRINTER_ENUM_REMOTE) return enum_all_printers_info_1(buffer, offered, needed, returned); - + return NT_STATUS_INVALID_LEVEL; } /******************************************************************** @@ -2675,7 +2683,6 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, int snum; NT_PRINTER_INFO_LEVEL printer; NT_DEVICEMODE *nt_devmode; - uint32 status = 0x0; Printer_entry *Printer = find_printer_index_by_hnd(handle); nt_devmode=NULL; -- cgit From 0f987d77becebc7d528f5fda6d0e23325035131c Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Tue, 7 Mar 2000 09:06:03 +0000 Subject: fixed enumprinterdata. J.F. (This used to be commit 2b4f09e7bbcbf1bf835f299e9f6bf89b32a7f03f) --- source3/rpc_server/srv_spoolss_nt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 9d465ca145..f15fc75181 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2483,7 +2483,7 @@ uint32 _spoolss_startdocprinter( const POLICY_HND *handle, uint32 level, if (strcmp(datatype, "RAW") != 0) { (*jobid)=0; - return STATUS_1804; + return ERROR_INVALID_DATATYPE; } } @@ -3674,7 +3674,7 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 index, if (!get_specific_param_by_index(printer, 2, index, value, &data, &type, &data_len)) { free_a_printer(printer, 2); - return 0x0103; /* ERROR_NO_MORE_ITEMS */ + return ERROR_NO_MORE_ITEMS; } /* -- cgit From fd69e4a13a8bbaf838b33ab7a3f3f00ed558b163 Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Tue, 7 Mar 2000 18:10:20 +0000 Subject: Enumprinters level 1: reply *exactly* like an NT server BTW, found a little memleak in it. J.F. (This used to be commit 9c37b5df2de9bf8fa6f5536fd75f9c8faf338a52) --- source3/rpc_server/srv_spoolss_nt.c | 228 ++++++++++++++++++++---------------- 1 file changed, 126 insertions(+), 102 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index f15fc75181..41f37c3f74 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1551,35 +1551,29 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer,int snum, pstring s * construct_printer_info_1 * fill a printer_info_1 struct ********************************************************************/ -static BOOL construct_printer_info_1(PRINTER_INFO_1 *printer, int snum, pstring servername) +static BOOL construct_printer_info_1(fstring server, uint32 flags, PRINTER_INFO_1 *printer, int snum) { pstring chaine; pstring chaine2; NT_PRINTER_INFO_LEVEL ntprinter; - + if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) != 0) - { - return (False); - } - - printer->flags=PRINTER_ENUM_ICON8; + return False; - /* the description and the name are of the form \\server\share */ + printer->flags=flags; - snprintf(chaine,sizeof(chaine)-1,"\\\\%s\\%s,%s,%s",servername, - ntprinter.info_2->printername, - ntprinter.info_2->drivername, - lp_comment(snum)); - init_unistr(&(printer->description), chaine); - - snprintf(chaine2,sizeof(chaine)-1,"\\\\%s\\%s", servername, ntprinter.info_2->printername); - init_unistr(&(printer->name), chaine2); - - init_unistr(&(printer->comment), lp_comment(snum)); + snprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",server, ntprinter.info_2->printername, + ntprinter.info_2->drivername, lp_comment(snum)); + + snprintf(chaine2,sizeof(chaine)-1,"%s%s", server, ntprinter.info_2->printername); + + init_unistr(&printer->description, chaine); + init_unistr(&printer->name, chaine2); + init_unistr(&printer->comment, lp_comment(snum)); free_a_printer(ntprinter, 2); - return (True); + return True; } /**************************************************************************** @@ -1703,25 +1697,6 @@ static BOOL construct_printer_info_2(PRINTER_INFO_2 *printer, int snum, pstring return (True); } -/******************************************************************** - * enum_printer_info_1 - * glue between spoolss_enumprinters and construct_printer_info_1 - ********************************************************************/ -static BOOL get_printer_info_1(PRINTER_INFO_1 **printer, int snum, int number) -{ - pstring servername; - - *printer=(PRINTER_INFO_1 *)malloc(sizeof(PRINTER_INFO_1)); - DEBUG(4,("Allocated memory for ONE PRINTER_INFO_1 at [%p]\n", *printer)); - pstrcpy(servername, global_myname); - if (!construct_printer_info_1(*printer, snum, servername)) { - free(*printer); - return False; - } - else - return True; -} - /******************************************************************** * enum_printer_info_2 * glue between spoolss_enumprinters and construct_printer_info_2 @@ -1745,44 +1720,45 @@ static BOOL get_printer_info_2(PRINTER_INFO_2 **printer, int snum, int number) } /******************************************************************** - * spoolss_enumprinters - * - * called from api_spoolss_enumprinters (see this to understand) - ********************************************************************/ -static BOOL enum_printer_info_1(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) + Spoolss_enumprinters. +********************************************************************/ +static BOOL enum_all_printers_info_1(fstring server, uint32 flags, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int snum; int i; int n_services=lp_numservices(); - PRINTER_INFO_1 *printer=NULL; -DEBUG(1,("enum_printer_info_1\n")); + PRINTER_INFO_1 *printers=NULL; + PRINTER_INFO_1 current_prt; + + DEBUG(4,("enum_all_printers_info_1\n")); + for (snum=0; snum offered) { *returned=0; @@ -1793,49 +1769,85 @@ DEBUG(1,("enum_printer_info_1\n")); } /******************************************************************** - Spoolss_enumprinters. -********************************************************************/ -static BOOL enum_all_printers_info_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) + enum_all_printers_info_1_local. +*********************************************************************/ +static BOOL enum_all_printers_info_1_local(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { - int snum; - int i; - int n_services=lp_numservices(); - PRINTER_INFO_1 *printers=NULL; - PRINTER_INFO_1 current_prt; - pstring servername; + fstring temp; + DEBUG(4,("enum_all_printers_info_1_local\n")); - DEBUG(4,("enum_all_printers_info_1\n")); + fstrcpy(temp, "\\\\"); + fstrcat(temp, global_myname); + + if (!strcmp(name, temp)) { + fstrcat(temp, "\\"); + enum_all_printers_info_1(temp, PRINTER_ENUM_ICON8, buffer, offered, needed, returned); + } + else + enum_all_printers_info_1("", PRINTER_ENUM_ICON8, buffer, offered, needed, returned); +} + +/******************************************************************** + enum_all_printers_info_1_name. +*********************************************************************/ +static BOOL enum_all_printers_info_1_name(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +{ + fstring temp; + DEBUG(4,("enum_all_printers_info_1_name\n")); - pstrcpy(servername, global_myname); + fstrcpy(temp, "\\\\"); + fstrcat(temp, global_myname); - for (snum=0; snumdescription, desc); + init_unistr(&printer->name, printername); + init_unistr(&printer->comment, comment); + printer->flags=PRINTER_ENUM_ICON3|PRINTER_ENUM_CONTAINER; /* check the required size. */ - for (i=0; i<*returned; i++) - (*needed) += spoolss_size_printer_info_1(&(printers[i])); + *needed += spoolss_size_printer_info_1(printer); if (!alloc_buffer_size(buffer, *needed)) return ERROR_INSUFFICIENT_BUFFER; - /* fill the buffer with the structures */ - - for (i=0; i<*returned; i++) - new_smb_io_printer_info_1("", buffer, &(printers[i]), 0); + new_smb_io_printer_info_1("", buffer, printer, 0); /* clear memory */ + safe_free(printer); if (*needed > offered) { *returned=0; @@ -1845,6 +1857,20 @@ static BOOL enum_all_printers_info_1(NEW_BUFFER *buffer, uint32 offered, uint32 return NT_STATUS_NO_PROBLEMO; } +/******************************************************************** + enum_all_printers_info_1_network. +*********************************************************************/ +static BOOL enum_all_printers_info_1_network(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +{ + fstring temp; + DEBUG(4,("enum_all_printers_info_1_network\n")); + + fstrcpy(temp, "\\\\"); + fstrcat(temp, global_myname); + fstrcat(temp, "\\"); + enum_all_printers_info_1(temp, PRINTER_ENUM_UNKNOWN_8, buffer, offered, needed, returned); +} + /******************************************************************** * api_spoolss_enumprinters * @@ -1861,11 +1887,8 @@ static BOOL enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint32 if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) { DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum)); - printers=Realloc(printers, ((*returned)+1)*sizeof(PRINTER_INFO_2 *)); - DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_2 pointers\n", (*returned)+1)); - if (get_printer_info_2( &(printers[*returned]), snum, *returned) ) (*returned)++; } @@ -1901,20 +1924,21 @@ static uint32 enumprinters_level1( uint32 flags, fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { - if (flags && PRINTER_ENUM_NETWORK) - return enum_all_printers_info_1(buffer, offered, needed, returned); - - if (flags && PRINTER_ENUM_NAME) { - if (*name=='\0') - return enum_all_printers_info_1(buffer, offered, needed, returned); - else - return enum_printer_info_1(name, buffer, offered, needed, returned); - } - - if (flags && PRINTER_ENUM_REMOTE) - return enum_all_printers_info_1(buffer, offered, needed, returned); + /* Not all the flags are equals */ + + if (flags & PRINTER_ENUM_LOCAL) + return enum_all_printers_info_1_local(name, buffer, offered, needed, returned); + + if (flags & PRINTER_ENUM_NAME) + return enum_all_printers_info_1_name(name, buffer, offered, needed, returned); + + if (flags & PRINTER_ENUM_REMOTE) + return enum_all_printers_info_1_remote(name, buffer, offered, needed, returned); + + if (flags & PRINTER_ENUM_NETWORK) + return enum_all_printers_info_1_network(name, buffer, offered, needed, returned); - return NT_STATUS_INVALID_LEVEL; + return NT_STATUS_NO_PROBLEMO; /* NT4sp5 does that */ } /******************************************************************** @@ -2022,7 +2046,7 @@ static uint32 getprinter_level_1(pstring servername, int snum, NEW_BUFFER *buffe PRINTER_INFO_1 *printer=NULL; printer=(PRINTER_INFO_1*)malloc(sizeof(PRINTER_INFO_1)); - construct_printer_info_1(printer, snum, servername); + construct_printer_info_1(servername, PRINTER_ENUM_ICON8, printer, snum); /* check the required size. */ *needed += spoolss_size_printer_info_1(printer); -- cgit From e0ebb76a7453c07c16e8f736233226a774ab58e8 Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Fri, 10 Mar 2000 17:12:24 +0000 Subject: getprinter level 0: was to short, found most of the fields, undocumented, undecoded, nothing in MSDN, but now it works :-) cleanup of error codes. fixed some dfs declarations function. J.F. (This used to be commit 87da4404aba29a2ebd999886e4c06958c96d3e05) --- source3/rpc_server/srv_spoolss_nt.c | 314 ++++++++++++++++++++++-------------- 1 file changed, 193 insertions(+), 121 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 41f37c3f74..9170b8afdd 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -72,7 +72,17 @@ typedef struct _Printer{ } client; } Printer_entry; +typedef struct _counter_printer_0 { + ubi_dlNode Next; + ubi_dlNode Prev; + + int snum; + uint32 counter; +} counter_printer_0; + static ubi_dlList Printer_list; +static ubi_dlList counter_list; + #define OPEN_HANDLE(pnum) ((pnum!=NULL) && (pnum->open!=False)) @@ -82,6 +92,7 @@ static ubi_dlList Printer_list; void init_printer_hnd(void) { ubi_dlInitList(&Printer_list); + ubi_dlInitList(&counter_list); } /**************************************************************************** @@ -1485,22 +1496,50 @@ uint32 _spoolss_rfnpcnex( const POLICY_HND *handle, uint32 change, * construct_printer_info_0 * fill a printer_info_1 struct ********************************************************************/ -static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer,int snum, pstring servername) +static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, pstring servername) { pstring chaine; int count; NT_PRINTER_INFO_LEVEL ntprinter; - + counter_printer_0 *session_counter; + uint32 global_counter; + struct tm *t; + print_queue_struct *queue=NULL; print_status_struct status; + memset(&status, 0, sizeof(status)); if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) != 0) - { - return (False); - } + return False; count=get_printqueue(snum, NULL, &queue, &status); + + /* check if we already have a counter for this printer */ + session_counter = (counter_printer_0 *)ubi_dlFirst(&counter_list); + + for(; session_counter; session_counter = (counter_printer_0 *)ubi_dlNext(session_counter)) { + if (session_counter->snum == snum) + break; + } + + /* it's the first time, add it to the list */ + if (session_counter==NULL) { + session_counter=(counter_printer_0 *)malloc(sizeof(counter_printer_0)); + ZERO_STRUCTP(session_counter); + session_counter->snum=snum; + session_counter->counter=0; + ubi_dlAddHead( &counter_list, (ubi_dlNode *)session_counter); + } + + /* increment it */ + session_counter->counter++; + + /* JFM: + * the global_counter should be stored in a TDB as it's common to all the clients + * and should be zeroed on samba startup + */ + global_counter=session_counter->counter; /* the description and the name are of the form \\server\share */ slprintf(chaine,sizeof(chaine)-1,"\\\\%s\\%s",servername, ntprinter.info_2->printername); @@ -1511,36 +1550,48 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer,int snum, pstring s init_unistr(&(printer->servername), chaine); printer->cjobs = count; - printer->attributes = PRINTER_ATTRIBUTE_SHARED \ - | PRINTER_ATTRIBUTE_NETWORK \ - | PRINTER_ATTRIBUTE_RAW_ONLY ; - printer->unknown0 = 0x1; /* pointer */ - printer->unknown1 = 0x000A07CE; /* don't known */ - printer->unknown2 = 0x00020005; - printer->unknown3 = 0x0006000D; - printer->unknown4 = 0x02180026; - printer->unknown5 = 0x09; - printer->unknown6 = 0x36; - printer->majorversion = 0x0004; /* NT 4 */ - printer->buildversion = 0x0565; /* build 1381 */ - printer->unknown7 = 0x1; - printer->unknown8 = 0x0; - printer->unknown9 = 0x2; - printer->unknown10 = 0x3; - printer->unknown11 = 0x0; - printer->unknown12 = 0x0; - printer->unknown13 = 0x0; - printer->unknown14 = 0x1; - printer->unknown15 = 0x024a; /*586 Pentium ? */ - printer->unknown16 = 0x0; - printer->unknown17 = 0x423ed444; /* CacheChangeID */ - printer->unknown18 = 0x0; - printer->status = status.status; - printer->unknown20 = 0x0; - printer->unknown21 = 0x0648; - printer->unknown22 = 0x0; - printer->unknown23 = 0x5; - + printer->total_jobs = 0; + printer->total_bytes = 0; + + t=gmtime(&ntprinter.info_2->setuptime); + + printer->year = t->tm_year+1900; + printer->month = t->tm_mon+1; + printer->dayofweek = t->tm_wday; + printer->day = t->tm_mday; + printer->hour = t->tm_hour; + printer->minute = t->tm_min; + printer->second = t->tm_sec; + printer->milliseconds = 0; + + printer->global_counter = global_counter; + printer->total_pages = 0; + printer->major_version = 0x0004; /* NT 4 */ + printer->build_version = 0x0565; /* build 1381 */ + printer->unknown7 = 0x1; + printer->unknown8 = 0x0; + printer->unknown9 = 0x2; + printer->session_counter = session_counter->counter; + printer->unknown11 = 0x0; + printer->printer_errors = 0x0; /* number of print failure */ + printer->unknown13 = 0x0; + printer->unknown14 = 0x1; + printer->unknown15 = 0x024a; /* 586 Pentium ? */ + printer->unknown16 = 0x0; + printer->change_id = ntprinter.info_2->changeid; /* ChangeID in milliseconds*/ + printer->unknown18 = 0x0; + printer->status = status.status; + printer->unknown20 = 0x0; + printer->c_setprinter = ntprinter.info_2->c_setprinter; /* how many times setprinter has been called */ + printer->unknown22 = 0x0; + printer->unknown23 = 0x6; /* 6 ???*/ + printer->unknown24 = 0; /* unknown 24 to 26 are always 0 */ + printer->unknown25 = 0; + printer->unknown26 = 0; + printer->unknown27 = 0; + printer->unknown28 = 0; + printer->unknown29 = 0; + safe_free(queue); free_a_printer(ntprinter, 2); @@ -1640,52 +1691,57 @@ static void construct_dev_mode(DEVICEMODE *devmode, int snum, char *servername) * construct_printer_info_2 * fill a printer_info_2 struct ********************************************************************/ -static BOOL construct_printer_info_2(PRINTER_INFO_2 *printer, int snum, pstring servername) +static BOOL construct_printer_info_2(pstring servername, PRINTER_INFO_2 *printer, int snum) { pstring chaine; + pstring chaine2; + pstring sl; int count; DEVICEMODE *devmode; NT_PRINTER_INFO_LEVEL ntprinter; - + print_queue_struct *queue=NULL; print_status_struct status; memset(&status, 0, sizeof(status)); - count=get_printqueue(snum, NULL, &queue, &status); if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0 ) - { - return (False); - } - - snprintf(chaine, sizeof(chaine)-1, "\\\\%s", servername); - init_unistr(&(printer->servername), chaine); /* servername*/ - - snprintf(chaine, sizeof(chaine)-1, "\\\\%s\\%s", servername, ntprinter.info_2->printername); - init_unistr(&(printer->printername), chaine); /* printername*/ + return False; + + memset(&status, 0, sizeof(status)); + count=get_printqueue(snum, NULL, &queue, &status); - init_unistr(&(printer->sharename), lp_servicename(snum)); /* sharename */ + snprintf(chaine, sizeof(chaine)-1, "%s", servername); - init_unistr(&(printer->portname), lp_servicename(snum)); /* port */ - init_unistr(&(printer->drivername), ntprinter.info_2->drivername); /* drivername */ - - init_unistr(&(printer->comment), ntprinter.info_2->comment); /* comment */ - init_unistr(&(printer->location), ntprinter.info_2->location); /* location */ - init_unistr(&(printer->sepfile), ntprinter.info_2->sepfile); /* separator file */ - init_unistr(&(printer->printprocessor), ntprinter.info_2->printprocessor);/* print processor */ - init_unistr(&(printer->datatype), ntprinter.info_2->datatype); /* datatype */ - init_unistr(&(printer->parameters), ntprinter.info_2->parameters); /* parameters (of print processor) */ + if (strlen(servername)!=0) + fstrcpy(sl, "\\"); + else + fstrcpy(sl, '\0'); + + snprintf(chaine2, sizeof(chaine)-1, "%s%s%s", servername, sl, ntprinter.info_2->printername); + + init_unistr(&printer->servername, chaine); /* servername*/ + init_unistr(&printer->printername, chaine2); /* printername*/ + init_unistr(&printer->sharename, lp_servicename(snum)); /* sharename */ + init_unistr(&printer->portname, lp_servicename(snum)); /* port */ + init_unistr(&printer->drivername, ntprinter.info_2->drivername); /* drivername */ + init_unistr(&printer->comment, lp_comment(snum)); /* comment */ + init_unistr(&printer->location, ntprinter.info_2->location); /* location */ + init_unistr(&printer->sepfile, ntprinter.info_2->sepfile); /* separator file */ + init_unistr(&printer->printprocessor, ntprinter.info_2->printprocessor);/* print processor */ + init_unistr(&printer->datatype, ntprinter.info_2->datatype); /* datatype */ + init_unistr(&printer->parameters, ntprinter.info_2->parameters); /* parameters (of print processor) */ printer->attributes = PRINTER_ATTRIBUTE_SHARED \ - | PRINTER_ATTRIBUTE_NETWORK \ - | PRINTER_ATTRIBUTE_RAW_ONLY ; /* attributes */ - - printer->priority = ntprinter.info_2->priority; /* priority */ - printer->defaultpriority = ntprinter.info_2->default_priority; /* default priority */ - printer->starttime = ntprinter.info_2->starttime; /* starttime */ - printer->untiltime = ntprinter.info_2->untiltime; /* untiltime */ - printer->status = status.status; /* status */ - printer->cjobs = count; /* jobs */ - printer->averageppm = ntprinter.info_2->averageppm; /* average pages per minute */ + | PRINTER_ATTRIBUTE_LOCAL \ + | PRINTER_ATTRIBUTE_RAW_ONLY ; /* attributes */ + + printer->priority = ntprinter.info_2->priority; /* priority */ + printer->defaultpriority = ntprinter.info_2->default_priority; /* default priority */ + printer->starttime = ntprinter.info_2->starttime; /* starttime */ + printer->untiltime = ntprinter.info_2->untiltime; /* untiltime */ + printer->status = status.status; /* status */ + printer->cjobs = count; /* jobs */ + printer->averageppm = ntprinter.info_2->averageppm; /* average pages per minute */ devmode=(DEVICEMODE *)malloc(sizeof(DEVICEMODE)); ZERO_STRUCTP(devmode); @@ -1694,29 +1750,7 @@ static BOOL construct_printer_info_2(PRINTER_INFO_2 *printer, int snum, pstring safe_free(queue); free_a_printer(ntprinter, 2); - return (True); -} - -/******************************************************************** - * enum_printer_info_2 - * glue between spoolss_enumprinters and construct_printer_info_2 - ********************************************************************/ -static BOOL get_printer_info_2(PRINTER_INFO_2 **printer, int snum, int number) -{ - pstring servername; - - *printer=(PRINTER_INFO_2 *)malloc(sizeof(PRINTER_INFO_2)); - DEBUG(4,("Allocated memory for ONE PRINTER_INFO_2 at [%p]\n", *printer)); - pstrcpy(servername, global_myname); - if (!construct_printer_info_2(*printer, snum, servername)) - { - free(*printer); - return (False); - } - else - { - return (True); - } + return True; } /******************************************************************** @@ -1736,8 +1770,7 @@ static BOOL enum_all_printers_info_1(fstring server, uint32 flags, NEW_BUFFER *b if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) { DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum)); - if (construct_printer_info_1(server, flags, ¤t_prt, snum)) - { + if (construct_printer_info_1(server, flags, ¤t_prt, snum)) { printers=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_1)); DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_1\n", *returned)); memcpy(&(printers[*returned]), ¤t_prt, sizeof(PRINTER_INFO_1)); @@ -1781,10 +1814,10 @@ static BOOL enum_all_printers_info_1_local(fstring name, NEW_BUFFER *buffer, uin if (!strcmp(name, temp)) { fstrcat(temp, "\\"); - enum_all_printers_info_1(temp, PRINTER_ENUM_ICON8, buffer, offered, needed, returned); + return enum_all_printers_info_1(temp, PRINTER_ENUM_ICON8, buffer, offered, needed, returned); } else - enum_all_printers_info_1("", PRINTER_ENUM_ICON8, buffer, offered, needed, returned); + return enum_all_printers_info_1("", PRINTER_ENUM_ICON8, buffer, offered, needed, returned); } /******************************************************************** @@ -1800,7 +1833,7 @@ static BOOL enum_all_printers_info_1_name(fstring name, NEW_BUFFER *buffer, uint if (!strcmp(name, temp)) { fstrcat(temp, "\\"); - enum_all_printers_info_1(temp, PRINTER_ENUM_ICON8, buffer, offered, needed, returned); + return enum_all_printers_info_1(temp, PRINTER_ENUM_ICON8, buffer, offered, needed, returned); } else return ERROR_INVALID_NAME; @@ -1840,8 +1873,10 @@ static BOOL enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, ui /* check the required size. */ *needed += spoolss_size_printer_info_1(printer); - if (!alloc_buffer_size(buffer, *needed)) + if (!alloc_buffer_size(buffer, *needed)) { + safe_free(printer); return ERROR_INSUFFICIENT_BUFFER; + } /* fill the buffer with the structures */ new_smb_io_printer_info_1("", buffer, printer, 0); @@ -1868,7 +1903,7 @@ static BOOL enum_all_printers_info_1_network(fstring name, NEW_BUFFER *buffer, u fstrcpy(temp, "\\\\"); fstrcat(temp, global_myname); fstrcat(temp, "\\"); - enum_all_printers_info_1(temp, PRINTER_ENUM_UNKNOWN_8, buffer, offered, needed, returned); + return enum_all_printers_info_1(temp, PRINTER_ENUM_UNKNOWN_8, buffer, offered, needed, returned); } /******************************************************************** @@ -1876,38 +1911,40 @@ static BOOL enum_all_printers_info_1_network(fstring name, NEW_BUFFER *buffer, u * * called from api_spoolss_enumprinters (see this to understand) ********************************************************************/ -static BOOL enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static BOOL enum_all_printers_info_2(fstring servername, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int snum; int i; int n_services=lp_numservices(); - PRINTER_INFO_2 **printers=NULL; + PRINTER_INFO_2 *printers=NULL; + PRINTER_INFO_2 current_prt; for (snum=0; snum offered) { *returned=0; @@ -1948,7 +1985,33 @@ static uint32 enumprinters_level2( uint32 flags, fstring servername, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { - return enum_all_printers_info_2(buffer, offered, needed, returned); + fstring temp; + + fstrcpy(temp, "\\\\"); + fstrcat(temp, global_myname); + + if (flags & PRINTER_ENUM_LOCAL) { + if (!strcmp(servername, temp)) { + fstrcat(temp, "\\"); + return enum_all_printers_info_2(temp, buffer, offered, needed, returned); + } + else + return enum_all_printers_info_2("", buffer, offered, needed, returned); + } + + if (flags & PRINTER_ENUM_NAME) { + if (!strcmp(servername, temp)) { + fstrcat(temp, "\\"); + return enum_all_printers_info_2(temp, buffer, offered, needed, returned); + } + else + return ERROR_INVALID_NAME; + } + + if (flags & PRINTER_ENUM_REMOTE) + return ERROR_INVALID_LEVEL; + + return NT_STATUS_NO_PROBLEMO; } /******************************************************************** @@ -2018,13 +2081,16 @@ static uint32 getprinter_level_0(pstring servername, int snum, NEW_BUFFER *buffe PRINTER_INFO_0 *printer=NULL; printer=(PRINTER_INFO_0*)malloc(sizeof(PRINTER_INFO_0)); + construct_printer_info_0(printer, snum, servername); /* check the required size. */ *needed += spoolss_size_printer_info_0(printer); - if (!alloc_buffer_size(buffer, *needed)) + if (!alloc_buffer_size(buffer, *needed)) { + safe_free(printer); return ERROR_INSUFFICIENT_BUFFER; + } /* fill the buffer with the structures */ new_smb_io_printer_info_0("", buffer, printer, 0); @@ -2051,8 +2117,10 @@ static uint32 getprinter_level_1(pstring servername, int snum, NEW_BUFFER *buffe /* check the required size. */ *needed += spoolss_size_printer_info_1(printer); - if (!alloc_buffer_size(buffer, *needed)) + if (!alloc_buffer_size(buffer, *needed)) { + safe_free(printer); return ERROR_INSUFFICIENT_BUFFER; + } /* fill the buffer with the structures */ new_smb_io_printer_info_1("", buffer, printer, 0); @@ -2072,15 +2140,21 @@ static uint32 getprinter_level_1(pstring servername, int snum, NEW_BUFFER *buffe static uint32 getprinter_level_2(pstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_2 *printer=NULL; + fstring temp; - printer=(PRINTER_INFO_2*)malloc(sizeof(PRINTER_INFO_2)); - construct_printer_info_2(printer, snum, servername); + printer=(PRINTER_INFO_2*)malloc(sizeof(PRINTER_INFO_2)); + + fstrcpy(temp, "\\\\"); + fstrcat(temp, servername); + construct_printer_info_2(temp, printer, snum); /* check the required size. */ *needed += spoolss_size_printer_info_2(printer); - if (!alloc_buffer_size(buffer, *needed)) + if (!alloc_buffer_size(buffer, *needed)) { + safe_free(printer); return ERROR_INSUFFICIENT_BUFFER; + } /* fill the buffer with the structures */ new_smb_io_printer_info_2("", buffer, printer, 0); @@ -2108,9 +2182,7 @@ uint32 _spoolss_getprinter(POLICY_HND *handle, uint32 level, pstrcpy(servername, global_myname); if (!get_printer_snum(handle, &snum)) - { return NT_STATUS_INVALID_HANDLE; - } switch (level) { case 0: @@ -2123,7 +2195,7 @@ uint32 _spoolss_getprinter(POLICY_HND *handle, uint32 level, return getprinter_level_2(servername,snum, buffer, offered, needed); break; default: - return NT_STATUS_INVALID_LEVEL; + return ERROR_INVALID_LEVEL; break; } } @@ -3617,11 +3689,11 @@ uint32 _spoolss_getprinterdriverdirectory(UNISTR2 *name, UNISTR2 *uni_environmen /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 index, +uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx, uint32 in_value_len, uint32 in_data_len, uint32 *out_max_value_len, uint16 **out_value, uint32 *out_value_len, uint32 *out_type, - uint32 *out_max_data_len, uint8 **out_data, uint32 *out_data_len) + uint32 *out_max_data_len, uint8 **data_out, uint32 *out_data_len) { NT_PRINTER_INFO_LEVEL printer; @@ -3645,7 +3717,7 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 index, *out_type=0; *out_max_data_len=0; - *out_data=NULL; + *data_out=NULL; *out_data_len=0; DEBUG(5,("spoolss_enumprinterdata\n")); @@ -3696,7 +3768,7 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 index, * that's the number of bytes not the number of unicode chars */ - if (!get_specific_param_by_index(printer, 2, index, value, &data, &type, &data_len)) { + if (!get_specific_param_by_index(printer, 2, idx, value, &data, &type, &data_len)) { free_a_printer(printer, 2); return ERROR_NO_MORE_ITEMS; } @@ -3719,7 +3791,7 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 index, /* the data is counted in bytes */ *out_max_data_len=in_data_len; - *out_data=(uint8 *)malloc(in_data_len*sizeof(uint8)); + *data_out=(uint8 *)malloc(in_data_len*sizeof(uint8)); memcpy(*out_data, data, data_len); *out_data_len=data_len; -- cgit From 5e22394654eba2ed5d01e81b165a044a59dd65ab Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 10 Mar 2000 19:50:03 +0000 Subject: Fixups for compiles with gcc flags -Wall -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual Partially implemented rpc daemon redirect (needs more work). Jeremy. (This used to be commit a462191698fa589ceac4afd14c652adf699eccad) --- source3/rpc_server/srv_spoolss_nt.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 9170b8afdd..b4aefe44c1 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4140,6 +4140,8 @@ static uint32 getjob_level_1(print_queue_struct *queue, int count, int snum, uin /**************************************************************************** ****************************************************************************/ +#if 0 +... Not yet used... static uint32 getjob_level_2(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { int i=0; @@ -4179,6 +4181,7 @@ static uint32 getjob_level_2(print_queue_struct *queue, int count, int snum, uin else return NT_STATUS_NO_PROBLEMO; } +#endif /**************************************************************************** ****************************************************************************/ -- cgit From 7b97d056a1deae9e885765153f596e8e30e334b1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 11 Mar 2000 01:02:45 +0000 Subject: You *must* use O_EXCL when using mktemp (security issue). Glad this code never shipped :-). This is not a problem in 2.0.x. Jeremy. (This used to be commit a0c302f4d03ab07d697115fa8520d0cb0b2ba616) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index b4aefe44c1..ef0b7fad9b 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2596,7 +2596,7 @@ uint32 _spoolss_startdocprinter( const POLICY_HND *handle, uint32 level, slprintf(tempname,sizeof(tempname)-1, "%s/smb_print.XXXXXX",lp_pathname(snum)); pstrcpy(fname, (char *)mktemp(tempname)); - fd=open(fname, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR ); + fd=open(fname, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, S_IRUSR|S_IWUSR ); DEBUG(4,("Temp spool file created: [%s]\n", fname)); Printer->current_jobid=fd; -- cgit From 79bfb14318423f5a26a4d0dc6fc6faa62b1401f8 Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Mon, 13 Mar 2000 11:09:20 +0000 Subject: parse correctly getprinterdriver2 found a stupid bug in enumprinters fixed some memleaks found a coredump in enumprinterdata getprinterdriverdir responds correctly now. J.F. (This used to be commit 07f2e194ba61e72320636fb7e5d0f041e255868b) --- source3/rpc_server/srv_spoolss_nt.c | 85 +++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 42 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index ef0b7fad9b..d0fc839154 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1991,19 +1991,15 @@ static uint32 enumprinters_level2( uint32 flags, fstring servername, fstrcat(temp, global_myname); if (flags & PRINTER_ENUM_LOCAL) { - if (!strcmp(servername, temp)) { - fstrcat(temp, "\\"); + if (!strcmp(servername, temp)) return enum_all_printers_info_2(temp, buffer, offered, needed, returned); - } else return enum_all_printers_info_2("", buffer, offered, needed, returned); } if (flags & PRINTER_ENUM_NAME) { - if (!strcmp(servername, temp)) { - fstrcat(temp, "\\"); + if (!strcmp(servername, temp)) return enum_all_printers_info_2(temp, buffer, offered, needed, returned); - } else return ERROR_INVALID_NAME; } @@ -2055,6 +2051,7 @@ uint32 _spoolss_enumprinters( uint32 flags, const UNISTR2 *servername, uint32 le */ unistr2_to_ascii(name, servername, sizeof(name)-1); + strupper(name); switch (level) { case 1: @@ -2391,8 +2388,10 @@ static uint32 getprinterdriver2_level1(pstring servername, pstring architecture, /* check the required size. */ *needed += spoolss_size_printer_driver_info_1(info); - if (!alloc_buffer_size(buffer, *needed)) + if (!alloc_buffer_size(buffer, *needed)) { + safe_free(info); return ERROR_INSUFFICIENT_BUFFER; + } /* fill the buffer with the structures */ new_smb_io_printer_driver_info_1("", buffer, info, 0); @@ -2400,9 +2399,8 @@ static uint32 getprinterdriver2_level1(pstring servername, pstring architecture, /* clear memory */ safe_free(info); - if (*needed > offered) { + if (*needed > offered) return ERROR_INSUFFICIENT_BUFFER; - } else return NT_STATUS_NO_PROBLEMO; } @@ -2420,8 +2418,10 @@ static uint32 getprinterdriver2_level2(pstring servername, pstring architecture, /* check the required size. */ *needed += spoolss_size_printer_driver_info_2(info); - if (!alloc_buffer_size(buffer, *needed)) + if (!alloc_buffer_size(buffer, *needed)) { + safe_free(info); return ERROR_INSUFFICIENT_BUFFER; + } /* fill the buffer with the structures */ new_smb_io_printer_driver_info_2("", buffer, info, 0); @@ -2429,9 +2429,8 @@ static uint32 getprinterdriver2_level2(pstring servername, pstring architecture, /* clear memory */ safe_free(info); - if (*needed > offered) { + if (*needed > offered) return ERROR_INSUFFICIENT_BUFFER; - } else return NT_STATUS_NO_PROBLEMO; } @@ -2449,8 +2448,10 @@ static uint32 getprinterdriver2_level3(pstring servername, pstring architecture, /* check the required size. */ *needed += spoolss_size_printer_driver_info_3(info); - if (!alloc_buffer_size(buffer, *needed)) + if (!alloc_buffer_size(buffer, *needed)) { + safe_free(info); return ERROR_INSUFFICIENT_BUFFER; + } /* fill the buffer with the structures */ new_smb_io_printer_driver_info_3("", buffer, info, 0); @@ -2458,18 +2459,18 @@ static uint32 getprinterdriver2_level3(pstring servername, pstring architecture, /* clear memory */ safe_free(info); - if (*needed > offered) { + if (*needed > offered) return ERROR_INSUFFICIENT_BUFFER; - } else return NT_STATUS_NO_PROBLEMO; } /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_getprinterdriver2(const POLICY_HND *handle, const UNISTR2 *uni_arch, uint32 level, uint32 unknown, +uint32 _spoolss_getprinterdriver2(const POLICY_HND *handle, const UNISTR2 *uni_arch, uint32 level, + uint32 clientmajorversion, uint32 clientminorversion, NEW_BUFFER *buffer, uint32 offered, - uint32 *needed, uint32 *unknown0, uint32 *unknown1) + uint32 *needed, uint32 *servermajorversion, uint32 *serverminorversion) { pstring servername; fstring architecture; @@ -2478,16 +2479,14 @@ uint32 _spoolss_getprinterdriver2(const POLICY_HND *handle, const UNISTR2 *uni_a DEBUG(4,("_spoolss_getprinterdriver2\n")); *needed=0; - *unknown0=0; - *unknown1=0; + *servermajorversion=0; + *serverminorversion=0; pstrcpy(servername, global_myname); unistr2_to_ascii(architecture, uni_arch, sizeof(architecture)-1); if (!get_printer_snum(handle, &snum)) - { return NT_STATUS_INVALID_HANDLE; - } switch (level) { case 1: @@ -3381,8 +3380,10 @@ uint32 _new_spoolss_enumforms( const POLICY_HND *handle, uint32 level, *needed=buffer_size; - if (!alloc_buffer_size(buffer, buffer_size)) + if (!alloc_buffer_size(buffer, buffer_size)){ + safe_free(list); return ERROR_INSUFFICIENT_BUFFER; + } /* fill the buffer with the form structures */ for (i=0; i<*numofforms; i++) @@ -3400,7 +3401,7 @@ uint32 _new_spoolss_enumforms( const POLICY_HND *handle, uint32 level, default: safe_free(list); - return NT_STATUS_INVALID_INFO_CLASS; + return ERROR_INVALID_LEVEL; } } @@ -3441,8 +3442,7 @@ static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need ports=(PORT_INFO_1 *)malloc( (*returned+1) * sizeof(PORT_INFO_1) ); - for (snum=0; snum Date: Mon, 13 Mar 2000 15:53:02 +0000 Subject: small fix for addprinterex at level 2 I have some network dumps at level 1, but quoting MSDN: "Level [in] Specifies the version of the structure to which pPrinter points. This value must be 2." I like NT so much :-) J.F. (This used to be commit fbf40c6a9140a27e773d59eaf056c9e25659d9b8) --- source3/rpc_server/srv_spoolss_nt.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index d0fc839154..340d776493 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3581,30 +3581,28 @@ uint32 _spoolss_addprinterex( const UNISTR2 *uni_srv_name, uint32 level, /* convert from UNICODE to ASCII */ convert_printer_info(info, &printer, level); - unistr2_to_ascii(share_name, &((info->info_2)->portname), sizeof(share_name)-1); + unistr2_to_ascii(share_name, &((info->info_2)->printername), sizeof(share_name)-1); slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname, share_name); + /* write the ASCII on disk */ + if (add_a_printer(printer, level) != 0x0) + return ERROR_ACCESS_DENIED; + create_printer_hnd(handle); open_printer_hnd(handle); if (!set_printer_hnd_printertype(handle, name)) { close_printer_handle(handle); - return NT_STATUS_ACCESS_DENIED; + return ERROR_ACCESS_DENIED; } - + if (!set_printer_hnd_printername(handle, name)) { close_printer_handle(handle); - return NT_STATUS_ACCESS_DENIED; + return ERROR_ACCESS_DENIED; } - /* write the ASCII on disk */ - if (add_a_printer(printer, level) != 0x0) { - close_printer_handle(handle); - return NT_STATUS_ACCESS_DENIED; - } - return NT_STATUS_NO_PROBLEMO; } -- cgit From c5fbb293a8fe2cc2251ffa0d46c79a2d247f7d9a Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Mon, 13 Mar 2000 19:34:04 +0000 Subject: oops ! forgot smb.h in last commit added info level 1 parsing code for addprinter(ex) J.F. (This used to be commit 4847f7b17b2d23e4efd4e7cae6bfcfc2319b9409) --- source3/rpc_server/srv_spoolss_nt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 340d776493..de994a1b5d 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2855,9 +2855,10 @@ uint32 _spoolss_setprinter(const POLICY_HND *handle, uint32 level, case 2: return update_printer(handle, level, info, devmode_ctr.devmode); break; + default: + return ERROR_INVALID_LEVEL; + break; } - - return NT_STATUS_INVALID_INFO_CLASS; } /**************************************************************************** -- cgit From 4d439771302ec46225f31e8fa26f62ec30df6d1d Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Thu, 16 Mar 2000 16:23:38 +0000 Subject: fix a bug in enumprinterdrivers J.F. (This used to be commit a8d04c26da601cb97e66c27c7ad21dd672fcec2d) --- source3/rpc_server/srv_spoolss_nt.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index de994a1b5d..8f1bcef9f3 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3189,8 +3189,10 @@ static uint32 enumprinterdrivers_level1(fstring *list, fstring servername, fstri *needed += spoolss_size_printer_driver_info_1(&(driver_info_1[i])); } - if (!alloc_buffer_size(buffer, *needed)) + if (!alloc_buffer_size(buffer, *needed)) { + safe_free(driver_info_1); return ERROR_INSUFFICIENT_BUFFER; + } /* fill the buffer with the form structures */ for (i=0; i<*returned; i++) @@ -3199,10 +3201,12 @@ static uint32 enumprinterdrivers_level1(fstring *list, fstring servername, fstri new_smb_io_printer_driver_info_1("", buffer, &(driver_info_1[i]), 0); } - safe_free(list); + safe_free(driver_info_1); - if (*needed > offered) + if (*needed > offered) { + *returned=0; return ERROR_INSUFFICIENT_BUFFER; + } else return NT_STATUS_NO_PROBLEMO; } @@ -3230,8 +3234,10 @@ static uint32 enumprinterdrivers_level2(fstring *list, fstring servername, fstri *needed += spoolss_size_printer_driver_info_2(&(driver_info_2[i])); } - if (!alloc_buffer_size(buffer, *needed)) + if (!alloc_buffer_size(buffer, *needed)) { + safe_free(driver_info_2); return ERROR_INSUFFICIENT_BUFFER; + } /* fill the buffer with the form structures */ for (i=0; i<*returned; i++) @@ -3240,10 +3246,12 @@ static uint32 enumprinterdrivers_level2(fstring *list, fstring servername, fstri new_smb_io_printer_driver_info_2("", buffer, &(driver_info_2[i]), 0); } - safe_free(list); + safe_free(driver_info_2); - if (*needed > offered) + if (*needed > offered) { + *returned=0; return ERROR_INSUFFICIENT_BUFFER; + } else return NT_STATUS_NO_PROBLEMO; } -- cgit From 6ca0ed9baa7d2a4b4d46ca730d4984f80965d849 Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Wed, 29 Mar 2000 12:36:44 +0000 Subject: rewrote getprinterdriver level 3, now correctly handle the dependent files. A number of memleak fixed some error return values fixed. J.F. (This used to be commit c212fbe009fe556d5329b5d7106159cf21402d82) --- source3/rpc_server/srv_spoolss_nt.c | 169 ++++++++++++++++++++---------------- 1 file changed, 95 insertions(+), 74 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 8f1bcef9f3..d08571b80b 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -305,8 +305,7 @@ static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) char *aprinter; BOOL found=False; - if (!OPEN_HANDLE(Printer)) - { + if (!OPEN_HANDLE(Printer)) { DEBUG(0,("Error setting printer name=%s\n", printername)); return False; } @@ -437,7 +436,7 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, clear_handle(handle); if (printername == NULL) - return NT_STATUS_ACCESS_DENIED; + return ERROR_INVALID_PRINTER_NAME; /* some sanity check because you can open a printer or a print server */ /* aka: \\server\printer or \\server */ @@ -451,12 +450,12 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, if (!set_printer_hnd_printertype(handle, name)) { close_printer_handle(handle); - return NT_STATUS_ACCESS_DENIED; + return ERROR_INVALID_PRINTER_NAME; } if (!set_printer_hnd_printername(handle, name)) { close_printer_handle(handle); - return NT_STATUS_ACCESS_DENIED; + return ERROR_INVALID_PRINTER_NAME; } /* @@ -471,7 +470,7 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, if (!set_printer_hnd_accesstype(handle, printer_default->access_required)) { close_printer_handle(handle); - return NT_STATUS_ACCESS_DENIED; + return ERROR_ACCESS_DENIED; } return NT_STATUS_NO_PROBLEMO; @@ -665,25 +664,32 @@ static BOOL getprinterdata_printer(const POLICY_HND *handle, DEBUG(5,("getprinterdata_printer\n")); - if (OPEN_HANDLE(Printer)) - { - get_printer_snum(handle, &snum); - get_a_printer(&printer, 2, lp_servicename(snum)); - - if (get_specific_param(printer, 2, value, &idata, type, &len)) - { - *data = (uint8 *)malloc( (len>in_size)?len:in_size *sizeof(uint8) ); - memset(*data, 0, sizeof(uint8)*len); - memcpy(*data, idata, (len>in_size)?len:in_size); - *needed = len; - - if (idata) free(idata); - return (True); - } + if (!OPEN_HANDLE(Printer)) + return False; + + get_printer_snum(handle, &snum); + get_a_printer(&printer, 2, lp_servicename(snum)); + + if (!get_specific_param(printer, 2, value, &idata, type, &len)) { free_a_printer(printer, 2); + return False; } - return (False); + DEBUG(5,("getprinterdata_printer:allocating %d\n", in_size)); + + *data = (uint8 *)malloc( in_size *sizeof(uint8) ); + memset(*data, 0, in_size *sizeof(uint8)); + /* copy the min(in_size, len) */ + memcpy(*data, idata, (len>in_size)?in_size:len *sizeof(uint8)); + + *needed = len; + + DEBUG(5,("getprinterdata_printer:copy done\n")); + + free_a_printer(printer, 2); + safe_free(idata); + + return True; } /******************************************************************** @@ -728,9 +734,10 @@ uint32 _spoolss_getprinterdata(const POLICY_HND *handle, UNISTR2 *valuename, found=getprinterdata_printer(handle, value, type, data, needed, *out_size); if (found==False) { + DEBUG(5, ("value not found, allocating %d\n", *out_size)); /* reply this param doesn't exist */ - *data=(uint8 *)malloc(4*sizeof(uint8)); - memset(*data, 0x0, 4); + *data=(uint8 *)malloc(*out_size*sizeof(uint8)); + memset(*data, 0x0, *out_size*sizeof(uint8)); return ERROR_INVALID_PARAMETER; } @@ -984,7 +991,7 @@ static void spoolss_notify_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_ memset(&status, 0, sizeof(status)); count=get_printqueue(snum, NULL, &q, &status); data->notify_data.value[0]=(uint32) status.status; - if (q) free(q); + safe_free(q); } /******************************************************************* @@ -997,7 +1004,7 @@ static void spoolss_notify_cjobs(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_q memset(&status, 0, sizeof(status)); data->notify_data.value[0]=get_printqueue(snum, NULL, &q, &status); - if (q) free(q); + safe_free(q); } /******************************************************************* @@ -1936,14 +1943,24 @@ static BOOL enum_all_printers_info_2(fstring servername, NEW_BUFFER *buffer, uin for (i=0; i<*returned; i++) (*needed) += spoolss_size_printer_info_2(&(printers[i])); - if (!alloc_buffer_size(buffer, *needed)) + if (!alloc_buffer_size(buffer, *needed)) { + for (i=0; i<*returned; i++) { + safe_free(printers[i].devmode->private); + safe_free(printers[i].devmode); + } + safe_free(printers); return ERROR_INSUFFICIENT_BUFFER; + } /* fill the buffer with the structures */ for (i=0; i<*returned; i++) new_smb_io_printer_info_2("", buffer, &(printers[i]), 0); /* clear memory */ + for (i=0; i<*returned; i++) { + safe_free(printers[i].devmode->private); + safe_free(printers[i].devmode); + } safe_free(printers); if (*needed > offered) { @@ -2157,6 +2174,8 @@ static uint32 getprinter_level_2(pstring servername, int snum, NEW_BUFFER *buffe new_smb_io_printer_info_2("", buffer, printer, 0); /* clear memory */ + safe_free(printer->devmode->private); + safe_free(printer->devmode); safe_free(printer); if (*needed > offered) { @@ -2263,8 +2282,7 @@ static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, * construct_printer_driver_info_2 * fill a printer_info_2 struct ********************************************************************/ -static void construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, - pstring servername, fstring architecture) +static void construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, pstring servername, fstring architecture) { NT_PRINTER_INFO_LEVEL printer; NT_PRINTER_DRIVER_INFO_LEVEL driver; @@ -2280,36 +2298,30 @@ static void construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, /******************************************************************** * copy a strings array and convert to UNICODE + * + * convert an array of ascii string to a UNICODE string ********************************************************************/ -static void init_unistr_array(UNISTR ***uni_array, char **char_array, char *where) +static void init_unistr_array(uint16 **uni_array, char **char_array, char *where) { int i=0; + int j=0; char *v; pstring line; DEBUG(6,("init_unistr_array\n")); + *uni_array=NULL; - for (v=char_array[i]; *v!='\0'; v=char_array[i]) - { - DEBUGADD(6,("i:%d:", i)); - DEBUGADD(6,("%s:%d:", v, strlen(v))); - - *uni_array=(UNISTR **)Realloc(*uni_array, sizeof(UNISTR *)*(i+1)); - DEBUGADD(7,("realloc:[%p],", *uni_array)); - - (*uni_array)[i]=(UNISTR *)malloc( sizeof(UNISTR) ); - DEBUGADD(7,("alloc:[%p],", (*uni_array)[i])); - + for (v=char_array[i]; *v!='\0'; v=char_array[i]) { snprintf(line, sizeof(line)-1, "%s%s", where, v); - init_unistr( (*uni_array)[i], line ); - DEBUGADD(7,("copy\n")); - + DEBUGADD(6,("%d:%s:%d\n", i, line, strlen(line))); + *uni_array=Realloc(*uni_array, (j+strlen(line)+2)*sizeof(uint16)); + ascii_to_unistr( *uni_array+j, line , strlen(line)); + j+=strlen(line)+1; i++; } - DEBUGADD(7,("last one\n")); - *uni_array=(UNISTR **)Realloc(*uni_array, sizeof(UNISTR *)*(i+1)); - (*uni_array)[i]=0x0000; + (*uni_array)[j]=0x0000; + DEBUGADD(6,("last one:done\n")); } @@ -2457,6 +2469,7 @@ static uint32 getprinterdriver2_level3(pstring servername, pstring architecture, new_smb_io_printer_driver_info_3("", buffer, info, 0); /* clear memory */ + safe_free(info->dependentfiles); safe_free(info); if (*needed > offered) @@ -3182,9 +3195,10 @@ static uint32 enumprinterdrivers_level1(fstring *list, fstring servername, fstri free_a_printer_driver(driver, 3); } + safe_free(list); + /* check the required size. */ - for (i=0; i<*returned; i++) - { + for (i=0; i<*returned; i++) { DEBUGADD(6,("adding driver [%d]'s size\n",i)); *needed += spoolss_size_printer_driver_info_1(&(driver_info_1[i])); } @@ -3195,8 +3209,7 @@ static uint32 enumprinterdrivers_level1(fstring *list, fstring servername, fstri } /* fill the buffer with the form structures */ - for (i=0; i<*returned; i++) - { + for (i=0; i<*returned; i++) { DEBUGADD(6,("adding driver [%d] to buffer\n",i)); new_smb_io_printer_driver_info_1("", buffer, &(driver_info_1[i]), 0); } @@ -3227,9 +3240,10 @@ static uint32 enumprinterdrivers_level2(fstring *list, fstring servername, fstri free_a_printer_driver(driver, 3); } + safe_free(list); + /* check the required size. */ - for (i=0; i<*returned; i++) - { + for (i=0; i<*returned; i++) { DEBUGADD(6,("adding driver [%d]'s size\n",i)); *needed += spoolss_size_printer_driver_info_2(&(driver_info_2[i])); } @@ -3240,8 +3254,7 @@ static uint32 enumprinterdrivers_level2(fstring *list, fstring servername, fstri } /* fill the buffer with the form structures */ - for (i=0; i<*returned; i++) - { + for (i=0; i<*returned; i++) { DEBUGADD(6,("adding driver [%d] to buffer\n",i)); new_smb_io_printer_driver_info_2("", buffer, &(driver_info_2[i]), 0); } @@ -3272,27 +3285,34 @@ static uint32 enumprinterdrivers_level3(fstring *list, fstring servername, fstri free_a_printer_driver(driver, 3); } + safe_free(list); + /* check the required size. */ - for (i=0; i<*returned; i++) - { + for (i=0; i<*returned; i++) { DEBUGADD(6,("adding driver [%d]'s size\n",i)); *needed += spoolss_size_printer_driver_info_3(&(driver_info_3[i])); } - if (!alloc_buffer_size(buffer, *needed)) + if (!alloc_buffer_size(buffer, *needed)) { + safe_free(driver_info_3); return ERROR_INSUFFICIENT_BUFFER; - + } + /* fill the buffer with the form structures */ - for (i=0; i<*returned; i++) - { + for (i=0; i<*returned; i++) { DEBUGADD(6,("adding form [%d] to buffer\n",i)); new_smb_io_printer_driver_info_3("", buffer, &(driver_info_3[i]), 0); } - safe_free(list); - - if (*needed > offered) + for (i=0; i<*returned; i++) + safe_free(driver_info_3[i].dependentfiles); + + safe_free(driver_info_3); + + if (*needed > offered) { + *returned=0; return ERROR_INSUFFICIENT_BUFFER; + } else return NT_STATUS_NO_PROBLEMO; } @@ -3332,7 +3352,7 @@ uint32 _spoolss_enumprinterdrivers( UNISTR2 *name, UNISTR2 *environment, uint32 return enumprinterdrivers_level3(list, servername, architecture, buffer, offered, needed, returned); break; default: - return NT_STATUS_INVALID_INFO_CLASS; + return ERROR_INVALID_LEVEL; break; } } @@ -3374,15 +3394,15 @@ uint32 _new_spoolss_enumforms( const POLICY_HND *handle, uint32 level, forms_1=(FORM_1 *)malloc(*numofforms * sizeof(FORM_1)); /* construct the list of form structures */ - for (i=0; i<*numofforms; i++) - { + for (i=0; i<*numofforms; i++) { DEBUGADD(6,("Filling form number [%d]\n",i)); fill_form_1(&(forms_1[i]), &(list[i]), i); } + + safe_free(list); /* check the required size. */ - for (i=0; i<*numofforms; i++) - { + for (i=0; i<*numofforms; i++) { DEBUGADD(6,("adding form [%d]'s size\n",i)); buffer_size += spoolss_size_form_1(&(forms_1[i])); } @@ -3390,21 +3410,22 @@ uint32 _new_spoolss_enumforms( const POLICY_HND *handle, uint32 level, *needed=buffer_size; if (!alloc_buffer_size(buffer, buffer_size)){ - safe_free(list); + safe_free(forms_1); return ERROR_INSUFFICIENT_BUFFER; } /* fill the buffer with the form structures */ - for (i=0; i<*numofforms; i++) - { + for (i=0; i<*numofforms; i++) { DEBUGADD(6,("adding form [%d] to buffer\n",i)); new_smb_io_form_1("", buffer, &(forms_1[i]), 0); } - safe_free(list); + safe_free(forms_1); - if (*needed > offered) + if (*needed > offered) { + *numofforms=0; return ERROR_INSUFFICIENT_BUFFER; + } else return NT_STATUS_NO_PROBLEMO; -- cgit From c475ab51d99ee3aa33f9d2c6eaa2811f2f8ea931 Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Wed, 29 Mar 2000 14:49:05 +0000 Subject: split addprinterex in preparation for level 1 support and to stop it coredump. J.F. (This used to be commit aea47dee7d85310f35309ecfa91d0b87e632a33f) --- source3/rpc_server/srv_spoolss_nt.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index d08571b80b..e55f1fb305 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3587,7 +3587,7 @@ uint32 _spoolss_enumports( UNISTR2 *name, uint32 level, /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_addprinterex( const UNISTR2 *uni_srv_name, uint32 level, +static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name, const SPOOL_PRINTER_INFO_LEVEL *info, uint32 unk0, uint32 unk1, uint32 unk2, uint32 unk3, uint32 user_switch, const SPOOL_USER_CTR *user, @@ -3599,24 +3599,19 @@ uint32 _spoolss_addprinterex( const UNISTR2 *uni_srv_name, uint32 level, clear_handle(handle); -/* - * FIX: JFM: we need to check the user here !!!! - * - * as the code is running as root, anybody can add printers to the server - */ /* NULLify info_2 here */ /* don't put it in convert_printer_info as it's used also with non-NULL values */ printer.info_2=NULL; /* convert from UNICODE to ASCII */ - convert_printer_info(info, &printer, level); + convert_printer_info(info, &printer, 2); unistr2_to_ascii(share_name, &((info->info_2)->printername), sizeof(share_name)-1); slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname, share_name); /* write the ASCII on disk */ - if (add_a_printer(printer, level) != 0x0) + if (add_a_printer(printer, 2) != 0x0) return ERROR_ACCESS_DENIED; create_printer_hnd(handle); @@ -3636,6 +3631,31 @@ uint32 _spoolss_addprinterex( const UNISTR2 *uni_srv_name, uint32 level, return NT_STATUS_NO_PROBLEMO; } +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_addprinterex( const UNISTR2 *uni_srv_name, uint32 level, + const SPOOL_PRINTER_INFO_LEVEL *info, + uint32 unk0, uint32 unk1, uint32 unk2, uint32 unk3, + uint32 user_switch, const SPOOL_USER_CTR *user, + POLICY_HND *handle) +{ + switch (level) { + case 1: + /* we don't handle yet */ + /* but I know what to do ... */ + break; + case 2: + return spoolss_addprinterex_level_2(uni_srv_name, info, + unk0, unk1, unk2, unk3, + user_switch, user, handle); + break; + default: + return ERROR_INVALID_LEVEL; + break; + } +} + + /**************************************************************************** ****************************************************************************/ uint32 _spoolss_addprinterdriver( const UNISTR2 *server_name, -- cgit From dc2d1544b3718dce5b3d7d91989b3cc5abfdef6b Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Wed, 5 Apr 2000 10:05:32 +0000 Subject: changed all the status code to ERROR_xxx instead of NT_STATUS_xx which are wrong in the spoolss case. fxed a bug in the job notify code (that's the polite answer), the truth is different: there is a bug in the NT spooler service, including SP6a and NT2K. changed the default lpcommand in the LPRNG case. J.F. (This used to be commit 396f73c11b29a47650b3243fef0825252a3cef9b) --- source3/rpc_server/srv_spoolss_nt.c | 162 ++++++++++++++++-------------------- 1 file changed, 74 insertions(+), 88 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index e55f1fb305..79ad5197cd 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -564,7 +564,7 @@ static BOOL convert_devicemode(DEVICEMODE devmode, NT_DEVICEMODE *nt_devmode) uint32 _spoolss_closeprinter(POLICY_HND *handle) { if (!close_printer_handle(handle)) - return NT_STATUS_INVALID_HANDLE; + return ERROR_INVALID_HANDLE; return NT_STATUS_NO_PROBLEMO; } @@ -723,7 +723,7 @@ uint32 _spoolss_getprinterdata(const POLICY_HND *handle, UNISTR2 *valuename, if (!OPEN_HANDLE(Printer)) { *data=(uint8 *)malloc(4*sizeof(uint8)); - return NT_STATUS_INVALID_HANDLE; + return ERROR_INVALID_HANDLE; } unistr2_to_ascii(value, valuename, sizeof(value)-1); @@ -767,7 +767,7 @@ uint32 _spoolss_rffpcnex(const POLICY_HND *handle, uint32 flags, uint32 options, Printer_entry *Printer=find_printer_index_by_hnd(handle); if (!OPEN_HANDLE(Printer)) - return NT_STATUS_INVALID_HANDLE; + return ERROR_INVALID_HANDLE; Printer->notify.flags=flags; Printer->notify.options=options; @@ -1411,7 +1411,7 @@ static uint32 printer_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info DEBUG(4,("printer_notify_info\n")); option=Printer->notify.option; - id=1; + id=0xffffffff; info->version=2; info->data=NULL; info->count=0; @@ -1425,15 +1425,14 @@ static uint32 printer_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info switch ( option_type->type ) { case PRINTER_NOTIFY_TYPE: if(construct_notify_printer_info(info, snum, option_type, id)) - id++; + id--; break; case JOB_NOTIFY_TYPE: memset(&status, 0, sizeof(status)); count=get_printqueue(snum, NULL, &queue, &status); for (j=0; jprinter_type)); @@ -1496,7 +1495,7 @@ uint32 _spoolss_rfnpcnex( const POLICY_HND *handle, uint32 change, break; } - return NT_STATUS_INVALID_INFO_CLASS; + return ERROR_INVALID_HANDLE; } /******************************************************************** @@ -1577,7 +1576,7 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, pstring printer->build_version = 0x0565; /* build 1381 */ printer->unknown7 = 0x1; printer->unknown8 = 0x0; - printer->unknown9 = 0x2; + printer->unknown9 = 0x0; printer->session_counter = session_counter->counter; printer->unknown11 = 0x0; printer->printer_errors = 0x0; /* number of print failure */ @@ -2083,7 +2082,7 @@ uint32 _spoolss_enumprinters( uint32 flags, const UNISTR2 *servername, uint32 le case 3: case 4: default: - return NT_STATUS_INVALID_LEVEL; + return ERROR_INVALID_LEVEL; break; } } @@ -2198,7 +2197,7 @@ uint32 _spoolss_getprinter(POLICY_HND *handle, uint32 level, pstrcpy(servername, global_myname); if (!get_printer_snum(handle, &snum)) - return NT_STATUS_INVALID_HANDLE; + return ERROR_INVALID_HANDLE; switch (level) { case 0: @@ -2361,7 +2360,7 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, snprintf(temp_helpfile, sizeof(temp_helpfile)-1, "%s%s", where, driver.info_3->helpfile); init_unistr( &(info->helpfile), temp_helpfile ); - init_unistr( &(info->monitorname), driver.info_3->monitorname ); + init_unistr( &(info->monitorname), driver.info_3->monitorname ); init_unistr( &(info->defaultdatatype), driver.info_3->defaultdatatype ); info->dependentfiles=NULL; @@ -2499,7 +2498,7 @@ uint32 _spoolss_getprinterdriver2(const POLICY_HND *handle, const UNISTR2 *uni_a unistr2_to_ascii(architecture, uni_arch, sizeof(architecture)-1); if (!get_printer_snum(handle, &snum)) - return NT_STATUS_INVALID_HANDLE; + return ERROR_INVALID_HANDLE; switch (level) { case 1: @@ -2512,7 +2511,7 @@ uint32 _spoolss_getprinterdriver2(const POLICY_HND *handle, const UNISTR2 *uni_a return getprinterdriver2_level3(servername, architecture, snum, buffer, offered, needed); break; default: - return NT_STATUS_INVALID_LEVEL; + return ERROR_INVALID_LEVEL; break; } } @@ -2530,7 +2529,7 @@ uint32 _spoolss_startpageprinter(const POLICY_HND *handle) } DEBUG(3,("Error in startpageprinter printer handle\n")); - return NT_STATUS_INVALID_HANDLE; + return ERROR_INVALID_HANDLE; } /**************************************************************************** @@ -2542,7 +2541,7 @@ uint32 _spoolss_endpageprinter(const POLICY_HND *handle) if (!OPEN_HANDLE(Printer)) { DEBUG(3,("Error in endpageprinter printer handle\n")); - return NT_STATUS_INVALID_HANDLE; + return ERROR_INVALID_HANDLE; } Printer->page_started=False; @@ -2570,7 +2569,7 @@ uint32 _spoolss_startdocprinter( const POLICY_HND *handle, uint32 level, if (!OPEN_HANDLE(Printer)) { - return NT_STATUS_INVALID_HANDLE; + return ERROR_INVALID_HANDLE; } /* @@ -2598,7 +2597,7 @@ uint32 _spoolss_startdocprinter( const POLICY_HND *handle, uint32 level, /* get the share number of the printer */ if (!get_printer_snum(handle, &snum)) { - return NT_STATUS_INVALID_HANDLE; + return ERROR_INVALID_HANDLE; } /* Create a temporary file in the printer spool directory @@ -2643,7 +2642,7 @@ uint32 _spoolss_enddocprinter(const POLICY_HND *handle) if (!OPEN_HANDLE(Printer)) { DEBUG(3,("Error in enddocprinter handle\n")); - return NT_STATUS_INVALID_HANDLE; + return ERROR_INVALID_HANDLE; } Printer->document_started=False; @@ -2655,7 +2654,7 @@ uint32 _spoolss_enddocprinter(const POLICY_HND *handle) if (!get_printer_snum(handle,&snum)) { - return NT_STATUS_INVALID_HANDLE; + return ERROR_INVALID_HANDLE; } /* copy the command into the buffer for extensive meddling. */ @@ -2681,8 +2680,7 @@ uint32 _spoolss_enddocprinter(const POLICY_HND *handle) */ tstr = lp_printername(snum); - if (tstr == NULL || tstr[0] == '\0') - { + if (tstr == NULL || tstr[0] == '\0') { DEBUG(3,( "No printer name - using %s.\n", SERVICE(snum))); tstr = SERVICE(snum); } @@ -2692,22 +2690,19 @@ uint32 _spoolss_enddocprinter(const POLICY_HND *handle) /* If the lpr command support the 'Job' option replace here */ pstring_sub(syscmd, "%j", job_name); - if ( *syscmd != '\0') - { - int ret = smbrun(syscmd, NULL, False); - DEBUG(3,("Running the command `%s' gave %d\n", syscmd, ret)); - if (ret < 0) - { + if ( *syscmd != '\0') { + int ret = smbrun(syscmd, NULL, False); + DEBUG(3,("Running the command `%s' gave %d\n", syscmd, ret)); + if (ret < 0) { lpq_reset(snum); - return NT_STATUS_ACCESS_DENIED; + return ERROR_ACCESS_DENIED; } } - else - { - DEBUG(0,("Null print command?\n")); - lpq_reset(snum); - return NT_STATUS_ACCESS_DENIED; - } + else { + DEBUG(0,("Null print command?\n")); + lpq_reset(snum); + return ERROR_ACCESS_DENIED; + } lpq_reset(snum); @@ -2727,7 +2722,7 @@ uint32 _spoolss_writeprinter( const POLICY_HND *handle, if (!OPEN_HANDLE(Printer)) { DEBUG(3,("Error in writeprinter handle\n")); - return NT_STATUS_INVALID_HANDLE; + return ERROR_INVALID_HANDLE; } fd = Printer->document_fd; @@ -2748,10 +2743,10 @@ static uint32 control_printer(const POLICY_HND *handle, uint32 command) Printer_entry *Printer = find_printer_index_by_hnd(handle); if (!OPEN_HANDLE(Printer)) - return NT_STATUS_INVALID_HANDLE; + return ERROR_INVALID_HANDLE; if (!get_printer_snum(handle, &snum) ) - return NT_STATUS_INVALID_HANDLE; + return ERROR_INVALID_HANDLE; switch (command) { case PRINTER_CONTROL_PAUSE: @@ -2777,7 +2772,7 @@ static uint32 control_printer(const POLICY_HND *handle, uint32 command) break; } - return NT_STATUS_INVALID_INFO_CLASS; + return ERROR_INVALID_FUNCTION; } /******************************************************************** @@ -2800,14 +2795,14 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, if (level!=2) { DEBUG(0,("Send a mail to jfm@samba.org\n")); DEBUGADD(0,("with the following message: update_printer: level!=2\n")); - return NT_STATUS_INVALID_INFO_CLASS; + return ERROR_INVALID_LEVEL; } if (!OPEN_HANDLE(Printer)) - return NT_STATUS_INVALID_HANDLE; + return ERROR_INVALID_HANDLE; if (!get_printer_snum(handle, &snum) ) - return NT_STATUS_INVALID_HANDLE; + return ERROR_INVALID_HANDLE; get_a_printer(&printer, 2, lp_servicename(snum)); @@ -2840,7 +2835,7 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, free_a_printer(printer, 2); /* I don't really know what to return here !!! */ - return NT_STATUS_INVALID_INFO_CLASS; + return ERROR_ACCESS_DENIED; } free_a_printer(printer, 2); @@ -2858,7 +2853,7 @@ uint32 _spoolss_setprinter(const POLICY_HND *handle, uint32 level, Printer_entry *Printer = find_printer_index_by_hnd(handle); if (!OPEN_HANDLE(Printer)) - return NT_STATUS_INVALID_HANDLE; + return ERROR_INVALID_HANDLE; /* check the level */ switch (level) { @@ -2881,7 +2876,7 @@ uint32 _spoolss_fcpn(const POLICY_HND *handle) Printer_entry *Printer= find_printer_index_by_hnd(handle); if (!OPEN_HANDLE(Printer)) - return NT_STATUS_INVALID_HANDLE; + return ERROR_INVALID_HANDLE; Printer->notify.flags=0; Printer->notify.options=0; @@ -3087,7 +3082,7 @@ uint32 _spoolss_enumjobs( POLICY_HND *handle, uint32 firstjob, uint32 numofjobs, if (!get_printer_snum(handle, &snum)) { - return NT_STATUS_INVALID_HANDLE; + return ERROR_INVALID_HANDLE; } *returned = get_printqueue(snum, NULL, &queue, &prt_status); @@ -3101,7 +3096,7 @@ uint32 _spoolss_enumjobs( POLICY_HND *handle, uint32 firstjob, uint32 numofjobs, return enumjobs_level2(queue, snum, buffer, offered, needed, returned); break; default: - return NT_STATUS_INVALID_LEVEL; + return ERROR_INVALID_LEVEL; break; } } @@ -3133,26 +3128,21 @@ uint32 _spoolss_setjob( const POLICY_HND *handle, memset(&prt_status, 0, sizeof(prt_status)); - if (!get_printer_snum(handle, &snum)) - { - return NT_STATUS_INVALID_HANDLE; + if (!get_printer_snum(handle, &snum)) { + return ERROR_INVALID_HANDLE; } count=get_printqueue(snum, NULL, &queue, &prt_status); - while ( (i Date: Thu, 6 Apr 2000 16:23:04 +0000 Subject: filled the architecture table (useless for the moment). fixed GetJob. J.F. (This used to be commit 3fea49e1d896987c54187cb326607284810fcb0d) --- source3/rpc_server/srv_spoolss_nt.c | 55 +++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 18 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 79ad5197cd..b7533c7873 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2939,9 +2939,7 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, time_t unixdate = time(NULL); if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0 ) - { - return (False); - } + return False; t=gmtime(&unixdate); snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname); @@ -2993,25 +2991,31 @@ static uint32 enumjobs_level1(print_queue_struct *queue, int snum, int i; info=(JOB_INFO_1 *)malloc(*returned*sizeof(JOB_INFO_1)); + if (info==NULL) { + safe_free(queue); + *returned=0; + return ERROR_NOT_ENOUGH_MEMORY; + } for (i=0; i<*returned; i++) - { fill_job_info_1(&(info[i]), &(queue[i]), i, snum); - } + + safe_free(queue); /* check the required size. */ for (i=0; i<*returned; i++) (*needed) += spoolss_size_job_info_1(&(info[i])); - if (!alloc_buffer_size(buffer, *needed)) + if (!alloc_buffer_size(buffer, *needed)) { + safe_free(info); return ERROR_INSUFFICIENT_BUFFER; + } /* fill the buffer with the structures */ for (i=0; i<*returned; i++) new_smb_io_job_info_1("", buffer, &(info[i]), 0); /* clear memory */ - safe_free(queue); safe_free(info); if (*needed > offered) { @@ -3033,25 +3037,31 @@ static uint32 enumjobs_level2(print_queue_struct *queue, int snum, int i; info=(JOB_INFO_2 *)malloc(*returned*sizeof(JOB_INFO_2)); + if (info==NULL) { + safe_free(queue); + *returned=0; + return ERROR_NOT_ENOUGH_MEMORY; + } for (i=0; i<*returned; i++) - { fill_job_info_2(&(info[i]), &(queue[i]), i, snum); - } + + safe_free(queue); /* check the required size. */ for (i=0; i<*returned; i++) (*needed) += spoolss_size_job_info_2(&(info[i])); - if (!alloc_buffer_size(buffer, *needed)) + if (!alloc_buffer_size(buffer, *needed)) { + safe_free(info); return ERROR_INSUFFICIENT_BUFFER; + } /* fill the buffer with the structures */ for (i=0; i<*returned; i++) new_smb_io_job_info_2("", buffer, &(info[i]), 0); /* clear memory */ - safe_free(queue); safe_free(info); if (*needed > offered) { @@ -3081,9 +3091,7 @@ uint32 _spoolss_enumjobs( POLICY_HND *handle, uint32 firstjob, uint32 numofjobs, *returned=0; if (!get_printer_snum(handle, &snum)) - { return ERROR_INVALID_HANDLE; - } *returned = get_printqueue(snum, NULL, &queue, &prt_status); DEBUGADD(4,("count:[%d], status:[%d], [%s]\n", *returned, prt_status.status, prt_status.message)); @@ -3096,13 +3104,14 @@ uint32 _spoolss_enumjobs( POLICY_HND *handle, uint32 firstjob, uint32 numofjobs, return enumjobs_level2(queue, snum, buffer, offered, needed, returned); break; default: + safe_free(queue); + *returned=0; return ERROR_INVALID_LEVEL; break; } } - /**************************************************************************** ****************************************************************************/ uint32 _spoolss_schedulejob( const POLICY_HND *handle, uint32 jobid) @@ -4156,16 +4165,21 @@ static uint32 getjob_level_1(print_queue_struct *queue, int count, int snum, uin if (found==False) { safe_free(queue); + safe_free(info_1); /* I shoud reply something else ... I can't find the good one */ return NT_STATUS_NO_PROBLEMO; } - fill_job_info_1(info_1, &(queue[i]), i, snum); + fill_job_info_1(info_1, &(queue[i-1]), i, snum); + + safe_free(queue); *needed += spoolss_size_job_info_1(info_1); - if (!alloc_buffer_size(buffer, *needed)) + if (!alloc_buffer_size(buffer, *needed)) { + safe_free(info_1); return ERROR_INSUFFICIENT_BUFFER; + } new_smb_io_job_info_1("", buffer, info_1, 0); @@ -4199,16 +4213,21 @@ static uint32 getjob_level_2(print_queue_struct *queue, int count, int snum, uin if (found==False) { safe_free(queue); + safe_free(info_2); /* I shoud reply something else ... I can't find the good one */ return NT_STATUS_NO_PROBLEMO; } - fill_job_info_2(info_2, &(queue[i]), i, snum); + fill_job_info_2(info_2, &(queue[i-1]), i, snum); + + safe_free(queue); *needed += spoolss_size_job_info_2(info_2); - if (!alloc_buffer_size(buffer, *needed)) + if (!alloc_buffer_size(buffer, *needed)) { + safe_free(info_2); return ERROR_INSUFFICIENT_BUFFER; + } new_smb_io_job_info_2("", buffer, info_2, 0); -- cgit From aac823aca154c46264dd29510c89b8eafac361c8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 6 Apr 2000 22:48:53 +0000 Subject: Modified interfaces and added checks around *all* *alloc calls so that errors are returned on memory allocation failure. Jeremy. (This used to be commit 9a118cd4a2b03146b341eeffb62144a2d29b574c) --- source3/rpc_server/srv_spoolss_nt.c | 195 +++++++++++++++++++++++++++--------- 1 file changed, 148 insertions(+), 47 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index b7533c7873..1d33b1b8bb 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -227,7 +227,9 @@ static BOOL open_printer_hnd(POLICY_HND *hnd) { Printer_entry *new_printer; - new_printer=(Printer_entry *)malloc(sizeof(Printer_entry)); + if((new_printer=(Printer_entry *)malloc(sizeof(Printer_entry))) == NULL) + return False; + ZERO_STRUCTP(new_printer); new_printer->open = True; @@ -343,6 +345,9 @@ static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) if (get_a_printer(&printer, 2, lp_servicename(snum))!=0) continue; + DEBUG(10,("set_printer_hnd_printername: printername [%s], aprinter [%s]\n", + printer.info_2->printername, aprinter )); + if ( strlen(printer.info_2->printername) != strlen(aprinter) ) { free_a_printer(printer, 2); continue; @@ -551,7 +556,8 @@ static BOOL convert_devicemode(DEVICEMODE devmode, NT_DEVICEMODE *nt_devmode) /* if we had a previous private delete it and make a new one */ if (nt_devmode->private != NULL) free(nt_devmode->private); - nt_devmode->private=(uint8 *)malloc(nt_devmode->driverextra * sizeof(uint8)); + if((nt_devmode->private=(uint8 *)malloc(nt_devmode->driverextra * sizeof(uint8))) == NULL) + return False; memcpy(nt_devmode->private, devmode.private, nt_devmode->driverextra); } @@ -581,7 +587,8 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d if (!strcmp(value, "BeepEnabled")) { *type = 0x4; - *data = (uint8 *)malloc( 4*sizeof(uint8) ); + if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL) + return False; SIVAL(*data, 0, 0x01); *needed = 0x4; return True; @@ -590,7 +597,8 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d if (!strcmp(value, "EventLog")) { *type = 0x4; - *data = (uint8 *)malloc( 4*sizeof(uint8) ); + if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL) + return False; SIVAL(*data, 0, 0x1B); *needed = 0x4; return True; @@ -599,7 +607,8 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d if (!strcmp(value, "NetPopup")) { *type = 0x4; - *data = (uint8 *)malloc( 4*sizeof(uint8) ); + if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL) + return False; SIVAL(*data, 0, 0x01); *needed = 0x4; return True; @@ -608,7 +617,8 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d if (!strcmp(value, "MajorVersion")) { *type = 0x4; - *data = (uint8 *)malloc( 4*sizeof(uint8) ); + if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL) + return False; SIVAL(*data, 0, 0x02); *needed = 0x4; return True; @@ -619,7 +629,8 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d pstring string="You are using a Samba server"; *type = 0x1; *needed = 2*(strlen(string)+1); - *data = (uint8 *)malloc( ((*needed > in_size) ? *needed:in_size) *sizeof(uint8)); + if((*data = (uint8 *)malloc( ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL) + return False; memset(*data, 0, (*needed > in_size) ? *needed:in_size); /* it's done by hand ready to go on the wire */ @@ -636,7 +647,8 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d pstring string="Windows NT x86"; *type = 0x1; *needed = 2*(strlen(string)+1); - *data = (uint8 *)malloc( ((*needed > in_size) ? *needed:in_size) *sizeof(uint8)); + if((*data = (uint8 *)malloc( ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL) + return False; memset(*data, 0, (*needed > in_size) ? *needed:in_size); for (i=0; iin_size)?in_size:len *sizeof(uint8)); @@ -722,7 +741,8 @@ uint32 _spoolss_getprinterdata(const POLICY_HND *handle, UNISTR2 *valuename, DEBUG(4,("_spoolss_getprinterdata\n")); if (!OPEN_HANDLE(Printer)) { - *data=(uint8 *)malloc(4*sizeof(uint8)); + if((*data=(uint8 *)malloc(4*sizeof(uint8))) == NULL) + return ERROR_NOT_ENOUGH_MEMORY; return ERROR_INVALID_HANDLE; } @@ -736,7 +756,8 @@ uint32 _spoolss_getprinterdata(const POLICY_HND *handle, UNISTR2 *valuename, if (found==False) { DEBUG(5, ("value not found, allocating %d\n", *out_size)); /* reply this param doesn't exist */ - *data=(uint8 *)malloc(*out_size*sizeof(uint8)); + if((*data=(uint8 *)malloc(*out_size*sizeof(uint8))) == NULL) + return ERROR_NOT_ENOUGH_MEMORY; memset(*data, 0x0, *out_size*sizeof(uint8)); return ERROR_INVALID_PARAMETER; } @@ -1250,7 +1271,10 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPO if (!search_notify(type, field, &j) ) continue; - info->data=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA)); + if((info->data=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) { + free_a_printer(printer, 2); + return False; + } current_data=&(info->data[info->count]); construct_info_data(current_data, type, field, id); @@ -1297,7 +1321,11 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_I if (!search_notify(type, field, &j) ) continue; - info->data=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA)); + if((info->data=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) { + free_a_printer(printer, 2); + return False; + } + current_data=&(info->data[info->count]); construct_info_data(current_data, type, field, id); @@ -1531,7 +1559,8 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, pstring /* it's the first time, add it to the list */ if (session_counter==NULL) { - session_counter=(counter_printer_0 *)malloc(sizeof(counter_printer_0)); + if((session_counter=(counter_printer_0 *)malloc(sizeof(counter_printer_0))) == NULL) + return False; ZERO_STRUCTP(session_counter); session_counter->snum=snum; session_counter->counter=0; @@ -1635,7 +1664,7 @@ static BOOL construct_printer_info_1(fstring server, uint32 flags, PRINTER_INFO_ /**************************************************************************** ****************************************************************************/ -static void construct_dev_mode(DEVICEMODE *devmode, int snum, char *servername) +static BOOL construct_dev_mode(DEVICEMODE *devmode, int snum, char *servername) { char adevice[32]; char aform[32]; @@ -1686,11 +1715,16 @@ static void construct_dev_mode(DEVICEMODE *devmode, int snum, char *servername) if (ntdevmode->private != NULL) { - devmode->private=(uint8 *)malloc(devmode->driverextra*sizeof(uint8)); + if((devmode->private=(uint8 *)malloc(devmode->driverextra*sizeof(uint8))) == NULL) { + free_a_printer(printer, 2); + return False; + } memcpy(devmode->private, ntdevmode->private, devmode->driverextra); } free_a_printer(printer, 2); + + return True; } /******************************************************************** @@ -1749,14 +1783,25 @@ static BOOL construct_printer_info_2(pstring servername, PRINTER_INFO_2 *printer printer->cjobs = count; /* jobs */ printer->averageppm = ntprinter.info_2->averageppm; /* average pages per minute */ - devmode=(DEVICEMODE *)malloc(sizeof(DEVICEMODE)); + if((devmode=(DEVICEMODE *)malloc(sizeof(DEVICEMODE))) == NULL) + goto err; + ZERO_STRUCTP(devmode); - construct_dev_mode(devmode, snum, servername); + + if(!construct_dev_mode(devmode, snum, servername)) + goto err; + printer->devmode=devmode; safe_free(queue); free_a_printer(ntprinter, 2); return True; + + err: + + safe_free(queue); + free_a_printer(ntprinter, 2); + return False; } /******************************************************************** @@ -1777,7 +1822,10 @@ static BOOL enum_all_printers_info_1(fstring server, uint32 flags, NEW_BUFFER *b DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum)); if (construct_printer_info_1(server, flags, ¤t_prt, snum)) { - printers=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_1)); + if((printers=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_1))) == NULL) { + *returned=0; + return ERROR_NOT_ENOUGH_MEMORY; + } DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_1\n", *returned)); memcpy(&(printers[*returned]), ¤t_prt, sizeof(PRINTER_INFO_1)); (*returned)++; @@ -1863,7 +1911,8 @@ static BOOL enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, ui * We should have a TDB here. The registration is done thru an undocumented RPC call. */ - printer=(PRINTER_INFO_1 *)malloc(sizeof(PRINTER_INFO_1)); + if((printer=(PRINTER_INFO_1 *)malloc(sizeof(PRINTER_INFO_1))) == NULL) + return ERROR_NOT_ENOUGH_MEMORY; *returned=1; @@ -1930,7 +1979,8 @@ static BOOL enum_all_printers_info_2(fstring servername, NEW_BUFFER *buffer, uin DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum)); if (construct_printer_info_2(servername, ¤t_prt, snum)) { - printers=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_2)); + if((printers=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_2))) == NULL) + return ERROR_NOT_ENOUGH_MEMORY; DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_2\n", *returned)); memcpy(&(printers[*returned]), ¤t_prt, sizeof(PRINTER_INFO_2)); (*returned)++; @@ -2093,7 +2143,8 @@ static uint32 getprinter_level_0(pstring servername, int snum, NEW_BUFFER *buffe { PRINTER_INFO_0 *printer=NULL; - printer=(PRINTER_INFO_0*)malloc(sizeof(PRINTER_INFO_0)); + if((printer=(PRINTER_INFO_0*)malloc(sizeof(PRINTER_INFO_0))) == NULL) + return ERROR_NOT_ENOUGH_MEMORY; construct_printer_info_0(printer, snum, servername); @@ -2124,7 +2175,9 @@ static uint32 getprinter_level_1(pstring servername, int snum, NEW_BUFFER *buffe { PRINTER_INFO_1 *printer=NULL; - printer=(PRINTER_INFO_1*)malloc(sizeof(PRINTER_INFO_1)); + if((printer=(PRINTER_INFO_1*)malloc(sizeof(PRINTER_INFO_1))) == NULL) + return ERROR_NOT_ENOUGH_MEMORY; + construct_printer_info_1(servername, PRINTER_ENUM_ICON8, printer, snum); /* check the required size. */ @@ -2155,7 +2208,8 @@ static uint32 getprinter_level_2(pstring servername, int snum, NEW_BUFFER *buffe PRINTER_INFO_2 *printer=NULL; fstring temp; - printer=(PRINTER_INFO_2*)malloc(sizeof(PRINTER_INFO_2)); + if((printer=(PRINTER_INFO_2*)malloc(sizeof(PRINTER_INFO_2)))==NULL) + return ERROR_NOT_ENOUGH_MEMORY; fstrcpy(temp, "\\\\"); fstrcat(temp, servername); @@ -2313,7 +2367,10 @@ static void init_unistr_array(uint16 **uni_array, char **char_array, char *where for (v=char_array[i]; *v!='\0'; v=char_array[i]) { snprintf(line, sizeof(line)-1, "%s%s", where, v); DEBUGADD(6,("%d:%s:%d\n", i, line, strlen(line))); - *uni_array=Realloc(*uni_array, (j+strlen(line)+2)*sizeof(uint16)); + if((*uni_array=Realloc(*uni_array, (j+strlen(line)+2)*sizeof(uint16))) == NULL) { + DEBUG(0,("init_unistr_array: Realloc error\n" )); + return; + } ascii_to_unistr( *uni_array+j, line , strlen(line)); j+=strlen(line)+1; i++; @@ -2392,7 +2449,8 @@ static uint32 getprinterdriver2_level1(pstring servername, pstring architecture, { DRIVER_INFO_1 *info=NULL; - info=(DRIVER_INFO_1 *)malloc(sizeof(DRIVER_INFO_1)); + if((info=(DRIVER_INFO_1 *)malloc(sizeof(DRIVER_INFO_1))) == NULL) + return ERROR_NOT_ENOUGH_MEMORY; construct_printer_driver_info_1(info, snum, servername, architecture); @@ -2422,7 +2480,8 @@ static uint32 getprinterdriver2_level2(pstring servername, pstring architecture, { DRIVER_INFO_2 *info=NULL; - info=(DRIVER_INFO_2 *)malloc(sizeof(DRIVER_INFO_2)); + if((info=(DRIVER_INFO_2 *)malloc(sizeof(DRIVER_INFO_2))) == NULL) + return ERROR_NOT_ENOUGH_MEMORY; construct_printer_driver_info_2(info, snum, servername, architecture); @@ -2452,7 +2511,8 @@ static uint32 getprinterdriver2_level3(pstring servername, pstring architecture, { DRIVER_INFO_3 *info=NULL; - info=(DRIVER_INFO_3 *)malloc(sizeof(DRIVER_INFO_3)); + if((info=(DRIVER_INFO_3 *)malloc(sizeof(DRIVER_INFO_3)))==NULL) + return ERROR_NOT_ENOUGH_MEMORY; construct_printer_driver_info_3(info, snum, servername, architecture); @@ -2971,9 +3031,16 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, job_info->timeelapsed=0; job_info->pagesprinted=0; - devmode=(DEVICEMODE *)malloc(sizeof(DEVICEMODE)); + if((devmode=(DEVICEMODE *)malloc(sizeof(DEVICEMODE))) == NULL) { + free_a_printer(ntprinter, 2); + return False; + } + ZERO_STRUCTP(devmode); - construct_dev_mode(devmode, snum, global_myname); + if(!construct_dev_mode(devmode, snum, global_myname)) { + free_a_printer(ntprinter, 2); + return False; + } job_info->devmode=devmode; free_a_printer(ntprinter, 2); @@ -3189,7 +3256,9 @@ static uint32 enumprinterdrivers_level1(fstring *list, fstring servername, fstri int i; NT_PRINTER_DRIVER_INFO_LEVEL driver; DRIVER_INFO_1 *driver_info_1=NULL; - driver_info_1=(DRIVER_INFO_1 *)malloc(*returned * sizeof(DRIVER_INFO_1)); + + if((driver_info_1=(DRIVER_INFO_1 *)malloc(*returned * sizeof(DRIVER_INFO_1))) == NULL) + return ERROR_NOT_ENOUGH_MEMORY; for (i=0; i<*returned; i++) { get_a_printer_driver(&driver, 3, list[i], architecture); @@ -3234,7 +3303,9 @@ static uint32 enumprinterdrivers_level2(fstring *list, fstring servername, fstri int i; NT_PRINTER_DRIVER_INFO_LEVEL driver; DRIVER_INFO_2 *driver_info_2=NULL; - driver_info_2=(DRIVER_INFO_2 *)malloc(*returned * sizeof(DRIVER_INFO_2)); + + if((driver_info_2=(DRIVER_INFO_2 *)malloc(*returned * sizeof(DRIVER_INFO_2))) == NULL) + return ERROR_NOT_ENOUGH_MEMORY; for (i=0; i<*returned; i++) { get_a_printer_driver(&driver, 3, list[i], architecture); @@ -3279,7 +3350,9 @@ static uint32 enumprinterdrivers_level3(fstring *list, fstring servername, fstri int i; NT_PRINTER_DRIVER_INFO_LEVEL driver; DRIVER_INFO_3 *driver_info_3=NULL; - driver_info_3=(DRIVER_INFO_3 *)malloc((*returned)*sizeof(DRIVER_INFO_3)); + + if((driver_info_3=(DRIVER_INFO_3 *)malloc((*returned)*sizeof(DRIVER_INFO_3))) == NULL) + return ERROR_NOT_ENOUGH_MEMORY; for (i=0; i<*returned; i++) { get_a_printer_driver(&driver, 3, list[i], architecture); @@ -3340,6 +3413,9 @@ uint32 _spoolss_enumprinterdrivers( UNISTR2 *name, UNISTR2 *environment, uint32 *returned=get_ntdrivers(&list, architecture); DEBUGADD(4,("we have: [%d] drivers in environment [%s]\n", *returned, architecture)); + if(*returned == -1) + return ERROR_NOT_ENOUGH_MEMORY; + for (i=0; i<*returned; i++) DEBUGADD(5,("driver: [%s]\n", list[i])); @@ -3393,7 +3469,10 @@ uint32 _new_spoolss_enumforms( const POLICY_HND *handle, uint32 level, switch (level) { case 1: - forms_1=(FORM_1 *)malloc(*numofforms * sizeof(FORM_1)); + if((forms_1=(FORM_1 *)malloc(*numofforms * sizeof(FORM_1))) == NULL) { + *numofforms=0; + return ERROR_NOT_ENOUGH_MEMORY; + } /* construct the list of form structures */ for (i=0; i<*numofforms; i++) { @@ -3472,7 +3551,8 @@ static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) (*returned)++; - ports=(PORT_INFO_1 *)malloc( (*returned+1) * sizeof(PORT_INFO_1) ); + if((ports=(PORT_INFO_1 *)malloc( (*returned+1) * sizeof(PORT_INFO_1) )) == NULL) + return ERROR_NOT_ENOUGH_MEMORY; for (snum=0; snumname), "winprint"); @@ -4010,7 +4104,9 @@ static uint32 enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered, { PRINTPROCDATATYPE_1 *info_1=NULL; - info_1 = (PRINTPROCDATATYPE_1 *)malloc(sizeof(PRINTPROCDATATYPE_1)); + if((info_1 = (PRINTPROCDATATYPE_1 *)malloc(sizeof(PRINTPROCDATATYPE_1))) == NULL) + return ERROR_NOT_ENOUGH_MEMORY; + (*returned) = 0x1; init_unistr(&(info_1->name), "RAW"); @@ -4060,7 +4156,9 @@ static uint32 enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, uint { PRINTMONITOR_1 *info_1=NULL; - info_1 = (PRINTMONITOR_1 *)malloc(sizeof(PRINTMONITOR_1)); + if((info_1 = (PRINTMONITOR_1 *)malloc(sizeof(PRINTMONITOR_1))) == NULL) + return ERROR_NOT_ENOUGH_MEMORY; + (*returned) = 0x1; init_unistr(&(info_1->name), "Local Port"); @@ -4089,7 +4187,9 @@ static uint32 enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint { PRINTMONITOR_2 *info_2=NULL; - info_2 = (PRINTMONITOR_2 *)malloc(sizeof(PRINTMONITOR_2)); + if((info_2 = (PRINTMONITOR_2 *)malloc(sizeof(PRINTMONITOR_2))) == NULL) + return ERROR_NOT_ENOUGH_MEMORY; + (*returned) = 0x1; init_unistr(&(info_2->name), "Local Port"); @@ -4151,6 +4251,7 @@ static uint32 getjob_level_1(print_queue_struct *queue, int count, int snum, uin int i=0; BOOL found=False; JOB_INFO_1 *info_1=NULL; + info_1=(JOB_INFO_1 *)malloc(sizeof(JOB_INFO_1)); if (info_1 == NULL) { -- cgit From 416fa5377bfca53f21b1fe9c1a71c7ca255abeb2 Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Mon, 10 Apr 2000 21:47:46 +0000 Subject: added checks to open both \\server\printer and \\server\share. it doesn't work, the getprinter level 0 reply is wrong... J.F. (This used to be commit a7b09e3e11dc66779ee50524ebe1f6687ec744c6) --- source3/rpc_server/srv_spoolss_nt.c | 47 ++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 1d33b1b8bb..3f9e98caa3 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -327,6 +327,7 @@ static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) aprinter++; DEBUGADD(5,("searching for [%s] (len=%d)\n", aprinter, strlen(aprinter))); + /* * store the Samba share name in it * in back we have the long printer name @@ -361,14 +362,54 @@ static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) found=True; } - if (found==False) - { + /* + * if we haven't found a printer with the given printername + * then it can be a share name as you can open both \\server\printer and + * \\server\share + */ + + /* + * we still check if the printer description file exists as NT won't be happy + * if we reply OK in the openprinter call and can't reply in the subsequent RPC calls + */ + + if (found==False) { + DEBUGADD(5,("Printer not found, checking for share now\n")); + + for (snum=0;snumprintername, aprinter )); + + if ( strlen(lp_servicename(snum)) != strlen(aprinter) ) { + free_a_printer(printer, 2); + continue; + } + + if ( strncasecmp(lp_servicename(snum), aprinter, strlen(aprinter))) { + free_a_printer(printer, 2); + continue; + } + + found=True; + } + } + + if (found==False) { DEBUGADD(4,("Printer not found\n")); return False; } snum--; - DEBUGADD(4,("Printer found: %s[%x]\n",lp_servicename(snum),snum)); + DEBUGADD(4,("Printer found: %s -> %s[%x]\n",printer.info_2->printername, lp_servicename(snum),snum)); ZERO_STRUCT(Printer->dev.printername); strncpy(Printer->dev.printername, lp_servicename(snum), strlen(lp_servicename(snum))); free_a_printer(printer, 2); -- cgit From 8a91379a00cade86a0b448c6a7c4e949cc58185c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 16 Apr 2000 06:20:43 +0000 Subject: JF and Jeremy - please have a look at what I did to the spoolss code. It now uses the new printing backend. ------------ The following series of commits are for the new tdb based printing backend. This completely replaces our old printing backend. Major changes include: - all print ops are now done in printing/*.c rather than scattered all over the place - system job ids are decoupled from SMB job ids - the lpq parsers don't need to be nearly so smart, they only need to parse the filename, the status and system job id - we can store lots more info about a job, including the full job name - the queue cache control is much better I also added a new utility routine file_lines_load() that loads a text file and parses it into lines. This is used in out lpq parsing and I also want to use it to replace all of our fgets() based code in other places. (This used to be commit 2df82862c061cca5644f5f69146c97302ccb42d5) --- source3/rpc_server/srv_spoolss_nt.c | 242 +++++++++--------------------------- 1 file changed, 59 insertions(+), 183 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 3f9e98caa3..54564b6c7d 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -46,11 +46,7 @@ typedef struct _Printer{ BOOL open; BOOL document_started; BOOL page_started; - uint32 current_jobid; - uint32 document_fd; - uint32 document_lastwritten; - pstring document_name; - pstring job_name; + int jobid; /* jobid in printing backend */ POLICY_HND printer_hnd; BOOL printer_type; union { @@ -183,11 +179,9 @@ static BOOL close_printer_handle(POLICY_HND *hnd) ****************************************************************************/ static BOOL get_printer_snum(const POLICY_HND *hnd, int *number) { - int snum; Printer_entry *Printer = find_printer_index_by_hnd(hnd); - int n_services=lp_numservices(); - if (!OPEN_HANDLE(Printer)) { + if (!OPEN_HANDLE(Printer)) { DEBUG(3,("Error getting printer - take a nap quickly !\n")); return False; } @@ -195,22 +189,8 @@ static BOOL get_printer_snum(const POLICY_HND *hnd, int *number) switch (Printer->printer_type) { case PRINTER_HANDLE_IS_PRINTER: DEBUG(4,("short name:%s\n", Printer->dev.printername)); - for (snum=0;snumdev.printername ) ) - && ( !strncasecmp(lp_servicename(snum), - Printer->dev.printername, - strlen( lp_servicename(snum) ))) ) { - DEBUG(4,("Printer found: %s[%x]\n",lp_servicename(snum),snum)); - *number=snum; - return True; - break; - } - } - } - return False; - break; + *number = print_queue_snum(Printer->dev.printername); + return (*number != -1); case PRINTER_HANDLE_IS_PRINTSERVER: return False; break; @@ -338,7 +318,7 @@ static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) for (snum=0;snumnotify_data.value[0]=(uint32) status.status; safe_free(q); } @@ -1065,7 +1045,7 @@ static void spoolss_notify_cjobs(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_q print_status_struct status; memset(&status, 0, sizeof(status)); - data->notify_data.value[0]=get_printqueue(snum, NULL, &q, &status); + data->notify_data.value[0] = print_queue_status(snum, &q, &status); safe_free(q); } @@ -1499,7 +1479,7 @@ static uint32 printer_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info case JOB_NOTIFY_TYPE: memset(&status, 0, sizeof(status)); - count=get_printqueue(snum, NULL, &queue, &status); + count = print_queue_status(snum, &queue, &status); for (j=0; jdoc_info_1; - - pstring fname; - pstring tempname; - pstring datatype; - int fd = -1; int snum; + pstring jobname; + fstring datatype; Printer_entry *Printer = find_printer_index_by_hnd(handle); if (!OPEN_HANDLE(Printer)) @@ -2701,24 +2678,18 @@ uint32 _spoolss_startdocprinter( const POLICY_HND *handle, uint32 level, return ERROR_INVALID_HANDLE; } - /* Create a temporary file in the printer spool directory - * and open it - */ - - slprintf(tempname,sizeof(tempname)-1, "%s/smb_print.XXXXXX",lp_pathname(snum)); - pstrcpy(fname, (char *)mktemp(tempname)); - - fd=open(fname, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, S_IRUSR|S_IWUSR ); - DEBUG(4,("Temp spool file created: [%s]\n", fname)); - - Printer->current_jobid=fd; - pstrcpy(Printer->document_name, fname); + unistr2_to_ascii(jobname, &info_1->docname, sizeof(jobname)); - unistr2_to_ascii(Printer->job_name, &info_1->docname, sizeof(Printer->job_name)); + Printer->jobid = print_job_start(snum, jobname); + + /* need to map error codes properly - for now give out of + memory as I don't know the correct codes (tridge) */ + if (Printer->jobid == -1) { + return ERROR_NOT_ENOUGH_MEMORY; + } - Printer->document_fd=fd; Printer->document_started=True; - (*jobid) = Printer->current_jobid; + (*jobid) = Printer->jobid; return 0x0; } @@ -2730,16 +2701,8 @@ uint32 _spoolss_startdocprinter( const POLICY_HND *handle, uint32 level, ********************************************************************/ uint32 _spoolss_enddocprinter(const POLICY_HND *handle) { - int snum; - pstring filename; - pstring filename1; - pstring job_name; - pstring syscmd; - char *tstr; Printer_entry *Printer=find_printer_index_by_hnd(handle); - *syscmd=0; - if (!OPEN_HANDLE(Printer)) { DEBUG(3,("Error in enddocprinter handle\n")); @@ -2747,65 +2710,8 @@ uint32 _spoolss_enddocprinter(const POLICY_HND *handle) } Printer->document_started=False; - close(Printer->document_fd); - DEBUG(4,("Temp spool file closed, printing now ...\n")); - - pstrcpy(filename1, Printer->document_name); - pstrcpy(job_name, Printer->job_name); - - if (!get_printer_snum(handle,&snum)) - { - return ERROR_INVALID_HANDLE; - } - - /* copy the command into the buffer for extensive meddling. */ - StrnCpy(syscmd, lp_printcommand(snum), sizeof(pstring) - 1); - - /* look for "%s" in the string. If there is no %s, we cannot print. */ - if (!strstr(syscmd, "%s") && !strstr(syscmd, "%f")) - { - DEBUG(2,("WARNING! No placeholder for the filename in the print command for service %s!\n", SERVICE(snum))); - } - - if (strstr(syscmd,"%s")) - { - pstrcpy(filename,filename1); - pstring_sub(syscmd, "%s", filename); - } - - pstring_sub(syscmd, "%f", filename1); - - /* Does the service have a printername? If not, make a fake and empty - * printer name. That way a %p is treated sanely if no printer - * name was specified to replace it. This eventuality is logged. - */ - - tstr = lp_printername(snum); - if (tstr == NULL || tstr[0] == '\0') { - DEBUG(3,( "No printer name - using %s.\n", SERVICE(snum))); - tstr = SERVICE(snum); - } - - pstring_sub(syscmd, "%p", tstr); - - /* If the lpr command support the 'Job' option replace here */ - pstring_sub(syscmd, "%j", job_name); - - if ( *syscmd != '\0') { - int ret = smbrun(syscmd, NULL, False); - DEBUG(3,("Running the command `%s' gave %d\n", syscmd, ret)); - if (ret < 0) { - lpq_reset(snum); - return ERROR_ACCESS_DENIED; - } - } - else { - DEBUG(0,("Null print command?\n")); - lpq_reset(snum); - return ERROR_ACCESS_DENIED; - } - - lpq_reset(snum); + print_job_end(Printer->jobid); + /* error codes unhandled so far ... */ return 0x0; } @@ -2817,7 +2723,6 @@ uint32 _spoolss_writeprinter( const POLICY_HND *handle, const uint8 *buffer, uint32 *buffer_written) { - int fd; Printer_entry *Printer = find_printer_index_by_hnd(handle); if (!OPEN_HANDLE(Printer)) @@ -2826,9 +2731,7 @@ uint32 _spoolss_writeprinter( const POLICY_HND *handle, return ERROR_INVALID_HANDLE; } - fd = Printer->document_fd; - (*buffer_written) = write(fd, buffer, buffer_size); - Printer->document_lastwritten = (*buffer_written); + (*buffer_written) = print_job_write(Printer->jobid, buffer, buffer_size); return 0x0; } @@ -2850,27 +2753,22 @@ static uint32 control_printer(const POLICY_HND *handle, uint32 command) return ERROR_INVALID_HANDLE; switch (command) { - case PRINTER_CONTROL_PAUSE: - /* pause the printer here */ - status_printqueue(NULL, snum, LPSTAT_STOPPED); - return 0x0; - break; - case PRINTER_CONTROL_RESUME: - case PRINTER_CONTROL_UNPAUSE: - /* UN-pause the printer here */ - status_printqueue(NULL, snum, LPSTAT_OK); - return 0x0; - break; - case PRINTER_CONTROL_PURGE: - /* - * It's not handled by samba - * we need a smb.conf param to do - * lprm -P%p - on BSD - * lprm -P%p all on LPRNG - * I don't know on SysV - * we could do it by looping in the job's list... - */ - break; + case PRINTER_CONTROL_PAUSE: + if (print_queue_pause(snum)) { + return 0; + } + break; + case PRINTER_CONTROL_RESUME: + case PRINTER_CONTROL_UNPAUSE: + if (print_queue_resume(snum)) { + return 0; + } + break; + case PRINTER_CONTROL_PURGE: + if (print_queue_purge(snum)) { + return 0; + } + break; } return ERROR_INVALID_FUNCTION; @@ -3201,7 +3099,7 @@ uint32 _spoolss_enumjobs( POLICY_HND *handle, uint32 firstjob, uint32 numofjobs, if (!get_printer_snum(handle, &snum)) return ERROR_INVALID_HANDLE; - *returned = get_printqueue(snum, NULL, &queue, &prt_status); + *returned = print_queue_status(snum, &queue, &prt_status); DEBUGADD(4,("count:[%d], status:[%d], [%s]\n", *returned, prt_status.status, prt_status.message)); switch (level) { @@ -3237,11 +3135,7 @@ uint32 _spoolss_setjob( const POLICY_HND *handle, { int snum; - print_queue_struct *queue=NULL; print_status_struct prt_status; - int i=0; - BOOL found=False; - int count; memset(&prt_status, 0, sizeof(prt_status)); @@ -3249,44 +3143,26 @@ uint32 _spoolss_setjob( const POLICY_HND *handle, return ERROR_INVALID_HANDLE; } - count=get_printqueue(snum, NULL, &queue, &prt_status); - - while ( (i Date: Sun, 16 Apr 2000 07:28:06 +0000 Subject: - put the job status in english not french! - add helper fns to change from internal status codes to nt spoolss codes (This used to be commit 917c4814fe076cc38b1becf7d219f2437cba6e60) --- source3/rpc_server/srv_spoolss_nt.c | 56 ++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 7 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 54564b6c7d..786bc90b91 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -82,6 +82,33 @@ static ubi_dlList counter_list; #define OPEN_HANDLE(pnum) ((pnum!=NULL) && (pnum->open!=False)) +/* translate between internal status numbers and NT status numbers */ +static int nt_printj_status(int v) +{ + switch (v) { + case LPQ_PAUSED: + return PRINTER_STATUS_PAUSED; + case LPQ_QUEUED: + case LPQ_SPOOLING: + case LPQ_PRINTING: + return 0; + } + return 0; +} + +static int nt_printq_status(int v) +{ + switch (v) { + case LPQ_PAUSED: + return PRINTER_STATUS_ERROR; + case LPQ_QUEUED: + case LPQ_SPOOLING: + case LPQ_PRINTING: + return 0; + } + return 0; +} + /**************************************************************************** initialise printer handle states... ****************************************************************************/ @@ -1073,7 +1100,7 @@ static void spoolss_notify_username(int snum, SPOOL_NOTIFY_INFO_DATA *data, prin ********************************************************************/ static void spoolss_notify_job_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { - data->notify_data.value[0]=queue->status; + data->notify_data.value[0]=nt_printj_status(queue->status); } /******************************************************************* @@ -1090,8 +1117,23 @@ static void spoolss_notify_job_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, prin ********************************************************************/ static void spoolss_notify_job_status_string(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { - data->notify_data.data.length=strlen("En attente"); - ascii_to_unistr(data->notify_data.data.string, "En attente", sizeof(data->notify_data.data.string)-1); + char *p = "unknown"; + switch (queue->status) { + case LPQ_QUEUED: + p = "QUEUED"; + break; + case LPQ_PAUSED: + p = "PAUSED"; + break; + case LPQ_SPOOLING: + p = "SPOOLING"; + break; + case LPQ_PRINTING: + p = "PRINTING"; + break; + } + data->notify_data.data.length=strlen(p); + ascii_to_unistr(data->notify_data.data.string, p, sizeof(data->notify_data.data.string)-1); } /******************************************************************* @@ -1636,7 +1678,7 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, pstring printer->unknown16 = 0x0; printer->change_id = ntprinter.info_2->changeid; /* ChangeID in milliseconds*/ printer->unknown18 = 0x0; - printer->status = status.status; + printer->status = nt_printq_status(status.status); printer->unknown20 = 0x0; printer->c_setprinter = ntprinter.info_2->c_setprinter; /* how many times setprinter has been called */ printer->unknown22 = 0x0; @@ -1800,7 +1842,7 @@ static BOOL construct_printer_info_2(pstring servername, PRINTER_INFO_2 *printer printer->defaultpriority = ntprinter.info_2->default_priority; /* default priority */ printer->starttime = ntprinter.info_2->starttime; /* starttime */ printer->untiltime = ntprinter.info_2->untiltime; /* untiltime */ - printer->status = status.status; /* status */ + printer->status = nt_printq_status(status.status); /* status */ printer->cjobs = count; /* jobs */ printer->averageppm = ntprinter.info_2->averageppm; /* average pages per minute */ @@ -2915,7 +2957,7 @@ static void fill_job_info_1(JOB_INFO_1 *job_info, print_queue_struct *queue, init_unistr(&(job_info->document), queue->file); init_unistr(&(job_info->datatype), "RAW"); init_unistr(&(job_info->text_status), ""); - job_info->status=queue->status; + job_info->status=nt_printj_status(queue->status); job_info->priority=queue->priority; job_info->position=position; job_info->totalpages=0; @@ -2959,7 +3001,7 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, /* and here the security descriptor */ - job_info->status=queue->status; + job_info->status=nt_printj_status(queue->status); job_info->priority=queue->priority; job_info->position=position; job_info->starttime=0; -- cgit From b1686a61091fb10ebaac837c95554076ed49e67a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 23 Apr 2000 08:13:48 +0000 Subject: we can't pass a fstring to a routine expecting a pstring (This used to be commit 8af70f288723e4597bc8639fc0cbec44af2e50c7) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 786bc90b91..52eaaafe6f 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1794,7 +1794,7 @@ static BOOL construct_dev_mode(DEVICEMODE *devmode, int snum, char *servername) * construct_printer_info_2 * fill a printer_info_2 struct ********************************************************************/ -static BOOL construct_printer_info_2(pstring servername, PRINTER_INFO_2 *printer, int snum) +static BOOL construct_printer_info_2(fstring servername, PRINTER_INFO_2 *printer, int snum) { pstring chaine; pstring chaine2; -- cgit From 6d667ad4d31f9ec02e6cdf289b4958506b847f26 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 23 Apr 2000 08:40:54 +0000 Subject: fixed another spoolss memory leak I am falling in love with insure - it is finding _lots_ of memory problems (This used to be commit d9b4076293a4d37e1558ad63a3f522385ee3e521) --- source3/rpc_server/srv_spoolss_nt.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 52eaaafe6f..05af14e830 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1575,8 +1575,6 @@ uint32 _spoolss_rfnpcnex( const POLICY_HND *handle, uint32 change, if (option!=NULL) safe_free(option->ctr.type); - safe_free(option); - switch (Printer->printer_type) { case PRINTER_HANDLE_IS_PRINTSERVER: return printserver_notify_info(handle, info); -- cgit From d0e9a0c4f2decbf2cd0753bdc25ac1463e8fb22b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 23 Apr 2000 08:44:55 +0000 Subject: another fstring/pstring fix (This used to be commit 91ed7d8ffe8208d06191c64f5332954ec6bf75da) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 05af14e830..89d4c55de1 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2362,7 +2362,7 @@ static void construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, ********************************************************************/ static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, - pstring servername, fstring architecture) + fstring servername, fstring architecture) { pstring where; pstring temp_driverpath; -- cgit From d315f69e542762efc54f1004e85c860dc5d7177a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 23 Apr 2000 14:25:36 +0000 Subject: more pstring/fstring errors found by insure (This used to be commit ba1931bb6596b538549e712cb8898b1ed19f5adc) --- source3/rpc_server/srv_spoolss_nt.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 89d4c55de1..d1ad0f6229 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1591,7 +1591,7 @@ uint32 _spoolss_rfnpcnex( const POLICY_HND *handle, uint32 change, * construct_printer_info_0 * fill a printer_info_1 struct ********************************************************************/ -static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, pstring servername) +static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, fstring servername) { pstring chaine; int count; @@ -2200,7 +2200,7 @@ uint32 _spoolss_enumprinters( uint32 flags, const UNISTR2 *servername, uint32 le /**************************************************************************** ****************************************************************************/ -static uint32 getprinter_level_0(pstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static uint32 getprinter_level_0(fstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_0 *printer=NULL; @@ -2232,7 +2232,7 @@ static uint32 getprinter_level_0(pstring servername, int snum, NEW_BUFFER *buffe /**************************************************************************** ****************************************************************************/ -static uint32 getprinter_level_1(pstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static uint32 getprinter_level_1(fstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_1 *printer=NULL; @@ -2264,7 +2264,7 @@ static uint32 getprinter_level_1(pstring servername, int snum, NEW_BUFFER *buffe /**************************************************************************** ****************************************************************************/ -static uint32 getprinter_level_2(pstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static uint32 getprinter_level_2(fstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_2 *printer=NULL; fstring temp; @@ -2305,7 +2305,7 @@ uint32 _spoolss_getprinter(POLICY_HND *handle, uint32 level, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { int snum; - pstring servername; + fstring servername; *needed=0; @@ -2336,13 +2336,13 @@ uint32 _spoolss_getprinter(POLICY_HND *handle, uint32 level, ********************************************************************/ static void fill_printer_driver_info_1(DRIVER_INFO_1 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, - pstring servername, fstring architecture) + fstring servername, fstring architecture) { init_unistr( &(info->name), driver.info_3->name); } static void construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, - pstring servername, fstring architecture) + fstring servername, fstring architecture) { NT_PRINTER_INFO_LEVEL printer; NT_PRINTER_DRIVER_INFO_LEVEL driver; @@ -2396,7 +2396,7 @@ static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, * construct_printer_driver_info_2 * fill a printer_info_2 struct ********************************************************************/ -static void construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, pstring servername, fstring architecture) +static void construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fstring servername, fstring architecture) { NT_PRINTER_INFO_LEVEL printer; NT_PRINTER_DRIVER_INFO_LEVEL driver; @@ -2448,7 +2448,7 @@ static void init_unistr_array(uint16 **uni_array, char **char_array, char *where ********************************************************************/ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, - pstring servername, fstring architecture) + fstring servername, fstring architecture) { pstring where; pstring temp_driverpath; @@ -2490,7 +2490,7 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, * fill a printer_info_3 struct ********************************************************************/ static void construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, - pstring servername, fstring architecture) + fstring servername, fstring architecture) { NT_PRINTER_INFO_LEVEL printer; NT_PRINTER_DRIVER_INFO_LEVEL driver; @@ -2506,7 +2506,7 @@ static void construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, /**************************************************************************** ****************************************************************************/ -static uint32 getprinterdriver2_level1(pstring servername, pstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static uint32 getprinterdriver2_level1(fstring servername, fstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_1 *info=NULL; @@ -2537,7 +2537,7 @@ static uint32 getprinterdriver2_level1(pstring servername, pstring architecture, /**************************************************************************** ****************************************************************************/ -static uint32 getprinterdriver2_level2(pstring servername, pstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static uint32 getprinterdriver2_level2(fstring servername, fstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_2 *info=NULL; @@ -2568,7 +2568,7 @@ static uint32 getprinterdriver2_level2(pstring servername, pstring architecture, /**************************************************************************** ****************************************************************************/ -static uint32 getprinterdriver2_level3(pstring servername, pstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static uint32 getprinterdriver2_level3(fstring servername, fstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_3 *info=NULL; @@ -2605,7 +2605,7 @@ uint32 _spoolss_getprinterdriver2(const POLICY_HND *handle, const UNISTR2 *uni_a NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *servermajorversion, uint32 *serverminorversion) { - pstring servername; + fstring servername; fstring architecture; int snum; @@ -3261,7 +3261,8 @@ static uint32 enumprinterdrivers_level2(fstring *list, fstring servername, fstri NT_PRINTER_DRIVER_INFO_LEVEL driver; DRIVER_INFO_2 *driver_info_2=NULL; - if((driver_info_2=(DRIVER_INFO_2 *)malloc(*returned * sizeof(DRIVER_INFO_2))) == NULL) + if (*returned > 0 && + !(driver_info_2=(DRIVER_INFO_2 *)malloc(*returned * sizeof(DRIVER_INFO_2)))) return ERROR_NOT_ENOUGH_MEMORY; for (i=0; i<*returned; i++) { -- cgit From 00e3fe132476fcaed0f4b9bbe74b0a6559c39df0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 25 Apr 2000 14:06:57 +0000 Subject: moved trans2.h and nterr.h into includes.h with all our other includes (This used to be commit d7cd7c88fdabb01d9e40ae8a657737907a21ac37) --- source3/rpc_server/srv_spoolss_nt.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index d1ad0f6229..1121d5c2b1 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -23,7 +23,6 @@ #include "includes.h" -#include "nterr.h" extern int DEBUGLEVEL; extern pstring global_myname; -- cgit From 565cc66e6ae93aa44305419298cd5973e57529fc Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 30 Apr 2000 14:27:39 +0000 Subject: fix handing of ascii_to_unistr (This used to be commit 385b1844b60beeb9db5f412a452816444e25cb83) --- source3/rpc_server/srv_spoolss_nt.c | 38 ++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 1121d5c2b1..1daa7e55da 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -561,8 +561,8 @@ static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL *u static BOOL convert_devicemode(DEVICEMODE devmode, NT_DEVICEMODE *nt_devmode) { - unistr_to_ascii(nt_devmode->devicename, devmode.devicename.buffer, 31); - unistr_to_ascii(nt_devmode->formname, devmode.formname.buffer, 31); + unistr_to_ascii(nt_devmode->devicename, (char *)devmode.devicename.buffer, 31); + unistr_to_ascii(nt_devmode->formname, (char *)devmode.formname.buffer, 31); nt_devmode->specversion=devmode.specversion; nt_devmode->driverversion=devmode.driverversion; @@ -856,7 +856,7 @@ static void spoolss_notify_server_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, p snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname); data->notify_data.data.length=strlen(temp_name); - ascii_to_unistr(data->notify_data.data.string, temp_name, sizeof(data->notify_data.data.string)-1); + ascii_to_unistr((char *)data->notify_data.data.string, temp_name, sizeof(data->notify_data.data.string)-1); } /******************************************************************* @@ -870,7 +870,7 @@ static void spoolss_notify_printer_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, ascii_to_unistr(data->notify_data.data.string, lp_servicename(snum), sizeof(data->notify_data.data.string)-1); */ data->notify_data.data.length=strlen(printer->info_2->printername); - ascii_to_unistr(data->notify_data.data.string, + ascii_to_unistr((char *)data->notify_data.data.string, printer->info_2->printername, sizeof(data->notify_data.data.string)-1); } @@ -881,7 +881,7 @@ static void spoolss_notify_printer_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, static void spoolss_notify_share_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { data->notify_data.data.length=strlen(lp_servicename(snum)); - ascii_to_unistr(data->notify_data.data.string, + ascii_to_unistr((char *)data->notify_data.data.string, lp_servicename(snum), sizeof(data->notify_data.data.string)-1); } @@ -894,7 +894,7 @@ static void spoolss_notify_port_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, pri /* even if it's strange, that's consistant in all the code */ data->notify_data.data.length=strlen(lp_servicename(snum)); - ascii_to_unistr(data->notify_data.data.string, + ascii_to_unistr((char *)data->notify_data.data.string, lp_servicename(snum), sizeof(data->notify_data.data.string)-1); } @@ -907,7 +907,7 @@ static void spoolss_notify_port_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, pri static void spoolss_notify_driver_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { data->notify_data.data.length=strlen(printer->info_2->drivername); - ascii_to_unistr(data->notify_data.data.string, + ascii_to_unistr((char *)data->notify_data.data.string, printer->info_2->drivername, sizeof(data->notify_data.data.string)-1); } @@ -918,7 +918,7 @@ static void spoolss_notify_driver_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, p static void spoolss_notify_comment(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { data->notify_data.data.length=strlen(lp_comment(snum)); - ascii_to_unistr(data->notify_data.data.string, + ascii_to_unistr((char *)data->notify_data.data.string, lp_comment(snum), sizeof(data->notify_data.data.string)-1); } @@ -931,7 +931,7 @@ static void spoolss_notify_comment(int snum, SPOOL_NOTIFY_INFO_DATA *data, print static void spoolss_notify_location(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { data->notify_data.data.length=strlen(printer->info_2->location); - ascii_to_unistr(data->notify_data.data.string, + ascii_to_unistr((char *)data->notify_data.data.string, printer->info_2->location, sizeof(data->notify_data.data.string)-1); } @@ -952,7 +952,7 @@ static void spoolss_notify_devmode(int snum, SPOOL_NOTIFY_INFO_DATA *data, print static void spoolss_notify_sepfile(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { data->notify_data.data.length=strlen(printer->info_2->sepfile); - ascii_to_unistr(data->notify_data.data.string, + ascii_to_unistr((char *)data->notify_data.data.string, printer->info_2->sepfile, sizeof(data->notify_data.data.string)-1); } @@ -964,7 +964,7 @@ static void spoolss_notify_sepfile(int snum, SPOOL_NOTIFY_INFO_DATA *data, print static void spoolss_notify_print_processor(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { data->notify_data.data.length=strlen(printer->info_2->printprocessor); - ascii_to_unistr(data->notify_data.data.string, + ascii_to_unistr((char *)data->notify_data.data.string, printer->info_2->printprocessor, sizeof(data->notify_data.data.string)-1); } @@ -976,7 +976,7 @@ static void spoolss_notify_print_processor(int snum, SPOOL_NOTIFY_INFO_DATA *dat static void spoolss_notify_parameters(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { data->notify_data.data.length=strlen(printer->info_2->parameters); - ascii_to_unistr(data->notify_data.data.string, + ascii_to_unistr((char *)data->notify_data.data.string, printer->info_2->parameters, sizeof(data->notify_data.data.string)-1); } @@ -988,7 +988,7 @@ static void spoolss_notify_parameters(int snum, SPOOL_NOTIFY_INFO_DATA *data, pr static void spoolss_notify_datatype(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { data->notify_data.data.length=strlen(printer->info_2->datatype); - ascii_to_unistr(data->notify_data.data.string, + ascii_to_unistr((char *)data->notify_data.data.string, printer->info_2->datatype, sizeof(data->notify_data.data.string)-1); } @@ -1091,7 +1091,7 @@ static void spoolss_notify_average_ppm(int snum, SPOOL_NOTIFY_INFO_DATA *data, p static void spoolss_notify_username(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { data->notify_data.data.length=strlen(queue->user); - ascii_to_unistr(data->notify_data.data.string, queue->user, sizeof(data->notify_data.data.string)-1); + ascii_to_unistr((char *)data->notify_data.data.string, queue->user, sizeof(data->notify_data.data.string)-1); } /******************************************************************* @@ -1108,7 +1108,7 @@ static void spoolss_notify_job_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, pr static void spoolss_notify_job_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { data->notify_data.data.length=strlen(queue->file); - ascii_to_unistr(data->notify_data.data.string, queue->file, sizeof(data->notify_data.data.string)-1); + ascii_to_unistr((char *)data->notify_data.data.string, queue->file, sizeof(data->notify_data.data.string)-1); } /******************************************************************* @@ -1132,7 +1132,7 @@ static void spoolss_notify_job_status_string(int snum, SPOOL_NOTIFY_INFO_DATA *d break; } data->notify_data.data.length=strlen(p); - ascii_to_unistr(data->notify_data.data.string, p, sizeof(data->notify_data.data.string)-1); + ascii_to_unistr((char *)data->notify_data.data.string, p, sizeof(data->notify_data.data.string)-1); } /******************************************************************* @@ -2431,7 +2431,7 @@ static void init_unistr_array(uint16 **uni_array, char **char_array, char *where DEBUG(0,("init_unistr_array: Realloc error\n" )); return; } - ascii_to_unistr( *uni_array+j, line , strlen(line)); + ascii_to_unistr((char *)(*uni_array+j), line , 2*strlen(line)); j+=strlen(line)+1; i++; } @@ -3874,13 +3874,13 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx, * take a pause *before* coding not *during* coding */ - *out_max_value_len=in_value_len/2; + *out_max_value_len=in_value_len; if((*out_value=(uint16 *)malloc(in_value_len*sizeof(uint8))) == NULL) { free_a_printer(printer, 2); safe_free(data); return ERROR_NOT_ENOUGH_MEMORY; } - ascii_to_unistr(*out_value, value, *out_max_value_len); + ascii_to_unistr((char *)*out_value, value, *out_max_value_len); *out_value_len=2*(1+strlen(value)); *out_type=type; -- cgit From 693ffb8466ada58ecc59fde754ba79fc6f51528d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 2 May 2000 02:23:41 +0000 Subject: Added sys_fork() and sys_getpid() functions to stop the overhead of doing a system call every time we want to just get our pid. Jeremy. (This used to be commit 148628b616b5c29ba6340d65fc3ddbcabba6e67a) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 1daa7e55da..2680c3a553 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -135,7 +135,7 @@ static void create_printer_hnd(POLICY_HND *hnd) SIVAL(hnd->data, 4 , prt_hnd_low ); /* second bit is incrementing */ SIVAL(hnd->data, 8 , prt_hnd_high); /* second bit is incrementing */ SIVAL(hnd->data, 12, time(NULL)); /* something random */ - SIVAL(hnd->data, 16, getpid()); /* something more random */ + SIVAL(hnd->data, 16, sys_getpid()); /* something more random */ } /**************************************************************************** -- cgit From f6dec4d551ba1054f9e936a973c2d9f90f84374f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 2 May 2000 07:10:26 +0000 Subject: fixed a memory leak (This used to be commit d4743ec0be419565c805fbc5ba2680c6ad5fe36d) --- source3/rpc_server/srv_spoolss_nt.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 2680c3a553..6a0323f850 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3710,6 +3710,8 @@ uint32 _spoolss_addprinterdriver( const UNISTR2 *server_name, if (add_a_printer_driver(driver, level)!=0) return ERROR_ACCESS_DENIED; + safe_free(driver.info_3); + return NT_STATUS_NO_PROBLEMO; } -- cgit From 59fa2dbe2cb18762e14a86045c7ad403205a3841 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 2 May 2000 15:31:55 +0000 Subject: added support for deleting printers into the spoolss system (This used to be commit e72a5718537b84409fc20ff21951b1d1ab24d97f) --- source3/rpc_server/srv_spoolss_nt.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 6a0323f850..43f0c94987 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -200,6 +200,27 @@ static BOOL close_printer_handle(POLICY_HND *hnd) return True; } +/**************************************************************************** + delete a printer given a handle +****************************************************************************/ +static BOOL delete_printer_handle(POLICY_HND *hnd) +{ + Printer_entry *Printer = find_printer_index_by_hnd(hnd); + + if (!OPEN_HANDLE(Printer)) + { + DEBUG(3,("Error closing printer handle\n")); + return False; + } + + if (del_a_printer(Printer->dev.printername) != 0) { + DEBUG(3,("Error deleting printer %s\n", Printer->dev.printername)); + return False; + } + + return True; +} + /**************************************************************************** return the snum of a printer corresponding to an handle ****************************************************************************/ @@ -622,6 +643,17 @@ uint32 _spoolss_closeprinter(POLICY_HND *handle) return NT_STATUS_NO_PROBLEMO; } +/******************************************************************** + * api_spoolss_deleteprinter + ********************************************************************/ +uint32 _spoolss_deleteprinter(POLICY_HND *handle) +{ + if (!delete_printer_handle(handle)) + return ERROR_INVALID_HANDLE; + + return NT_STATUS_NO_PROBLEMO; +} + /******************************************************************** GetPrinterData on a printer server Handle. ********************************************************************/ -- cgit From 612738a9e14b6fb6a2687993d6416bbe6c3ea94d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 10 May 2000 22:47:09 +0000 Subject: lib/util_unistr.c: libsmb/clilist.c: rpc_server/srv_spoolss_nt.c: smbd/trans2.c: Changed unistr_to_ascii to unistr_to_dos - do codepage conversion. msdfs/msdfs.c: Removed stub unistr_to_dos. libsmb/pwd_cache.c: Removed obfuscation functions as they don't do anything and don't add any security. Jeremy. (This used to be commit 1ed146467e764e6a81d8f78cd58fb5765ebf5d21) --- source3/rpc_server/srv_spoolss_nt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 43f0c94987..34e459d72b 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -582,8 +582,8 @@ static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL *u static BOOL convert_devicemode(DEVICEMODE devmode, NT_DEVICEMODE *nt_devmode) { - unistr_to_ascii(nt_devmode->devicename, (char *)devmode.devicename.buffer, 31); - unistr_to_ascii(nt_devmode->formname, (char *)devmode.formname.buffer, 31); + unistr_to_dos(nt_devmode->devicename, (char *)devmode.devicename.buffer, 31); + unistr_to_dos(nt_devmode->formname, (char *)devmode.formname.buffer, 31); nt_devmode->specversion=devmode.specversion; nt_devmode->driverversion=devmode.driverversion; -- cgit From 0806cf75ff96dee6715610bd61e21cde08fa1c61 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 12 May 2000 14:28:46 +0000 Subject: added spool_io_printer_driver_info_level_6() thsi function and the associated header structure were autogenerated using a little awk based code geerator I wroe ths evening. I'll commit that next ... (This used to be commit 974813f0d4afb6c14ed27c48ab24b19932557f9f) --- source3/rpc_server/srv_spoolss_nt.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 34e459d72b..95d7b7fdff 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -571,7 +571,11 @@ static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL *u switch (level) { case 3: printer->info_3=NULL; - uni_2_asc_printer_driver_3(uni->info_3, &(printer->info_3)); + uni_2_asc_printer_driver_3(uni->info_3, &(printer->info_3)); + break; + case 6: + printer->info_6=NULL; + uni_2_asc_printer_driver_6(uni->info_6, &(printer->info_6)); break; default: break; @@ -2378,6 +2382,9 @@ static void construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, NT_PRINTER_INFO_LEVEL printer; NT_PRINTER_DRIVER_INFO_LEVEL driver; + ZERO_STRUCT(driver); + ZERO_STRUCT(printer); + get_a_printer(&printer, 2, lp_servicename(snum) ); get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture); @@ -2431,7 +2438,10 @@ static void construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fstri { NT_PRINTER_INFO_LEVEL printer; NT_PRINTER_DRIVER_INFO_LEVEL driver; - + + ZERO_STRUCT(printer); + ZERO_STRUCT(driver); + get_a_printer(&printer, 2, lp_servicename(snum) ); get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture); @@ -2525,7 +2535,10 @@ static void construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, { NT_PRINTER_INFO_LEVEL printer; NT_PRINTER_DRIVER_INFO_LEVEL driver; - + + ZERO_STRUCT(printer); + ZERO_STRUCT(driver); + get_a_printer(&printer, 2, lp_servicename(snum) ); get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture); @@ -3245,6 +3258,8 @@ static uint32 enumprinterdrivers_level1(fstring *list, fstring servername, fstri NT_PRINTER_DRIVER_INFO_LEVEL driver; DRIVER_INFO_1 *driver_info_1=NULL; + ZERO_STRUCT(driver); + if((driver_info_1=(DRIVER_INFO_1 *)malloc(*returned * sizeof(DRIVER_INFO_1))) == NULL) return ERROR_NOT_ENOUGH_MEMORY; @@ -3292,6 +3307,8 @@ static uint32 enumprinterdrivers_level2(fstring *list, fstring servername, fstri NT_PRINTER_DRIVER_INFO_LEVEL driver; DRIVER_INFO_2 *driver_info_2=NULL; + ZERO_STRUCT(driver); + if (*returned > 0 && !(driver_info_2=(DRIVER_INFO_2 *)malloc(*returned * sizeof(DRIVER_INFO_2)))) return ERROR_NOT_ENOUGH_MEMORY; @@ -3340,6 +3357,8 @@ static uint32 enumprinterdrivers_level3(fstring *list, fstring servername, fstri NT_PRINTER_DRIVER_INFO_LEVEL driver; DRIVER_INFO_3 *driver_info_3=NULL; + ZERO_STRUCT(driver); + if((driver_info_3=(DRIVER_INFO_3 *)malloc((*returned)*sizeof(DRIVER_INFO_3))) == NULL) return ERROR_NOT_ENOUGH_MEMORY; @@ -3736,6 +3755,8 @@ uint32 _spoolss_addprinterdriver( const UNISTR2 *server_name, const SPOOL_PRINTER_DRIVER_INFO_LEVEL *info) { NT_PRINTER_DRIVER_INFO_LEVEL driver; + + ZERO_STRUCT(driver); convert_printer_driver_info(info, &driver, level); @@ -3743,6 +3764,7 @@ uint32 _spoolss_addprinterdriver( const UNISTR2 *server_name, return ERROR_ACCESS_DENIED; safe_free(driver.info_3); + safe_free(driver.info_6); return NT_STATUS_NO_PROBLEMO; } @@ -3775,7 +3797,7 @@ static uint32 getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen fill_driverdir_1(info, chaine); - *needed += spoolss_size_driverdir_info_1(info); + *needed += spoolss_size_driverdir_info_1(info); if (!alloc_buffer_size(buffer, *needed)) { safe_free(info); -- cgit From 69519df0f6a6d9c0d2b88cd092fa58421b13f4a3 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 22 May 2000 20:04:50 +0000 Subject: Modify NT driver heirarchy to fix HP bug with duplicate printer driver filenames :-). Jeremy. (This used to be commit adb6ad812a4d897ee0c0712cc06d1ff8553fa093) --- source3/rpc_server/srv_spoolss_nt.c | 68 +++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 10 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 95d7b7fdff..da808f1b57 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -889,7 +889,7 @@ static void spoolss_notify_server_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, p { pstring temp_name; - snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname); + snprintf(temp_name, sizeof(temp_name)-1, "\\\\%s", global_myname); data->notify_data.data.length=strlen(temp_name); ascii_to_unistr((char *)data->notify_data.data.string, temp_name, sizeof(data->notify_data.data.string)-1); @@ -2410,7 +2410,7 @@ static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, get_short_archi(short_archi,architecture); - snprintf(where,sizeof(where)-1,"\\\\%s\\print$\\%s\\", servername, short_archi); + snprintf(where,sizeof(where)-1,"\\\\%s\\print$\\%s\\%s\\", servername, short_archi, driver.info_3->name); info->version=driver.info_3->cversion; @@ -2500,8 +2500,8 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, get_short_archi(short_archi, architecture); - snprintf(where,sizeof(where)-1,"\\\\%s\\print$\\%s\\", servername, short_archi); - + snprintf(where,sizeof(where)-1,"\\\\%s\\print$\\%s\\%s\\", servername, short_archi, driver.info_3->name); + info->version=driver.info_3->cversion; init_unistr( &(info->name), driver.info_3->name ); @@ -3747,6 +3747,48 @@ uint32 _spoolss_addprinterex( const UNISTR2 *uni_srv_name, uint32 level, } } +/**************************************************************************** + Modify internal driver heirarchy. +****************************************************************************/ + +static uint32 modify_driver_heirarchy(NT_PRINTER_DRIVER_INFO_LEVEL *driver, uint32 level) +{ + pstring path_old; + pstring path_new; + pstring short_archi; + int snum = snum = find_service("print$"); + char *model = NULL; + + *short_archi = '\0'; + switch (level) { + case 3: + get_short_archi(short_archi, driver->info_3->environment); + model = driver->info_3->name; + break; + case 6: + get_short_archi(short_archi, driver->info_6->environment); + model = driver->info_6->name; + break; + default: + DEBUG(0,("modify_driver_heirarchy: unknown info level (%d)\n", level)); + return ERROR_INVALID_LEVEL; + break; + } + + slprintf(path_old, sizeof(path_old)-1, "%s/%s/TMP_%u", lp_pathname(snum), short_archi, + (unsigned int)sys_getpid()); + slprintf(path_new, sizeof(path_new)-1, "%s/%s/%s", lp_pathname(snum), short_archi, model); + + DEBUG(10,("_spoolss_addprinterdriver: old_path=%s, new_path=%s\n", + path_old, path_new )); + if (dos_rename(path_old, path_new) == -1) { + DEBUG(0,("modify_driver_heirarchy: rename failed (%s)\n", strerror(errno) )); + /* We need to clean up here.... - how ? */ + return ERROR_ACCESS_DENIED; /* We need a generic mapping from NT errors here... */ + } + + return NT_STATUS_NO_PROBLEMO; +} /**************************************************************************** ****************************************************************************/ @@ -3755,7 +3797,7 @@ uint32 _spoolss_addprinterdriver( const UNISTR2 *server_name, const SPOOL_PRINTER_DRIVER_INFO_LEVEL *info) { NT_PRINTER_DRIVER_INFO_LEVEL driver; - + uint32 err; ZERO_STRUCT(driver); convert_printer_driver_info(info, &driver, level); @@ -3763,6 +3805,12 @@ uint32 _spoolss_addprinterdriver( const UNISTR2 *server_name, if (add_a_printer_driver(driver, level)!=0) return ERROR_ACCESS_DENIED; + if ((err = modify_driver_heirarchy(&driver, level)) != 0) { + safe_free(driver.info_3); + safe_free(driver.info_6); + return err; + } + safe_free(driver.info_3); safe_free(driver.info_6); @@ -3780,7 +3828,7 @@ static void fill_driverdir_1(DRIVER_DIRECTORY_1 *info, char *name) ****************************************************************************/ static uint32 getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environment, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { - pstring chaine; + pstring path; pstring long_archi; pstring short_archi; DRIVER_DIRECTORY_1 *info=NULL; @@ -3791,11 +3839,11 @@ static uint32 getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)-1); get_short_archi(short_archi, long_archi); - slprintf(chaine, sizeof(chaine)-1, "\\\\%s\\print$\\%s", global_myname, short_archi); - - DEBUG(4,("printer driver directory: [%s]\n", chaine)); + slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s\\TMP_%u", global_myname, short_archi, + (unsigned int)sys_getpid()); + DEBUG(4,("printer driver directory: [%s]\n", path)); - fill_driverdir_1(info, chaine); + fill_driverdir_1(info, path); *needed += spoolss_size_driverdir_info_1(info); -- cgit From 722c86a38f72fb8b114a1d89aed23f262d00b6c6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 24 May 2000 06:34:47 +0000 Subject: a fairly big change in spoolss. got rid of the forms, drivers and printers files in the nt drivers directory and instead use a single tdb note that this is _not_ all finished. (This used to be commit 537cd6dff057df481fb208121ce4396fc76c2a06) --- source3/rpc_server/srv_spoolss_nt.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index da808f1b57..dc24c3bc31 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2456,7 +2456,7 @@ static void construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fstri * * convert an array of ascii string to a UNICODE string ********************************************************************/ -static void init_unistr_array(uint16 **uni_array, char **char_array, char *where) +static void init_unistr_array(uint16 **uni_array, fstring *char_array, char *where) { int i=0; int j=0; @@ -2466,7 +2466,8 @@ static void init_unistr_array(uint16 **uni_array, char **char_array, char *where DEBUG(6,("init_unistr_array\n")); *uni_array=NULL; - for (v=char_array[i]; *v!='\0'; v=char_array[i]) { + while (1) { + v = char_array[i]; snprintf(line, sizeof(line)-1, "%s%s", where, v); DEBUGADD(6,("%d:%s:%d\n", i, line, strlen(line))); if((*uni_array=Realloc(*uni_array, (j+strlen(line)+2)*sizeof(uint16))) == NULL) { @@ -2476,9 +2477,12 @@ static void init_unistr_array(uint16 **uni_array, char **char_array, char *where ascii_to_unistr((char *)(*uni_array+j), line , 2*strlen(line)); j+=strlen(line)+1; i++; + if (strlen(v) == 0) break; } - (*uni_array)[j]=0x0000; + if (*uni_array) { + (*uni_array)[j]=0x0000; + } DEBUGADD(6,("last one:done\n")); } @@ -2614,27 +2618,21 @@ static uint32 getprinterdriver2_level2(fstring servername, fstring architecture, ****************************************************************************/ static uint32 getprinterdriver2_level3(fstring servername, fstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { - DRIVER_INFO_3 *info=NULL; - - if((info=(DRIVER_INFO_3 *)malloc(sizeof(DRIVER_INFO_3)))==NULL) - return ERROR_NOT_ENOUGH_MEMORY; - - construct_printer_driver_info_3(info, snum, servername, architecture); + DRIVER_INFO_3 info; + + ZERO_STRUCT(info); + + construct_printer_driver_info_3(&info, snum, servername, architecture); /* check the required size. */ - *needed += spoolss_size_printer_driver_info_3(info); + *needed += spoolss_size_printer_driver_info_3(&info); if (!alloc_buffer_size(buffer, *needed)) { - safe_free(info); return ERROR_INSUFFICIENT_BUFFER; } /* fill the buffer with the structures */ - new_smb_io_printer_driver_info_3("", buffer, info, 0); - - /* clear memory */ - safe_free(info->dependentfiles); - safe_free(info); + new_smb_io_printer_driver_info_3("", buffer, &info, 0); if (*needed > offered) return ERROR_INSUFFICIENT_BUFFER; -- cgit From 9646e6e1ba5e44b3c4349e85e08ab9f73372a4d5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 26 May 2000 20:54:46 +0000 Subject: Compile time warning fixes and a time_t -> uint32 conversion fix. Jeremy. (This used to be commit 80a0079b2f993159ef35b02ba5c70ce9d8096879) --- source3/rpc_server/srv_spoolss_nt.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index dc24c3bc31..7c56a5f640 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1,3 +1,4 @@ +#define OLD_NTDOMAIN 1 /* * Unix SMB/Netbios implementation. * Version 1.9. @@ -1634,6 +1635,7 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, fstring counter_printer_0 *session_counter; uint32 global_counter; struct tm *t; + time_t setup_time; print_queue_struct *queue=NULL; print_status_struct status; @@ -1684,7 +1686,8 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, fstring printer->total_jobs = 0; printer->total_bytes = 0; - t=gmtime(&ntprinter.info_2->setuptime); + t=gmtime(&setup_time); + ntprinter.info_2->setuptime = (uint32)setup_time; /* FIXME !! */ printer->year = t->tm_year+1900; printer->month = t->tm_mon+1; @@ -3754,7 +3757,7 @@ static uint32 modify_driver_heirarchy(NT_PRINTER_DRIVER_INFO_LEVEL *driver, uint pstring path_old; pstring path_new; pstring short_archi; - int snum = snum = find_service("print$"); + int snum = find_service("print$"); char *model = NULL; *short_archi = '\0'; @@ -4437,4 +4440,5 @@ uint32 _spoolss_getjob( POLICY_HND *handle, uint32 jobid, uint32 level, break; } } +#undef OLD_NTDOMAIN -- cgit From a65dead017b3f52d7c2f753ce8ca876371183629 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Sat, 27 May 2000 01:26:34 +0000 Subject: security descs in spoolss. needs parse_sec.c nttrans.c broken. (This used to be commit f9f2a04fdb7b2af1cfe5bf26ec6f0d955ea948b9) --- source3/rpc_server/srv_spoolss_nt.c | 80 ++++++++++++++++++++++++++++++++++--- 1 file changed, 75 insertions(+), 5 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 7c56a5f640..90a3a3e632 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -587,8 +587,8 @@ static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL *u static BOOL convert_devicemode(DEVICEMODE devmode, NT_DEVICEMODE *nt_devmode) { - unistr_to_dos(nt_devmode->devicename, (char *)devmode.devicename.buffer, 31); - unistr_to_dos(nt_devmode->formname, (char *)devmode.formname.buffer, 31); + unistr_to_ascii(nt_devmode->devicename, (char *)devmode.devicename.buffer, 31); + unistr_to_ascii(nt_devmode->formname, (char *)devmode.formname.buffer, 31); nt_devmode->specversion=devmode.specversion; nt_devmode->driverversion=devmode.driverversion; @@ -1892,6 +1892,17 @@ static BOOL construct_printer_info_2(fstring servername, PRINTER_INFO_2 *printer printer->devmode=devmode; + if (ntprinter.info_2->secdesc.len != 0) + { + /* steal the printer info sec_desc structure. [badly done]. */ + printer->secdesc = ntprinter.info_2->secdesc.sec; + ZERO_STRUCT(ntprinter.info_2->secdesc); + } + else + { + printer->secdesc = NULL; + } + safe_free(queue); free_a_printer(ntprinter, 2); return True; @@ -1903,6 +1914,31 @@ static BOOL construct_printer_info_2(fstring servername, PRINTER_INFO_2 *printer return False; } +/******************************************************************** + * construct_printer_info_3 + * fill a printer_info_3 struct + ********************************************************************/ +static BOOL construct_printer_info_3(fstring servername, + PRINTER_INFO_3 *printer, int snum) +{ + NT_PRINTER_INFO_LEVEL ntprinter; + + if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0 ) + return False; + + printer->flags = 4; /* no idea, yet. see MSDN. */ + if (ntprinter.info_2->secdesc.len != 0) + { + /* steal the printer info sec_desc structure. [badly done]. */ + printer->sec = *ntprinter.info_2->secdesc.sec; + safe_free(ntprinter.info_2->secdesc.sec); + ZERO_STRUCT(ntprinter.info_2->secdesc); + } + + free_a_printer(ntprinter, 2); + return True; +} + /******************************************************************** Spoolss_enumprinters. ********************************************************************/ @@ -2337,6 +2373,41 @@ static uint32 getprinter_level_2(fstring servername, int snum, NEW_BUFFER *buffe return NT_STATUS_NO_PROBLEMO; } +/**************************************************************************** +****************************************************************************/ +static uint32 getprinter_level_3(fstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +{ + PRINTER_INFO_3 *printer=NULL; + fstring temp; + + if((printer=(PRINTER_INFO_3*)malloc(sizeof(PRINTER_INFO_3)))==NULL) + return ERROR_NOT_ENOUGH_MEMORY; + + fstrcpy(temp, "\\\\"); + fstrcat(temp, servername); + construct_printer_info_3(temp, printer, snum); + + /* check the required size. */ + *needed += spoolss_size_printer_info_3(printer); + + if (!alloc_buffer_size(buffer, *needed)) { + safe_free(printer); + return ERROR_INSUFFICIENT_BUFFER; + } + + /* fill the buffer with the structures */ + new_smb_io_printer_info_3("", buffer, printer, 0); + + /* clear memory */ + free_sec_desc(&printer->sec); + + if (*needed > offered) { + return ERROR_INSUFFICIENT_BUFFER; + } + else + return NT_STATUS_NO_PROBLEMO; +} + /**************************************************************************** ****************************************************************************/ uint32 _spoolss_getprinter(POLICY_HND *handle, uint32 level, @@ -2355,13 +2426,12 @@ uint32 _spoolss_getprinter(POLICY_HND *handle, uint32 level, switch (level) { case 0: return getprinter_level_0(servername, snum, buffer, offered, needed); - break; case 1: return getprinter_level_1(servername,snum, buffer, offered, needed); - break; case 2: return getprinter_level_2(servername,snum, buffer, offered, needed); - break; + case 3: + return getprinter_level_3(servername,snum, buffer, offered, needed); default: return ERROR_INVALID_LEVEL; break; -- cgit From 682cccd8af4008b508328672009a5bfc1344f55d Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Sat, 27 May 2000 02:05:15 +0000 Subject: unistr_to_dos not unistr_to_ascii (This used to be commit f46c4fe876a0cabe7044ca30c17e6c217d618635) --- source3/rpc_server/srv_spoolss_nt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 90a3a3e632..f974311c71 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -587,8 +587,8 @@ static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL *u static BOOL convert_devicemode(DEVICEMODE devmode, NT_DEVICEMODE *nt_devmode) { - unistr_to_ascii(nt_devmode->devicename, (char *)devmode.devicename.buffer, 31); - unistr_to_ascii(nt_devmode->formname, (char *)devmode.formname.buffer, 31); + unistr_to_dos(nt_devmode->devicename, (char *)devmode.devicename.buffer, 31); + unistr_to_dos(nt_devmode->formname, (char *)devmode.formname.buffer, 31); nt_devmode->specversion=devmode.specversion; nt_devmode->driverversion=devmode.driverversion; -- cgit From afab6492e1297737366573cdd9d1483320c30b3f Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Sat, 27 May 2000 03:12:06 +0000 Subject: uninitialised variable "list" (This used to be commit bf33b10a43a42c3ec5dbfdc713869c4aeb452aef) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index f974311c71..29294f1783 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3479,7 +3479,7 @@ uint32 _spoolss_enumprinterdrivers( UNISTR2 *name, UNISTR2 *environment, uint32 uint32 *needed, uint32 *returned) { int i; - fstring *list; + fstring *list = NULL; fstring servername; fstring architecture; -- cgit From 5f7c40f6d02df70dd3a92d5658f79b668e0ed5df Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 27 May 2000 09:53:11 +0000 Subject: getting and setting security descriptors on printers now works this needed some fixes in tdb_unpack(). Tim, you'll need to update (This used to be commit 9422719ab4c35e4ce3199b62dd632433bf391283) --- source3/rpc_server/srv_spoolss_nt.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 29294f1783..01535b2933 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2620,9 +2620,6 @@ static void construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture); fill_printer_driver_info_3(info, driver, servername, architecture); - - free_a_printer_driver(driver, 3); - free_a_printer(printer, 2); } /**************************************************************************** @@ -2929,6 +2926,23 @@ static uint32 control_printer(const POLICY_HND *handle, uint32 command) return ERROR_INVALID_FUNCTION; } +/******************************************************************** + * called by spoolss_api_setprinter + * when updating a printer description + ********************************************************************/ +static uint32 update_printer_sec(const POLICY_HND *handle, uint32 level, + const SPOOL_PRINTER_INFO_LEVEL *info, + const SEC_DESC_BUF *secdesc_ctr) +{ + Printer_entry *Printer = find_printer_index_by_hnd(handle); + + if (!OPEN_HANDLE(Printer)) + return ERROR_INVALID_HANDLE; + + return nt_printing_setsec(Printer->dev.printername, secdesc_ctr); +} + + /******************************************************************** * called by spoolss_api_setprinter * when updating a printer description @@ -3002,6 +3016,7 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, uint32 _spoolss_setprinter(const POLICY_HND *handle, uint32 level, const SPOOL_PRINTER_INFO_LEVEL *info, const DEVMODE_CTR devmode_ctr, + const SEC_DESC_BUF *secdesc_ctr, uint32 command) { Printer_entry *Printer = find_printer_index_by_hnd(handle); @@ -3017,6 +3032,9 @@ uint32 _spoolss_setprinter(const POLICY_HND *handle, uint32 level, case 2: return update_printer(handle, level, info, devmode_ctr.devmode); break; + case 3: + return update_printer_sec(handle, level, info, secdesc_ctr); + break; default: return ERROR_INVALID_LEVEL; break; -- cgit From b38aa95bc9becb89fa1b966c7d6ecd91e3d47a99 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Sun, 28 May 2000 21:01:14 +0000 Subject: moved notif_y_table struct to spoolss_nt.c only used there. #ifdef'd driver-code out with define RELIES_ON_SMBD_SPECIFIC_CODE because spoolssd doesn't link with smbd/*.c (find_service("print$") is not possible). (This used to be commit 726c359d1d9f1fc8227ca920c888d2f040170e0b) --- source3/rpc_server/srv_spoolss_nt.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 01535b2933..ba122e04f8 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -25,6 +25,8 @@ #include "includes.h" +#define RELIES_ON_SMBD_FUNCTIONS_LINKED_INTO_SPOOLSSD + extern int DEBUGLEVEL; extern pstring global_myname; @@ -168,7 +170,7 @@ static Printer_entry *find_printer_index_by_hnd(const POLICY_HND *hnd) ****************************************************************************/ static void clear_handle(POLICY_HND *hnd) { - memset(hnd->data, 0, POLICY_HND_SIZE); + ZERO_STRUCTP(hnd); } /**************************************************************************** @@ -1198,6 +1200,17 @@ static void spoolss_notify_job_position(int snum, SPOOL_NOTIFY_INFO_DATA *data, #define END 65535 +struct s_notify_info_data_table +{ + uint16 type; + uint16 field; + char *name; + uint32 size; + void (*fn) (int snum, SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer); +}; + struct s_notify_info_data_table notify_info_data_table[] = { { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SERVER_NAME, "PRINTER_NOTIFY_SERVER_NAME", POINTER, spoolss_notify_server_name }, @@ -3840,11 +3853,13 @@ uint32 _spoolss_addprinterex( const UNISTR2 *uni_srv_name, uint32 level, Modify internal driver heirarchy. ****************************************************************************/ +#if RELIES_ON_SMBD_FUNCTIONS_LINKED_INTO_SPOOLSSD static uint32 modify_driver_heirarchy(NT_PRINTER_DRIVER_INFO_LEVEL *driver, uint32 level) { pstring path_old; pstring path_new; pstring short_archi; + /* find_service is an smbd-specific function call */ int snum = find_service("print$"); char *model = NULL; @@ -3878,6 +3893,7 @@ static uint32 modify_driver_heirarchy(NT_PRINTER_DRIVER_INFO_LEVEL *driver, uint return NT_STATUS_NO_PROBLEMO; } +#endif /**************************************************************************** ****************************************************************************/ @@ -3894,11 +3910,13 @@ uint32 _spoolss_addprinterdriver( const UNISTR2 *server_name, if (add_a_printer_driver(driver, level)!=0) return ERROR_ACCESS_DENIED; +#if RELIES_ON_SMBD_FUNCTIONS_LINKED_INTO_SPOOLSSD if ((err = modify_driver_heirarchy(&driver, level)) != 0) { safe_free(driver.info_3); safe_free(driver.info_6); return err; } +#endif safe_free(driver.info_3); safe_free(driver.info_6); @@ -3928,8 +3946,13 @@ static uint32 getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)-1); get_short_archi(short_archi, long_archi); +#if RELIES_ON_SMBD_FUNCTIONS_LINKED_INTO_SPOOLSSD slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s\\TMP_%u", global_myname, short_archi, (unsigned int)sys_getpid()); +#else + slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", + global_myname, short_archi); +#endif DEBUG(4,("printer driver directory: [%s]\n", path)); fill_driverdir_1(info, path); -- cgit From 4a0635cd6df183b0093a672616065fb44cdd2e0c Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Sun, 28 May 2000 21:21:07 +0000 Subject: #ifdef not #if (This used to be commit f0229102fe337213cd53fcb0a3d7e2ba786470b9) --- source3/rpc_server/srv_spoolss_nt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index ba122e04f8..25d8f63aef 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3853,7 +3853,7 @@ uint32 _spoolss_addprinterex( const UNISTR2 *uni_srv_name, uint32 level, Modify internal driver heirarchy. ****************************************************************************/ -#if RELIES_ON_SMBD_FUNCTIONS_LINKED_INTO_SPOOLSSD +#ifdef RELIES_ON_SMBD_FUNCTIONS_LINKED_INTO_SPOOLSSD static uint32 modify_driver_heirarchy(NT_PRINTER_DRIVER_INFO_LEVEL *driver, uint32 level) { pstring path_old; @@ -3910,7 +3910,7 @@ uint32 _spoolss_addprinterdriver( const UNISTR2 *server_name, if (add_a_printer_driver(driver, level)!=0) return ERROR_ACCESS_DENIED; -#if RELIES_ON_SMBD_FUNCTIONS_LINKED_INTO_SPOOLSSD +#ifdef RELIES_ON_SMBD_FUNCTIONS_LINKED_INTO_SPOOLSSD if ((err = modify_driver_heirarchy(&driver, level)) != 0) { safe_free(driver.info_3); safe_free(driver.info_6); @@ -3946,7 +3946,7 @@ static uint32 getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)-1); get_short_archi(short_archi, long_archi); -#if RELIES_ON_SMBD_FUNCTIONS_LINKED_INTO_SPOOLSSD +#ifdef RELIES_ON_SMBD_FUNCTIONS_LINKED_INTO_SPOOLSSD slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s\\TMP_%u", global_myname, short_archi, (unsigned int)sys_getpid()); #else -- cgit From 38b32fb97f5a91f09a6e41b6c14aafb510bbbe6a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 28 May 2000 23:00:23 +0000 Subject: don't free a driver structure from the stack! (This used to be commit d241f1dcaf612881a428dd578b97383d02a4d3c3) --- source3/rpc_server/srv_spoolss_nt.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 25d8f63aef..fbf5bc88bf 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3406,19 +3406,21 @@ static uint32 enumprinterdrivers_level1(fstring *list, fstring servername, fstri static uint32 enumprinterdrivers_level2(fstring *list, fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int i; - NT_PRINTER_DRIVER_INFO_LEVEL driver; DRIVER_INFO_2 *driver_info_2=NULL; - ZERO_STRUCT(driver); - if (*returned > 0 && !(driver_info_2=(DRIVER_INFO_2 *)malloc(*returned * sizeof(DRIVER_INFO_2)))) return ERROR_NOT_ENOUGH_MEMORY; for (i=0; i<*returned; i++) { - get_a_printer_driver(&driver, 3, list[i], architecture); + NT_PRINTER_DRIVER_INFO_LEVEL driver; + ZERO_STRUCT(driver); + if (get_a_printer_driver(&driver, 3, list[i], architecture) + != 0) { + *returned = i; + break; + } fill_printer_driver_info_2(&(driver_info_2[i]), driver, servername, architecture ); - free_a_printer_driver(driver, 3); } safe_free(list); -- cgit From 5b5f41d8e0e707bb4e1626f4406b2e46305a5183 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 29 May 2000 01:09:14 +0000 Subject: fixed some more crashes this introduces some memory leaks that I need to fix later (This used to be commit 2170d72d508ab8fb63a1da3024395f8fd6011cfa) --- source3/rpc_server/srv_spoolss_nt.c | 130 ++++++++++++------------------------ 1 file changed, 44 insertions(+), 86 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index fbf5bc88bf..f817300734 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -380,12 +380,10 @@ static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) printer.info_2->printername, aprinter )); if ( strlen(printer.info_2->printername) != strlen(aprinter) ) { - free_a_printer(printer, 2); continue; } if ( strncasecmp(printer.info_2->printername, aprinter, strlen(aprinter))) { - free_a_printer(printer, 2); continue; } @@ -420,12 +418,10 @@ static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) printer.info_2->printername, aprinter )); if ( strlen(lp_servicename(snum)) != strlen(aprinter) ) { - free_a_printer(printer, 2); continue; } if ( strncasecmp(lp_servicename(snum), aprinter, strlen(aprinter))) { - free_a_printer(printer, 2); continue; } @@ -442,7 +438,6 @@ static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) DEBUGADD(4,("Printer found: %s -> %s[%x]\n",printer.info_2->printername, lp_servicename(snum),snum)); ZERO_STRUCT(Printer->dev.printername); strncpy(Printer->dev.printername, lp_servicename(snum), strlen(lp_servicename(snum))); - free_a_printer(printer, 2); return True; } @@ -772,14 +767,12 @@ static BOOL getprinterdata_printer(const POLICY_HND *handle, return False; if (!get_specific_param(printer, 2, value, &idata, type, &len)) { - free_a_printer(printer, 2); return False; } DEBUG(5,("getprinterdata_printer:allocating %d\n", in_size)); if((*data = (uint8 *)malloc( in_size *sizeof(uint8) )) == NULL) { - free_a_printer(printer, 2); return False; } @@ -791,7 +784,6 @@ static BOOL getprinterdata_printer(const POLICY_HND *handle, DEBUG(5,("getprinterdata_printer:copy done\n")); - free_a_printer(printer, 2); safe_free(idata); return True; @@ -1384,7 +1376,6 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPO continue; if((info->data=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) { - free_a_printer(printer, 2); return False; } current_data=&(info->data[info->count]); @@ -1395,7 +1386,6 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPO info->count++; } - free_a_printer(printer, 2); return True; } @@ -1434,7 +1424,6 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_I continue; if((info->data=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) { - free_a_printer(printer, 2); return False; } @@ -1445,8 +1434,6 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_I info->count++; } - free_a_printer(printer, 2); - return True; } @@ -1741,7 +1728,6 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, fstring safe_free(queue); - free_a_printer(ntprinter, 2); return (True); } @@ -1769,8 +1755,6 @@ static BOOL construct_printer_info_1(fstring server, uint32 flags, PRINTER_INFO_ init_unistr(&printer->name, chaine2); init_unistr(&printer->comment, lp_comment(snum)); - free_a_printer(ntprinter, 2); - return True; } @@ -1781,7 +1765,7 @@ static BOOL construct_dev_mode(DEVICEMODE *devmode, int snum, char *servername) char adevice[32]; char aform[32]; NT_PRINTER_INFO_LEVEL printer; - NT_DEVICEMODE *ntdevmode; + NT_DEVICEMODE ntdevmode; DEBUG(7,("construct_dev_mode\n")); @@ -1791,51 +1775,52 @@ static BOOL construct_dev_mode(DEVICEMODE *devmode, int snum, char *servername) DEBUGADD(8,("getting printer characteristics\n")); get_a_printer(&printer, 2, lp_servicename(snum)); - ntdevmode=(printer.info_2)->devmode; + if (printer.info_2->devmode) { + ntdevmode = *printer.info_2->devmode; + } else { + init_devicemode(&ntdevmode); + } DEBUGADD(8,("loading DEVICEMODE\n")); snprintf(adevice, sizeof(adevice), "\\\\%s\\%s", global_myname, printer.info_2->printername); init_unistr(&(devmode->devicename), adevice); - snprintf(aform, sizeof(aform), ntdevmode->formname); + snprintf(aform, sizeof(aform), ntdevmode.formname); init_unistr(&(devmode->formname), aform); - devmode->specversion = ntdevmode->specversion; - devmode->driverversion = ntdevmode->driverversion; - devmode->size = ntdevmode->size; - devmode->driverextra = ntdevmode->driverextra; - devmode->fields = ntdevmode->fields; + devmode->specversion = ntdevmode.specversion; + devmode->driverversion = ntdevmode.driverversion; + devmode->size = ntdevmode.size; + devmode->driverextra = ntdevmode.driverextra; + devmode->fields = ntdevmode.fields; - devmode->orientation = ntdevmode->orientation; - devmode->papersize = ntdevmode->papersize; - devmode->paperlength = ntdevmode->paperlength; - devmode->paperwidth = ntdevmode->paperwidth; - devmode->scale = ntdevmode->scale; - devmode->copies = ntdevmode->copies; - devmode->defaultsource = ntdevmode->defaultsource; - devmode->printquality = ntdevmode->printquality; - devmode->color = ntdevmode->color; - devmode->duplex = ntdevmode->duplex; - devmode->yresolution = ntdevmode->yresolution; - devmode->ttoption = ntdevmode->ttoption; - devmode->collate = ntdevmode->collate; - devmode->icmmethod = ntdevmode->icmmethod; - devmode->icmintent = ntdevmode->icmintent; - devmode->mediatype = ntdevmode->mediatype; - devmode->dithertype = ntdevmode->dithertype; - - if (ntdevmode->private != NULL) + devmode->orientation = ntdevmode.orientation; + devmode->papersize = ntdevmode.papersize; + devmode->paperlength = ntdevmode.paperlength; + devmode->paperwidth = ntdevmode.paperwidth; + devmode->scale = ntdevmode.scale; + devmode->copies = ntdevmode.copies; + devmode->defaultsource = ntdevmode.defaultsource; + devmode->printquality = ntdevmode.printquality; + devmode->color = ntdevmode.color; + devmode->duplex = ntdevmode.duplex; + devmode->yresolution = ntdevmode.yresolution; + devmode->ttoption = ntdevmode.ttoption; + devmode->collate = ntdevmode.collate; + devmode->icmmethod = ntdevmode.icmmethod; + devmode->icmintent = ntdevmode.icmintent; + devmode->mediatype = ntdevmode.mediatype; + devmode->dithertype = ntdevmode.dithertype; + + if (ntdevmode.private != NULL) { if((devmode->private=(uint8 *)malloc(devmode->driverextra*sizeof(uint8))) == NULL) { - free_a_printer(printer, 2); return False; } - memcpy(devmode->private, ntdevmode->private, devmode->driverextra); + memcpy(devmode->private, ntdevmode.private, devmode->driverextra); } - free_a_printer(printer, 2); - return True; } @@ -1917,13 +1902,11 @@ static BOOL construct_printer_info_2(fstring servername, PRINTER_INFO_2 *printer } safe_free(queue); - free_a_printer(ntprinter, 2); return True; err: safe_free(queue); - free_a_printer(ntprinter, 2); return False; } @@ -1948,7 +1931,6 @@ static BOOL construct_printer_info_3(fstring servername, ZERO_STRUCT(ntprinter.info_2->secdesc); } - free_a_printer(ntprinter, 2); return True; } @@ -2475,9 +2457,6 @@ static void construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture); fill_printer_driver_info_1(info, driver, servername, architecture); - - free_a_printer_driver(driver, 3); - free_a_printer(printer, 2); } /******************************************************************** @@ -2532,9 +2511,6 @@ static void construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fstri get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture); fill_printer_driver_info_2(info, driver, servername, architecture); - - free_a_printer_driver(driver, 3); - free_a_printer(printer, 2); } /******************************************************************** @@ -2554,6 +2530,7 @@ static void init_unistr_array(uint16 **uni_array, fstring *char_array, char *whe while (1) { v = char_array[i]; + if (!v) v = ""; /* hack to handle null lists */ snprintf(line, sizeof(line)-1, "%s%s", where, v); DEBUGADD(6,("%d:%s:%d\n", i, line, strlen(line))); if((*uni_array=Realloc(*uni_array, (j+strlen(line)+2)*sizeof(uint16))) == NULL) { @@ -2945,7 +2922,7 @@ static uint32 control_printer(const POLICY_HND *handle, uint32 command) ********************************************************************/ static uint32 update_printer_sec(const POLICY_HND *handle, uint32 level, const SPOOL_PRINTER_INFO_LEVEL *info, - const SEC_DESC_BUF *secdesc_ctr) + SEC_DESC_BUF *secdesc_ctr) { Printer_entry *Printer = find_printer_index_by_hnd(handle); @@ -2966,10 +2943,8 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, { int snum; NT_PRINTER_INFO_LEVEL printer; - NT_DEVICEMODE *nt_devmode; + NT_DEVICEMODE nt_devmode; Printer_entry *Printer = find_printer_index_by_hnd(handle); - - nt_devmode=NULL; DEBUG(8,("update_printer\n")); @@ -2994,17 +2969,14 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, /* we have a valid devmode convert it and link it*/ - /* the nt_devmode memory is already alloced - * while doing the get_a_printer call - * but the devmode private part is not - * it's done by convert_devicemode - */ DEBUGADD(8,("Converting the devicemode struct\n")); - nt_devmode=printer.info_2->devmode; - - init_devicemode(nt_devmode); + if (printer.info_2->devmode) { + nt_devmode = *printer.info_2->devmode; + } else { + init_devicemode(&nt_devmode); + } - convert_devicemode(*devmode, nt_devmode); + convert_devicemode(*devmode, &nt_devmode); } else { if (printer.info_2->devmode != NULL) @@ -3013,14 +2985,10 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, } if (add_a_printer(printer, 2)!=0) { - free_a_printer(printer, 2); - /* I don't really know what to return here !!! */ return ERROR_ACCESS_DENIED; } - free_a_printer(printer, 2); - return NT_STATUS_NO_PROBLEMO; } @@ -3157,18 +3125,15 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, job_info->pagesprinted=0; if((devmode=(DEVICEMODE *)malloc(sizeof(DEVICEMODE))) == NULL) { - free_a_printer(ntprinter, 2); return False; } ZERO_STRUCTP(devmode); if(!construct_dev_mode(devmode, snum, global_myname)) { - free_a_printer(ntprinter, 2); return False; } job_info->devmode=devmode; - free_a_printer(ntprinter, 2); return (True); } @@ -3368,7 +3333,6 @@ static uint32 enumprinterdrivers_level1(fstring *list, fstring servername, fstri for (i=0; i<*returned; i++) { get_a_printer_driver(&driver, 3, list[i], architecture); fill_printer_driver_info_1(&(driver_info_1[i]), driver, servername, architecture ); - free_a_printer_driver(driver, 3); } safe_free(list); @@ -3469,7 +3433,6 @@ static uint32 enumprinterdrivers_level3(fstring *list, fstring servername, fstri for (i=0; i<*returned; i++) { get_a_printer_driver(&driver, 3, list[i], architecture); fill_printer_driver_info_3(&(driver_info_3[i]), driver, servername, architecture ); - free_a_printer_driver(driver, 3); } safe_free(list); @@ -3579,9 +3542,11 @@ uint32 _new_spoolss_enumforms( const POLICY_HND *handle, uint32 level, *numofforms = get_ntforms(&list); DEBUGADD(5,("Number of forms [%d]\n", *numofforms)); + if (*numofforms == 0) return ERROR_NO_MORE_ITEMS; + switch (level) { case 1: - if((forms_1=(FORM_1 *)malloc(*numofforms * sizeof(FORM_1))) == NULL) { + if ((forms_1=(FORM_1 *)malloc(*numofforms * sizeof(FORM_1))) == NULL) { *numofforms=0; return ERROR_NOT_ENOUGH_MEMORY; } @@ -4068,7 +4033,6 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx, DEBUG(6,("final values: [%d], [%d]\n", *out_value_len, *out_data_len)); - free_a_printer(printer, 2); return NT_STATUS_NO_PROBLEMO; } @@ -4078,7 +4042,6 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx, */ if (!get_specific_param_by_index(printer, 2, idx, value, &data, &type, &data_len)) { - free_a_printer(printer, 2); safe_free(data); return ERROR_NO_MORE_ITEMS; } @@ -4094,7 +4057,6 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx, *out_max_value_len=in_value_len; if((*out_value=(uint16 *)malloc(in_value_len*sizeof(uint8))) == NULL) { - free_a_printer(printer, 2); safe_free(data); return ERROR_NOT_ENOUGH_MEMORY; } @@ -4106,7 +4068,6 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx, /* the data is counted in bytes */ *out_max_data_len=in_data_len; if((*data_out=(uint8 *)malloc(in_data_len*sizeof(uint8))) == NULL) { - free_a_printer(printer, 2); safe_free(data); return ERROR_NOT_ENOUGH_MEMORY; } @@ -4115,7 +4076,6 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx, safe_free(data); - free_a_printer(printer, 2); return NT_STATUS_NO_PROBLEMO; } @@ -4157,8 +4117,6 @@ uint32 _spoolss_setprinterdata( const POLICY_HND *handle, else status = add_a_printer(printer, 2); - free_a_printer(printer, 2); - return status; } -- cgit From cc22d7ea29f0ccb2256a58510600e1f73d69bb6a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 1 Jun 2000 02:35:30 +0000 Subject: Changes I really don't want to lose whilst CVS is playing up. Dynamic changes to spoolss code. Jeremy. (This used to be commit 0a5e7a8f31c26fe80db5398a441a1969a8882845) --- source3/rpc_server/srv_spoolss_nt.c | 479 +++++++++++++++++++----------------- 1 file changed, 257 insertions(+), 222 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index f817300734..424e1f5e95 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -331,7 +331,7 @@ static BOOL set_printer_hnd_printertype(POLICY_HND *hnd, char *printername) static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) { Printer_entry *Printer = find_printer_index_by_hnd(hnd); - NT_PRINTER_INFO_LEVEL printer; + NT_PRINTER_INFO_LEVEL *printer = NULL; int snum; int n_services=lp_numservices(); char *aprinter; @@ -377,13 +377,15 @@ static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) continue; DEBUG(10,("set_printer_hnd_printername: printername [%s], aprinter [%s]\n", - printer.info_2->printername, aprinter )); + printer->info_2->printername, aprinter )); - if ( strlen(printer.info_2->printername) != strlen(aprinter) ) { + if ( strlen(printer->info_2->printername) != strlen(aprinter) ) { + free_a_printer(&printer, 2); continue; } - if ( strncasecmp(printer.info_2->printername, aprinter, strlen(aprinter))) { + if ( strncasecmp(printer->info_2->printername, aprinter, strlen(aprinter))) { + free_a_printer(&printer, 2); continue; } @@ -415,13 +417,15 @@ static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) continue; DEBUG(10,("set_printer_hnd_printername: printername [%s], aprinter [%s]\n", - printer.info_2->printername, aprinter )); + printer->info_2->printername, aprinter )); if ( strlen(lp_servicename(snum)) != strlen(aprinter) ) { + free_a_printer(&printer, 2); continue; } if ( strncasecmp(lp_servicename(snum), aprinter, strlen(aprinter))) { + free_a_printer(&printer, 2); continue; } @@ -435,10 +439,12 @@ static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) } snum--; - DEBUGADD(4,("Printer found: %s -> %s[%x]\n",printer.info_2->printername, lp_servicename(snum),snum)); + DEBUGADD(4,("Printer found: %s -> %s[%x]\n",printer->info_2->printername, lp_servicename(snum),snum)); ZERO_STRUCT(Printer->dev.printername); strncpy(Printer->dev.printername, lp_servicename(snum), strlen(lp_servicename(snum))); + free_a_printer(&printer, 2); + return True; } @@ -582,53 +588,51 @@ static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL *u return True; } -static BOOL convert_devicemode(DEVICEMODE devmode, NT_DEVICEMODE *nt_devmode) -{ - unistr_to_dos(nt_devmode->devicename, (char *)devmode.devicename.buffer, 31); - unistr_to_dos(nt_devmode->formname, (char *)devmode.formname.buffer, 31); - - nt_devmode->specversion=devmode.specversion; - nt_devmode->driverversion=devmode.driverversion; - nt_devmode->size=devmode.size; - nt_devmode->driverextra=devmode.driverextra; - nt_devmode->fields=devmode.fields; - nt_devmode->orientation=devmode.orientation; - nt_devmode->papersize=devmode.papersize; - nt_devmode->paperlength=devmode.paperlength; - nt_devmode->paperwidth=devmode.paperwidth; - nt_devmode->scale=devmode.scale; - nt_devmode->copies=devmode.copies; - nt_devmode->defaultsource=devmode.defaultsource; - nt_devmode->printquality=devmode.printquality; - nt_devmode->color=devmode.color; - nt_devmode->duplex=devmode.duplex; - nt_devmode->yresolution=devmode.yresolution; - nt_devmode->ttoption=devmode.ttoption; - nt_devmode->collate=devmode.collate; - - nt_devmode->logpixels=devmode.logpixels; - nt_devmode->bitsperpel=devmode.bitsperpel; - nt_devmode->pelswidth=devmode.pelswidth; - nt_devmode->pelsheight=devmode.pelsheight; - nt_devmode->displayflags=devmode.displayflags; - nt_devmode->displayfrequency=devmode.displayfrequency; - nt_devmode->icmmethod=devmode.icmmethod; - nt_devmode->icmintent=devmode.icmintent; - nt_devmode->mediatype=devmode.mediatype; - nt_devmode->dithertype=devmode.dithertype; - nt_devmode->reserved1=devmode.reserved1; - nt_devmode->reserved2=devmode.reserved2; - nt_devmode->panningwidth=devmode.panningwidth; - nt_devmode->panningheight=devmode.panningheight; - - if (nt_devmode->driverextra != 0) - { +static BOOL convert_devicemode(const DEVICEMODE *devmode, NT_DEVICEMODE *nt_devmode) +{ + unistr_to_dos(nt_devmode->devicename, (const char *)devmode->devicename.buffer, 31); + unistr_to_dos(nt_devmode->formname, (const char *)devmode->formname.buffer, 31); + + nt_devmode->specversion=devmode->specversion; + nt_devmode->driverversion=devmode->driverversion; + nt_devmode->size=devmode->size; + nt_devmode->driverextra=devmode->driverextra; + nt_devmode->fields=devmode->fields; + nt_devmode->orientation=devmode->orientation; + nt_devmode->papersize=devmode->papersize; + nt_devmode->paperlength=devmode->paperlength; + nt_devmode->paperwidth=devmode->paperwidth; + nt_devmode->scale=devmode->scale; + nt_devmode->copies=devmode->copies; + nt_devmode->defaultsource=devmode->defaultsource; + nt_devmode->printquality=devmode->printquality; + nt_devmode->color=devmode->color; + nt_devmode->duplex=devmode->duplex; + nt_devmode->yresolution=devmode->yresolution; + nt_devmode->ttoption=devmode->ttoption; + nt_devmode->collate=devmode->collate; + + nt_devmode->logpixels=devmode->logpixels; + nt_devmode->bitsperpel=devmode->bitsperpel; + nt_devmode->pelswidth=devmode->pelswidth; + nt_devmode->pelsheight=devmode->pelsheight; + nt_devmode->displayflags=devmode->displayflags; + nt_devmode->displayfrequency=devmode->displayfrequency; + nt_devmode->icmmethod=devmode->icmmethod; + nt_devmode->icmintent=devmode->icmintent; + nt_devmode->mediatype=devmode->mediatype; + nt_devmode->dithertype=devmode->dithertype; + nt_devmode->reserved1=devmode->reserved1; + nt_devmode->reserved2=devmode->reserved2; + nt_devmode->panningwidth=devmode->panningwidth; + nt_devmode->panningheight=devmode->panningheight; + + if (nt_devmode->driverextra != 0) { /* if we had a previous private delete it and make a new one */ - if (nt_devmode->private != NULL) - free(nt_devmode->private); + safe_free(nt_devmode->private); if((nt_devmode->private=(uint8 *)malloc(nt_devmode->driverextra * sizeof(uint8))) == NULL) return False; - memcpy(nt_devmode->private, devmode.private, nt_devmode->driverextra); + memcpy(nt_devmode->private, devmode->private, nt_devmode->driverextra); } return True; @@ -665,8 +669,7 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d DEBUG(8,("getprinterdata_printer_server:%s\n", value)); - if (!strcmp(value, "BeepEnabled")) - { + if (!strcmp(value, "BeepEnabled")) { *type = 0x4; if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL) return False; @@ -675,8 +678,7 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d return True; } - if (!strcmp(value, "EventLog")) - { + if (!strcmp(value, "EventLog")) { *type = 0x4; if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL) return False; @@ -685,8 +687,7 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d return True; } - if (!strcmp(value, "NetPopup")) - { + if (!strcmp(value, "NetPopup")) { *type = 0x4; if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL) return False; @@ -695,8 +696,7 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d return True; } - if (!strcmp(value, "MajorVersion")) - { + if (!strcmp(value, "MajorVersion")) { *type = 0x4; if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL) return False; @@ -705,8 +705,7 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d return True; } - if (!strcmp(value, "DefaultSpoolDirectory")) - { + if (!strcmp(value, "DefaultSpoolDirectory")) { pstring string="You are using a Samba server"; *type = 0x1; *needed = 2*(strlen(string)+1); @@ -715,24 +714,21 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d memset(*data, 0, (*needed > in_size) ? *needed:in_size); /* it's done by hand ready to go on the wire */ - for (i=0; i in_size) ? *needed:in_size) *sizeof(uint8))) == NULL) return False; memset(*data, 0, (*needed > in_size) ? *needed:in_size); - for (i=0; inotify_data.data.length=strlen(lp_servicename(snum)); @@ -1351,7 +1352,7 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPO uint16 field; SPOOL_NOTIFY_INFO_DATA *current_data; - NT_PRINTER_INFO_LEVEL printer; + NT_PRINTER_INFO_LEVEL *printer = NULL; print_queue_struct *queue=NULL; DEBUG(4,("construct_notify_printer_info\n")); @@ -1363,9 +1364,7 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPO option_type->count, lp_servicename(snum))); if (get_a_printer(&printer, 2, lp_servicename(snum))!=0) - { return False; - } for(field_num=0; field_numcount; field_num++) { @@ -1381,11 +1380,12 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPO current_data=&(info->data[info->count]); construct_info_data(current_data, type, field, id); - notify_info_data_table[j].fn(snum, current_data, queue, &printer); + notify_info_data_table[j].fn(snum, current_data, queue, printer); info->count++; } + free_a_printer(&printer, 2); return True; } @@ -1401,7 +1401,7 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_I uint16 field; SPOOL_NOTIFY_INFO_DATA *current_data; - NT_PRINTER_INFO_LEVEL printer; + NT_PRINTER_INFO_LEVEL *printer = NULL; DEBUG(4,("construct_notify_jobs_info\n")); @@ -1412,12 +1412,9 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_I option_type->count)); if (get_a_printer(&printer, 2, lp_servicename(snum))!=0) - { return False; - } - for(field_num=0; field_numcount; field_num++) - { + for(field_num=0; field_numcount; field_num++) { field = option_type->fields[field_num]; if (!search_notify(type, field, &j) ) @@ -1430,10 +1427,11 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_I current_data=&(info->data[info->count]); construct_info_data(current_data, type, field, id); - notify_info_data_table[j].fn(snum, current_data, queue, &printer); + notify_info_data_table[j].fn(snum, current_data, queue, printer); info->count++; } - + + free_a_printer(&printer, 2); return True; } @@ -1631,7 +1629,7 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, fstring { pstring chaine; int count; - NT_PRINTER_INFO_LEVEL ntprinter; + NT_PRINTER_INFO_LEVEL *ntprinter = NULL; counter_printer_0 *session_counter; uint32 global_counter; struct tm *t; @@ -1657,8 +1655,10 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, fstring /* it's the first time, add it to the list */ if (session_counter==NULL) { - if((session_counter=(counter_printer_0 *)malloc(sizeof(counter_printer_0))) == NULL) + if((session_counter=(counter_printer_0 *)malloc(sizeof(counter_printer_0))) == NULL) { + free_a_printer(&ntprinter, 2); return False; + } ZERO_STRUCTP(session_counter); session_counter->snum=snum; session_counter->counter=0; @@ -1675,7 +1675,7 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, fstring global_counter=session_counter->counter; /* the description and the name are of the form \\server\share */ - slprintf(chaine,sizeof(chaine)-1,"\\\\%s\\%s",servername, ntprinter.info_2->printername); + slprintf(chaine,sizeof(chaine)-1,"\\\\%s\\%s",servername, ntprinter->info_2->printername); init_unistr(&(printer->printername), chaine); @@ -1687,7 +1687,7 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, fstring printer->total_bytes = 0; t=gmtime(&setup_time); - ntprinter.info_2->setuptime = (uint32)setup_time; /* FIXME !! */ + ntprinter->info_2->setuptime = (uint32)setup_time; /* FIXME !! */ printer->year = t->tm_year+1900; printer->month = t->tm_mon+1; @@ -1712,11 +1712,11 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, fstring printer->unknown14 = 0x1; printer->unknown15 = 0x024a; /* 586 Pentium ? */ printer->unknown16 = 0x0; - printer->change_id = ntprinter.info_2->changeid; /* ChangeID in milliseconds*/ + printer->change_id = ntprinter->info_2->changeid; /* ChangeID in milliseconds*/ printer->unknown18 = 0x0; printer->status = nt_printq_status(status.status); printer->unknown20 = 0x0; - printer->c_setprinter = ntprinter.info_2->c_setprinter; /* how many times setprinter has been called */ + printer->c_setprinter = ntprinter->info_2->c_setprinter; /* how many times setprinter has been called */ printer->unknown22 = 0x0; printer->unknown23 = 0x6; /* 6 ???*/ printer->unknown24 = 0; /* unknown 24 to 26 are always 0 */ @@ -1727,7 +1727,7 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, fstring printer->unknown29 = 0; safe_free(queue); - + free_a_printer(&ntprinter,2); return (True); } @@ -1739,103 +1739,138 @@ static BOOL construct_printer_info_1(fstring server, uint32 flags, PRINTER_INFO_ { pstring chaine; pstring chaine2; - NT_PRINTER_INFO_LEVEL ntprinter; + NT_PRINTER_INFO_LEVEL *ntprinter = NULL; if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) != 0) return False; printer->flags=flags; - snprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",server, ntprinter.info_2->printername, - ntprinter.info_2->drivername, lp_comment(snum)); + snprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",server, ntprinter->info_2->printername, + ntprinter->info_2->drivername, lp_comment(snum)); - snprintf(chaine2,sizeof(chaine)-1,"%s%s", server, ntprinter.info_2->printername); + snprintf(chaine2,sizeof(chaine)-1,"%s%s", server, ntprinter->info_2->printername); init_unistr(&printer->description, chaine); init_unistr(&printer->name, chaine2); init_unistr(&printer->comment, lp_comment(snum)); + free_a_printer(&ntprinter,2); + return True; } /**************************************************************************** + Free a DEVMODE struct. +****************************************************************************/ + +static void free_dev_mode(DEVICEMODE *dev) +{ + if (dev == NULL) + return; + + if (dev->private) + safe_free(dev->private); + + safe_free(dev); +} + +/**************************************************************************** + Create a DEVMODE struct. Returns malloced memory. ****************************************************************************/ -static BOOL construct_dev_mode(DEVICEMODE *devmode, int snum, char *servername) + +static DEVICEMODE *construct_dev_mode(int snum, char *servername) { char adevice[32]; char aform[32]; - NT_PRINTER_INFO_LEVEL printer; - NT_DEVICEMODE ntdevmode; + NT_PRINTER_INFO_LEVEL *printer = NULL; + NT_DEVICEMODE *ntdevmode = NULL; + DEVICEMODE *devmode = NULL; DEBUG(7,("construct_dev_mode\n")); - memset(&(devmode->devicename), 0, 2*sizeof(adevice)); - memset(&(devmode->formname), 0, 2*sizeof(aform)); - DEBUGADD(8,("getting printer characteristics\n")); - get_a_printer(&printer, 2, lp_servicename(snum)); - if (printer.info_2->devmode) { - ntdevmode = *printer.info_2->devmode; - } else { - init_devicemode(&ntdevmode); + if ((devmode = (DEVICEMODE *)malloc(sizeof(DEVICEMODE))) == NULL) { + DEBUG(0,("construct_dev_mode: malloc fail.\n")); + return NULL; } + ZERO_STRUCTP(devmode); + + if(get_a_printer(&printer, 2, lp_servicename(snum)) != 0) + goto fail; + + if (printer->info_2->devmode) + ntdevmode = dup_nt_devicemode(printer->info_2->devmode); + else + ntdevmode = construct_nt_devicemode(); + + if (ntdevmode == NULL) + goto fail; + DEBUGADD(8,("loading DEVICEMODE\n")); snprintf(adevice, sizeof(adevice), "\\\\%s\\%s", global_myname, - printer.info_2->printername); - init_unistr(&(devmode->devicename), adevice); + printer->info_2->printername); + init_unistr(&devmode->devicename, adevice); - snprintf(aform, sizeof(aform), ntdevmode.formname); - init_unistr(&(devmode->formname), aform); + snprintf(aform, sizeof(aform), ntdevmode->formname); + init_unistr(&devmode->formname, aform); - devmode->specversion = ntdevmode.specversion; - devmode->driverversion = ntdevmode.driverversion; - devmode->size = ntdevmode.size; - devmode->driverextra = ntdevmode.driverextra; - devmode->fields = ntdevmode.fields; + devmode->specversion = ntdevmode->specversion; + devmode->driverversion = ntdevmode->driverversion; + devmode->size = ntdevmode->size; + devmode->driverextra = ntdevmode->driverextra; + devmode->fields = ntdevmode->fields; - devmode->orientation = ntdevmode.orientation; - devmode->papersize = ntdevmode.papersize; - devmode->paperlength = ntdevmode.paperlength; - devmode->paperwidth = ntdevmode.paperwidth; - devmode->scale = ntdevmode.scale; - devmode->copies = ntdevmode.copies; - devmode->defaultsource = ntdevmode.defaultsource; - devmode->printquality = ntdevmode.printquality; - devmode->color = ntdevmode.color; - devmode->duplex = ntdevmode.duplex; - devmode->yresolution = ntdevmode.yresolution; - devmode->ttoption = ntdevmode.ttoption; - devmode->collate = ntdevmode.collate; - devmode->icmmethod = ntdevmode.icmmethod; - devmode->icmintent = ntdevmode.icmintent; - devmode->mediatype = ntdevmode.mediatype; - devmode->dithertype = ntdevmode.dithertype; - - if (ntdevmode.private != NULL) - { - if((devmode->private=(uint8 *)malloc(devmode->driverextra*sizeof(uint8))) == NULL) { - return False; - } - memcpy(devmode->private, ntdevmode.private, devmode->driverextra); - } + devmode->orientation = ntdevmode->orientation; + devmode->papersize = ntdevmode->papersize; + devmode->paperlength = ntdevmode->paperlength; + devmode->paperwidth = ntdevmode->paperwidth; + devmode->scale = ntdevmode->scale; + devmode->copies = ntdevmode->copies; + devmode->defaultsource = ntdevmode->defaultsource; + devmode->printquality = ntdevmode->printquality; + devmode->color = ntdevmode->color; + devmode->duplex = ntdevmode->duplex; + devmode->yresolution = ntdevmode->yresolution; + devmode->ttoption = ntdevmode->ttoption; + devmode->collate = ntdevmode->collate; + devmode->icmmethod = ntdevmode->icmmethod; + devmode->icmintent = ntdevmode->icmintent; + devmode->mediatype = ntdevmode->mediatype; + devmode->dithertype = ntdevmode->dithertype; + + if (ntdevmode->private != NULL) { + if ((devmode->private=(uint8 *)memdup(ntdevmode->private, ntdevmode->driverextra)) == NULL) + goto fail; + } + + return devmode; + + fail: + + if (ntdevmode) + free_nt_devicemode(&ntdevmode); + if (printer) + free_a_printer(&printer,2); + free_dev_mode(devmode); - return True; + return NULL; } /******************************************************************** * construct_printer_info_2 * fill a printer_info_2 struct ********************************************************************/ + static BOOL construct_printer_info_2(fstring servername, PRINTER_INFO_2 *printer, int snum) { pstring chaine; pstring chaine2; pstring sl; int count; - DEVICEMODE *devmode; - NT_PRINTER_INFO_LEVEL ntprinter; + NT_PRINTER_INFO_LEVEL *ntprinter = NULL; print_queue_struct *queue=NULL; print_status_struct status; @@ -1854,58 +1889,54 @@ static BOOL construct_printer_info_2(fstring servername, PRINTER_INFO_2 *printer else fstrcpy(sl, '\0'); - snprintf(chaine2, sizeof(chaine)-1, "%s%s%s", servername, sl, ntprinter.info_2->printername); + snprintf(chaine2, sizeof(chaine)-1, "%s%s%s", servername, sl, ntprinter->info_2->printername); init_unistr(&printer->servername, chaine); /* servername*/ init_unistr(&printer->printername, chaine2); /* printername*/ init_unistr(&printer->sharename, lp_servicename(snum)); /* sharename */ init_unistr(&printer->portname, lp_servicename(snum)); /* port */ - init_unistr(&printer->drivername, ntprinter.info_2->drivername); /* drivername */ + init_unistr(&printer->drivername, ntprinter->info_2->drivername); /* drivername */ init_unistr(&printer->comment, lp_comment(snum)); /* comment */ - init_unistr(&printer->location, ntprinter.info_2->location); /* location */ - init_unistr(&printer->sepfile, ntprinter.info_2->sepfile); /* separator file */ - init_unistr(&printer->printprocessor, ntprinter.info_2->printprocessor);/* print processor */ - init_unistr(&printer->datatype, ntprinter.info_2->datatype); /* datatype */ - init_unistr(&printer->parameters, ntprinter.info_2->parameters); /* parameters (of print processor) */ + init_unistr(&printer->location, ntprinter->info_2->location); /* location */ + init_unistr(&printer->sepfile, ntprinter->info_2->sepfile); /* separator file */ + init_unistr(&printer->printprocessor, ntprinter->info_2->printprocessor);/* print processor */ + init_unistr(&printer->datatype, ntprinter->info_2->datatype); /* datatype */ + init_unistr(&printer->parameters, ntprinter->info_2->parameters); /* parameters (of print processor) */ printer->attributes = PRINTER_ATTRIBUTE_SHARED \ | PRINTER_ATTRIBUTE_LOCAL \ | PRINTER_ATTRIBUTE_RAW_ONLY ; /* attributes */ - printer->priority = ntprinter.info_2->priority; /* priority */ - printer->defaultpriority = ntprinter.info_2->default_priority; /* default priority */ - printer->starttime = ntprinter.info_2->starttime; /* starttime */ - printer->untiltime = ntprinter.info_2->untiltime; /* untiltime */ + printer->priority = ntprinter->info_2->priority; /* priority */ + printer->defaultpriority = ntprinter->info_2->default_priority; /* default priority */ + printer->starttime = ntprinter->info_2->starttime; /* starttime */ + printer->untiltime = ntprinter->info_2->untiltime; /* untiltime */ printer->status = nt_printq_status(status.status); /* status */ printer->cjobs = count; /* jobs */ - printer->averageppm = ntprinter.info_2->averageppm; /* average pages per minute */ + printer->averageppm = ntprinter->info_2->averageppm; /* average pages per minute */ - if((devmode=(DEVICEMODE *)malloc(sizeof(DEVICEMODE))) == NULL) + if((printer->devmode = construct_dev_mode(snum, servername)) == NULL) goto err; - ZERO_STRUCTP(devmode); - - if(!construct_dev_mode(devmode, snum, servername)) - goto err; - - printer->devmode=devmode; - - if (ntprinter.info_2->secdesc.len != 0) - { + if (ntprinter->info_2->secdesc_buf->len != 0) { /* steal the printer info sec_desc structure. [badly done]. */ - printer->secdesc = ntprinter.info_2->secdesc.sec; - ZERO_STRUCT(ntprinter.info_2->secdesc); + printer->secdesc = ntprinter->info_2->secdesc_buf->sec; + ntprinter->info_2->secdesc_buf->sec = NULL; /* Stolen memory. */ + ntprinter->info_2->secdesc_buf->len = 0; /* Stolen memory. */ + ntprinter->info_2->secdesc_buf->max_len = 0; /* Stolen memory. */ } - else - { + else { printer->secdesc = NULL; } + free_a_printer(&ntprinter, 2); safe_free(queue); return True; err: + if (ntprinter) + free_a_printer(&ntprinter, 2); safe_free(queue); return False; } @@ -1917,20 +1948,21 @@ static BOOL construct_printer_info_2(fstring servername, PRINTER_INFO_2 *printer static BOOL construct_printer_info_3(fstring servername, PRINTER_INFO_3 *printer, int snum) { - NT_PRINTER_INFO_LEVEL ntprinter; + NT_PRINTER_INFO_LEVEL *ntprinter = NULL; if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0 ) return False; - printer->flags = 4; /* no idea, yet. see MSDN. */ - if (ntprinter.info_2->secdesc.len != 0) - { + printer->flags = 4; /* This is the offset to the SEC_DESC. */ + if (ntprinter->info_2->secdesc_buf->len != 0) { /* steal the printer info sec_desc structure. [badly done]. */ - printer->sec = *ntprinter.info_2->secdesc.sec; - safe_free(ntprinter.info_2->secdesc.sec); - ZERO_STRUCT(ntprinter.info_2->secdesc); + printer->secdesc = ntprinter->info_2->secdesc_buf->sec; + ntprinter->info_2->secdesc_buf->sec = NULL; /* Stolen the malloced memory. */ + ntprinter->info_2->secdesc_buf->len = 0; /* Stolen the malloced memory. */ + ntprinter->info_2->secdesc_buf->max_len = 0; /* Stolen the malloced memory. */ } + free_a_printer(&ntprinter, 2); return True; } @@ -2394,7 +2426,7 @@ static uint32 getprinter_level_3(fstring servername, int snum, NEW_BUFFER *buffe new_smb_io_printer_info_3("", buffer, printer, 0); /* clear memory */ - free_sec_desc(&printer->sec); + free_sec_desc(&printer->secdesc); if (*needed > offered) { return ERROR_INSUFFICIENT_BUFFER; @@ -2447,16 +2479,17 @@ static void fill_printer_driver_info_1(DRIVER_INFO_1 *info, static void construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, fstring servername, fstring architecture) { - NT_PRINTER_INFO_LEVEL printer; + NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; ZERO_STRUCT(driver); - ZERO_STRUCT(printer); get_a_printer(&printer, 2, lp_servicename(snum) ); - get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture); + get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture); fill_printer_driver_info_1(info, driver, servername, architecture); + + free_a_printer(&printer,2); } /******************************************************************** @@ -2501,16 +2534,18 @@ static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, ********************************************************************/ static void construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fstring servername, fstring architecture) { - NT_PRINTER_INFO_LEVEL printer; + NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; ZERO_STRUCT(printer); ZERO_STRUCT(driver); get_a_printer(&printer, 2, lp_servicename(snum) ); - get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture); + get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture); fill_printer_driver_info_2(info, driver, servername, architecture); + + free_a_printer(&printer,2); } /******************************************************************** @@ -2600,16 +2635,17 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, static void construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fstring servername, fstring architecture) { - NT_PRINTER_INFO_LEVEL printer; + NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; - ZERO_STRUCT(printer); ZERO_STRUCT(driver); get_a_printer(&printer, 2, lp_servicename(snum) ); - get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture); + get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture); fill_printer_driver_info_3(info, driver, servername, architecture); + + free_a_printer(&printer,2); } /**************************************************************************** @@ -2932,24 +2968,24 @@ static uint32 update_printer_sec(const POLICY_HND *handle, uint32 level, return nt_printing_setsec(Printer->dev.printername, secdesc_ctr); } - /******************************************************************** * called by spoolss_api_setprinter * when updating a printer description ********************************************************************/ + static uint32 update_printer(const POLICY_HND *handle, uint32 level, const SPOOL_PRINTER_INFO_LEVEL *info, - const DEVICEMODE *devmode) + DEVICEMODE *devmode) { int snum; - NT_PRINTER_INFO_LEVEL printer; - NT_DEVICEMODE nt_devmode; + NT_PRINTER_INFO_LEVEL *printer = NULL; + NT_DEVICEMODE *ntdevmode = NULL; Printer_entry *Printer = find_printer_index_by_hnd(handle); DEBUG(8,("update_printer\n")); if (level!=2) { - DEBUG(0,("Send a mail to jfm@samba.org\n")); + DEBUG(0,("Send a mail to samba@samba.org\n")); DEBUGADD(0,("with the following message: update_printer: level!=2\n")); return ERROR_INVALID_LEVEL; } @@ -2963,32 +2999,34 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, get_a_printer(&printer, 2, lp_servicename(snum)); DEBUGADD(8,("Converting info_2 struct\n")); - convert_printer_info(info, &printer, level); + convert_printer_info(info, printer, level); - if ((info->info_2)->devmode_ptr != 0) { + if (info->info_2->devmode_ptr != 0) { /* we have a valid devmode convert it and link it*/ DEBUGADD(8,("Converting the devicemode struct\n")); - if (printer.info_2->devmode) { - nt_devmode = *printer.info_2->devmode; + if (printer->info_2->devmode) { + ntdevmode = dup_nt_devicemode(printer->info_2->devmode); } else { - init_devicemode(&nt_devmode); + ntdevmode = construct_nt_devicemode(); } - convert_devicemode(*devmode, &nt_devmode); - } - else { - if (printer.info_2->devmode != NULL) - free(printer.info_2->devmode); - printer.info_2->devmode=NULL; + convert_devicemode(devmode, ntdevmode); + } else { + if (printer->info_2->devmode != NULL) + free_nt_devicemode(&printer->info_2->devmode); + printer->info_2->devmode=NULL; } - if (add_a_printer(printer, 2)!=0) { + if (add_a_printer(*printer, 2)!=0) { /* I don't really know what to return here !!! */ + free_a_printer(&printer, 2); return ERROR_ACCESS_DENIED; } + free_a_printer(&printer, 2); + return NT_STATUS_NO_PROBLEMO; } @@ -2996,8 +3034,8 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, ****************************************************************************/ uint32 _spoolss_setprinter(const POLICY_HND *handle, uint32 level, const SPOOL_PRINTER_INFO_LEVEL *info, - const DEVMODE_CTR devmode_ctr, - const SEC_DESC_BUF *secdesc_ctr, + DEVMODE_CTR devmode_ctr, + SEC_DESC_BUF *secdesc_ctr, uint32 command) { Printer_entry *Printer = find_printer_index_by_hnd(handle); @@ -3085,7 +3123,7 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, { pstring temp_name; DEVICEMODE *devmode; - NT_PRINTER_INFO_LEVEL ntprinter; + NT_PRINTER_INFO_LEVEL *ntprinter = NULL; pstring chaine; struct tm *t; @@ -3099,7 +3137,8 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, job_info->jobid=queue->job; - snprintf(chaine, sizeof(chaine)-1, "\\\\%s\\%s", global_myname, ntprinter.info_2->printername); + snprintf(chaine, sizeof(chaine)-1, "\\\\%s\\%s", global_myname, ntprinter->info_2->printername); + init_unistr(&(job_info->printername), chaine); init_unistr(&(job_info->machinename), temp_name); @@ -3124,16 +3163,13 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, job_info->timeelapsed=0; job_info->pagesprinted=0; - if((devmode=(DEVICEMODE *)malloc(sizeof(DEVICEMODE))) == NULL) { + if((job_info->devmode = construct_dev_mode(snum, global_myname)) == NULL) { + free_a_printer(&ntprinter, 2); return False; } - ZERO_STRUCTP(devmode); - if(!construct_dev_mode(devmode, snum, global_myname)) { - return False; - } job_info->devmode=devmode; - + free_a_printer(&ntprinter, 2); return (True); } @@ -3753,7 +3789,7 @@ static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name, uint32 user_switch, const SPOOL_USER_CTR *user, POLICY_HND *handle) { - NT_PRINTER_INFO_LEVEL printer; + NT_PRINTER_INFO_LEVEL *printer = NULL; fstring name; fstring share_name; @@ -3761,17 +3797,17 @@ static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name, /* NULLify info_2 here */ /* don't put it in convert_printer_info as it's used also with non-NULL values */ - printer.info_2=NULL; + printer->info_2=NULL; /* convert from UNICODE to ASCII */ - convert_printer_info(info, &printer, 2); + convert_printer_info(info, printer, 2); - unistr2_to_ascii(share_name, &((info->info_2)->printername), sizeof(share_name)-1); + unistr2_to_ascii(share_name, &info->info_2->printername, sizeof(share_name)-1); slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname, share_name); /* write the ASCII on disk */ - if (add_a_printer(printer, 2) != 0x0) + if (add_a_printer(*printer, 2) != 0x0) return ERROR_ACCESS_DENIED; create_printer_hnd(handle); @@ -3969,7 +4005,7 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx, uint32 *out_type, uint32 *out_max_data_len, uint8 **data_out, uint32 *out_data_len) { - NT_PRINTER_INFO_LEVEL printer; + NT_PRINTER_INFO_LEVEL *printer = NULL; fstring value; @@ -4017,7 +4053,7 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx, biggest_valuesize=0; biggest_datasize=0; - while (get_specific_param_by_index(printer, 2, param_index, value, &data, &type, &data_len)) { + while (get_specific_param_by_index(*printer, 2, param_index, value, &data, &type, &data_len)) { if (strlen(value) > biggest_valuesize) biggest_valuesize=strlen(value); if (data_len > biggest_datasize) biggest_datasize=data_len; @@ -4041,7 +4077,7 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx, * that's the number of bytes not the number of unicode chars */ - if (!get_specific_param_by_index(printer, 2, idx, value, &data, &type, &data_len)) { + if (!get_specific_param_by_index(*printer, 2, idx, value, &data, &type, &data_len)) { safe_free(data); return ERROR_NO_MORE_ITEMS; } @@ -4089,7 +4125,7 @@ uint32 _spoolss_setprinterdata( const POLICY_HND *handle, uint32 real_len, uint32 numeric_data) { - NT_PRINTER_INFO_LEVEL printer; + NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_PARAM *param = NULL; int snum=0; @@ -4110,12 +4146,12 @@ uint32 _spoolss_setprinterdata( const POLICY_HND *handle, return ERROR_INVALID_NAME; convert_specific_param(¶m, value , type, data, real_len); - unlink_specific_param_if_exist(printer.info_2, param); + unlink_specific_param_if_exist(printer->info_2, param); - if (!add_a_specific_param(printer.info_2, param)) + if (!add_a_specific_param(printer->info_2, param)) status = ERROR_INVALID_PARAMETER; else - status = add_a_printer(printer, 2); + status = add_a_printer(*printer, 2); return status; } @@ -4512,4 +4548,3 @@ uint32 _spoolss_getjob( POLICY_HND *handle, uint32 jobid, uint32 level, } } #undef OLD_NTDOMAIN - -- cgit From b9fedcb2de5612bdb4e763fe0788e1a4a9c16d33 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 1 Jun 2000 21:00:37 +0000 Subject: param/loadparm.c: Looks like someone ran indent on this ! passdb/smbpass.c: Insure uninitialized memory reference fix. printing/nt_printing.c: rpc_server/srv_spoolss_nt.c: Insure memory leak fixes. smbd/unix_acls.c: Shadow ref fix. Jeremy. (This used to be commit d175d3ebefc053e9badd91ca5f2d8bd03eb6705d) --- source3/rpc_server/srv_spoolss_nt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 424e1f5e95..f181585c84 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3862,6 +3862,7 @@ static uint32 modify_driver_heirarchy(NT_PRINTER_DRIVER_INFO_LEVEL *driver, uint pstring path_old; pstring path_new; pstring short_archi; + /* find_service is an smbd-specific function call */ int snum = find_service("print$"); char *model = NULL; @@ -3886,10 +3887,11 @@ static uint32 modify_driver_heirarchy(NT_PRINTER_DRIVER_INFO_LEVEL *driver, uint (unsigned int)sys_getpid()); slprintf(path_new, sizeof(path_new)-1, "%s/%s/%s", lp_pathname(snum), short_archi, model); - DEBUG(10,("_spoolss_addprinterdriver: old_path=%s, new_path=%s\n", + DEBUG(10,("modify_driver_heirarchy: old_path=%s, new_path=%s\n", path_old, path_new )); if (dos_rename(path_old, path_new) == -1) { - DEBUG(0,("modify_driver_heirarchy: rename failed (%s)\n", strerror(errno) )); + DEBUG(0,("modify_driver_heirarchy: rename from %s to %s failed (%s)\n", + path_old, path_new, strerror(errno) )); /* We need to clean up here.... - how ? */ return ERROR_ACCESS_DENIED; /* We need a generic mapping from NT errors here... */ } -- cgit From 8ff6458a3e568e759969fd1a9c827c4b47008cfb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 1 Jun 2000 21:52:49 +0000 Subject: More insure found memory leak and corruption fixes. Jeremy. (This used to be commit 3cdcfa6325b9cd2d7f7c90c4b2d1c6ec73fc2f6d) --- source3/rpc_server/srv_spoolss_nt.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index f181585c84..b77deca158 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3917,14 +3917,12 @@ uint32 _spoolss_addprinterdriver( const UNISTR2 *server_name, #ifdef RELIES_ON_SMBD_FUNCTIONS_LINKED_INTO_SPOOLSSD if ((err = modify_driver_heirarchy(&driver, level)) != 0) { - safe_free(driver.info_3); - safe_free(driver.info_6); + free_a_printer_driver(driver, level); return err; } #endif - safe_free(driver.info_3); - safe_free(driver.info_6); + free_a_printer_driver(driver, level); return NT_STATUS_NO_PROBLEMO; } -- cgit From 01c4ecd2343a4c87a0f023cd58382bf08610304e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 2 Jun 2000 18:38:49 +0000 Subject: Fixed null pointer indirect in addprinterex. Still working on problem with extra directory layer in NT drivers. Jeremy. (This used to be commit 48a80318269c832e702678237e86ba55c10444f1) --- source3/rpc_server/srv_spoolss_nt.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index b77deca158..e88aa9fa72 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -560,7 +560,7 @@ static BOOL convert_printer_info(const SPOOL_PRINTER_INFO_LEVEL *uni, { switch (level) { case 2: - uni_2_asc_printer_info_2(uni->info_2, &(printer->info_2)); + uni_2_asc_printer_info_2(uni->info_2, &printer->info_2); break; default: break; @@ -3793,13 +3793,16 @@ static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name, fstring name; fstring share_name; + if ((printer = (NT_PRINTER_INFO_LEVEL *)malloc(sizeof(NT_PRINTER_INFO_LEVEL))) == NULL) { + DEBUG(0,("spoolss_addprinterex_level_2: malloc fail.\n")); + return ERROR_NOT_ENOUGH_MEMORY; + } + + ZERO_STRUCTP(printer); + clear_handle(handle); - /* NULLify info_2 here */ - /* don't put it in convert_printer_info as it's used also with non-NULL values */ - printer->info_2=NULL; - - /* convert from UNICODE to ASCII */ + /* 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->printername, sizeof(share_name)-1); @@ -3807,23 +3810,28 @@ static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name, slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname, share_name); /* write the ASCII on disk */ - if (add_a_printer(*printer, 2) != 0x0) + if (add_a_printer(*printer, 2) != 0) { + free_a_printer(&printer,2); return ERROR_ACCESS_DENIED; + } create_printer_hnd(handle); open_printer_hnd(handle); if (!set_printer_hnd_printertype(handle, name)) { + free_a_printer(&printer,2); close_printer_handle(handle); return ERROR_ACCESS_DENIED; } if (!set_printer_hnd_printername(handle, name)) { + free_a_printer(&printer,2); close_printer_handle(handle); return ERROR_ACCESS_DENIED; } + free_a_printer(&printer,2); return NT_STATUS_NO_PROBLEMO; } @@ -3862,6 +3870,7 @@ static uint32 modify_driver_heirarchy(NT_PRINTER_DRIVER_INFO_LEVEL *driver, uint pstring path_old; pstring path_new; pstring short_archi; + pstring model_name; /* find_service is an smbd-specific function call */ int snum = find_service("print$"); @@ -3885,7 +3894,11 @@ static uint32 modify_driver_heirarchy(NT_PRINTER_DRIVER_INFO_LEVEL *driver, uint slprintf(path_old, sizeof(path_old)-1, "%s/%s/TMP_%u", lp_pathname(snum), short_archi, (unsigned int)sys_getpid()); - slprintf(path_new, sizeof(path_new)-1, "%s/%s/%s", lp_pathname(snum), short_archi, model); + + /* Clean up any '/' and other characters in the model name. */ + alpha_strcpy(model_name, model, sizeof(pstring)); + + slprintf(path_new, sizeof(path_new)-1, "%s/%s/%s", lp_pathname(snum), short_archi, model_name); DEBUG(10,("modify_driver_heirarchy: old_path=%s, new_path=%s\n", path_old, path_new )); -- cgit From 2472ab1e60c27bf8ac84e32e67c8cb18e5647306 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 2 Jun 2000 19:42:11 +0000 Subject: More memory corruption (leaks etc.) fixes. Jeremy. (This used to be commit 71a0621f552083880e89923055e8bd14d0b1b82f) --- source3/rpc_server/srv_spoolss_nt.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index e88aa9fa72..37833df508 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1846,6 +1846,9 @@ static DEVICEMODE *construct_dev_mode(int snum, char *servername) goto fail; } + free_nt_devicemode(&ntdevmode); + free_a_printer(&printer,2); + return devmode; fail: @@ -2152,12 +2155,12 @@ static BOOL enum_all_printers_info_2(fstring servername, NEW_BUFFER *buffer, uin /* check the required size. */ for (i=0; i<*returned; i++) - (*needed) += spoolss_size_printer_info_2(&(printers[i])); + (*needed) += spoolss_size_printer_info_2(&printers[i]); if (!alloc_buffer_size(buffer, *needed)) { for (i=0; i<*returned; i++) { - safe_free(printers[i].devmode->private); - safe_free(printers[i].devmode); + free_devmode(printers[i].devmode); + free_sec_desc(&printers[i].secdesc); } safe_free(printers); return ERROR_INSUFFICIENT_BUFFER; @@ -2381,7 +2384,7 @@ static uint32 getprinter_level_2(fstring servername, int snum, NEW_BUFFER *buffe *needed += spoolss_size_printer_info_2(printer); if (!alloc_buffer_size(buffer, *needed)) { - safe_free(printer); + free_printer_info_2(printer); return ERROR_INSUFFICIENT_BUFFER; } @@ -2389,9 +2392,7 @@ static uint32 getprinter_level_2(fstring servername, int snum, NEW_BUFFER *buffe new_smb_io_printer_info_2("", buffer, printer, 0); /* clear memory */ - safe_free(printer->devmode->private); - safe_free(printer->devmode); - safe_free(printer); + free_printer_info_2(printer); if (*needed > offered) { return ERROR_INSUFFICIENT_BUFFER; @@ -3892,8 +3893,8 @@ static uint32 modify_driver_heirarchy(NT_PRINTER_DRIVER_INFO_LEVEL *driver, uint break; } - slprintf(path_old, sizeof(path_old)-1, "%s/%s/TMP_%u", lp_pathname(snum), short_archi, - (unsigned int)sys_getpid()); + slprintf(path_old, sizeof(path_old)-1, "%s/%s/TMP_%s", lp_pathname(snum), short_archi, + client_addr()); /* Clean up any '/' and other characters in the model name. */ alpha_strcpy(model_name, model, sizeof(pstring)); @@ -3963,8 +3964,8 @@ static uint32 getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen get_short_archi(short_archi, long_archi); #ifdef RELIES_ON_SMBD_FUNCTIONS_LINKED_INTO_SPOOLSSD - slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s\\TMP_%u", global_myname, short_archi, - (unsigned int)sys_getpid()); + slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s\\TMP_%s", global_myname, short_archi, + client_addr()); #else slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", global_myname, short_archi); -- cgit From c7d0975183c286d9f93e57bf8c73c96c1a9ebd55 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 2 Jun 2000 20:08:28 +0000 Subject: More memory leak fixes. Jeremy. (This used to be commit 4e7b6b20eabe02f1ab74254607178ba35e61c9ce) --- source3/rpc_server/srv_spoolss_nt.c | 52 ++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 15 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 37833df508..327a4a15fe 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1633,7 +1633,7 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, fstring counter_printer_0 *session_counter; uint32 global_counter; struct tm *t; - time_t setup_time; + time_t setup_time = time(NULL); print_queue_struct *queue=NULL; print_status_struct status; @@ -1949,13 +1949,20 @@ static BOOL construct_printer_info_2(fstring servername, PRINTER_INFO_2 *printer * fill a printer_info_3 struct ********************************************************************/ static BOOL construct_printer_info_3(fstring servername, - PRINTER_INFO_3 *printer, int snum) + PRINTER_INFO_3 **pp_printer, int snum) { NT_PRINTER_INFO_LEVEL *ntprinter = NULL; + PRINTER_INFO_3 *printer = NULL; if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0 ) return False; - + + *pp_printer = NULL; + if ((printer = (PRINTER_INFO_3 *)malloc(sizeof(PRINTER_INFO_3))) == NULL) { + DEBUG(0,("construct_printer_info_3: malloc fail.\n")); + return False; + } + printer->flags = 4; /* This is the offset to the SEC_DESC. */ if (ntprinter->info_2->secdesc_buf->len != 0) { /* steal the printer info sec_desc structure. [badly done]. */ @@ -1966,6 +1973,8 @@ static BOOL construct_printer_info_3(fstring servername, } free_a_printer(&ntprinter, 2); + + *pp_printer = printer; return True; } @@ -2172,8 +2181,8 @@ static BOOL enum_all_printers_info_2(fstring servername, NEW_BUFFER *buffer, uin /* clear memory */ for (i=0; i<*returned; i++) { - safe_free(printers[i].devmode->private); - safe_free(printers[i].devmode); + free_devmode(printers[i].devmode); + free_sec_desc(&printers[i].secdesc); } safe_free(printers); @@ -2408,18 +2417,16 @@ static uint32 getprinter_level_3(fstring servername, int snum, NEW_BUFFER *buffe PRINTER_INFO_3 *printer=NULL; fstring temp; - if((printer=(PRINTER_INFO_3*)malloc(sizeof(PRINTER_INFO_3)))==NULL) - return ERROR_NOT_ENOUGH_MEMORY; - fstrcpy(temp, "\\\\"); fstrcat(temp, servername); - construct_printer_info_3(temp, printer, snum); + if (!construct_printer_info_3(temp, &printer, snum)) + return ERROR_NOT_ENOUGH_MEMORY; /* check the required size. */ *needed += spoolss_size_printer_info_3(printer); if (!alloc_buffer_size(buffer, *needed)) { - safe_free(printer); + free_printer_info_3(printer); return ERROR_INSUFFICIENT_BUFFER; } @@ -2427,8 +2434,8 @@ static uint32 getprinter_level_3(fstring servername, int snum, NEW_BUFFER *buffe new_smb_io_printer_info_3("", buffer, printer, 0); /* clear memory */ - free_sec_desc(&printer->secdesc); - + free_printer_info_3(printer); + if (*needed > offered) { return ERROR_INSUFFICIENT_BUFFER; } @@ -2565,8 +2572,12 @@ static void init_unistr_array(uint16 **uni_array, fstring *char_array, char *whe *uni_array=NULL; while (1) { - v = char_array[i]; - if (!v) v = ""; /* hack to handle null lists */ + if (char_array == NULL) + v = ""; + else { + v = char_array[i]; + if (!v) v = ""; /* hack to handle null lists */ + } snprintf(line, sizeof(line)-1, "%s%s", where, v); DEBUGADD(6,("%d:%s:%d\n", i, line, strlen(line))); if((*uni_array=Realloc(*uni_array, (j+strlen(line)+2)*sizeof(uint16))) == NULL) { @@ -2626,7 +2637,7 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, init_unistr( &(info->defaultdatatype), driver.info_3->defaultdatatype ); info->dependentfiles=NULL; - init_unistr_array(&(info->dependentfiles), driver.info_3->dependentfiles, where); + init_unistr_array(&info->dependentfiles, driver.info_3->dependentfiles, where); } /******************************************************************** @@ -2649,6 +2660,14 @@ static void construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, free_a_printer(&printer,2); } +/**************************************************************************** +****************************************************************************/ + +static void free_printer_driver_info_3(DRIVER_INFO_3 *info) +{ + safe_free(info->dependentfiles); +} + /**************************************************************************** ****************************************************************************/ static uint32 getprinterdriver2_level1(fstring servername, fstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) @@ -2725,12 +2744,15 @@ static uint32 getprinterdriver2_level3(fstring servername, fstring architecture, *needed += spoolss_size_printer_driver_info_3(&info); if (!alloc_buffer_size(buffer, *needed)) { + free_printer_driver_info_3(&info); return ERROR_INSUFFICIENT_BUFFER; } /* fill the buffer with the structures */ new_smb_io_printer_driver_info_3("", buffer, &info, 0); + free_printer_driver_info_3(&info); + if (*needed > offered) return ERROR_INSUFFICIENT_BUFFER; else -- cgit From 0cc138993573a8337c335563ba3c5936d260f298 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 2 Jun 2000 21:16:39 +0000 Subject: More memory leak and PANIC action fixes. This is *horrible* code :-(. Jeremy. (This used to be commit ac383bb765ea606fc1105aa91470fcdf453d9335) --- source3/rpc_server/srv_spoolss_nt.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 327a4a15fe..393ba64130 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -473,7 +473,7 @@ static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size) uint32 extra_space; uint32 old_offset; - ps=&(buffer->prs); + ps= &buffer->prs; /* damn, I'm doing the reverse operation of prs_grow() :) */ if (buffer_size < prs_data_size(ps)) @@ -2398,7 +2398,10 @@ static uint32 getprinter_level_2(fstring servername, int snum, NEW_BUFFER *buffe } /* fill the buffer with the structures */ - new_smb_io_printer_info_2("", buffer, printer, 0); + if (!new_smb_io_printer_info_2("", buffer, printer, 0)) { + free_printer_info_2(printer); + return ERROR_NOT_ENOUGH_MEMORY; + } /* clear memory */ free_printer_info_2(printer); @@ -3002,7 +3005,6 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, { int snum; NT_PRINTER_INFO_LEVEL *printer = NULL; - NT_DEVICEMODE *ntdevmode = NULL; Printer_entry *Printer = find_printer_index_by_hnd(handle); DEBUG(8,("update_printer\n")); @@ -3025,6 +3027,7 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, convert_printer_info(info, printer, level); if (info->info_2->devmode_ptr != 0) { + NT_DEVICEMODE *ntdevmode = NULL; /* we have a valid devmode convert it and link it*/ @@ -3036,6 +3039,7 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, } convert_devicemode(devmode, ntdevmode); + free_nt_devicemode(&ntdevmode); } else { if (printer->info_2->devmode != NULL) free_nt_devicemode(&printer->info_2->devmode); @@ -3097,6 +3101,7 @@ uint32 _spoolss_fcpn(const POLICY_HND *handle) Printer->notify.localmachine[0]='\0'; Printer->notify.printerlocal=0; safe_free(Printer->notify.option); + safe_free(Printer->notify.option->ctr.type); Printer->notify.option=NULL; return NT_STATUS_NO_PROBLEMO; -- cgit From 5a5540f87a89224397d791f4fe8093be214e1f15 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 3 Jun 2000 00:53:07 +0000 Subject: rpc_client/cli_lsarpc.c: Removed unused variable. rpc_server/srv_spoolss_nt.c: Fixed more memory leaks. smbd/nttrans.c: Fixed shadow variable problem. Jeremy. (This used to be commit f0a7540831181d3a47e7f8ce8be55a36a2f2aba1) --- source3/rpc_server/srv_spoolss_nt.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 393ba64130..0efcbdae1c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4110,6 +4110,7 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx, DEBUG(6,("final values: [%d], [%d]\n", *out_value_len, *out_data_len)); + free_a_printer(&printer, 2); return NT_STATUS_NO_PROBLEMO; } @@ -4120,9 +4121,12 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx, if (!get_specific_param_by_index(*printer, 2, idx, value, &data, &type, &data_len)) { safe_free(data); + free_a_printer(&printer, 2); return ERROR_NO_MORE_ITEMS; } + free_a_printer(&printer, 2); + /* * the value is: * - counted in bytes in the request @@ -4194,6 +4198,7 @@ uint32 _spoolss_setprinterdata( const POLICY_HND *handle, else status = add_a_printer(*printer, 2); + free_a_printer(&printer, 2); return status; } -- cgit From dbf004bdabd08272e5dfb07a5511091746b6631a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 4 Jun 2000 00:26:08 +0000 Subject: added a MANGLE_DRIVER_PATH define to chooose whether we stuff with the driver path do a rename etc. I turned it off by default as it is causing me no end of problems. The client will *cache* this path, and that screws things up badly as the temp directory is no longer there when it is needed. (This used to be commit 46f5f41c88b6ffa117d30f7702628b43dd456902) --- source3/rpc_server/srv_spoolss_nt.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 0efcbdae1c..8015b9e4f8 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -25,7 +25,9 @@ #include "includes.h" -#define RELIES_ON_SMBD_FUNCTIONS_LINKED_INTO_SPOOLSSD +#ifndef MANGLE_DRIVER_PATH +#define MANGLE_DRIVER_PATH 0 +#endif extern int DEBUGLEVEL; extern pstring global_myname; @@ -3892,7 +3894,7 @@ uint32 _spoolss_addprinterex( const UNISTR2 *uni_srv_name, uint32 level, Modify internal driver heirarchy. ****************************************************************************/ -#ifdef RELIES_ON_SMBD_FUNCTIONS_LINKED_INTO_SPOOLSSD +#if MANGLE_DRIVER_PATH static uint32 modify_driver_heirarchy(NT_PRINTER_DRIVER_INFO_LEVEL *driver, uint32 level) { pstring path_old; @@ -3947,8 +3949,8 @@ uint32 _spoolss_addprinterdriver( const UNISTR2 *server_name, uint32 level, const SPOOL_PRINTER_DRIVER_INFO_LEVEL *info) { + uint32 err = NT_STATUS_NO_PROBLEMO; NT_PRINTER_DRIVER_INFO_LEVEL driver; - uint32 err; ZERO_STRUCT(driver); convert_printer_driver_info(info, &driver, level); @@ -3956,16 +3958,13 @@ uint32 _spoolss_addprinterdriver( const UNISTR2 *server_name, if (add_a_printer_driver(driver, level)!=0) return ERROR_ACCESS_DENIED; -#ifdef RELIES_ON_SMBD_FUNCTIONS_LINKED_INTO_SPOOLSSD - if ((err = modify_driver_heirarchy(&driver, level)) != 0) { - free_a_printer_driver(driver, level); - return err; - } +#if MANGLE_DRIVER_PATH + err = modify_driver_heirarchy(&driver, level); #endif free_a_printer_driver(driver, level); - return NT_STATUS_NO_PROBLEMO; + return err; } /**************************************************************************** @@ -3990,7 +3989,7 @@ static uint32 getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)-1); get_short_archi(short_archi, long_archi); -#ifdef RELIES_ON_SMBD_FUNCTIONS_LINKED_INTO_SPOOLSSD +#if MANGLE_DRIVER_PATH slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s\\TMP_%s", global_myname, short_archi, client_addr()); #else -- cgit From 6d8c131f50e708d4c009355a7c5fe026cf8d350a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 5 Jun 2000 20:55:57 +0000 Subject: Some tidyup fixes (memory leaks etc.). Still no progress with the "no driver" issue. I'm banging my head against comparitive packet dumps right now... Jeremy. (This used to be commit 03cd4aa1443acd958593f37c61ff9c90a43c660b) --- source3/rpc_server/srv_spoolss_nt.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 8015b9e4f8..8dca09dc95 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -773,13 +773,17 @@ static BOOL getprinterdata_printer(const POLICY_HND *handle, DEBUG(5,("getprinterdata_printer:allocating %d\n", in_size)); - if((*data = (uint8 *)malloc( in_size *sizeof(uint8) )) == NULL) { - return False; - } + if (in_size) { + if((*data = (uint8 *)malloc( in_size *sizeof(uint8) )) == NULL) { + return False; + } - memset(*data, 0, in_size *sizeof(uint8)); - /* copy the min(in_size, len) */ - memcpy(*data, idata, (len>in_size)?in_size:len *sizeof(uint8)); + memset(*data, 0, in_size *sizeof(uint8)); + /* copy the min(in_size, len) */ + memcpy(*data, idata, (len>in_size)?in_size:len *sizeof(uint8)); + } else { + *data = NULL; + } *needed = len; @@ -835,9 +839,14 @@ uint32 _spoolss_getprinterdata(const POLICY_HND *handle, UNISTR2 *valuename, if (found==False) { DEBUG(5, ("value not found, allocating %d\n", *out_size)); /* reply this param doesn't exist */ - if((*data=(uint8 *)malloc(*out_size*sizeof(uint8))) == NULL) - return ERROR_NOT_ENOUGH_MEMORY; - memset(*data, 0x0, *out_size*sizeof(uint8)); + if (*out_size) { + if((*data=(uint8 *)malloc(*out_size*sizeof(uint8))) == NULL) + return ERROR_NOT_ENOUGH_MEMORY; + memset(*data, '\0', *out_size*sizeof(uint8)); + } else { + *data = NULL; + } + return ERROR_INVALID_PARAMETER; } @@ -3102,8 +3111,8 @@ uint32 _spoolss_fcpn(const POLICY_HND *handle) Printer->notify.options=0; Printer->notify.localmachine[0]='\0'; Printer->notify.printerlocal=0; - safe_free(Printer->notify.option); safe_free(Printer->notify.option->ctr.type); + safe_free(Printer->notify.option); Printer->notify.option=NULL; return NT_STATUS_NO_PROBLEMO; -- cgit From 84aa9ad0493ede5acf6b1bbf901b3cbb980c5dbc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 6 Jun 2000 01:34:20 +0000 Subject: Create elements in default, not in read. Jeremy. (This used to be commit 0d681ea252e0cf7fdf57d316d2bfe7caa9b4fbf5) --- source3/rpc_server/srv_spoolss_nt.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 8dca09dc95..5793d5a137 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1917,9 +1917,7 @@ static BOOL construct_printer_info_2(fstring servername, PRINTER_INFO_2 *printer init_unistr(&printer->datatype, ntprinter->info_2->datatype); /* datatype */ init_unistr(&printer->parameters, ntprinter->info_2->parameters); /* parameters (of print processor) */ - printer->attributes = PRINTER_ATTRIBUTE_SHARED \ - | PRINTER_ATTRIBUTE_LOCAL \ - | PRINTER_ATTRIBUTE_RAW_ONLY ; /* attributes */ + printer->attributes = ntprinter->info_2->attributes; printer->priority = ntprinter->info_2->priority; /* priority */ printer->defaultpriority = ntprinter->info_2->default_priority; /* default priority */ -- cgit From d253db1b9a10644940650cc802feb2a509adbaed Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 6 Jun 2000 20:44:58 +0000 Subject: Memory leak fixes. Jeremy. (This used to be commit 34b63896ab1543936d6b9b382ef6727a161b6bf2) --- source3/rpc_server/srv_spoolss_nt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 5793d5a137..b341dbe12a 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3109,7 +3109,8 @@ uint32 _spoolss_fcpn(const POLICY_HND *handle) Printer->notify.options=0; Printer->notify.localmachine[0]='\0'; Printer->notify.printerlocal=0; - safe_free(Printer->notify.option->ctr.type); + if (Printer->notify.option) + safe_free(Printer->notify.option->ctr.type); safe_free(Printer->notify.option); Printer->notify.option=NULL; -- cgit From 0164047afbd082b0003147845a72ca08b4781b81 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 7 Jun 2000 01:49:23 +0000 Subject: Fixing get/set of security descriptors. Removed ugly hack for NT printing. Fixed up tdb parse stuff memory leaks. Jeremy. (This used to be commit 8ef41f31c53e14ad057d883810a1cd2301fede2a) --- source3/rpc_server/srv_spoolss_nt.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index b341dbe12a..e3552c3879 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1971,6 +1971,8 @@ static BOOL construct_printer_info_3(fstring servername, DEBUG(0,("construct_printer_info_3: malloc fail.\n")); return False; } + + ZERO_STRUCTP(printer); printer->flags = 4; /* This is the offset to the SEC_DESC. */ if (ntprinter->info_2->secdesc_buf->len != 0) { -- cgit From e83ddf6e695f6d250c3ebbaa279a19f7f9484fb4 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 16 Jun 2000 08:18:09 +0000 Subject: Simplified server pipe implementation by changing arguments passed down through to the individual pipe api calls. Instead of passing two prs_struct pointers, we now pass the pipes_struct pointer which contains the former information as well as other useful stuff like the vuid. Pass the vuid from the pipes_struct down to the lower level spoolss functions to perform security checks. ZERO_STRUCTP the info_2 structure before filling it. Free the device mode field before freeing the info_2 to avoid a memory leak. Fixed uninitialised pointer bug in fill_job_info_2(). (This used to be commit a9547b7e3a068941cda5619f05a64e798584535a) --- source3/rpc_server/srv_spoolss_nt.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index e3552c3879..90536daedf 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2852,7 +2852,7 @@ uint32 _spoolss_endpageprinter(const POLICY_HND *handle) * ********************************************************************/ uint32 _spoolss_startdocprinter( const POLICY_HND *handle, uint32 level, - DOC_INFO *docinfo, uint32 *jobid) + uint32 vuid, DOC_INFO *docinfo, uint32 *jobid) { DOC_INFO_1 *info_1 = &docinfo->doc_info_1; int snum; @@ -2895,7 +2895,7 @@ uint32 _spoolss_startdocprinter( const POLICY_HND *handle, uint32 level, unistr2_to_ascii(jobname, &info_1->docname, sizeof(jobname)); - Printer->jobid = print_job_start(snum, jobname); + Printer->jobid = print_job_start(snum, vuid, jobname); /* need to map error codes properly - for now give out of memory as I don't know the correct codes (tridge) */ @@ -2956,7 +2956,8 @@ uint32 _spoolss_writeprinter( const POLICY_HND *handle, * called from the spoolss dispatcher * ********************************************************************/ -static uint32 control_printer(const POLICY_HND *handle, uint32 command) +static uint32 control_printer(const POLICY_HND *handle, uint32 command, + uint16 vuid) { int snum; Printer_entry *Printer = find_printer_index_by_hnd(handle); @@ -2969,18 +2970,18 @@ static uint32 control_printer(const POLICY_HND *handle, uint32 command) switch (command) { case PRINTER_CONTROL_PAUSE: - if (print_queue_pause(snum)) { + if (print_queue_pause(snum, vuid)) { return 0; } break; case PRINTER_CONTROL_RESUME: case PRINTER_CONTROL_UNPAUSE: - if (print_queue_resume(snum)) { + if (print_queue_resume(snum, vuid)) { return 0; } break; case PRINTER_CONTROL_PURGE: - if (print_queue_purge(snum)) { + if (print_queue_purge(snum, vuid)) { return 0; } break; @@ -3074,7 +3075,7 @@ uint32 _spoolss_setprinter(const POLICY_HND *handle, uint32 level, const SPOOL_PRINTER_INFO_LEVEL *info, DEVMODE_CTR devmode_ctr, SEC_DESC_BUF *secdesc_ctr, - uint32 command) + uint32 command, uint16 vuid) { Printer_entry *Printer = find_printer_index_by_hnd(handle); @@ -3084,7 +3085,7 @@ uint32 _spoolss_setprinter(const POLICY_HND *handle, uint32 level, /* check the level */ switch (level) { case 0: - return control_printer(handle, command); + return control_printer(handle, command, vuid); break; case 2: return update_printer(handle, level, info, devmode_ctr.devmode); @@ -3162,7 +3163,6 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, int position, int snum) { pstring temp_name; - DEVICEMODE *devmode; NT_PRINTER_INFO_LEVEL *ntprinter = NULL; pstring chaine; @@ -3208,7 +3208,6 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, return False; } - job_info->devmode=devmode; free_a_printer(&ntprinter, 2); return (True); } @@ -3357,6 +3356,7 @@ uint32 _spoolss_schedulejob( const POLICY_HND *handle, uint32 jobid) uint32 _spoolss_setjob( const POLICY_HND *handle, uint32 jobid, uint32 level, + uint32 vuid, JOB_INFO *ctr, uint32 command) @@ -3377,13 +3377,13 @@ uint32 _spoolss_setjob( const POLICY_HND *handle, switch (command) { case JOB_CONTROL_CANCEL: case JOB_CONTROL_DELETE: - if (print_job_delete(jobid)) return 0x0; + if (print_job_delete(vuid, jobid)) return 0x0; break; case JOB_CONTROL_PAUSE: - if (print_job_pause(jobid)) return 0x0; + if (print_job_pause(vuid, jobid)) return 0x0; break; case JOB_CONTROL_RESUME: - if (print_job_resume(jobid)) return 0x0; + if (print_job_resume(vuid, jobid)) return 0x0; break; default: return ERROR_INVALID_LEVEL; @@ -4523,9 +4523,11 @@ static uint32 getjob_level_2(print_queue_struct *queue, int count, int snum, uin { int i=0; BOOL found=False; - JOB_INFO_2 *info_2=NULL; + JOB_INFO_2 *info_2; info_2=(JOB_INFO_2 *)malloc(sizeof(JOB_INFO_2)); + ZERO_STRUCTP(info_2); + if (info_2 == NULL) { safe_free(queue); return ERROR_NOT_ENOUGH_MEMORY; @@ -4556,6 +4558,7 @@ static uint32 getjob_level_2(print_queue_struct *queue, int count, int snum, uin new_smb_io_job_info_2("", buffer, info_2, 0); + free_dev_mode(info_2->devmode); safe_free(info_2); if (*needed > offered) -- cgit From 69c75c8a165f05c01d13ba4eddbb970540e44b96 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 20 Jun 2000 23:58:56 +0000 Subject: Fixes for Win2k "add printer driver" INFO_LEVEL_6 was wrong, also some memory fixes. Jeremy. (This used to be commit 2a9e645cbddef1cddc5c978310b7efed492758d2) --- source3/rpc_server/srv_spoolss_nt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 90536daedf..8cff8d68d9 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -577,11 +577,11 @@ static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL *u switch (level) { case 3: printer->info_3=NULL; - uni_2_asc_printer_driver_3(uni->info_3, &(printer->info_3)); + uni_2_asc_printer_driver_3(uni->info_3, &printer->info_3); break; case 6: printer->info_6=NULL; - uni_2_asc_printer_driver_6(uni->info_6, &(printer->info_6)); + uni_2_asc_printer_driver_6(uni->info_6, &printer->info_6); break; default: break; -- cgit From f9e9f98a4a579f24d8ad1804b22bf36ede250e23 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 22 Jun 2000 01:39:17 +0000 Subject: lib/util_unistr.c: Removed ascii_to_unistr() as it does no codepage. Removed unistr_to_ascii() as it was never used. printing/nt_printing.c: Removed "DUMMY.XX" files. rpc_server/srv_spoolss_nt.c: Use dos_PutUniCode() instead of ascii_to_unistr(). Attempted to fix the "return value" size code based on J.F's comments. This needs looking at. Jeremy. (This used to be commit de99011bf3b2a23bd1854a047382a107aaeb9c68) --- source3/rpc_server/srv_spoolss_nt.c | 86 ++++++++++++++----------------------- 1 file changed, 32 insertions(+), 54 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 8cff8d68d9..dc4932fdfc 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -897,8 +897,8 @@ static void spoolss_notify_server_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, p snprintf(temp_name, sizeof(temp_name)-1, "\\\\%s", global_myname); - data->notify_data.data.length=strlen(temp_name); - ascii_to_unistr((char *)data->notify_data.data.string, temp_name, sizeof(data->notify_data.data.string)-1); + data->notify_data.data.length= (uint32)((dos_PutUniCode((char *)data->notify_data.data.string, + temp_name, sizeof(data->notify_data.data.string), True) - sizeof(uint16))/sizeof(uint16)); } /******************************************************************* @@ -910,12 +910,10 @@ static void spoolss_notify_printer_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, { /* data->notify_data.data.length=strlen(lp_servicename(snum)); - ascii_to_unistr(data->notify_data.data.string, lp_servicename(snum), sizeof(data->notify_data.data.string)-1); + dos_PutUniCode(data->notify_data.data.string, lp_servicename(snum), sizeof(data->notify_data.data.string), True); */ - data->notify_data.data.length=strlen(printer->info_2->printername); - ascii_to_unistr((char *)data->notify_data.data.string, - printer->info_2->printername, - sizeof(data->notify_data.data.string)-1); + data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, + printer->info_2->printername, sizeof(data->notify_data.data.string), True) - sizeof(uint16))/sizeof(uint16)); } /******************************************************************* @@ -923,10 +921,8 @@ static void spoolss_notify_printer_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, ********************************************************************/ static void spoolss_notify_share_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { - data->notify_data.data.length=strlen(lp_servicename(snum)); - ascii_to_unistr((char *)data->notify_data.data.string, - lp_servicename(snum), - sizeof(data->notify_data.data.string)-1); + data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, + lp_servicename(snum), sizeof(data->notify_data.data.string),True) - sizeof(uint16))/sizeof(uint16)); } /******************************************************************* @@ -936,10 +932,8 @@ static void spoolss_notify_port_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, pri { /* even if it's strange, that's consistant in all the code */ - data->notify_data.data.length=strlen(lp_servicename(snum)); - ascii_to_unistr((char *)data->notify_data.data.string, - lp_servicename(snum), - sizeof(data->notify_data.data.string)-1); + data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, + lp_servicename(snum), sizeof(data->notify_data.data.string), True) - sizeof(uint16))/sizeof(uint16)); } /******************************************************************* @@ -949,10 +943,8 @@ static void spoolss_notify_port_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, pri ********************************************************************/ static void spoolss_notify_driver_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { - data->notify_data.data.length=strlen(printer->info_2->drivername); - ascii_to_unistr((char *)data->notify_data.data.string, - printer->info_2->drivername, - sizeof(data->notify_data.data.string)-1); + data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, + printer->info_2->drivername, sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16)); } /******************************************************************* @@ -960,10 +952,8 @@ static void spoolss_notify_driver_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, p ********************************************************************/ static void spoolss_notify_comment(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { - data->notify_data.data.length=strlen(lp_comment(snum)); - ascii_to_unistr((char *)data->notify_data.data.string, - lp_comment(snum), - sizeof(data->notify_data.data.string)-1); + data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, + lp_comment(snum), sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16)); } /******************************************************************* @@ -973,10 +963,8 @@ static void spoolss_notify_comment(int snum, SPOOL_NOTIFY_INFO_DATA *data, print ********************************************************************/ static void spoolss_notify_location(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { - data->notify_data.data.length=strlen(printer->info_2->location); - ascii_to_unistr((char *)data->notify_data.data.string, - printer->info_2->location, - sizeof(data->notify_data.data.string)-1); + data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, + printer->info_2->location, sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16)); } /******************************************************************* @@ -994,10 +982,8 @@ static void spoolss_notify_devmode(int snum, SPOOL_NOTIFY_INFO_DATA *data, print ********************************************************************/ static void spoolss_notify_sepfile(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { - data->notify_data.data.length=strlen(printer->info_2->sepfile); - ascii_to_unistr((char *)data->notify_data.data.string, - printer->info_2->sepfile, - sizeof(data->notify_data.data.string)-1); + data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, + printer->info_2->sepfile, sizeof(data->notify_data.data.string)-1,True) - sizeof(uint16))/sizeof(uint16)); } /******************************************************************* @@ -1006,10 +992,8 @@ static void spoolss_notify_sepfile(int snum, SPOOL_NOTIFY_INFO_DATA *data, print ********************************************************************/ static void spoolss_notify_print_processor(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { - data->notify_data.data.length=strlen(printer->info_2->printprocessor); - ascii_to_unistr((char *)data->notify_data.data.string, - printer->info_2->printprocessor, - sizeof(data->notify_data.data.string)-1); + data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, + printer->info_2->printprocessor, sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16)); } /******************************************************************* @@ -1018,10 +1002,8 @@ static void spoolss_notify_print_processor(int snum, SPOOL_NOTIFY_INFO_DATA *dat ********************************************************************/ static void spoolss_notify_parameters(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { - data->notify_data.data.length=strlen(printer->info_2->parameters); - ascii_to_unistr((char *)data->notify_data.data.string, - printer->info_2->parameters, - sizeof(data->notify_data.data.string)-1); + data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, + printer->info_2->parameters, sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16)); } /******************************************************************* @@ -1030,10 +1012,8 @@ static void spoolss_notify_parameters(int snum, SPOOL_NOTIFY_INFO_DATA *data, pr ********************************************************************/ static void spoolss_notify_datatype(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { - data->notify_data.data.length=strlen(printer->info_2->datatype); - ascii_to_unistr((char *)data->notify_data.data.string, - printer->info_2->datatype, - sizeof(data->notify_data.data.string)-1); + data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, + printer->info_2->datatype, sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16)); } /******************************************************************* @@ -1133,8 +1113,8 @@ static void spoolss_notify_average_ppm(int snum, SPOOL_NOTIFY_INFO_DATA *data, p ********************************************************************/ static void spoolss_notify_username(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { - data->notify_data.data.length=strlen(queue->user); - ascii_to_unistr((char *)data->notify_data.data.string, queue->user, sizeof(data->notify_data.data.string)-1); + data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, + queue->user, sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16)); } /******************************************************************* @@ -1150,8 +1130,8 @@ static void spoolss_notify_job_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, pr ********************************************************************/ static void spoolss_notify_job_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { - data->notify_data.data.length=strlen(queue->file); - ascii_to_unistr((char *)data->notify_data.data.string, queue->file, sizeof(data->notify_data.data.string)-1); + data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, + queue->file, sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16)); } /******************************************************************* @@ -1174,8 +1154,8 @@ static void spoolss_notify_job_status_string(int snum, SPOOL_NOTIFY_INFO_DATA *d p = "PRINTING"; break; } - data->notify_data.data.length=strlen(p); - ascii_to_unistr((char *)data->notify_data.data.string, p, sizeof(data->notify_data.data.string)-1); + data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, + p, sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16)); } /******************************************************************* @@ -2598,8 +2578,7 @@ static void init_unistr_array(uint16 **uni_array, fstring *char_array, char *whe DEBUG(0,("init_unistr_array: Realloc error\n" )); return; } - ascii_to_unistr((char *)(*uni_array+j), line , 2*strlen(line)); - j+=strlen(line)+1; + j += (dos_PutUniCode((char *)(*uni_array+j), line , sizeof(uint16)*strlen(line), True) / sizeof(uint16) ); i++; if (strlen(v) == 0) break; } @@ -4145,13 +4124,12 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx, * take a pause *before* coding not *during* coding */ - *out_max_value_len=in_value_len; + *out_max_value_len=(in_value_len/sizeof(uint16)); if((*out_value=(uint16 *)malloc(in_value_len*sizeof(uint8))) == NULL) { safe_free(data); return ERROR_NOT_ENOUGH_MEMORY; } - ascii_to_unistr((char *)*out_value, value, *out_max_value_len); - *out_value_len=2*(1+strlen(value)); + *out_value_len = (uint32)dos_PutUniCode((char *)*out_value, value, in_value_len, True); *out_type=type; -- cgit From eecab5c66096cc42323aaa4a796bf4a17e491a00 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 22 Jun 2000 23:59:22 +0000 Subject: Changed enumports to show printernames as ports. In line with 'the grand plan' :-) Gerald & I discussed with HP. More changes to follow. Jeremy. (This used to be commit 193a248beda99103c73a0b0ea5e2fbcbb516ce8e) --- source3/rpc_server/srv_spoolss_nt.c | 62 ++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 11 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index dc4932fdfc..b8b25a1ecb 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3653,16 +3653,16 @@ uint32 _new_spoolss_enumforms( const POLICY_HND *handle, uint32 level, ****************************************************************************/ static void fill_port_1(PORT_INFO_1 *port, char *name) { - init_unistr(&(port->port_name), name); + init_unistr(&port->port_name, name); } /**************************************************************************** ****************************************************************************/ static void fill_port_2(PORT_INFO_2 *port, char *name) { - init_unistr(&(port->port_name), name); - init_unistr(&(port->monitor_name), "Moniteur Local"); - init_unistr(&(port->description), "Local Port"); + init_unistr(&port->port_name, name); + init_unistr(&port->monitor_name, "Local Monitor"); + init_unistr(&port->description, "Local Port"); #define PORT_TYPE_WRITE 1 port->port_type=PORT_TYPE_WRITE; port->reserved=0x0; @@ -3688,16 +3688,36 @@ static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need for (snum=0; snum Date: Sat, 24 Jun 2000 00:15:08 +0000 Subject: lib/util_sid.c: Uninitialized memory read. rpc_parse/parse_spoolss.c: Added note about prs_align when marshalling a SEC_DESC... rpc_server/srv_lsa.c: Tim - your changes broke the display of the 'everyone' group when doing file access with no winbindd running. This is a partial fix - more when I have analysed this more. rpc_server/srv_spoolss_nt.c: Fix for the 'change driver' problem ! Hurrah ! Jeremy. (This used to be commit 151b131ee01ef916c072bcdaa9943a2e984a0f45) --- source3/rpc_server/srv_spoolss_nt.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index b8b25a1ecb..d1ff58404e 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -413,7 +413,7 @@ static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) if ( !(lp_snum_ok(snum) && lp_print_ok(snum) ) ) continue; - DEBUGADD(5,("share:%s\n",lp_servicename(snum))); + DEBUGADD(5,("set_printer_hnd_printername: share:%s\n",lp_servicename(snum))); if (get_a_printer(&printer, 2, lp_servicename(snum))!=0) continue; @@ -441,7 +441,9 @@ static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) } snum--; - DEBUGADD(4,("Printer found: %s -> %s[%x]\n",printer->info_2->printername, lp_servicename(snum),snum)); + DEBUGADD(4,("set_printer_hnd_printername: Printer found: %s -> %s[%x]\n", + printer->info_2->printername, lp_servicename(snum),snum)); + ZERO_STRUCT(Printer->dev.printername); strncpy(Printer->dev.printername, lp_servicename(snum), strlen(lp_servicename(snum))); @@ -1667,11 +1669,11 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, fstring /* the description and the name are of the form \\server\share */ slprintf(chaine,sizeof(chaine)-1,"\\\\%s\\%s",servername, ntprinter->info_2->printername); - - init_unistr(&(printer->printername), chaine); + + init_unistr(&printer->printername, chaine); slprintf(chaine,sizeof(chaine)-1,"\\\\%s", servername); - init_unistr(&(printer->servername), chaine); + init_unistr(&printer->servername, chaine); printer->cjobs = count; printer->total_jobs = 0; @@ -1801,8 +1803,8 @@ static DEVICEMODE *construct_dev_mode(int snum, char *servername) goto fail; DEBUGADD(8,("loading DEVICEMODE\n")); - snprintf(adevice, sizeof(adevice), "\\\\%s\\%s", global_myname, - printer->info_2->printername); + snprintf(adevice, sizeof(adevice), "%s", printer->info_2->printername); + init_unistr(&devmode->devicename, adevice); snprintf(aform, sizeof(aform), ntdevmode->formname); -- cgit From 36fd3866efa89b5a537d4cb312e6a0d77ca9b89a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 26 Jun 2000 22:08:20 +0000 Subject: Changing drivers using the properties page works - but only if getting/setting security descriptors is disabled (as it is in this code). If get/set sd's is enabled spooler.exe crashes on NT. I'll investigate and fix that issue next. Jeremy. (This used to be commit 8c9ed874363e6a710bc0fe521bb8c4f7ee219587) --- source3/rpc_server/srv_spoolss_nt.c | 70 +++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 30 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index d1ff58404e..cd5f829a83 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -154,8 +154,7 @@ static Printer_entry *find_printer_index_by_hnd(const POLICY_HND *hnd) for(; find_printer; find_printer = (Printer_entry *)ubi_dlNext(find_printer)) { - if (memcmp(&(find_printer->printer_hnd), hnd, sizeof(*hnd)) == 0) - { + if (memcmp(&(find_printer->printer_hnd), hnd, sizeof(*hnd)) == 0) { DEBUG(4,("Found printer handle \n")); /*dump_data(4, hnd->data, sizeof(hnd->data));*/ return find_printer; @@ -182,8 +181,7 @@ static BOOL close_printer_handle(POLICY_HND *hnd) { Printer_entry *Printer = find_printer_index_by_hnd(hnd); - if (!OPEN_HANDLE(Printer)) - { + if (!OPEN_HANDLE(Printer)) { DEBUG(3,("Error closing printer handle\n")); return False; } @@ -212,8 +210,7 @@ static BOOL delete_printer_handle(POLICY_HND *hnd) { Printer_entry *Printer = find_printer_index_by_hnd(hnd); - if (!OPEN_HANDLE(Printer)) - { + if (!OPEN_HANDLE(Printer)) { DEBUG(3,("Error closing printer handle\n")); return False; } @@ -267,7 +264,7 @@ static BOOL open_printer_hnd(POLICY_HND *hnd) new_printer->open = True; new_printer->notify.option=NULL; - memcpy(&(new_printer->printer_hnd), hnd, sizeof(*hnd)); + memcpy(&new_printer->printer_hnd, hnd, sizeof(*hnd)); ubi_dlAddHead( &Printer_list, (ubi_dlNode *)new_printer); @@ -1797,14 +1794,18 @@ static DEVICEMODE *construct_dev_mode(int snum, char *servername) if (printer->info_2->devmode) ntdevmode = dup_nt_devicemode(printer->info_2->devmode); else - ntdevmode = construct_nt_devicemode(); + ntdevmode = construct_nt_devicemode(printer->info_2->printername); if (ntdevmode == NULL) goto fail; DEBUGADD(8,("loading DEVICEMODE\n")); - snprintf(adevice, sizeof(adevice), "%s", printer->info_2->printername); +#if 1 /* JRATEST */ + snprintf(adevice, sizeof(adevice), "%s", ntdevmode->devicename); +#else /* JRATEST */ + snprintf(adevice, sizeof(adevice), "%s", printer->info_2->printername); +#endif /* JRATEST */ init_unistr(&devmode->devicename, adevice); snprintf(aform, sizeof(aform), ntdevmode->formname); @@ -1912,7 +1913,7 @@ static BOOL construct_printer_info_2(fstring servername, PRINTER_INFO_2 *printer if((printer->devmode = construct_dev_mode(snum, servername)) == NULL) goto err; - if (ntprinter->info_2->secdesc_buf->len != 0) { + if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->len != 0) { /* steal the printer info sec_desc structure. [badly done]. */ printer->secdesc = ntprinter->info_2->secdesc_buf->sec; ntprinter->info_2->secdesc_buf->sec = NULL; /* Stolen memory. */ @@ -1957,7 +1958,7 @@ static BOOL construct_printer_info_3(fstring servername, ZERO_STRUCTP(printer); printer->flags = 4; /* This is the offset to the SEC_DESC. */ - if (ntprinter->info_2->secdesc_buf->len != 0) { + if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->len != 0) { /* steal the printer info sec_desc structure. [badly done]. */ printer->secdesc = ntprinter->info_2->secdesc_buf->sec; ntprinter->info_2->secdesc_buf->sec = NULL; /* Stolen the malloced memory. */ @@ -2574,6 +2575,7 @@ static void init_unistr_array(uint16 **uni_array, fstring *char_array, char *whe v = char_array[i]; if (!v) v = ""; /* hack to handle null lists */ } + if (strlen(v) == 0) break; snprintf(line, sizeof(line)-1, "%s%s", where, v); DEBUGADD(6,("%d:%s:%d\n", i, line, strlen(line))); if((*uni_array=Realloc(*uni_array, (j+strlen(line)+2)*sizeof(uint16))) == NULL) { @@ -2582,7 +2584,6 @@ static void init_unistr_array(uint16 **uni_array, fstring *char_array, char *whe } j += (dos_PutUniCode((char *)(*uni_array+j), line , sizeof(uint16)*strlen(line), True) / sizeof(uint16) ); i++; - if (strlen(v) == 0) break; } if (*uni_array) { @@ -2613,23 +2614,23 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, info->version=driver.info_3->cversion; - init_unistr( &(info->name), driver.info_3->name ); - init_unistr( &(info->architecture), architecture ); + init_unistr( &info->name, driver.info_3->name ); + init_unistr( &info->architecture, architecture ); snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "%s%s", where, driver.info_3->driverpath); - init_unistr( &(info->driverpath), temp_driverpath ); + init_unistr( &info->driverpath, temp_driverpath ); snprintf(temp_datafile, sizeof(temp_datafile)-1, "%s%s", where, driver.info_3->datafile); - init_unistr( &(info->datafile), temp_datafile ); + init_unistr( &info->datafile, temp_datafile ); snprintf(temp_configfile, sizeof(temp_configfile)-1, "%s%s", where, driver.info_3->configfile); - init_unistr( &(info->configfile), temp_configfile ); + init_unistr( &info->configfile, temp_configfile ); snprintf(temp_helpfile, sizeof(temp_helpfile)-1, "%s%s", where, driver.info_3->helpfile); - init_unistr( &(info->helpfile), temp_helpfile ); + init_unistr( &info->helpfile, temp_helpfile ); - init_unistr( &(info->monitorname), driver.info_3->monitorname ); - init_unistr( &(info->defaultdatatype), driver.info_3->defaultdatatype ); + init_unistr( &info->monitorname, driver.info_3->monitorname ); + init_unistr( &info->defaultdatatype, driver.info_3->defaultdatatype ); info->dependentfiles=NULL; init_unistr_array(&info->dependentfiles, driver.info_3->dependentfiles, where); @@ -3014,25 +3015,34 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, if (!get_printer_snum(handle, &snum) ) return ERROR_INVALID_HANDLE; - get_a_printer(&printer, 2, lp_servicename(snum)); + if(get_a_printer(&printer, 2, lp_servicename(snum)) != 0) + return ERROR_INVALID_HANDLE; DEBUGADD(8,("Converting info_2 struct\n")); + + /* + * convert_printer_info converts the incoming + * info from the client and overwrites the info + * just read from the tdb in the pointer 'printer'. + */ + convert_printer_info(info, printer, level); if (info->info_2->devmode_ptr != 0) { - NT_DEVICEMODE *ntdevmode = NULL; /* we have a valid devmode convert it and link it*/ + + /* + * Ensure printer->info_2->devmode is a valid pointer + * as we will be overwriting it in convert_devicemode(). + */ + if (printer->info_2->devmode == NULL) + printer->info_2->devmode = construct_nt_devicemode(printer->info_2->printername); + DEBUGADD(8,("Converting the devicemode struct\n")); - if (printer->info_2->devmode) { - ntdevmode = dup_nt_devicemode(printer->info_2->devmode); - } else { - ntdevmode = construct_nt_devicemode(); - } - - convert_devicemode(devmode, ntdevmode); - free_nt_devicemode(&ntdevmode); + convert_devicemode(devmode, printer->info_2->devmode); + } else { if (printer->info_2->devmode != NULL) free_nt_devicemode(&printer->info_2->devmode); -- cgit From 774b06ee212ee764fb2e17c1f366d0de552c07cc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 29 Jun 2000 00:52:40 +0000 Subject: Tidy up current spool code - added some JRATEST ifdefs to allow experimentation with what is making spoolss.exe crash - may be removed later. Jeremy. (This used to be commit f3fe384dc39ce49c639a7adf35179a50cb86abf0) --- source3/rpc_server/srv_spoolss_nt.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index cd5f829a83..7259ccc428 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1356,8 +1356,7 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPO if (get_a_printer(&printer, 2, lp_servicename(snum))!=0) return False; - for(field_num=0; field_numcount; field_num++) - { + for(field_num=0; field_numcount; field_num++) { field = option_type->fields[field_num]; DEBUGADD(4,("notify [%d]: type [%x], field [%x]\n", field_num, type, field)); @@ -1367,7 +1366,7 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPO if((info->data=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) { return False; } - current_data=&(info->data[info->count]); + current_data=&info->data[info->count]; construct_info_data(current_data, type, field, id); notify_info_data_table[j].fn(snum, current_data, queue, printer); @@ -1474,8 +1473,7 @@ static uint32 printserver_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO * info->data=NULL; info->count=0; - for (i=0; icount; i++) - { + for (i=0; icount; i++) { option_type=&(option->ctr.type[i]); if (option_type->type!=PRINTER_NOTIFY_TYPE) @@ -1495,8 +1493,7 @@ static uint32 printserver_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO * DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count)); DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n")); - for (i=0; icount; i++) - { + for (i=0; icount; i++) { DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n", i, info->data[i].type, info->data[i].field, info->data[i].reserved, info->data[i].id, info->data[i].size, info->data[i].enc_type)); @@ -1533,9 +1530,8 @@ static uint32 printer_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info get_printer_snum(hnd, &snum); - for (i=0; icount; i++) - { - option_type=&(option->ctr.type[i]); + for (i=0; icount; i++) { + option_type=&option->ctr.type[i]; switch ( option_type->type ) { case PRINTER_NOTIFY_TYPE: @@ -1547,7 +1543,7 @@ static uint32 printer_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info memset(&status, 0, sizeof(status)); count = print_queue_status(snum, &queue, &status); for (j=0; jversion:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count)); DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n")); - for (i=0; icount; i++) - { + for (i=0; icount; i++) { DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n", i, info->data[i].type, info->data[i].field, info->data[i].reserved, info->data[i].id, info->data[i].size, info->data[i].enc_type)); @@ -2150,7 +2145,7 @@ static BOOL enum_all_printers_info_2(fstring servername, NEW_BUFFER *buffer, uin if((printers=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_2))) == NULL) return ERROR_NOT_ENOUGH_MEMORY; DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_2\n", *returned)); - memcpy(&(printers[*returned]), ¤t_prt, sizeof(PRINTER_INFO_2)); + memcpy(&printers[*returned], ¤t_prt, sizeof(PRINTER_INFO_2)); (*returned)++; } } @@ -4119,7 +4114,7 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx, if (!get_printer_snum(handle, &snum)) return ERROR_INVALID_HANDLE; - if (get_a_printer(&printer, 2, lp_servicename(snum)) != 0x0) + if (get_a_printer(&printer, 2, lp_servicename(snum)) != 0) return ERROR_INVALID_HANDLE; /* @@ -4182,6 +4177,9 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx, return ERROR_NOT_ENOUGH_MEMORY; } *out_value_len = (uint32)dos_PutUniCode((char *)*out_value, value, in_value_len, True); +#if 1 /* JRATEST */ + *out_max_value_len=(*out_value_len/sizeof(uint16)); +#endif /* JRATEST */ *out_type=type; @@ -4191,8 +4189,11 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx, safe_free(data); return ERROR_NOT_ENOUGH_MEMORY; } - memcpy(*data_out, data, data_len); + memcpy(*data_out, data, (size_t)data_len); *out_data_len=data_len; +#if 1 /* JRATEST */ + *out_max_data_len=data_len; +#endif /* JRATEST */ safe_free(data); -- cgit From eed5e03043f851c299a572f5979f6c52d51b1d11 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 30 Jun 2000 01:07:26 +0000 Subject: Fixed oops with missing MANGLE_PATH directive. Jeremy. (This used to be commit fb6b5a964512dec37f85f8de39c0c06f702aabbd) --- source3/rpc_server/srv_spoolss_nt.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 7259ccc428..79f6030414 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2605,7 +2605,11 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, get_short_archi(short_archi, architecture); +#if MANGLE_DRIVER_PATH snprintf(where,sizeof(where)-1,"\\\\%s\\print$\\%s\\%s\\", servername, short_archi, driver.info_3->name); +#else + snprintf(where,sizeof(where)-1,"\\\\%s\\print$\\%s\\", servername, short_archi); +#endif info->version=driver.info_3->cversion; @@ -3502,7 +3506,7 @@ static uint32 enumprinterdrivers_level3(fstring *list, fstring servername, fstri /* check the required size. */ for (i=0; i<*returned; i++) { DEBUGADD(6,("adding driver [%d]'s size\n",i)); - *needed += spoolss_size_printer_driver_info_3(&(driver_info_3[i])); + *needed += spoolss_size_printer_driver_info_3(&driver_info_3[i]); } if (!alloc_buffer_size(buffer, *needed)) { @@ -3513,7 +3517,7 @@ static uint32 enumprinterdrivers_level3(fstring *list, fstring servername, fstri /* fill the buffer with the form structures */ for (i=0; i<*returned; i++) { DEBUGADD(6,("adding form [%d] to buffer\n",i)); - new_smb_io_printer_driver_info_3("", buffer, &(driver_info_3[i]), 0); + new_smb_io_printer_driver_info_3("", buffer, &driver_info_3[i], 0); } for (i=0; i<*returned; i++) -- cgit From 104217f3b05aa206b37ab6af0899dbe71d142d2e Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Sat, 1 Jul 2000 09:34:37 +0000 Subject: Found that the minimum priority is 1 and not 0 on NT. Changed back the devicemode's devicename to "\\server\printer". I'm 100% sure it is correct, it's what NT sends on the wire. And that's the printer's name and NOT the port's name as it has to be unique. It must also be a UNC because it's a remote printer (remote for the client). J.F. (This used to be commit a7098c47b6ecbd7bb5df1330ea176aa4d463aad3) --- source3/rpc_server/srv_spoolss_nt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 79f6030414..2e153b26c5 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1033,7 +1033,7 @@ static void spoolss_notify_security_desc(int snum, SPOOL_NOTIFY_INFO_DATA *data, static void spoolss_notify_attributes(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { data->notify_data.value[0] = PRINTER_ATTRIBUTE_SHARED \ - | PRINTER_ATTRIBUTE_NETWORK \ + | PRINTER_ATTRIBUTE_LOCAL \ | PRINTER_ATTRIBUTE_RAW_ONLY ; } @@ -1796,10 +1796,10 @@ static DEVICEMODE *construct_dev_mode(int snum, char *servername) DEBUGADD(8,("loading DEVICEMODE\n")); -#if 1 /* JRATEST */ - snprintf(adevice, sizeof(adevice), "%s", ntdevmode->devicename); +#if 0 /* JRATEST */ + snprintf(adevice, sizeof(adevice), "\\\\%s\\%s", global_myname, ntdevmode->devicename); #else /* JRATEST */ - snprintf(adevice, sizeof(adevice), "%s", printer->info_2->printername); + snprintf(adevice, sizeof(adevice), "\\\\%s\\%s", global_myname, printer->info_2->printername); #endif /* JRATEST */ init_unistr(&devmode->devicename, adevice); -- cgit From 2d2b6a46f7d6430ee274eed70ba488338a32861a Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Sat, 1 Jul 2000 16:40:10 +0000 Subject: reverting Jeremy's changes to enumprinterdata. Jeremy, the out_max_value_len and out_max_data_len were good. Your change is breaking NT4SP6 checked version. J.F. (This used to be commit 5f2be8ba7dcd1eacc169e8d1d53c309e45a5cce6) --- source3/rpc_server/srv_spoolss_nt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 2e153b26c5..c31fd8ebf5 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4181,7 +4181,7 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx, return ERROR_NOT_ENOUGH_MEMORY; } *out_value_len = (uint32)dos_PutUniCode((char *)*out_value, value, in_value_len, True); -#if 1 /* JRATEST */ +#if 0 /* JRATEST */ *out_max_value_len=(*out_value_len/sizeof(uint16)); #endif /* JRATEST */ @@ -4195,7 +4195,7 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx, } memcpy(*data_out, data, (size_t)data_len); *out_data_len=data_len; -#if 1 /* JRATEST */ +#if 0 /* JRATEST */ *out_max_data_len=data_len; #endif /* JRATEST */ -- cgit From d01839e49ec6858c3b0929ad6038a3ff62ac4271 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 6 Jul 2000 06:53:47 +0000 Subject: Pass either an authenticated pipe or SMB user in a current_user struct down to the printing back end functions. (This used to be commit a2751a269e05d5e46d4b22d6082a5898cdb4526f) --- source3/rpc_server/srv_spoolss_nt.c | 51 +++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 13 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index c31fd8ebf5..92babf37d1 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2832,20 +2832,29 @@ uint32 _spoolss_endpageprinter(const POLICY_HND *handle) * called from the spoolss dispatcher * ********************************************************************/ -uint32 _spoolss_startdocprinter( const POLICY_HND *handle, uint32 level, - uint32 vuid, DOC_INFO *docinfo, uint32 *jobid) +uint32 _spoolss_startdocprinter(const POLICY_HND *handle, uint32 level, + pipes_struct *p, DOC_INFO *docinfo, + uint32 *jobid) { DOC_INFO_1 *info_1 = &docinfo->doc_info_1; int snum; pstring jobname; fstring datatype; Printer_entry *Printer = find_printer_index_by_hnd(handle); + struct current_user user; if (!OPEN_HANDLE(Printer)) { return ERROR_INVALID_HANDLE; } + if (p->ntlmssp_auth_validated) { + memcpy(&user, &p->pipe_user, sizeof(user)); + } else { + extern struct current_user current_user; + memcpy(&user, ¤t_user, sizeof(user)); + } + /* * a nice thing with NT is it doesn't listen to what you tell it. * when asked to send _only_ RAW datas, it tries to send datas @@ -2876,7 +2885,7 @@ uint32 _spoolss_startdocprinter( const POLICY_HND *handle, uint32 level, unistr2_to_ascii(jobname, &info_1->docname, sizeof(jobname)); - Printer->jobid = print_job_start(snum, vuid, jobname); + Printer->jobid = print_job_start(&user, snum, jobname); /* need to map error codes properly - for now give out of memory as I don't know the correct codes (tridge) */ @@ -2938,11 +2947,19 @@ uint32 _spoolss_writeprinter( const POLICY_HND *handle, * ********************************************************************/ static uint32 control_printer(const POLICY_HND *handle, uint32 command, - uint16 vuid) + pipes_struct *p) { + struct current_user user; int snum; Printer_entry *Printer = find_printer_index_by_hnd(handle); + if (p->ntlmssp_auth_validated) { + memcpy(&user, &p->pipe_user, sizeof(user)); + } else { + extern struct current_user current_user; + memcpy(&user, ¤t_user, sizeof(user)); + } + if (!OPEN_HANDLE(Printer)) return ERROR_INVALID_HANDLE; @@ -2951,18 +2968,18 @@ static uint32 control_printer(const POLICY_HND *handle, uint32 command, switch (command) { case PRINTER_CONTROL_PAUSE: - if (print_queue_pause(snum, vuid)) { + if (print_queue_pause(&user, snum)) { return 0; } break; case PRINTER_CONTROL_RESUME: case PRINTER_CONTROL_UNPAUSE: - if (print_queue_resume(snum, vuid)) { + if (print_queue_resume(&user, snum)) { return 0; } break; case PRINTER_CONTROL_PURGE: - if (print_queue_purge(snum, vuid)) { + if (print_queue_purge(&user, snum)) { return 0; } break; @@ -3065,7 +3082,7 @@ uint32 _spoolss_setprinter(const POLICY_HND *handle, uint32 level, const SPOOL_PRINTER_INFO_LEVEL *info, DEVMODE_CTR devmode_ctr, SEC_DESC_BUF *secdesc_ctr, - uint32 command, uint16 vuid) + uint32 command, pipes_struct *p) { Printer_entry *Printer = find_printer_index_by_hnd(handle); @@ -3075,7 +3092,7 @@ uint32 _spoolss_setprinter(const POLICY_HND *handle, uint32 level, /* check the level */ switch (level) { case 0: - return control_printer(handle, command, vuid); + return control_printer(handle, command, p); break; case 2: return update_printer(handle, level, info, devmode_ctr.devmode); @@ -3346,11 +3363,12 @@ uint32 _spoolss_schedulejob( const POLICY_HND *handle, uint32 jobid) uint32 _spoolss_setjob( const POLICY_HND *handle, uint32 jobid, uint32 level, - uint32 vuid, + pipes_struct *p, JOB_INFO *ctr, uint32 command) { + struct current_user user; int snum; print_status_struct prt_status; @@ -3364,16 +3382,23 @@ uint32 _spoolss_setjob( const POLICY_HND *handle, return ERROR_INVALID_PRINTER_NAME; } + if (p->ntlmssp_auth_validated) { + memcpy(&user, &p->pipe_user, sizeof(user)); + } else { + extern struct current_user current_user; + memcpy(&user, ¤t_user, sizeof(user)); + } + switch (command) { case JOB_CONTROL_CANCEL: case JOB_CONTROL_DELETE: - if (print_job_delete(vuid, jobid)) return 0x0; + if (print_job_delete(&user, jobid)) return 0x0; break; case JOB_CONTROL_PAUSE: - if (print_job_pause(vuid, jobid)) return 0x0; + if (print_job_pause(&user, jobid)) return 0x0; break; case JOB_CONTROL_RESUME: - if (print_job_resume(vuid, jobid)) return 0x0; + if (print_job_resume(&user, jobid)) return 0x0; break; default: return ERROR_INVALID_LEVEL; -- cgit From 89eafd3ceffc7b4965133f6ddc059a134eaffb61 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 6 Jul 2000 23:31:46 +0000 Subject: printing/nt_printing.c: (From JF) use the driver name - already given to us. printing/printing.c: priority needs to be 1 not zero (found by checked build). rpc_server/srv_spoolss_nt.c: Log invalid handle access, also print out if this is a different pid handle. This will help track down client access after a connection is closed. Jeremy. (This used to be commit 4ff949228c40b6abb2008df8db985562ac2895d2) --- source3/rpc_server/srv_spoolss_nt.c | 109 ++++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 47 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 92babf37d1..522a266b8c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -84,7 +84,8 @@ static ubi_dlList Printer_list; static ubi_dlList counter_list; -#define OPEN_HANDLE(pnum) ((pnum!=NULL) && (pnum->open!=False)) +#define OPEN_HANDLE(pnum) ((pnum!=NULL) && (pnum->open!=False) && (IVAL(pnum->printer_hnd.data,16)==(uint32)sys_getpid())) +#define OUR_HANDLE(pnum) ((pnum==NULL)?"NULL":(IVAL(pnum->data,16)==sys_getpid()?"OURS":"OTHER")) /* translate between internal status numbers and NT status numbers */ static int nt_printj_status(int v) @@ -182,7 +183,7 @@ static BOOL close_printer_handle(POLICY_HND *hnd) Printer_entry *Printer = find_printer_index_by_hnd(hnd); if (!OPEN_HANDLE(Printer)) { - DEBUG(3,("Error closing printer handle\n")); + DEBUG(0,("close_printer_handle: Invalid handle (%s)\n", OUR_HANDLE(hnd))); return False; } @@ -211,7 +212,7 @@ static BOOL delete_printer_handle(POLICY_HND *hnd) Printer_entry *Printer = find_printer_index_by_hnd(hnd); if (!OPEN_HANDLE(Printer)) { - DEBUG(3,("Error closing printer handle\n")); + DEBUG(0,("delete_printer_handle: Invalid handle (%s)\n", OUR_HANDLE(hnd))); return False; } @@ -231,7 +232,7 @@ static BOOL get_printer_snum(const POLICY_HND *hnd, int *number) Printer_entry *Printer = find_printer_index_by_hnd(hnd); if (!OPEN_HANDLE(Printer)) { - DEBUG(3,("Error getting printer - take a nap quickly !\n")); + DEBUG(0,("get_printer_snum: Invalid handle (%s)\n", OUR_HANDLE(hnd))); return False; } @@ -279,7 +280,7 @@ static BOOL set_printer_hnd_accesstype(POLICY_HND *hnd, uint32 access_required) Printer_entry *Printer = find_printer_index_by_hnd(hnd); if (!OPEN_HANDLE(Printer)) { - DEBUG(4,("Error setting printer type=%x", access_required)); + DEBUG(0,("set_printer_hnd_accesstype: Invalid handle (%s)", OUR_HANDLE(hnd))); return False; } @@ -297,7 +298,7 @@ static BOOL set_printer_hnd_printertype(POLICY_HND *hnd, char *printername) Printer_entry *Printer = find_printer_index_by_hnd(hnd); if (!OPEN_HANDLE(Printer)) { - DEBUGADD(4,("Error setting printer name %s", printername)); + DEBUG(0,("set_printer_hnd_printertype: Invalid handle (%s)", OUR_HANDLE(hnd))); return False; } @@ -337,7 +338,7 @@ static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) BOOL found=False; if (!OPEN_HANDLE(Printer)) { - DEBUG(0,("Error setting printer name=%s\n", printername)); + DEBUG(0,("set_printer_hnd_printername: Invalid handle (%s)\n", OUR_HANDLE(hnd))); return False; } @@ -754,8 +755,10 @@ static BOOL getprinterdata_printer(const POLICY_HND *handle, DEBUG(5,("getprinterdata_printer\n")); - if (!OPEN_HANDLE(Printer)) + if (!OPEN_HANDLE(Printer)) { + DEBUG(0,("getprinterdata_printer: Invalid handle (%s).\n", OUR_HANDLE(handle))); return False; + } if(!get_printer_snum(handle, &snum)) return False; @@ -825,6 +828,7 @@ uint32 _spoolss_getprinterdata(const POLICY_HND *handle, UNISTR2 *valuename, if (!OPEN_HANDLE(Printer)) { if((*data=(uint8 *)malloc(4*sizeof(uint8))) == NULL) return ERROR_NOT_ENOUGH_MEMORY; + DEBUG(0,("_spoolss_getprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; } @@ -874,8 +878,10 @@ uint32 _spoolss_rffpcnex(const POLICY_HND *handle, uint32 flags, uint32 options, Printer_entry *Printer=find_printer_index_by_hnd(handle); - if (!OPEN_HANDLE(Printer)) + if (!OPEN_HANDLE(Printer)) { + DEBUG(0,("_spoolss_rffpcnex: Invalid handle (%s).\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; + } Printer->notify.flags=flags; Printer->notify.options=options; @@ -1574,8 +1580,10 @@ uint32 _spoolss_rfnpcnex( const POLICY_HND *handle, uint32 change, { Printer_entry *Printer=find_printer_index_by_hnd(handle); - if (!OPEN_HANDLE(Printer)) + if (!OPEN_HANDLE(Printer)) { + DEBUG(0,("_spoolss_rfnpcnex: Invalid handle (%s).\n",OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; + } DEBUG(4,("Printer type %x\n",Printer->printer_type)); @@ -1796,11 +1804,7 @@ static DEVICEMODE *construct_dev_mode(int snum, char *servername) DEBUGADD(8,("loading DEVICEMODE\n")); -#if 0 /* JRATEST */ - snprintf(adevice, sizeof(adevice), "\\\\%s\\%s", global_myname, ntdevmode->devicename); -#else /* JRATEST */ snprintf(adevice, sizeof(adevice), "\\\\%s\\%s", global_myname, printer->info_2->printername); -#endif /* JRATEST */ init_unistr(&devmode->devicename, adevice); snprintf(aform, sizeof(aform), ntdevmode->formname); @@ -1886,7 +1890,12 @@ static BOOL construct_printer_info_2(fstring servername, PRINTER_INFO_2 *printer init_unistr(&printer->servername, chaine); /* servername*/ init_unistr(&printer->printername, chaine2); /* printername*/ init_unistr(&printer->sharename, lp_servicename(snum)); /* sharename */ +#if 1 /* JRATEST */ + /* We need to determine the correct model for this..... */ + init_unistr(&printer->portname, lp_printername(snum)); /* port */ +#else init_unistr(&printer->portname, lp_servicename(snum)); /* port */ +#endif init_unistr(&printer->drivername, ntprinter->info_2->drivername); /* drivername */ init_unistr(&printer->comment, lp_comment(snum)); /* comment */ init_unistr(&printer->location, ntprinter->info_2->location); /* location */ @@ -2799,8 +2808,7 @@ uint32 _spoolss_startpageprinter(const POLICY_HND *handle) { Printer_entry *Printer = find_printer_index_by_hnd(handle); - if (OPEN_HANDLE(Printer)) - { + if (OPEN_HANDLE(Printer)) { Printer->page_started=True; return 0x0; } @@ -2815,9 +2823,8 @@ uint32 _spoolss_endpageprinter(const POLICY_HND *handle) { Printer_entry *Printer = find_printer_index_by_hnd(handle); - if (!OPEN_HANDLE(Printer)) - { - DEBUG(3,("Error in endpageprinter printer handle\n")); + if (!OPEN_HANDLE(Printer)) { + DEBUG(0,("_spoolss_endpageprinter: Invalid handle (%s).\n",OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; } @@ -2843,8 +2850,8 @@ uint32 _spoolss_startdocprinter(const POLICY_HND *handle, uint32 level, Printer_entry *Printer = find_printer_index_by_hnd(handle); struct current_user user; - if (!OPEN_HANDLE(Printer)) - { + if (!OPEN_HANDLE(Printer)) { + DEBUG(0,("_spoolss_startdocprinter: Invalid handle (%s)\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; } @@ -2908,9 +2915,8 @@ uint32 _spoolss_enddocprinter(const POLICY_HND *handle) { Printer_entry *Printer=find_printer_index_by_hnd(handle); - if (!OPEN_HANDLE(Printer)) - { - DEBUG(3,("Error in enddocprinter handle\n")); + if (!OPEN_HANDLE(Printer)) { + DEBUG(0,("_spoolss_enddocprinter: Invalid handle (%s)\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; } @@ -2930,9 +2936,8 @@ uint32 _spoolss_writeprinter( const POLICY_HND *handle, { Printer_entry *Printer = find_printer_index_by_hnd(handle); - if (!OPEN_HANDLE(Printer)) - { - DEBUG(3,("Error in writeprinter handle\n")); + if (!OPEN_HANDLE(Printer)) { + DEBUG(0,("_spoolss_writeprinter: Invalid handle (%s)\n",OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; } @@ -2960,8 +2965,10 @@ static uint32 control_printer(const POLICY_HND *handle, uint32 command, memcpy(&user, ¤t_user, sizeof(user)); } - if (!OPEN_HANDLE(Printer)) + if (!OPEN_HANDLE(Printer)) { + DEBUG(0,("control_printer: Invalid handle (%s)\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; + } if (!get_printer_snum(handle, &snum) ) return ERROR_INVALID_HANDLE; @@ -2998,8 +3005,10 @@ static uint32 update_printer_sec(const POLICY_HND *handle, uint32 level, { Printer_entry *Printer = find_printer_index_by_hnd(handle); - if (!OPEN_HANDLE(Printer)) + if (!OPEN_HANDLE(Printer)) { + DEBUG(0,("update_printer_sec: Invalid handle (%s)\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; + } return nt_printing_setsec(Printer->dev.printername, secdesc_ctr); } @@ -3025,8 +3034,10 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, return ERROR_INVALID_LEVEL; } - if (!OPEN_HANDLE(Printer)) + if (!OPEN_HANDLE(Printer)) { + DEBUG(0,("update_printer: Invalid handle (%s)\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; + } if (!get_printer_snum(handle, &snum) ) return ERROR_INVALID_HANDLE; @@ -3086,8 +3097,10 @@ uint32 _spoolss_setprinter(const POLICY_HND *handle, uint32 level, { Printer_entry *Printer = find_printer_index_by_hnd(handle); - if (!OPEN_HANDLE(Printer)) + if (!OPEN_HANDLE(Printer)) { + DEBUG(0,("_spoolss_setprinter: Invalid handle (%s)\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; + } /* check the level */ switch (level) { @@ -3112,8 +3125,10 @@ uint32 _spoolss_fcpn(const POLICY_HND *handle) { Printer_entry *Printer= find_printer_index_by_hnd(handle); - if (!OPEN_HANDLE(Printer)) + if (!OPEN_HANDLE(Printer)) { + DEBUG(0,("_spoolss_fcpn: Invalid handle (%s)\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; + } Printer->notify.flags=0; Printer->notify.options=0; @@ -3606,7 +3621,7 @@ uint32 _spoolss_enumprinterdrivers( UNISTR2 *name, UNISTR2 *environment, uint32 static void fill_form_1(FORM_1 *form, nt_forms_struct *list, int position) { form->flag=list->flag; - init_unistr(&(form->name), list->name); + init_unistr(&form->name, list->name); form->width=list->width; form->length=list->length; form->left=list->left; @@ -3645,7 +3660,7 @@ uint32 _new_spoolss_enumforms( const POLICY_HND *handle, uint32 level, /* construct the list of form structures */ for (i=0; i<*numofforms; i++) { DEBUGADD(6,("Filling form number [%d]\n",i)); - fill_form_1(&(forms_1[i]), &(list[i]), i); + fill_form_1(&forms_1[i], &list[i], i); } safe_free(list); @@ -3653,7 +3668,7 @@ uint32 _new_spoolss_enumforms( const POLICY_HND *handle, uint32 level, /* check the required size. */ for (i=0; i<*numofforms; i++) { DEBUGADD(6,("adding form [%d]'s size\n",i)); - buffer_size += spoolss_size_form_1(&(forms_1[i])); + buffer_size += spoolss_size_form_1(&forms_1[i]); } *needed=buffer_size; @@ -3666,7 +3681,7 @@ uint32 _new_spoolss_enumforms( const POLICY_HND *handle, uint32 level, /* fill the buffer with the form structures */ for (i=0; i<*numofforms; i++) { DEBUGADD(6,("adding form [%d] to buffer\n",i)); - new_smb_io_form_1("", buffer, &(forms_1[i]), 0); + new_smb_io_form_1("", buffer, &forms_1[i], 0); } safe_free(forms_1); @@ -4137,8 +4152,10 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx, DEBUG(5,("spoolss_enumprinterdata\n")); - if (!OPEN_HANDLE(Printer)) + if (!OPEN_HANDLE(Printer)) { + DEBUG(0,("_spoolss_enumprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; + } if (!get_printer_snum(handle, &snum)) return ERROR_INVALID_HANDLE; @@ -4206,9 +4223,6 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx, return ERROR_NOT_ENOUGH_MEMORY; } *out_value_len = (uint32)dos_PutUniCode((char *)*out_value, value, in_value_len, True); -#if 0 /* JRATEST */ - *out_max_value_len=(*out_value_len/sizeof(uint16)); -#endif /* JRATEST */ *out_type=type; @@ -4220,9 +4234,6 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx, } memcpy(*data_out, data, (size_t)data_len); *out_data_len=data_len; -#if 0 /* JRATEST */ - *out_max_data_len=data_len; -#endif /* JRATEST */ safe_free(data); @@ -4249,8 +4260,10 @@ uint32 _spoolss_setprinterdata( const POLICY_HND *handle, DEBUG(5,("spoolss_setprinterdata\n")); - if (!OPEN_HANDLE(Printer)) + if (!OPEN_HANDLE(Printer)) { + DEBUG(0,("_spoolss_setprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; + } if (!get_printer_snum(handle, &snum)) return ERROR_INVALID_HANDLE; @@ -4283,8 +4296,10 @@ uint32 _spoolss_addform( const POLICY_HND *handle, DEBUG(5,("spoolss_addform\n")); - if (!OPEN_HANDLE(Printer)) + if (!OPEN_HANDLE(Printer)) { + DEBUG(0,("_spoolss_addform: Invalid handle (%s).\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; + } count=get_ntforms(&list); if(!add_a_form(&list, form, &count)) @@ -4309,8 +4324,8 @@ uint32 _spoolss_setform( const POLICY_HND *handle, DEBUG(5,("spoolss_setform\n")); - if (!OPEN_HANDLE(Printer)) - { + if (!OPEN_HANDLE(Printer)) { + DEBUG(0,("_spoolss_setform: Invalid handle (%s).\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; } count=get_ntforms(&list); -- cgit From 78a4848e8da7bb4f96e99e3419c5473c4c23bb6d Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 10 Jul 2000 05:08:21 +0000 Subject: Re-instated lanman printing security checks (oops). A user can now pause, resume or delete their own job even if they don't have the Manage Documents privilege. Added call to se_access_check() for changing printer properties. The Full Access privilege is required for the user to perform this. Several uninitialised variables and memory leaks plugged. Modified default ACL created on new printers to be Everyone / Print instead of Everyone / Full Access. This required some random stuffing around with the value of the revision field to correspond with the ACL that NT produces when setting the same permission on the printer. Fixed dodgy function call in printing/printfsp.c (This used to be commit 2abce4dcfa351051df6e5f789b34fa99c9b81c22) --- source3/rpc_server/srv_spoolss_nt.c | 69 +++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 14 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 522a266b8c..0be371df11 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3001,8 +3001,10 @@ static uint32 control_printer(const POLICY_HND *handle, uint32 command, ********************************************************************/ static uint32 update_printer_sec(const POLICY_HND *handle, uint32 level, const SPOOL_PRINTER_INFO_LEVEL *info, - SEC_DESC_BUF *secdesc_ctr) + pipes_struct *p, SEC_DESC_BUF *secdesc_ctr) { + struct current_user user; + Printer_entry *Printer = find_printer_index_by_hnd(handle); if (!OPEN_HANDLE(Printer)) { @@ -3010,7 +3012,15 @@ static uint32 update_printer_sec(const POLICY_HND *handle, uint32 level, return ERROR_INVALID_HANDLE; } - return nt_printing_setsec(Printer->dev.printername, secdesc_ctr); + if (p->ntlmssp_auth_validated) { + memcpy(&user, &p->pipe_user, sizeof(user)); + } else { + extern struct current_user current_user; + memcpy(&user, ¤t_user, sizeof(user)); + } + + return nt_printing_setsec(Printer->dev.printername, &user, + secdesc_ctr); } /******************************************************************** @@ -3025,25 +3035,53 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, int snum; NT_PRINTER_INFO_LEVEL *printer = NULL; Printer_entry *Printer = find_printer_index_by_hnd(handle); - + SEC_DESC_BUF *sd = NULL; + uint32 result, acc_granted; + extern struct current_user current_user; + DEBUG(8,("update_printer\n")); + result = NT_STATUS_NO_PROBLEMO; + + /* Check calling user has permission to update printer description */ + + if (!nt_printing_getsec(Printer->dev.printername, &sd)) { + DEBUG(3, ("Could not get security descriptor for printer %s", + Printer->dev.printername)); + result = ERROR_INVALID_FUNCTION; + goto done; + } + + if (!se_access_check(sd->sec, current_user.uid, current_user.gid, + current_user.ngroups, current_user.groups, + PRINTER_ACE_FULL_CONTROL, &acc_granted, + &result)) { + DEBUG(3, ("printer property change denied by security " + "descriptor\n")); + goto done; + } + if (level!=2) { DEBUG(0,("Send a mail to samba@samba.org\n")); DEBUGADD(0,("with the following message: update_printer: level!=2\n")); - return ERROR_INVALID_LEVEL; + result = ERROR_INVALID_LEVEL; + goto done; } if (!OPEN_HANDLE(Printer)) { - DEBUG(0,("update_printer: Invalid handle (%s)\n", OUR_HANDLE(handle))); - return ERROR_INVALID_HANDLE; + result = ERROR_INVALID_HANDLE; + goto done; } - if (!get_printer_snum(handle, &snum) ) - return ERROR_INVALID_HANDLE; + if (!get_printer_snum(handle, &snum)) { + result = ERROR_INVALID_HANDLE; + goto done; + } - if(get_a_printer(&printer, 2, lp_servicename(snum)) != 0) - return ERROR_INVALID_HANDLE; + if(get_a_printer(&printer, 2, lp_servicename(snum)) != 0) { + result = ERROR_INVALID_HANDLE; + goto done; + } DEBUGADD(8,("Converting info_2 struct\n")); @@ -3078,13 +3116,15 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, if (add_a_printer(*printer, 2)!=0) { /* I don't really know what to return here !!! */ - free_a_printer(&printer, 2); - return ERROR_ACCESS_DENIED; + result = ERROR_ACCESS_DENIED; + goto done; } + done: free_a_printer(&printer, 2); + free_sec_desc_buf(&sd); - return NT_STATUS_NO_PROBLEMO; + return result; } /**************************************************************************** @@ -3111,7 +3151,8 @@ uint32 _spoolss_setprinter(const POLICY_HND *handle, uint32 level, return update_printer(handle, level, info, devmode_ctr.devmode); break; case 3: - return update_printer_sec(handle, level, info, secdesc_ctr); + return update_printer_sec(handle, level, info, p, + secdesc_ctr); break; default: return ERROR_INVALID_LEVEL; -- cgit From b561c185972921861946a69b8846681bc7ed3f87 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 10 Jul 2000 06:41:04 +0000 Subject: Fixes for various compile warnings on Solaris 8. (This used to be commit 898a483cdab1ed7d8ff902c0dc0e0620440ae4cd) --- source3/rpc_server/srv_spoolss_nt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 0be371df11..dd3a5dd733 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2941,7 +2941,8 @@ uint32 _spoolss_writeprinter( const POLICY_HND *handle, return ERROR_INVALID_HANDLE; } - (*buffer_written) = print_job_write(Printer->jobid, buffer, buffer_size); + (*buffer_written) = print_job_write(Printer->jobid, (char *)buffer, + buffer_size); return 0x0; } -- cgit From 445e92eb01949335feed9fa5716209976d8021f1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 10 Jul 2000 22:30:13 +0000 Subject: Ensure correct driver paths are returned in INFO_2 struct. Jeremy. (This used to be commit 7a95c289cd0b4615d2a5aa8a148c767b57460ffa) --- source3/rpc_server/srv_spoolss_nt.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index dd3a5dd733..320ff8ff3a 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2517,24 +2517,24 @@ static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, get_short_archi(short_archi,architecture); - snprintf(where,sizeof(where)-1,"\\\\%s\\print$\\%s\\%s\\", servername, short_archi, driver.info_3->name); + snprintf(where,sizeof(where)-1,"\\\\%s\\print$\\%s\\", servername, short_archi); info->version=driver.info_3->cversion; - init_unistr( &(info->name), driver.info_3->name ); - init_unistr( &(info->architecture), architecture ); + init_unistr( &info->name, driver.info_3->name ); + init_unistr( &info->architecture, architecture ); snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "%s%s", where, driver.info_3->driverpath); - init_unistr( &(info->driverpath), temp_driverpath ); + init_unistr( &info->driverpath, temp_driverpath ); snprintf(temp_datafile, sizeof(temp_datafile)-1, "%s%s", where, driver.info_3->datafile); - init_unistr( &(info->datafile), temp_datafile ); + init_unistr( &info->datafile, temp_datafile ); snprintf(temp_configfile, sizeof(temp_configfile)-1, "%s%s", where, driver.info_3->configfile); - init_unistr( &(info->configfile), temp_configfile ); + init_unistr( &info->configfile, temp_configfile ); } /******************************************************************** -- cgit From 5813ecff99431c3529cd45f3b579ef16e72a46f0 Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Wed, 12 Jul 2000 14:10:40 +0000 Subject: - The printers are indexed by the sharename in both get_a_printer() and add_a_printer() now. - correctly unpack the private part of a devmode and remove a memleak - correctly retrieve the pair(value,data) for getprinterdata - handle null devicemode in printer_info_2 I still have some bugs but I'm not crashing anymore NT4SP6 d/c build :-) J.F. (This used to be commit 493f7d11acf753ba24c88e6cbb73d86a8595a66a) --- source3/rpc_server/srv_spoolss_nt.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 320ff8ff3a..c0c721a082 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1796,9 +1796,10 @@ static DEVICEMODE *construct_dev_mode(int snum, char *servername) if (printer->info_2->devmode) ntdevmode = dup_nt_devicemode(printer->info_2->devmode); +#if 0 /* JFMTEST */ else ntdevmode = construct_nt_devicemode(printer->info_2->printername); - +#endif if (ntdevmode == NULL) goto fail; @@ -1914,8 +1915,12 @@ static BOOL construct_printer_info_2(fstring servername, PRINTER_INFO_2 *printer printer->cjobs = count; /* jobs */ printer->averageppm = ntprinter->info_2->averageppm; /* average pages per minute */ - if((printer->devmode = construct_dev_mode(snum, servername)) == NULL) + if((printer->devmode = construct_dev_mode(snum, servername)) == NULL) { + DEBUG(8, ("Returning NULL Devicemode!\n")); +#if 0 /* JFMTEST */ goto err; +#endif + } if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->len != 0) { /* steal the printer info sec_desc structure. [badly done]. */ @@ -3045,7 +3050,8 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, result = NT_STATUS_NO_PROBLEMO; /* Check calling user has permission to update printer description */ - + +#if 1 /* JFMTEST */ if (!nt_printing_getsec(Printer->dev.printername, &sd)) { DEBUG(3, ("Could not get security descriptor for printer %s", Printer->dev.printername)); @@ -3061,7 +3067,7 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, "descriptor\n")); goto done; } - +#endif if (level!=2) { DEBUG(0,("Send a mail to samba@samba.org\n")); DEBUGADD(0,("with the following message: update_printer: level!=2\n")); @@ -3596,9 +3602,9 @@ static uint32 enumprinterdrivers_level3(fstring *list, fstring servername, fstri return ERROR_INSUFFICIENT_BUFFER; } - /* fill the buffer with the form structures */ + /* fill the buffer with the driver structures */ for (i=0; i<*returned; i++) { - DEBUGADD(6,("adding form [%d] to buffer\n",i)); + DEBUGADD(6,("adding driver [%d] to buffer\n",i)); new_smb_io_printer_driver_info_3("", buffer, &driver_info_3[i], 0); } @@ -3653,6 +3659,7 @@ uint32 _spoolss_enumprinterdrivers( UNISTR2 *name, UNISTR2 *environment, uint32 return enumprinterdrivers_level3(list, servername, architecture, buffer, offered, needed, returned); break; default: + *returned=0; return ERROR_INVALID_LEVEL; break; } @@ -4264,6 +4271,8 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx, safe_free(data); return ERROR_NOT_ENOUGH_MEMORY; } + + ZERO_STRUCTP(*out_value); *out_value_len = (uint32)dos_PutUniCode((char *)*out_value, value, in_value_len, True); *out_type=type; @@ -4274,6 +4283,8 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx, safe_free(data); return ERROR_NOT_ENOUGH_MEMORY; } + + ZERO_STRUCTP(*data_out); memcpy(*data_out, data, (size_t)data_len); *out_data_len=data_len; -- cgit From 53c91652c62c3629904be94902be64b5652cc02a Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 17 Jul 2000 02:38:43 +0000 Subject: Renamed arguments to se_access_check() (This used to be commit 714b50b47dab46f5cdde49d7c200b353c2e0398a) --- source3/rpc_server/srv_spoolss_nt.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index c0c721a082..75cec8f04c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3009,7 +3009,9 @@ static uint32 update_printer_sec(const POLICY_HND *handle, uint32 level, const SPOOL_PRINTER_INFO_LEVEL *info, pipes_struct *p, SEC_DESC_BUF *secdesc_ctr) { + SEC_DESC_BUF *old_secdesc_ctr = NULL; struct current_user user; + uint32 acc_granted, status; Printer_entry *Printer = find_printer_index_by_hnd(handle); @@ -3018,6 +3020,8 @@ static uint32 update_printer_sec(const POLICY_HND *handle, uint32 level, return ERROR_INVALID_HANDLE; } + /* Work out which user is performing the operation */ + if (p->ntlmssp_auth_validated) { memcpy(&user, &p->pipe_user, sizeof(user)); } else { @@ -3025,8 +3029,29 @@ static uint32 update_printer_sec(const POLICY_HND *handle, uint32 level, memcpy(&user, ¤t_user, sizeof(user)); } - return nt_printing_setsec(Printer->dev.printername, &user, - secdesc_ctr); + /* Get old security descriptor */ + + if (!nt_printing_getsec(Printer->dev.printername, &old_secdesc_ctr)) { + DEBUG(3, ("could not get old security descriptor for " + "printer %s", Printer->dev.printername)); + return ERROR_INVALID_FUNCTION; + } + + /* Check the user has permissions to change the security + descriptor. By experimentation with two NT machines, the user + requires Full Access to the printer to change security + information. */ + + if (!se_access_check(old_secdesc_ctr->sec, &user, + PRINTER_ACE_FULL_CONTROL, &acc_granted, + &status)) { + DEBUG(3, ("security descriptor change denied by existing " + "security descriptor\n")); + free_sec_desc_buf(&old_secdesc_ctr); + return status; + } + + return nt_printing_setsec(Printer->dev.printername, secdesc_ctr); } /******************************************************************** @@ -3059,8 +3084,7 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, goto done; } - if (!se_access_check(sd->sec, current_user.uid, current_user.gid, - current_user.ngroups, current_user.groups, + if (!se_access_check(sd->sec, ¤t_user, PRINTER_ACE_FULL_CONTROL, &acc_granted, &result)) { DEBUG(3, ("printer property change denied by security " -- cgit From 873c0366d95dd747f93613f6519836fc8f0c8feb Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 17 Jul 2000 05:38:26 +0000 Subject: Free security descriptor after access check in update_printer_sec() (This used to be commit bc5f9c00be5b8c2f6d258f0c95ed3b4fc0201b87) --- source3/rpc_server/srv_spoolss_nt.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 75cec8f04c..587b31f535 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3047,11 +3047,15 @@ static uint32 update_printer_sec(const POLICY_HND *handle, uint32 level, &status)) { DEBUG(3, ("security descriptor change denied by existing " "security descriptor\n")); - free_sec_desc_buf(&old_secdesc_ctr); - return status; + result = status; + goto done; } - return nt_printing_setsec(Printer->dev.printername, secdesc_ctr); + result = nt_printing_setsec(Printer->dev.printername, secdesc_ctr); + + done: + free_sec_desc_buf(&old_secdesc_ctr); + return result; } /******************************************************************** -- cgit From 9665d3fc7b5aaa3b514ddd5fb2bc849e25ec494f Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 17 Jul 2000 06:04:23 +0000 Subject: Missing var. (This used to be commit 5c1c5622269c54dca89eb178ca25981ab7928e75) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 587b31f535..e30180a250 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3011,7 +3011,7 @@ static uint32 update_printer_sec(const POLICY_HND *handle, uint32 level, { SEC_DESC_BUF *old_secdesc_ctr = NULL; struct current_user user; - uint32 acc_granted, status; + uint32 acc_granted, status, result; Printer_entry *Printer = find_printer_index_by_hnd(handle); -- cgit From 2637bfee06c1fb2d5fcb9345ff56b0883e024f31 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 18 Jul 2000 19:25:32 +0000 Subject: rpc_parse/parse_prs.c: Removed extraneous ()'s. rpc_parse/parse_spoolss.c: Fixed the security descriptor marshalling in a INFO_2 struct. for some reason SD's should be done inline after the info2, not as the last buffer marshall. rpc_server/srv_spoolss_nt.c: Removed extraneous ()'s. Jeremy. (This used to be commit f038a24e9f624fdb04cd52769d45783248ce8a38) --- source3/rpc_server/srv_spoolss_nt.c | 44 ++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index e30180a250..0143f531d5 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -495,7 +495,11 @@ static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size) prs_set_offset(ps, old_offset); +#if 0 /* JRATEST */ + buffer->string_at_end = buffer_size; +#else buffer->string_at_end=prs_data_size(ps); +#endif return True; } @@ -3240,12 +3244,12 @@ static void fill_job_info_1(JOB_INFO_1 *job_info, print_queue_struct *queue, snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname); job_info->jobid=queue->job; - init_unistr(&(job_info->printername), lp_servicename(snum)); - init_unistr(&(job_info->machinename), temp_name); - init_unistr(&(job_info->username), queue->user); - init_unistr(&(job_info->document), queue->file); - init_unistr(&(job_info->datatype), "RAW"); - init_unistr(&(job_info->text_status), ""); + init_unistr(&job_info->printername, lp_servicename(snum)); + init_unistr(&job_info->machinename, temp_name); + init_unistr(&job_info->username, queue->user); + init_unistr(&job_info->document, queue->file); + init_unistr(&job_info->datatype, "RAW"); + init_unistr(&job_info->text_status, ""); job_info->status=nt_printj_status(queue->status); job_info->priority=queue->priority; job_info->position=position; @@ -3279,14 +3283,14 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, init_unistr(&(job_info->printername), chaine); - init_unistr(&(job_info->machinename), temp_name); - init_unistr(&(job_info->username), queue->user); - init_unistr(&(job_info->document), queue->file); - init_unistr(&(job_info->notifyname), queue->user); - init_unistr(&(job_info->datatype), "RAW"); - init_unistr(&(job_info->printprocessor), "winprint"); - init_unistr(&(job_info->parameters), ""); - init_unistr(&(job_info->text_status), ""); + init_unistr(&job_info->machinename, temp_name); + init_unistr(&job_info->username, queue->user); + init_unistr(&job_info->document, queue->file); + init_unistr(&job_info->notifyname, queue->user); + init_unistr(&job_info->datatype, "RAW"); + init_unistr(&job_info->printprocessor, "winprint"); + init_unistr(&job_info->parameters, ""); + init_unistr(&job_info->text_status, ""); /* and here the security descriptor */ @@ -3328,13 +3332,13 @@ static uint32 enumjobs_level1(print_queue_struct *queue, int snum, } for (i=0; i<*returned; i++) - fill_job_info_1(&(info[i]), &(queue[i]), i, snum); + fill_job_info_1(&info[i], &queue[i], i, snum); safe_free(queue); /* check the required size. */ for (i=0; i<*returned; i++) - (*needed) += spoolss_size_job_info_1(&(info[i])); + (*needed) += spoolss_size_job_info_1(&info[i]); if (!alloc_buffer_size(buffer, *needed)) { safe_free(info); @@ -3343,7 +3347,7 @@ static uint32 enumjobs_level1(print_queue_struct *queue, int snum, /* fill the buffer with the structures */ for (i=0; i<*returned; i++) - new_smb_io_job_info_1("", buffer, &(info[i]), 0); + new_smb_io_job_info_1("", buffer, &info[i], 0); /* clear memory */ safe_free(info); @@ -3374,13 +3378,13 @@ static uint32 enumjobs_level2(print_queue_struct *queue, int snum, } for (i=0; i<*returned; i++) - fill_job_info_2(&(info[i]), &(queue[i]), i, snum); + fill_job_info_2(&(info[i]), &queue[i], i, snum); safe_free(queue); /* check the required size. */ for (i=0; i<*returned; i++) - (*needed) += spoolss_size_job_info_2(&(info[i])); + (*needed) += spoolss_size_job_info_2(&info[i]); if (!alloc_buffer_size(buffer, *needed)) { safe_free(info); @@ -3389,7 +3393,7 @@ static uint32 enumjobs_level2(print_queue_struct *queue, int snum, /* fill the buffer with the structures */ for (i=0; i<*returned; i++) - new_smb_io_job_info_2("", buffer, &(info[i]), 0); + new_smb_io_job_info_2("", buffer, &info[i], 0); /* clear memory */ safe_free(info); -- cgit From 78bbcec21b0683aa859aceeb42b106580d48e467 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 22 Jul 2000 00:48:29 +0000 Subject: Fixed open handle code in printers - 3 functions were always being done in order - moved them into open_printer_hnd(). Added saving of comment field. Jeremy. (This used to be commit a0ee774fe92e5d0bc84d1d6729e8c538c67e8aba) --- source3/rpc_server/srv_spoolss_nt.c | 254 +++++++++++++++++++----------------- 1 file changed, 134 insertions(+), 120 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 0143f531d5..3a8040d905 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -54,7 +54,7 @@ typedef struct _Printer{ POLICY_HND printer_hnd; BOOL printer_type; union { - fstring printername; + fstring handlename; fstring printerservername; } dev; uint32 type; @@ -216,8 +216,8 @@ static BOOL delete_printer_handle(POLICY_HND *hnd) return False; } - if (del_a_printer(Printer->dev.printername) != 0) { - DEBUG(3,("Error deleting printer %s\n", Printer->dev.printername)); + if (del_a_printer(Printer->dev.handlename) != 0) { + DEBUG(3,("Error deleting printer %s\n", Printer->dev.handlename)); return False; } @@ -227,7 +227,7 @@ static BOOL delete_printer_handle(POLICY_HND *hnd) /**************************************************************************** return the snum of a printer corresponding to an handle ****************************************************************************/ -static BOOL get_printer_snum(const POLICY_HND *hnd, int *number) +static BOOL get_printer_snum(POLICY_HND *hnd, int *number) { Printer_entry *Printer = find_printer_index_by_hnd(hnd); @@ -238,8 +238,8 @@ static BOOL get_printer_snum(const POLICY_HND *hnd, int *number) switch (Printer->printer_type) { case PRINTER_HANDLE_IS_PRINTER: - DEBUG(4,("short name:%s\n", Printer->dev.printername)); - *number = print_queue_snum(Printer->dev.printername); + DEBUG(4,("short name:%s\n", Printer->dev.handlename)); + *number = print_queue_snum(Printer->dev.handlename); return (*number != -1); case PRINTER_HANDLE_IS_PRINTSERVER: return False; @@ -250,28 +250,6 @@ static BOOL get_printer_snum(const POLICY_HND *hnd, int *number) } } -/**************************************************************************** - find first available printer slot. creates a printer handle for you. - ****************************************************************************/ -static BOOL open_printer_hnd(POLICY_HND *hnd) -{ - Printer_entry *new_printer; - - if((new_printer=(Printer_entry *)malloc(sizeof(Printer_entry))) == NULL) - return False; - - ZERO_STRUCTP(new_printer); - - new_printer->open = True; - new_printer->notify.option=NULL; - - memcpy(&new_printer->printer_hnd, hnd, sizeof(*hnd)); - - ubi_dlAddHead( &Printer_list, (ubi_dlNode *)new_printer); - - return True; -} - /**************************************************************************** set printer handle type. ****************************************************************************/ @@ -290,27 +268,21 @@ static BOOL set_printer_hnd_accesstype(POLICY_HND *hnd, uint32 access_required) } /**************************************************************************** - set printer handle type. - check if it's \\server or \\server\printer + Set printer handle type. + Check if it's \\server or \\server\printer ****************************************************************************/ -static BOOL set_printer_hnd_printertype(POLICY_HND *hnd, char *printername) + +static BOOL set_printer_hnd_printertype(Printer_entry *Printer, char *handlename) { - Printer_entry *Printer = find_printer_index_by_hnd(hnd); - - if (!OPEN_HANDLE(Printer)) { - DEBUG(0,("set_printer_hnd_printertype: Invalid handle (%s)", OUR_HANDLE(hnd))); - return False; - } - - DEBUG(3,("Setting printer type=%s\n", printername)); + DEBUG(3,("Setting printer type=%s\n", handlename)); - if ( strlen(printername) < 3 ) { - DEBUGADD(4,("A print server must have at least 1 char ! %s\n", printername)); + if ( strlen(handlename) < 3 ) { + DEBUGADD(4,("A print server must have at least 1 char ! %s\n", handlename)); return False; } /* it's a print server */ - if (!strchr(printername+2, '\\')) { + if (!strchr(handlename+2, '\\')) { DEBUGADD(4,("Printer is a print server\n")); Printer->printer_type = PRINTER_HANDLE_IS_PRINTSERVER; return True; @@ -326,34 +298,29 @@ static BOOL set_printer_hnd_printertype(POLICY_HND *hnd, char *printername) } /**************************************************************************** - set printer handle printername. + Set printer handle name. ****************************************************************************/ -static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) + +static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) { - Printer_entry *Printer = find_printer_index_by_hnd(hnd); NT_PRINTER_INFO_LEVEL *printer = NULL; int snum; int n_services=lp_numservices(); char *aprinter; BOOL found=False; - if (!OPEN_HANDLE(Printer)) { - DEBUG(0,("set_printer_hnd_printername: Invalid handle (%s)\n", OUR_HANDLE(hnd))); - return False; - } - - DEBUG(4,("Setting printer name=%s (len=%d)\n", printername, strlen(printername))); + DEBUG(4,("Setting printer name=%s (len=%d)\n", handlename, strlen(handlename))); if (Printer->printer_type==PRINTER_HANDLE_IS_PRINTSERVER) { ZERO_STRUCT(Printer->dev.printerservername); - strncpy(Printer->dev.printerservername, printername, strlen(printername)); + strncpy(Printer->dev.printerservername, handlename, strlen(handlename)); return True; } if (Printer->printer_type!=PRINTER_HANDLE_IS_PRINTER) return False; - aprinter=strchr(printername+2, '\\'); + aprinter=strchr(handlename+2, '\\'); aprinter++; DEBUGADD(5,("searching for [%s] (len=%d)\n", aprinter, strlen(aprinter))); @@ -376,7 +343,7 @@ static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) if (get_a_printer(&printer, 2, lp_servicename(snum))!=0) continue; - DEBUG(10,("set_printer_hnd_printername: printername [%s], aprinter [%s]\n", + DEBUG(10,("set_printer_hnd_name: name [%s], aprinter [%s]\n", printer->info_2->printername, aprinter )); if ( strlen(printer->info_2->printername) != strlen(aprinter) ) { @@ -393,7 +360,7 @@ static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) } /* - * if we haven't found a printer with the given printername + * if we haven't found a printer with the given handlename * then it can be a share name as you can open both \\server\printer and * \\server\share */ @@ -411,12 +378,12 @@ static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) if ( !(lp_snum_ok(snum) && lp_print_ok(snum) ) ) continue; - DEBUGADD(5,("set_printer_hnd_printername: share:%s\n",lp_servicename(snum))); + DEBUGADD(5,("set_printer_hnd_name: share:%s\n",lp_servicename(snum))); if (get_a_printer(&printer, 2, lp_servicename(snum))!=0) continue; - DEBUG(10,("set_printer_hnd_printername: printername [%s], aprinter [%s]\n", + DEBUG(10,("set_printer_hnd_name: printername [%s], aprinter [%s]\n", printer->info_2->printername, aprinter )); if ( strlen(lp_servicename(snum)) != strlen(aprinter) ) { @@ -439,17 +406,53 @@ static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername) } snum--; - DEBUGADD(4,("set_printer_hnd_printername: Printer found: %s -> %s[%x]\n", + DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s[%x]\n", printer->info_2->printername, lp_servicename(snum),snum)); - ZERO_STRUCT(Printer->dev.printername); - strncpy(Printer->dev.printername, lp_servicename(snum), strlen(lp_servicename(snum))); + ZERO_STRUCT(Printer->dev.handlename); + strncpy(Printer->dev.handlename, lp_servicename(snum), strlen(lp_servicename(snum))); free_a_printer(&printer, 2); return True; } +/**************************************************************************** + find first available printer slot. creates a printer handle for you. + ****************************************************************************/ + +static BOOL open_printer_hnd(POLICY_HND *hnd, char *name) +{ + Printer_entry *new_printer; + + clear_handle(hnd); + create_printer_hnd(hnd); + + if((new_printer=(Printer_entry *)malloc(sizeof(Printer_entry))) == NULL) + return False; + + ZERO_STRUCTP(new_printer); + + new_printer->open = True; + new_printer->notify.option=NULL; + + memcpy(&new_printer->printer_hnd, hnd, sizeof(*hnd)); + + ubi_dlAddHead( &Printer_list, (ubi_dlNode *)new_printer); + + if (!set_printer_hnd_printertype(new_printer, name)) { + close_printer_handle(hnd); + return False; + } + + if (!set_printer_hnd_name(new_printer, name)) { + close_printer_handle(hnd); + return False; + } + + return True; +} + /******************************************************************** Return True is the handle is a print server. ********************************************************************/ @@ -516,8 +519,6 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, { fstring name; - clear_handle(handle); - if (printername == NULL) return ERROR_INVALID_PRINTER_NAME; @@ -527,20 +528,9 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, DEBUGADD(3,("checking name: %s\n",name)); - create_printer_hnd(handle); - - open_printer_hnd(handle); - - if (!set_printer_hnd_printertype(handle, name)) { - close_printer_handle(handle); + if (!open_printer_hnd(handle, name)) return ERROR_INVALID_PRINTER_NAME; - } - if (!set_printer_hnd_printername(handle, name)) { - close_printer_handle(handle); - return ERROR_INVALID_PRINTER_NAME; - } - /* if (printer_default->datatype_ptr != NULL) { @@ -747,7 +737,7 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d /******************************************************************** GetPrinterData on a printer Handle. ********************************************************************/ -static BOOL getprinterdata_printer(const POLICY_HND *handle, +static BOOL getprinterdata_printer(POLICY_HND *handle, fstring value, uint32 *type, uint8 **data, uint32 *needed, uint32 in_size ) { @@ -803,7 +793,7 @@ static BOOL getprinterdata_printer(const POLICY_HND *handle, /******************************************************************** * spoolss_getprinterdata ********************************************************************/ -uint32 _spoolss_getprinterdata(const POLICY_HND *handle, UNISTR2 *valuename, +uint32 _spoolss_getprinterdata(POLICY_HND *handle, UNISTR2 *valuename, uint32 in_size, uint32 *type, uint32 *out_size, @@ -874,7 +864,7 @@ uint32 _spoolss_getprinterdata(const POLICY_HND *handle, UNISTR2 *valuename, * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe * called from api_spoolss_rffpcnex ********************************************************************/ -uint32 _spoolss_rffpcnex(const POLICY_HND *handle, uint32 flags, uint32 options, +uint32 _spoolss_rffpcnex(POLICY_HND *handle, uint32 flags, uint32 options, const UNISTR2 *localmachine, uint32 printerlocal, SPOOL_NOTIFY_OPTION *option) { @@ -1518,7 +1508,7 @@ static uint32 printserver_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO * * fill a notify_info struct with info asked * ********************************************************************/ -static uint32 printer_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info) +static uint32 printer_notify_info(POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info) { int snum; Printer_entry *Printer=find_printer_index_by_hnd(hnd); @@ -1579,7 +1569,7 @@ static uint32 printer_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info /******************************************************************** * spoolss_rfnpcnex ********************************************************************/ -uint32 _spoolss_rfnpcnex( const POLICY_HND *handle, uint32 change, +uint32 _spoolss_rfnpcnex( POLICY_HND *handle, uint32 change, SPOOL_NOTIFY_OPTION *option, SPOOL_NOTIFY_INFO *info) { Printer_entry *Printer=find_printer_index_by_hnd(handle); @@ -1902,7 +1892,12 @@ static BOOL construct_printer_info_2(fstring servername, PRINTER_INFO_2 *printer init_unistr(&printer->portname, lp_servicename(snum)); /* port */ #endif init_unistr(&printer->drivername, ntprinter->info_2->drivername); /* drivername */ - init_unistr(&printer->comment, lp_comment(snum)); /* comment */ + + if (*ntprinter->info_2->comment == '\0') + init_unistr(&printer->comment, lp_comment(snum)); /* comment */ + else + init_unistr(&printer->comment, ntprinter->info_2->comment); /* saved comment. */ + init_unistr(&printer->location, ntprinter->info_2->location); /* location */ init_unistr(&printer->sepfile, ntprinter->info_2->sepfile); /* separator file */ init_unistr(&printer->printprocessor, ntprinter->info_2->printprocessor);/* print processor */ @@ -2774,7 +2769,7 @@ static uint32 getprinterdriver2_level3(fstring servername, fstring architecture, /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_getprinterdriver2(const POLICY_HND *handle, const UNISTR2 *uni_arch, uint32 level, +uint32 _spoolss_getprinterdriver2(POLICY_HND *handle, const UNISTR2 *uni_arch, uint32 level, uint32 clientmajorversion, uint32 clientminorversion, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *servermajorversion, uint32 *serverminorversion) @@ -2813,7 +2808,7 @@ uint32 _spoolss_getprinterdriver2(const POLICY_HND *handle, const UNISTR2 *uni_a /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_startpageprinter(const POLICY_HND *handle) +uint32 _spoolss_startpageprinter(POLICY_HND *handle) { Printer_entry *Printer = find_printer_index_by_hnd(handle); @@ -2828,7 +2823,7 @@ uint32 _spoolss_startpageprinter(const POLICY_HND *handle) /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_endpageprinter(const POLICY_HND *handle) +uint32 _spoolss_endpageprinter(POLICY_HND *handle) { Printer_entry *Printer = find_printer_index_by_hnd(handle); @@ -2848,7 +2843,7 @@ uint32 _spoolss_endpageprinter(const POLICY_HND *handle) * called from the spoolss dispatcher * ********************************************************************/ -uint32 _spoolss_startdocprinter(const POLICY_HND *handle, uint32 level, +uint32 _spoolss_startdocprinter(POLICY_HND *handle, uint32 level, pipes_struct *p, DOC_INFO *docinfo, uint32 *jobid) { @@ -2920,7 +2915,7 @@ uint32 _spoolss_startdocprinter(const POLICY_HND *handle, uint32 level, * called from the spoolss dispatcher * ********************************************************************/ -uint32 _spoolss_enddocprinter(const POLICY_HND *handle) +uint32 _spoolss_enddocprinter(POLICY_HND *handle) { Printer_entry *Printer=find_printer_index_by_hnd(handle); @@ -2938,9 +2933,9 @@ uint32 _spoolss_enddocprinter(const POLICY_HND *handle) /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_writeprinter( const POLICY_HND *handle, +uint32 _spoolss_writeprinter( POLICY_HND *handle, uint32 buffer_size, - const uint8 *buffer, + uint8 *buffer, uint32 *buffer_written) { Printer_entry *Printer = find_printer_index_by_hnd(handle); @@ -2961,7 +2956,7 @@ uint32 _spoolss_writeprinter( const POLICY_HND *handle, * called from the spoolss dispatcher * ********************************************************************/ -static uint32 control_printer(const POLICY_HND *handle, uint32 command, +static uint32 control_printer(POLICY_HND *handle, uint32 command, pipes_struct *p) { struct current_user user; @@ -3009,7 +3004,7 @@ static uint32 control_printer(const POLICY_HND *handle, uint32 command, * called by spoolss_api_setprinter * when updating a printer description ********************************************************************/ -static uint32 update_printer_sec(const POLICY_HND *handle, uint32 level, +static uint32 update_printer_sec(POLICY_HND *handle, uint32 level, const SPOOL_PRINTER_INFO_LEVEL *info, pipes_struct *p, SEC_DESC_BUF *secdesc_ctr) { @@ -3035,9 +3030,9 @@ static uint32 update_printer_sec(const POLICY_HND *handle, uint32 level, /* Get old security descriptor */ - if (!nt_printing_getsec(Printer->dev.printername, &old_secdesc_ctr)) { + if (!nt_printing_getsec(Printer->dev.handlename, &old_secdesc_ctr)) { DEBUG(3, ("could not get old security descriptor for " - "printer %s", Printer->dev.printername)); + "printer %s", Printer->dev.handlename)); return ERROR_INVALID_FUNCTION; } @@ -3055,19 +3050,42 @@ static uint32 update_printer_sec(const POLICY_HND *handle, uint32 level, goto done; } - result = nt_printing_setsec(Printer->dev.printername, secdesc_ctr); + result = nt_printing_setsec(Printer->dev.handlename, secdesc_ctr); done: free_sec_desc_buf(&old_secdesc_ctr); return result; } +/******************************************************************** + Do Samba sanity checks on a printer info struct. + ********************************************************************/ + +static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) +{ + /* + * Ensure that this printer is shared under the correct name + * as this is what Samba insists upon. + */ + + if (!(info->attributes & PRINTER_ATTRIBUTE_SHARED)) + return False; + + if (!(info->attributes & PRINTER_ATTRIBUTE_RAW_ONLY)) + return False; + + if (!strequal(info->sharename, lp_servicename(snum))) + return False; + + return True; +} + /******************************************************************** * called by spoolss_api_setprinter * when updating a printer description ********************************************************************/ -static uint32 update_printer(const POLICY_HND *handle, uint32 level, +static uint32 update_printer(POLICY_HND *handle, uint32 level, const SPOOL_PRINTER_INFO_LEVEL *info, DEVICEMODE *devmode) { @@ -3085,9 +3103,9 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, /* Check calling user has permission to update printer description */ #if 1 /* JFMTEST */ - if (!nt_printing_getsec(Printer->dev.printername, &sd)) { + if (!nt_printing_getsec(Printer->dev.handlename, &sd)) { DEBUG(3, ("Could not get security descriptor for printer %s", - Printer->dev.printername)); + Printer->dev.handlename)); result = ERROR_INVALID_FUNCTION; goto done; } @@ -3152,7 +3170,16 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, free_nt_devicemode(&printer->info_2->devmode); printer->info_2->devmode=NULL; } - + + /* + * Do sanity check on the requested changes for Samba. + */ + + if (!check_printer_ok(printer->info_2, snum)) { + result = ERROR_ACCESS_DENIED; + goto done; + } + if (add_a_printer(*printer, 2)!=0) { /* I don't really know what to return here !!! */ result = ERROR_ACCESS_DENIED; @@ -3168,7 +3195,7 @@ static uint32 update_printer(const POLICY_HND *handle, uint32 level, /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_setprinter(const POLICY_HND *handle, uint32 level, +uint32 _spoolss_setprinter(POLICY_HND *handle, uint32 level, const SPOOL_PRINTER_INFO_LEVEL *info, DEVMODE_CTR devmode_ctr, SEC_DESC_BUF *secdesc_ctr, @@ -3201,7 +3228,7 @@ uint32 _spoolss_setprinter(const POLICY_HND *handle, uint32 level, /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_fcpn(const POLICY_HND *handle) +uint32 _spoolss_fcpn(POLICY_HND *handle) { Printer_entry *Printer= find_printer_index_by_hnd(handle); @@ -3224,7 +3251,7 @@ uint32 _spoolss_fcpn(const POLICY_HND *handle) /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_addjob(const POLICY_HND *handle, uint32 level, +uint32 _spoolss_addjob(POLICY_HND *handle, uint32 level, NEW_BUFFER *buffer, uint32 offered) { return NT_STATUS_NO_PROBLEMO; @@ -3448,14 +3475,14 @@ uint32 _spoolss_enumjobs( POLICY_HND *handle, uint32 firstjob, uint32 numofjobs, /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_schedulejob( const POLICY_HND *handle, uint32 jobid) +uint32 _spoolss_schedulejob( POLICY_HND *handle, uint32 jobid) { return 0x0; } /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_setjob( const POLICY_HND *handle, +uint32 _spoolss_setjob( POLICY_HND *handle, uint32 jobid, uint32 level, pipes_struct *p, @@ -3713,7 +3740,7 @@ static void fill_form_1(FORM_1 *form, nt_forms_struct *list, int position) /**************************************************************************** ****************************************************************************/ -uint32 _new_spoolss_enumforms( const POLICY_HND *handle, uint32 level, +uint32 _new_spoolss_enumforms( POLICY_HND *handle, uint32 level, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *numofforms) { @@ -3991,8 +4018,6 @@ static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name, ZERO_STRUCTP(printer); - clear_handle(handle); - /* convert from UNICODE to ASCII - this allocates the info_2 struct inside *printer.*/ convert_printer_info(info, printer, 2); @@ -4006,19 +4031,8 @@ static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name, return ERROR_ACCESS_DENIED; } - create_printer_hnd(handle); - - open_printer_hnd(handle); - - if (!set_printer_hnd_printertype(handle, name)) { + if (!open_printer_hnd(handle, name)) { free_a_printer(&printer,2); - close_printer_handle(handle); - return ERROR_ACCESS_DENIED; - } - - if (!set_printer_hnd_printername(handle, name)) { - free_a_printer(&printer,2); - close_printer_handle(handle); return ERROR_ACCESS_DENIED; } @@ -4200,7 +4214,7 @@ uint32 _spoolss_getprinterdriverdirectory(UNISTR2 *name, UNISTR2 *uni_environmen /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx, +uint32 _spoolss_enumprinterdata(POLICY_HND *handle, uint32 idx, uint32 in_value_len, uint32 in_data_len, uint32 *out_max_value_len, uint16 **out_value, uint32 *out_value_len, uint32 *out_type, @@ -4327,7 +4341,7 @@ uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx, /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_setprinterdata( const POLICY_HND *handle, +uint32 _spoolss_setprinterdata( POLICY_HND *handle, const UNISTR2 *value, uint32 type, uint32 max_len, @@ -4371,7 +4385,7 @@ uint32 _spoolss_setprinterdata( const POLICY_HND *handle, /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_addform( const POLICY_HND *handle, +uint32 _spoolss_addform( POLICY_HND *handle, uint32 level, const FORM *form) { @@ -4398,7 +4412,7 @@ uint32 _spoolss_addform( const POLICY_HND *handle, /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_setform( const POLICY_HND *handle, +uint32 _spoolss_setform( POLICY_HND *handle, const UNISTR2 *uni_name, uint32 level, const FORM *form) -- cgit From ac70155b252eb57e28d54598556e244da438cd34 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 25 Jul 2000 01:50:53 +0000 Subject: Tidy up code to add printer. Always index in tdb by sharename. This is beginning to come together... Jeremy. (This used to be commit 614bf56186b5836020a7813855a5108da0ee8433) --- source3/rpc_server/srv_spoolss_nt.c | 38 ++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 3a8040d905..7d5036c6d4 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3068,14 +3068,25 @@ static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) * as this is what Samba insists upon. */ - if (!(info->attributes & PRINTER_ATTRIBUTE_SHARED)) + if (!(info->attributes & PRINTER_ATTRIBUTE_SHARED)) { + DEBUG(10,("check_printer_ok: SHARED check failed (%x).\n", (unsigned int)info->attributes )); return False; + } - if (!(info->attributes & PRINTER_ATTRIBUTE_RAW_ONLY)) - return False; + if (!(info->attributes & PRINTER_ATTRIBUTE_RAW_ONLY)) { + /* NT forgets to set the raw attribute but sends the correct type. */ + if (strequal(info->datatype, "RAW")) + info->attributes |= PRINTER_ATTRIBUTE_RAW_ONLY; + else { + DEBUG(10,("check_printer_ok: RAW check failed (%x).\n", (unsigned int)info->attributes )); + return False; + } + } - if (!strequal(info->sharename, lp_servicename(snum))) + if (!strequal(info->sharename, lp_servicename(snum))) { + DEBUG(10,("check_printer_ok: NAME check failed (%s) (%s).\n", info->sharename, lp_servicename(snum))); return False; + } return True; } @@ -4010,6 +4021,7 @@ 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) { DEBUG(0,("spoolss_addprinterex_level_2: malloc fail.\n")); @@ -4021,10 +4033,24 @@ 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->printername, sizeof(share_name)-1); + unistr2_to_ascii(share_name, &info->info_2->sharename, sizeof(share_name)-1); slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname, share_name); + if ((snum = print_queue_snum(share_name)) == -1) { + free_a_printer(&printer,2); + return ERROR_ACCESS_DENIED; + } + + /* + * Do sanity check on the requested changes for Samba. + */ + + if (!check_printer_ok(printer->info_2, snum)) { + free_a_printer(&printer,2); + return ERROR_ACCESS_DENIED; + } + /* write the ASCII on disk */ if (add_a_printer(*printer, 2) != 0) { free_a_printer(&printer,2); @@ -4032,6 +4058,8 @@ 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); free_a_printer(&printer,2); return ERROR_ACCESS_DENIED; } -- cgit From 5a5ef183799dd84ff453db849e929533e709fd0b Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Tue, 25 Jul 2000 13:15:16 +0000 Subject: A rather big change set ! (listed in no particular order) - changed the default forms flag to 2 - all short architecture name are uppercased - get_short_archi() is now case unsensitive - the drivers TDB is indexed by archi/version/name - implemented code to move drivers from the upload area to the download area. Someone else need to look at that code. - don't return anymore a default driver if it doesn't exist in the TDB. Instead return an error. - cleaned prs_unistr. - #ifdef out jeremy's new SD parsing in printer_info_2 - removed the unused MANGLE_CODE - #ifdef out the security checking in update_printer() as it doesn't work for me. Zap your ntdrivers.tdb, it won't work anymore. J.F. (This used to be commit ac0a145acc0953a6f362497abbf4dfe70aa522a6) --- source3/rpc_server/srv_spoolss_nt.c | 407 +++++++++++++++++++----------------- 1 file changed, 210 insertions(+), 197 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 7d5036c6d4..99ed18677a 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -25,10 +25,6 @@ #include "includes.h" -#ifndef MANGLE_DRIVER_PATH -#define MANGLE_DRIVER_PATH 0 -#endif - extern int DEBUGLEVEL; extern pstring global_myname; @@ -2479,73 +2475,66 @@ uint32 _spoolss_getprinter(POLICY_HND *handle, uint32 level, } /******************************************************************** - * construct_printer_driver_info_1 - * fill a construct_printer_driver_info_1 struct + * fill a DRIVER_INFO_1 struct ********************************************************************/ -static void fill_printer_driver_info_1(DRIVER_INFO_1 *info, - NT_PRINTER_DRIVER_INFO_LEVEL driver, - fstring servername, fstring architecture) +static void fill_printer_driver_info_1(DRIVER_INFO_1 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername, fstring architecture) { init_unistr( &(info->name), driver.info_3->name); } -static void construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, - fstring servername, fstring architecture) +/******************************************************************** + * construct_printer_driver_info_1 + ********************************************************************/ +static uint32 construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, fstring servername, fstring architecture, uint32 version) { NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; ZERO_STRUCT(driver); - get_a_printer(&printer, 2, lp_servicename(snum) ); - get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture); - + if (get_a_printer(&printer, 2, lp_servicename(snum)) != 0) + return ERROR_INVALID_PRINTER_NAME; + + if (get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version) != 0) + return ERROR_UNKNOWN_PRINTER_DRIVER; + fill_printer_driver_info_1(info, driver, servername, architecture); free_a_printer(&printer,2); + + return NT_STATUS_NO_PROBLEMO; } /******************************************************************** * construct_printer_driver_info_2 * fill a printer_info_2 struct ********************************************************************/ -static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, - NT_PRINTER_DRIVER_INFO_LEVEL driver, - fstring servername, fstring architecture) +static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername) { - pstring where; pstring temp_driverpath; pstring temp_datafile; pstring temp_configfile; - fstring short_archi; - - get_short_archi(short_archi,architecture); - - snprintf(where,sizeof(where)-1,"\\\\%s\\print$\\%s\\", servername, short_archi); info->version=driver.info_3->cversion; - init_unistr( &info->name, driver.info_3->name ); - init_unistr( &info->architecture, architecture ); - - snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "%s%s", where, - driver.info_3->driverpath); - init_unistr( &info->driverpath, temp_driverpath ); + init_unistr( &info->name, driver.info_3->name ); + init_unistr( &info->architecture, driver.info_3->environment ); - snprintf(temp_datafile, sizeof(temp_datafile)-1, "%s%s", where, - driver.info_3->datafile); - init_unistr( &info->datafile, temp_datafile ); + snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "\\\\%s%s", servername, driver.info_3->driverpath); + init_unistr( &info->driverpath, temp_driverpath ); - snprintf(temp_configfile, sizeof(temp_configfile)-1, "%s%s", where, - driver.info_3->configfile); - init_unistr( &info->configfile, temp_configfile ); + snprintf(temp_datafile, sizeof(temp_datafile)-1, "\\\\%s%s", servername, driver.info_3->datafile); + init_unistr( &info->datafile, temp_datafile ); + + snprintf(temp_configfile, sizeof(temp_configfile)-1, "\\\\%s%s", servername, driver.info_3->configfile); + init_unistr( &info->configfile, temp_configfile ); } /******************************************************************** * construct_printer_driver_info_2 * fill a printer_info_2 struct ********************************************************************/ -static void construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fstring servername, fstring architecture) +static uint32 construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fstring servername, fstring architecture, uint32 version) { NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; @@ -2553,12 +2542,17 @@ static void construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fstri ZERO_STRUCT(printer); ZERO_STRUCT(driver); - get_a_printer(&printer, 2, lp_servicename(snum) ); - get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture); + if (!get_a_printer(&printer, 2, lp_servicename(snum)) != 0) + return ERROR_INVALID_PRINTER_NAME; + + if (!get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version) != 0) + return ERROR_UNKNOWN_PRINTER_DRIVER; - fill_printer_driver_info_2(info, driver, servername, architecture); + fill_printer_driver_info_2(info, driver, servername); free_a_printer(&printer,2); + + return NT_STATUS_NO_PROBLEMO; } /******************************************************************** @@ -2566,7 +2560,7 @@ static void construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fstri * * convert an array of ascii string to a UNICODE string ********************************************************************/ -static void init_unistr_array(uint16 **uni_array, fstring *char_array, char *where) +static void init_unistr_array(uint16 **uni_array, fstring *char_array, char *servername) { int i=0; int j=0; @@ -2584,7 +2578,7 @@ static void init_unistr_array(uint16 **uni_array, fstring *char_array, char *whe if (!v) v = ""; /* hack to handle null lists */ } if (strlen(v) == 0) break; - snprintf(line, sizeof(line)-1, "%s%s", where, v); + snprintf(line, sizeof(line)-1, "\\\\%s%s", servername, v); DEBUGADD(6,("%d:%s:%d\n", i, line, strlen(line))); if((*uni_array=Realloc(*uni_array, (j+strlen(line)+2)*sizeof(uint16))) == NULL) { DEBUG(0,("init_unistr_array: Realloc error\n" )); @@ -2605,67 +2599,63 @@ static void init_unistr_array(uint16 **uni_array, fstring *char_array, char *whe * construct_printer_info_3 * fill a printer_info_3 struct ********************************************************************/ -static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, - NT_PRINTER_DRIVER_INFO_LEVEL driver, - fstring servername, fstring architecture) +static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername) { - pstring where; pstring temp_driverpath; pstring temp_datafile; pstring temp_configfile; pstring temp_helpfile; - fstring short_archi; - - get_short_archi(short_archi, architecture); - -#if MANGLE_DRIVER_PATH - snprintf(where,sizeof(where)-1,"\\\\%s\\print$\\%s\\%s\\", servername, short_archi, driver.info_3->name); -#else - snprintf(where,sizeof(where)-1,"\\\\%s\\print$\\%s\\", servername, short_archi); -#endif info->version=driver.info_3->cversion; - init_unistr( &info->name, driver.info_3->name ); - init_unistr( &info->architecture, architecture ); - - snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "%s%s", where, driver.info_3->driverpath); + init_unistr( &info->name, driver.info_3->name ); + init_unistr( &info->architecture, driver.info_3->environment ); + + snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "\\\\%s%s", servername, driver.info_3->driverpath); init_unistr( &info->driverpath, temp_driverpath ); - - snprintf(temp_datafile, sizeof(temp_datafile)-1, "%s%s", where, driver.info_3->datafile); + + snprintf(temp_datafile, sizeof(temp_datafile)-1, "\\\\%s%s", servername, driver.info_3->datafile); init_unistr( &info->datafile, temp_datafile ); - - snprintf(temp_configfile, sizeof(temp_configfile)-1, "%s%s", where, driver.info_3->configfile); + + snprintf(temp_configfile, sizeof(temp_configfile)-1, "\\\\%s%s", servername, driver.info_3->configfile); init_unistr( &info->configfile, temp_configfile ); - - snprintf(temp_helpfile, sizeof(temp_helpfile)-1, "%s%s", where, driver.info_3->helpfile); + + snprintf(temp_helpfile, sizeof(temp_helpfile)-1, "\\\\%s%s", servername, driver.info_3->helpfile); init_unistr( &info->helpfile, temp_helpfile ); init_unistr( &info->monitorname, driver.info_3->monitorname ); init_unistr( &info->defaultdatatype, driver.info_3->defaultdatatype ); info->dependentfiles=NULL; - init_unistr_array(&info->dependentfiles, driver.info_3->dependentfiles, where); + init_unistr_array(&info->dependentfiles, driver.info_3->dependentfiles, servername); } /******************************************************************** * construct_printer_info_3 * fill a printer_info_3 struct ********************************************************************/ -static void construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, - fstring servername, fstring architecture) +static uint32 construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fstring servername, fstring architecture, uint32 version) { NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; - +uint32 status=0; ZERO_STRUCT(driver); - get_a_printer(&printer, 2, lp_servicename(snum) ); - get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture); + status=get_a_printer(&printer, 2, lp_servicename(snum) ); + DEBUG(8,("construct_printer_driver_info_3: status: %d\n", status)); + if (status != 0) + return ERROR_INVALID_PRINTER_NAME; + + status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version); + DEBUG(8,("construct_printer_driver_info_3: status: %d\n", status)); + if (status != 0) + return ERROR_UNKNOWN_PRINTER_DRIVER; - fill_printer_driver_info_3(info, driver, servername, architecture); + fill_printer_driver_info_3(info, driver, servername); free_a_printer(&printer,2); + + return NT_STATUS_NO_PROBLEMO; } /**************************************************************************** @@ -2678,14 +2668,19 @@ static void free_printer_driver_info_3(DRIVER_INFO_3 *info) /**************************************************************************** ****************************************************************************/ -static uint32 getprinterdriver2_level1(fstring servername, fstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static uint32 getprinterdriver2_level1(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_1 *info=NULL; + uint32 status; if((info=(DRIVER_INFO_1 *)malloc(sizeof(DRIVER_INFO_1))) == NULL) return ERROR_NOT_ENOUGH_MEMORY; - construct_printer_driver_info_1(info, snum, servername, architecture); + status=construct_printer_driver_info_1(info, snum, servername, architecture, version); + if (status != NT_STATUS_NO_PROBLEMO) { + safe_free(info); + return status; + } /* check the required size. */ *needed += spoolss_size_printer_driver_info_1(info); @@ -2709,14 +2704,19 @@ static uint32 getprinterdriver2_level1(fstring servername, fstring architecture, /**************************************************************************** ****************************************************************************/ -static uint32 getprinterdriver2_level2(fstring servername, fstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static uint32 getprinterdriver2_level2(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_2 *info=NULL; + uint32 status; if((info=(DRIVER_INFO_2 *)malloc(sizeof(DRIVER_INFO_2))) == NULL) return ERROR_NOT_ENOUGH_MEMORY; - construct_printer_driver_info_2(info, snum, servername, architecture); + status=construct_printer_driver_info_2(info, snum, servername, architecture, version); + if (status != NT_STATUS_NO_PROBLEMO) { + safe_free(info); + return status; + } /* check the required size. */ *needed += spoolss_size_printer_driver_info_2(info); @@ -2740,13 +2740,17 @@ static uint32 getprinterdriver2_level2(fstring servername, fstring architecture, /**************************************************************************** ****************************************************************************/ -static uint32 getprinterdriver2_level3(fstring servername, fstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static uint32 getprinterdriver2_level3(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_3 info; + uint32 status; ZERO_STRUCT(info); - construct_printer_driver_info_3(&info, snum, servername, architecture); + status=construct_printer_driver_info_3(&info, snum, servername, architecture, version); + if (status != NT_STATUS_NO_PROBLEMO) { + return status; + } /* check the required size. */ *needed += spoolss_size_printer_driver_info_3(&info); @@ -2792,13 +2796,13 @@ uint32 _spoolss_getprinterdriver2(POLICY_HND *handle, const UNISTR2 *uni_arch, u switch (level) { case 1: - return getprinterdriver2_level1(servername, architecture, snum, buffer, offered, needed); + return getprinterdriver2_level1(servername, architecture, clientmajorversion, snum, buffer, offered, needed); break; case 2: - return getprinterdriver2_level2(servername, architecture, snum, buffer, offered, needed); + return getprinterdriver2_level2(servername, architecture, clientmajorversion, snum, buffer, offered, needed); break; case 3: - return getprinterdriver2_level3(servername, architecture, snum, buffer, offered, needed); + return getprinterdriver2_level3(servername, architecture, clientmajorversion, snum, buffer, offered, needed); break; default: return ERROR_INVALID_LEVEL; @@ -3113,7 +3117,7 @@ static uint32 update_printer(POLICY_HND *handle, uint32 level, /* Check calling user has permission to update printer description */ -#if 1 /* JFMTEST */ +#if 0 /* JFMTEST */ if (!nt_printing_getsec(Printer->dev.handlename, &sd)) { DEBUG(3, ("Could not get security descriptor for printer %s", Printer->dev.handlename)); @@ -3543,24 +3547,46 @@ uint32 _spoolss_setjob( POLICY_HND *handle, /**************************************************************************** Enumerates all printer drivers at level 1. ****************************************************************************/ -static uint32 enumprinterdrivers_level1(fstring *list, fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static uint32 enumprinterdrivers_level1(fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int i; + int ndrivers; + uint32 version; + fstring *list = NULL; + NT_PRINTER_DRIVER_INFO_LEVEL driver; DRIVER_INFO_1 *driver_info_1=NULL; - ZERO_STRUCT(driver); + *returned=0; - if((driver_info_1=(DRIVER_INFO_1 *)malloc(*returned * sizeof(DRIVER_INFO_1))) == NULL) - return ERROR_NOT_ENOUGH_MEMORY; +#define MAX_VERSION 4 - for (i=0; i<*returned; i++) { - get_a_printer_driver(&driver, 3, list[i], architecture); - fill_printer_driver_info_1(&(driver_info_1[i]), driver, servername, architecture ); + for (version=0; version 0 && - !(driver_info_2=(DRIVER_INFO_2 *)malloc(*returned * sizeof(DRIVER_INFO_2)))) - return ERROR_NOT_ENOUGH_MEMORY; + *returned=0; - for (i=0; i<*returned; i++) { - NT_PRINTER_DRIVER_INFO_LEVEL driver; - ZERO_STRUCT(driver); - if (get_a_printer_driver(&driver, 3, list[i], architecture) - != 0) { - *returned = i; - break; +#define MAX_VERSION 4 + + for (version=0; versioninfo_3->environment); - model = driver->info_3->name; - break; - case 6: - get_short_archi(short_archi, driver->info_6->environment); - model = driver->info_6->name; - break; - default: - DEBUG(0,("modify_driver_heirarchy: unknown info level (%d)\n", level)); - return ERROR_INVALID_LEVEL; - break; - } - - slprintf(path_old, sizeof(path_old)-1, "%s/%s/TMP_%s", lp_pathname(snum), short_archi, - client_addr()); - - /* Clean up any '/' and other characters in the model name. */ - alpha_strcpy(model_name, model, sizeof(pstring)); - - slprintf(path_new, sizeof(path_new)-1, "%s/%s/%s", lp_pathname(snum), short_archi, model_name); - - DEBUG(10,("modify_driver_heirarchy: old_path=%s, new_path=%s\n", - path_old, path_new )); - if (dos_rename(path_old, path_new) == -1) { - DEBUG(0,("modify_driver_heirarchy: rename from %s to %s failed (%s)\n", - path_old, path_new, strerror(errno) )); - /* We need to clean up here.... - how ? */ - return ERROR_ACCESS_DENIED; /* We need a generic mapping from NT errors here... */ - } - - return NT_STATUS_NO_PROBLEMO; -} -#endif - /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_addprinterdriver( const UNISTR2 *server_name, - uint32 level, - const SPOOL_PRINTER_DRIVER_INFO_LEVEL *info) +uint32 _spoolss_addprinterdriver(pipes_struct *p, const UNISTR2 *server_name, + uint32 level, const SPOOL_PRINTER_DRIVER_INFO_LEVEL *info) { uint32 err = NT_STATUS_NO_PROBLEMO; NT_PRINTER_DRIVER_INFO_LEVEL driver; + struct current_user user; + ZERO_STRUCT(driver); + if (p->ntlmssp_auth_validated) { + memcpy(&user, &p->pipe_user, sizeof(user)); + } else { + extern struct current_user current_user; + memcpy(&user, ¤t_user, sizeof(user)); + } + convert_printer_driver_info(info, &driver, level); + DEBUG(5,("Cleaning driver's information\n")); + clean_up_driver_struct(driver, level); + + DEBUG(5,("Moving driver to final destination\n")); + move_driver_to_download_area(driver, level, &user); + if (add_a_printer_driver(driver, level)!=0) return ERROR_ACCESS_DENIED; -#if MANGLE_DRIVER_PATH - err = modify_driver_heirarchy(&driver, level); -#endif - free_a_printer_driver(driver, level); return err; @@ -4185,20 +4201,17 @@ static uint32 getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen pstring long_archi; pstring short_archi; DRIVER_DIRECTORY_1 *info=NULL; - + + unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)-1); + + if (get_short_archi(short_archi, long_archi)==FALSE) + return ERROR_INVALID_ENVIRONMENT; + if((info=(DRIVER_DIRECTORY_1 *)malloc(sizeof(DRIVER_DIRECTORY_1))) == NULL) return ERROR_NOT_ENOUGH_MEMORY; - - unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)-1); - get_short_archi(short_archi, long_archi); - -#if MANGLE_DRIVER_PATH - slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s\\TMP_%s", global_myname, short_archi, - client_addr()); -#else - slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", - global_myname, short_archi); -#endif + + slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", global_myname, short_archi); + DEBUG(4,("printer driver directory: [%s]\n", path)); fill_driverdir_1(info, path); -- cgit From fcbf69495784000861d432c13217702cc28884f8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 25 Jul 2000 17:09:29 +0000 Subject: Added some error checking and returns to the new 'move' code. Jeremy. (This used to be commit 0bd88d304cd773e0bbf3e6f7fedcb3b544d41cbe) --- source3/rpc_server/srv_spoolss_nt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 99ed18677a..53df5dfee4 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4176,7 +4176,8 @@ uint32 _spoolss_addprinterdriver(pipes_struct *p, const UNISTR2 *server_name, clean_up_driver_struct(driver, level); DEBUG(5,("Moving driver to final destination\n")); - move_driver_to_download_area(driver, level, &user); + if(!move_driver_to_download_area(driver, level, &user)) + return ERROR_ACCESS_DENIED; if (add_a_printer_driver(driver, level)!=0) return ERROR_ACCESS_DENIED; @@ -4190,7 +4191,7 @@ uint32 _spoolss_addprinterdriver(pipes_struct *p, const UNISTR2 *server_name, ****************************************************************************/ static void fill_driverdir_1(DRIVER_DIRECTORY_1 *info, char *name) { - init_unistr(&(info->name), name); + init_unistr(&info->name, name); } /**************************************************************************** -- cgit From bc22ae0b47bddd919b07e4c81ae12243c1f3226a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 25 Jul 2000 22:35:57 +0000 Subject: Fixed up error checking and move printer file code. Fixed a memory leak. Jeremy. (This used to be commit 5130dd0f8b80aed5fb3c0df290b627057cc9b825) --- source3/rpc_server/srv_spoolss_nt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 53df5dfee4..30131482ac 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2648,8 +2648,10 @@ uint32 status=0; status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version); DEBUG(8,("construct_printer_driver_info_3: status: %d\n", status)); - if (status != 0) + if (status != 0) { + free_a_printer(&printer,2); return ERROR_UNKNOWN_PRINTER_DRIVER; + } fill_printer_driver_info_3(info, driver, servername); @@ -3764,7 +3766,6 @@ uint32 _spoolss_enumprinterdrivers( UNISTR2 *name, UNISTR2 *environment, uint32 NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { - int i; fstring *list = NULL; fstring servername; fstring architecture; -- cgit From c89cf814cc976924c9e1db7ea448af3893a6f70d Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 26 Jul 2000 03:38:30 +0000 Subject: Fixed memory leaks in _spoolss_addprinterdriver() (This used to be commit 1f49788442b0d1264c70166e727b8588b936e6ec) --- source3/rpc_server/srv_spoolss_nt.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 30131482ac..288b9648b7 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4177,14 +4177,18 @@ uint32 _spoolss_addprinterdriver(pipes_struct *p, const UNISTR2 *server_name, clean_up_driver_struct(driver, level); DEBUG(5,("Moving driver to final destination\n")); - if(!move_driver_to_download_area(driver, level, &user)) - return ERROR_ACCESS_DENIED; + if(!move_driver_to_download_area(driver, level, &user)) { + err = ERROR_ACCESS_DENIED; + goto done; + } - if (add_a_printer_driver(driver, level)!=0) - return ERROR_ACCESS_DENIED; + if (add_a_printer_driver(driver, level)!=0) { + err = ERROR_ACCESS_DENIED; + goto done; + } + done: free_a_printer_driver(driver, level); - return err; } -- cgit From 134a4b86548db77cba292c50fbd6b91ecaa69f14 Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Wed, 26 Jul 2000 10:31:05 +0000 Subject: if no comment in TDB, use comment from print share. J.F. (This used to be commit c267b23620677a11f702bfea4885a28e66a05b05) --- source3/rpc_server/srv_spoolss_nt.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 288b9648b7..76dff789c6 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -947,8 +947,12 @@ static void spoolss_notify_driver_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, p ********************************************************************/ static void spoolss_notify_comment(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { - data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, + if (*printer->info_2->comment == '\0') + data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, lp_comment(snum), sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16)); + else + data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, + printer->info_2->comment, sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16)); } /******************************************************************* @@ -1729,14 +1733,21 @@ static BOOL construct_printer_info_1(fstring server, uint32 flags, PRINTER_INFO_ printer->flags=flags; - snprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",server, ntprinter->info_2->printername, - ntprinter->info_2->drivername, lp_comment(snum)); + if (*ntprinter->info_2->comment == '\0') { + init_unistr(&printer->comment, lp_comment(snum)); + snprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",server, ntprinter->info_2->printername, + ntprinter->info_2->drivername, lp_comment(snum)); + } + else { + init_unistr(&printer->comment, ntprinter->info_2->comment); /* saved comment. */ + snprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",server, ntprinter->info_2->printername, + ntprinter->info_2->drivername, ntprinter->info_2->comment); + } snprintf(chaine2,sizeof(chaine)-1,"%s%s", server, ntprinter->info_2->printername); init_unistr(&printer->description, chaine); init_unistr(&printer->name, chaine2); - init_unistr(&printer->comment, lp_comment(snum)); free_a_printer(&ntprinter,2); -- cgit From 5ec1642809d9de83da8c88c65d6595c6eb0270f5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 27 Jul 2000 00:47:19 +0000 Subject: Ok - this is a *BIG* change - but it fixes the problems with static strings in the RPC code. This change was prompted by trying to save a long (>256) character comment in the printer properties page. The new system associates a TALLOC_CTX with the pipe struct, and frees the pool on return of a complete PDU. A global TALLOC_CTX is used for the odd buffer allocated in the BUFFERxx code, and is freed in the main loop. This code works with insure, and seems to be free of memory leaks and crashes (so far) but there are probably the occasional problem with code that uses UNISTRxx structs on the stack and expects them to contain storage without doing a init_unistrXX(). This means that rpcclient will probably be horribly broken. A TALLOC_CTX also needed associating with the struct cli_state also, to make the prs_xx code there work. The main interface change is the addition of a TALLOC_CTX to the prs_init calls - used for dynamic allocation in the prs_XXX calls. Now this is in place it should make dynamic allocation of all RPC memory on unmarshall *much* easier to fix. Jeremy. (This used to be commit 0ff2ce543ee54f7364e6d839db6d06e7ef1edcf4) --- source3/rpc_server/srv_spoolss_nt.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 76dff789c6..c9d81e1cba 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2490,7 +2490,7 @@ uint32 _spoolss_getprinter(POLICY_HND *handle, uint32 level, ********************************************************************/ static void fill_printer_driver_info_1(DRIVER_INFO_1 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername, fstring architecture) { - init_unistr( &(info->name), driver.info_3->name); + init_unistr( &info->name, driver.info_3->name); } /******************************************************************** @@ -3336,7 +3336,7 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, snprintf(chaine, sizeof(chaine)-1, "\\\\%s\\%s", global_myname, ntprinter->info_2->printername); - init_unistr(&(job_info->printername), chaine); + init_unistr(&job_info->printername, chaine); init_unistr(&job_info->machinename, temp_name); init_unistr(&job_info->username, queue->user); @@ -4506,7 +4506,7 @@ static uint32 enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, ui (*returned) = 0x1; - init_unistr(&(info_1->name), "winprint"); + init_unistr(&info_1->name, "winprint"); *needed += spoolss_size_printprocessor_info_1(info_1); @@ -4565,7 +4565,7 @@ static uint32 enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered, (*returned) = 0x1; - init_unistr(&(info_1->name), "RAW"); + init_unistr(&info_1->name, "RAW"); *needed += spoolss_size_printprocdatatype_info_1(info_1); @@ -4617,7 +4617,7 @@ static uint32 enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, uint (*returned) = 0x1; - init_unistr(&(info_1->name), "Local Port"); + init_unistr(&info_1->name, "Local Port"); *needed += spoolss_size_printmonitor_info_1(info_1); @@ -4648,9 +4648,9 @@ static uint32 enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint (*returned) = 0x1; - init_unistr(&(info_2->name), "Local Port"); - init_unistr(&(info_2->environment), "Windows NT X86"); - init_unistr(&(info_2->dll_name), "localmon.dll"); + init_unistr(&info_2->name, "Local Port"); + init_unistr(&info_2->environment, "Windows NT X86"); + init_unistr(&info_2->dll_name, "localmon.dll"); *needed += spoolss_size_printmonitor_info_2(info_2); -- cgit 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/srv_spoolss_nt.c') 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 From 55ff9cb38bbabfaee591f6f5190e57b5564f3942 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 31 Jul 2000 21:41:03 +0000 Subject: Save & restore the port name correctly. Jeremy. (This used to be commit c0648c981edef2a29b3a22a7d08aa226ca724e95) --- source3/rpc_server/srv_spoolss_nt.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index b675175544..47df204ef3 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1935,12 +1935,7 @@ static BOOL construct_printer_info_2(fstring servername, PRINTER_INFO_2 *printer init_unistr(&printer->servername, chaine); /* servername*/ init_unistr(&printer->printername, chaine2); /* printername*/ init_unistr(&printer->sharename, lp_servicename(snum)); /* sharename */ -#if 1 /* JRATEST */ - /* We need to determine the correct model for this..... */ - init_unistr(&printer->portname, lp_printername(snum)); /* port */ -#else - init_unistr(&printer->portname, lp_servicename(snum)); /* port */ -#endif + init_unistr(&printer->portname, ntprinter->info_2->portname); /* port */ init_unistr(&printer->drivername, ntprinter->info_2->drivername); /* drivername */ if (*ntprinter->info_2->comment == '\0') @@ -1966,9 +1961,6 @@ static BOOL construct_printer_info_2(fstring servername, PRINTER_INFO_2 *printer if((printer->devmode = construct_dev_mode(snum, servername)) == NULL) { DEBUG(8, ("Returning NULL Devicemode!\n")); -#if 0 /* JFMTEST */ - goto err; -#endif } if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->len != 0) { @@ -1985,13 +1977,6 @@ static BOOL construct_printer_info_2(fstring servername, PRINTER_INFO_2 *printer free_a_printer(&ntprinter, 2); safe_free(queue); return True; - - err: - - if (ntprinter) - free_a_printer(&ntprinter, 2); - safe_free(queue); - return False; } /******************************************************************** -- cgit From d95777ac34f68a3525786103b9217f6397d9f1d4 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 1 Aug 2000 00:41:19 +0000 Subject: Added print job substitutions for %{printername}, %{sharename} and %{portname} from the NT printer tdb. Also added checks for time restrictions before allowing a job to print. Jeremy. (This used to be commit 8cfb55e81abebf0354e6d470ed68bbac1d6560ad) --- source3/rpc_server/srv_spoolss_nt.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 47df204ef3..4774375db4 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -28,10 +28,6 @@ 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 @@ -3339,7 +3335,7 @@ static void fill_job_info_1(JOB_INFO_1 *job_info, print_queue_struct *queue, job_info->totalpages=0; job_info->pagesprinted=0; - make_systemtime(&(job_info->submitted), t); + make_systemtime(&job_info->submitted, t); } /**************************************************************************** -- cgit From db2445358161e1a0a68b80a7551ed88e7dcc38c6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 9 Aug 2000 04:19:18 +0000 Subject: added printer admin option any user in that list can do anything to a printer (This used to be commit 7b5912be150dd590d6195be40b0976305b8716ba) --- source3/rpc_server/srv_spoolss_nt.c | 68 ++++++++++++++----------------------- 1 file changed, 26 insertions(+), 42 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 4774375db4..d6c39fa022 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3049,19 +3049,18 @@ static uint32 update_printer_sec(POLICY_HND *handle, uint32 level, const SPOOL_PRINTER_INFO_LEVEL *info, pipes_struct *p, SEC_DESC_BUF *secdesc_ctr) { - SEC_DESC_BUF *old_secdesc_ctr = NULL; struct current_user user; - uint32 acc_granted, status, result; + uint32 result; + int snum; Printer_entry *Printer = find_printer_index_by_hnd(handle); - if (!OPEN_HANDLE(Printer)) { + if (!OPEN_HANDLE(Printer) || !get_printer_snum(handle, &snum)) { DEBUG(0,("update_printer_sec: Invalid handle (%s)\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; } /* Work out which user is performing the operation */ - if (p->ntlmssp_auth_validated) { memcpy(&user, &p->pipe_user, sizeof(user)); } else { @@ -3069,32 +3068,18 @@ static uint32 update_printer_sec(POLICY_HND *handle, uint32 level, memcpy(&user, ¤t_user, sizeof(user)); } - /* Get old security descriptor */ - - if (!nt_printing_getsec(Printer->dev.handlename, &old_secdesc_ctr)) { - DEBUG(3, ("could not get old security descriptor for " - "printer %s", Printer->dev.handlename)); - return ERROR_INVALID_FUNCTION; - } - /* Check the user has permissions to change the security descriptor. By experimentation with two NT machines, the user requires Full Access to the printer to change security information. */ - - if (!se_access_check(old_secdesc_ctr->sec, &user, - PRINTER_ACE_FULL_CONTROL, &acc_granted, - &status)) { - DEBUG(3, ("security descriptor change denied by existing " - "security descriptor\n")); - result = status; + if (!print_access_check(&user, snum, PRINTER_ACE_FULL_CONTROL)) { + result = NT_STATUS_ACCESS_DENIED; goto done; } result = nt_printing_setsec(Printer->dev.handlename, secdesc_ctr); done: - free_sec_desc_buf(&old_secdesc_ctr); return result; } @@ -3144,9 +3129,7 @@ static uint32 update_printer(POLICY_HND *handle, uint32 level, int snum; NT_PRINTER_INFO_LEVEL *printer = NULL; Printer_entry *Printer = find_printer_index_by_hnd(handle); - SEC_DESC_BUF *sd = NULL; - uint32 result, acc_granted; - extern struct current_user current_user; + uint32 result; DEBUG(8,("update_printer\n")); @@ -3154,22 +3137,6 @@ static uint32 update_printer(POLICY_HND *handle, uint32 level, /* Check calling user has permission to update printer description */ -#if 0 /* JFMTEST */ - if (!nt_printing_getsec(Printer->dev.handlename, &sd)) { - DEBUG(3, ("Could not get security descriptor for printer %s", - Printer->dev.handlename)); - result = ERROR_INVALID_FUNCTION; - goto done; - } - - if (!se_access_check(sd->sec, ¤t_user, - PRINTER_ACE_FULL_CONTROL, &acc_granted, - &result)) { - DEBUG(3, ("printer property change denied by security " - "descriptor\n")); - goto done; - } -#endif if (level!=2) { DEBUG(0,("Send a mail to samba@samba.org\n")); DEBUGADD(0,("with the following message: update_printer: level!=2\n")); @@ -3186,6 +3153,13 @@ static uint32 update_printer(POLICY_HND *handle, uint32 level, result = ERROR_INVALID_HANDLE; goto done; } + + if (!print_access_check(NULL, snum, PRINTER_ACE_FULL_CONTROL)) { + DEBUG(3, ("printer property change denied by security " + "descriptor\n")); + result = NT_STATUS_ACCESS_DENIED; + goto done; + } if(get_a_printer(&printer, 2, lp_servicename(snum)) != 0) { result = ERROR_INVALID_HANDLE; @@ -3240,7 +3214,6 @@ static uint32 update_printer(POLICY_HND *handle, uint32 level, done: free_a_printer(&printer, 2); - free_sec_desc_buf(&sd); return result; } @@ -4251,6 +4224,12 @@ static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name, free_a_printer(&printer,2); return ERROR_ACCESS_DENIED; } + + /* you must be a printer admin to add a new printer */ + if (!print_access_check(NULL, snum, PRINTER_ACE_FULL_CONTROL)) { + free_a_printer(&printer,2); + return ERROR_ACCESS_DENIED; + } /* * Do sanity check on the requested changes for Samba. @@ -4547,8 +4526,7 @@ uint32 _spoolss_setprinterdata( POLICY_HND *handle, uint32 numeric_data) { NT_PRINTER_INFO_LEVEL *printer = NULL; - NT_PRINTER_PARAM *param = NULL; - + NT_PRINTER_PARAM *param = NULL; int snum=0; uint32 status = 0x0; Printer_entry *Printer=find_printer_index_by_hnd(handle); @@ -4564,6 +4542,12 @@ uint32 _spoolss_setprinterdata( POLICY_HND *handle, if (!get_printer_snum(handle, &snum)) return ERROR_INVALID_HANDLE; + if (!print_access_check(NULL, snum, PRINTER_ACE_FULL_CONTROL)) { + DEBUG(3, ("security descriptor change denied by existing " + "security descriptor\n")); + return NT_STATUS_ACCESS_DENIED; + } + status = get_a_printer(&printer, 2, lp_servicename(snum)); if (status != 0x0) return ERROR_INVALID_NAME; -- cgit From fadb15da71d6143e622f7fb669080c5b882df48f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 9 Aug 2000 07:34:35 +0000 Subject: got error code right for printer update/add failure (This used to be commit 0d00d2ec258b36d73e865f06d5d11745d7cdafa9) --- source3/rpc_server/srv_spoolss_nt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index d6c39fa022..08abf4c301 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3073,7 +3073,7 @@ static uint32 update_printer_sec(POLICY_HND *handle, uint32 level, requires Full Access to the printer to change security information. */ if (!print_access_check(&user, snum, PRINTER_ACE_FULL_CONTROL)) { - result = NT_STATUS_ACCESS_DENIED; + result = ERROR_ACCESS_DENIED; goto done; } @@ -3157,7 +3157,7 @@ static uint32 update_printer(POLICY_HND *handle, uint32 level, if (!print_access_check(NULL, snum, PRINTER_ACE_FULL_CONTROL)) { DEBUG(3, ("printer property change denied by security " "descriptor\n")); - result = NT_STATUS_ACCESS_DENIED; + result = ERROR_ACCESS_DENIED; goto done; } @@ -4545,7 +4545,7 @@ uint32 _spoolss_setprinterdata( POLICY_HND *handle, if (!print_access_check(NULL, snum, PRINTER_ACE_FULL_CONTROL)) { DEBUG(3, ("security descriptor change denied by existing " "security descriptor\n")); - return NT_STATUS_ACCESS_DENIED; + return ERROR_ACCESS_DENIED; } status = get_a_printer(&printer, 2, lp_servicename(snum)); -- cgit From 137b7f873a7885a9ee30871403229e338a8a4a04 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 10 Aug 2000 23:41:16 +0000 Subject: Added "add_printer_hook" call to update printer for Win9x clients. Patch from John Reilly . Jeremy. (This used to be commit 76a5713bd3fad18ec60d12fc3f965f3e9717c159) --- source3/rpc_server/srv_spoolss_nt.c | 130 +++++++++++++++++++----------------- 1 file changed, 68 insertions(+), 62 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 08abf4c301..a8b948db4a 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3117,6 +3117,68 @@ static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) return True; } +/**************************************************************************** +****************************************************************************/ +static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) +{ + pid_t local_pid = sys_getpid(); + char *cmd = lp_addprinter_cmd(); + char *path; + char **qlines; + pstring tmp_file; + pstring command; + pstring driverlocation; + int numlines; + int ret; + + if (*lp_pathname(lp_servicenumber(PRINTERS_NAME))) + path = lp_pathname(lp_servicenumber(PRINTERS_NAME)); + else + path = tmpdir(); + + /* build driver path... only 9X architecture is needed for legacy reasons */ + slprintf(driverlocation, sizeof(driverlocation)-1, "\\\\%s\\print$\\WIN40\\0", + global_myname); + /* change \ to \\ for the shell */ + all_string_sub(driverlocation,"\\","\\\\",sizeof(pstring)); + + slprintf(tmp_file, sizeof(tmp_file), "%s/smbcmd.%d", path, local_pid); + slprintf(command, sizeof(command), "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"", + cmd, printer->info_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; +} + /******************************************************************** * called by spoolss_api_setprinter * when updating a printer description @@ -3206,6 +3268,12 @@ static uint32 update_printer(POLICY_HND *handle, uint32 level, goto done; } + if (*lp_addprinter_cmd() ) + if ( !add_printer_hook(printer) ) { + result = ERROR_ACCESS_DENIED; + goto done; + } + if (add_a_printer(*printer, 2)!=0) { /* I don't really know what to return here !!! */ result = ERROR_ACCESS_DENIED; @@ -4129,68 +4197,6 @@ uint32 _spoolss_enumports( UNISTR2 *name, uint32 level, } } -/**************************************************************************** -****************************************************************************/ -static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) -{ - pid_t local_pid = sys_getpid(); - char *cmd = lp_addprinter_cmd(); - char *path; - char **qlines; - pstring tmp_file; - pstring command; - pstring driverlocation; - int numlines; - int ret; - - if (*lp_pathname(lp_servicenumber(PRINTERS_NAME))) - path = lp_pathname(lp_servicenumber(PRINTERS_NAME)); - else - path = tmpdir(); - - /* build driver path... only 9X architecture is needed for legacy reasons */ - slprintf(driverlocation, sizeof(driverlocation)-1, "\\\\%s\\print$\\WIN40\\0", - global_myname); - /* change \ to \\ for the shell */ - all_string_sub(driverlocation,"\\","\\\\",sizeof(pstring)); - - slprintf(tmp_file, sizeof(tmp_file), "%s/smbcmd.%d", path, local_pid); - slprintf(command, sizeof(command), "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"", - cmd, printer->info_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, -- cgit From f03879e0b3db1871d003bfb5713a88928f032260 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 23 Aug 2000 23:05:49 +0000 Subject: Tidied up some error returns from printing calls. Still need to map UNIX errors to NT error for print job failure returns. Patch from John Reilly at HP. Jeremy. (This used to be commit 3514b5bb8fffd78e3647425d93b74e2e6291bafc) --- source3/rpc_server/srv_spoolss_nt.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a8b948db4a..36a8a1697c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2919,19 +2919,16 @@ uint32 _spoolss_startdocprinter(POLICY_HND *handle, uint32 level, * server-side code. *nnnnnggggh!* */ - if (info_1->p_datatype != 0) - { - unistr2_to_ascii(datatype, &(info_1->docname), sizeof(datatype)); - if (strcmp(datatype, "RAW") != 0) - { + if (info_1->p_datatype != 0) { + unistr2_to_ascii(datatype, &info_1->docname, sizeof(datatype)); + if (strcmp(datatype, "RAW") != 0) { (*jobid)=0; return ERROR_INVALID_DATATYPE; } } /* get the share number of the printer */ - if (!get_printer_snum(handle, &snum)) - { + if (!get_printer_snum(handle, &snum)) { return ERROR_INVALID_HANDLE; } -- cgit From 9e1f9a5719315aaa9b184fc5b0a750c68fbd8941 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 28 Aug 2000 04:42:31 +0000 Subject: yipee! The spoolss AddJob function has an [in,out] buffer not an [in] buffer (despite the comment in the code to the contrary). Also, we must fail this function - not just blindly reply "no problem" as AddJob should always fail on non-local printers. This fixes a bug where the "print test page" failed about half the time. I suspect it will also fix a bunch of other intermittent spoolss bugs where the client (incorrectly) tries to use the AddJob printing interface. (This used to be commit 14e534a8907c34b53e00a63756efd71903ff9432) --- source3/rpc_server/srv_spoolss_nt.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 36a8a1697c..b118b7c933 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3342,9 +3342,14 @@ uint32 _spoolss_fcpn(POLICY_HND *handle) /**************************************************************************** ****************************************************************************/ uint32 _spoolss_addjob(POLICY_HND *handle, uint32 level, - NEW_BUFFER *buffer, uint32 offered) -{ - return NT_STATUS_NO_PROBLEMO; + NEW_BUFFER *buffer, uint32 offered, + uint32 *needed) +{ + *needed = 0; + return ERROR_INVALID_PARAMETER; /* this is what a NT server + returns for AddJob. AddJob + must fail on non-local + printers */ } /**************************************************************************** -- cgit From d407579b94ee2647d1e51c536534024e5c4c51ad Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 30 Aug 2000 00:45:59 +0000 Subject: Implemented AbortPrinter() from Gerald's Win32 test code. Just purge all possible printjobs from that printer (I think this is correct). Added error code returns for print_queue_XXX() functions. Jeremy. (This used to be commit 6d081a9017f87f59b7189ba507e211db01c40af5) --- source3/rpc_server/srv_spoolss_nt.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index b118b7c933..b9266c7ee1 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2999,6 +2999,7 @@ static uint32 control_printer(POLICY_HND *handle, uint32 command, { struct current_user user; int snum; + int errcode = 0; Printer_entry *Printer = find_printer_index_by_hnd(handle); if (p->ntlmssp_auth_validated) { @@ -3018,26 +3019,38 @@ static uint32 control_printer(POLICY_HND *handle, uint32 command, switch (command) { case PRINTER_CONTROL_PAUSE: - if (print_queue_pause(&user, snum)) { + if (print_queue_pause(&user, snum, &errcode)) { return 0; } break; case PRINTER_CONTROL_RESUME: case PRINTER_CONTROL_UNPAUSE: - if (print_queue_resume(&user, snum)) { + if (print_queue_resume(&user, snum, &errcode)) { return 0; } break; case PRINTER_CONTROL_PURGE: - if (print_queue_purge(&user, snum)) { + if (print_queue_purge(&user, snum, &errcode)) { return 0; } break; } + if (errcode) + return (uint32)errcode; + return ERROR_INVALID_FUNCTION; } +/******************************************************************** + * api_spoolss_abortprinter + ********************************************************************/ + +uint32 _spoolss_abortprinter(POLICY_HND *handle, pipes_struct *p) +{ + return control_printer(handle, PRINTER_CONTROL_PURGE, p); +} + /******************************************************************** * called by spoolss_api_setprinter * when updating a printer description -- cgit From c77bf3d9e2ef416050bd2a25576f8fa584107fb5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 30 Aug 2000 21:09:21 +0000 Subject: Fixed error returns for moving printer driver files around so generic "Access denied" isn't always returned. More fixes found using Gerald's wonderful Win32 test progs :-). Jeremy. (This used to be commit 67b9d40e3df19523714430cb4457717575f2a61e) --- source3/rpc_server/srv_spoolss_nt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index b9266c7ee1..8f58f72d73 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4327,8 +4327,9 @@ uint32 _spoolss_addprinterdriver(pipes_struct *p, const UNISTR2 *server_name, clean_up_driver_struct(driver, level); DEBUG(5,("Moving driver to final destination\n")); - if(!move_driver_to_download_area(driver, level, &user)) { - err = ERROR_ACCESS_DENIED; + if(!move_driver_to_download_area(driver, level, &user, &err)) { + if (err == 0) + err = ERROR_ACCESS_DENIED; goto done; } -- cgit From fa810d4c8001c10bddce452b4ab1178eb80dee87 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 31 Aug 2000 19:04:51 +0000 Subject: Implemented DELETEFORM tested using Gerald's Win32 test code :-). Jeremy. (This used to be commit 596c21a2af0309ce43a5e52a343a671036d05ebf) --- source3/rpc_server/srv_spoolss_nt.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 8f58f72d73..0938b37ab3 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4613,6 +4613,31 @@ uint32 _spoolss_addform( POLICY_HND *handle, return 0x0; } +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_deleteform( POLICY_HND *handle, UNISTR2 *form_name) +{ + int count=0; + uint32 ret = 0; + nt_forms_struct *list=NULL; + Printer_entry *Printer = find_printer_index_by_hnd(handle); + + DEBUG(5,("spoolss_deleteform\n")); + + if (!OPEN_HANDLE(Printer)) { + DEBUG(0,("_spoolss_deleteform: Invalid handle (%s).\n", OUR_HANDLE(handle))); + return ERROR_INVALID_HANDLE; + } + + count = get_ntforms(&list); + if(!delete_a_form(&list, form_name, &count, &ret)) + return ERROR_INVALID_PARAMETER; + + safe_free(list); + + return ret; +} + /**************************************************************************** ****************************************************************************/ uint32 _spoolss_setform( POLICY_HND *handle, -- cgit From a3a28675fafbbc5a5a378b3a7235253d772ef63e Mon Sep 17 00:00:00 2001 From: David O'Neill Date: Fri, 1 Sep 2000 18:49:26 +0000 Subject: Changes from APPLIANCE_HEAD (per Tim Potter): - make proto - addition of function to convert from errno values to NT status codes (source/lib/error.c) - purge queue done without full access permission will purge only the jobs owned by that user, rather than failing. - unlock job database tdb before sending job to printer - in print_job_start(), ensure that we don't pick a jobid with an existing temporary file that may be owned by another user, as it causes silent failures. - fixes for printer permission checking for NT5 clients (source/include/rpc_spoolss.h, source/printing/nt_printing.c, source/printing/printing.c, source/rpc_server/srv_spoolss_nt.c) - change from uint8 to 'enum SID_NAME_USE' (source/rpc_server/srv_lsa.c) - fixed memory leaks for win95 driver download process (source/smbd/lanman.c) - properly free prs_structs and dacl in testsuite/printing/psec.c (This used to be commit 74af3e2caec7197e5d1ca389e2f78054a4197502) --- source3/rpc_server/srv_spoolss_nt.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 0938b37ab3..1f19be1188 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -22,7 +22,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - #include "includes.h" extern int DEBUGLEVEL; @@ -2936,10 +2935,11 @@ uint32 _spoolss_startdocprinter(POLICY_HND *handle, uint32 level, Printer->jobid = print_job_start(&user, snum, jobname); - /* need to map error codes properly - for now give out of - memory as I don't know the correct codes (tridge) */ + /* An error occured in print_job_start() so return an appropriate + NT error code. */ + if (Printer->jobid == -1) { - return ERROR_NOT_ENOUGH_MEMORY; + return map_nt_error_from_unix(errno); } Printer->document_started=True; @@ -3082,7 +3082,7 @@ static uint32 update_printer_sec(POLICY_HND *handle, uint32 level, descriptor. By experimentation with two NT machines, the user requires Full Access to the printer to change security information. */ - if (!print_access_check(&user, snum, PRINTER_ACE_FULL_CONTROL)) { + if (!print_access_check(&user, snum, PRINTER_ACCESS_ADMINISTER)) { result = ERROR_ACCESS_DENIED; goto done; } @@ -3172,13 +3172,13 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) 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)); + DEBUGADD(6,("Line[0] = [%s]\n", qlines[0])); // Send SIGHUP to process group... is there a better way? kill(0, SIGHUP); @@ -3226,7 +3226,7 @@ static uint32 update_printer(POLICY_HND *handle, uint32 level, goto done; } - if (!print_access_check(NULL, snum, PRINTER_ACE_FULL_CONTROL)) { + if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { DEBUG(3, ("printer property change denied by security " "descriptor\n")); result = ERROR_ACCESS_DENIED; @@ -4028,7 +4028,6 @@ static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need 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); @@ -4127,7 +4126,6 @@ static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need 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); @@ -4247,7 +4245,7 @@ static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name, } /* you must be a printer admin to add a new printer */ - if (!print_access_check(NULL, snum, PRINTER_ACE_FULL_CONTROL)) { + if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { free_a_printer(&printer,2); return ERROR_ACCESS_DENIED; } @@ -4564,7 +4562,7 @@ uint32 _spoolss_setprinterdata( POLICY_HND *handle, if (!get_printer_snum(handle, &snum)) return ERROR_INVALID_HANDLE; - if (!print_access_check(NULL, snum, PRINTER_ACE_FULL_CONTROL)) { + if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { DEBUG(3, ("security descriptor change denied by existing " "security descriptor\n")); return ERROR_ACCESS_DENIED; -- cgit From d644d4438cfef54733118cbd09f89518ffb318ca Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 5 Sep 2000 20:56:09 +0000 Subject: Implemented GETFORM tested and working using Gerald's Win32 test progs.... Jeremy. (This used to be commit 55ed0a9b0c91159c0fc4282c2171d9ced74a302a) --- source3/rpc_server/srv_spoolss_nt.c | 67 +++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 1f19be1188..a31858a3e0 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3888,7 +3888,7 @@ uint32 _spoolss_enumprinterdrivers( UNISTR2 *name, UNISTR2 *environment, uint32 /**************************************************************************** ****************************************************************************/ -static void fill_form_1(FORM_1 *form, nt_forms_struct *list, int position) +static void fill_form_1(FORM_1 *form, nt_forms_struct *list) { form->flag=list->flag; init_unistr(&form->name, list->name); @@ -3930,7 +3930,7 @@ uint32 _new_spoolss_enumforms( POLICY_HND *handle, uint32 level, /* construct the list of form structures */ for (i=0; i<*numofforms; i++) { DEBUGADD(6,("Filling form number [%d]\n",i)); - fill_form_1(&forms_1[i], &list[i], i); + fill_form_1(&forms_1[i], &list[i]); } safe_free(list); @@ -3970,6 +3970,69 @@ uint32 _new_spoolss_enumforms( POLICY_HND *handle, uint32 level, } +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_getform( POLICY_HND *handle, uint32 level, UNISTR2 *uni_formname, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +{ + nt_forms_struct *list=NULL; + FORM_1 form_1; + fstring form_name; + int buffer_size=0; + int numofforms, i; + + unistr2_to_ascii(form_name, uni_formname, sizeof(form_name)-1); + + DEBUG(4,("_spoolss_getform\n")); + DEBUGADD(5,("Offered buffer size [%d]\n", offered)); + DEBUGADD(5,("Info level [%d]\n", level)); + + numofforms = get_ntforms(&list); + DEBUGADD(5,("Number of forms [%d]\n", numofforms)); + + if (numofforms == 0) + return ERROR_NO_MORE_ITEMS; + + switch (level) { + case 1: + + /* Check if the requested name is in the list of form structures */ + for (i=0; i offered) { + return ERROR_INSUFFICIENT_BUFFER; + } + + /* fill the buffer with the form structures */ + DEBUGADD(6,("adding form %s [%d] to buffer\n", form_name, i)); + new_smb_io_form_1("", buffer, &form_1, 0); + + return NT_STATUS_NO_PROBLEMO; + + default: + safe_free(list); + return ERROR_INVALID_LEVEL; + } +} + /**************************************************************************** ****************************************************************************/ static void fill_port_1(PORT_INFO_1 *port, char *name) -- cgit From 061fc961cd0f6f10e794402a56b80e0c0039e3b2 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 6 Sep 2000 01:55:36 +0000 Subject: Fix from John Reilly for double free of printer struct. Jeremy. (This used to be commit c15b7e41e170ced4e4de2e08f6fba860f51e66ac) --- source3/rpc_server/srv_spoolss_nt.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a31858a3e0..d73fc649dd 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3165,7 +3165,6 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) if ( ret != 0 ) { unlink(tmp_file); - free_a_printer(&printer,2); return False; } @@ -4296,9 +4295,11 @@ static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name, convert_printer_info(info, printer, 2); if (*lp_addprinter_cmd() ) - if ( !add_printer_hook(printer) ) + if ( !add_printer_hook(printer) ) { + free_a_printer(&printer,2); return ERROR_ACCESS_DENIED; - + } + slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname, printer->info_2->sharename); -- cgit From 6ef7bf0eac2ca8838322ffc92704fe275b19ec6f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 7 Sep 2000 19:12:59 +0000 Subject: Added code to return NO_MORE_ENTRIES when trying to determine size using "NT mega hack". I think this is the correct thing to do but JF should also examine the. Jeremy. (This used to be commit 29ba3a2cdf7f6fbcf0be41b75d76c04007cd4651) --- source3/rpc_server/srv_spoolss_nt.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index d73fc649dd..8e5c48271b 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4540,6 +4540,18 @@ uint32 _spoolss_enumprinterdata(POLICY_HND *handle, uint32 idx, param_index++; } + /* + * I think this is correct, it doesn't break APW and + * allows Gerald's Win32 test programs to work correctly, + * but may need altering.... JRA. + */ + + if (param_index == 0) { + /* No parameters found. */ + free_a_printer(&printer, 2); + return ERROR_NO_MORE_ITEMS; + } + /* the value is an UNICODE string but realvaluesize is the length in bytes including the leading 0 */ *out_value_len=2*(1+biggest_valuesize); *out_data_len=biggest_datasize; -- cgit From 8808c4e6c8da17dbb6f173d4694aa58e4443e893 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 7 Sep 2000 20:56:24 +0000 Subject: Fixed the printerdata code to return NO_MORE_ITEMS if a size is requested and the parameter index doesn't exist. I think this code can be simplified considerably, but JF needs to check to be sure. Jeremy. (This used to be commit 4d792e6bcb7bef640c2c4e3054ed8839d8fc86f4) --- source3/rpc_server/srv_spoolss_nt.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 8e5c48271b..99ead42ffd 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4525,7 +4525,25 @@ uint32 _spoolss_enumprinterdata(POLICY_HND *handle, uint32 idx, */ if ( (in_value_len==0) && (in_data_len==0) ) { DEBUGADD(6,("Activating NT mega-hack to find sizes\n")); - + + /* + * NT can ask for a specific parameter size - we need to return NO_MORE_ITEMS + * if this parameter size doesn't exist. + * Ok - my opinion here is that the client is not asking for the greatest + * possible size of all the parameters, but is asking specifically for the size needed + * for this specific parameter. In that case we can remove the loop below and + * simplify this lookup code considerably. JF - comments welcome. JRA. + */ + + if (!get_specific_param_by_index(*printer, 2, idx, value, &data, &type, &data_len)) { + safe_free(data); + free_a_printer(&printer, 2); + return ERROR_NO_MORE_ITEMS; + } + + safe_free(data); + data = NULL; + param_index=0; biggest_valuesize=0; biggest_datasize=0; @@ -4537,6 +4555,7 @@ uint32 _spoolss_enumprinterdata(POLICY_HND *handle, uint32 idx, DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize, biggest_datasize)); safe_free(data); + data = NULL; param_index++; } -- cgit From f4ae5a6e389aa64782986ba6eed4bb1e31f1cb71 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 8 Sep 2000 00:28:07 +0000 Subject: Win32 API is explicit that EnumPrinterData returns ERROR_MORE_DATA not ERROR_INSUFICIENT_BUFFER when working out what space is needed. This fix gives us the same return that WinNT does. Jeremy. (This used to be commit a87f6277b1faa1ea492f31add4ce33556bdf3695) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 99ead42ffd..71df03cd08 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -882,7 +882,7 @@ uint32 _spoolss_getprinterdata(POLICY_HND *handle, UNISTR2 *valuename, } if (*needed > *out_size) - return ERROR_INSUFFICIENT_BUFFER; + return ERROR_MORE_DATA; else return NT_STATUS_NO_PROBLEMO; } -- cgit From 912ecf7fb9d2276c7aa23dbe81f59af41fa422f1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 8 Sep 2000 02:20:48 +0000 Subject: Fixed typo where docname was being checked for datatype - was causing STARTDOCPRINTER call to fail. I *love* Gerald's test code :-). Jeremy. (This used to be commit 43192370f31c7cc71d1f72449a067573adad3ebc) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 71df03cd08..52a677fbe0 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2919,7 +2919,7 @@ uint32 _spoolss_startdocprinter(POLICY_HND *handle, uint32 level, */ if (info_1->p_datatype != 0) { - unistr2_to_ascii(datatype, &info_1->docname, sizeof(datatype)); + unistr2_to_ascii(datatype, &info_1->datatype, sizeof(datatype)); if (strcmp(datatype, "RAW") != 0) { (*jobid)=0; return ERROR_INVALID_DATATYPE; -- cgit From e0f9de0c49dde82610b0da406b4685e787f69725 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 9 Sep 2000 00:19:35 +0000 Subject: Implemented DELETEPRINTERDATA (tested with Gerald's Win32 progs). Jeremy. (This used to be commit fb48efaf830626f6ef05b88f5f8a74b932ceb257) --- source3/rpc_server/srv_spoolss_nt.c | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 52a677fbe0..2c0dc79fb2 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4679,6 +4679,48 @@ uint32 _spoolss_setprinterdata( POLICY_HND *handle, return status; } +/**************************************************************************** +****************************************************************************/ +uint32 _spoolss_deleteprinterdata( POLICY_HND *handle, const UNISTR2 *value) +{ + NT_PRINTER_INFO_LEVEL *printer = NULL; + NT_PRINTER_PARAM param; + int snum=0; + uint32 status = 0x0; + Printer_entry *Printer=find_printer_index_by_hnd(handle); + + DEBUG(5,("spoolss_deleteprinterdata\n")); + + if (!OPEN_HANDLE(Printer)) { + DEBUG(0,("_spoolss_deleteprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); + return ERROR_INVALID_HANDLE; + } + + if (!get_printer_snum(handle, &snum)) + return ERROR_INVALID_HANDLE; + + if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { + DEBUG(3, ("_spoolss_deleteprinterdata: security descriptor change denied by existing " + "security descriptor\n")); + return ERROR_ACCESS_DENIED; + } + + status = get_a_printer(&printer, 2, lp_servicename(snum)); + if (status != 0x0) + return ERROR_INVALID_NAME; + + ZERO_STRUCTP(¶m); + unistr2_to_ascii(param.value, value, sizeof(param.value)-1); + + if(!unlink_specific_param_if_exist(printer->info_2, ¶m)) + status = ERROR_INVALID_PARAMETER; + else + status = add_a_printer(*printer, 2); + + free_a_printer(&printer, 2); + return status; +} + /**************************************************************************** ****************************************************************************/ uint32 _spoolss_addform( POLICY_HND *handle, -- cgit From 692fe0cabfaf4b0e13083aa5d6fc9dddb4e5dd5b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 11 Sep 2000 23:21:16 +0000 Subject: Fix for malloc of zero bytes found by insure. Jeremy. (This used to be commit 2916790859acc56e582056774b02d4a33cedeaa4) --- source3/rpc_server/srv_spoolss_nt.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 2c0dc79fb2..da5b3e960f 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3564,6 +3564,11 @@ uint32 _spoolss_enumjobs( POLICY_HND *handle, uint32 firstjob, uint32 numofjobs, *returned = print_queue_status(snum, &queue, &prt_status); DEBUGADD(4,("count:[%d], status:[%d], [%s]\n", *returned, prt_status.status, prt_status.message)); + if (*returned == 0) { + safe_free(queue); + return NT_STATUS_NO_PROBLEMO; + } + switch (level) { case 1: return enumjobs_level1(queue, snum, buffer, offered, needed, returned); -- cgit From d836024b2816f37abd523afb3b2d4f2bfb130f0a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 11 Sep 2000 23:43:44 +0000 Subject: Fixed memory leaks found in enumprinterdrivers code. Jeremy. (This used to be commit e08b521559a824da09b0b73a04e462c573c42b06) --- source3/rpc_server/srv_spoolss_nt.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index da5b3e960f..7f7a75fc5c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3677,7 +3677,8 @@ static uint32 enumprinterdrivers_level1(fstring servername, fstring architecture DEBUGADD(5,("\tdriver: [%s]\n", list[i])); ZERO_STRUCT(driver); get_a_printer_driver(&driver, 3, list[i], architecture, version); - fill_printer_driver_info_1(&(driver_info_1[*returned+i]), driver, servername, architecture ); + fill_printer_driver_info_1(&driver_info_1[*returned+i], driver, servername, architecture ); + free_a_printer_driver(driver, 3); } *returned+=ndrivers; @@ -3687,7 +3688,7 @@ static uint32 enumprinterdrivers_level1(fstring servername, fstring architecture /* check the required size. */ for (i=0; i<*returned; i++) { DEBUGADD(6,("adding driver [%d]'s size\n",i)); - *needed += spoolss_size_printer_driver_info_1(&(driver_info_1[i])); + *needed += spoolss_size_printer_driver_info_1(&driver_info_1[i]); } if (!alloc_buffer_size(buffer, *needed)) { @@ -3698,7 +3699,7 @@ static uint32 enumprinterdrivers_level1(fstring servername, fstring architecture /* fill the buffer with the form structures */ for (i=0; i<*returned; i++) { DEBUGADD(6,("adding driver [%d] to buffer\n",i)); - new_smb_io_printer_driver_info_1("", buffer, &(driver_info_1[i]), 0); + new_smb_io_printer_driver_info_1("", buffer, &driver_info_1[i], 0); } safe_free(driver_info_1); @@ -3747,7 +3748,8 @@ static uint32 enumprinterdrivers_level2(fstring servername, fstring architecture DEBUGADD(5,("\tdriver: [%s]\n", list[i])); ZERO_STRUCT(driver); get_a_printer_driver(&driver, 3, list[i], architecture, version); - fill_printer_driver_info_2(&(driver_info_2[*returned+i]), driver, servername); + fill_printer_driver_info_2(&driver_info_2[*returned+i], driver, servername); + free_a_printer_driver(driver, 3); } *returned+=ndrivers; @@ -3817,7 +3819,8 @@ static uint32 enumprinterdrivers_level3(fstring servername, fstring architecture DEBUGADD(5,("\tdriver: [%s]\n", list[i])); ZERO_STRUCT(driver); get_a_printer_driver(&driver, 3, list[i], architecture, version); - fill_printer_driver_info_3(&(driver_info_3[*returned+i]), driver, servername); + fill_printer_driver_info_3(&driver_info_3[*returned+i], driver, servername); + free_a_printer_driver(driver, 3); } *returned+=ndrivers; -- cgit From 043860d8b71925b0973d81daf7cf7e39354bdc28 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 12 Sep 2000 21:45:42 +0000 Subject: Fixed error return when printer is PAUSED - should be returning "Pause". Jeremy. (This used to be commit 41d03a118c9981fc2159f37cd5ed4684e1d36037) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 7f7a75fc5c..0464d252f0 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -100,7 +100,7 @@ static int nt_printq_status(int v) { switch (v) { case LPQ_PAUSED: - return PRINTER_STATUS_ERROR; + return PRINTER_STATUS_PAUSED; case LPQ_QUEUED: case LPQ_SPOOLING: case LPQ_PRINTING: -- cgit From 3e675875a45dea286cc28beef043f6e18d6addde Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 12 Sep 2000 22:33:41 +0000 Subject: Fix for enumjobs infor level 2 which caused smbd to coredump. Uninitialized element in struct. Jeremy. (This used to be commit 9e1fbb0c2f1d2ad0c907f1e902e44ea7af214b57) --- source3/rpc_server/srv_spoolss_nt.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 0464d252f0..5f69c097c7 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3424,6 +3424,7 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, init_unistr(&job_info->datatype, "RAW"); init_unistr(&job_info->printprocessor, "winprint"); init_unistr(&job_info->parameters, ""); + init_unistr(&job_info->drivername, ntprinter->info_2->drivername); init_unistr(&job_info->text_status, ""); /* and here the security descriptor */ -- cgit From ed6530800ccf4e8303bc7e106ca7443950fa27c9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 13 Sep 2000 18:50:38 +0000 Subject: Added SIGHUP when printer deleted as well as added. Jeremy. (This used to be commit 79c94f37d0434150d84858e67c8677650106d76c) --- source3/rpc_server/srv_spoolss_nt.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 5f69c097c7..4727ee8092 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -247,6 +247,9 @@ static BOOL delete_printer_handle(POLICY_HND *hnd) DEBUGADD(10,("Unlinking output file [%s]\n", tmp_file)); unlink(tmp_file); + // Send SIGHUP to process group... is there a better way? + kill(0, SIGHUP); + if ( ( i = lp_servicenumber( Printer->dev.handlename ) ) >= 0 ) { lp_remove_service( i ); lp_killservice( i ); -- cgit From ccddd111c6b0c2d41c7b1e3875dca4e760205b79 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 15 Sep 2000 00:15:10 +0000 Subject: Move towards getting W2k p&p to upload NT4.x drivers. Still doesn't work - not sure why (JF - a glance at this would be appreciated). Removed code that JF objected to with enumprinterdata. Added translations to/from level 6 - but Win2k still not happy... hmmm... Jeremy. (This used to be commit e5d98ba9e97eb16337ff6c49f799e130844ae72e) --- source3/rpc_server/srv_spoolss_nt.c | 179 +++++++++++++++++++++++++++++++++--- 1 file changed, 166 insertions(+), 13 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 4727ee8092..c22767c43a 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -535,11 +535,7 @@ static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size) prs_set_offset(ps, old_offset); -#if 0 /* JRATEST */ - buffer->string_at_end = buffer_size; -#else buffer->string_at_end=prs_data_size(ps); -#endif return True; } @@ -1838,10 +1834,7 @@ static DEVICEMODE *construct_dev_mode(int snum, char *servername) if (printer->info_2->devmode) ntdevmode = dup_nt_devicemode(printer->info_2->devmode); -#if 0 /* JFMTEST */ - else - ntdevmode = construct_nt_devicemode(printer->info_2->printername); -#endif + if (ntdevmode == NULL) goto fail; @@ -1998,10 +1991,29 @@ static BOOL construct_printer_info_3(fstring servername, ZERO_STRUCTP(printer); - printer->flags = 4; /* This is the offset to the SEC_DESC. */ + printer->flags = 4; /* These are the components of the SD we are returning. */ if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->len != 0) { /* steal the printer info sec_desc structure. [badly done]. */ printer->secdesc = ntprinter->info_2->secdesc_buf->sec; + +#if 0 + /* + * Set the flags for the components we are returning. + */ + + if (printer->secdesc->owner_sid) + printer->flags |= OWNER_SECURITY_INFORMATION; + + if (printer->secdesc->grp_sid) + printer->flags |= GROUP_SECURITY_INFORMATION; + + if (printer->secdesc->dacl) + printer->flags |= DACL_SECURITY_INFORMATION; + + if (printer->secdesc->sacl) + printer->flags |= SACL_SECURITY_INFORMATION; +#endif + ntprinter->info_2->secdesc_buf->sec = NULL; /* Stolen the malloced memory. */ ntprinter->info_2->secdesc_buf->len = 0; /* Stolen the malloced memory. */ ntprinter->info_2->secdesc_buf->max_len = 0; /* Stolen the malloced memory. */ @@ -2643,6 +2655,8 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_IN pstring temp_configfile; pstring temp_helpfile; + ZERO_STRUCTP(info); + info->version=driver.info_3->cversion; init_unistr( &info->name, driver.info_3->name ); @@ -2675,7 +2689,7 @@ static uint32 construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fst { NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; -uint32 status=0; + uint32 status=0; ZERO_STRUCT(driver); status=get_a_printer(&printer, 2, lp_servicename(snum) ); @@ -2697,6 +2711,84 @@ uint32 status=0; return NT_STATUS_NO_PROBLEMO; } +/******************************************************************** + * construct_printer_info_6 + * fill a printer_info_6 struct - we know that driver is really level 3. This sucks. JRA. + ********************************************************************/ + +static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername) +{ + pstring temp_driverpath; + pstring temp_datafile; + pstring temp_configfile; + pstring temp_helpfile; + fstring nullstr; + + ZERO_STRUCTP(info); + memset(&nullstr, '\0', sizeof(fstring)); + + info->version=driver.info_3->cversion; + + init_unistr( &info->name, driver.info_3->name ); + init_unistr( &info->architecture, driver.info_3->environment ); + + snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "\\\\%s%s", servername, driver.info_3->driverpath); + init_unistr( &info->driverpath, temp_driverpath ); + + snprintf(temp_datafile, sizeof(temp_datafile)-1, "\\\\%s%s", servername, driver.info_3->datafile); + init_unistr( &info->datafile, temp_datafile ); + + snprintf(temp_configfile, sizeof(temp_configfile)-1, "\\\\%s%s", servername, driver.info_3->configfile); + init_unistr( &info->configfile, temp_configfile ); + + snprintf(temp_helpfile, sizeof(temp_helpfile)-1, "\\\\%s%s", servername, driver.info_3->helpfile); + init_unistr( &info->helpfile, temp_helpfile ); + + init_unistr( &info->monitorname, driver.info_3->monitorname ); + init_unistr( &info->defaultdatatype, driver.info_3->defaultdatatype ); + + info->dependentfiles=NULL; + init_unistr_array(&info->dependentfiles, driver.info_3->dependentfiles, servername); + + info->previousdrivernames=NULL; + init_unistr_array(&info->previousdrivernames, &nullstr, servername); + + init_unistr( &info->mfgname, ""); + init_unistr( &info->oem_url, ""); + init_unistr( &info->hardware_id, ""); + init_unistr( &info->provider, ""); +} + +/******************************************************************** + * construct_printer_info_6 + * fill a printer_info_6 struct + ********************************************************************/ +static uint32 construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, fstring servername, fstring architecture, uint32 version) +{ + NT_PRINTER_INFO_LEVEL *printer = NULL; + NT_PRINTER_DRIVER_INFO_LEVEL driver; + uint32 status=0; + ZERO_STRUCT(driver); + + status=get_a_printer(&printer, 2, lp_servicename(snum) ); + DEBUG(8,("construct_printer_driver_info_6: status: %d\n", status)); + if (status != 0) + return ERROR_INVALID_PRINTER_NAME; + + status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version); + DEBUG(8,("construct_printer_driver_info_6: status: %d\n", status)); + if (status != 0) { + free_a_printer(&printer,2); + return ERROR_UNKNOWN_PRINTER_DRIVER; + } + + fill_printer_driver_info_6(info, driver, servername); + + free_a_printer(&printer,2); + + return NT_STATUS_NO_PROBLEMO; +} + /**************************************************************************** ****************************************************************************/ @@ -2705,6 +2797,15 @@ static void free_printer_driver_info_3(DRIVER_INFO_3 *info) safe_free(info->dependentfiles); } +/**************************************************************************** +****************************************************************************/ + +static void free_printer_driver_info_6(DRIVER_INFO_6 *info) +{ + safe_free(info->dependentfiles); + +} + /**************************************************************************** ****************************************************************************/ static uint32 getprinterdriver2_level1(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) @@ -2810,6 +2911,39 @@ static uint32 getprinterdriver2_level3(fstring servername, fstring architecture, return NT_STATUS_NO_PROBLEMO; } +/**************************************************************************** +****************************************************************************/ +static uint32 getprinterdriver2_level6(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +{ + DRIVER_INFO_6 info; + uint32 status; + + ZERO_STRUCT(info); + + status=construct_printer_driver_info_6(&info, snum, servername, architecture, version); + if (status != NT_STATUS_NO_PROBLEMO) { + return status; + } + + /* check the required size. */ + *needed += spoolss_size_printer_driver_info_6(&info); + + if (!alloc_buffer_size(buffer, *needed)) { + free_printer_driver_info_3(&info); + return ERROR_INSUFFICIENT_BUFFER; + } + + /* fill the buffer with the structures */ + new_smb_io_printer_driver_info_6("", buffer, &info, 0); + + free_printer_driver_info_6(&info); + + if (*needed > offered) + return ERROR_INSUFFICIENT_BUFFER; + else + return NT_STATUS_NO_PROBLEMO; +} + /**************************************************************************** ****************************************************************************/ uint32 _spoolss_getprinterdriver2(POLICY_HND *handle, const UNISTR2 *uni_arch, uint32 level, @@ -2843,6 +2977,9 @@ uint32 _spoolss_getprinterdriver2(POLICY_HND *handle, const UNISTR2 *uni_arch, u case 3: return getprinterdriver2_level3(servername, architecture, clientmajorversion, snum, buffer, offered, needed); break; + case 6: + return getprinterdriver2_level6(servername, architecture, clientmajorversion, snum, buffer, offered, needed); + break; default: return ERROR_INVALID_LEVEL; break; @@ -3678,9 +3815,13 @@ static uint32 enumprinterdrivers_level1(fstring servername, fstring architecture } for (i=0; i Date: Sat, 16 Sep 2000 10:07:46 +0000 Subject: in a printer_info_6, driver version is 64 bits long and there is a 32 bit padding before. J.F. (This used to be commit cd41d7a35477accec1a82b86f9fa3477e5a49d6e) --- source3/rpc_server/srv_spoolss_nt.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index c22767c43a..0430563629 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2753,6 +2753,13 @@ static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_IN info->previousdrivernames=NULL; init_unistr_array(&info->previousdrivernames, &nullstr, servername); + info->driver_date.low=0; + info->driver_date.high=0; + + info->padding=0; + info->driver_version_low=0; + info->driver_version_high=0; + init_unistr( &info->mfgname, ""); init_unistr( &info->oem_url, ""); init_unistr( &info->hardware_id, ""); -- cgit From b774aa4b8978b7824e6a0361672179afb1fc7b2d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 21 Sep 2000 21:44:15 +0000 Subject: Adding fix from Jim Vopni to ensure jobs are closed before a printer is closed/deleted. Jeremy. (This used to be commit f0c16f7228d6923b11ac521aef986960a1d0c0b4) --- source3/rpc_server/srv_spoolss_nt.c | 66 ++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 33 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 0430563629..ca1b20522b 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -672,6 +672,11 @@ static BOOL convert_devicemode(const DEVICEMODE *devmode, NT_DEVICEMODE *nt_devm ********************************************************************/ uint32 _spoolss_closeprinter(POLICY_HND *handle) { + Printer_entry *Printer=find_printer_index_by_hnd(handle); + + if (Printer && Printer->document_started) + _spoolss_enddocprinter(handle); /* print job was not closed */ + if (!close_printer_handle(handle)) return ERROR_INVALID_HANDLE; @@ -683,6 +688,11 @@ uint32 _spoolss_closeprinter(POLICY_HND *handle) ********************************************************************/ uint32 _spoolss_deleteprinter(POLICY_HND *handle) { + Printer_entry *Printer=find_printer_index_by_hnd(handle); + + if (Printer && Printer->document_started) + _spoolss_enddocprinter(handle); /* print job was not closed */ + if (!delete_printer_handle(handle)) return ERROR_INVALID_HANDLE; @@ -3024,6 +3034,21 @@ uint32 _spoolss_endpageprinter(POLICY_HND *handle) return NT_STATUS_NO_PROBLEMO; } +/**************************************************************************** + Return a user struct for a pipe user. +****************************************************************************/ + +static struct current_user *get_current_user(struct current_user *user, pipes_struct *p) +{ + if (p->ntlmssp_auth_validated) { + memcpy(user, &p->pipe_user, sizeof(user)); + } else { + extern struct current_user current_user; + memcpy(user, ¤t_user, sizeof(user)); + } + + return user; +} /******************************************************************** * api_spoolss_getprinter @@ -3046,12 +3071,7 @@ uint32 _spoolss_startdocprinter(POLICY_HND *handle, uint32 level, return ERROR_INVALID_HANDLE; } - if (p->ntlmssp_auth_validated) { - memcpy(&user, &p->pipe_user, sizeof(user)); - } else { - extern struct current_user current_user; - memcpy(&user, ¤t_user, sizeof(user)); - } + get_current_user(&user, p); /* * a nice thing with NT is it doesn't listen to what you tell it. @@ -3149,12 +3169,7 @@ static uint32 control_printer(POLICY_HND *handle, uint32 command, int errcode = 0; Printer_entry *Printer = find_printer_index_by_hnd(handle); - if (p->ntlmssp_auth_validated) { - memcpy(&user, &p->pipe_user, sizeof(user)); - } else { - extern struct current_user current_user; - memcpy(&user, ¤t_user, sizeof(user)); - } + get_current_user(&user, p); if (!OPEN_HANDLE(Printer)) { DEBUG(0,("control_printer: Invalid handle (%s)\n", OUR_HANDLE(handle))); @@ -3218,12 +3233,7 @@ static uint32 update_printer_sec(POLICY_HND *handle, uint32 level, } /* Work out which user is performing the operation */ - if (p->ntlmssp_auth_validated) { - memcpy(&user, &p->pipe_user, sizeof(user)); - } else { - extern struct current_user current_user; - memcpy(&user, ¤t_user, sizeof(user)); - } + get_current_user(&user, p); /* Check the user has permissions to change the security descriptor. By experimentation with two NT machines, the user @@ -3745,7 +3755,7 @@ uint32 _spoolss_schedulejob( POLICY_HND *handle, uint32 jobid) uint32 _spoolss_setjob( POLICY_HND *handle, uint32 jobid, uint32 level, - pipes_struct *p, + pipes_struct *p, JOB_INFO *ctr, uint32 command) @@ -3763,13 +3773,8 @@ uint32 _spoolss_setjob( POLICY_HND *handle, if (!print_job_exists(jobid)) { return ERROR_INVALID_PRINTER_NAME; } - - if (p->ntlmssp_auth_validated) { - memcpy(&user, &p->pipe_user, sizeof(user)); - } else { - extern struct current_user current_user; - memcpy(&user, ¤t_user, sizeof(user)); - } + + get_current_user(&user, p); switch (command) { case JOB_CONTROL_CANCEL: @@ -4545,13 +4550,8 @@ uint32 _spoolss_addprinterdriver(pipes_struct *p, const UNISTR2 *server_name, struct current_user user; ZERO_STRUCT(driver); - - if (p->ntlmssp_auth_validated) { - memcpy(&user, &p->pipe_user, sizeof(user)); - } else { - extern struct current_user current_user; - memcpy(&user, ¤t_user, sizeof(user)); - } + + get_current_user(&user, p); convert_printer_driver_info(info, &driver, level); -- cgit From 233bc000209cf5759e0e49ad83da70b280d51dae Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Mon, 25 Sep 2000 21:05:18 +0000 Subject: printer notify code. It only sends notifies to one client. The broadcasting notify code will code soon. J.F. (This used to be commit 4c63c9185887c64e57d901e82a4a16a83522c898) --- source3/rpc_server/srv_spoolss_nt.c | 150 ++++++++++++++++++++++++++++++++++-- 1 file changed, 144 insertions(+), 6 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index ca1b20522b..2a25f615d8 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -60,6 +60,8 @@ typedef struct _Printer{ fstring localmachine; uint32 printerlocal; SPOOL_NOTIFY_OPTION *option; + POLICY_HND client_hnd; + uint32 client_connected; } notify; struct { fstring machine; @@ -78,6 +80,8 @@ typedef struct _counter_printer_0 { static ubi_dlList Printer_list; static ubi_dlList counter_list; +static struct cli_state cli; +static uint32 smb_connections=0; #define OPEN_HANDLE(pnum) ((pnum!=NULL) && (pnum->open!=False) && (IVAL(pnum->printer_hnd.data,16)==(uint32)sys_getpid())) #define OUR_HANDLE(pnum) ((pnum==NULL)?"NULL":(IVAL(pnum->data,16)==sys_getpid()?"OURS":"OTHER")) @@ -170,6 +174,30 @@ static void clear_handle(POLICY_HND *hnd) ZERO_STRUCTP(hnd); } +/*************************************************************************** + Disconnect from the client +****************************************************************************/ +static BOOL srv_spoolss_replycloseprinter(POLICY_HND *handle) +{ + uint32 status; + + /* weird if the test succeds !!! */ + if (smb_connections==0) { + DEBUG(0,("srv_spoolss_replycloseprinter:Trying to close non-existant notify backchannel !\n")); + return False; + } + + if(!cli_spoolss_reply_close_printer(&cli, handle, &status)) + return False; + + /* if it's the last connection, deconnect the IPC$ share */ + if (smb_connections==1) + if(!spoolss_disconnect_from_client(&cli)) + return False; + + smb_connections--; +} + /**************************************************************************** close printer index by handle ****************************************************************************/ @@ -182,6 +210,10 @@ static BOOL close_printer_handle(POLICY_HND *hnd) return False; } + if (Printer->notify.client_connected==True) + if(!srv_spoolss_replycloseprinter(&Printer->notify.client_hnd)) + return ERROR_INVALID_HANDLE; + Printer->open=False; Printer->notify.flags=0; Printer->notify.options=0; @@ -189,7 +221,8 @@ static BOOL close_printer_handle(POLICY_HND *hnd) Printer->notify.printerlocal=0; safe_free(Printer->notify.option); Printer->notify.option=NULL; - + Printer->notify.client_connected=False; + clear_handle(hnd); ubi_dlRemThis(&Printer_list, Printer); @@ -540,6 +573,57 @@ static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size) return True; } +/*************************************************************************** + receive the notify message +****************************************************************************/ +static BOOL srv_spoolss_receive_message(char *printer) +{ + uint32 status; + Printer_entry *find_printer; + + find_printer = (Printer_entry *)ubi_dlFirst(&Printer_list); + + /* Iterate the printer list. */ + for(; find_printer; find_printer = (Printer_entry *)ubi_dlNext(find_printer)) { + + /* + * if the entry is the given printer or if it's a printerserver + * we send the message + */ + + if (find_printer->printer_type==PRINTER_HANDLE_IS_PRINTER) + if (strcmp(find_printer->dev.handlename, printer)) + continue; + + if (find_printer->notify.client_connected==True) + if( !cli_spoolss_reply_rrpcn(&cli, &find_printer->notify.client_hnd, PRINTER_CHANGE_ALL, 0x0, &status)) + return False; + + } +} + +/*************************************************************************** + send a notify event +****************************************************************************/ +static BOOL srv_spoolss_sendnotify(POLICY_HND *handle) +{ + fstring printer; + + Printer_entry *Printer=find_printer_index_by_hnd(handle); + + if (!OPEN_HANDLE(Printer)) { + DEBUG(0,("srv_spoolss_sendnotify: Invalid handle (%s).\n", OUR_HANDLE(handle))); + return False; + } + + if (Printer->printer_type==PRINTER_HANDLE_IS_PRINTER) + fstrcpy(printer, Printer->dev.handlename); + else + fstrcpy(printer, ""); + + srv_spoolss_receive_message(printer); +} + /******************************************************************** * spoolss_open_printer * @@ -695,6 +779,8 @@ uint32 _spoolss_deleteprinter(POLICY_HND *handle) if (!delete_printer_handle(handle)) return ERROR_INVALID_HANDLE; + + srv_spoolss_sendnotify(handle); return NT_STATUS_NO_PROBLEMO; } @@ -896,6 +982,27 @@ uint32 _spoolss_getprinterdata(POLICY_HND *handle, UNISTR2 *valuename, return NT_STATUS_NO_PROBLEMO; } +/*************************************************************************** + connect to the client +****************************************************************************/ +static BOOL srv_spoolss_replyopenprinter(char *printer, uint32 localprinter, uint32 type, POLICY_HND *handle) +{ + uint32 status; + + /* + * If it's the first connection, contact the client + * and connect to the IPC$ share anonumously + */ + if (smb_connections==0) + if(!spoolss_connect_to_client(&cli, printer+2)) /* the +2 is to strip the leading 2 backslashs */ + return False; + + smb_connections++; + + if(!cli_spoolss_reply_open_printer(&cli, printer, localprinter, type, &status, handle)) + return False; +} + /******************************************************************** * _spoolss_rffpcnex * ReplyFindFirstPrinterChangeNotifyEx @@ -926,6 +1033,12 @@ uint32 _spoolss_rffpcnex(POLICY_HND *handle, uint32 flags, uint32 options, Printer->notify.option=option; unistr2_to_ascii(Printer->notify.localmachine, localmachine, sizeof(Printer->notify.localmachine)-1); + /* connect to the client machine and send a ReplyOpenPrinter */ + if(srv_spoolss_replyopenprinter(Printer->notify.localmachine, + Printer->notify.printerlocal, 1, + &Printer->notify.client_hnd)) + Printer->notify.client_connected=True; + return NT_STATUS_NO_PROBLEMO; } @@ -3112,6 +3225,7 @@ uint32 _spoolss_startdocprinter(POLICY_HND *handle, uint32 level, Printer->document_started=True; (*jobid) = Printer->jobid; + srv_spoolss_sendnotify(handle); return 0x0; } @@ -3133,6 +3247,8 @@ uint32 _spoolss_enddocprinter(POLICY_HND *handle) print_job_end(Printer->jobid); /* error codes unhandled so far ... */ + srv_spoolss_sendnotify(handle); + return 0x0; } @@ -3182,17 +3298,20 @@ static uint32 control_printer(POLICY_HND *handle, uint32 command, switch (command) { case PRINTER_CONTROL_PAUSE: if (print_queue_pause(&user, snum, &errcode)) { + srv_spoolss_sendnotify(handle); return 0; } break; case PRINTER_CONTROL_RESUME: case PRINTER_CONTROL_UNPAUSE: if (print_queue_resume(&user, snum, &errcode)) { + srv_spoolss_sendnotify(handle); return 0; } break; case PRINTER_CONTROL_PURGE: if (print_queue_purge(&user, snum, &errcode)) { + srv_spoolss_sendnotify(handle); return 0; } break; @@ -3449,6 +3568,8 @@ static uint32 update_printer(POLICY_HND *handle, uint32 level, done: free_a_printer(&printer, 2); + srv_spoolss_sendnotify(handle); + return result; } @@ -3495,7 +3616,11 @@ uint32 _spoolss_fcpn(POLICY_HND *handle) DEBUG(0,("_spoolss_fcpn: Invalid handle (%s)\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; } - + + if (Printer->notify.client_connected==True) + if(!srv_spoolss_replycloseprinter(&Printer->notify.client_hnd)) + return ERROR_INVALID_HANDLE; + Printer->notify.flags=0; Printer->notify.options=0; Printer->notify.localmachine[0]='\0'; @@ -3504,7 +3629,8 @@ uint32 _spoolss_fcpn(POLICY_HND *handle) safe_free(Printer->notify.option->ctr.type); safe_free(Printer->notify.option); Printer->notify.option=NULL; - + Printer->notify.client_connected=False; + return NT_STATUS_NO_PROBLEMO; } @@ -3779,13 +3905,22 @@ uint32 _spoolss_setjob( POLICY_HND *handle, switch (command) { case JOB_CONTROL_CANCEL: case JOB_CONTROL_DELETE: - if (print_job_delete(&user, jobid)) return 0x0; + if (print_job_delete(&user, jobid)) { + srv_spoolss_sendnotify(handle); + return 0x0; + } break; case JOB_CONTROL_PAUSE: - if (print_job_pause(&user, jobid)) return 0x0; + if (print_job_pause(&user, jobid)) { + srv_spoolss_sendnotify(handle); + return 0x0; + } break; case JOB_CONTROL_RESUME: - if (print_job_resume(&user, jobid)) return 0x0; + if (print_job_resume(&user, jobid)) { + srv_spoolss_sendnotify(handle); + return 0x0; + } break; default: return ERROR_INVALID_LEVEL; @@ -4512,6 +4647,9 @@ static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name, } free_a_printer(&printer,2); + + srv_spoolss_sendnotify(handle); + return NT_STATUS_NO_PROBLEMO; } -- cgit From 5be845af6bea3d4795dc50fe9ee880527be5ecc0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 26 Sep 2000 00:54:18 +0000 Subject: Changes from John Reilly to add a parameter "show add printer wizard" that allows Samba to turn off the display of APW (hmmm. This should probably be a share specific parameter, I'll fix that in another commit). Also a few small changes to JF's code to fix compiler warnings about missing return statements and also change '//' comments (C++) to /* .. */ comments (C). Jeremy. (This used to be commit 0a9ccc99b335650d235eb747d803d059f7828fd7) --- source3/rpc_server/srv_spoolss_nt.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 2a25f615d8..821cdf30e5 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -196,6 +196,8 @@ static BOOL srv_spoolss_replycloseprinter(POLICY_HND *handle) return False; smb_connections--; + + return True; } /**************************************************************************** @@ -280,7 +282,7 @@ static BOOL delete_printer_handle(POLICY_HND *hnd) DEBUGADD(10,("Unlinking output file [%s]\n", tmp_file)); unlink(tmp_file); - // Send SIGHUP to process group... is there a better way? + /* Send SIGHUP to process group... is there a better way? */ kill(0, SIGHUP); if ( ( i = lp_servicenumber( Printer->dev.handlename ) ) >= 0 ) { @@ -495,6 +497,7 @@ static BOOL open_printer_hnd(POLICY_HND *hnd, char *name) { Printer_entry *new_printer; + DEBUG(10,("open_printer_hnd: name [%s]\n", name)); clear_handle(hnd); create_printer_hnd(hnd); @@ -600,6 +603,8 @@ static BOOL srv_spoolss_receive_message(char *printer) return False; } + + return True; } /*************************************************************************** @@ -622,6 +627,8 @@ static BOOL srv_spoolss_sendnotify(POLICY_HND *handle) fstrcpy(printer, ""); srv_spoolss_receive_message(printer); + + return True; } /******************************************************************** @@ -663,6 +670,17 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, return ERROR_ACCESS_DENIED; } + /* Disallow MS AddPrinterWizard if access rights are insufficient OR + if parameter disables it. The client tries an OpenPrinterEx with + SERVER_ALL_ACCESS(0xf0003), which we force to fail. It then tries + OpenPrinterEx with SERVER_READ(0x20002) which we allow. This lets + it see any printers there, but does not show the MSAPW */ + if (handle_is_printserver(handle) && + printer_default->access_required != (SERVER_READ) && + !lp_ms_add_printer_wizard() ) { + return ERROR_ACCESS_DENIED; + } + return NT_STATUS_NO_PROBLEMO; } @@ -1001,6 +1019,8 @@ static BOOL srv_spoolss_replyopenprinter(char *printer, uint32 localprinter, uin if(!cli_spoolss_reply_open_printer(&cli, printer, localprinter, type, &status, handle)) return False; + + return True; } /******************************************************************** @@ -3451,11 +3471,11 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) unlink(tmp_file); if(numlines) { - // Set the portname to what the script says the portname should be + /* Set the portname to what the script says the portname should be. */ strncpy(printer->info_2->portname, qlines[0], sizeof(printer->info_2->portname)); DEBUGADD(6,("Line[0] = [%s]\n", qlines[0])); - // Send SIGHUP to process group... is there a better way? + /* Send SIGHUP to process group... is there a better way? */ kill(0, SIGHUP); add_all_printers(); } @@ -4393,7 +4413,7 @@ static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need DEBUG(10,("Returned [%d]\n", ret)); if (ret != 0) { unlink(tmp_file); - // Is this the best error to return here? + /* Is this the best error to return here? */ return ERROR_ACCESS_DENIED; } @@ -4491,7 +4511,7 @@ static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need DEBUGADD(10,("returned [%d]\n", ret)); if (ret != 0) { unlink(tmp_file); - // Is this the best error to return here? + /* Is this the best error to return here? */ return ERROR_ACCESS_DENIED; } -- cgit From 56917236a0414a03fb4ec193243c5de123bd3aa5 Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Tue, 26 Sep 2000 10:15:12 +0000 Subject: broadcast printer notify message to all clients. We now have printer notification as on NT. Andrew, your message passing code is cool :-) J.F. (This used to be commit 0374bc4b5f56d0fab3f7310e13cb71b5a71f9112) --- source3/rpc_server/srv_spoolss_nt.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 821cdf30e5..86fa0d108d 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -191,10 +191,13 @@ static BOOL srv_spoolss_replycloseprinter(POLICY_HND *handle) return False; /* if it's the last connection, deconnect the IPC$ share */ - if (smb_connections==1) + if (smb_connections==1) { if(!spoolss_disconnect_from_client(&cli)) return False; + message_deregister(MSG_PRINTER_NOTIFY); + } + smb_connections--; return True; @@ -579,11 +582,14 @@ static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size) /*************************************************************************** receive the notify message ****************************************************************************/ -static BOOL srv_spoolss_receive_message(char *printer) +void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size_t len) { + char printer[256]; uint32 status; Printer_entry *find_printer; + memcpy(printer, buf, len); + find_printer = (Printer_entry *)ubi_dlFirst(&Printer_list); /* Iterate the printer list. */ @@ -599,12 +605,9 @@ static BOOL srv_spoolss_receive_message(char *printer) continue; if (find_printer->notify.client_connected==True) - if( !cli_spoolss_reply_rrpcn(&cli, &find_printer->notify.client_hnd, PRINTER_CHANGE_ALL, 0x0, &status)) - return False; + cli_spoolss_reply_rrpcn(&cli, &find_printer->notify.client_hnd, PRINTER_CHANGE_ALL, 0x0, &status); } - - return True; } /*************************************************************************** @@ -626,7 +629,8 @@ static BOOL srv_spoolss_sendnotify(POLICY_HND *handle) else fstrcpy(printer, ""); - srv_spoolss_receive_message(printer); + /*srv_spoolss_receive_message(printer);*/ + message_send_all(MSG_PRINTER_NOTIFY, printer, strlen(printer)); return True; } @@ -1011,9 +1015,12 @@ static BOOL srv_spoolss_replyopenprinter(char *printer, uint32 localprinter, uin * If it's the first connection, contact the client * and connect to the IPC$ share anonumously */ - if (smb_connections==0) + if (smb_connections==0) { if(!spoolss_connect_to_client(&cli, printer+2)) /* the +2 is to strip the leading 2 backslashs */ return False; + message_register(MSG_PRINTER_NOTIFY, srv_spoolss_receive_message); + + } smb_connections++; -- cgit From efe9922b43ab3c0d89f55749389a7ec49bc8bd62 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 27 Sep 2000 21:57:38 +0000 Subject: Fixed stupid introduced bug found by "Jim McDonough/Boulder/IBM" . Jeremy. (This used to be commit 563f8b09a810446c658bf58303b5fe998d27bec9) --- source3/rpc_server/srv_spoolss_nt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 86fa0d108d..c281ccaacc 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3181,10 +3181,10 @@ uint32 _spoolss_endpageprinter(POLICY_HND *handle) static struct current_user *get_current_user(struct current_user *user, pipes_struct *p) { if (p->ntlmssp_auth_validated) { - memcpy(user, &p->pipe_user, sizeof(user)); + memcpy(user, &p->pipe_user, sizeof(struct current_user)); } else { extern struct current_user current_user; - memcpy(user, ¤t_user, sizeof(user)); + memcpy(user, ¤t_user, sizeof(struct current_user)); } return user; -- cgit From 7de0b5588e855a967f0a5094c515b955ff4a23cf Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 29 Sep 2000 21:15:45 +0000 Subject: Missing null termination on printer changenotify message caused insure error. Jeremy. (This used to be commit 3733d29ce678c71ef2ee8b600e547765d8d8ea9e) --- source3/rpc_server/srv_spoolss_nt.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index c281ccaacc..8996389039 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -584,11 +584,12 @@ static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size) ****************************************************************************/ void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size_t len) { - char printer[256]; + fstring printer; uint32 status; Printer_entry *find_printer; - memcpy(printer, buf, len); + *printer = '\0'; + fstrcpy(printer,buf); find_printer = (Printer_entry *)ubi_dlFirst(&Printer_list); @@ -630,7 +631,7 @@ static BOOL srv_spoolss_sendnotify(POLICY_HND *handle) fstrcpy(printer, ""); /*srv_spoolss_receive_message(printer);*/ - message_send_all(MSG_PRINTER_NOTIFY, printer, strlen(printer)); + message_send_all(MSG_PRINTER_NOTIFY, printer, strlen(printer) + 1); /* Null terminate... */ return True; } -- cgit From e26d09685cf4aff2256adccf9b576d48fe52cc89 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 2 Oct 2000 19:28:26 +0000 Subject: Added debug so if zero length messages get sent we successfully remove them (this can happen if smbd processes are shut down at the wrong time). Jeremy. (This used to be commit c1de97f96b8c5ad8e5f01a0d17c6387733769442) --- source3/rpc_server/srv_spoolss_nt.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 8996389039..6e222b2386 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -591,6 +591,13 @@ void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size_t len) *printer = '\0'; fstrcpy(printer,buf); + if (len == 0) { + DEBUG(0,("srv_spoolss_receive_message: got null message !\n")); + return; + } + + DEBUG(10,("srv_spoolss_receive_message: Got message about printer %s\n", printer )); + find_printer = (Printer_entry *)ubi_dlFirst(&Printer_list); /* Iterate the printer list. */ @@ -631,6 +638,8 @@ static BOOL srv_spoolss_sendnotify(POLICY_HND *handle) fstrcpy(printer, ""); /*srv_spoolss_receive_message(printer);*/ + DEBUG(10,("srv_spoolss_sendnotify: Sending message about printer %s\n", printer )); + message_send_all(MSG_PRINTER_NOTIFY, printer, strlen(printer) + 1); /* Null terminate... */ return True; -- cgit From c5ca95aeb1202c64bf37c8031c83d5c59c990ce3 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 3 Oct 2000 18:29:12 +0000 Subject: Fixes from Herb - compiler warnings. Jeremy. (This used to be commit d9d3668fa322cbed36ca3393d8268bf0e5255e8d) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 6e222b2386..717ee1bed1 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3096,7 +3096,7 @@ static uint32 getprinterdriver2_level6(fstring servername, fstring architecture, *needed += spoolss_size_printer_driver_info_6(&info); if (!alloc_buffer_size(buffer, *needed)) { - free_printer_driver_info_3(&info); + free_printer_driver_info_6(&info); return ERROR_INSUFFICIENT_BUFFER; } -- cgit From 23f78fd7b91878176c518471cdca84cad826cba9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 4 Oct 2000 01:03:23 +0000 Subject: Adding Herb's compile warning fixes to HEAD. Jeremy. (This used to be commit d131ad1ce3f6e72e295f865a463f8dcbfa6f8d42) --- source3/rpc_server/srv_spoolss_nt.c | 45 ------------------------------------- 1 file changed, 45 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 717ee1bed1..c32ca8d871 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -318,10 +318,8 @@ static BOOL get_printer_snum(POLICY_HND *hnd, int *number) return (*number != -1); case PRINTER_HANDLE_IS_PRINTSERVER: return False; - break; default: return False; - break; } } @@ -1459,7 +1457,6 @@ static uint32 size_of_notify_info_data(uint16 type, uint16 field) (notify_info_data_table[i].field == field ) ) { return (notify_info_data_table[i].size); - continue; } i++; } @@ -1486,7 +1483,6 @@ static BOOL type_of_notify_info_data(uint16 type, uint16 field) { return (True); } - continue; } i++; } @@ -1796,10 +1792,8 @@ uint32 _spoolss_rfnpcnex( POLICY_HND *handle, uint32 change, switch (Printer->printer_type) { case PRINTER_HANDLE_IS_PRINTSERVER: return printserver_notify_info(handle, info); - break; case PRINTER_HANDLE_IS_PRINTER: return printer_notify_info(handle, info); - break; } return ERROR_INVALID_HANDLE; @@ -2503,18 +2497,14 @@ uint32 _spoolss_enumprinters( uint32 flags, const UNISTR2 *servername, uint32 le switch (level) { case 1: return enumprinters_level1(flags, name, buffer, offered, needed, returned); - break; case 2: return enumprinters_level2(flags, name, buffer, offered, needed, returned); - break; case 5: return enumprinters_level5(flags, name, buffer, offered, needed, returned); - break; case 3: case 4: default: return ERROR_INVALID_LEVEL; - break; } } @@ -2679,7 +2669,6 @@ uint32 _spoolss_getprinter(POLICY_HND *handle, uint32 level, return getprinter_level_3(servername,snum, buffer, offered, needed); default: return ERROR_INVALID_LEVEL; - break; } } @@ -3137,19 +3126,14 @@ uint32 _spoolss_getprinterdriver2(POLICY_HND *handle, const UNISTR2 *uni_arch, u switch (level) { case 1: return getprinterdriver2_level1(servername, architecture, clientmajorversion, snum, buffer, offered, needed); - break; case 2: return getprinterdriver2_level2(servername, architecture, clientmajorversion, snum, buffer, offered, needed); - break; case 3: return getprinterdriver2_level3(servername, architecture, clientmajorversion, snum, buffer, offered, needed); - break; case 6: return getprinterdriver2_level6(servername, architecture, clientmajorversion, snum, buffer, offered, needed); - break; default: return ERROR_INVALID_LEVEL; - break; } } @@ -3629,17 +3613,13 @@ uint32 _spoolss_setprinter(POLICY_HND *handle, uint32 level, switch (level) { case 0: return control_printer(handle, command, p); - break; case 2: return update_printer(handle, level, info, devmode_ctr.devmode); - break; case 3: return update_printer_sec(handle, level, info, p, secdesc_ctr); - break; default: return ERROR_INVALID_LEVEL; - break; } } @@ -3893,15 +3873,12 @@ uint32 _spoolss_enumjobs( POLICY_HND *handle, uint32 firstjob, uint32 numofjobs, switch (level) { case 1: return enumjobs_level1(queue, snum, buffer, offered, needed, returned); - break; case 2: return enumjobs_level2(queue, snum, buffer, offered, needed, returned); - break; default: safe_free(queue); *returned=0; return ERROR_INVALID_LEVEL; - break; } } @@ -4217,18 +4194,14 @@ uint32 _spoolss_enumprinterdrivers( UNISTR2 *name, UNISTR2 *environment, uint32 switch (level) { case 1: return enumprinterdrivers_level1(servername, architecture, buffer, offered, needed, returned); - break; case 2: return enumprinterdrivers_level2(servername, architecture, buffer, offered, needed, returned); - break; case 3: return enumprinterdrivers_level3(servername, architecture, buffer, offered, needed, returned); - break; default: *returned=0; safe_free(list); return ERROR_INVALID_LEVEL; - break; } } @@ -4609,13 +4582,10 @@ uint32 _spoolss_enumports( UNISTR2 *name, uint32 level, switch (level) { case 1: return enumports_level_1(buffer, offered, needed, returned); - break; case 2: return enumports_level_2(buffer, offered, needed, returned); - break; default: return ERROR_INVALID_LEVEL; - break; } } @@ -4703,15 +4673,12 @@ uint32 _spoolss_addprinterex( const UNISTR2 *uni_srv_name, uint32 level, /* we don't handle yet */ /* but I know what to do ... */ return ERROR_INVALID_LEVEL; - break; case 2: return spoolss_addprinterex_level_2(uni_srv_name, info, unk0, unk1, unk2, unk3, user_switch, user, handle); - break; default: return ERROR_INVALID_LEVEL; - break; } } @@ -4810,10 +4777,8 @@ uint32 _spoolss_getprinterdriverdirectory(UNISTR2 *name, UNISTR2 *uni_environmen switch(level) { case 1: return getprinterdriverdir_level_1(name, uni_environment, buffer, offered, needed); - break; default: return ERROR_INVALID_LEVEL; - break; } } @@ -5198,10 +5163,8 @@ uint32 _spoolss_enumprintprocessors(UNISTR2 *name, UNISTR2 *environment, uint32 switch (level) { case 1: return enumprintprocessors_level_1(buffer, offered, needed, returned); - break; default: return ERROR_INVALID_LEVEL; - break; } } @@ -5250,10 +5213,8 @@ uint32 _spoolss_enumprintprocdatatypes(UNISTR2 *name, UNISTR2 *processor, uint32 switch (level) { case 1: return enumprintprocdatatypes_level_1(buffer, offered, needed, returned); - break; default: return ERROR_INVALID_LEVEL; - break; } } @@ -5342,13 +5303,10 @@ uint32 _spoolss_enumprintmonitors(UNISTR2 *name,uint32 level, switch (level) { case 1: return enumprintmonitors_level_1(buffer, offered, needed, returned); - break; case 2: return enumprintmonitors_level_2(buffer, offered, needed, returned); - break; default: return ERROR_INVALID_LEVEL; - break; } } @@ -5479,14 +5437,11 @@ uint32 _spoolss_getjob( POLICY_HND *handle, uint32 jobid, uint32 level, switch (level) { case 1: return getjob_level_1(queue, count, snum, jobid, buffer, offered, needed); - break; case 2: return getjob_level_2(queue, count, snum, jobid, buffer, offered, needed); - break; default: safe_free(queue); return ERROR_INVALID_LEVEL; - break; } } #undef OLD_NTDOMAIN -- cgit From ba00796e6dd13b87b7988a98e532676d9eab702c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 6 Oct 2000 18:13:52 +0000 Subject: Herb's warning fixes. Also the POSIX locking fix. We now use our own vfs layer to do get/set acl calls (hurrah!). Jeremy. (This used to be commit dfe77c7046cbd65ee52aea7439f21503c1eac41d) --- source3/rpc_server/srv_spoolss_nt.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index c32ca8d871..5a724d6ab6 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -358,16 +358,14 @@ static BOOL set_printer_hnd_printertype(Printer_entry *Printer, char *handlename if (!strchr(handlename+2, '\\')) { DEBUGADD(4,("Printer is a print server\n")); Printer->printer_type = PRINTER_HANDLE_IS_PRINTSERVER; - return True; } /* it's a printer */ else { DEBUGADD(4,("Printer is a printer\n")); Printer->printer_type = PRINTER_HANDLE_IS_PRINTER; - return True; } - return False; + return True; } /**************************************************************************** -- cgit From 1126775808f434c3df4089159512988df82cbdd5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 6 Oct 2000 20:03:17 +0000 Subject: Proto update. Also fix from John Reilly @ HP for not showing APW with W2K. Jeremy. (This used to be commit 698288cb9de316527c0c2a271e18c920578f9930) --- source3/rpc_server/srv_spoolss_nt.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 5a724d6ab6..56de5375fb 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -680,14 +680,21 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, return ERROR_ACCESS_DENIED; } - /* Disallow MS AddPrinterWizard if access rights are insufficient OR - if parameter disables it. The client tries an OpenPrinterEx with - SERVER_ALL_ACCESS(0xf0003), which we force to fail. It then tries - OpenPrinterEx with SERVER_READ(0x20002) which we allow. This lets - it see any printers there, but does not show the MSAPW */ + /* Disallow MS AddPrinterWizard if parameter disables it. A Win2k + client 1st tries an OpenPrinterEx with access==0, MUST be allowed. + Then both Win2k and WinNT clients try an OpenPrinterEx with + SERVER_ALL_ACCESS, which we force to fail. Then they try + OpenPrinterEx with SERVER_READ which we allow. This lets the + client view printer folder, but does not show the MSAPW. + + Note: this test needs code to check access rights here too. Jeremy + could you look at this? */ + if (handle_is_printserver(handle) && - printer_default->access_required != (SERVER_READ) && - !lp_ms_add_printer_wizard() ) { + !lp_ms_add_printer_wizard()) { + if (printer_default->access_required == 0) + return NT_STATUS_NO_PROBLEMO; + else if (printer_default->access_required != (SERVER_READ)) return ERROR_ACCESS_DENIED; } -- cgit From e8912baf025a1356aa8c02f971fbe3d67adc9b0a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 10 Oct 2000 19:09:48 +0000 Subject: Fix found by Andrew to stop local/remote printers being confused. check_printer_ok was causing SETPRINTER calls to fail. Jeremy. (This used to be commit b41cc5fea7409d07529adad44f0cbba5c764591c) --- source3/rpc_server/srv_spoolss_nt.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 56de5375fb..72c87ae819 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3406,8 +3406,9 @@ static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) * as this is what Samba insists upon. */ - if (!(info->attributes & PRINTER_ATTRIBUTE_SHARED)) { - DEBUG(10,("check_printer_ok: SHARED check failed (%x).\n", (unsigned int)info->attributes )); + if (!(info->attributes & (PRINTER_ATTRIBUTE_SHARED|PRINTER_ATTRIBUTE_NETWORK))) { + DEBUG(10,("check_printer_ok: SHARED/NETWORK check failed (%x).\n", + (unsigned int)info->attributes )); return False; } @@ -3421,8 +3422,22 @@ static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) } } + /* + * Sometimes the NT client doesn't set the sharename, but + * includes the sharename in the printername. This could + * cause SETPRINTER to fail which causes problems with the + * client getting confused between local/remote printers... + */ + + if (*info->sharename == '\0') { + char *p = strrchr(info->printername, '\\'); + if (p) + fstrcpy(info->sharename, p+1); + } + if (!strequal(info->sharename, lp_servicename(snum))) { - DEBUG(10,("check_printer_ok: NAME check failed (%s) (%s).\n", info->sharename, lp_servicename(snum))); + DEBUG(10,("check_printer_ok: NAME check failed (%s) (%s).\n", + info->sharename, lp_servicename(snum))); return False; } -- cgit From 4e1d30694555fe2b7b2684686778c7b143aea41e Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 20 Oct 2000 03:23:36 +0000 Subject: Merge from appliance-head (This used to be commit 6d39df7cf84d391bb4dd55d9a26f9f5a6368f46f) --- source3/rpc_server/srv_spoolss_nt.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 72c87ae819..928ac45046 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2080,7 +2080,11 @@ static BOOL construct_printer_info_2(fstring servername, PRINTER_INFO_2 *printer else fstrcpy(sl, '\0'); - snprintf(chaine2, sizeof(chaine)-1, "%s%s%s", servername, sl, ntprinter->info_2->printername); + if (!strchr(ntprinter->info_2->printername, '\\')) { + snprintf(chaine2, sizeof(chaine)-1, "%s%s%s", servername, sl, ntprinter->info_2->printername); + } else { + pstrcpy(chaine2, ntprinter->info_2->printername); + } init_unistr(&printer->servername, chaine); /* servername*/ init_unistr(&printer->printername, chaine2); /* printername*/ -- cgit From b5ac72cc646a981469ee65305da83f273c4cd093 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 26 Oct 2000 21:43:13 +0000 Subject: Sorry JF - no billable hours :-). I fixed the "stream of events" problem with PCL drivers. The problem was we were updating the changeid on every SETPRINTERDATA/DELETEPRINTERDATA call. We should not do this, we should just update the 'setprinter' called count. We update the changeid on calls to SETPRINTER/ADDPRINTER/ADDPRINTEREX etc. Also fixed the correct returning of the create time on printers. Jeremy. (This used to be commit 521f09829fd329f87b3d19e8871e2b989c98a58e) --- source3/rpc_server/srv_spoolss_nt.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 928ac45046..0eb75a7480 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1816,7 +1816,7 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, fstring counter_printer_0 *session_counter; uint32 global_counter; struct tm *t; - time_t setup_time = time(NULL); + time_t setuptime; print_queue_struct *queue=NULL; print_status_struct status; @@ -1869,8 +1869,8 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, fstring printer->total_jobs = 0; printer->total_bytes = 0; - t=gmtime(&setup_time); - ntprinter->info_2->setuptime = (uint32)setup_time; /* FIXME !! */ + setuptime = (time_t)ntprinter->info_2->setuptime; + t=gmtime(&setuptime); printer->year = t->tm_year+1900; printer->month = t->tm_mon+1; @@ -4957,7 +4957,7 @@ uint32 _spoolss_enumprinterdata(POLICY_HND *handle, uint32 idx, return ERROR_NOT_ENOUGH_MEMORY; } - ZERO_STRUCTP(*data_out); + memset(*data_out,'\0',in_data_len); memcpy(*data_out, data, (size_t)data_len); *out_data_len=data_len; @@ -5009,7 +5009,7 @@ uint32 _spoolss_setprinterdata( POLICY_HND *handle, if (!add_a_specific_param(printer->info_2, param)) status = ERROR_INVALID_PARAMETER; else - status = add_a_printer(*printer, 2); + status = mod_a_printer(*printer, 2); free_a_printer(&printer, 2); return status; @@ -5051,7 +5051,7 @@ uint32 _spoolss_deleteprinterdata( POLICY_HND *handle, const UNISTR2 *value) if(!unlink_specific_param_if_exist(printer->info_2, ¶m)) status = ERROR_INVALID_PARAMETER; else - status = add_a_printer(*printer, 2); + status = mod_a_printer(*printer, 2); free_a_printer(&printer, 2); return status; -- cgit From 9a8749d33aebdb4b5cb705cf250012bfa8cf9238 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 26 Oct 2000 22:09:22 +0000 Subject: Added John Reillys patch for error code returns from clean_up_printer_driver_strunct() calls. Jeremy. (This used to be commit f81a2a03bf435e65e7484ab021f86a8a4f62b656) --- source3/rpc_server/srv_spoolss_nt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 0eb75a7480..ebcccc8cf4 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4722,7 +4722,8 @@ uint32 _spoolss_addprinterdriver(pipes_struct *p, const UNISTR2 *server_name, convert_printer_driver_info(info, &driver, level); DEBUG(5,("Cleaning driver's information\n")); - clean_up_driver_struct(driver, level); + if ((err = clean_up_driver_struct(driver, level)) != NT_STATUS_NO_PROBLEMO ) + goto done; DEBUG(5,("Moving driver to final destination\n")); if(!move_driver_to_download_area(driver, level, &user, &err)) { -- cgit From c33d0e466dbcbb5dfa68250bec031af7503bd2fa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 29 Oct 2000 17:27:41 +0000 Subject: Patches from John Reilly @ HP for print job time bugs. Jeremy. (This used to be commit 0eb7f2d514317882684e9c0c51d46b1ac1eb2568) --- source3/rpc_server/srv_spoolss_nt.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index ebcccc8cf4..9c0a3319f5 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1381,6 +1381,19 @@ static void spoolss_notify_job_position(int snum, SPOOL_NOTIFY_INFO_DATA *data, data->notify_data.value[0]=queue->job; } +/******************************************************************* + * fill a notify_info_data with + ********************************************************************/ +static void spoolss_notify_submitted_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +{ + struct tm *t; + + t=gmtime(&queue->time); + + data->notify_data.data.length = sizeof(SYSTEMTIME); + make_systemtime((SYSTEMTIME*)(data->notify_data.data.string), t); +} + #define END 65535 struct s_notify_info_data_table @@ -1438,7 +1451,7 @@ struct s_notify_info_data_table notify_info_data_table[] = { JOB_NOTIFY_TYPE, JOB_NOTIFY_DOCUMENT, "JOB_NOTIFY_DOCUMENT", POINTER, spoolss_notify_job_name }, { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRIORITY, "JOB_NOTIFY_PRIORITY", ONE_VALUE, spoolss_notify_priority }, { JOB_NOTIFY_TYPE, JOB_NOTIFY_POSITION, "JOB_NOTIFY_POSITION", ONE_VALUE, spoolss_notify_job_position }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_SUBMITTED, "JOB_NOTIFY_SUBMITTED", POINTER, NULL }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_SUBMITTED, "JOB_NOTIFY_SUBMITTED", POINTER, spoolss_notify_submitted_time }, { JOB_NOTIFY_TYPE, JOB_NOTIFY_START_TIME, "JOB_NOTIFY_START_TIME", ONE_VALUE, spoolss_notify_start_time }, { JOB_NOTIFY_TYPE, JOB_NOTIFY_UNTIL_TIME, "JOB_NOTIFY_UNTIL_TIME", ONE_VALUE, spoolss_notify_until_time }, { JOB_NOTIFY_TYPE, JOB_NOTIFY_TIME, "JOB_NOTIFY_TIME", ONE_VALUE, spoolss_notify_job_time }, @@ -3696,9 +3709,8 @@ static void fill_job_info_1(JOB_INFO_1 *job_info, print_queue_struct *queue, pstring temp_name; struct tm *t; - time_t unixdate = time(NULL); - t=gmtime(&unixdate); + t=gmtime(&queue->time); snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname); job_info->jobid=queue->job; @@ -3725,14 +3737,12 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, pstring temp_name; NT_PRINTER_INFO_LEVEL *ntprinter = NULL; pstring chaine; - struct tm *t; - time_t unixdate = time(NULL); if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0 ) return False; - t=gmtime(&unixdate); + t=gmtime(&queue->time); snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname); job_info->jobid=queue->job; -- cgit From cd8525a767b293f0927d9a332e322db8cfb66f8d Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 30 Oct 2000 21:55:30 +0000 Subject: Merge of comment repair. (This used to be commit 7712421910b12fd64cf90100e4495669bec67c2f) --- source3/rpc_server/srv_spoolss_nt.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 9c0a3319f5..a99874bfcd 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1308,7 +1308,7 @@ static void spoolss_notify_average_ppm(int snum, SPOOL_NOTIFY_INFO_DATA *data, p } /******************************************************************* - * fill a notify_info_data with + * fill a notify_info_data with username ********************************************************************/ static void spoolss_notify_username(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { @@ -1317,7 +1317,7 @@ static void spoolss_notify_username(int snum, SPOOL_NOTIFY_INFO_DATA *data, prin } /******************************************************************* - * fill a notify_info_data with + * fill a notify_info_data with job status ********************************************************************/ static void spoolss_notify_job_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { @@ -1325,7 +1325,7 @@ static void spoolss_notify_job_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, pr } /******************************************************************* - * fill a notify_info_data with + * fill a notify_info_data with job name ********************************************************************/ static void spoolss_notify_job_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { @@ -1334,7 +1334,7 @@ static void spoolss_notify_job_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, prin } /******************************************************************* - * fill a notify_info_data with + * fill a notify_info_data with job status ********************************************************************/ static void spoolss_notify_job_status_string(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { @@ -1358,7 +1358,7 @@ static void spoolss_notify_job_status_string(int snum, SPOOL_NOTIFY_INFO_DATA *d } /******************************************************************* - * fill a notify_info_data with + * fill a notify_info_data with job time ********************************************************************/ static void spoolss_notify_job_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { @@ -1366,7 +1366,7 @@ static void spoolss_notify_job_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, prin } /******************************************************************* - * fill a notify_info_data with + * fill a notify_info_data with job size ********************************************************************/ static void spoolss_notify_job_size(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { @@ -1374,7 +1374,7 @@ static void spoolss_notify_job_size(int snum, SPOOL_NOTIFY_INFO_DATA *data, prin } /******************************************************************* - * fill a notify_info_data with + * fill a notify_info_data with job position ********************************************************************/ static void spoolss_notify_job_position(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { @@ -1382,7 +1382,7 @@ static void spoolss_notify_job_position(int snum, SPOOL_NOTIFY_INFO_DATA *data, } /******************************************************************* - * fill a notify_info_data with + * fill a notify_info_data with submitted time ********************************************************************/ static void spoolss_notify_submitted_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { -- cgit From 8a190a9e46db3907bd389af68b393adeb6e1ca3d Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 7 Nov 2000 02:54:50 +0000 Subject: Merge of printer security descriptor, info level and printerdata comparison changes from appliance branch. (This used to be commit ae087bdf312806e08848695cad70a943bb3d71b9) --- source3/rpc_server/srv_spoolss_nt.c | 304 +++++++++++++++++++++++++++++++----- 1 file changed, 267 insertions(+), 37 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a99874bfcd..9363829165 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3325,7 +3325,7 @@ static uint32 control_printer(POLICY_HND *handle, uint32 command, { struct current_user user; int snum; - int errcode = 0; + int errcode = ERROR_INVALID_FUNCTION; Printer_entry *Printer = find_printer_index_by_hnd(handle); get_current_user(&user, p); @@ -3335,35 +3335,29 @@ static uint32 control_printer(POLICY_HND *handle, uint32 command, return ERROR_INVALID_HANDLE; } - if (!get_printer_snum(handle, &snum) ) + if (!get_printer_snum(handle, &snum)) return ERROR_INVALID_HANDLE; switch (command) { case PRINTER_CONTROL_PAUSE: if (print_queue_pause(&user, snum, &errcode)) { - srv_spoolss_sendnotify(handle); - return 0; + errcode = 0; } break; case PRINTER_CONTROL_RESUME: case PRINTER_CONTROL_UNPAUSE: if (print_queue_resume(&user, snum, &errcode)) { - srv_spoolss_sendnotify(handle); - return 0; + errcode = 0; } break; case PRINTER_CONTROL_PURGE: if (print_queue_purge(&user, snum, &errcode)) { - srv_spoolss_sendnotify(handle); - return 0; + errcode = 0; } break; } - if (errcode) - return (uint32)errcode; - - return ERROR_INVALID_FUNCTION; + return errcode; } /******************************************************************** @@ -3383,6 +3377,7 @@ static uint32 update_printer_sec(POLICY_HND *handle, uint32 level, const SPOOL_PRINTER_INFO_LEVEL *info, pipes_struct *p, SEC_DESC_BUF *secdesc_ctr) { + SEC_DESC_BUF *new_secdesc_ctr = NULL, *old_secdesc_ctr = NULL; struct current_user user; uint32 result; int snum; @@ -3390,25 +3385,47 @@ static uint32 update_printer_sec(POLICY_HND *handle, uint32 level, Printer_entry *Printer = find_printer_index_by_hnd(handle); if (!OPEN_HANDLE(Printer) || !get_printer_snum(handle, &snum)) { - DEBUG(0,("update_printer_sec: Invalid handle (%s)\n", OUR_HANDLE(handle))); - return ERROR_INVALID_HANDLE; + DEBUG(0,("update_printer_sec: Invalid handle (%s)\n", + OUR_HANDLE(handle))); + + result = ERROR_INVALID_HANDLE; + goto done; + } + + /* NT seems to like setting the security descriptor even though + nothing may have actually changed. This causes annoying + dialog boxes when the user doesn't have permission to change + the security descriptor. */ + + nt_printing_getsec(Printer->dev.handlename, &old_secdesc_ctr); + + new_secdesc_ctr = sec_desc_merge(secdesc_ctr, old_secdesc_ctr); + + if (sec_desc_equal(new_secdesc_ctr->sec, old_secdesc_ctr->sec)) { + result = NT_STATUS_NO_PROBLEMO; + goto done; } /* Work out which user is performing the operation */ + get_current_user(&user, p); /* Check the user has permissions to change the security descriptor. By experimentation with two NT machines, the user requires Full Access to the printer to change security information. */ + if (!print_access_check(&user, snum, PRINTER_ACCESS_ADMINISTER)) { result = ERROR_ACCESS_DENIED; goto done; } - result = nt_printing_setsec(Printer->dev.handlename, secdesc_ctr); + result = nt_printing_setsec(Printer->dev.handlename, new_secdesc_ctr); done: + free_sec_desc_buf(&new_secdesc_ctr); + free_sec_desc_buf(&old_secdesc_ctr); + return result; } @@ -3522,6 +3539,181 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) return True; } +/* Return true if two devicemodes are equal */ + +static BOOL nt_devicemode_equal(NT_DEVICEMODE *d1, NT_DEVICEMODE *d2) +{ + if (!strequal(d1->devicename, d2->devicename) || + !strequal(d1->formname, d2->formname)) { + return False; + } + + if (d1->specversion != d2->specversion || + d1->driverversion != d2->driverversion || + d1->size != d2->size || + d1->driverextra != d2->driverextra || + d1->orientation != d2->orientation || + d1->papersize != d2->papersize || + d1->paperlength != d2->paperlength || + d1->paperwidth != d2->paperwidth || + d1->scale != d2->scale || + d1->copies != d2->copies || + d1->defaultsource != d2->defaultsource || + d1->printquality != d2->printquality || + d1->color != d2->color || + d1->duplex != d2->duplex || + d1->yresolution != d2->yresolution || + d1->ttoption != d2->ttoption || + d1->collate != d2->collate || + d1->logpixels != d2->logpixels) { + return False; + } + + if (d1->fields != d2->fields || + d1->bitsperpel != d2->bitsperpel || + d1->pelswidth != d2->pelswidth || + d1->pelsheight != d2->pelsheight || + d1->displayflags != d2->displayflags || + d1->displayfrequency != d2->displayfrequency || + d1->icmmethod != d2->icmmethod || + d1->icmintent != d2->icmintent || + d1->mediatype != d2->mediatype || + d1->dithertype != d2->dithertype || + d1->reserved1 != d2->reserved1 || + d1->reserved2 != d2->reserved2 || + d1->panningwidth != d2->panningwidth || + d1->panningheight != d2->panningheight) { + return False; + } + + /* Not sure what to do about these fields */ +#if 0 + uint8 *private; +#endif + + return True; +} + +/* Return true if two NT_PRINTER_PARAM structures are equal */ + +static BOOL nt_printer_param_equal(NT_PRINTER_PARAM *p1, + NT_PRINTER_PARAM *p2) +{ + if (!p1 && !p2) return True; + + if ((!p1 && p2) || (p1 && !p2)) return False; + + /* Compare lists of printer parameters */ + + while (p1) { + BOOL found = False; + NT_PRINTER_PARAM *q = p1; + + /* Find the parameter in the second structure */ + + while(q) { + + if (strequal(p1->value, q->value) && + p1->type == q->type && + p1->data_len == q->data_len && + memcmp(p1->data, q->data, p1->data_len) == 0) { + found = True; + goto found_it; + } + + q = q->next; + } + + found_it: + if (!found) { + return False; + } + + p1 = p1->next; + } + + return True; +} + +/******************************************************************** + * Called by update_printer when trying to work out whether to + * actually update printer info. + ********************************************************************/ + +static BOOL nt_printer_info_level_equal(NT_PRINTER_INFO_LEVEL *p1, + NT_PRINTER_INFO_LEVEL *p2) +{ + NT_PRINTER_INFO_LEVEL_2 *pi1, *pi2; + + /* Trivial conditions */ + + if ((!p1 && !p2) || (!p1->info_2 && !p2->info_2)) { + return True; + } + + if ((!p1 && p2) || (p1 && !p2) || + (!p1->info_2 && p2->info_2) || + (p1->info_2 && !p2->info_2)) { + return False; + } + + /* Compare two nt_printer_info_level structures. Don't compare + status or cjobs as they seem to have something to do with the + printer queue. */ + + pi1 = p1->info_2; + pi2 = p2->info_2; + + if (pi1->attributes != pi2->attributes || + pi1->priority != pi2->priority || + pi1->default_priority != pi2->default_priority || + pi1->starttime != pi2->starttime || + pi1->untiltime != pi2->untiltime || + pi1->averageppm != pi2->averageppm) { + return False; + } + + /* Yuck - don't check the printername or servername as the + add_a_printer() code plays games with them. You can't + change the printername or the sharename through this interface + in Samba. */ + + if (!strequal(pi1->sharename, pi2->sharename) || + !strequal(pi1->portname, pi2->portname) || + !strequal(pi1->drivername, pi2->drivername) || + !strequal(pi1->comment, pi2->comment) || + !strequal(pi1->location, pi2->location)) { + return False; + } + + if (!nt_devicemode_equal(pi1->devmode, pi2->devmode)) { + return False; + } + + if (!strequal(pi1->sepfile, pi2->sepfile) || + !strequal(pi1->printprocessor, pi2->printprocessor) || + !strequal(pi1->datatype, pi2->datatype) || + !strequal(pi1->parameters, pi2->parameters)) { + return False; + } + + if (!nt_printer_param_equal(pi1->specific, pi2->specific)) { + return False; + } + + if (!sec_desc_equal(pi1->secdesc_buf->sec, pi2->secdesc_buf->sec)) { + return False; + } + + if (pi1->changeid != pi2->changeid || + pi1->c_setprinter != pi2->c_setprinter || + pi1->setuptime != pi2->setuptime) { + return False; + } + + return True; +} + /******************************************************************** * called by spoolss_api_setprinter * when updating a printer description @@ -3532,7 +3724,7 @@ static uint32 update_printer(POLICY_HND *handle, uint32 level, DEVICEMODE *devmode) { int snum; - NT_PRINTER_INFO_LEVEL *printer = NULL; + NT_PRINTER_INFO_LEVEL *printer = NULL, *old_printer = NULL; Printer_entry *Printer = find_printer_index_by_hnd(handle); uint32 result; @@ -3540,8 +3732,6 @@ static uint32 update_printer(POLICY_HND *handle, uint32 level, result = NT_STATUS_NO_PROBLEMO; - /* Check calling user has permission to update printer description */ - if (level!=2) { DEBUG(0,("Send a mail to samba@samba.org\n")); DEBUGADD(0,("with the following message: update_printer: level!=2\n")); @@ -3559,14 +3749,8 @@ static uint32 update_printer(POLICY_HND *handle, uint32 level, goto done; } - if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { - DEBUG(3, ("printer property change denied by security " - "descriptor\n")); - result = ERROR_ACCESS_DENIED; - goto done; - } - - if(get_a_printer(&printer, 2, lp_servicename(snum)) != 0) { + if((get_a_printer(&printer, 2, lp_servicename(snum)) != 0) || + (get_a_printer(&old_printer, 2, lp_servicename(snum)) != 0)) { result = ERROR_INVALID_HANDLE; goto done; } @@ -3602,21 +3786,42 @@ static uint32 update_printer(POLICY_HND *handle, uint32 level, printer->info_2->devmode=NULL; } - /* - * Do sanity check on the requested changes for Samba. - */ + /* Do sanity check on the requested changes for Samba */ if (!check_printer_ok(printer->info_2, snum)) { result = ERROR_INVALID_PARAMETER; goto done; } + /* NT likes to call this function even though nothing has actually + changed. Check this so the user doesn't end up with an + annoying permission denied dialog box. */ + + if (nt_printer_info_level_equal(printer, old_printer)) { + DEBUG(3, ("printer info has not changed\n")); + result = NT_STATUS_NO_PROBLEMO; + goto done; + } + + /* Check calling user has permission to update printer description */ + + if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { + DEBUG(3, ("printer property change denied by security " + "descriptor\n")); + result = ERROR_ACCESS_DENIED; + goto done; + } + + /* Call addprinter hook */ + if (*lp_addprinter_cmd() ) if ( !add_printer_hook(printer) ) { result = ERROR_ACCESS_DENIED; goto done; } + /* Update printer info */ + if (add_a_printer(*printer, 2)!=0) { /* I don't really know what to return here !!! */ result = ERROR_ACCESS_DENIED; @@ -4988,14 +5193,13 @@ uint32 _spoolss_setprinterdata( POLICY_HND *handle, uint32 numeric_data) { NT_PRINTER_INFO_LEVEL *printer = NULL; - NT_PRINTER_PARAM *param = NULL; + NT_PRINTER_PARAM *param = NULL, old_param; int snum=0; uint32 status = 0x0; Printer_entry *Printer=find_printer_index_by_hnd(handle); DEBUG(5,("spoolss_setprinterdata\n")); - if (!OPEN_HANDLE(Printer)) { DEBUG(0,("_spoolss_setprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; @@ -5004,17 +5208,40 @@ uint32 _spoolss_setprinterdata( POLICY_HND *handle, if (!get_printer_snum(handle, &snum)) return ERROR_INVALID_HANDLE; - if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { - DEBUG(3, ("security descriptor change denied by existing " - "security descriptor\n")); - return ERROR_ACCESS_DENIED; - } - status = get_a_printer(&printer, 2, lp_servicename(snum)); if (status != 0x0) return ERROR_INVALID_NAME; convert_specific_param(¶m, value , type, data, real_len); + + /* Check if we are making any changes or not. Return true if + nothing is actually changing. */ + + ZERO_STRUCT(old_param); + + if (get_specific_param(*printer, 2, param->value, &old_param.data, + &old_param.type, &old_param.data_len)) { + + if (param->type == old_param.type && + param->data_len == old_param.data_len && + memcmp(param->data, old_param.data, + old_param.data_len) == 0) { + + DEBUG(3, ("setprinterdata hasn't changed\n")); + status = NT_STATUS_NO_PROBLEMO; + goto done; + } + } + + /* Access check */ + + if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { + DEBUG(3, ("security descriptor change denied by existing " + "security descriptor\n")); + status = ERROR_ACCESS_DENIED; + goto done; + } + unlink_specific_param_if_exist(printer->info_2, param); if (!add_a_specific_param(printer->info_2, param)) @@ -5022,7 +5249,10 @@ uint32 _spoolss_setprinterdata( POLICY_HND *handle, else status = mod_a_printer(*printer, 2); + done: free_a_printer(&printer, 2); + safe_free(old_param.data); + return status; } -- cgit From 1d3747e7f296c062854fe66fffa60c4ff83a2200 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 8 Nov 2000 00:20:26 +0000 Subject: Merge fest!!! (This used to be commit 87775074b22bb969c3585556e2a86ac4c7d4b0d4) --- source3/rpc_server/srv_spoolss_nt.c | 44 +++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 24 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 9363829165..67b29bdbcf 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1339,18 +1339,19 @@ static void spoolss_notify_job_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, prin static void spoolss_notify_job_status_string(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { char *p = "unknown"; + switch (queue->status) { case LPQ_QUEUED: - p = "QUEUED"; + p = "Queued"; break; case LPQ_PAUSED: - p = "PAUSED"; + p = ""; /* NT provides the paused string */ break; case LPQ_SPOOLING: - p = "SPOOLING"; + p = "Spooling"; break; case LPQ_PRINTING: - p = "PRINTING"; + p = "Printing"; break; } data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, @@ -3324,8 +3325,7 @@ static uint32 control_printer(POLICY_HND *handle, uint32 command, pipes_struct *p) { struct current_user user; - int snum; - int errcode = ERROR_INVALID_FUNCTION; + int snum, errcode = ERROR_INVALID_FUNCTION; Printer_entry *Printer = find_printer_index_by_hnd(handle); get_current_user(&user, p); @@ -3355,6 +3355,8 @@ static uint32 control_printer(POLICY_HND *handle, uint32 command, errcode = 0; } break; + default: + return ERROR_INVALID_LEVEL; } return errcode; @@ -3830,6 +3832,7 @@ static uint32 update_printer(POLICY_HND *handle, uint32 level, done: free_a_printer(&printer, 2); + free_a_printer(&old_printer, 2); srv_spoolss_sendnotify(handle); @@ -4131,17 +4134,12 @@ uint32 _spoolss_schedulejob( POLICY_HND *handle, uint32 jobid) /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_setjob( POLICY_HND *handle, - uint32 jobid, - uint32 level, - pipes_struct *p, - JOB_INFO *ctr, - uint32 command) - +uint32 _spoolss_setjob(POLICY_HND *handle, uint32 jobid, uint32 level, + pipes_struct *p, JOB_INFO *ctr, uint32 command) { struct current_user user; - int snum; print_status_struct prt_status; + int snum, errcode = ERROR_INVALID_FUNCTION; memset(&prt_status, 0, sizeof(prt_status)); @@ -4158,28 +4156,26 @@ uint32 _spoolss_setjob( POLICY_HND *handle, switch (command) { case JOB_CONTROL_CANCEL: case JOB_CONTROL_DELETE: - if (print_job_delete(&user, jobid)) { - srv_spoolss_sendnotify(handle); - return 0x0; + if (print_job_delete(&user, jobid, &errcode)) { + errcode = 0; } break; case JOB_CONTROL_PAUSE: - if (print_job_pause(&user, jobid)) { - srv_spoolss_sendnotify(handle); - return 0x0; + if (print_job_pause(&user, jobid, &errcode)) { + errcode = 0; } break; + case JOB_CONTROL_RESTART: case JOB_CONTROL_RESUME: - if (print_job_resume(&user, jobid)) { - srv_spoolss_sendnotify(handle); - return 0x0; + if (print_job_resume(&user, jobid, &errcode)) { + errcode = 0; } break; default: return ERROR_INVALID_LEVEL; } - return ERROR_INVALID_HANDLE; + return errcode; } /**************************************************************************** -- cgit From 3adc0e7a4ee71d255d2181a928d6e632664b7f4c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 8 Nov 2000 03:12:16 +0000 Subject: an attempt to get the handling of fields in printer info structures consistent. Still working with Jeremy on this, there is probably more to be done (This used to be commit c4bb9c598cf9781d48bc123a8cbbed9c2049bf89) --- source3/rpc_server/srv_spoolss_nt.c | 67 +++++++++++++------------------------ 1 file changed, 24 insertions(+), 43 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 67b29bdbcf..86c97b33ef 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1103,12 +1103,19 @@ static void spoolss_notify_server_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, p static void spoolss_notify_printer_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { + /* the notify name should not contain the \\server\ part */ + char *p = strrchr(printer->info_2->printername, '\\'); + if (!p) { + p = printer->info_2->printername; + } else { + p++; + } /* data->notify_data.data.length=strlen(lp_servicename(snum)); dos_PutUniCode(data->notify_data.data.string, lp_servicename(snum), sizeof(data->notify_data.data.string), True); */ data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, - printer->info_2->printername, sizeof(data->notify_data.data.string), True) - sizeof(uint16))/sizeof(uint16)); + p, sizeof(data->notify_data.data.string), True) - sizeof(uint16))/sizeof(uint16)); } /******************************************************************* @@ -1871,8 +1878,7 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, fstring */ global_counter=session_counter->counter; - /* the description and the name are of the form \\server\share */ - slprintf(chaine,sizeof(chaine)-1,"\\\\%s\\%s",servername, ntprinter->info_2->printername); + pstrcpy(chaine,ntprinter->info_2->printername); init_unistr(&printer->printername, chaine); @@ -2013,7 +2019,7 @@ static DEVICEMODE *construct_dev_mode(int snum, char *servername) DEBUGADD(8,("loading DEVICEMODE\n")); - snprintf(adevice, sizeof(adevice), "\\\\%s\\%s", global_myname, printer->info_2->printername); + safe_strcpy(adevice, printer->info_2->printername, sizeof(adevice)); init_unistr(&devmode->devicename, adevice); snprintf(aform, sizeof(aform), ntdevmode->formname); @@ -3433,50 +3439,25 @@ static uint32 update_printer_sec(POLICY_HND *handle, uint32 level, /******************************************************************** Do Samba sanity checks on a printer info struct. + this has changed purpose: it now "canonicalises" printer + info from a client rather than just checking it is correct ********************************************************************/ static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) { - /* - * Ensure that this printer is shared under the correct name - * as this is what Samba insists upon. - */ - - if (!(info->attributes & (PRINTER_ATTRIBUTE_SHARED|PRINTER_ATTRIBUTE_NETWORK))) { - DEBUG(10,("check_printer_ok: SHARED/NETWORK check failed (%x).\n", - (unsigned int)info->attributes )); - return False; - } - - if (!(info->attributes & PRINTER_ATTRIBUTE_RAW_ONLY)) { - /* NT forgets to set the raw attribute but sends the correct type. */ - if (strequal(info->datatype, "RAW")) - info->attributes |= PRINTER_ATTRIBUTE_RAW_ONLY; - else { - DEBUG(10,("check_printer_ok: RAW check failed (%x).\n", (unsigned int)info->attributes )); - return False; - } - } - - /* - * Sometimes the NT client doesn't set the sharename, but - * includes the sharename in the printername. This could - * cause SETPRINTER to fail which causes problems with the - * client getting confused between local/remote printers... - */ - - if (*info->sharename == '\0') { - char *p = strrchr(info->printername, '\\'); - if (p) - fstrcpy(info->sharename, p+1); - } - - if (!strequal(info->sharename, lp_servicename(snum))) { - DEBUG(10,("check_printer_ok: NAME check failed (%s) (%s).\n", - info->sharename, lp_servicename(snum))); - return False; - } + DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s portname=%s drivername=%s comment=%s location=%s\n", + info->servername, info->printername, info->sharename, info->portname, info->drivername, info->comment, info->location)); + /* we force some elements to "correct" values */ + slprintf(info->servername, sizeof(info->servername), "\\\\%s", global_myname); + slprintf(info->printername, sizeof(info->printername), "\\\\%s\\%s", + global_myname, lp_servicename(snum)); + fstrcpy(info->sharename, lp_servicename(snum)); + info->attributes = PRINTER_ATTRIBUTE_SHARED \ + | PRINTER_ATTRIBUTE_LOCAL \ + | PRINTER_ATTRIBUTE_RAW_ONLY \ + | PRINTER_ATTRIBUTE_QUEUED ; + return True; } -- cgit From c1900772ce6fdedc5c380d88f3640107d52e2096 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 10 Nov 2000 19:36:34 +0000 Subject: printing/nt_printing.c: use getpwuid not smbgetpwuid. Canonicalize printernames. printing/printing.c: Insure fix for malloc of zero. rpc_parse/parse_misc.c: Enusre UNISTR's are zero filled. rpc_parse/parse_spoolss.c: Correct INFO_6 - differs between pre-releases of W2K and shipping build. rpc_server/srv_spoolss_nt.c: Canonicalize printernames. Jeremy. (This used to be commit b17e23a8ff2b44540726968355a4b7e26f244f3b) --- source3/rpc_server/srv_spoolss_nt.c | 150 ++++++++++++++++-------------------- 1 file changed, 65 insertions(+), 85 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 86c97b33ef..42f9d29d9c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1588,6 +1588,10 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPO current_data=&info->data[info->count]; construct_info_data(current_data, type, field, id); + + DEBUG(10,("construct_notify_printer_info: calling %s\n", + notify_info_data_table[j].name )); + notify_info_data_table[j].fn(snum, current_data, queue, printer); info->count++; @@ -1827,9 +1831,9 @@ uint32 _spoolss_rfnpcnex( POLICY_HND *handle, uint32 change, /******************************************************************** * construct_printer_info_0 - * fill a printer_info_1 struct + * fill a printer_info_0 struct ********************************************************************/ -static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, fstring servername) +static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum) { pstring chaine; int count; @@ -1882,7 +1886,7 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, fstring init_unistr(&printer->printername, chaine); - slprintf(chaine,sizeof(chaine)-1,"\\\\%s", servername); + slprintf(chaine,sizeof(chaine)-1,"\\\\%s", global_myname); init_unistr(&printer->servername, chaine); printer->cjobs = count; @@ -1938,7 +1942,7 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, fstring * construct_printer_info_1 * fill a printer_info_1 struct ********************************************************************/ -static BOOL construct_printer_info_1(fstring server, uint32 flags, PRINTER_INFO_1 *printer, int snum) +static BOOL construct_printer_info_1(uint32 flags, PRINTER_INFO_1 *printer, int snum) { pstring chaine; pstring chaine2; @@ -1951,16 +1955,16 @@ static BOOL construct_printer_info_1(fstring server, uint32 flags, PRINTER_INFO_ if (*ntprinter->info_2->comment == '\0') { init_unistr(&printer->comment, lp_comment(snum)); - snprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",server, ntprinter->info_2->printername, + snprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",global_myname, ntprinter->info_2->printername, ntprinter->info_2->drivername, lp_comment(snum)); } else { init_unistr(&printer->comment, ntprinter->info_2->comment); /* saved comment. */ - snprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",server, ntprinter->info_2->printername, + snprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",global_myname, ntprinter->info_2->printername, ntprinter->info_2->drivername, ntprinter->info_2->comment); } - snprintf(chaine2,sizeof(chaine)-1,"%s%s", server, ntprinter->info_2->printername); + snprintf(chaine2,sizeof(chaine)-1,"%s", ntprinter->info_2->printername); init_unistr(&printer->description, chaine); init_unistr(&printer->name, chaine2); @@ -1989,7 +1993,7 @@ static void free_dev_mode(DEVICEMODE *dev) Create a DEVMODE struct. Returns malloced memory. ****************************************************************************/ -static DEVICEMODE *construct_dev_mode(int snum, char *servername) +static DEVICEMODE *construct_dev_mode(int snum) { char adevice[32]; char aform[32]; @@ -2075,11 +2079,8 @@ static DEVICEMODE *construct_dev_mode(int snum, char *servername) * fill a printer_info_2 struct ********************************************************************/ -static BOOL construct_printer_info_2(fstring servername, PRINTER_INFO_2 *printer, int snum) +static BOOL construct_printer_info_2(PRINTER_INFO_2 *printer, int snum) { - pstring chaine; - pstring chaine2; - pstring sl; int count; NT_PRINTER_INFO_LEVEL *ntprinter = NULL; @@ -2093,21 +2094,8 @@ static BOOL construct_printer_info_2(fstring servername, PRINTER_INFO_2 *printer memset(&status, 0, sizeof(status)); count = print_queue_status(snum, &queue, &status); - snprintf(chaine, sizeof(chaine)-1, "%s", servername); - - if (strlen(servername)!=0) - fstrcpy(sl, "\\"); - else - fstrcpy(sl, '\0'); - - if (!strchr(ntprinter->info_2->printername, '\\')) { - snprintf(chaine2, sizeof(chaine)-1, "%s%s%s", servername, sl, ntprinter->info_2->printername); - } else { - pstrcpy(chaine2, ntprinter->info_2->printername); - } - - init_unistr(&printer->servername, chaine); /* servername*/ - init_unistr(&printer->printername, chaine2); /* printername*/ + init_unistr(&printer->servername, ntprinter->info_2->servername); /* servername*/ + init_unistr(&printer->printername, ntprinter->info_2->printername); /* printername*/ init_unistr(&printer->sharename, lp_servicename(snum)); /* sharename */ init_unistr(&printer->portname, ntprinter->info_2->portname); /* port */ init_unistr(&printer->drivername, ntprinter->info_2->drivername); /* drivername */ @@ -2133,7 +2121,7 @@ static BOOL construct_printer_info_2(fstring servername, PRINTER_INFO_2 *printer printer->cjobs = count; /* jobs */ printer->averageppm = ntprinter->info_2->averageppm; /* average pages per minute */ - if((printer->devmode = construct_dev_mode(snum, servername)) == NULL) { + if((printer->devmode = construct_dev_mode(snum)) == NULL) { DEBUG(8, ("Returning NULL Devicemode!\n")); } @@ -2157,8 +2145,7 @@ static BOOL construct_printer_info_2(fstring servername, PRINTER_INFO_2 *printer * construct_printer_info_3 * fill a printer_info_3 struct ********************************************************************/ -static BOOL construct_printer_info_3(fstring servername, - PRINTER_INFO_3 **pp_printer, int snum) +static BOOL construct_printer_info_3(PRINTER_INFO_3 **pp_printer, int snum) { NT_PRINTER_INFO_LEVEL *ntprinter = NULL; PRINTER_INFO_3 *printer = NULL; @@ -2211,7 +2198,7 @@ static BOOL construct_printer_info_3(fstring servername, /******************************************************************** Spoolss_enumprinters. ********************************************************************/ -static BOOL enum_all_printers_info_1(fstring server, uint32 flags, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static BOOL enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int snum; int i; @@ -2225,7 +2212,7 @@ static BOOL enum_all_printers_info_1(fstring server, uint32 flags, NEW_BUFFER *b if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) { DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum)); - if (construct_printer_info_1(server, flags, ¤t_prt, snum)) { + if (construct_printer_info_1(flags, ¤t_prt, snum)) { if((printers=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_1))) == NULL) { *returned=0; return ERROR_NOT_ENOUGH_MEMORY; @@ -2262,20 +2249,11 @@ static BOOL enum_all_printers_info_1(fstring server, uint32 flags, NEW_BUFFER *b /******************************************************************** enum_all_printers_info_1_local. *********************************************************************/ -static BOOL enum_all_printers_info_1_local(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static BOOL enum_all_printers_info_1_local(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { - fstring temp; DEBUG(4,("enum_all_printers_info_1_local\n")); - fstrcpy(temp, "\\\\"); - fstrcat(temp, global_myname); - - if (!strcmp(name, temp)) { - fstrcat(temp, "\\"); - return enum_all_printers_info_1(temp, PRINTER_ENUM_ICON8, buffer, offered, needed, returned); - } - else - return enum_all_printers_info_1("", PRINTER_ENUM_ICON8, buffer, offered, needed, returned); + return enum_all_printers_info_1(PRINTER_ENUM_ICON8, buffer, offered, needed, returned); } /******************************************************************** @@ -2289,9 +2267,8 @@ static BOOL enum_all_printers_info_1_name(fstring name, NEW_BUFFER *buffer, uint fstrcpy(temp, "\\\\"); fstrcat(temp, global_myname); - if (!strcmp(name, temp)) { - fstrcat(temp, "\\"); - return enum_all_printers_info_1(temp, PRINTER_ENUM_ICON8, buffer, offered, needed, returned); + if (strequal(name, temp)) { + return enum_all_printers_info_1(PRINTER_ENUM_ICON8, buffer, offered, needed, returned); } else return ERROR_INVALID_NAME; @@ -2354,15 +2331,11 @@ static BOOL enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, ui /******************************************************************** enum_all_printers_info_1_network. *********************************************************************/ -static BOOL enum_all_printers_info_1_network(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static BOOL enum_all_printers_info_1_network(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { - fstring temp; DEBUG(4,("enum_all_printers_info_1_network\n")); - fstrcpy(temp, "\\\\"); - fstrcat(temp, global_myname); - fstrcat(temp, "\\"); - return enum_all_printers_info_1(temp, PRINTER_ENUM_UNKNOWN_8, buffer, offered, needed, returned); + return enum_all_printers_info_1(PRINTER_ENUM_UNKNOWN_8, buffer, offered, needed, returned); } /******************************************************************** @@ -2370,7 +2343,7 @@ static BOOL enum_all_printers_info_1_network(fstring name, NEW_BUFFER *buffer, u * * called from api_spoolss_enumprinters (see this to understand) ********************************************************************/ -static BOOL enum_all_printers_info_2(fstring servername, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static BOOL enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int snum; int i; @@ -2382,7 +2355,7 @@ static BOOL enum_all_printers_info_2(fstring servername, NEW_BUFFER *buffer, uin if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) { DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum)); - if (construct_printer_info_2(servername, ¤t_prt, snum)) { + if (construct_printer_info_2(¤t_prt, snum)) { if((printers=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_2))) == NULL) return ERROR_NOT_ENOUGH_MEMORY; DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_2\n", *returned)); @@ -2434,7 +2407,7 @@ static uint32 enumprinters_level1( uint32 flags, fstring name, /* Not all the flags are equals */ if (flags & PRINTER_ENUM_LOCAL) - return enum_all_printers_info_1_local(name, buffer, offered, needed, returned); + return enum_all_printers_info_1_local(buffer, offered, needed, returned); if (flags & PRINTER_ENUM_NAME) return enum_all_printers_info_1_name(name, buffer, offered, needed, returned); @@ -2443,7 +2416,7 @@ static uint32 enumprinters_level1( uint32 flags, fstring name, return enum_all_printers_info_1_remote(name, buffer, offered, needed, returned); if (flags & PRINTER_ENUM_NETWORK) - return enum_all_printers_info_1_network(name, buffer, offered, needed, returned); + return enum_all_printers_info_1_network(buffer, offered, needed, returned); return NT_STATUS_NO_PROBLEMO; /* NT4sp5 does that */ } @@ -2461,15 +2434,15 @@ static uint32 enumprinters_level2( uint32 flags, fstring servername, fstrcat(temp, global_myname); if (flags & PRINTER_ENUM_LOCAL) { - if (!strcmp(servername, temp)) - return enum_all_printers_info_2(temp, buffer, offered, needed, returned); + if (strequal(servername, temp)) + return enum_all_printers_info_2(buffer, offered, needed, returned); else - return enum_all_printers_info_2("", buffer, offered, needed, returned); + return enum_all_printers_info_2(buffer, offered, needed, returned); } if (flags & PRINTER_ENUM_NAME) { - if (!strcmp(servername, temp)) - return enum_all_printers_info_2(temp, buffer, offered, needed, returned); + if (strequal(servername, temp)) + return enum_all_printers_info_2(buffer, offered, needed, returned); else return ERROR_INVALID_NAME; } @@ -2539,14 +2512,14 @@ uint32 _spoolss_enumprinters( uint32 flags, const UNISTR2 *servername, uint32 le /**************************************************************************** ****************************************************************************/ -static uint32 getprinter_level_0(fstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static uint32 getprinter_level_0(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_0 *printer=NULL; if((printer=(PRINTER_INFO_0*)malloc(sizeof(PRINTER_INFO_0))) == NULL) return ERROR_NOT_ENOUGH_MEMORY; - construct_printer_info_0(printer, snum, servername); + construct_printer_info_0(printer, snum); /* check the required size. */ *needed += spoolss_size_printer_info_0(printer); @@ -2571,14 +2544,14 @@ static uint32 getprinter_level_0(fstring servername, int snum, NEW_BUFFER *buffe /**************************************************************************** ****************************************************************************/ -static uint32 getprinter_level_1(fstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static uint32 getprinter_level_1(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_1 *printer=NULL; if((printer=(PRINTER_INFO_1*)malloc(sizeof(PRINTER_INFO_1))) == NULL) return ERROR_NOT_ENOUGH_MEMORY; - construct_printer_info_1(servername, PRINTER_ENUM_ICON8, printer, snum); + construct_printer_info_1(PRINTER_ENUM_ICON8, printer, snum); /* check the required size. */ *needed += spoolss_size_printer_info_1(printer); @@ -2603,17 +2576,14 @@ static uint32 getprinter_level_1(fstring servername, int snum, NEW_BUFFER *buffe /**************************************************************************** ****************************************************************************/ -static uint32 getprinter_level_2(fstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static uint32 getprinter_level_2(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_2 *printer=NULL; - fstring temp; if((printer=(PRINTER_INFO_2*)malloc(sizeof(PRINTER_INFO_2)))==NULL) return ERROR_NOT_ENOUGH_MEMORY; - fstrcpy(temp, "\\\\"); - fstrcat(temp, servername); - construct_printer_info_2(temp, printer, snum); + construct_printer_info_2(printer, snum); /* check the required size. */ *needed += spoolss_size_printer_info_2(printer); @@ -2641,14 +2611,12 @@ static uint32 getprinter_level_2(fstring servername, int snum, NEW_BUFFER *buffe /**************************************************************************** ****************************************************************************/ -static uint32 getprinter_level_3(fstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static uint32 getprinter_level_3(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_3 *printer=NULL; fstring temp; - fstrcpy(temp, "\\\\"); - fstrcat(temp, servername); - if (!construct_printer_info_3(temp, &printer, snum)) + if (!construct_printer_info_3(&printer, snum)) return ERROR_NOT_ENOUGH_MEMORY; /* check the required size. */ @@ -2678,24 +2646,21 @@ uint32 _spoolss_getprinter(POLICY_HND *handle, uint32 level, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { int snum; - fstring servername; *needed=0; - pstrcpy(servername, global_myname); - if (!get_printer_snum(handle, &snum)) return ERROR_INVALID_HANDLE; switch (level) { case 0: - return getprinter_level_0(servername, snum, buffer, offered, needed); + return getprinter_level_0(snum, buffer, offered, needed); case 1: - return getprinter_level_1(servername,snum, buffer, offered, needed); + return getprinter_level_1(snum, buffer, offered, needed); case 2: - return getprinter_level_2(servername,snum, buffer, offered, needed); + return getprinter_level_2(snum, buffer, offered, needed); case 3: - return getprinter_level_3(servername,snum, buffer, offered, needed); + return getprinter_level_3(snum, buffer, offered, needed); default: return ERROR_INVALID_LEVEL; } @@ -2963,8 +2928,23 @@ static uint32 construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, fst status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version); DEBUG(8,("construct_printer_driver_info_6: status: %d\n", status)); if (status != 0) { - free_a_printer(&printer,2); - return ERROR_UNKNOWN_PRINTER_DRIVER; + /* + * Is this a W2k client ? + */ + + if (version < 3) { + free_a_printer(&printer,2); + return ERROR_UNKNOWN_PRINTER_DRIVER; + } + + /* Yes - try again with a WinNT driver. */ + version = 2; + status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version); + DEBUG(8,("construct_printer_driver_info_6: status: %d\n", status)); + if (status != 0) { + free_a_printer(&printer,2); + return ERROR_UNKNOWN_PRINTER_DRIVER; + } } fill_printer_driver_info_6(info, driver, servername); @@ -3747,7 +3727,7 @@ static uint32 update_printer(POLICY_HND *handle, uint32 level, */ convert_printer_info(info, printer, level); - + if (info->info_2->devmode_ptr != 0) { /* we have a valid devmode convert it and link it*/ @@ -3963,7 +3943,7 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, job_info->timeelapsed=0; job_info->pagesprinted=0; - if((job_info->devmode = construct_dev_mode(snum, global_myname)) == NULL) { + if((job_info->devmode = construct_dev_mode(snum)) == NULL) { free_a_printer(&ntprinter, 2); return False; } -- cgit From e0bcc7ff5434e9f858acc6a79d1842d86d37d73e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 14 Nov 2000 02:14:58 +0000 Subject: printing/nt_printing.c: After long soul searching and making both Andrew and my life a misery, here is the only possible null driver fix we have found. This *SUCKS*. rpc_server/srv_spoolss_nt.c: Correct printername search. Correct portname reply Correct attributes reply. Removal of unused temp variable. Jeremy. (This used to be commit 06e71c9f8be20b84e33e143c3d0b7904225efb45) --- source3/rpc_server/srv_spoolss_nt.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 42f9d29d9c..cd2b4c4e3d 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -405,6 +405,7 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) */ for (snum=0;snuminfo_2->printername+2, '\\'); + printername++; + DEBUG(10,("set_printer_hnd_name: name [%s], aprinter [%s]\n", printer->info_2->printername, aprinter )); - if ( strlen(printer->info_2->printername) != strlen(aprinter) ) { + if ( strlen(printername) != strlen(aprinter) ) { free_a_printer(&printer, 2); continue; } - if ( strncasecmp(printer->info_2->printername, aprinter, strlen(aprinter))) { + if ( strncasecmp(printername, aprinter, strlen(aprinter))) { free_a_printer(&printer, 2); continue; } @@ -1097,8 +1101,7 @@ static void spoolss_notify_server_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, p } /******************************************************************* - * fill a notify_info_data with the servicename - * jfmxxxx: it's incorrect should be long_printername + * fill a notify_info_data with the printername (not including the servername). ********************************************************************/ static void spoolss_notify_printer_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) @@ -1110,10 +1113,7 @@ static void spoolss_notify_printer_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, } else { p++; } -/* - data->notify_data.data.length=strlen(lp_servicename(snum)); - dos_PutUniCode(data->notify_data.data.string, lp_servicename(snum), sizeof(data->notify_data.data.string), True); -*/ + data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, p, sizeof(data->notify_data.data.string), True) - sizeof(uint16))/sizeof(uint16)); } @@ -1135,7 +1135,7 @@ static void spoolss_notify_port_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, pri /* even if it's strange, that's consistant in all the code */ data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, - lp_servicename(snum), sizeof(data->notify_data.data.string), True) - sizeof(uint16))/sizeof(uint16)); + printer->info_2->portname, sizeof(data->notify_data.data.string), True) - sizeof(uint16))/sizeof(uint16)); } /******************************************************************* @@ -1239,9 +1239,7 @@ static void spoolss_notify_security_desc(int snum, SPOOL_NOTIFY_INFO_DATA *data, ********************************************************************/ static void spoolss_notify_attributes(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) { - data->notify_data.value[0] = PRINTER_ATTRIBUTE_SHARED \ - | PRINTER_ATTRIBUTE_LOCAL \ - | PRINTER_ATTRIBUTE_RAW_ONLY ; + data->notify_data.value[0] = printer->info_2->attributes; } /******************************************************************* @@ -2614,7 +2612,6 @@ static uint32 getprinter_level_2(int snum, NEW_BUFFER *buffer, uint32 offered, u static uint32 getprinter_level_3(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_3 *printer=NULL; - fstring temp; if (!construct_printer_info_3(&printer, snum)) return ERROR_NOT_ENOUGH_MEMORY; -- cgit From 4bce271e4fe239a8b4aac2bb65a52165d68d8ea5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 14 Nov 2000 21:56:32 +0000 Subject: Merge from appliance head of JR's changes for driver versioning. Jeremy. (This used to be commit cdbd2e99775642dc2e92004be9014bf38a92d80f) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index cd2b4c4e3d..6a3b72ffa7 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4891,7 +4891,7 @@ uint32 _spoolss_addprinterdriver(pipes_struct *p, const UNISTR2 *server_name, convert_printer_driver_info(info, &driver, level); DEBUG(5,("Cleaning driver's information\n")); - if ((err = clean_up_driver_struct(driver, level)) != NT_STATUS_NO_PROBLEMO ) + if ((err = clean_up_driver_struct(driver, level, &user)) != NT_STATUS_NO_PROBLEMO ) goto done; DEBUG(5,("Moving driver to final destination\n")); -- cgit From cdac09614ef426092ed1b1de480fe90c3c4cdd83 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 16 Nov 2000 21:38:24 +0000 Subject: Fix for a problem with the new messaging system. If a sender is using the messaging system as a notification mechanism, and the speed of notification greatly exceeds the speed of message recovery, then you get a massively (>75Mb) growing tdb. If the message is a simple notification, then the message is static, and you only need one of them in transit to a target process at any one time. This patch adds a BOOL "allow_duplicates" to the message_send_XX primitives. If set to False, then before sending a message the sender checks the existing message queue for a target pid for a duplicate of this message, and doesn't add to it if one already exists. Also added code into msgtest.c to test this. Jeremy. (This used to be commit 3aa7995660395ecb85c8e35b638fa9fbbb952558) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 6a3b72ffa7..30acc14904 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -640,7 +640,7 @@ static BOOL srv_spoolss_sendnotify(POLICY_HND *handle) /*srv_spoolss_receive_message(printer);*/ DEBUG(10,("srv_spoolss_sendnotify: Sending message about printer %s\n", printer )); - message_send_all(MSG_PRINTER_NOTIFY, printer, strlen(printer) + 1); /* Null terminate... */ + message_send_all(MSG_PRINTER_NOTIFY, printer, strlen(printer) + 1, False); /* Null terminate... */ return True; } -- cgit From 475fb713a9427b54c747a4e71a011c7db29d5e13 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 17 Nov 2000 02:22:35 +0000 Subject: Fix for memory leak when adding driver. Jeremy. (This used to be commit eeab4e0290f9df84025e91c85d27b21e0c02781f) --- source3/rpc_server/srv_spoolss_nt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 30acc14904..a04c85368f 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -5198,13 +5198,13 @@ uint32 _spoolss_setprinterdata( POLICY_HND *handle, unlink_specific_param_if_exist(printer->info_2, param); - if (!add_a_specific_param(printer->info_2, param)) - status = ERROR_INVALID_PARAMETER; - else - status = mod_a_printer(*printer, 2); + add_a_specific_param(printer->info_2, ¶m); + status = mod_a_printer(*printer, 2); done: free_a_printer(&printer, 2); + if (param) + free_nt_printer_param(¶m); safe_free(old_param.data); return status; -- cgit From ac4d2775618a9ac3428d60bf667e3b968d634799 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 17 Nov 2000 23:10:56 +0000 Subject: Fix from John Reilly for equivalence tests. Jeremy. (This used to be commit b456274a7ba22d512bab5ede979cd9363398825b) --- source3/rpc_server/srv_spoolss_nt.c | 155 ++++++++++++++++++------------------ 1 file changed, 79 insertions(+), 76 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a04c85368f..0fea4a8763 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1,22 +1,22 @@ #define OLD_NTDOMAIN 1 -/* +/* * Unix SMB/Netbios implementation. * Version 1.9. * RPC Pipe client / server routines * Copyright (C) Andrew Tridgell 1992-2000, * Copyright (C) Luke Kenneth Casson Leighton 1996-2000, * Copyright (C) Jean François Micouleau 1998-2000. - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. @@ -57,7 +57,7 @@ typedef struct _Printer{ struct { uint32 flags; uint32 options; - fstring localmachine; + fstring localmachine; uint32 printerlocal; SPOOL_NOTIFY_OPTION *option; POLICY_HND client_hnd; @@ -312,7 +312,7 @@ static BOOL get_printer_snum(POLICY_HND *hnd, int *number) } switch (Printer->printer_type) { - case PRINTER_HANDLE_IS_PRINTER: + case PRINTER_HANDLE_IS_PRINTER: DEBUG(4,("short name:%s\n", Printer->dev.handlename)); *number = print_queue_snum(Printer->dev.handlename); return (*number != -1); @@ -418,7 +418,7 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) printername=strchr(printer->info_2->printername+2, '\\'); printername++; - DEBUG(10,("set_printer_hnd_name: name [%s], aprinter [%s]\n", + DEBUG(10,("set_printer_hnd_name: name [%s], aprinter [%s]\n", printer->info_2->printername, aprinter )); if ( strlen(printername) != strlen(aprinter) ) { @@ -434,7 +434,7 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) found=True; } - /* + /* * if we haven't found a printer with the given handlename * then it can be a share name as you can open both \\server\printer and * \\server\share @@ -458,7 +458,7 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) if (get_a_printer(&printer, 2, lp_servicename(snum))!=0) continue; - DEBUG(10,("set_printer_hnd_name: printername [%s], aprinter [%s]\n", + DEBUG(10,("set_printer_hnd_name: printername [%s], aprinter [%s]\n", printer->info_2->printername, aprinter )); if ( strlen(lp_servicename(snum)) != strlen(aprinter) ) { @@ -562,9 +562,9 @@ static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size) else extra_space = buffer_size - prs_data_size(ps); - /* + /* * save the offset and move to the end of the buffer - * prs_grow() checks the extra_space against the offset + * prs_grow() checks the extra_space against the offset */ old_offset=prs_offset(ps); prs_set_offset(ps, prs_data_size(ps)); @@ -583,7 +583,7 @@ static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size) receive the notify message ****************************************************************************/ void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size_t len) -{ +{ fstring printer; uint32 status; Printer_entry *find_printer; @@ -603,7 +603,7 @@ void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size_t len) /* Iterate the printer list. */ for(; find_printer; find_printer = (Printer_entry *)ubi_dlNext(find_printer)) { - /* + /* * if the entry is the given printer or if it's a printerserver * we send the message */ @@ -711,7 +711,7 @@ static BOOL convert_printer_info(const SPOOL_PRINTER_INFO_LEVEL *uni, NT_PRINTER_INFO_LEVEL *printer, uint32 level) { switch (level) { - case 2: + case 2: uni_2_asc_printer_info_2(uni->info_2, &printer->info_2); break; default: @@ -725,11 +725,11 @@ static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL *u NT_PRINTER_DRIVER_INFO_LEVEL *printer, uint32 level) { switch (level) { - case 3: + case 3: printer->info_3=NULL; uni_2_asc_printer_driver_3(uni->info_3, &printer->info_3); break; - case 6: + case 6: printer->info_6=NULL; uni_2_asc_printer_driver_6(uni->info_6, &printer->info_6); break; @@ -906,7 +906,7 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d GetPrinterData on a printer Handle. ********************************************************************/ static BOOL getprinterdata_printer(POLICY_HND *handle, - fstring value, uint32 *type, + fstring value, uint32 *type, uint8 **data, uint32 *needed, uint32 in_size ) { NT_PRINTER_INFO_LEVEL *printer = NULL; @@ -972,7 +972,7 @@ uint32 _spoolss_getprinterdata(POLICY_HND *handle, UNISTR2 *valuename, BOOL found=False; Printer_entry *Printer = find_printer_index_by_hnd(handle); - /* + /* * Reminder: when it's a string, the length is in BYTES * even if UNICODE is negociated. * @@ -1029,7 +1029,7 @@ static BOOL srv_spoolss_replyopenprinter(char *printer, uint32 localprinter, uin uint32 status; /* - * If it's the first connection, contact the client + * If it's the first connection, contact the client * and connect to the IPC$ share anonumously */ if (smb_connections==0) { @@ -1056,7 +1056,7 @@ static BOOL srv_spoolss_replyopenprinter(char *printer, uint32 localprinter, uin * have to code it, later. * * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe - * called from api_spoolss_rffpcnex + * called from api_spoolss_rffpcnex ********************************************************************/ uint32 _spoolss_rffpcnex(POLICY_HND *handle, uint32 flags, uint32 options, const UNISTR2 *localmachine, uint32 printerlocal, @@ -1078,8 +1078,8 @@ uint32 _spoolss_rffpcnex(POLICY_HND *handle, uint32 flags, uint32 options, unistr2_to_ascii(Printer->notify.localmachine, localmachine, sizeof(Printer->notify.localmachine)-1); /* connect to the client machine and send a ReplyOpenPrinter */ - if(srv_spoolss_replyopenprinter(Printer->notify.localmachine, - Printer->notify.printerlocal, 1, + if(srv_spoolss_replyopenprinter(Printer->notify.localmachine, + Printer->notify.printerlocal, 1, &Printer->notify.client_hnd)) Printer->notify.client_connected=True; @@ -1470,7 +1470,7 @@ struct s_notify_info_data_table notify_info_data_table[] = /******************************************************************* return the size of info_data structure -********************************************************************/ +********************************************************************/ static uint32 size_of_notify_info_data(uint16 type, uint16 field) { int i=0; @@ -1489,7 +1489,7 @@ static uint32 size_of_notify_info_data(uint16 type, uint16 field) /******************************************************************* return the type of notify_info_data -********************************************************************/ +********************************************************************/ static BOOL type_of_notify_info_data(uint16 type, uint16 field) { int i=0; @@ -1550,7 +1550,7 @@ static void construct_info_data(SPOOL_NOTIFY_INFO_DATA *info_data, uint16 type, /******************************************************************* * * fill a notify_info struct with info asked - * + * ********************************************************************/ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPOOL_NOTIFY_OPTION_TYPE *option_type, uint32 id) { @@ -1567,7 +1567,7 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPO type=option_type->type; DEBUGADD(4,("Notify type: [%s], number of notify info: [%d] on printer: [%s]\n", - (option_type->type==PRINTER_NOTIFY_TYPE?"PRINTER_NOTIFY_TYPE":"JOB_NOTIFY_TYPE"), + (option_type->type==PRINTER_NOTIFY_TYPE?"PRINTER_NOTIFY_TYPE":"JOB_NOTIFY_TYPE"), option_type->count, lp_servicename(snum))); if (get_a_printer(&printer, 2, lp_servicename(snum))!=0) @@ -1602,7 +1602,7 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPO /******************************************************************* * * fill a notify_info struct with info asked - * + * ********************************************************************/ static BOOL construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_INFO *info, int snum, SPOOL_NOTIFY_OPTION_TYPE *option_type, uint32 id) { @@ -1618,7 +1618,7 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_I type = option_type->type; DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n", - (option_type->type==PRINTER_NOTIFY_TYPE?"PRINTER_NOTIFY_TYPE":"JOB_NOTIFY_TYPE"), + (option_type->type==PRINTER_NOTIFY_TYPE?"PRINTER_NOTIFY_TYPE":"JOB_NOTIFY_TYPE"), option_type->count)); if (get_a_printer(&printer, 2, lp_servicename(snum))!=0) @@ -1652,7 +1652,7 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_I * the printer's name and the number of jobs currently queued. * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure. * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS. - * + * * I have 3 printers on the back of my server. * * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA @@ -1674,7 +1674,7 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_I * * enumerate all printers on the printserver * fill a notify_info struct with info asked - * + * ********************************************************************/ static uint32 printserver_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info) { @@ -1709,7 +1709,7 @@ static uint32 printserver_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO * /* * Debugging information, don't delete. */ - /* + /* DEBUG(1,("dumping the NOTIFY_INFO\n")); DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count)); DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n")); @@ -1727,7 +1727,7 @@ static uint32 printserver_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO * /******************************************************************* * * fill a notify_info struct with info asked - * + * ********************************************************************/ static uint32 printer_notify_info(POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info) { @@ -1773,7 +1773,7 @@ static uint32 printer_notify_info(POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info) /* * Debugging information, don't delete. */ - /* + /* DEBUG(1,("dumping the NOTIFY_INFO\n")); DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count)); DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n")); @@ -1808,7 +1808,7 @@ uint32 _spoolss_rfnpcnex( POLICY_HND *handle, uint32 change, * b) we'll have a way to communicate between the spoolss process. * * same thing for option->flags - * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as + * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as * I don't have a global notification system, I'm sending back all the * informations even when _NOTHING_ has changed. */ @@ -2032,7 +2032,7 @@ static DEVICEMODE *construct_dev_mode(int snum) devmode->size = ntdevmode->size; devmode->driverextra = ntdevmode->driverextra; devmode->fields = ntdevmode->fields; - + devmode->orientation = ntdevmode->orientation; devmode->papersize = ntdevmode->papersize; devmode->paperlength = ntdevmode->paperlength; @@ -2286,7 +2286,7 @@ static BOOL enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, ui /* JFM: currently it's more a place holder than anything else. * In the spooler world there is a notion of server registration. * the print servers are registring (sp ?) on the PDC (in the same domain) - * + * * We should have a TDB here. The registration is done thru an undocumented RPC call. */ @@ -2479,7 +2479,7 @@ uint32 _spoolss_enumprinters( uint32 flags, const UNISTR2 *servername, uint32 le *returned=0; /* - * Level 1: + * Level 1: * flags==PRINTER_ENUM_NAME * if name=="" then enumerates all printers * if name!="" then enumerate the printer @@ -2802,10 +2802,10 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_IN init_unistr( &info->name, driver.info_3->name ); init_unistr( &info->architecture, driver.info_3->environment ); - snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "\\\\%s%s", servername, driver.info_3->driverpath); + snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "\\\\%s%s", servername, driver.info_3->driverpath); init_unistr( &info->driverpath, temp_driverpath ); - snprintf(temp_datafile, sizeof(temp_datafile)-1, "\\\\%s%s", servername, driver.info_3->datafile); + snprintf(temp_datafile, sizeof(temp_datafile)-1, "\\\\%s%s", servername, driver.info_3->datafile); init_unistr( &info->datafile, temp_datafile ); snprintf(temp_configfile, sizeof(temp_configfile)-1, "\\\\%s%s", servername, driver.info_3->configfile); @@ -2872,10 +2872,10 @@ static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_IN init_unistr( &info->name, driver.info_3->name ); init_unistr( &info->architecture, driver.info_3->environment ); - snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "\\\\%s%s", servername, driver.info_3->driverpath); + snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "\\\\%s%s", servername, driver.info_3->driverpath); init_unistr( &info->driverpath, temp_driverpath ); - snprintf(temp_datafile, sizeof(temp_datafile)-1, "\\\\%s%s", servername, driver.info_3->datafile); + snprintf(temp_datafile, sizeof(temp_datafile)-1, "\\\\%s%s", servername, driver.info_3->datafile); init_unistr( &info->datafile, temp_datafile ); snprintf(temp_configfile, sizeof(temp_configfile)-1, "\\\\%s%s", servername, driver.info_3->configfile); @@ -3108,7 +3108,7 @@ static uint32 getprinterdriver2_level6(fstring servername, fstring architecture, /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_getprinterdriver2(POLICY_HND *handle, const UNISTR2 *uni_arch, uint32 level, +uint32 _spoolss_getprinterdriver2(POLICY_HND *handle, const UNISTR2 *uni_arch, uint32 level, uint32 clientmajorversion, uint32 clientminorversion, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *servermajorversion, uint32 *serverminorversion) @@ -3196,7 +3196,7 @@ static struct current_user *get_current_user(struct current_user *user, pipes_st * ********************************************************************/ uint32 _spoolss_startdocprinter(POLICY_HND *handle, uint32 level, - pipes_struct *p, DOC_INFO *docinfo, + pipes_struct *p, DOC_INFO *docinfo, uint32 *jobid) { DOC_INFO_1 *info_1 = &docinfo->doc_info_1; @@ -3231,7 +3231,7 @@ uint32 _spoolss_startdocprinter(POLICY_HND *handle, uint32 level, (*jobid)=0; return ERROR_INVALID_DATATYPE; } - } + } /* get the share number of the printer */ if (!get_printer_snum(handle, &snum)) { @@ -3293,7 +3293,7 @@ uint32 _spoolss_writeprinter( POLICY_HND *handle, return ERROR_INVALID_HANDLE; } - (*buffer_written) = print_job_write(Printer->jobid, (char *)buffer, + (*buffer_written) = print_job_write(Printer->jobid, (char *)buffer, buffer_size); return 0x0; @@ -3370,7 +3370,7 @@ static uint32 update_printer_sec(POLICY_HND *handle, uint32 level, Printer_entry *Printer = find_printer_index_by_hnd(handle); if (!OPEN_HANDLE(Printer) || !get_printer_snum(handle, &snum)) { - DEBUG(0,("update_printer_sec: Invalid handle (%s)\n", + DEBUG(0,("update_printer_sec: Invalid handle (%s)\n", OUR_HANDLE(handle))); result = ERROR_INVALID_HANDLE; @@ -3398,7 +3398,7 @@ static uint32 update_printer_sec(POLICY_HND *handle, uint32 level, /* Check the user has permissions to change the security descriptor. By experimentation with two NT machines, the user requires Full Access to the printer to change security - information. */ + information. */ if (!print_access_check(&user, snum, PRINTER_ACCESS_ADMINISTER)) { result = ERROR_ACCESS_DENIED; @@ -3427,13 +3427,13 @@ static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) /* we force some elements to "correct" values */ slprintf(info->servername, sizeof(info->servername), "\\\\%s", global_myname); - slprintf(info->printername, sizeof(info->printername), "\\\\%s\\%s", + slprintf(info->printername, sizeof(info->printername), "\\\\%s\\%s", global_myname, lp_servicename(snum)); fstrcpy(info->sharename, lp_servicename(snum)); info->attributes = PRINTER_ATTRIBUTE_SHARED \ | PRINTER_ATTRIBUTE_LOCAL \ | PRINTER_ATTRIBUTE_RAW_ONLY \ - | PRINTER_ATTRIBUTE_QUEUED ; + | PRINTER_ATTRIBUTE_QUEUED ; return True; } @@ -3503,6 +3503,9 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) static BOOL nt_devicemode_equal(NT_DEVICEMODE *d1, NT_DEVICEMODE *d2) { + if (!d1 && !d2) return True; /* if both are NULL they are equal */ + if (!d1 ^ !d2) return False; /* if either is exclusively NULL are not equal */ + if (!strequal(d1->devicename, d2->devicename) || !strequal(d1->formname, d2->formname)) { return False; @@ -3611,7 +3614,7 @@ static BOOL nt_printer_info_level_equal(NT_PRINTER_INFO_LEVEL *p1, return True; } - if ((!p1 && p2) || (p1 && !p2) || + if ((!p1 && p2) || (p1 && !p2) || (!p1->info_2 && p2->info_2) || (p1->info_2 && !p2->info_2)) { return False; @@ -3633,7 +3636,7 @@ static BOOL nt_printer_info_level_equal(NT_PRINTER_INFO_LEVEL *p1, return False; } - /* Yuck - don't check the printername or servername as the + /* Yuck - don't check the printername or servername as the add_a_printer() code plays games with them. You can't change the printername or the sharename through this interface in Samba. */ @@ -3730,7 +3733,7 @@ static uint32 update_printer(POLICY_HND *handle, uint32 level, convert it and link it*/ /* - * Ensure printer->info_2->devmode is a valid pointer + * Ensure printer->info_2->devmode is a valid pointer * as we will be overwriting it in convert_devicemode(). */ @@ -3763,7 +3766,7 @@ static uint32 update_printer(POLICY_HND *handle, uint32 level, goto done; } - /* Check calling user has permission to update printer description */ + /* Check calling user has permission to update printer description */ if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { DEBUG(3, ("printer property change denied by security " @@ -3952,8 +3955,8 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, /**************************************************************************** Enumjobs at level 1. ****************************************************************************/ -static uint32 enumjobs_level1(print_queue_struct *queue, int snum, - NEW_BUFFER *buffer, uint32 offered, +static uint32 enumjobs_level1(print_queue_struct *queue, int snum, + NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { JOB_INFO_1 *info; @@ -3998,8 +4001,8 @@ static uint32 enumjobs_level1(print_queue_struct *queue, int snum, /**************************************************************************** Enumjobs at level 2. ****************************************************************************/ -static uint32 enumjobs_level2(print_queue_struct *queue, int snum, - NEW_BUFFER *buffer, uint32 offered, +static uint32 enumjobs_level2(print_queue_struct *queue, int snum, + NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { JOB_INFO_2 *info; @@ -4044,7 +4047,7 @@ static uint32 enumjobs_level2(print_queue_struct *queue, int snum, /**************************************************************************** Enumjobs. ****************************************************************************/ -uint32 _spoolss_enumjobs( POLICY_HND *handle, uint32 firstjob, uint32 numofjobs, uint32 level, +uint32 _spoolss_enumjobs( POLICY_HND *handle, uint32 firstjob, uint32 numofjobs, uint32 level, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { @@ -4414,8 +4417,8 @@ static void fill_form_1(FORM_1 *form, nt_forms_struct *list) /**************************************************************************** ****************************************************************************/ -uint32 _new_spoolss_enumforms( POLICY_HND *handle, uint32 level, - NEW_BUFFER *buffer, uint32 offered, +uint32 _new_spoolss_enumforms( POLICY_HND *handle, uint32 level, + NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *numofforms) { nt_forms_struct *list=NULL; @@ -4763,8 +4766,8 @@ static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need /**************************************************************************** enumports. ****************************************************************************/ -uint32 _spoolss_enumports( UNISTR2 *name, uint32 level, - NEW_BUFFER *buffer, uint32 offered, +uint32 _spoolss_enumports( UNISTR2 *name, uint32 level, + NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { DEBUG(4,("_spoolss_enumports\n")); @@ -4867,7 +4870,7 @@ uint32 _spoolss_addprinterex( const UNISTR2 *uni_srv_name, uint32 level, /* but I know what to do ... */ return ERROR_INVALID_LEVEL; case 2: - return spoolss_addprinterex_level_2(uni_srv_name, info, + return spoolss_addprinterex_level_2(uni_srv_name, info, unk0, unk1, unk2, unk3, user_switch, user, handle); default: @@ -4961,7 +4964,7 @@ static uint32 getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen /**************************************************************************** ****************************************************************************/ uint32 _spoolss_getprinterdriverdirectory(UNISTR2 *name, UNISTR2 *uni_environment, uint32 level, - NEW_BUFFER *buffer, uint32 offered, + NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { DEBUG(4,("_spoolss_getprinterdriverdirectory\n")); @@ -5022,7 +5025,7 @@ uint32 _spoolss_enumprinterdata(POLICY_HND *handle, uint32 idx, if (get_a_printer(&printer, 2, lp_servicename(snum)) != 0) return ERROR_INVALID_HANDLE; - /* + /* * The NT machine wants to know the biggest size of value and data * * cf: MSDN EnumPrinterData remark section @@ -5087,7 +5090,7 @@ uint32 _spoolss_enumprinterdata(POLICY_HND *handle, uint32 idx, return NT_STATUS_NO_PROBLEMO; } - /* + /* * the value len is wrong in NT sp3 * that's the number of bytes not the number of unicode chars */ @@ -5100,7 +5103,7 @@ uint32 _spoolss_enumprinterdata(POLICY_HND *handle, uint32 idx, free_a_printer(&printer, 2); - /* + /* * the value is: * - counted in bytes in the request * - counted in UNICODE chars in the max reply @@ -5108,7 +5111,7 @@ uint32 _spoolss_enumprinterdata(POLICY_HND *handle, uint32 idx, * * take a pause *before* coding not *during* coding */ - + *out_max_value_len=(in_value_len/sizeof(uint16)); if((*out_value=(uint16 *)malloc(in_value_len*sizeof(uint8))) == NULL) { safe_free(data); @@ -5168,13 +5171,13 @@ uint32 _spoolss_setprinterdata( POLICY_HND *handle, convert_specific_param(¶m, value , type, data, real_len); - /* Check if we are making any changes or not. Return true if + /* Check if we are making any changes or not. Return true if nothing is actually changing. */ ZERO_STRUCT(old_param); if (get_specific_param(*printer, 2, param->value, &old_param.data, - &old_param.type, &old_param.data_len)) { + &old_param.type, (unsigned int *)&old_param.data_len)) { if (param->type == old_param.type && param->data_len == old_param.data_len && @@ -5364,12 +5367,12 @@ static uint32 enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, ui /**************************************************************************** ****************************************************************************/ uint32 _spoolss_enumprintprocessors(UNISTR2 *name, UNISTR2 *environment, uint32 level, - NEW_BUFFER *buffer, uint32 offered, + NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { DEBUG(5,("spoolss_enumprintprocessors\n")); - /* + /* * Enumerate the print processors ... * * Just reply with "winprint", to keep NT happy @@ -5421,7 +5424,7 @@ static uint32 enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered, /**************************************************************************** ****************************************************************************/ uint32 _spoolss_enumprintprocdatatypes(UNISTR2 *name, UNISTR2 *processor, uint32 level, - NEW_BUFFER *buffer, uint32 offered, + NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { DEBUG(5,("_spoolss_enumprintprocdatatypes\n")); @@ -5504,12 +5507,12 @@ static uint32 enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint /**************************************************************************** ****************************************************************************/ uint32 _spoolss_enumprintmonitors(UNISTR2 *name,uint32 level, - NEW_BUFFER *buffer, uint32 offered, + NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { DEBUG(5,("spoolss_enumprintmonitors\n")); - /* + /* * Enumerate the print monitors ... * * Just reply with "Local Port", to keep NT happy @@ -5631,7 +5634,7 @@ static uint32 getjob_level_2(print_queue_struct *queue, int count, int snum, uin /**************************************************************************** ****************************************************************************/ uint32 _spoolss_getjob( POLICY_HND *handle, uint32 jobid, uint32 level, - NEW_BUFFER *buffer, uint32 offered, + NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { int snum; -- cgit From a69a1a87d8f6fece120c423e473b6f67b7a6bb8e Mon Sep 17 00:00:00 2001 From: David O'Neill Date: Wed, 22 Nov 2000 16:19:07 +0000 Subject: Changes from APPLIANCE_HEAD: - Add code to test equivalence of private data in NT_DEVICEMODE (This used to be commit 684981851ffa3b51e78a6fd5960e219823eb90d5) --- source3/rpc_server/srv_spoolss_nt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 0fea4a8763..1ef6a8c11b 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3549,10 +3549,10 @@ static BOOL nt_devicemode_equal(NT_DEVICEMODE *d1, NT_DEVICEMODE *d2) return False; } - /* Not sure what to do about these fields */ -#if 0 - uint8 *private; -#endif + /* compare the private data if it exists */ + if (!d1->driverextra && !d2->driverextra) return True; + if ( d1->driverextra != d2->driverextra) return False; + if (memcmp(d1->private, d2->private, d1->driverextra)) return False; return True; } -- cgit From cf5b71994d6cdb2f81c390579f4a0e676926c6b9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 7 Dec 2000 19:26:04 +0000 Subject: file_lines_load/file_lines_pload can now optionally convert unix_to_dos() on read. Jeremy. (This used to be commit 76b8dd376d13eb4469417be217c966d54d333367) --- source3/rpc_server/srv_spoolss_nt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 1ef6a8c11b..69cb79156b 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3480,7 +3480,7 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) } numlines = 0; - qlines = file_lines_load(tmp_file, &numlines); + qlines = file_lines_load(tmp_file, &numlines, True); DEBUGADD(10,("Lines returned = [%d]\n", numlines)); DEBUGADD(10,("Unlinking port file [%s]\n", tmp_file)); unlink(tmp_file); @@ -4604,7 +4604,7 @@ static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need } numlines = 0; - qlines = file_lines_load(tmp_file, &numlines); + qlines = file_lines_load(tmp_file, &numlines,True); DEBUGADD(10,("Lines returned = [%d]\n", numlines)); DEBUGADD(10,("Unlinking port file [%s]\n", tmp_file)); unlink(tmp_file); @@ -4702,7 +4702,7 @@ static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need } numlines = 0; - qlines = file_lines_load(tmp_file, &numlines); + qlines = file_lines_load(tmp_file, &numlines,True); DEBUGADD(10,("Lines returned = [%d]\n", numlines)); DEBUGADD(10,("Unlinking port file [%s]\n", tmp_file)); unlink(tmp_file); -- cgit From a95ccc27790cb8275f44df76fa6dc33a6a17c12e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 11 Dec 2000 19:24:59 +0000 Subject: Adding in debug for SD's. Jeremy. (This used to be commit a19f936b644fedc4c59ada5f12172abed9894910) --- source3/rpc_server/srv_spoolss_nt.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 69cb79156b..c0ecfefc92 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3384,6 +3384,37 @@ static uint32 update_printer_sec(POLICY_HND *handle, uint32 level, nt_printing_getsec(Printer->dev.handlename, &old_secdesc_ctr); + if (DEBUGLEVEL >= 10) { + SEC_ACL *acl; + int i; + + acl = old_secdesc_ctr->sec->dacl; + DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n", + PRINTERNAME(snum), acl->num_aces)); + + for (i = 0; i < acl->num_aces; i++) { + fstring sid_str; + + sid_to_string(sid_str, &acl->ace[i].sid); + + DEBUG(10, ("%s 0x%08x\n", sid_str, + acl->ace[i].info.mask)); + } + + acl = secdesc_ctr->sec->dacl; + DEBUG(10, ("secdesc_ctr for %s has %d aces:\n", + PRINTERNAME(snum), acl->num_aces)); + + for (i = 0; i < acl->num_aces; i++) { + fstring sid_str; + + sid_to_string(sid_str, &acl->ace[i].sid); + + DEBUG(10, ("%s 0x%08x\n", sid_str, + acl->ace[i].info.mask)); + } + } + new_secdesc_ctr = sec_desc_merge(secdesc_ctr, old_secdesc_ctr); if (sec_desc_equal(new_secdesc_ctr->sec, old_secdesc_ctr->sec)) { -- cgit From 57779c6f3bb469263c195b5eb1afbf4769c00ffb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 14 Dec 2000 18:37:01 +0000 Subject: Updates from appliance-head. Jeremy. (This used to be commit 15ae2c335b52e34c06d8f4f9ebad28078292b208) --- source3/rpc_server/srv_spoolss_nt.c | 55 +++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 8 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index c0ecfefc92..a7614ff640 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3534,11 +3534,16 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) static BOOL nt_devicemode_equal(NT_DEVICEMODE *d1, NT_DEVICEMODE *d2) { - if (!d1 && !d2) return True; /* if both are NULL they are equal */ - if (!d1 ^ !d2) return False; /* if either is exclusively NULL are not equal */ + if (!d1 && !d2) goto equal; /* if both are NULL they are equal */ + + if (!d1 ^ !d2) { + DEBUG(10, ("nt_devicemode_equal(): pointers not equal\n")); + return False; /* if either is exclusively NULL are not equal */ + } if (!strequal(d1->devicename, d2->devicename) || !strequal(d1->formname, d2->formname)) { + DEBUG(10, ("nt_devicemode_equal(): device,form not equal\n")); return False; } @@ -3560,6 +3565,8 @@ static BOOL nt_devicemode_equal(NT_DEVICEMODE *d1, NT_DEVICEMODE *d2) d1->ttoption != d2->ttoption || d1->collate != d2->collate || d1->logpixels != d2->logpixels) { + DEBUG(10, ("nt_devicemode_equal(): specversion-logpixels " + "not equal\n")); return False; } @@ -3577,14 +3584,26 @@ static BOOL nt_devicemode_equal(NT_DEVICEMODE *d1, NT_DEVICEMODE *d2) d1->reserved2 != d2->reserved2 || d1->panningwidth != d2->panningwidth || d1->panningheight != d2->panningheight) { + DEBUG(10, ("nt_devicemode_equal(): fields-panningheight " + "not equal\n")); return False; } /* compare the private data if it exists */ - if (!d1->driverextra && !d2->driverextra) return True; - if ( d1->driverextra != d2->driverextra) return False; - if (memcmp(d1->private, d2->private, d1->driverextra)) return False; + if (!d1->driverextra && !d2->driverextra) goto equal; + + if (d1->driverextra != d2->driverextra) { + DEBUG(10, ("nt_devicemode_equal(): driverextra not equal\n")); + return False; + } + + if (memcmp(d1->private, d2->private, d1->driverextra)) { + DEBUG(10, ("nt_devicemode_equal(): private data not equal\n")); + return False; + } + equal: + DEBUG(10, ("nt_devicemode_equal(): devicemodes identical\n")); return True; } @@ -3593,9 +3612,12 @@ static BOOL nt_devicemode_equal(NT_DEVICEMODE *d1, NT_DEVICEMODE *d2) static BOOL nt_printer_param_equal(NT_PRINTER_PARAM *p1, NT_PRINTER_PARAM *p2) { - if (!p1 && !p2) return True; + if (!p1 && !p2) goto equal; - if ((!p1 && p2) || (p1 && !p2)) return False; + if ((!p1 && p2) || (p1 && !p2)) { + DEBUG(10, ("nt_printer_param_equal(): pointers differ\n")); + return False; + } /* Compare lists of printer parameters */ @@ -3620,12 +3642,17 @@ static BOOL nt_printer_param_equal(NT_PRINTER_PARAM *p1, found_it: if (!found) { + DEBUG(10, ("nt_printer_param_equal(): param %s " + "differs\n", p1->value)); return False; } p1 = p1->next; } + equal: + + DEBUG(10, ("nt_printer_param_equal(): printer params identical\n")); return True; } @@ -3642,12 +3669,14 @@ static BOOL nt_printer_info_level_equal(NT_PRINTER_INFO_LEVEL *p1, /* Trivial conditions */ if ((!p1 && !p2) || (!p1->info_2 && !p2->info_2)) { - return True; + goto equal; } if ((!p1 && p2) || (p1 && !p2) || (!p1->info_2 && p2->info_2) || (p1->info_2 && !p2->info_2)) { + DEBUG(10, ("nt_printer_info_level_equal(): info levels " + "differ\n")); return False; } @@ -3664,6 +3693,8 @@ static BOOL nt_printer_info_level_equal(NT_PRINTER_INFO_LEVEL *p1, pi1->starttime != pi2->starttime || pi1->untiltime != pi2->untiltime || pi1->averageppm != pi2->averageppm) { + DEBUG(10, ("nt_printer_info_level_equal(): attr-ppm values " + "differ\n")); return False; } @@ -3677,6 +3708,8 @@ static BOOL nt_printer_info_level_equal(NT_PRINTER_INFO_LEVEL *p1, !strequal(pi1->drivername, pi2->drivername) || !strequal(pi1->comment, pi2->comment) || !strequal(pi1->location, pi2->location)) { + DEBUG(10, ("nt_printer_info_level_equal(): values for names " + "differ\n")); return False; } @@ -3688,6 +3721,8 @@ static BOOL nt_printer_info_level_equal(NT_PRINTER_INFO_LEVEL *p1, !strequal(pi1->printprocessor, pi2->printprocessor) || !strequal(pi1->datatype, pi2->datatype) || !strequal(pi1->parameters, pi2->parameters)) { + DEBUG(10, ("nt_printer_info_level_equal(): sep-params values " + "differ\n")); return False; } @@ -3702,9 +3737,13 @@ static BOOL nt_printer_info_level_equal(NT_PRINTER_INFO_LEVEL *p1, if (pi1->changeid != pi2->changeid || pi1->c_setprinter != pi2->c_setprinter || pi1->setuptime != pi2->setuptime) { + DEBUG(10, ("nt_printer_info_level_equal(): id-setuptime " + "values differ\n")); return False; } + equal: + DEBUG(10, ("nt_printer_info_level_equal(): infos are identical\n")); return True; } -- cgit From 369f5fd1d7a6e6298bc3cbe01e3aaed0106f6cf4 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 15 Dec 2000 01:02:11 +0000 Subject: Fixed memory leaks in lsa_XX calls. Fixed memory leaks in smbcacls. Merged in fixes from appliance-head and 2.2. Fixed multiple connection.tdb open problem. Jeremy. (This used to be commit 0a40bc83e14c69a09948ec09bb6fc5026c4f4c14) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a7614ff640..b43501a56b 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -640,7 +640,7 @@ static BOOL srv_spoolss_sendnotify(POLICY_HND *handle) /*srv_spoolss_receive_message(printer);*/ DEBUG(10,("srv_spoolss_sendnotify: Sending message about printer %s\n", printer )); - message_send_all(MSG_PRINTER_NOTIFY, printer, strlen(printer) + 1, False); /* Null terminate... */ + message_send_all(conn_tdb_ctx(), MSG_PRINTER_NOTIFY, printer, strlen(printer) + 1, False); /* Null terminate... */ return True; } -- cgit From a18ade3fe0e823ceb83de2078f8f7e23e6c4fcf2 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 15 Dec 2000 01:47:37 +0000 Subject: Fixed memory leak in JOB_INFO_2 code. Jeremy. (This used to be commit d0d31eead3367485bbac684d881839029010975d) --- source3/rpc_server/srv_spoolss_nt.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index b43501a56b..c2054143b7 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4104,7 +4104,7 @@ static uint32 enumjobs_level2(print_queue_struct *queue, int snum, new_smb_io_job_info_2("", buffer, &info[i], 0); /* clear memory */ - safe_free(info); + free_job_info_2(info); if (*needed > offered) { *returned=0; @@ -5692,8 +5692,7 @@ static uint32 getjob_level_2(print_queue_struct *queue, int count, int snum, uin new_smb_io_job_info_2("", buffer, info_2, 0); - free_dev_mode(info_2->devmode); - safe_free(info_2); + free_job_info_2(info_2); if (*needed > offered) return ERROR_INSUFFICIENT_BUFFER; -- cgit From 89af6fd745a6f49668bae5b5c2d239d3671fb299 Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Fri, 15 Dec 2000 09:31:56 +0000 Subject: lib/util_unistr.c: rewrote unistr2_to_ascii() to correct a bug seen on SGI boxes. rpc_parse/parse_misc.c: rpc_parse/parse_prs.c: rewrote of BUFFER5 handling to NOT byteswap when it was already in network byte order. rpc_parse/parse_samr.c: cleanup of samr_io_q_lookup_domain(), remove the over-parsing by 2 bytes. rpc_server/srv_lsa.c: UNISTR2 strings need to be NULL terminated to pleased W2K. rpc_server/srv_spoolss_nt.c: use snprintf instead of safe_strcpy as we want the string truncated at 32 chars. That should fix SUN and SGI box not able to act as printserver and the problem with joining from a W2K wks. J.F. (This used to be commit 69fe739303b105f2c488f266f13977da1b6b201d) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index c2054143b7..a4f5e257f1 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2021,7 +2021,7 @@ static DEVICEMODE *construct_dev_mode(int snum) DEBUGADD(8,("loading DEVICEMODE\n")); - safe_strcpy(adevice, printer->info_2->printername, sizeof(adevice)); + snprintf(adevice, sizeof(adevice), printer->info_2->printername); init_unistr(&devmode->devicename, adevice); snprintf(aform, sizeof(aform), ntdevmode->formname); -- cgit From 452102deb4b8aecb45569239685ec73e2e9282ec Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 18 Dec 2000 06:02:31 +0000 Subject: Merged Tim's fixes from appliance-head. Jeremy. (This used to be commit 26f873540c2299600cb80eb059fcdaf70ec82473) --- source3/rpc_server/srv_spoolss_nt.c | 208 ++++++++++++++++++++---------------- 1 file changed, 113 insertions(+), 95 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a4f5e257f1..38a4b26a60 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3402,16 +3402,21 @@ static uint32 update_printer_sec(POLICY_HND *handle, uint32 level, } acl = secdesc_ctr->sec->dacl; - DEBUG(10, ("secdesc_ctr for %s has %d aces:\n", - PRINTERNAME(snum), acl->num_aces)); - for (i = 0; i < acl->num_aces; i++) { - fstring sid_str; - - sid_to_string(sid_str, &acl->ace[i].sid); + if (acl) { + DEBUG(10, ("secdesc_ctr for %s has %d aces:\n", + PRINTERNAME(snum), acl->num_aces)); - DEBUG(10, ("%s 0x%08x\n", sid_str, - acl->ace[i].info.mask)); + for (i = 0; i < acl->num_aces; i++) { + fstring sid_str; + + sid_to_string(sid_str, &acl->ace[i].sid); + + DEBUG(10, ("%s 0x%08x\n", sid_str, + acl->ace[i].info.mask)); + } + } else { + DEBUG(10, ("dacl for secdesc_ctr is NULL\n")); } } @@ -3532,6 +3537,13 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) /* Return true if two devicemodes are equal */ +#define DEVMODE_CHECK_INT(field) \ + if (d1->field != d2->field) { \ + DEBUG(10, ("nt_devicemode_equal(): " #field " not equal (%d != %d)\n", \ + d1->field, d2->field)); \ + return False; \ + } + static BOOL nt_devicemode_equal(NT_DEVICEMODE *d1, NT_DEVICEMODE *d2) { if (!d1 && !d2) goto equal; /* if both are NULL they are equal */ @@ -3547,55 +3559,44 @@ static BOOL nt_devicemode_equal(NT_DEVICEMODE *d1, NT_DEVICEMODE *d2) return False; } - if (d1->specversion != d2->specversion || - d1->driverversion != d2->driverversion || - d1->size != d2->size || - d1->driverextra != d2->driverextra || - d1->orientation != d2->orientation || - d1->papersize != d2->papersize || - d1->paperlength != d2->paperlength || - d1->paperwidth != d2->paperwidth || - d1->scale != d2->scale || - d1->copies != d2->copies || - d1->defaultsource != d2->defaultsource || - d1->printquality != d2->printquality || - d1->color != d2->color || - d1->duplex != d2->duplex || - d1->yresolution != d2->yresolution || - d1->ttoption != d2->ttoption || - d1->collate != d2->collate || - d1->logpixels != d2->logpixels) { - DEBUG(10, ("nt_devicemode_equal(): specversion-logpixels " - "not equal\n")); - return False; - } - - if (d1->fields != d2->fields || - d1->bitsperpel != d2->bitsperpel || - d1->pelswidth != d2->pelswidth || - d1->pelsheight != d2->pelsheight || - d1->displayflags != d2->displayflags || - d1->displayfrequency != d2->displayfrequency || - d1->icmmethod != d2->icmmethod || - d1->icmintent != d2->icmintent || - d1->mediatype != d2->mediatype || - d1->dithertype != d2->dithertype || - d1->reserved1 != d2->reserved1 || - d1->reserved2 != d2->reserved2 || - d1->panningwidth != d2->panningwidth || - d1->panningheight != d2->panningheight) { - DEBUG(10, ("nt_devicemode_equal(): fields-panningheight " - "not equal\n")); - return False; - } + DEVMODE_CHECK_INT(specversion); + DEVMODE_CHECK_INT(driverversion); + DEVMODE_CHECK_INT(driverextra); + DEVMODE_CHECK_INT(orientation); + DEVMODE_CHECK_INT(papersize); + DEVMODE_CHECK_INT(paperlength); + DEVMODE_CHECK_INT(paperwidth); + DEVMODE_CHECK_INT(scale); + DEVMODE_CHECK_INT(copies); + DEVMODE_CHECK_INT(defaultsource); + DEVMODE_CHECK_INT(printquality); + DEVMODE_CHECK_INT(color); + DEVMODE_CHECK_INT(duplex); + DEVMODE_CHECK_INT(yresolution); + DEVMODE_CHECK_INT(ttoption); + DEVMODE_CHECK_INT(collate); + DEVMODE_CHECK_INT(logpixels); + + DEVMODE_CHECK_INT(fields); + DEVMODE_CHECK_INT(bitsperpel); + DEVMODE_CHECK_INT(pelswidth); + DEVMODE_CHECK_INT(pelsheight); + DEVMODE_CHECK_INT(displayflags); + DEVMODE_CHECK_INT(displayfrequency); + DEVMODE_CHECK_INT(icmmethod); + DEVMODE_CHECK_INT(icmintent); + DEVMODE_CHECK_INT(mediatype); + DEVMODE_CHECK_INT(dithertype); + DEVMODE_CHECK_INT(reserved1); + DEVMODE_CHECK_INT(reserved2); + DEVMODE_CHECK_INT(panningwidth); + DEVMODE_CHECK_INT(panningheight); /* compare the private data if it exists */ if (!d1->driverextra && !d2->driverextra) goto equal; - if (d1->driverextra != d2->driverextra) { - DEBUG(10, ("nt_devicemode_equal(): driverextra not equal\n")); - return False; - } + + DEVMODE_CHECK_INT(driverextra); if (memcmp(d1->private, d2->private, d1->driverextra)) { DEBUG(10, ("nt_devicemode_equal(): private data not equal\n")); @@ -3629,21 +3630,40 @@ static BOOL nt_printer_param_equal(NT_PRINTER_PARAM *p1, while(q) { - if (strequal(p1->value, q->value) && - p1->type == q->type && - p1->data_len == q->data_len && - memcmp(p1->data, q->data, p1->data_len) == 0) { - found = True; - goto found_it; + if (strequal(p1->value, q->value)) { + + if (p1->type != q->type) { + DEBUG(10, ("nt_printer_param_equal():" + "types for %s differ (%d != %d)\n", + p1->value, p1->type, + q->type)); + break; + } + + if (p1->data_len != q->data_len) { + DEBUG(10, ("nt_printer_param_equal():" + "len for %s differs (%d != %d)\n", + p1->value, p1->data_len, + q->data_len)); + break; + } + + if (memcmp(p1->data, q->data, p1->data_len) == 0) { + found = True; + } else { + DEBUG(10, ("nt_printer_param_equal():" + "data for %s differs\n", p1->value)); + } + + break; } q = q->next; } - found_it: if (!found) { DEBUG(10, ("nt_printer_param_equal(): param %s " - "differs\n", p1->value)); + "does not exist\n", p1->value)); return False; } @@ -3661,6 +3681,20 @@ static BOOL nt_printer_param_equal(NT_PRINTER_PARAM *p1, * actually update printer info. ********************************************************************/ +#define PI_CHECK_INT(field) \ + if (pi1->field != pi2->field) { \ + DEBUG(10, ("nt_printer_info_level_equal(): " #field " not equal (%d != %d)\n", \ + pi1->field, pi2->field)); \ + return False; \ + } + +#define PI_CHECK_STR(field) \ + if (!strequal(pi1->field, pi2->field)) { \ + DEBUG(10, ("nt_printer_info_level_equal(): " #field " not equal (%s != %s)\n", \ + pi1->field, pi2->field)); \ + return False; \ + } + static BOOL nt_printer_info_level_equal(NT_PRINTER_INFO_LEVEL *p1, NT_PRINTER_INFO_LEVEL *p2) { @@ -3687,44 +3721,32 @@ static BOOL nt_printer_info_level_equal(NT_PRINTER_INFO_LEVEL *p1, pi1 = p1->info_2; pi2 = p2->info_2; - if (pi1->attributes != pi2->attributes || - pi1->priority != pi2->priority || - pi1->default_priority != pi2->default_priority || - pi1->starttime != pi2->starttime || - pi1->untiltime != pi2->untiltime || - pi1->averageppm != pi2->averageppm) { - DEBUG(10, ("nt_printer_info_level_equal(): attr-ppm values " - "differ\n")); - return False; - } + PI_CHECK_INT(attributes); + PI_CHECK_INT(priority); + PI_CHECK_INT(default_priority); + PI_CHECK_INT(starttime); + PI_CHECK_INT(untiltime); + PI_CHECK_INT(averageppm); /* Yuck - don't check the printername or servername as the add_a_printer() code plays games with them. You can't change the printername or the sharename through this interface in Samba. */ - if (!strequal(pi1->sharename, pi2->sharename) || - !strequal(pi1->portname, pi2->portname) || - !strequal(pi1->drivername, pi2->drivername) || - !strequal(pi1->comment, pi2->comment) || - !strequal(pi1->location, pi2->location)) { - DEBUG(10, ("nt_printer_info_level_equal(): values for names " - "differ\n")); - return False; - } + PI_CHECK_STR(sharename); + PI_CHECK_STR(portname); + PI_CHECK_STR(drivername); + PI_CHECK_STR(comment); + PI_CHECK_STR(location); if (!nt_devicemode_equal(pi1->devmode, pi2->devmode)) { return False; } - if (!strequal(pi1->sepfile, pi2->sepfile) || - !strequal(pi1->printprocessor, pi2->printprocessor) || - !strequal(pi1->datatype, pi2->datatype) || - !strequal(pi1->parameters, pi2->parameters)) { - DEBUG(10, ("nt_printer_info_level_equal(): sep-params values " - "differ\n")); - return False; - } + PI_CHECK_STR(sepfile); + PI_CHECK_STR(printprocessor); + PI_CHECK_STR(datatype); + PI_CHECK_STR(parameters); if (!nt_printer_param_equal(pi1->specific, pi2->specific)) { return False; @@ -3734,13 +3756,9 @@ static BOOL nt_printer_info_level_equal(NT_PRINTER_INFO_LEVEL *p1, return False; } - if (pi1->changeid != pi2->changeid || - pi1->c_setprinter != pi2->c_setprinter || - pi1->setuptime != pi2->setuptime) { - DEBUG(10, ("nt_printer_info_level_equal(): id-setuptime " - "values differ\n")); - return False; - } + PI_CHECK_INT(changeid); + PI_CHECK_INT(c_setprinter); + PI_CHECK_INT(setuptime); equal: DEBUG(10, ("nt_printer_info_level_equal(): infos are identical\n")); -- cgit From 21f0dc985ae2d6c3ef85bcca34f07d216f51b692 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 21 Dec 2000 23:23:34 +0000 Subject: merge from appliance head (This used to be commit 4671a313775f052ae949ba441db7e0060bed0b75) --- source3/rpc_server/srv_spoolss_nt.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 38a4b26a60..cd67a3b88a 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -779,13 +779,16 @@ static BOOL convert_devicemode(const DEVICEMODE *devmode, NT_DEVICEMODE *nt_devm nt_devmode->panningwidth=devmode->panningwidth; nt_devmode->panningheight=devmode->panningheight; + safe_free(nt_devmode->private); if (nt_devmode->driverextra != 0) { /* if we had a previous private delete it and make a new one */ - safe_free(nt_devmode->private); if((nt_devmode->private=(uint8 *)malloc(nt_devmode->driverextra * sizeof(uint8))) == NULL) return False; memcpy(nt_devmode->private, devmode->private, nt_devmode->driverextra); } + else { + nt_devmode->private = NULL; + } return True; } -- cgit From 85b1953f6dfb8a8219da1b4ee75ba22982853ffb Mon Sep 17 00:00:00 2001 From: David O'Neill Date: Fri, 5 Jan 2001 19:01:11 +0000 Subject: Changes from APPLIANCE_HEAD: source/rpc_server/srv_spoolss_nt.c - fixed printer policy handle leak in the allow MS printer wizard stuff. - mimic behaviour of NT on open_printer_ex() calls by not allowing call to succeed if connecting user doesn't have at least print permissions to the printer. Unfortunately, this seems to trigger a anonymous connection re-using bug so subsequent connects to the printer by a different user from the same machine always fail. Blame Tim. =^) (This used to be commit 33fc7f4527c34b39b1a0f3fee2f0697ea74f79c4) --- source3/rpc_server/srv_spoolss_nt.c | 57 ++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 10 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index cd67a3b88a..bcd9b46256 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -655,10 +655,16 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, uint32 user_switch, SPOOL_USER_CTR user_ctr, POLICY_HND *handle) { + uint32 result = NT_STATUS_NO_PROBLEMO; + SEC_DESC_BUF *sec_desc = NULL; + uint32 acc_granted, status; fstring name; + extern struct current_user current_user; - if (printername == NULL) - return ERROR_INVALID_PRINTER_NAME; + if (printername == NULL) { + result = ERROR_INVALID_PRINTER_NAME; + goto done; + } /* some sanity check because you can open a printer or a print server */ /* aka: \\server\printer or \\server */ @@ -666,8 +672,10 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, DEBUGADD(3,("checking name: %s\n",name)); - if (!open_printer_hnd(handle, name)) - return ERROR_INVALID_PRINTER_NAME; + if (!open_printer_hnd(handle, name)) { + result = ERROR_INVALID_PRINTER_NAME; + goto done; + } /* if (printer_default->datatype_ptr != NULL) @@ -681,7 +689,8 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, if (!set_printer_hnd_accesstype(handle, printer_default->access_required)) { close_printer_handle(handle); - return ERROR_ACCESS_DENIED; + result = ERROR_ACCESS_DENIED; + goto done; } /* Disallow MS AddPrinterWizard if parameter disables it. A Win2k @@ -696,13 +705,41 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, if (handle_is_printserver(handle) && !lp_ms_add_printer_wizard()) { - if (printer_default->access_required == 0) - return NT_STATUS_NO_PROBLEMO; - else if (printer_default->access_required != (SERVER_READ)) - return ERROR_ACCESS_DENIED; + if (printer_default->access_required == 0) { + goto done; + } + else if (printer_default->access_required != (SERVER_READ)) { + close_printer_handle(handle); + result = ERROR_ACCESS_DENIED; + goto done; + } } - return NT_STATUS_NO_PROBLEMO; + /* NT doesn't let us connect to a printer if the connecting user + doesn't have print permission. If no security descriptor just + return OK. */ + + if (!nt_printing_getsec(name, &sec_desc)) { + goto done; + } + + /* Yuck - we should use the pipe_user rather than current_user but + it doesn't seem to be filled in correctly. )-: */ + + map_printer_permissions(sec_desc->sec); + + if (!se_access_check(sec_desc->sec, ¤t_user, PRINTER_ACCESS_USE, + &acc_granted, &status)) { + DEBUG(3, ("access DENIED for printer open\n")); + close_printer_handle(handle); + result = ERROR_ACCESS_DENIED; + goto done; + } + + done: + free_sec_desc_buf(&sec_desc); + + return result; } /**************************************************************************** -- cgit From ab60974082e1dea0280eb4c80a48f900c0b55995 Mon Sep 17 00:00:00 2001 From: David O'Neill Date: Mon, 8 Jan 2001 19:58:30 +0000 Subject: Changes merged from APPLIANCE_HEAD: source/printing/printing.c source/rpc_server/srv_spoolss_nt.c - convert args for print command to unix codepage. (This used to be commit 1c0ae957f8f1abee7d22a18b6df092eb2a884ae1) --- source3/rpc_server/srv_spoolss_nt.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index bcd9b46256..74cc19eee1 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3546,6 +3546,9 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) printer->info_2->location, driverlocation); unlink(tmp_file); + + /* Convert script args to unix-codepage */ + dos_to_unix(command, True); DEBUG(10,("Running [%s > %s]\n", command,tmp_file)); ret = smbrun(command, tmp_file, False); DEBUGADD(10,("returned [%d]\n", ret)); @@ -3556,9 +3559,10 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) } numlines = 0; + /* Get lines and convert them back to dos-codepage */ qlines = file_lines_load(tmp_file, &numlines, True); DEBUGADD(10,("Lines returned = [%d]\n", numlines)); - DEBUGADD(10,("Unlinking port file [%s]\n", tmp_file)); + DEBUGADD(10,("Unlinking script output file [%s]\n", tmp_file)); unlink(tmp_file); if(numlines) { -- cgit From 3380ffae9c231a34406dd694c9ab03bb0b6d8070 Mon Sep 17 00:00:00 2001 From: David O'Neill Date: Thu, 11 Jan 2001 20:41:19 +0000 Subject: Changes from APPLIANCE_HEAD: testsuite/printing/psec.c - Use lock directory from smb.conf parameter when peeking at the ntdrivers.tdb file. source/rpc_parse/parse_sec.c - fix typo in debug message source/script/installbin.sh - create private directory as part of 'make install'. source/nsswitch/winbindd_cache.c source/nsswitch/winbindd_idmap.c source/passdb/secrets.c source/smbd/connection.c - always convert tdb key to unix code-page when generating. source/printing/nt_printing.c - always convert tdb key to unix code-page when generating. - don't prepend path to a filename that is NULL in add_a_printer_driver_3(). source/rpc_server/srv_spoolss_nt.c - always convert tdb key to unix code-page when generating. - don't prepend server name to a path/filename that is NULL in the fill_printer_driver_info functions. source/printing/printing.c - always convert tdb key to unix code-page when generating. - move access check for print_queue_purge() outside of job delete loop. source/smbd/unix_acls.c - fix for setting ACLs (this got missed earlier) source/lib/messages.c - trivial sync with appliance_head (This used to be commit 376601d17d53ef7bfaafa576bd770e554516e808) --- source3/rpc_server/srv_spoolss_nt.c | 112 ++++++++++++++++++++++-------------- 1 file changed, 69 insertions(+), 43 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 74cc19eee1..23f8ab15ef 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2740,23 +2740,31 @@ static uint32 construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, fst ********************************************************************/ static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername) { - pstring temp_driverpath; - pstring temp_datafile; - pstring temp_configfile; + pstring temp; info->version=driver.info_3->cversion; init_unistr( &info->name, driver.info_3->name ); init_unistr( &info->architecture, driver.info_3->environment ); - snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "\\\\%s%s", servername, driver.info_3->driverpath); - init_unistr( &info->driverpath, temp_driverpath ); - snprintf(temp_datafile, sizeof(temp_datafile)-1, "\\\\%s%s", servername, driver.info_3->datafile); - init_unistr( &info->datafile, temp_datafile ); + if (strlen(driver.info_3->driverpath)) { + snprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->driverpath); + init_unistr( &info->driverpath, temp ); + } else + init_unistr( &info->driverpath, "" ); - snprintf(temp_configfile, sizeof(temp_configfile)-1, "\\\\%s%s", servername, driver.info_3->configfile); - init_unistr( &info->configfile, temp_configfile ); + if (strlen(driver.info_3->datafile)) { + snprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->datafile); + init_unistr( &info->datafile, temp ); + } else + init_unistr( &info->datafile, "" ); + + if (strlen(driver.info_3->configfile)) { + snprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->configfile); + init_unistr( &info->configfile, temp ); + } else + init_unistr( &info->configfile, "" ); } /******************************************************************** @@ -2830,10 +2838,7 @@ static void init_unistr_array(uint16 **uni_array, fstring *char_array, char *ser ********************************************************************/ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername) { - pstring temp_driverpath; - pstring temp_datafile; - pstring temp_configfile; - pstring temp_helpfile; + pstring temp; ZERO_STRUCTP(info); @@ -2842,17 +2847,29 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_IN init_unistr( &info->name, driver.info_3->name ); init_unistr( &info->architecture, driver.info_3->environment ); - snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "\\\\%s%s", servername, driver.info_3->driverpath); - init_unistr( &info->driverpath, temp_driverpath ); - - snprintf(temp_datafile, sizeof(temp_datafile)-1, "\\\\%s%s", servername, driver.info_3->datafile); - init_unistr( &info->datafile, temp_datafile ); - - snprintf(temp_configfile, sizeof(temp_configfile)-1, "\\\\%s%s", servername, driver.info_3->configfile); - init_unistr( &info->configfile, temp_configfile ); - - snprintf(temp_helpfile, sizeof(temp_helpfile)-1, "\\\\%s%s", servername, driver.info_3->helpfile); - init_unistr( &info->helpfile, temp_helpfile ); + if (strlen(driver.info_3->driverpath)) { + snprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->driverpath); + init_unistr( &info->driverpath, temp ); + } else + init_unistr( &info->driverpath, "" ); + + if (strlen(driver.info_3->datafile)) { + snprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->datafile); + init_unistr( &info->datafile, temp ); + } else + init_unistr( &info->datafile, "" ); + + if (strlen(driver.info_3->configfile)) { + snprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->configfile); + init_unistr( &info->configfile, temp ); + } else + init_unistr( &info->configfile, "" ); + + if (strlen(driver.info_3->helpfile)) { + snprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->helpfile); + init_unistr( &info->helpfile, temp ); + } else + init_unistr( &info->helpfile, "" ); init_unistr( &info->monitorname, driver.info_3->monitorname ); init_unistr( &info->defaultdatatype, driver.info_3->defaultdatatype ); @@ -2898,10 +2915,7 @@ static uint32 construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fst static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername) { - pstring temp_driverpath; - pstring temp_datafile; - pstring temp_configfile; - pstring temp_helpfile; + pstring temp; fstring nullstr; ZERO_STRUCTP(info); @@ -2912,18 +2926,30 @@ static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_IN init_unistr( &info->name, driver.info_3->name ); init_unistr( &info->architecture, driver.info_3->environment ); - snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "\\\\%s%s", servername, driver.info_3->driverpath); - init_unistr( &info->driverpath, temp_driverpath ); - - snprintf(temp_datafile, sizeof(temp_datafile)-1, "\\\\%s%s", servername, driver.info_3->datafile); - init_unistr( &info->datafile, temp_datafile ); - - snprintf(temp_configfile, sizeof(temp_configfile)-1, "\\\\%s%s", servername, driver.info_3->configfile); - init_unistr( &info->configfile, temp_configfile ); - - snprintf(temp_helpfile, sizeof(temp_helpfile)-1, "\\\\%s%s", servername, driver.info_3->helpfile); - init_unistr( &info->helpfile, temp_helpfile ); - + if (strlen(driver.info_3->driverpath)) { + snprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->driverpath); + init_unistr( &info->driverpath, temp ); + } else + init_unistr( &info->driverpath, "" ); + + if (strlen(driver.info_3->datafile)) { + snprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->datafile); + init_unistr( &info->datafile, temp ); + } else + init_unistr( &info->datafile, "" ); + + if (strlen(driver.info_3->configfile)) { + snprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->configfile); + init_unistr( &info->configfile, temp ); + } else + init_unistr( &info->configfile, "" ); + + if (strlen(driver.info_3->helpfile)) { + snprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->helpfile); + init_unistr( &info->helpfile, temp ); + } else + init_unistr( &info->helpfile, "" ); + init_unistr( &info->monitorname, driver.info_3->monitorname ); init_unistr( &info->defaultdatatype, driver.info_3->defaultdatatype ); @@ -3547,8 +3573,8 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) unlink(tmp_file); - /* Convert script args to unix-codepage */ - dos_to_unix(command, True); + /* Convert script args to unix-codepage */ + dos_to_unix(command, True); DEBUG(10,("Running [%s > %s]\n", command,tmp_file)); ret = smbrun(command, tmp_file, False); DEBUGADD(10,("returned [%d]\n", ret)); @@ -3559,7 +3585,7 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) } numlines = 0; - /* Get lines and convert them back to dos-codepage */ + /* Get lines and convert them back to dos-codepage */ qlines = file_lines_load(tmp_file, &numlines, True); DEBUGADD(10,("Lines returned = [%d]\n", numlines)); DEBUGADD(10,("Unlinking script output file [%s]\n", tmp_file)); -- cgit From 27922c0430bf28dca910d2a2903cf410a4187643 Mon Sep 17 00:00:00 2001 From: David O'Neill Date: Mon, 15 Jan 2001 18:36:50 +0000 Subject: Changes from APPLIANCE_HEAD: source/rpc_parse/parse_lsa.c - off by one unistr length bug in init_lsa_trans_name() source/lib/util_sid.c - resolve more BUILTIN sid values to names. source/nsswitch/wb_client.c - fix typo in debug message - set errno on error so we don't get bogus value from last failure. source/rpc_server/srv_spoolss_nt.c - add debug to track number of open printer handles for ease of tracking handle leaks in the future. source/rpc_server/srv_lsa.c - fix off-by-one string bug. This was preventing NT from displaying names for well-know SIDs in printer permissions dialog. (This used to be commit 59229b9025cff54cbdd05e374616ffbf9c6fee33) --- source3/rpc_server/srv_spoolss_nt.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 23f8ab15ef..4355e2eb59 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -526,6 +526,8 @@ static BOOL open_printer_hnd(POLICY_HND *hnd, char *name) return False; } + DEBUG(5, ("%d printer handles active\n", ubi_dlCount(&Printer_list))); + return True; } -- cgit From 792ca5d98938c3c52ff4e598bcb55056565dc202 Mon Sep 17 00:00:00 2001 From: David O'Neill Date: Wed, 17 Jan 2001 18:47:46 +0000 Subject: Changes from APPLIANCE_HEAD: source/rpc_server/srv_spoolss_nt.c - Unrolled construct_notify_jobs_info() loop to only fetch printer info_2 structure once rather than num_print_jobs times. - convert command to unix codepage. - remove lp_remove_service() call as it prevents lp_killservice() from working. - Modified some DEBUG and DEBUGADD statements. source/param/loadparm.c source/param/params.c - change printer, preload, auto services to FLAG_DOS_STRING, reverted earlier changes to szPrintername et al, add comments. source/printing/load.c - fix bug with lp_auto_services() and strtok() source/printing/nt_printing.c source/printing/printing.c - remove redundant test that used SERVICE(snum) source/printing/pcap.c - add unix_to_dos() calls, add notes wrt FIXMEs for xxx_printer_fn() functions. source/web/swat.c - added FIXME comment. source/smbd/service.c - added comment re: dos codepage (This used to be commit 7b774b72c2857af9519012106714a9e2cb099da3) --- source3/rpc_server/srv_spoolss_nt.c | 51 ++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 18 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 4355e2eb59..0654eea6f4 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -272,6 +272,7 @@ static BOOL delete_printer_handle(POLICY_HND *hnd) /* Printer->dev.handlename equals portname equals sharename */ slprintf(command, sizeof(command), "%s \"%s\"", cmd, Printer->dev.handlename); + dos_to_unix(command, True); /* Convert printername to unix-codepage */ slprintf(tmp_file, sizeof(tmp_file), "%s/smbcmd.%d", path, local_pid); unlink(tmp_file); @@ -289,7 +290,6 @@ static BOOL delete_printer_handle(POLICY_HND *hnd) kill(0, SIGHUP); if ( ( i = lp_servicenumber( Printer->dev.handlename ) ) >= 0 ) { - lp_remove_service( i ); lp_killservice( i ); return True; } else @@ -526,7 +526,8 @@ static BOOL open_printer_hnd(POLICY_HND *hnd, char *name) return False; } - DEBUG(5, ("%d printer handles active\n", ubi_dlCount(&Printer_list))); + DEBUG(5, ("%d printer handles active\n", + (int)ubi_dlCount(&Printer_list))); return True; } @@ -1604,11 +1605,9 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPO NT_PRINTER_INFO_LEVEL *printer = NULL; print_queue_struct *queue=NULL; - DEBUG(4,("construct_notify_printer_info\n")); - type=option_type->type; - DEBUGADD(4,("Notify type: [%s], number of notify info: [%d] on printer: [%s]\n", + DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n", (option_type->type==PRINTER_NOTIFY_TYPE?"PRINTER_NOTIFY_TYPE":"JOB_NOTIFY_TYPE"), option_type->count, lp_servicename(snum))); @@ -1617,7 +1616,7 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPO for(field_num=0; field_numcount; field_num++) { field = option_type->fields[field_num]; - DEBUGADD(4,("notify [%d]: type [%x], field [%x]\n", field_num, type, field)); + DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field)); if (!search_notify(type, field, &j) ) continue; @@ -1629,8 +1628,8 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPO construct_info_data(current_data, type, field, id); - DEBUG(10,("construct_notify_printer_info: calling %s\n", - notify_info_data_table[j].name )); + DEBUG(10,("construct_notify_printer_info: calling [%s] snum=%d printername=[%s])\n", + notify_info_data_table[j].name, snum, printer->info_2->printername )); notify_info_data_table[j].fn(snum, current_data, queue, printer); @@ -1646,14 +1645,17 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPO * fill a notify_info struct with info asked * ********************************************************************/ -static BOOL construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_INFO *info, int snum, SPOOL_NOTIFY_OPTION_TYPE *option_type, uint32 id) +static BOOL construct_notify_jobs_info(print_queue_struct *queue, + SPOOL_NOTIFY_INFO *info, + NT_PRINTER_INFO_LEVEL *printer, + int snum, SPOOL_NOTIFY_OPTION_TYPE + *option_type, uint32 id) { int field_num,j; uint16 type; uint16 field; SPOOL_NOTIFY_INFO_DATA *current_data; - NT_PRINTER_INFO_LEVEL *printer = NULL; DEBUG(4,("construct_notify_jobs_info\n")); @@ -1663,9 +1665,6 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_I (option_type->type==PRINTER_NOTIFY_TYPE?"PRINTER_NOTIFY_TYPE":"JOB_NOTIFY_TYPE"), option_type->count)); - if (get_a_printer(&printer, 2, lp_servicename(snum))!=0) - return False; - for(field_num=0; field_numcount; field_num++) { field = option_type->fields[field_num]; @@ -1683,7 +1682,6 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_I info->count++; } - free_a_printer(&printer, 2); return True; } @@ -1798,18 +1796,35 @@ static uint32 printer_notify_info(POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info) switch ( option_type->type ) { case PRINTER_NOTIFY_TYPE: - if(construct_notify_printer_info(info, snum, option_type, id)) + if(construct_notify_printer_info(info, snum, + option_type, id)) id--; break; - case JOB_NOTIFY_TYPE: + case JOB_NOTIFY_TYPE: { + NT_PRINTER_INFO_LEVEL *printer = NULL; + memset(&status, 0, sizeof(status)); count = print_queue_status(snum, &queue, &status); - for (j=0; j Date: Wed, 17 Jan 2001 22:55:02 +0000 Subject: Changes from APPLIANCE_HEAD: source/include/proto.h source/include/rpc_spoolss.h source/rpc_parse/parse_spoolss.c source/rpc_server/srv_spoolss.c source/rpc_server/srv_spoolss_nt.c - speedups in printer queue enumeration - still room for improvement. The construct_dev_mode() still creates and destroys a printer info_2 structure every time it is called. - fixed job->devmode memory leak - converted printer job notification routines to use tallocated memory rather than a fixed 2K buffer. This reduces the memory requirements of a 4500 job queue enumeration from 90MB to about 16MB. (This used to be commit 7853b27bc1765d48d5f06837f8aca71a3a0d1e5d) --- source3/rpc_server/srv_spoolss_nt.c | 526 +++++++++++++++++++++++++++++------- 1 file changed, 431 insertions(+), 95 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 0654eea6f4..24626d1a9a 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -273,7 +273,7 @@ static BOOL delete_printer_handle(POLICY_HND *hnd) slprintf(command, sizeof(command), "%s \"%s\"", cmd, Printer->dev.handlename); dos_to_unix(command, True); /* Convert printername to unix-codepage */ - slprintf(tmp_file, sizeof(tmp_file), "%s/smbcmd.%d", path, local_pid); + slprintf(tmp_file, sizeof(tmp_file), "%s/smbcmd.%d", path, local_pid); unlink(tmp_file); DEBUG(10,("Running [%s > %s]\n", command,tmp_file)); @@ -1132,53 +1132,116 @@ uint32 _spoolss_rffpcnex(POLICY_HND *handle, uint32 flags, uint32 options, /******************************************************************* * fill a notify_info_data with the servername ********************************************************************/ -static void spoolss_notify_server_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, - NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_server_name(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { - pstring temp_name; + pstring temp_name, temp; + uint32 len; snprintf(temp_name, sizeof(temp_name)-1, "\\\\%s", global_myname); - data->notify_data.data.length= (uint32)((dos_PutUniCode((char *)data->notify_data.data.string, - temp_name, sizeof(data->notify_data.data.string), True) - sizeof(uint16))/sizeof(uint16)); + len = (uint32)dos_PutUniCode(temp, temp_name, sizeof(temp) - 2, True); + + data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } + + memcpy(data->notify_data.data.string, temp, len); } /******************************************************************* * fill a notify_info_data with the printername (not including the servername). ********************************************************************/ -static void spoolss_notify_printer_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, - NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_printer_name(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { + pstring temp; + uint32 len; + /* the notify name should not contain the \\server\ part */ char *p = strrchr(printer->info_2->printername, '\\'); + if (!p) { p = printer->info_2->printername; } else { p++; } - data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, - p, sizeof(data->notify_data.data.string), True) - sizeof(uint16))/sizeof(uint16)); + len = (uint32)dos_PutUniCode(temp, p, sizeof(temp) - 2, True); + + data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } + + memcpy(data->notify_data.data.string, temp, len); } /******************************************************************* * fill a notify_info_data with the servicename ********************************************************************/ -static void spoolss_notify_share_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_share_name(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { - data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, - lp_servicename(snum), sizeof(data->notify_data.data.string),True) - sizeof(uint16))/sizeof(uint16)); + pstring temp; + uint32 len; + + len = (uint32)dos_PutUniCode(temp, lp_servicename(snum), + sizeof(temp) - 2, True); + + data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } + + memcpy(data->notify_data.data.string, temp, len); } /******************************************************************* * fill a notify_info_data with the port name ********************************************************************/ -static void spoolss_notify_port_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_port_name(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { + pstring temp; + uint32 len; + /* even if it's strange, that's consistant in all the code */ - data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, - printer->info_2->portname, sizeof(data->notify_data.data.string), True) - sizeof(uint16))/sizeof(uint16)); + len = (uint32)dos_PutUniCode(temp, printer->info_2->portname, + sizeof(temp) - 2, True); + + data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } + + memcpy(data->notify_data.data.string, temp, len); } /******************************************************************* @@ -1186,23 +1249,57 @@ static void spoolss_notify_port_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, pri * jfmxxxx: it's incorrect, should be lp_printerdrivername() * but it doesn't exist, have to see what to do ********************************************************************/ -static void spoolss_notify_driver_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_driver_name(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { - data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, - printer->info_2->drivername, sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16)); + pstring temp; + uint32 len; + + len = (uint32)dos_PutUniCode(temp, printer->info_2->drivername, + sizeof(temp) - 2, True); + + data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } + + memcpy(data->notify_data.data.string, temp, len); } /******************************************************************* * fill a notify_info_data with the comment ********************************************************************/ -static void spoolss_notify_comment(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_comment(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { + pstring temp; + uint32 len; + if (*printer->info_2->comment == '\0') - data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, - lp_comment(snum), sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16)); + len = (uint32)dos_PutUniCode(temp, lp_comment(snum), + sizeof(temp) - 2, True); else - data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, - printer->info_2->comment, sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16)); + len = (uint32)dos_PutUniCode(temp, printer->info_2->comment, + sizeof(temp) - 2, True); + + data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } + + memcpy(data->notify_data.data.string, temp, len); } /******************************************************************* @@ -1210,17 +1307,38 @@ static void spoolss_notify_comment(int snum, SPOOL_NOTIFY_INFO_DATA *data, print * jfm:xxxx incorrect, have to create a new smb.conf option * location = "Room 1, floor 2, building 3" ********************************************************************/ -static void spoolss_notify_location(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_location(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { - data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, - printer->info_2->location, sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16)); + pstring temp; + uint32 len; + + len = (uint32)dos_PutUniCode(temp, printer->info_2->location, + sizeof(temp) - 2, True); + + data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } + + memcpy(data->notify_data.data.string, temp, len); } /******************************************************************* * fill a notify_info_data with the device mode * jfm:xxxx don't to it for know but that's a real problem !!! ********************************************************************/ -static void spoolss_notify_devmode(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_devmode(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { } @@ -1229,40 +1347,108 @@ static void spoolss_notify_devmode(int snum, SPOOL_NOTIFY_INFO_DATA *data, print * jfm:xxxx just return no file could add an option to smb.conf * separator file = "separator.txt" ********************************************************************/ -static void spoolss_notify_sepfile(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_sepfile(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { - data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, - printer->info_2->sepfile, sizeof(data->notify_data.data.string)-1,True) - sizeof(uint16))/sizeof(uint16)); + pstring temp; + uint32 len; + + len = (uint32)dos_PutUniCode(temp, printer->info_2->sepfile, + sizeof(temp) - 2, True); + + data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } + + memcpy(data->notify_data.data.string, temp, len); } /******************************************************************* * fill a notify_info_data with the print processor * jfm:xxxx return always winprint to indicate we don't do anything to it ********************************************************************/ -static void spoolss_notify_print_processor(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_print_processor(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { - data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, - printer->info_2->printprocessor, sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16)); + pstring temp; + uint32 len; + + len = (uint32)dos_PutUniCode(temp, printer->info_2->printprocessor, + sizeof(temp) - 2, True); + + data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } + + memcpy(data->notify_data.data.string, temp, len); } /******************************************************************* * fill a notify_info_data with the print processor options * jfm:xxxx send an empty string ********************************************************************/ -static void spoolss_notify_parameters(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_parameters(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { - data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, - printer->info_2->parameters, sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16)); + pstring temp; + uint32 len; + + len = (uint32)dos_PutUniCode(temp, printer->info_2->parameters, + sizeof(temp) - 2, True); + + data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } + + memcpy(data->notify_data.data.string, temp, len); } /******************************************************************* * fill a notify_info_data with the data type * jfm:xxxx always send RAW as data type ********************************************************************/ -static void spoolss_notify_datatype(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_datatype(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { - data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, - printer->info_2->datatype, sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16)); + pstring temp; + uint32 len; + + len = (uint32)dos_PutUniCode(temp, printer->info_2->datatype, + sizeof(pstring) - 2, True); + + data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } + + memcpy(data->notify_data.data.string, temp, len); } /******************************************************************* @@ -1270,7 +1456,11 @@ static void spoolss_notify_datatype(int snum, SPOOL_NOTIFY_INFO_DATA *data, prin * jfm:xxxx send an null pointer to say no security desc * have to implement security before ! ********************************************************************/ -static void spoolss_notify_security_desc(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_security_desc(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { data->notify_data.data.length=0; data->notify_data.data.string[0]=0x00; @@ -1280,7 +1470,11 @@ static void spoolss_notify_security_desc(int snum, SPOOL_NOTIFY_INFO_DATA *data, * fill a notify_info_data with the attributes * jfm:xxxx a samba printer is always shared ********************************************************************/ -static void spoolss_notify_attributes(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_attributes(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { data->notify_data.value[0] = printer->info_2->attributes; } @@ -1288,7 +1482,11 @@ static void spoolss_notify_attributes(int snum, SPOOL_NOTIFY_INFO_DATA *data, pr /******************************************************************* * fill a notify_info_data with the priority ********************************************************************/ -static void spoolss_notify_priority(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_priority(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { data->notify_data.value[0] = printer->info_2->priority; } @@ -1296,7 +1494,11 @@ static void spoolss_notify_priority(int snum, SPOOL_NOTIFY_INFO_DATA *data, prin /******************************************************************* * fill a notify_info_data with the default priority ********************************************************************/ -static void spoolss_notify_default_priority(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_default_priority(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { data->notify_data.value[0] = printer->info_2->default_priority; } @@ -1304,7 +1506,11 @@ static void spoolss_notify_default_priority(int snum, SPOOL_NOTIFY_INFO_DATA *da /******************************************************************* * fill a notify_info_data with the start time ********************************************************************/ -static void spoolss_notify_start_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_start_time(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { data->notify_data.value[0] = printer->info_2->starttime; } @@ -1312,7 +1518,11 @@ static void spoolss_notify_start_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, pr /******************************************************************* * fill a notify_info_data with the until time ********************************************************************/ -static void spoolss_notify_until_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_until_time(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { data->notify_data.value[0] = printer->info_2->untiltime; } @@ -1320,9 +1530,14 @@ static void spoolss_notify_until_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, pr /******************************************************************* * fill a notify_info_data with the status ********************************************************************/ -static void spoolss_notify_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_status(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { int count; + print_queue_struct *q=NULL; print_status_struct status; @@ -1335,7 +1550,11 @@ static void spoolss_notify_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_ /******************************************************************* * fill a notify_info_data with the number of jobs queued ********************************************************************/ -static void spoolss_notify_cjobs(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_cjobs(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { print_queue_struct *q=NULL; print_status_struct status; @@ -1348,7 +1567,11 @@ static void spoolss_notify_cjobs(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_q /******************************************************************* * fill a notify_info_data with the average ppm ********************************************************************/ -static void spoolss_notify_average_ppm(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_average_ppm(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { /* always respond 8 pages per minutes */ /* a little hard ! */ @@ -1358,16 +1581,37 @@ static void spoolss_notify_average_ppm(int snum, SPOOL_NOTIFY_INFO_DATA *data, p /******************************************************************* * fill a notify_info_data with username ********************************************************************/ -static void spoolss_notify_username(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_username(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { - data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, - queue->user, sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16)); + pstring temp; + uint32 len; + + len = (uint32)dos_PutUniCode(temp, queue->user, + sizeof(temp) - 2, True); + + data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } + + memcpy(data->notify_data.data.string, temp, len); } /******************************************************************* * fill a notify_info_data with job status ********************************************************************/ -static void spoolss_notify_job_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_job_status(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { data->notify_data.value[0]=nt_printj_status(queue->status); } @@ -1375,18 +1619,41 @@ static void spoolss_notify_job_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, pr /******************************************************************* * fill a notify_info_data with job name ********************************************************************/ -static void spoolss_notify_job_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_job_name(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { - data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, - queue->file, sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16)); + pstring temp; + uint32 len; + + len = (uint32)dos_PutUniCode(temp, queue->file, sizeof(temp) - 2, + True); + + data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } + + memcpy(data->notify_data.data.string, temp, len); } /******************************************************************* * fill a notify_info_data with job status ********************************************************************/ -static void spoolss_notify_job_status_string(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_job_status_string(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { char *p = "unknown"; + pstring temp; + uint32 len; switch (queue->status) { case LPQ_QUEUED: @@ -1402,14 +1669,28 @@ static void spoolss_notify_job_status_string(int snum, SPOOL_NOTIFY_INFO_DATA *d p = "Printing"; break; } - data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string, - p, sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16)); + + len = (uint32)dos_PutUniCode(temp, p, sizeof(temp) - 2, True); + + data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } + + memcpy(data->notify_data.data.string, temp, len); } /******************************************************************* * fill a notify_info_data with job time ********************************************************************/ -static void spoolss_notify_job_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_job_time(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { data->notify_data.value[0]=0x0; } @@ -1417,7 +1698,11 @@ static void spoolss_notify_job_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, prin /******************************************************************* * fill a notify_info_data with job size ********************************************************************/ -static void spoolss_notify_job_size(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_job_size(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { data->notify_data.value[0]=queue->size; } @@ -1425,7 +1710,11 @@ static void spoolss_notify_job_size(int snum, SPOOL_NOTIFY_INFO_DATA *data, prin /******************************************************************* * fill a notify_info_data with job position ********************************************************************/ -static void spoolss_notify_job_position(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_job_position(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { data->notify_data.value[0]=queue->job; } @@ -1433,13 +1722,27 @@ static void spoolss_notify_job_position(int snum, SPOOL_NOTIFY_INFO_DATA *data, /******************************************************************* * fill a notify_info_data with submitted time ********************************************************************/ -static void spoolss_notify_submitted_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer) +static void spoolss_notify_submitted_time(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) { struct tm *t; + uint32 len; t=gmtime(&queue->time); - data->notify_data.data.length = sizeof(SYSTEMTIME); + len = sizeof(SYSTEMTIME); + + data->notify_data.data.length = len; + data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } + make_systemtime((SYSTEMTIME*)(data->notify_data.data.string), t); } @@ -1453,7 +1756,7 @@ struct s_notify_info_data_table uint32 size; void (*fn) (int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, - NT_PRINTER_INFO_LEVEL *printer); + NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx); }; struct s_notify_info_data_table notify_info_data_table[] = @@ -1595,7 +1898,10 @@ static void construct_info_data(SPOOL_NOTIFY_INFO_DATA *info_data, uint16 type, * fill a notify_info struct with info asked * ********************************************************************/ -static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPOOL_NOTIFY_OPTION_TYPE *option_type, uint32 id) +static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int + snum, SPOOL_NOTIFY_OPTION_TYPE + *option_type, uint32 id, + TALLOC_CTX *mem_ctx) { int field_num,j; uint16 type; @@ -1631,7 +1937,8 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPO DEBUG(10,("construct_notify_printer_info: calling [%s] snum=%d printername=[%s])\n", notify_info_data_table[j].name, snum, printer->info_2->printername )); - notify_info_data_table[j].fn(snum, current_data, queue, printer); + notify_info_data_table[j].fn(snum, current_data, queue, + printer, mem_ctx); info->count++; } @@ -1649,7 +1956,8 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_INFO *info, NT_PRINTER_INFO_LEVEL *printer, int snum, SPOOL_NOTIFY_OPTION_TYPE - *option_type, uint32 id) + *option_type, uint32 id, + TALLOC_CTX *mem_ctx) { int field_num,j; uint16 type; @@ -1678,7 +1986,8 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, current_data=&(info->data[info->count]); construct_info_data(current_data, type, field, id); - notify_info_data_table[j].fn(snum, current_data, queue, printer); + notify_info_data_table[j].fn(snum, current_data, queue, + printer, mem_ctx); info->count++; } @@ -1716,7 +2025,9 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, * fill a notify_info struct with info asked * ********************************************************************/ -static uint32 printserver_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info) +static uint32 printserver_notify_info(const POLICY_HND *hnd, + SPOOL_NOTIFY_INFO *info, + TALLOC_CTX *mem_ctx) { int snum; Printer_entry *Printer=find_printer_index_by_hnd(hnd); @@ -1742,7 +2053,8 @@ static uint32 printserver_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO * for (snum=0; snumtype ) { case PRINTER_NOTIFY_TYPE: - if(construct_notify_printer_info(info, snum, - option_type, id)) + if(construct_notify_printer_info(info, snum, + option_type, id, + mem_ctx)) id--; break; @@ -1815,11 +2129,12 @@ static uint32 printer_notify_info(POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info) construct_notify_jobs_info(&queue[j], info, printer, snum, option_type, - queue[j].job); + queue[j].job, + mem_ctx); } free_a_printer(&printer, 2); - + done: safe_free(queue); break; @@ -1848,13 +2163,16 @@ static uint32 printer_notify_info(POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info) * spoolss_rfnpcnex ********************************************************************/ uint32 _spoolss_rfnpcnex( POLICY_HND *handle, uint32 change, - SPOOL_NOTIFY_OPTION *option, SPOOL_NOTIFY_INFO *info) + SPOOL_NOTIFY_OPTION *option, TALLOC_CTX *mem_ctx, + SPOOL_NOTIFY_INFO *info) { Printer_entry *Printer=find_printer_index_by_hnd(handle); + uint32 result = ERROR_INVALID_HANDLE; if (!OPEN_HANDLE(Printer)) { - DEBUG(0,("_spoolss_rfnpcnex: Invalid handle (%s).\n",OUR_HANDLE(handle))); - return ERROR_INVALID_HANDLE; + DEBUG(0,("_spoolss_rfnpcnex: Invalid handle (%s).\n", + OUR_HANDLE(handle))); + goto done; } DEBUG(4,("Printer type %x\n",Printer->printer_type)); @@ -1876,12 +2194,17 @@ uint32 _spoolss_rfnpcnex( POLICY_HND *handle, uint32 change, switch (Printer->printer_type) { case PRINTER_HANDLE_IS_PRINTSERVER: - return printserver_notify_info(handle, info); + result = printserver_notify_info(handle, info, + mem_ctx); + break; + case PRINTER_HANDLE_IS_PRINTER: - return printer_notify_info(handle, info); + result = printer_notify_info(handle, info, mem_ctx); + break; } - - return ERROR_INVALID_HANDLE; + + done: + return result; } /******************************************************************** @@ -4076,16 +4399,13 @@ static void fill_job_info_1(JOB_INFO_1 *job_info, print_queue_struct *queue, /**************************************************************************** ****************************************************************************/ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, - int position, int snum) + int position, int snum, + NT_PRINTER_INFO_LEVEL *ntprinter) { pstring temp_name; - NT_PRINTER_INFO_LEVEL *ntprinter = NULL; pstring chaine; struct tm *t; - if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0 ) - return False; - t=gmtime(&queue->time); snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname); @@ -4119,11 +4439,9 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, job_info->pagesprinted=0; if((job_info->devmode = construct_dev_mode(snum)) == NULL) { - free_a_printer(&ntprinter, 2); return False; } - free_a_printer(&ntprinter, 2); return (True); } @@ -4180,19 +4498,25 @@ static uint32 enumjobs_level2(print_queue_struct *queue, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { + NT_PRINTER_INFO_LEVEL *ntprinter = NULL; JOB_INFO_2 *info; int i; info=(JOB_INFO_2 *)malloc(*returned*sizeof(JOB_INFO_2)); if (info==NULL) { - safe_free(queue); *returned=0; return ERROR_NOT_ENOUGH_MEMORY; } - + + if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0) { + *returned = 0; + return ERROR_NOT_ENOUGH_MEMORY; + } + for (i=0; i<*returned; i++) - fill_job_info_2(&(info[i]), &queue[i], i, snum); + fill_job_info_2(&(info[i]), &queue[i], i, snum, ntprinter); + free_a_printer(&ntprinter, 2); safe_free(queue); /* check the required size. */ @@ -4209,7 +4533,10 @@ static uint32 enumjobs_level2(print_queue_struct *queue, int snum, new_smb_io_job_info_2("", buffer, &info[i], 0); /* clear memory */ - free_job_info_2(info); + for (i = 0; i < *returned; i++) + free_job_info_2(&info[i]); + + free(info); if (*needed > offered) { *returned=0; @@ -5763,6 +6090,8 @@ static uint32 getjob_level_2(print_queue_struct *queue, int count, int snum, uin int i=0; BOOL found=False; JOB_INFO_2 *info_2; + NT_PRINTER_INFO_LEVEL *ntprinter = NULL; + info_2=(JOB_INFO_2 *)malloc(sizeof(JOB_INFO_2)); ZERO_STRUCTP(info_2); @@ -5784,8 +6113,14 @@ static uint32 getjob_level_2(print_queue_struct *queue, int count, int snum, uin return NT_STATUS_NO_PROBLEMO; } - fill_job_info_2(info_2, &(queue[i-1]), i, snum); + if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0) { + safe_free(queue); + return ERROR_NOT_ENOUGH_MEMORY; + } + + fill_job_info_2(info_2, &(queue[i-1]), i, snum, ntprinter); + free_a_printer(&ntprinter, 2); safe_free(queue); *needed += spoolss_size_job_info_2(info_2); @@ -5798,6 +6133,7 @@ static uint32 getjob_level_2(print_queue_struct *queue, int count, int snum, uin new_smb_io_job_info_2("", buffer, info_2, 0); free_job_info_2(info_2); + free(info_2); if (*needed > offered) return ERROR_INSUFFICIENT_BUFFER; -- cgit From 1a0d64a4254ae769e147699f0dc2b40429e43f23 Mon Sep 17 00:00:00 2001 From: David O'Neill Date: Thu, 18 Jan 2001 16:13:03 +0000 Subject: Changes from APPLIANCE_HEAD: source/rpc_server/srv_spoolss_nt.c - Fixed dereference of NULL pointer in security descriptor notification used by Win2K printers. (This used to be commit 1b6efd18943ef3ed0e2e061495d05cfdecd86c88) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 24626d1a9a..5b92a51189 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1463,7 +1463,7 @@ static void spoolss_notify_security_desc(int snum, TALLOC_CTX *mem_ctx) { data->notify_data.data.length=0; - data->notify_data.data.string[0]=0x00; + data->notify_data.data.string = NULL; } /******************************************************************* -- cgit From c4e0cb72bc654cbdae6e9c3bbcb40683bc0cadca Mon Sep 17 00:00:00 2001 From: David O'Neill Date: Fri, 19 Jan 2001 16:58:23 +0000 Subject: Changes from APPLIANCE_HEAD: source/include/proto.h - make proto source/rpc_server/srv_spoolss_nt.c - clean up incorrect debug statement (This used to be commit f07f4e9c7b9bb5230f10fffe50beab163b6f7790) --- source3/rpc_server/srv_spoolss_nt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 5b92a51189..d838d08c3c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -5736,8 +5736,8 @@ uint32 _spoolss_deleteprinterdata( POLICY_HND *handle, const UNISTR2 *value) return ERROR_INVALID_HANDLE; if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { - DEBUG(3, ("_spoolss_deleteprinterdata: security descriptor change denied by existing " - "security descriptor\n")); + DEBUG(3, ("_spoolss_deleteprinterdata: printer properties " + "change denied by existing security descriptor\n")); return ERROR_ACCESS_DENIED; } -- cgit From b9c5be4d79364db0fd3f9af186f165638cae1c54 Mon Sep 17 00:00:00 2001 From: David O'Neill Date: Tue, 23 Jan 2001 17:39:03 +0000 Subject: Changes from APPLIANCE_HEAD: source/rpc_server/srv_spoolss_nt.c - remove redundant srv_spoolss_sendnotify() calls from _spoolss_startdocprinter() and _spoolss_enddocprinter(), as its functionality is already covered in print_job_start() and print_job_end() source/printing/printing.c - force a print_queue_update() prior to print queue purge so that all jobs are purged. (This used to be commit 0ccc552203d6432cde844c5946b203b27f257b1a) --- source3/rpc_server/srv_spoolss_nt.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index d838d08c3c..4f2c7fa03e 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3658,7 +3658,6 @@ uint32 _spoolss_startdocprinter(POLICY_HND *handle, uint32 level, Printer->document_started=True; (*jobid) = Printer->jobid; - srv_spoolss_sendnotify(handle); return 0x0; } @@ -3680,8 +3679,6 @@ uint32 _spoolss_enddocprinter(POLICY_HND *handle) print_job_end(Printer->jobid); /* error codes unhandled so far ... */ - srv_spoolss_sendnotify(handle); - return 0x0; } -- cgit From eee29958f5cacc753f3fa324327e0d8b14ac3006 Mon Sep 17 00:00:00 2001 From: David O'Neill Date: Tue, 23 Jan 2001 20:25:25 +0000 Subject: Changes from APPLIANCE_HEAD: source/rpc_server/srv_spoolss_nt.c - add an access check to _spoolss_deleteprinter() to stop random users and passers by from deleting printers. source/lib/messages.c - converted global msg_all struct to a local in message_send_all() function. source/include/smb.h - added a success error code to the spoolss return codes. source/include/proto.h source/param/loadparm.c source/printing/printing.c - Added new parameter "total print jobs" to limit the total number of print jobs across all queues. Currently individual queues are limited by "max print jobs". (This used to be commit 02f154e729b0e8465d3e1e2ac794e6ab3844ce57) --- source3/rpc_server/srv_spoolss_nt.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 4f2c7fa03e..4be338d4d6 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -240,18 +240,28 @@ static BOOL close_printer_handle(POLICY_HND *hnd) /**************************************************************************** delete a printer given a handle ****************************************************************************/ -static BOOL delete_printer_handle(POLICY_HND *hnd) +static uint32 delete_printer_handle(POLICY_HND *hnd) { Printer_entry *Printer = find_printer_index_by_hnd(hnd); if (!OPEN_HANDLE(Printer)) { DEBUG(0,("delete_printer_handle: Invalid handle (%s)\n", OUR_HANDLE(hnd))); - return False; + return ERROR_INVALID_HANDLE; } if (del_a_printer(Printer->dev.handlename) != 0) { DEBUG(3,("Error deleting printer %s\n", Printer->dev.handlename)); - return False; + return ERROR_INVALID_HANDLE; + } + + /* Check calling user has permission to delete printer. Note that + since we set the snum parameter to -1 only administrators can + delete the printer. This stops people with the Full Control + permission from deleting the printer. */ + + if (!print_access_check(NULL, -1, PRINTER_ACCESS_ADMINISTER)) { + DEBUG(3, ("printer delete denied by security descriptor\n")); + return ERROR_ACCESS_DENIED; } if (*lp_deleteprinter_cmd()) { @@ -280,7 +290,7 @@ static BOOL delete_printer_handle(POLICY_HND *hnd) ret = smbrun(command, tmp_file, False); if (ret != 0) { unlink(tmp_file); - return False; + return ERROR_INVALID_HANDLE; /* What to return here? */ } DEBUGADD(10,("returned [%d]\n", ret)); DEBUGADD(10,("Unlinking output file [%s]\n", tmp_file)); @@ -291,12 +301,12 @@ static BOOL delete_printer_handle(POLICY_HND *hnd) if ( ( i = lp_servicenumber( Printer->dev.handlename ) ) >= 0 ) { lp_killservice( i ); - return True; + return ERROR_SUCCESS; } else - return False; + return ERROR_ACCESS_DENIED; } - return True; + return ERROR_SUCCESS; } /**************************************************************************** @@ -855,16 +865,18 @@ uint32 _spoolss_closeprinter(POLICY_HND *handle) uint32 _spoolss_deleteprinter(POLICY_HND *handle) { Printer_entry *Printer=find_printer_index_by_hnd(handle); + uint32 result; if (Printer && Printer->document_started) - _spoolss_enddocprinter(handle); /* print job was not closed */ + _spoolss_enddocprinter(handle); /* print job was not closed */ - if (!delete_printer_handle(handle)) - return ERROR_INVALID_HANDLE; + result = delete_printer_handle(handle); - srv_spoolss_sendnotify(handle); + if (result == ERROR_SUCCESS) { + srv_spoolss_sendnotify(handle); + } - return NT_STATUS_NO_PROBLEMO; + return result; } /******************************************************************** -- cgit From c7a7dea3331c5d77f57fb0622303933ca7afb0f9 Mon Sep 17 00:00:00 2001 From: David O'Neill Date: Thu, 25 Jan 2001 20:15:32 +0000 Subject: Changes from APPLIANCE_HEAD: source/rpc_server/srv_spoolss_nt.c - Changed the se_access_check() call in _spoolss_open_printer_ex() to a print_access_check(). This allows the 'printer admins' smb.conf and other permission override parameters to affect the result of a printer open. - Don't perform access check when opening a handle on a print server as it breaks browsing the Printers folder. (This used to be commit bbe51d4b5f6da4c7668214511e25eff098bf03b1) --- source3/rpc_server/srv_spoolss_nt.c | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 4be338d4d6..0ffe172b0a 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -669,10 +669,8 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, POLICY_HND *handle) { uint32 result = NT_STATUS_NO_PROBLEMO; - SEC_DESC_BUF *sec_desc = NULL; - uint32 acc_granted, status; fstring name; - extern struct current_user current_user; + int snum; if (printername == NULL) { result = ERROR_INVALID_PRINTER_NAME; @@ -729,29 +727,22 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, } /* NT doesn't let us connect to a printer if the connecting user - doesn't have print permission. If no security descriptor just - return OK. */ + doesn't have print permission. */ - if (!nt_printing_getsec(name, &sec_desc)) { - goto done; - } - - /* Yuck - we should use the pipe_user rather than current_user but - it doesn't seem to be filled in correctly. )-: */ + if (!handle_is_printserver(handle)) { - map_printer_permissions(sec_desc->sec); + if (!get_printer_snum(handle, &snum)) + return ERROR_INVALID_HANDLE; - if (!se_access_check(sec_desc->sec, ¤t_user, PRINTER_ACCESS_USE, - &acc_granted, &status)) { - DEBUG(3, ("access DENIED for printer open\n")); - close_printer_handle(handle); - result = ERROR_ACCESS_DENIED; - goto done; + if (!print_access_check(NULL, snum, PRINTER_ACCESS_USE)) { + DEBUG(3, ("access DENIED for printer open\n")); + close_printer_handle(handle); + result = ERROR_ACCESS_DENIED; + goto done; + } } done: - free_sec_desc_buf(&sec_desc); - return result; } -- cgit From 2506c61ab3bd667d54c5e004cc80ce5e40643b5d Mon Sep 17 00:00:00 2001 From: David O'Neill Date: Mon, 29 Jan 2001 21:34:08 +0000 Subject: Changes from APPLIANCE_HEAD: source/include/proto.h - make proto source/printing/nt_printing.c source/rpc_server/srv_spoolss_nt.c - Fix for the overwriting of printerdata entries when WinNT and Win2k are modifying printer parameters on PCL printers. Turns out that Win2k creates a printer with a NULL devmode entry and then expects to set it on *OPEN* (yes this is insane). So we cannot return a "default" devmode for a printer - and we must allow an open to set it. source/tdb/tdb.c - Show freelist in an easier format. Show total free. - When storing a new record, allocate memory for the key + data before the tdb_allocate() as if the malloc fails a (sparse) hole is left in the tdb. source/tdb/tdbtool.c - Show freelist in an easier format. Show total free. source/tdb/Makefile - cleaned up Makefile dependancies source/smbd/lanman.c - Fix for Win9x corrupting it's own parameter string. source/printing/printfsp.c source/printing/printing.c source/rpc_server/srv_spoolss_nt.c source/smbd/close.c - Added normal close parameter into print_fsp_end() which treats an abnormal close as error condition and deletes the spool file. (This used to be commit 025f7a092ad258ff774e3f5e53737f8210cc8af6) --- source3/rpc_server/srv_spoolss_nt.c | 87 +++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 32 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 0ffe172b0a..dabaca5d66 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -740,6 +740,22 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, result = ERROR_ACCESS_DENIED; goto done; } + + /* + * If we have a default device pointer in the + * printer_default struct, then we need to get + * the printer info from the tdb and if there is + * no default devicemode there then we do a *SET* + * here ! This is insanity.... JRA. + */ + + if (printer_default->devmode_cont.devmode != NULL) { + result = printer_write_default_dev( snum, printer_default); + if (result != 0) { + close_printer_handle(handle); + goto done; + } + } } done: @@ -781,15 +797,26 @@ static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL *u return True; } -static BOOL convert_devicemode(const DEVICEMODE *devmode, NT_DEVICEMODE *nt_devmode) +BOOL convert_devicemode(char *printername, const DEVICEMODE *devmode, + NT_DEVICEMODE **pp_nt_devmode) { + NT_DEVICEMODE *nt_devmode = *pp_nt_devmode; + + /* + * Ensure nt_devmode is a valid pointer + * as we will be overwriting it. + */ + + if (nt_devmode == NULL) + if ((nt_devmode = construct_nt_devicemode(printername)) == NULL) + return False; + unistr_to_dos(nt_devmode->devicename, (const char *)devmode->devicename.buffer, 31); unistr_to_dos(nt_devmode->formname, (const char *)devmode->formname.buffer, 31); nt_devmode->specversion=devmode->specversion; nt_devmode->driverversion=devmode->driverversion; nt_devmode->size=devmode->size; - nt_devmode->driverextra=devmode->driverextra; nt_devmode->fields=devmode->fields; nt_devmode->orientation=devmode->orientation; nt_devmode->papersize=devmode->papersize; @@ -820,16 +847,20 @@ static BOOL convert_devicemode(const DEVICEMODE *devmode, NT_DEVICEMODE *nt_devm nt_devmode->panningwidth=devmode->panningwidth; nt_devmode->panningheight=devmode->panningheight; - safe_free(nt_devmode->private); - if (nt_devmode->driverextra != 0) { - /* if we had a previous private delete it and make a new one */ + /* + * Only change private and driverextra if the incoming devmode + * has a new one. JRA. + */ + + if ((devmode->driverextra != 0) && (devmode->private != NULL)) { + safe_free(nt_devmode->private); + nt_devmode->driverextra=devmode->driverextra; if((nt_devmode->private=(uint8 *)malloc(nt_devmode->driverextra * sizeof(uint8))) == NULL) return False; memcpy(nt_devmode->private, devmode->private, nt_devmode->driverextra); } - else { - nt_devmode->private = NULL; - } + + *pp_nt_devmode = nt_devmode; return True; } @@ -915,7 +946,7 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d return True; } - if (!strcmp(value, "DefaultSpoolDirectory")) { + if (!strcmp(value, "DefaultSpoolDirectory")) { pstring string="You are using a Samba server"; *type = 0x1; *needed = 2*(strlen(string)+1); @@ -1045,7 +1076,7 @@ uint32 _spoolss_getprinterdata(POLICY_HND *handle, UNISTR2 *valuename, if (handle_is_printserver(handle)) found=getprinterdata_printer_server(value, type, data, needed, *out_size); else - found=getprinterdata_printer(handle, value, type, data, needed, *out_size); + found= getprinterdata_printer(handle, value, type, data, needed, *out_size); if (found==False) { DEBUG(5, ("value not found, allocating %d\n", *out_size)); @@ -1063,8 +1094,9 @@ uint32 _spoolss_getprinterdata(POLICY_HND *handle, UNISTR2 *valuename, if (*needed > *out_size) return ERROR_MORE_DATA; - else + else { return NT_STATUS_NO_PROBLEMO; + } } /*************************************************************************** @@ -2299,11 +2331,11 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum) printer->unknown13 = 0x0; printer->unknown14 = 0x1; printer->unknown15 = 0x024a; /* 586 Pentium ? */ - printer->unknown16 = 0x0; + printer->unknown16 = 0x0; printer->change_id = ntprinter->info_2->changeid; /* ChangeID in milliseconds*/ - printer->unknown18 = 0x0; + printer->unknown18 = 0x0; printer->status = nt_printq_status(status.status); - printer->unknown20 = 0x0; + printer->unknown20 = 0x0; printer->c_setprinter = ntprinter->info_2->c_setprinter; /* how many times setprinter has been called */ printer->unknown22 = 0x0; printer->unknown23 = 0x6; /* 6 ???*/ @@ -3679,7 +3711,7 @@ uint32 _spoolss_enddocprinter(POLICY_HND *handle) } Printer->document_started=False; - print_job_end(Printer->jobid); + print_job_end(Printer->jobid,True); /* error codes unhandled so far ... */ return 0x0; @@ -4230,21 +4262,12 @@ static uint32 update_printer(POLICY_HND *handle, uint32 level, /* we have a valid devmode convert it and link it*/ - /* - * Ensure printer->info_2->devmode is a valid pointer - * as we will be overwriting it in convert_devicemode(). - */ - - if (printer->info_2->devmode == NULL) - printer->info_2->devmode = construct_nt_devicemode(printer->info_2->printername); - DEBUGADD(8,("Converting the devicemode struct\n")); - convert_devicemode(devmode, printer->info_2->devmode); - - } else { - if (printer->info_2->devmode != NULL) - free_nt_devicemode(&printer->info_2->devmode); - printer->info_2->devmode=NULL; + if (!convert_devicemode(printer->info_2->printername, devmode, + &printer->info_2->devmode)) { + result = ERROR_NOT_ENOUGH_MEMORY; + goto done; + } } /* Do sanity check on the requested changes for Samba */ @@ -5673,10 +5696,10 @@ uint32 _spoolss_setprinterdata( POLICY_HND *handle, convert_specific_param(¶m, value , type, data, real_len); - /* Check if we are making any changes or not. Return true if + /* Check if we are making any changes or not. Return true if nothing is actually changing. */ - - ZERO_STRUCT(old_param); + + ZERO_STRUCT(old_param); if (get_specific_param(*printer, 2, param->value, &old_param.data, &old_param.type, (unsigned int *)&old_param.data_len)) { -- cgit From 4a9fb6b6b7d8696487f64316010559618f8848d6 Mon Sep 17 00:00:00 2001 From: David O'Neill Date: Wed, 31 Jan 2001 18:34:49 +0000 Subject: Changes from SAMBA_2_2: source/rpc_server/srv_spoolss_nt.c source/rpc_server/srv_spoolss.c source/include/proto.h - correct checking of access_required in openprinterex as talked with John R. and Jerry. You can only do server stuff (adding printers, changing forms, ..) if you're root or if user is in printer admin list. Printers options are grayed if you don't have the PRINTER_ADMINISTER flag in the secdesc. (This used to be commit f449d871bf0c385d8c57de2d795e1d7ef7f256f7) --- source3/rpc_server/srv_spoolss_nt.c | 116 ++++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 51 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index dabaca5d66..ff9dfabe69 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -658,12 +658,28 @@ static BOOL srv_spoolss_sendnotify(POLICY_HND *handle) return True; } +/**************************************************************************** + Return a user struct for a pipe user. +****************************************************************************/ + +static struct current_user *get_current_user(struct current_user *user, pipes_struct *p) +{ + if (p->ntlmssp_auth_validated) { + memcpy(user, &p->pipe_user, sizeof(struct current_user)); + } else { + extern struct current_user current_user; + memcpy(user, ¤t_user, sizeof(struct current_user)); + } + + return user; +} + /******************************************************************** * spoolss_open_printer * * called from the spoolss dispatcher ********************************************************************/ -uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, +uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, pipes_struct *p, const PRINTER_DEFAULT *printer_default, uint32 user_switch, SPOOL_USER_CTR user_ctr, POLICY_HND *handle) @@ -671,11 +687,10 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, uint32 result = NT_STATUS_NO_PROBLEMO; fstring name; int snum; + struct current_user user; - if (printername == NULL) { - result = ERROR_INVALID_PRINTER_NAME; - goto done; - } + if (printername == NULL) + return ERROR_INVALID_PRINTER_NAME; /* some sanity check because you can open a printer or a print server */ /* aka: \\server\printer or \\server */ @@ -683,10 +698,8 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, DEBUGADD(3,("checking name: %s\n",name)); - if (!open_printer_hnd(handle, name)) { - result = ERROR_INVALID_PRINTER_NAME; - goto done; - } + if (!open_printer_hnd(handle, name)) + return ERROR_INVALID_PRINTER_NAME; /* if (printer_default->datatype_ptr != NULL) @@ -700,45 +713,62 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, if (!set_printer_hnd_accesstype(handle, printer_default->access_required)) { close_printer_handle(handle); - result = ERROR_ACCESS_DENIED; - goto done; + return ERROR_ACCESS_DENIED; } - /* Disallow MS AddPrinterWizard if parameter disables it. A Win2k + /* + First case: the user is opening the print server: + + Disallow MS AddPrinterWizard if parameter disables it. A Win2k client 1st tries an OpenPrinterEx with access==0, MUST be allowed. + Then both Win2k and WinNT clients try an OpenPrinterEx with - SERVER_ALL_ACCESS, which we force to fail. Then they try - OpenPrinterEx with SERVER_READ which we allow. This lets the + SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0) + or if the user is listed in the smb.conf printer admin parameter. + + Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the client view printer folder, but does not show the MSAPW. Note: this test needs code to check access rights here too. Jeremy - could you look at this? */ + could you look at this? + + + Second case: the user is opening a printer: + NT doesn't let us connect to a printer if the connecting user + doesn't have print permission. - if (handle_is_printserver(handle) && - !lp_ms_add_printer_wizard()) { + */ + + get_current_user(&user, p); + + if (handle_is_printserver(handle) ) { if (printer_default->access_required == 0) { - goto done; - } - else if (printer_default->access_required != (SERVER_READ)) { - close_printer_handle(handle); - result = ERROR_ACCESS_DENIED; - goto done; + return NT_STATUS_NO_PROBLEMO; } - } - - /* NT doesn't let us connect to a printer if the connecting user - doesn't have print permission. */ - - if (!handle_is_printserver(handle)) { + else if ( (printer_default->access_required & SERVER_ACCESS_ADMINISTER ) == SERVER_ACCESS_ADMINISTER) { + if (lp_ms_add_printer_wizard()) { + close_printer_handle(handle); + return ERROR_ACCESS_DENIED; + } + else if (user.uid == 0 || user_in_list(uidtoname(user.uid), lp_printer_admin(snum))) { + return NT_STATUS_NO_PROBLEMO; + } else { + close_printer_handle(handle); + return ERROR_ACCESS_DENIED; + } + } + else + return NT_STATUS_NO_PROBLEMO; + } else { + if (!get_printer_snum(handle, &snum)) return ERROR_INVALID_HANDLE; - if (!print_access_check(NULL, snum, PRINTER_ACCESS_USE)) { + if (!print_access_check(&user, snum, printer_default->access_required)) { DEBUG(3, ("access DENIED for printer open\n")); close_printer_handle(handle); - result = ERROR_ACCESS_DENIED; - goto done; + return ERROR_ACCESS_DENIED; } /* @@ -753,13 +783,13 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, result = printer_write_default_dev( snum, printer_default); if (result != 0) { close_printer_handle(handle); - goto done; + return result; } } + + return NT_STATUS_NO_PROBLEMO; } - done: - return result; } /**************************************************************************** @@ -3615,22 +3645,6 @@ uint32 _spoolss_endpageprinter(POLICY_HND *handle) return NT_STATUS_NO_PROBLEMO; } -/**************************************************************************** - Return a user struct for a pipe user. -****************************************************************************/ - -static struct current_user *get_current_user(struct current_user *user, pipes_struct *p) -{ - if (p->ntlmssp_auth_validated) { - memcpy(user, &p->pipe_user, sizeof(struct current_user)); - } else { - extern struct current_user current_user; - memcpy(user, ¤t_user, sizeof(struct current_user)); - } - - return user; -} - /******************************************************************** * api_spoolss_getprinter * called from the spoolss dispatcher -- cgit From deb638a7aca9b52ce11ce27c8107f6d189b40f38 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sat, 3 Feb 2001 23:45:59 +0000 Subject: merge from APPLIANCE_HEAD (mapping access_required 0x0 to PRINTER_ACCESS_USE) (This used to be commit 0c57b05de46f04dda941fcb4ba4f2a5a88b8dc9f) --- source3/rpc_server/srv_spoolss_nt.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index ff9dfabe69..fecdadbf08 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -680,7 +680,7 @@ static struct current_user *get_current_user(struct current_user *user, pipes_st * called from the spoolss dispatcher ********************************************************************/ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, pipes_struct *p, - const PRINTER_DEFAULT *printer_default, + PRINTER_DEFAULT *printer_default, uint32 user_switch, SPOOL_USER_CTR user_ctr, POLICY_HND *handle) { @@ -747,7 +747,7 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, pipes_struct *p, } else if ( (printer_default->access_required & SERVER_ACCESS_ADMINISTER ) == SERVER_ACCESS_ADMINISTER) { - if (lp_ms_add_printer_wizard()) { + if (!lp_ms_add_printer_wizard()) { close_printer_handle(handle); return ERROR_ACCESS_DENIED; } @@ -765,6 +765,10 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, pipes_struct *p, if (!get_printer_snum(handle, &snum)) return ERROR_INVALID_HANDLE; + /* map an empty access mask to the minimum access mask */ + if (printer_default->access_required == 0x0) + printer_default->access_required = PRINTER_ACCESS_USE; + if (!print_access_check(&user, snum, printer_default->access_required)) { DEBUG(3, ("access DENIED for printer open\n")); close_printer_handle(handle); -- cgit From fd46817f0b20c633c80dee70a29cf7478e2dfd68 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 16 Feb 2001 19:21:18 +0000 Subject: Excise snprintf -> slprintf. srv_samr.c: duplicate gid fix. srv_spoolss_nt.c: Merge of JF's work. uid.c: Fix for returning names when a PDC. Jeremy. (This used to be commit d938ad6963a2dd4eda930d508600ec1902dc2b16) --- source3/rpc_server/srv_spoolss_nt.c | 204 +++++++++++++++++++++++++----------- 1 file changed, 140 insertions(+), 64 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index fecdadbf08..05fbbca0f3 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -122,6 +122,22 @@ void init_printer_hnd(void) ubi_dlInitList(&counter_list); } +/**************************************************************************** + Return a user struct for a pipe user. +****************************************************************************/ + +static struct current_user *get_current_user(struct current_user *user, pipes_struct *p) +{ + if (p->ntlmssp_auth_validated) { + memcpy(user, &p->pipe_user, sizeof(struct current_user)); + } else { + extern struct current_user current_user; + memcpy(user, ¤t_user, sizeof(struct current_user)); + } + + return user; +} + /**************************************************************************** create a unique printer handle ****************************************************************************/ @@ -280,10 +296,10 @@ static uint32 delete_printer_handle(POLICY_HND *hnd) path = tmpdir(); /* Printer->dev.handlename equals portname equals sharename */ - slprintf(command, sizeof(command), "%s \"%s\"", cmd, + slprintf(command, sizeof(command)-1, "%s \"%s\"", cmd, Printer->dev.handlename); dos_to_unix(command, True); /* Convert printername to unix-codepage */ - slprintf(tmp_file, sizeof(tmp_file), "%s/smbcmd.%d", path, local_pid); + slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%d", path, local_pid); unlink(tmp_file); DEBUG(10,("Running [%s > %s]\n", command,tmp_file)); @@ -658,22 +674,6 @@ static BOOL srv_spoolss_sendnotify(POLICY_HND *handle) return True; } -/**************************************************************************** - Return a user struct for a pipe user. -****************************************************************************/ - -static struct current_user *get_current_user(struct current_user *user, pipes_struct *p) -{ - if (p->ntlmssp_auth_validated) { - memcpy(user, &p->pipe_user, sizeof(struct current_user)); - } else { - extern struct current_user current_user; - memcpy(user, ¤t_user, sizeof(struct current_user)); - } - - return user; -} - /******************************************************************** * spoolss_open_printer * @@ -684,7 +684,9 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, pipes_struct *p, uint32 user_switch, SPOOL_USER_CTR user_ctr, POLICY_HND *handle) { +#if 0 uint32 result = NT_STATUS_NO_PROBLEMO; +#endif fstring name; int snum; struct current_user user; @@ -740,12 +742,12 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, pipes_struct *p, */ get_current_user(&user, p); - - if (handle_is_printserver(handle) ) { + + if (handle_is_printserver(handle)) { if (printer_default->access_required == 0) { return NT_STATUS_NO_PROBLEMO; } - else if ( (printer_default->access_required & SERVER_ACCESS_ADMINISTER ) == SERVER_ACCESS_ADMINISTER) { + else if ((printer_default->access_required & SERVER_ACCESS_ADMINISTER ) == SERVER_ACCESS_ADMINISTER) { if (!lp_ms_add_printer_wizard()) { close_printer_handle(handle); @@ -753,15 +755,18 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, pipes_struct *p, } else if (user.uid == 0 || user_in_list(uidtoname(user.uid), lp_printer_admin(snum))) { return NT_STATUS_NO_PROBLEMO; - } else { + } + else { close_printer_handle(handle); return ERROR_ACCESS_DENIED; } } - else - return NT_STATUS_NO_PROBLEMO; - } else { - + } + else + { + /* NT doesn't let us connect to a printer if the connecting user + doesn't have print permission. */ + if (!get_printer_snum(handle, &snum)) return ERROR_INVALID_HANDLE; @@ -783,6 +788,64 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, pipes_struct *p, * here ! This is insanity.... JRA. */ + /* + * If the openprinterex rpc call contains a devmode, + * it's a per-user one. This per-user devmode is derivated + * from the global devmode. Openprinterex() contains a per-user + * devmode for when you do EMF printing and spooling. + * In the EMF case, the NT workstation is only doing half the job + * of rendering the page. The other half is done by running the printer + * driver on the server. + * The EMF file doesn't contain the page description (paper size, orientation, ...). + * The EMF file only contains what is to be printed on the page. + * So in order for the server to know how to print, the NT client sends + * a devicemode attached to the openprinterex call. + * But this devicemode is short lived, it's only valid for the current print job. + * + * If Samba would have supported EMF spooling, this devicemode would + * have been attached to the handle, to sent it to the driver to correctly + * rasterize the EMF file. + * + * As Samba only supports RAW spooling, we only receive a ready-to-print file, + * we just act as a pass-thru between windows and the printer. + * + * In order to know that Samba supports only RAW spooling, NT has to call + * getprinter() at level 2 (attribute field) or NT has to call startdoc() + * and until NT sends a RAW job, we refuse it. + * + * But to call getprinter() or startdoc(), you first need a valid handle, + * and to get an handle you have to call openprintex(). Hence why you have + * a devicemode in the openprinterex() call. + * + * + * Differences between NT4 and NT 2000. + * NT4: + * --- + * On NT4, you only have a global devicemode. This global devicemode can be changed + * by the administrator (or by a user with enough privs). Everytime a user + * wants to print, the devicemode is resetted to the default. In Word, everytime + * you print, the printer's characteristics are always reset to the global devicemode. + * + * NT 2000: + * ------- + * In W2K, there is the notion of per-user devicemode. The first time you use + * a printer, a per-user devicemode is build from the global devicemode. + * If you change your per-user devicemode, it is saved in the registry, under the + * H_KEY_CURRENT_KEY sub_tree. So that everytime you print, you have your default + * printer preferences available. + * + * To change the per-user devicemode: it's the "Printing Preferences ..." button + * on the General Tab of the printer properties windows. + * + * To change the global devicemode: it's the "Printing Defaults..." button + * on the Advanced Tab of the printer properties window. + * + * JFM. + */ + + + +#if 0 if (printer_default->devmode_cont.devmode != NULL) { result = printer_write_default_dev( snum, printer_default); if (result != 0) { @@ -790,10 +853,10 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, pipes_struct *p, return result; } } - - return NT_STATUS_NO_PROBLEMO; +#endif } + return NT_STATUS_NO_PROBLEMO; } /**************************************************************************** @@ -841,9 +904,11 @@ BOOL convert_devicemode(char *printername, const DEVICEMODE *devmode, * as we will be overwriting it. */ - if (nt_devmode == NULL) + if (nt_devmode == NULL) { + DEBUG(5, ("convert_devicemode: allocating a generic devmode\n")); if ((nt_devmode = construct_nt_devicemode(printername)) == NULL) return False; + } unistr_to_dos(nt_devmode->devicename, (const char *)devmode->devicename.buffer, 31); unistr_to_dos(nt_devmode->formname, (const char *)devmode->formname.buffer, 31); @@ -1210,7 +1275,7 @@ static void spoolss_notify_server_name(int snum, pstring temp_name, temp; uint32 len; - snprintf(temp_name, sizeof(temp_name)-1, "\\\\%s", global_myname); + slprintf(temp_name, sizeof(temp_name)-1, "\\\\%s", global_myname); len = (uint32)dos_PutUniCode(temp, temp_name, sizeof(temp) - 2, True); @@ -2402,16 +2467,16 @@ static BOOL construct_printer_info_1(uint32 flags, PRINTER_INFO_1 *printer, int if (*ntprinter->info_2->comment == '\0') { init_unistr(&printer->comment, lp_comment(snum)); - snprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",global_myname, ntprinter->info_2->printername, + slprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",global_myname, ntprinter->info_2->printername, ntprinter->info_2->drivername, lp_comment(snum)); } else { init_unistr(&printer->comment, ntprinter->info_2->comment); /* saved comment. */ - snprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",global_myname, ntprinter->info_2->printername, + slprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",global_myname, ntprinter->info_2->printername, ntprinter->info_2->drivername, ntprinter->info_2->comment); } - snprintf(chaine2,sizeof(chaine)-1,"%s", ntprinter->info_2->printername); + slprintf(chaine2,sizeof(chaine)-1,"%s", ntprinter->info_2->printername); init_unistr(&printer->description, chaine); init_unistr(&printer->name, chaine2); @@ -2470,10 +2535,10 @@ static DEVICEMODE *construct_dev_mode(int snum) DEBUGADD(8,("loading DEVICEMODE\n")); - snprintf(adevice, sizeof(adevice), printer->info_2->printername); + slprintf(adevice, sizeof(adevice)-1, printer->info_2->printername); init_unistr(&devmode->devicename, adevice); - snprintf(aform, sizeof(aform), ntdevmode->formname); + slprintf(aform, sizeof(aform)-1, ntdevmode->formname); init_unistr(&devmode->formname, aform); devmode->specversion = ntdevmode->specversion; @@ -2744,9 +2809,9 @@ static BOOL enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, ui *returned=1; - snprintf(printername, sizeof(printername)-1,"Windows NT Remote Printers!!\\\\%s", global_myname); - snprintf(desc, sizeof(desc)-1,"%s", global_myname); - snprintf(comment, sizeof(comment)-1, "Logged on Domain"); + slprintf(printername, sizeof(printername)-1,"Windows NT Remote Printers!!\\\\%s", global_myname); + slprintf(desc, sizeof(desc)-1,"%s", global_myname); + slprintf(comment, sizeof(comment)-1, "Logged on Domain"); init_unistr(&printer->description, desc); init_unistr(&printer->name, printername); @@ -3158,19 +3223,19 @@ static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, NT_PRINTER_DRIVER_IN if (strlen(driver.info_3->driverpath)) { - snprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->driverpath); + slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->driverpath); init_unistr( &info->driverpath, temp ); } else init_unistr( &info->driverpath, "" ); if (strlen(driver.info_3->datafile)) { - snprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->datafile); + slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->datafile); init_unistr( &info->datafile, temp ); } else init_unistr( &info->datafile, "" ); if (strlen(driver.info_3->configfile)) { - snprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->configfile); + slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->configfile); init_unistr( &info->configfile, temp ); } else init_unistr( &info->configfile, "" ); @@ -3224,7 +3289,7 @@ static void init_unistr_array(uint16 **uni_array, fstring *char_array, char *ser if (!v) v = ""; /* hack to handle null lists */ } if (strlen(v) == 0) break; - snprintf(line, sizeof(line)-1, "\\\\%s%s", servername, v); + slprintf(line, sizeof(line)-1, "\\\\%s%s", servername, v); DEBUGADD(6,("%d:%s:%d\n", i, line, strlen(line))); if((*uni_array=Realloc(*uni_array, (j+strlen(line)+2)*sizeof(uint16))) == NULL) { DEBUG(0,("init_unistr_array: Realloc error\n" )); @@ -3257,25 +3322,25 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_IN init_unistr( &info->architecture, driver.info_3->environment ); if (strlen(driver.info_3->driverpath)) { - snprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->driverpath); + slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->driverpath); init_unistr( &info->driverpath, temp ); } else init_unistr( &info->driverpath, "" ); if (strlen(driver.info_3->datafile)) { - snprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->datafile); + slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->datafile); init_unistr( &info->datafile, temp ); } else init_unistr( &info->datafile, "" ); if (strlen(driver.info_3->configfile)) { - snprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->configfile); + slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->configfile); init_unistr( &info->configfile, temp ); } else init_unistr( &info->configfile, "" ); if (strlen(driver.info_3->helpfile)) { - snprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->helpfile); + slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->helpfile); init_unistr( &info->helpfile, temp ); } else init_unistr( &info->helpfile, "" ); @@ -3336,25 +3401,25 @@ static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_IN init_unistr( &info->architecture, driver.info_3->environment ); if (strlen(driver.info_3->driverpath)) { - snprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->driverpath); + slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->driverpath); init_unistr( &info->driverpath, temp ); } else init_unistr( &info->driverpath, "" ); if (strlen(driver.info_3->datafile)) { - snprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->datafile); + slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->datafile); init_unistr( &info->datafile, temp ); } else init_unistr( &info->datafile, "" ); if (strlen(driver.info_3->configfile)) { - snprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->configfile); + slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->configfile); init_unistr( &info->configfile, temp ); } else init_unistr( &info->configfile, "" ); if (strlen(driver.info_3->helpfile)) { - snprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->helpfile); + slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->helpfile); init_unistr( &info->helpfile, temp ); } else init_unistr( &info->helpfile, "" ); @@ -3649,6 +3714,7 @@ uint32 _spoolss_endpageprinter(POLICY_HND *handle) return NT_STATUS_NO_PROBLEMO; } + /******************************************************************** * api_spoolss_getprinter * called from the spoolss dispatcher @@ -3918,8 +3984,8 @@ static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) info->servername, info->printername, info->sharename, info->portname, info->drivername, info->comment, info->location)); /* we force some elements to "correct" values */ - slprintf(info->servername, sizeof(info->servername), "\\\\%s", global_myname); - slprintf(info->printername, sizeof(info->printername), "\\\\%s\\%s", + slprintf(info->servername, sizeof(info->servername)-1, "\\\\%s", global_myname); + slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s", global_myname, lp_servicename(snum)); fstrcpy(info->sharename, lp_servicename(snum)); info->attributes = PRINTER_ATTRIBUTE_SHARED \ @@ -3955,8 +4021,8 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) /* change \ to \\ for the shell */ all_string_sub(driverlocation,"\\","\\\\",sizeof(pstring)); - slprintf(tmp_file, sizeof(tmp_file), "%s/smbcmd.%d", path, local_pid); - slprintf(command, sizeof(command), "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"", + slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%d", path, local_pid); + slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"", cmd, printer->info_2->printername, printer->info_2->sharename, printer->info_2->portname, printer->info_2->drivername, printer->info_2->location, driverlocation); @@ -4013,9 +4079,13 @@ static BOOL nt_devicemode_equal(NT_DEVICEMODE *d1, NT_DEVICEMODE *d2) return False; /* if either is exclusively NULL are not equal */ } - if (!strequal(d1->devicename, d2->devicename) || - !strequal(d1->formname, d2->formname)) { - DEBUG(10, ("nt_devicemode_equal(): device,form not equal\n")); + if (!strequal(d1->devicename, d2->devicename)) { + DEBUG(10, ("nt_devicemode_equal(): device not equal (%s != %s)\n", d1->devicename, d2->devicename)); + return False; + } + + if (!strequal(d1->formname, d2->formname)) { + DEBUG(10, ("nt_devicemode_equal(): formname not equal (%s != %s)\n", d1->formname, d2->formname)); return False; } @@ -4181,7 +4251,13 @@ static BOOL nt_printer_info_level_equal(NT_PRINTER_INFO_LEVEL *p1, pi1 = p1->info_2; pi2 = p2->info_2; + /* Don't check the attributes as we stomp on the value in + check_printer_ok() anyway. */ + +#if 0 PI_CHECK_INT(attributes); +#endif + PI_CHECK_INT(priority); PI_CHECK_INT(default_priority); PI_CHECK_INT(starttime); @@ -4419,7 +4495,7 @@ static void fill_job_info_1(JOB_INFO_1 *job_info, print_queue_struct *queue, struct tm *t; t=gmtime(&queue->time); - snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname); + slprintf(temp_name, sizeof(temp_name)-1, "\\\\%s", global_myname); job_info->jobid=queue->job; init_unistr(&job_info->printername, lp_servicename(snum)); @@ -4448,11 +4524,11 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, struct tm *t; t=gmtime(&queue->time); - snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname); + slprintf(temp_name, sizeof(temp_name)-1, "\\\\%s", global_myname); job_info->jobid=queue->job; - snprintf(chaine, sizeof(chaine)-1, "\\\\%s\\%s", global_myname, ntprinter->info_2->printername); + slprintf(chaine, sizeof(chaine)-1, "\\\\%s\\%s", global_myname, ntprinter->info_2->printername); init_unistr(&job_info->printername, chaine); @@ -5133,8 +5209,8 @@ static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need else path = tmpdir(); - slprintf(tmp_file, sizeof(tmp_file), "%s/smbcmd.%d", path, local_pid); - slprintf(command, sizeof(command), "%s \"%d\"", cmd, 1); + slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%d", path, local_pid); + slprintf(command, sizeof(command)-1, "%s \"%d\"", cmd, 1); unlink(tmp_file); DEBUG(10,("Running [%s > %s]\n", command,tmp_file)); @@ -5231,8 +5307,8 @@ static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need else path = tmpdir(); - slprintf(tmp_file, sizeof(tmp_file), "%s/smbcmd.%d", path, local_pid); - slprintf(command, sizeof(command), "%s \"%d\"", cmd, 2); + slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%d", path, local_pid); + slprintf(command, sizeof(command)-1, "%s \"%d\"", cmd, 2); unlink(tmp_file); DEBUG(10,("Running [%s > %s]\n", command,tmp_file)); -- cgit From ed77fca1990f96dba6fe9204e551056395c6ed29 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 23 Feb 2001 03:59:37 +0000 Subject: include/rpc_spoolss.h: Added JOB_STATUS_XXX defines. include/smb.h: Added LPQ_xx enums to correspond with the NT JOB_STATUS_XXX. We need these to be different as we're storing LPQ_xx enums in the tdb already. rpc_server/srv_spoolss_nt.c: Don't need to return status strings as we're now returning status codes. smbd/lanman.c: Change the RAP status codes to have "RAP" in the name. printing/printing.c: Keep track of the status of a job. Allow a job to be deleted from one smbd when being submitted by another. Made logic in mutex clearer. Jeremy. (This used to be commit 71029da7dd74eb91dd6953752bdf238f319d985d) --- source3/rpc_server/srv_spoolss_nt.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 05fbbca0f3..d5f0703e03 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -45,7 +45,7 @@ typedef struct _Printer{ BOOL open; BOOL document_started; BOOL page_started; - int jobid; /* jobid in printing backend */ + int jobid; /* jobid in printing backend */ POLICY_HND printer_hnd; BOOL printer_type; union { @@ -90,12 +90,30 @@ static uint32 smb_connections=0; static int nt_printj_status(int v) { switch (v) { - case LPQ_PAUSED: - return PRINTER_STATUS_PAUSED; case LPQ_QUEUED: + return 0; + case LPQ_PAUSED: + return JOB_STATUS_PAUSED; case LPQ_SPOOLING: + return JOB_STATUS_SPOOLING; case LPQ_PRINTING: - return 0; + return JOB_STATUS_PRINTING; + case LPQ_ERROR: + return JOB_STATUS_ERROR; + case LPQ_DELETING: + return JOB_STATUS_DELETING; + case LPQ_OFFLINE: + return JOB_STATUS_OFFLINE; + case LPQ_PAPEROUT: + return JOB_STATUS_PAPEROUT; + case LPQ_PRINTED: + return JOB_STATUS_PRINTED; + case LPQ_DELETED: + return JOB_STATUS_DELETED; + case LPQ_BLOCKED: + return JOB_STATUS_BLOCKED; + case LPQ_USER_INTERVENTION: + return JOB_STATUS_USER_INTERVENTION; } return 0; } @@ -1785,10 +1803,17 @@ static void spoolss_notify_job_status_string(int snum, NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) { - char *p = "unknown"; + /* + * Now we're returning job status codes we just return a "" here. JRA. + */ + + char *p = ""; pstring temp; uint32 len; +#if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */ + p = "unknown"; + switch (queue->status) { case LPQ_QUEUED: p = "Queued"; @@ -1803,6 +1828,7 @@ static void spoolss_notify_job_status_string(int snum, p = "Printing"; break; } +#endif /* NO LONGER NEEDED. */ len = (uint32)dos_PutUniCode(temp, p, sizeof(temp) - 2, True); -- cgit From 0f2799aaf1e33aa474a12b9389728d57af926cb3 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 28 Feb 2001 00:51:02 +0000 Subject: Move to talloc control of SPOOL_XXX structs. Move to talloc control of security descriptors and pointers. Syncup with 2.2 tree. Jeremy. (This used to be commit 14d5997dc841e78a619e865288486d50c245896d) --- source3/rpc_server/srv_spoolss_nt.c | 49 ++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 25 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index d5f0703e03..4612384b0d 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1155,7 +1155,7 @@ static BOOL getprinterdata_printer(POLICY_HND *handle, /******************************************************************** * spoolss_getprinterdata ********************************************************************/ -uint32 _spoolss_getprinterdata(POLICY_HND *handle, UNISTR2 *valuename, +uint32 _spoolss_getprinterdata(pipes_struct *p, POLICY_HND *handle, UNISTR2 *valuename, uint32 in_size, uint32 *type, uint32 *out_size, @@ -1199,9 +1199,8 @@ uint32 _spoolss_getprinterdata(POLICY_HND *handle, UNISTR2 *valuename, DEBUG(5, ("value not found, allocating %d\n", *out_size)); /* reply this param doesn't exist */ if (*out_size) { - if((*data=(uint8 *)malloc(*out_size*sizeof(uint8))) == NULL) + if((*data=(uint8 *)talloc_zero(p->mem_ctx, *out_size*sizeof(uint8))) == NULL) return ERROR_NOT_ENOUGH_MEMORY; - memset(*data, '\0', *out_size*sizeof(uint8)); } else { *data = NULL; } @@ -2070,7 +2069,9 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int SPOOL_NOTIFY_INFO_DATA *current_data; NT_PRINTER_INFO_LEVEL *printer = NULL; print_queue_struct *queue=NULL; - + size_t realloc_size = 0; + SPOOL_NOTIFY_INFO_DATA *info_data_ptr = NULL; + type=option_type->type; DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n", @@ -2087,10 +2088,11 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int if (!search_notify(type, field, &j) ) continue; - if((info->data=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) { + realloc_size = (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA); + if((info_data_ptr=(SPOOL_NOTIFY_INFO_DATA *)Realloc(info_data_ptr, realloc_size)) == NULL) { return False; } - current_data=&info->data[info->count]; + current_data=&info_data_ptr[info->count]; construct_info_data(current_data, type, field, id); @@ -2103,6 +2105,12 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int info->count++; } + if (realloc_size) + info->data = talloc_memdup(mem_ctx, info_data_ptr, realloc_size); + else + info->data = NULL; + + safe_free(info_data_ptr); free_a_printer(&printer, 2); return True; } @@ -2322,9 +2330,8 @@ static uint32 printer_notify_info(POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info, /******************************************************************** * spoolss_rfnpcnex ********************************************************************/ -uint32 _spoolss_rfnpcnex( POLICY_HND *handle, uint32 change, - SPOOL_NOTIFY_OPTION *option, TALLOC_CTX *mem_ctx, - SPOOL_NOTIFY_INFO *info) +uint32 _spoolss_rfnpcnex( pipes_struct *p, POLICY_HND *handle, uint32 change, + SPOOL_NOTIFY_OPTION *option, SPOOL_NOTIFY_INFO *info) { Printer_entry *Printer=find_printer_index_by_hnd(handle); uint32 result = ERROR_INVALID_HANDLE; @@ -2348,18 +2355,16 @@ uint32 _spoolss_rfnpcnex( POLICY_HND *handle, uint32 change, * informations even when _NOTHING_ has changed. */ - /* just discard the SPOOL_NOTIFY_OPTION */ - if (option!=NULL) - safe_free(option->ctr.type); + /* just ignore the SPOOL_NOTIFY_OPTION */ switch (Printer->printer_type) { case PRINTER_HANDLE_IS_PRINTSERVER: result = printserver_notify_info(handle, info, - mem_ctx); + p->mem_ctx); break; case PRINTER_HANDLE_IS_PRINTER: - result = printer_notify_info(handle, info, mem_ctx); + result = printer_notify_info(handle, info, p->mem_ctx); break; } @@ -2910,7 +2915,6 @@ static BOOL enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint32 if (!alloc_buffer_size(buffer, *needed)) { for (i=0; i<*returned; i++) { free_devmode(printers[i].devmode); - free_sec_desc(&printers[i].secdesc); } safe_free(printers); return ERROR_INSUFFICIENT_BUFFER; @@ -2923,7 +2927,6 @@ static BOOL enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint32 /* clear memory */ for (i=0; i<*returned; i++) { free_devmode(printers[i].devmode); - free_sec_desc(&printers[i].secdesc); } safe_free(printers); @@ -3930,7 +3933,7 @@ static uint32 update_printer_sec(POLICY_HND *handle, uint32 level, dialog boxes when the user doesn't have permission to change the security descriptor. */ - nt_printing_getsec(Printer->dev.handlename, &old_secdesc_ctr); + nt_printing_getsec(p->mem_ctx, Printer->dev.handlename, &old_secdesc_ctr); if (DEBUGLEVEL >= 10) { SEC_ACL *acl; @@ -3968,7 +3971,7 @@ static uint32 update_printer_sec(POLICY_HND *handle, uint32 level, } } - new_secdesc_ctr = sec_desc_merge(secdesc_ctr, old_secdesc_ctr); + new_secdesc_ctr = sec_desc_merge(p->mem_ctx, secdesc_ctr, old_secdesc_ctr); if (sec_desc_equal(new_secdesc_ctr->sec, old_secdesc_ctr->sec)) { result = NT_STATUS_NO_PROBLEMO; @@ -3992,8 +3995,6 @@ static uint32 update_printer_sec(POLICY_HND *handle, uint32 level, result = nt_printing_setsec(Printer->dev.handlename, new_secdesc_ctr); done: - free_sec_desc_buf(&new_secdesc_ctr); - free_sec_desc_buf(&old_secdesc_ctr); return result; } @@ -5626,7 +5627,7 @@ uint32 _spoolss_getprinterdriverdirectory(UNISTR2 *name, UNISTR2 *uni_environmen /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_enumprinterdata(POLICY_HND *handle, uint32 idx, +uint32 _spoolss_enumprinterdata(pipes_struct *p, POLICY_HND *handle, uint32 idx, uint32 in_value_len, uint32 in_data_len, uint32 *out_max_value_len, uint16 **out_value, uint32 *out_value_len, uint32 *out_type, @@ -5758,24 +5759,22 @@ uint32 _spoolss_enumprinterdata(POLICY_HND *handle, uint32 idx, */ *out_max_value_len=(in_value_len/sizeof(uint16)); - if((*out_value=(uint16 *)malloc(in_value_len*sizeof(uint8))) == NULL) { + if((*out_value=(uint16 *)talloc_zero(p->mem_ctx,in_value_len*sizeof(uint8))) == NULL) { safe_free(data); return ERROR_NOT_ENOUGH_MEMORY; } - ZERO_STRUCTP(*out_value); *out_value_len = (uint32)dos_PutUniCode((char *)*out_value, value, in_value_len, True); *out_type=type; /* the data is counted in bytes */ *out_max_data_len=in_data_len; - if((*data_out=(uint8 *)malloc(in_data_len*sizeof(uint8))) == NULL) { + if((*data_out=(uint8 *)talloc_zero(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) { safe_free(data); return ERROR_NOT_ENOUGH_MEMORY; } - memset(*data_out,'\0',in_data_len); memcpy(*data_out, data, (size_t)data_len); *out_data_len=data_len; -- cgit From 403562cb94bc06707f86ec87caf0cf2d32a02ed7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 28 Feb 2001 01:24:55 +0000 Subject: Partial conversion of SPOOLSS code to canonical format. More to follow. Once complete then the PRINTER_XX functions and structures will be converted to talloc control. Jeremy. (This used to be commit 8171cc56428920d8b765d077198893201f68766e) --- source3/rpc_server/srv_spoolss_nt.c | 103 ++++++++++++++++++++++++++++-------- 1 file changed, 80 insertions(+), 23 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 4612384b0d..4170700705 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -697,18 +697,26 @@ static BOOL srv_spoolss_sendnotify(POLICY_HND *handle) * * called from the spoolss dispatcher ********************************************************************/ -uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, pipes_struct *p, - PRINTER_DEFAULT *printer_default, - uint32 user_switch, SPOOL_USER_CTR user_ctr, - POLICY_HND *handle) + +uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, SPOOL_R_OPEN_PRINTER_EX *r_u) { #if 0 uint32 result = NT_STATUS_NO_PROBLEMO; #endif + + UNISTR2 *printername = NULL; + PRINTER_DEFAULT *printer_default = &q_u->printer_default; +/* uint32 user_switch = q_u->user_switch; - notused */ +/* SPOOL_USER_CTR user_ctr = q_u->user_ctr; - notused */ + POLICY_HND *handle = &r_u->handle; + fstring name; int snum; struct current_user user; - + + if (q_u->printername_ptr != 0) + printername = &q_u->printername; + if (printername == NULL) return ERROR_INVALID_PRINTER_NAME; @@ -985,13 +993,18 @@ BOOL convert_devicemode(char *printername, const DEVICEMODE *devmode, /******************************************************************** * api_spoolss_closeprinter ********************************************************************/ -uint32 _spoolss_closeprinter(POLICY_HND *handle) + +uint32 _spoolss_closeprinter(pipes_struct *p, SPOOL_Q_CLOSEPRINTER *q_u, SPOOL_R_CLOSEPRINTER *r_u) { + POLICY_HND *handle = &q_u->handle; + Printer_entry *Printer=find_printer_index_by_hnd(handle); if (Printer && Printer->document_started) _spoolss_enddocprinter(handle); /* print job was not closed */ + memcpy(&r_u->handle, &q_u->handle, sizeof(r_u->handle)); + if (!close_printer_handle(handle)) return ERROR_INVALID_HANDLE; @@ -1000,15 +1013,21 @@ uint32 _spoolss_closeprinter(POLICY_HND *handle) /******************************************************************** * api_spoolss_deleteprinter + ********************************************************************/ -uint32 _spoolss_deleteprinter(POLICY_HND *handle) + +uint32 _spoolss_deleteprinter(pipes_struct *p, SPOOL_Q_DELETEPRINTER *q_u, SPOOL_R_DELETEPRINTER *r_u) { + POLICY_HND *handle = &q_u->handle; + Printer_entry *Printer=find_printer_index_by_hnd(handle); uint32 result; if (Printer && Printer->document_started) _spoolss_enddocprinter(handle); /* print job was not closed */ + memcpy(&r_u->handle, &q_u->handle, sizeof(r_u->handle)); + result = delete_printer_handle(handle); if (result == ERROR_SUCCESS) { @@ -1155,13 +1174,17 @@ static BOOL getprinterdata_printer(POLICY_HND *handle, /******************************************************************** * spoolss_getprinterdata ********************************************************************/ -uint32 _spoolss_getprinterdata(pipes_struct *p, POLICY_HND *handle, UNISTR2 *valuename, - uint32 in_size, - uint32 *type, - uint32 *out_size, - uint8 **data, - uint32 *needed) + +uint32 _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPOOL_R_GETPRINTERDATA *r_u) { + POLICY_HND *handle = &q_u->handle; + UNISTR2 *valuename = &q_u->valuename; + uint32 in_size = q_u->size; + uint32 *type = &r_u->type; + uint32 *out_size = &r_u->size; + uint8 **data = &r_u->data; + uint32 *needed = &r_u->needed; + fstring value; BOOL found=False; Printer_entry *Printer = find_printer_index_by_hnd(handle); @@ -1252,10 +1275,16 @@ static BOOL srv_spoolss_replyopenprinter(char *printer, uint32 localprinter, uin * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe * called from api_spoolss_rffpcnex ********************************************************************/ -uint32 _spoolss_rffpcnex(POLICY_HND *handle, uint32 flags, uint32 options, - const UNISTR2 *localmachine, uint32 printerlocal, - SPOOL_NOTIFY_OPTION *option) + +uint32 _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNEX *r_u) { + POLICY_HND *handle = &q_u->handle; + uint32 flags = q_u->flags; + uint32 options = q_u->options; + UNISTR2 *localmachine = &q_u->localmachine; + uint32 printerlocal = q_u->printerlocal; + SPOOL_NOTIFY_OPTION *option = q_u->option; + /* store the notify value in the printer struct */ Printer_entry *Printer=find_printer_index_by_hnd(handle); @@ -1283,6 +1312,7 @@ uint32 _spoolss_rffpcnex(POLICY_HND *handle, uint32 flags, uint32 options, /******************************************************************* * fill a notify_info_data with the servername ********************************************************************/ + static void spoolss_notify_server_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -2330,12 +2360,20 @@ static uint32 printer_notify_info(POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info, /******************************************************************** * spoolss_rfnpcnex ********************************************************************/ -uint32 _spoolss_rfnpcnex( pipes_struct *p, POLICY_HND *handle, uint32 change, - SPOOL_NOTIFY_OPTION *option, SPOOL_NOTIFY_INFO *info) + +uint32 _spoolss_rfnpcnex( pipes_struct *p, SPOOL_Q_RFNPCNEX *q_u, SPOOL_R_RFNPCNEX *r_u) { + POLICY_HND *handle = &q_u->handle; +/* uint32 change = q_u->change; - notused. */ +/* SPOOL_NOTIFY_OPTION *option = q_u->option; - notused. */ + SPOOL_NOTIFY_INFO *info = &r_u->info; + Printer_entry *Printer=find_printer_index_by_hnd(handle); uint32 result = ERROR_INVALID_HANDLE; + /* we always have a NOTIFY_INFO struct */ + r_u->info_ptr=0x1; + if (!OPEN_HANDLE(Printer)) { DEBUG(0,("_spoolss_rfnpcnex: Invalid handle (%s).\n", OUR_HANDLE(handle))); @@ -2874,6 +2912,7 @@ static BOOL enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, ui /******************************************************************** enum_all_printers_info_1_network. *********************************************************************/ + static BOOL enum_all_printers_info_1_network(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { DEBUG(4,("enum_all_printers_info_1_network\n")); @@ -2886,6 +2925,7 @@ static BOOL enum_all_printers_info_1_network(NEW_BUFFER *buffer, uint32 offered, * * called from api_spoolss_enumprinters (see this to understand) ********************************************************************/ + static BOOL enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int snum; @@ -3010,12 +3050,23 @@ static uint32 enumprinters_level5( uint32 flags, fstring servername, * * called from api_spoolss_enumprinters (see this to understand) ********************************************************************/ -uint32 _spoolss_enumprinters( uint32 flags, const UNISTR2 *servername, uint32 level, - NEW_BUFFER *buffer, uint32 offered, - uint32 *needed, uint32 *returned) + +uint32 _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOOL_R_ENUMPRINTERS *r_u) { + uint32 flags = q_u->flags; + UNISTR2 *servername = &q_u->servername; + uint32 level = q_u->level; + NEW_BUFFER *buffer = NULL; + uint32 offered = q_u->offered; + uint32 *needed = &r_u->needed; + uint32 *returned = &r_u->returned; + fstring name; + /* that's an [in out] buffer */ + new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + DEBUG(4,("_spoolss_enumprinters\n")); *needed=0; @@ -3900,8 +3951,10 @@ static uint32 control_printer(POLICY_HND *handle, uint32 command, * api_spoolss_abortprinter ********************************************************************/ -uint32 _spoolss_abortprinter(POLICY_HND *handle, pipes_struct *p) +uint32 _spoolss_abortprinter(pipes_struct *p, SPOOL_Q_ABORTPRINTER *q_u, SPOOL_R_ABORTPRINTER *r_u) { + POLICY_HND *handle = &q_u->handle; + return control_printer(handle, PRINTER_CONTROL_PURGE, p); } @@ -5859,8 +5912,12 @@ uint32 _spoolss_setprinterdata( POLICY_HND *handle, /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_deleteprinterdata( POLICY_HND *handle, const UNISTR2 *value) + +uint32 _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_u, SPOOL_R_DELETEPRINTERDATA *r_u) { + POLICY_HND *handle = &q_u->handle; + UNISTR2 *value = &q_u->valuename; + NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_PARAM param; int snum=0; -- cgit From 6ed9b52862fa076c26a267ab48df5a097f17edd6 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 28 Feb 2001 01:38:12 +0000 Subject: Ooops - forgot to check the rpcclient and smbcacls compile with the new code :-(. Jeremy. (This used to be commit 70beabf73bdaad7b6a60e24b7a11798a411bed02) --- source3/rpc_server/srv_spoolss_nt.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 4170700705..0e09bff289 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6,6 +6,7 @@ * Copyright (C) Andrew Tridgell 1992-2000, * Copyright (C) Luke Kenneth Casson Leighton 1996-2000, * Copyright (C) Jean François Micouleau 1998-2000. + * Copyright (C) Jeremy Allison 2001. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -3233,11 +3234,21 @@ static uint32 getprinter_level_3(int snum, NEW_BUFFER *buffer, uint32 offered, u /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_getprinter(POLICY_HND *handle, uint32 level, - NEW_BUFFER *buffer, uint32 offered, uint32 *needed) + +uint32 _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GETPRINTER *r_u) { + POLICY_HND *handle = &q_u->handle; + uint32 level = q_u->level; + NEW_BUFFER *buffer = NULL; + uint32 offered = q_u->offered; + uint32 *needed = &r_u->needed; + int snum; - + + /* that's an [in out] buffer */ + new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + *needed=0; if (!get_printer_snum(handle, &snum)) -- cgit From 2a258f7a64873fe4be213f974e21e6f0f596d0cd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 28 Feb 2001 02:03:02 +0000 Subject: Converted more to canonical format... save as I go., Jeremy. (This used to be commit 1d4ff7a81bccce0e5701102314af4f9c64c55cd6) --- source3/rpc_server/srv_spoolss_nt.c | 42 ++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 10 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 0e09bff289..4b5d27d002 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3739,15 +3739,28 @@ static uint32 getprinterdriver2_level6(fstring servername, fstring architecture, /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_getprinterdriver2(POLICY_HND *handle, const UNISTR2 *uni_arch, uint32 level, - uint32 clientmajorversion, uint32 clientminorversion, - NEW_BUFFER *buffer, uint32 offered, - uint32 *needed, uint32 *servermajorversion, uint32 *serverminorversion) + +uint32 _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_u, SPOOL_R_GETPRINTERDRIVER2 *r_u) { + POLICY_HND *handle = &q_u->handle; + UNISTR2 *uni_arch = &q_u->architecture; + uint32 level = q_u->level; + uint32 clientmajorversion = q_u->clientmajorversion; +/* uint32 clientminorversion = q_u->clientminorversion; - notused. */ + NEW_BUFFER *buffer = NULL; + uint32 offered = q_u->offered; + uint32 *needed = &r_u->needed; + uint32 *servermajorversion = &r_u->servermajorversion; + uint32 *serverminorversion = &r_u->serverminorversion; + fstring servername; fstring architecture; int snum; + /* that's an [in out] buffer */ + new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + DEBUG(4,("_spoolss_getprinterdriver2\n")); *needed=0; @@ -3776,8 +3789,11 @@ uint32 _spoolss_getprinterdriver2(POLICY_HND *handle, const UNISTR2 *uni_arch, u /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_startpageprinter(POLICY_HND *handle) + +uint32 _spoolss_startpageprinter(pipes_struct *p, SPOOL_Q_STARTPAGEPRINTER *q_u, SPOOL_R_STARTPAGEPRINTER *r_u) { + POLICY_HND *handle = &q_u->handle; + Printer_entry *Printer = find_printer_index_by_hnd(handle); if (OPEN_HANDLE(Printer)) { @@ -3791,8 +3807,11 @@ uint32 _spoolss_startpageprinter(POLICY_HND *handle) /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_endpageprinter(POLICY_HND *handle) + +uint32 _spoolss_endpageprinter(pipes_struct *p, SPOOL_Q_ENDPAGEPRINTER *q_u, SPOOL_R_ENDPAGEPRINTER *r_u) { + POLICY_HND *handle = &q_u->handle; + Printer_entry *Printer = find_printer_index_by_hnd(handle); if (!OPEN_HANDLE(Printer)) { @@ -3805,16 +3824,19 @@ uint32 _spoolss_endpageprinter(POLICY_HND *handle) return NT_STATUS_NO_PROBLEMO; } - /******************************************************************** * api_spoolss_getprinter * called from the spoolss dispatcher * ********************************************************************/ -uint32 _spoolss_startdocprinter(POLICY_HND *handle, uint32 level, - pipes_struct *p, DOC_INFO *docinfo, - uint32 *jobid) + +uint32 _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, SPOOL_R_STARTDOCPRINTER *r_u) { + POLICY_HND *handle = &q_u->handle; +/* uint32 level = q_u->doc_info_container.level; - notused. */ + DOC_INFO *docinfo = &q_u->doc_info_container.docinfo; + uint32 *jobid = &r_u->jobid; + DOC_INFO_1 *info_1 = &docinfo->doc_info_1; int snum; pstring jobname; -- cgit From acc06fc7a83f1bdd28bddec7fcf47319d4c35b2b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 28 Feb 2001 02:38:09 +0000 Subject: More converted to canonical format. Home now - do the rest tomorrow... Jeremy. (This used to be commit 9d5979f51ec7b2a62fb9b290eb0393594cfa6224) --- source3/rpc_server/srv_spoolss_nt.c | 136 +++++++++++++++++++++++++----------- 1 file changed, 96 insertions(+), 40 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 4b5d27d002..1f179a9b1d 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -991,6 +991,26 @@ BOOL convert_devicemode(char *printername, const DEVICEMODE *devmode, return True; } +/******************************************************************** + * _spoolss_enddocprinter_internal. + ********************************************************************/ + +static uint32 _spoolss_enddocprinter_internal(POLICY_HND *handle) +{ + Printer_entry *Printer=find_printer_index_by_hnd(handle); + + if (!OPEN_HANDLE(Printer)) { + DEBUG(0,("_spoolss_enddocprinter_internal: Invalid handle (%s)\n", OUR_HANDLE(handle))); + return ERROR_INVALID_HANDLE; + } + + Printer->document_started=False; + print_job_end(Printer->jobid,True); + /* error codes unhandled so far ... */ + + return 0x0; +} + /******************************************************************** * api_spoolss_closeprinter ********************************************************************/ @@ -1002,7 +1022,7 @@ uint32 _spoolss_closeprinter(pipes_struct *p, SPOOL_Q_CLOSEPRINTER *q_u, SPOOL_R Printer_entry *Printer=find_printer_index_by_hnd(handle); if (Printer && Printer->document_started) - _spoolss_enddocprinter(handle); /* print job was not closed */ + _spoolss_enddocprinter_internal(handle); /* print job was not closed */ memcpy(&r_u->handle, &q_u->handle, sizeof(r_u->handle)); @@ -1025,7 +1045,7 @@ uint32 _spoolss_deleteprinter(pipes_struct *p, SPOOL_Q_DELETEPRINTER *q_u, SPOOL uint32 result; if (Printer && Printer->document_started) - _spoolss_enddocprinter(handle); /* print job was not closed */ + _spoolss_enddocprinter_internal(handle); /* print job was not closed */ memcpy(&r_u->handle, &q_u->handle, sizeof(r_u->handle)); @@ -3898,38 +3918,36 @@ uint32 _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, S * called from the spoolss dispatcher * ********************************************************************/ -uint32 _spoolss_enddocprinter(POLICY_HND *handle) + +uint32 _spoolss_enddocprinter(pipes_struct *p, SPOOL_Q_ENDDOCPRINTER *q_u, SPOOL_R_ENDDOCPRINTER *r_u) { - Printer_entry *Printer=find_printer_index_by_hnd(handle); - - if (!OPEN_HANDLE(Printer)) { - DEBUG(0,("_spoolss_enddocprinter: Invalid handle (%s)\n", OUR_HANDLE(handle))); - return ERROR_INVALID_HANDLE; - } - - Printer->document_started=False; - print_job_end(Printer->jobid,True); - /* error codes unhandled so far ... */ + POLICY_HND *handle = &q_u->handle; - return 0x0; + return _spoolss_enddocprinter_internal(handle); } /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_writeprinter( POLICY_HND *handle, - uint32 buffer_size, - uint8 *buffer, - uint32 *buffer_written) + +uint32 _spoolss_writeprinter(pipes_struct *p, SPOOL_Q_WRITEPRINTER *q_u, SPOOL_R_WRITEPRINTER *r_u) { + POLICY_HND *handle = &q_u->handle; + uint32 buffer_size = q_u->buffer_size; + uint8 *buffer = q_u->buffer; + uint32 *buffer_written = &q_u->buffer_size2; + Printer_entry *Printer = find_printer_index_by_hnd(handle); if (!OPEN_HANDLE(Printer)) { DEBUG(0,("_spoolss_writeprinter: Invalid handle (%s)\n",OUR_HANDLE(handle))); + r_u->buffer_written = q_u->buffer_size2; return ERROR_INVALID_HANDLE; } - (*buffer_written) = print_job_write(Printer->jobid, (char *)buffer, - buffer_size); + (*buffer_written) = print_job_write(Printer->jobid, (char *)buffer, buffer_size); + + + r_u->buffer_written = q_u->buffer_size2; return 0x0; } @@ -4530,12 +4548,16 @@ static uint32 update_printer(POLICY_HND *handle, uint32 level, /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_setprinter(POLICY_HND *handle, uint32 level, - const SPOOL_PRINTER_INFO_LEVEL *info, - DEVMODE_CTR devmode_ctr, - SEC_DESC_BUF *secdesc_ctr, - uint32 command, pipes_struct *p) + +uint32 _spoolss_setprinter(pipes_struct *p, SPOOL_Q_SETPRINTER *q_u, SPOOL_R_SETPRINTER *r_u) { + POLICY_HND *handle = &q_u->handle; + uint32 level = q_u->level; + SPOOL_PRINTER_INFO_LEVEL *info = &q_u->info; + DEVMODE_CTR devmode_ctr = q_u->devmode_ctr; + SEC_DESC_BUF *secdesc_ctr = q_u->secdesc_ctr; + uint32 command = q_u->command; + Printer_entry *Printer = find_printer_index_by_hnd(handle); if (!OPEN_HANDLE(Printer)) { @@ -4559,8 +4581,11 @@ uint32 _spoolss_setprinter(POLICY_HND *handle, uint32 level, /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_fcpn(POLICY_HND *handle) + +uint32 _spoolss_fcpn(pipes_struct *p, SPOOL_Q_FCPN *q_u, SPOOL_R_FCPN *r_u) { + POLICY_HND *handle = &q_u->handle; + Printer_entry *Printer= find_printer_index_by_hnd(handle); if (!OPEN_HANDLE(Printer)) { @@ -4587,11 +4612,13 @@ uint32 _spoolss_fcpn(POLICY_HND *handle) /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_addjob(POLICY_HND *handle, uint32 level, - NEW_BUFFER *buffer, uint32 offered, - uint32 *needed) + +uint32 _spoolss_addjob(pipes_struct *p, SPOOL_Q_ADDJOB *q_u, SPOOL_R_ADDJOB *r_u) { - *needed = 0; + /* that's an [in out] buffer (despite appearences to the contrary) */ + new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + + r_u->needed = 0; return ERROR_INVALID_PARAMETER; /* this is what a NT server returns for AddJob. AddJob must fail on non-local @@ -4779,14 +4806,26 @@ static uint32 enumjobs_level2(print_queue_struct *queue, int snum, /**************************************************************************** Enumjobs. ****************************************************************************/ -uint32 _spoolss_enumjobs( POLICY_HND *handle, uint32 firstjob, uint32 numofjobs, uint32 level, - NEW_BUFFER *buffer, uint32 offered, - uint32 *needed, uint32 *returned) + +uint32 _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJOBS *r_u) { + POLICY_HND *handle = &q_u->handle; +/* uint32 firstjob = q_u->firstjob; - notused. */ +/* uint32 numofjobs = q_u->numofjobs; - notused. */ + uint32 level = q_u->level; + NEW_BUFFER *buffer = NULL; + uint32 offered = q_u->offered; + uint32 *needed = &r_u->needed; + uint32 *returned = &r_u->returned; + int snum; print_queue_struct *queue=NULL; print_status_struct prt_status; + /* that's an [in out] buffer */ + new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + DEBUG(4,("_spoolss_enumjobs\n")); ZERO_STRUCT(prt_status); @@ -4817,19 +4856,25 @@ uint32 _spoolss_enumjobs( POLICY_HND *handle, uint32 firstjob, uint32 numofjobs, } } - /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_schedulejob( POLICY_HND *handle, uint32 jobid) + +uint32 _spoolss_schedulejob( pipes_struct *p, SPOOL_Q_SCHEDULEJOB *q_u, SPOOL_R_SCHEDULEJOB *r_u) { return 0x0; } /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_setjob(POLICY_HND *handle, uint32 jobid, uint32 level, - pipes_struct *p, JOB_INFO *ctr, uint32 command) + +uint32 _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u) { + POLICY_HND *handle = &q_u->handle; + uint32 jobid = q_u->jobid; +/* uint32 level = q_u->level; - notused. */ +/* JOB_INFO *ctr = &q_u->ctr; - notused. */ + uint32 command = q_u->command; + struct current_user user; print_status_struct prt_status; int snum, errcode = ERROR_INVALID_FUNCTION; @@ -5104,14 +5149,25 @@ static uint32 enumprinterdrivers_level3(fstring servername, fstring architecture /**************************************************************************** Enumerates all printer drivers. ****************************************************************************/ -uint32 _spoolss_enumprinterdrivers( UNISTR2 *name, UNISTR2 *environment, uint32 level, - NEW_BUFFER *buffer, uint32 offered, - uint32 *needed, uint32 *returned) + +uint32 _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS *q_u, SPOOL_R_ENUMPRINTERDRIVERS *r_u) { +/* UNISTR2 *name = &q_u->name; - notused. */ + UNISTR2 *environment = &q_u->environment; + uint32 level = q_u->level; + NEW_BUFFER *buffer = NULL; + uint32 offered = q_u->offered; + uint32 *needed = &r_u->needed; + uint32 *returned = &r_u->returned; + fstring *list = NULL; fstring servername; fstring architecture; + /* that's an [in out] buffer */ + new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + DEBUG(4,("_spoolss_enumprinterdrivers\n")); fstrcpy(servername, global_myname); *needed=0; -- cgit From 30d74f54e6d6c876d3a6b8258b2c0cab1b5a3ef3 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 28 Feb 2001 21:19:31 +0000 Subject: Finished converion of spoolss code to canonical format. Now to work on the PRINT_XX struct alloc/free issues. Jeremy. (This used to be commit db98d4b020032b2a934b21bfdf9082765692fc5a) --- source3/rpc_server/srv_spoolss_nt.c | 218 ++++++++++++++++++++++++++++-------- 1 file changed, 169 insertions(+), 49 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 1f179a9b1d..8e7e3c28e5 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -5191,6 +5191,7 @@ uint32 _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS /**************************************************************************** ****************************************************************************/ + static void fill_form_1(FORM_1 *form, nt_forms_struct *list) { form->flag=list->flag; @@ -5205,15 +5206,25 @@ static void fill_form_1(FORM_1 *form, nt_forms_struct *list) /**************************************************************************** ****************************************************************************/ -uint32 _new_spoolss_enumforms( POLICY_HND *handle, uint32 level, - NEW_BUFFER *buffer, uint32 offered, - uint32 *needed, uint32 *numofforms) + +uint32 _new_spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMFORMS *r_u) { +/* POLICY_HND *handle = &q_u->handle; - notused. */ + uint32 level = q_u->level; + NEW_BUFFER *buffer = NULL; + uint32 offered = q_u->offered; + uint32 *needed = &r_u->needed; + uint32 *numofforms = &r_u->numofforms; + nt_forms_struct *list=NULL; FORM_1 *forms_1; int buffer_size=0; int i; + /* that's an [in out] buffer */ + new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + DEBUG(4,("_new_spoolss_enumforms\n")); DEBUGADD(5,("Offered buffer size [%d]\n", offered)); DEBUGADD(5,("Info level [%d]\n", level)); @@ -5275,14 +5286,26 @@ uint32 _new_spoolss_enumforms( POLICY_HND *handle, uint32 level, /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_getform( POLICY_HND *handle, uint32 level, UNISTR2 *uni_formname, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) + +uint32 _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM *r_u) { +/* POLICY_HND *handle = &q_u->handle; - notused. */ + uint32 level = q_u->level; + UNISTR2 *uni_formname = &q_u->formname; + NEW_BUFFER *buffer = NULL; + uint32 offered = q_u->offered; + uint32 *needed = &r_u->needed; + nt_forms_struct *list=NULL; FORM_1 form_1; fstring form_name; int buffer_size=0; int numofforms, i; + /* that's an [in out] buffer */ + new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + unistr2_to_ascii(form_name, uni_formname, sizeof(form_name)-1); DEBUG(4,("_spoolss_getform\n")); @@ -5554,10 +5577,20 @@ static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need /**************************************************************************** enumports. ****************************************************************************/ -uint32 _spoolss_enumports( UNISTR2 *name, uint32 level, - NEW_BUFFER *buffer, uint32 offered, - uint32 *needed, uint32 *returned) + +uint32 _spoolss_enumports( pipes_struct *p, SPOOL_Q_ENUMPORTS *q_u, SPOOL_R_ENUMPORTS *r_u) { +/* UNISTR2 *name = &q_u->name; - notused. */ + uint32 level = q_u->level; + NEW_BUFFER *buffer = NULL; + uint32 offered = q_u->offered; + uint32 *needed = &r_u->needed; + uint32 *returned = &r_u->returned; + + /* that's an [in out] buffer */ + new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + DEBUG(4,("_spoolss_enumports\n")); *returned=0; @@ -5646,12 +5679,20 @@ static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name, /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_addprinterex( const UNISTR2 *uni_srv_name, uint32 level, - const SPOOL_PRINTER_INFO_LEVEL *info, - uint32 unk0, uint32 unk1, uint32 unk2, uint32 unk3, - uint32 user_switch, const SPOOL_USER_CTR *user, - POLICY_HND *handle) + +uint32 _spoolss_addprinterex( pipes_struct *p, SPOOL_Q_ADDPRINTEREX *q_u, SPOOL_R_ADDPRINTEREX *r_u) { + UNISTR2 *uni_srv_name = &q_u->server_name; + uint32 level = q_u->level; + SPOOL_PRINTER_INFO_LEVEL *info = &q_u->info; + uint32 unk0 = q_u->unk0; + uint32 unk1 = q_u->unk1; + uint32 unk2 = q_u->unk2; + uint32 unk3 = q_u->unk3; + uint32 user_switch = q_u->user_switch; + SPOOL_USER_CTR *user = &q_u->user_ctr; + POLICY_HND *handle = &r_u->handle; + switch (level) { case 1: /* we don't handle yet */ @@ -5668,9 +5709,13 @@ uint32 _spoolss_addprinterex( const UNISTR2 *uni_srv_name, uint32 level, /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_addprinterdriver(pipes_struct *p, const UNISTR2 *server_name, - uint32 level, const SPOOL_PRINTER_DRIVER_INFO_LEVEL *info) + +uint32 _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u, SPOOL_R_ADDPRINTERDRIVER *r_u) { +/* UNISTR2 *server_name = &q_u->server_name; - notused. */ + uint32 level = q_u->level; + SPOOL_PRINTER_DRIVER_INFO_LEVEL *info = &q_u->info; + uint32 err = NT_STATUS_NO_PROBLEMO; NT_PRINTER_DRIVER_INFO_LEVEL driver; struct current_user user; @@ -5751,10 +5796,20 @@ static uint32 getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_getprinterdriverdirectory(UNISTR2 *name, UNISTR2 *uni_environment, uint32 level, - NEW_BUFFER *buffer, uint32 offered, - uint32 *needed) + +uint32 _spoolss_getprinterdriverdirectory(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVERDIR *q_u, SPOOL_R_GETPRINTERDRIVERDIR *r_u) { + UNISTR2 *name = &q_u->name; + UNISTR2 *uni_environment = &q_u->environment; + uint32 level = q_u->level; + NEW_BUFFER *buffer = NULL; + uint32 offered = q_u->offered; + uint32 *needed = &r_u->needed; + + /* that's an [in out] buffer */ + new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + DEBUG(4,("_spoolss_getprinterdriverdirectory\n")); *needed=0; @@ -5769,12 +5824,21 @@ uint32 _spoolss_getprinterdriverdirectory(UNISTR2 *name, UNISTR2 *uni_environmen /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_enumprinterdata(pipes_struct *p, POLICY_HND *handle, uint32 idx, - uint32 in_value_len, uint32 in_data_len, - uint32 *out_max_value_len, uint16 **out_value, uint32 *out_value_len, - uint32 *out_type, - uint32 *out_max_data_len, uint8 **data_out, uint32 *out_data_len) + +uint32 _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, SPOOL_R_ENUMPRINTERDATA *r_u) { + POLICY_HND *handle = &q_u->handle; + uint32 idx = q_u->index; + uint32 in_value_len = q_u->valuesize; + uint32 in_data_len = q_u->datasize; + uint32 *out_max_value_len = &r_u->valuesize; + uint16 **out_value = &r_u->value; + uint32 *out_value_len = &r_u->realvaluesize; + uint32 *out_type = &r_u->type; + uint32 *out_max_data_len = &r_u->datasize; + uint8 **data_out = &r_u->data; + uint32 *out_data_len = &r_u->realdatasize; + NT_PRINTER_INFO_LEVEL *printer = NULL; fstring value; @@ -5927,14 +5991,17 @@ uint32 _spoolss_enumprinterdata(pipes_struct *p, POLICY_HND *handle, uint32 idx, /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_setprinterdata( POLICY_HND *handle, - const UNISTR2 *value, - uint32 type, - uint32 max_len, - const uint8 *data, - uint32 real_len, - uint32 numeric_data) + +uint32 _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SPOOL_R_SETPRINTERDATA *r_u) { + POLICY_HND *handle = &q_u->handle; + UNISTR2 *value = &q_u->value; + uint32 type = q_u->type; +/* uint32 max_len = q_u->max_len; - notused. */ + uint8 *data = q_u->data; + uint32 real_len = q_u->real_len; +/* uint32 numeric_data = q_u->numeric_data; - notused. */ + NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_PARAM *param = NULL, old_param; int snum=0; @@ -6047,10 +6114,13 @@ uint32 _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_ /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_addform( POLICY_HND *handle, - uint32 level, - const FORM *form) + +uint32 _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM *r_u) { + POLICY_HND *handle = &q_u->handle; +/* uint32 level = q_u->level; - notused. */ + FORM *form = &q_u->form; + int count=0; nt_forms_struct *list=NULL; Printer_entry *Printer = find_printer_index_by_hnd(handle); @@ -6074,8 +6144,12 @@ uint32 _spoolss_addform( POLICY_HND *handle, /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_deleteform( POLICY_HND *handle, UNISTR2 *form_name) + +uint32 _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DELETEFORM *r_u) { + POLICY_HND *handle = &q_u->handle; + UNISTR2 *form_name = &q_u->name; + int count=0; uint32 ret = 0; nt_forms_struct *list=NULL; @@ -6099,11 +6173,14 @@ uint32 _spoolss_deleteform( POLICY_HND *handle, UNISTR2 *form_name) /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_setform( POLICY_HND *handle, - const UNISTR2 *uni_name, - uint32 level, - const FORM *form) + +uint32 _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM *r_u) { + POLICY_HND *handle = &q_u->handle; +/* UNISTR2 *uni_name = &q_u->name; - notused. */ +/* uint32 level = q_u->level; - notused. */ + FORM *form = &q_u->form; + int count=0; nt_forms_struct *list=NULL; Printer_entry *Printer = find_printer_index_by_hnd(handle); @@ -6156,10 +6233,21 @@ static uint32 enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, ui /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_enumprintprocessors(UNISTR2 *name, UNISTR2 *environment, uint32 level, - NEW_BUFFER *buffer, uint32 offered, - uint32 *needed, uint32 *returned) + +uint32 _spoolss_enumprintprocessors(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCESSORS *q_u, SPOOL_R_ENUMPRINTPROCESSORS *r_u) { +/* UNISTR2 *name = &q_u->name; - notused. */ +/* UNISTR2 *environment = &q_u->environment; - notused. */ + uint32 level = q_u->level; + NEW_BUFFER *buffer = NULL; + uint32 offered = q_u->offered; + uint32 *needed = &r_u->needed; + uint32 *returned = &r_u->returned; + + /* that's an [in out] buffer */ + new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + DEBUG(5,("spoolss_enumprintprocessors\n")); /* @@ -6213,10 +6301,21 @@ static uint32 enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered, /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_enumprintprocdatatypes(UNISTR2 *name, UNISTR2 *processor, uint32 level, - NEW_BUFFER *buffer, uint32 offered, - uint32 *needed, uint32 *returned) + +uint32 _spoolss_enumprintprocdatatypes(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCDATATYPES *q_u, SPOOL_R_ENUMPRINTPROCDATATYPES *r_u) { +/* UNISTR2 *name = &q_u->name; - notused. */ +/* UNISTR2 *processor = &q_u->processor; - notused. */ + uint32 level = q_u->level; + NEW_BUFFER *buffer = NULL; + uint32 offered = q_u->offered; + uint32 *needed = &r_u->needed; + uint32 *returned = &r_u->returned; + + /* that's an [in out] buffer */ + new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + DEBUG(5,("_spoolss_enumprintprocdatatypes\n")); *returned=0; @@ -6233,6 +6332,7 @@ uint32 _spoolss_enumprintprocdatatypes(UNISTR2 *name, UNISTR2 *processor, uint32 /**************************************************************************** enumprintmonitors level 1. ****************************************************************************/ + static uint32 enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PRINTMONITOR_1 *info_1=NULL; @@ -6296,10 +6396,20 @@ static uint32 enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_enumprintmonitors(UNISTR2 *name,uint32 level, - NEW_BUFFER *buffer, uint32 offered, - uint32 *needed, uint32 *returned) + +uint32 _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS *q_u, SPOOL_R_ENUMPRINTMONITORS *r_u) { +/* UNISTR2 *name = &q_u->name; - notused. */ + uint32 level = q_u->level; + NEW_BUFFER *buffer = NULL; + uint32 offered = q_u->offered; + uint32 *needed = &r_u->needed; + uint32 *returned = &r_u->returned; + + /* that's an [in out] buffer */ + new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + DEBUG(5,("spoolss_enumprintmonitors\n")); /* @@ -6431,15 +6541,25 @@ static uint32 getjob_level_2(print_queue_struct *queue, int count, int snum, uin /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_getjob( POLICY_HND *handle, uint32 jobid, uint32 level, - NEW_BUFFER *buffer, uint32 offered, - uint32 *needed) + +uint32 _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_u) { + POLICY_HND *handle = &q_u->handle; + uint32 jobid = q_u->jobid; + uint32 level = q_u->level; + NEW_BUFFER *buffer = NULL; + uint32 offered = q_u->offered; + uint32 *needed = &r_u->needed; + int snum; int count; print_queue_struct *queue=NULL; print_status_struct prt_status; + /* that's an [in out] buffer */ + new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + DEBUG(5,("spoolss_getjob\n")); memset(&prt_status, 0, sizeof(prt_status)); -- cgit From 011422ab5a45570d92740f4e11d1104296e38c9b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 1 Mar 2001 00:14:45 +0000 Subject: Ensure that SPOOL_NOTIFY_OPTION structs are safely copied out of the talloc area into the Printer_entry struct - these are used for changenotification. Jeremy. (This used to be commit 4c2a49168e53b5ed96d61c6bae908086c3852f64) --- source3/rpc_server/srv_spoolss_nt.c | 76 ++++++++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 14 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 8e7e3c28e5..d17082b880 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -132,6 +132,55 @@ static int nt_printq_status(int v) return 0; } +/**************************************************************************** + Functions to handle SPOOL_NOTIFY_OPTION struct stored in Printer_entry. +****************************************************************************/ + +static void free_spool_notify_option(SPOOL_NOTIFY_OPTION **pp) +{ + SPOOL_NOTIFY_OPTION *sp = *pp; + + *pp = NULL; + + if (!sp) + return; + + if (sp->ctr.type) + safe_free(sp->ctr.type); + + free(sp); + +} + +/**************************************************************************** + Functions to duplicate a SPOOL_NOTIFY_OPTION struct stored in Printer_entry. +****************************************************************************/ + +SPOOL_NOTIFY_OPTION *dup_spool_notify_option(SPOOL_NOTIFY_OPTION *sp) +{ + SPOOL_NOTIFY_OPTION *new_sp = malloc(sizeof(SPOOL_NOTIFY_OPTION)); + + if (!sp) + return NULL; + + new_sp = (SPOOL_NOTIFY_OPTION *)malloc(sizeof(SPOOL_NOTIFY_OPTION)); + if (!new_sp) + return NULL; + + *new_sp = *sp; + + if (sp->ctr.count) { + new_sp->ctr.type = (SPOOL_NOTIFY_OPTION_TYPE *)memdup(sp->ctr.type, sizeof(SPOOL_NOTIFY_OPTION_TYPE) * sp->ctr.count); + + if (!new_sp->ctr.type) { + safe_free(new_sp); + return NULL; + } + } + + return new_sp; +} + /**************************************************************************** initialise printer handle states... ****************************************************************************/ @@ -241,6 +290,7 @@ static BOOL srv_spoolss_replycloseprinter(POLICY_HND *handle) /**************************************************************************** close printer index by handle ****************************************************************************/ + static BOOL close_printer_handle(POLICY_HND *hnd) { Printer_entry *Printer = find_printer_index_by_hnd(hnd); @@ -259,8 +309,7 @@ static BOOL close_printer_handle(POLICY_HND *hnd) Printer->notify.options=0; Printer->notify.localmachine[0]='\0'; Printer->notify.printerlocal=0; - safe_free(Printer->notify.option); - Printer->notify.option=NULL; + free_spool_notify_option(&Printer->notify.option); Printer->notify.client_connected=False; clear_handle(hnd); @@ -1316,9 +1365,14 @@ uint32 _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE } Printer->notify.flags=flags; - Printer->notify.options=options; Printer->notify.printerlocal=printerlocal; - Printer->notify.option=option; + + if (Printer->notify.option) + free_spool_notify_option(&Printer->notify.option); + + Printer->notify.options=options; + Printer->notify.option=dup_spool_notify_option(option); + unistr2_to_ascii(Printer->notify.localmachine, localmachine, sizeof(Printer->notify.localmachine)-1); /* connect to the client machine and send a ReplyOpenPrinter */ @@ -2272,8 +2326,7 @@ static uint32 printserver_notify_info(const POLICY_HND *hnd, for (snum=0; snumtype ) { case PRINTER_NOTIFY_TYPE: - if(construct_notify_printer_info(info, snum, - option_type, id, - mem_ctx)) + if(construct_notify_printer_info(info, snum, option_type, id, mem_ctx)) id--; break; @@ -2340,8 +2391,7 @@ static uint32 printer_notify_info(POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info, memset(&status, 0, sizeof(status)); count = print_queue_status(snum, &queue, &status); - if (get_a_printer(&printer, 2, - lp_servicename(snum)) != 0) + if (get_a_printer(&printer, 2, lp_servicename(snum)) != 0) goto done; for (j=0; jnotify.localmachine[0]='\0'; Printer->notify.printerlocal=0; if (Printer->notify.option) - safe_free(Printer->notify.option->ctr.type); - safe_free(Printer->notify.option); - Printer->notify.option=NULL; + free_spool_notify_option(&Printer->notify.option); Printer->notify.client_connected=False; return NT_STATUS_NO_PROBLEMO; -- cgit From c014d3b709c0c71f6a092069f88854ee3f5387d3 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 1 Mar 2001 00:40:25 +0000 Subject: Remove unused code. Jeremy. (This used to be commit 3495d5cc3ba0f380fc78389b9ba17235ccd97ae4) --- source3/rpc_server/srv_spoolss_nt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index d17082b880..5e666a9a7a 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2870,7 +2870,7 @@ static BOOL enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 of return ERROR_NOT_ENOUGH_MEMORY; } DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_1\n", *returned)); - memcpy(&(printers[*returned]), ¤t_prt, sizeof(PRINTER_INFO_1)); + memcpy(&printers[*returned], ¤t_prt, sizeof(PRINTER_INFO_1)); (*returned)++; } } @@ -2878,14 +2878,14 @@ static BOOL enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 of /* check the required size. */ for (i=0; i<*returned; i++) - (*needed) += spoolss_size_printer_info_1(&(printers[i])); + (*needed) += spoolss_size_printer_info_1(&printers[i]); if (!alloc_buffer_size(buffer, *needed)) return ERROR_INSUFFICIENT_BUFFER; /* fill the buffer with the structures */ for (i=0; i<*returned; i++) - new_smb_io_printer_info_1("", buffer, &(printers[i]), 0); + new_smb_io_printer_info_1("", buffer, &printers[i], 0); /* clear memory */ safe_free(printers); -- cgit From 7d853615338e4c81a2204f57a7fc22da725f55fe Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 1 Mar 2001 03:04:13 +0000 Subject: rpc_parse/parse_spoolss.c: Fixed memory leak introduced by restructuring. rpc_server/srv_spoolss_nt.c: Fixed problem with printer snum being read uninitialised. Jeremy. (This used to be commit 1552db715da576b41060f0d31d2c4cdec790c1d4) --- source3/rpc_server/srv_spoolss_nt.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 5e666a9a7a..95bb64fef3 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -158,7 +158,7 @@ static void free_spool_notify_option(SPOOL_NOTIFY_OPTION **pp) SPOOL_NOTIFY_OPTION *dup_spool_notify_option(SPOOL_NOTIFY_OPTION *sp) { - SPOOL_NOTIFY_OPTION *new_sp = malloc(sizeof(SPOOL_NOTIFY_OPTION)); + SPOOL_NOTIFY_OPTION *new_sp = NULL; if (!sp) return NULL; @@ -825,6 +825,9 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, } else if ((printer_default->access_required & SERVER_ACCESS_ADMINISTER ) == SERVER_ACCESS_ADMINISTER) { + if (!get_printer_snum(handle, &snum)) + return ERROR_INVALID_HANDLE; + if (!lp_ms_add_printer_wizard()) { close_printer_handle(handle); return ERROR_ACCESS_DENIED; @@ -843,13 +846,13 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, /* NT doesn't let us connect to a printer if the connecting user doesn't have print permission. */ - if (!get_printer_snum(handle, &snum)) - return ERROR_INVALID_HANDLE; - /* map an empty access mask to the minimum access mask */ if (printer_default->access_required == 0x0) printer_default->access_required = PRINTER_ACCESS_USE; + if (!get_printer_snum(handle, &snum)) + return ERROR_INVALID_HANDLE; + if (!print_access_check(&user, snum, printer_default->access_required)) { DEBUG(3, ("access DENIED for printer open\n")); close_printer_handle(handle); -- cgit From 5fa70d774780c2b3781b8dd89784cb768fbadcb0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 1 Mar 2001 03:36:02 +0000 Subject: When opening a printserver use a global snum of -1. Jeremy (This used to be commit 3f44cb6103fe8df9182fbbca7dc7888171b4352a) --- source3/rpc_server/srv_spoolss_nt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 95bb64fef3..c5a15ed37e 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -825,8 +825,8 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, } else if ((printer_default->access_required & SERVER_ACCESS_ADMINISTER ) == SERVER_ACCESS_ADMINISTER) { - if (!get_printer_snum(handle, &snum)) - return ERROR_INVALID_HANDLE; + /* Printserver handles use global struct... */ + snum = -1; if (!lp_ms_add_printer_wizard()) { close_printer_handle(handle); -- cgit From fe4d6cd3bb52f4a28b91f90c3e64e782e2f2f08e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 1 Mar 2001 04:00:45 +0000 Subject: Fix memory leaks introduced in restructure. Jeremy. (This used to be commit a355e11201e4dcb495b65b86e79de40d94c52a5b) --- source3/rpc_server/srv_spoolss_nt.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index c5a15ed37e..341117f346 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1113,7 +1113,8 @@ uint32 _spoolss_deleteprinter(pipes_struct *p, SPOOL_Q_DELETEPRINTER *q_u, SPOOL /******************************************************************** GetPrinterData on a printer server Handle. ********************************************************************/ -static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **data, uint32 *needed, uint32 in_size) + +static BOOL getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint32 *type, uint8 **data, uint32 *needed, uint32 in_size) { int i; @@ -1121,7 +1122,7 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d if (!strcmp(value, "BeepEnabled")) { *type = 0x4; - if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL) + if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) return False; SIVAL(*data, 0, 0x01); *needed = 0x4; @@ -1130,7 +1131,7 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d if (!strcmp(value, "EventLog")) { *type = 0x4; - if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL) + if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) return False; SIVAL(*data, 0, 0x1B); *needed = 0x4; @@ -1139,7 +1140,7 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d if (!strcmp(value, "NetPopup")) { *type = 0x4; - if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL) + if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) return False; SIVAL(*data, 0, 0x01); *needed = 0x4; @@ -1148,7 +1149,7 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d if (!strcmp(value, "MajorVersion")) { *type = 0x4; - if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL) + if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) return False; SIVAL(*data, 0, 0x02); *needed = 0x4; @@ -1159,9 +1160,8 @@ static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **d pstring string="You are using a Samba server"; *type = 0x1; *needed = 2*(strlen(string)+1); - if((*data = (uint8 *)malloc( ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL) + if((*data = (uint8 *)talloc_zero( ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL) return False; - memset(*data, 0, (*needed > in_size) ? *needed:in_size); /* it's done by hand ready to go on the wire */ for (i=0; i in_size) ? *needed:in_size) *sizeof(uint8))) == NULL) + if((*data = (uint8 *)talloc_zero( ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL) return False; - memset(*data, 0, (*needed > in_size) ? *needed:in_size); for (i=0; iin_size)?in_size:len *sizeof(uint8)); } else { @@ -1278,7 +1276,7 @@ uint32 _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO DEBUG(4,("_spoolss_getprinterdata\n")); if (!OPEN_HANDLE(Printer)) { - if((*data=(uint8 *)malloc(4*sizeof(uint8))) == NULL) + if((*data=(uint8 *)talloc_zero(p->mem_ctx, 4*sizeof(uint8))) == NULL) return ERROR_NOT_ENOUGH_MEMORY; DEBUG(0,("_spoolss_getprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; @@ -1287,9 +1285,9 @@ uint32 _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO unistr2_to_ascii(value, valuename, sizeof(value)-1); if (handle_is_printserver(handle)) - found=getprinterdata_printer_server(value, type, data, needed, *out_size); + found=getprinterdata_printer_server(p->mem_ctx, value, type, data, needed, *out_size); else - found= getprinterdata_printer(handle, value, type, data, needed, *out_size); + found= getprinterdata_printer(p->mem_ctx, handle, value, type, data, needed, *out_size); if (found==False) { DEBUG(5, ("value not found, allocating %d\n", *out_size)); -- cgit From 74294f5a967cbcdaa4d502bda3b6147d912f8411 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 2 Mar 2001 00:20:43 +0000 Subject: Move to talloc controlled NT forms. Jeremy. (This used to be commit 3e190e693375c6032dd64bf8dd3c90f90dc4e3b4) --- source3/rpc_server/srv_spoolss_nt.c | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 341117f346..01055f4e71 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -5278,14 +5278,14 @@ uint32 _new_spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_E DEBUGADD(5,("Offered buffer size [%d]\n", offered)); DEBUGADD(5,("Info level [%d]\n", level)); - *numofforms = get_ntforms(&list); + *numofforms = get_ntforms(p->mem_ctx, &list); DEBUGADD(5,("Number of forms [%d]\n", *numofforms)); if (*numofforms == 0) return ERROR_NO_MORE_ITEMS; switch (level) { case 1: - if ((forms_1=(FORM_1 *)malloc(*numofforms * sizeof(FORM_1))) == NULL) { + if ((forms_1=(FORM_1 *)talloc(p->mem_ctx, *numofforms * sizeof(FORM_1))) == NULL) { *numofforms=0; return ERROR_NOT_ENOUGH_MEMORY; } @@ -5296,8 +5296,6 @@ uint32 _new_spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_E fill_form_1(&forms_1[i], &list[i]); } - safe_free(list); - /* check the required size. */ for (i=0; i<*numofforms; i++) { DEBUGADD(6,("adding form [%d]'s size\n",i)); @@ -5306,10 +5304,8 @@ uint32 _new_spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_E *needed=buffer_size; - if (!alloc_buffer_size(buffer, buffer_size)){ - safe_free(forms_1); + if (!alloc_buffer_size(buffer, buffer_size)) return ERROR_INSUFFICIENT_BUFFER; - } /* fill the buffer with the form structures */ for (i=0; i<*numofforms; i++) { @@ -5317,8 +5313,6 @@ uint32 _new_spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_E new_smb_io_form_1("", buffer, &forms_1[i], 0); } - safe_free(forms_1); - if (*needed > offered) { *numofforms=0; return ERROR_INSUFFICIENT_BUFFER; @@ -5327,10 +5321,8 @@ uint32 _new_spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_E return NT_STATUS_NO_PROBLEMO; default: - safe_free(list); return ERROR_INVALID_LEVEL; } - } /**************************************************************************** @@ -5361,7 +5353,7 @@ uint32 _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * DEBUGADD(5,("Offered buffer size [%d]\n", offered)); DEBUGADD(5,("Info level [%d]\n", level)); - numofforms = get_ntforms(&list); + numofforms = get_ntforms(p->mem_ctx, &list); DEBUGADD(5,("Number of forms [%d]\n", numofforms)); if (numofforms == 0) @@ -5382,8 +5374,6 @@ uint32 _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * } } - safe_free(list); - /* check the required size. */ *needed=spoolss_size_form_1(&form_1); @@ -5403,7 +5393,6 @@ uint32 _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * return NT_STATUS_NO_PROBLEMO; default: - safe_free(list); return ERROR_INVALID_LEVEL; } } @@ -6181,14 +6170,12 @@ uint32 _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM return ERROR_INVALID_HANDLE; } - count=get_ntforms(&list); - if(!add_a_form(&list, form, &count)) + count=get_ntforms(p->mem_ctx, &list); + if(!add_a_form(p->mem_ctx, &list, form, &count)) return ERROR_NOT_ENOUGH_MEMORY; write_ntforms(&list, count); - safe_free(list); - - return 0x0; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** @@ -6211,12 +6198,10 @@ uint32 _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE return ERROR_INVALID_HANDLE; } - count = get_ntforms(&list); + count = get_ntforms(p->mem_ctx, &list); if(!delete_a_form(&list, form_name, &count, &ret)) return ERROR_INVALID_PARAMETER; - safe_free(list); - return ret; } @@ -6240,12 +6225,10 @@ uint32 _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM * DEBUG(0,("_spoolss_setform: Invalid handle (%s).\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; } - count=get_ntforms(&list); + count=get_ntforms(p->mem_ctx, &list); update_a_form(&list, form, count); write_ntforms(&list, count); - safe_free(list); - return 0x0; } -- cgit From 28c43a3cd50e2504f814d864f6423b5df4dc8d45 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 2 Mar 2001 02:59:17 +0000 Subject: Arrgggh. Returning the SPOOL_INFO stuff requires that the realloced data be realloced between different functions. This took a *long* time to track down (even with insure :-). Jeremy. (This used to be commit e61899f490e0d4109a5fc2faa04eefb934e8448c) --- source3/rpc_server/srv_spoolss_nt.c | 59 ++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 23 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 01055f4e71..2b6fb9a7e5 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2157,12 +2157,12 @@ static void construct_info_data(SPOOL_NOTIFY_INFO_DATA *info_data, uint16 type, info_data->enc_type = type_of_notify_info_data(type, field); } - /******************************************************************* * * fill a notify_info struct with info asked * ********************************************************************/ + static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPOOL_NOTIFY_OPTION_TYPE *option_type, uint32 id, @@ -2175,8 +2175,6 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int SPOOL_NOTIFY_INFO_DATA *current_data; NT_PRINTER_INFO_LEVEL *printer = NULL; print_queue_struct *queue=NULL; - size_t realloc_size = 0; - SPOOL_NOTIFY_INFO_DATA *info_data_ptr = NULL; type=option_type->type; @@ -2194,11 +2192,10 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int if (!search_notify(type, field, &j) ) continue; - realloc_size = (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA); - if((info_data_ptr=(SPOOL_NOTIFY_INFO_DATA *)Realloc(info_data_ptr, realloc_size)) == NULL) { + if((info->data=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) { return False; } - current_data=&info_data_ptr[info->count]; + current_data=&info->data[info->count]; construct_info_data(current_data, type, field, id); @@ -2211,12 +2208,6 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int info->count++; } - if (realloc_size) - info->data = talloc_memdup(mem_ctx, info_data_ptr, realloc_size); - else - info->data = NULL; - - safe_free(info_data_ptr); free_a_printer(&printer, 2); return True; } @@ -2226,6 +2217,7 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int * fill a notify_info struct with info asked * ********************************************************************/ + static BOOL construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_INFO *info, NT_PRINTER_INFO_LEVEL *printer, @@ -2236,7 +2228,6 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, int field_num,j; uint16 type; uint16 field; - SPOOL_NOTIFY_INFO_DATA *current_data; DEBUG(4,("construct_notify_jobs_info\n")); @@ -2257,9 +2248,13 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, return False; } - current_data=&(info->data[info->count]); + current_data=&info->data[info->count]; construct_info_data(current_data, type, field, id); + + DEBUG(10,("construct_notify_jobs_info: calling [%s] snum=%d printername=[%s])\n", + notify_info_data_table[j].name, snum, printer->info_2->printername )); + notify_info_data_table[j].fn(snum, current_data, queue, printer, mem_ctx); info->count++; @@ -2335,7 +2330,7 @@ static uint32 printserver_notify_info(const POLICY_HND *hnd, * Debugging information, don't delete. */ /* - DEBUG(1,("dumping the NOTIFY_INFO\n")); + DEBUG(1,("printserver_notify_info: dumping the NOTIFY_INFO\n")); DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count)); DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n")); @@ -2415,17 +2410,17 @@ static uint32 printer_notify_info(POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info, /* * Debugging information, don't delete. */ - /* - DEBUG(1,("dumping the NOTIFY_INFO\n")); - DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count)); - DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n")); + + DEBUG(10,("printer_notify_info: dumping the NOTIFY_INFO\n")); + DEBUGADD(10,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count)); + DEBUGADD(10,("num\ttype\tfield\tres\tid\tsize\tenc_type\n")); for (i=0; icount; i++) { - DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n", + DEBUGADD(10,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n", i, info->data[i].type, info->data[i].field, info->data[i].reserved, info->data[i].id, info->data[i].size, info->data[i].enc_type)); } - */ + return NT_STATUS_NO_PROBLEMO; } @@ -2477,7 +2472,25 @@ uint32 _spoolss_rfnpcnex( pipes_struct *p, SPOOL_Q_RFNPCNEX *q_u, SPOOL_R_RFNPCN result = printer_notify_info(handle, info, p->mem_ctx); break; } - + + /* + * The data returned in info->data is realloced. We need to + * convert to talloc for return. The data really should come + * back as a linked list, not a realloced array, as realloc can + * fail... JRA. + */ + + if (info->data) { + SPOOL_NOTIFY_INFO_DATA *new_data = (SPOOL_NOTIFY_INFO_DATA *)talloc_memdup(p->mem_ctx, + info->data, + info->count * sizeof(SPOOL_NOTIFY_INFO_DATA)); + if (!new_data) + return NT_STATUS_NO_MEMORY; + + safe_free(info->data); + info->data = new_data; + } + done: return result; } @@ -5024,7 +5037,7 @@ static uint32 enumprinterdrivers_level1(fstring servername, fstring architecture return ERROR_INSUFFICIENT_BUFFER; } - /* fill the buffer with the form structures */ + /* fill the buffer with the driver structures */ for (i=0; i<*returned; i++) { DEBUGADD(6,("adding driver [%d] to buffer\n",i)); new_smb_io_printer_driver_info_1("", buffer, &driver_info_1[i], 0); -- cgit From 93169a1f34f180f8a469a25532792f23e55e6966 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 3 Mar 2001 05:27:26 +0000 Subject: Roll back to using malloc/realloc on some of spoolss in head. I'm having problems with talloc_realloc in the 2.2 branch and I want a stable reference. The only problem is this breaks the clean auto-generated code in *one* call in srv_spoolss.c (the rfnpcnex call). Jeremy. (This used to be commit 57a9340cbafa40f3a41e6c676c6f2477855fd799) --- source3/rpc_server/srv_spoolss_nt.c | 114 ++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 57 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 2b6fb9a7e5..830f5cdcf4 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -149,7 +149,6 @@ static void free_spool_notify_option(SPOOL_NOTIFY_OPTION **pp) safe_free(sp->ctr.type); free(sp); - } /**************************************************************************** @@ -290,7 +289,6 @@ static BOOL srv_spoolss_replycloseprinter(POLICY_HND *handle) /**************************************************************************** close printer index by handle ****************************************************************************/ - static BOOL close_printer_handle(POLICY_HND *hnd) { Printer_entry *Printer = find_printer_index_by_hnd(hnd); @@ -310,6 +308,7 @@ static BOOL close_printer_handle(POLICY_HND *hnd) Printer->notify.localmachine[0]='\0'; Printer->notify.printerlocal=0; free_spool_notify_option(&Printer->notify.option); + Printer->notify.option=NULL; Printer->notify.client_connected=False; clear_handle(hnd); @@ -846,13 +845,13 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, /* NT doesn't let us connect to a printer if the connecting user doesn't have print permission. */ + if (!get_printer_snum(handle, &snum)) + return ERROR_INVALID_HANDLE; + /* map an empty access mask to the minimum access mask */ if (printer_default->access_required == 0x0) printer_default->access_required = PRINTER_ACCESS_USE; - if (!get_printer_snum(handle, &snum)) - return ERROR_INVALID_HANDLE; - if (!print_access_check(&user, snum, printer_default->access_required)) { DEBUG(3, ("access DENIED for printer open\n")); close_printer_handle(handle); @@ -1113,7 +1112,6 @@ uint32 _spoolss_deleteprinter(pipes_struct *p, SPOOL_Q_DELETEPRINTER *q_u, SPOOL /******************************************************************** GetPrinterData on a printer server Handle. ********************************************************************/ - static BOOL getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint32 *type, uint8 **data, uint32 *needed, uint32 in_size) { int i; @@ -1160,8 +1158,9 @@ static BOOL getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint32 pstring string="You are using a Samba server"; *type = 0x1; *needed = 2*(strlen(string)+1); - if((*data = (uint8 *)talloc_zero( ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL) + if((*data = (uint8 *)talloc(ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL) return False; + memset(*data, 0, (*needed > in_size) ? *needed:in_size); /* it's done by hand ready to go on the wire */ for (i=0; i in_size) ? *needed:in_size) *sizeof(uint8))) == NULL) + if((*data = (uint8 *)talloc(ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL) return False; + memset(*data, 0, (*needed > in_size) ? *needed:in_size); for (i=0; iin_size)?in_size:len *sizeof(uint8)); } else { @@ -1276,7 +1277,7 @@ uint32 _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO DEBUG(4,("_spoolss_getprinterdata\n")); if (!OPEN_HANDLE(Printer)) { - if((*data=(uint8 *)talloc_zero(p->mem_ctx, 4*sizeof(uint8))) == NULL) + if((*data=(uint8 *)malloc(4*sizeof(uint8))) == NULL) return ERROR_NOT_ENOUGH_MEMORY; DEBUG(0,("_spoolss_getprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; @@ -1366,12 +1367,12 @@ uint32 _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE } Printer->notify.flags=flags; + Printer->notify.options=options; Printer->notify.printerlocal=printerlocal; if (Printer->notify.option) free_spool_notify_option(&Printer->notify.option); - Printer->notify.options=options; Printer->notify.option=dup_spool_notify_option(option); unistr2_to_ascii(Printer->notify.localmachine, localmachine, sizeof(Printer->notify.localmachine)-1); @@ -2157,12 +2158,12 @@ static void construct_info_data(SPOOL_NOTIFY_INFO_DATA *info_data, uint16 type, info_data->enc_type = type_of_notify_info_data(type, field); } + /******************************************************************* * * fill a notify_info struct with info asked * ********************************************************************/ - static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPOOL_NOTIFY_OPTION_TYPE *option_type, uint32 id, @@ -2192,7 +2193,7 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int if (!search_notify(type, field, &j) ) continue; - if((info->data=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) { + if((info->data=(SPOOL_NOTIFY_INFO_DATA *)Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) { return False; } current_data=&info->data[info->count]; @@ -2217,7 +2218,6 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int * fill a notify_info struct with info asked * ********************************************************************/ - static BOOL construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_INFO *info, NT_PRINTER_INFO_LEVEL *printer, @@ -2228,6 +2228,7 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, int field_num,j; uint16 type; uint16 field; + SPOOL_NOTIFY_INFO_DATA *current_data; DEBUG(4,("construct_notify_jobs_info\n")); @@ -2248,13 +2249,9 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, return False; } - current_data=&info->data[info->count]; + current_data=&(info->data[info->count]); construct_info_data(current_data, type, field, id); - - DEBUG(10,("construct_notify_jobs_info: calling [%s] snum=%d printername=[%s])\n", - notify_info_data_table[j].name, snum, printer->info_2->printername )); - notify_info_data_table[j].fn(snum, current_data, queue, printer, mem_ctx); info->count++; @@ -2322,7 +2319,8 @@ static uint32 printserver_notify_info(const POLICY_HND *hnd, for (snum=0; snumversion:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count)); DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n")); @@ -2377,7 +2375,9 @@ static uint32 printer_notify_info(POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info, switch ( option_type->type ) { case PRINTER_NOTIFY_TYPE: - if(construct_notify_printer_info(info, snum, option_type, id, mem_ctx)) + if(construct_notify_printer_info(info, snum, + option_type, id, + mem_ctx)) id--; break; @@ -2387,7 +2387,8 @@ static uint32 printer_notify_info(POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info, memset(&status, 0, sizeof(status)); count = print_queue_status(snum, &queue, &status); - if (get_a_printer(&printer, 2, lp_servicename(snum)) != 0) + if (get_a_printer(&printer, 2, + lp_servicename(snum)) != 0) goto done; for (j=0; jversion:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count)); - DEBUGADD(10,("num\ttype\tfield\tres\tid\tsize\tenc_type\n")); + /* + DEBUG(1,("dumping the NOTIFY_INFO\n")); + DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count)); + DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n")); for (i=0; icount; i++) { - DEBUGADD(10,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n", + DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n", i, info->data[i].type, info->data[i].field, info->data[i].reserved, info->data[i].id, info->data[i].size, info->data[i].enc_type)); } - + */ return NT_STATUS_NO_PROBLEMO; } @@ -2472,25 +2473,7 @@ uint32 _spoolss_rfnpcnex( pipes_struct *p, SPOOL_Q_RFNPCNEX *q_u, SPOOL_R_RFNPCN result = printer_notify_info(handle, info, p->mem_ctx); break; } - - /* - * The data returned in info->data is realloced. We need to - * convert to talloc for return. The data really should come - * back as a linked list, not a realloced array, as realloc can - * fail... JRA. - */ - - if (info->data) { - SPOOL_NOTIFY_INFO_DATA *new_data = (SPOOL_NOTIFY_INFO_DATA *)talloc_memdup(p->mem_ctx, - info->data, - info->count * sizeof(SPOOL_NOTIFY_INFO_DATA)); - if (!new_data) - return NT_STATUS_NO_MEMORY; - - safe_free(info->data); - info->data = new_data; - } - + done: return result; } @@ -5291,14 +5274,14 @@ uint32 _new_spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_E DEBUGADD(5,("Offered buffer size [%d]\n", offered)); DEBUGADD(5,("Info level [%d]\n", level)); - *numofforms = get_ntforms(p->mem_ctx, &list); + *numofforms = get_ntforms(&list); DEBUGADD(5,("Number of forms [%d]\n", *numofforms)); if (*numofforms == 0) return ERROR_NO_MORE_ITEMS; switch (level) { case 1: - if ((forms_1=(FORM_1 *)talloc(p->mem_ctx, *numofforms * sizeof(FORM_1))) == NULL) { + if ((forms_1=(FORM_1 *)malloc(*numofforms * sizeof(FORM_1))) == NULL) { *numofforms=0; return ERROR_NOT_ENOUGH_MEMORY; } @@ -5309,6 +5292,8 @@ uint32 _new_spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_E fill_form_1(&forms_1[i], &list[i]); } + safe_free(list); + /* check the required size. */ for (i=0; i<*numofforms; i++) { DEBUGADD(6,("adding form [%d]'s size\n",i)); @@ -5317,8 +5302,10 @@ uint32 _new_spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_E *needed=buffer_size; - if (!alloc_buffer_size(buffer, buffer_size)) + if (!alloc_buffer_size(buffer, buffer_size)){ + safe_free(forms_1); return ERROR_INSUFFICIENT_BUFFER; + } /* fill the buffer with the form structures */ for (i=0; i<*numofforms; i++) { @@ -5326,6 +5313,8 @@ uint32 _new_spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_E new_smb_io_form_1("", buffer, &forms_1[i], 0); } + safe_free(forms_1); + if (*needed > offered) { *numofforms=0; return ERROR_INSUFFICIENT_BUFFER; @@ -5334,8 +5323,10 @@ uint32 _new_spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_E return NT_STATUS_NO_PROBLEMO; default: + safe_free(list); return ERROR_INVALID_LEVEL; } + } /**************************************************************************** @@ -5366,7 +5357,7 @@ uint32 _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * DEBUGADD(5,("Offered buffer size [%d]\n", offered)); DEBUGADD(5,("Info level [%d]\n", level)); - numofforms = get_ntforms(p->mem_ctx, &list); + numofforms = get_ntforms(&list); DEBUGADD(5,("Number of forms [%d]\n", numofforms)); if (numofforms == 0) @@ -5387,6 +5378,8 @@ uint32 _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * } } + safe_free(list); + /* check the required size. */ *needed=spoolss_size_form_1(&form_1); @@ -5406,6 +5399,7 @@ uint32 _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * return NT_STATUS_NO_PROBLEMO; default: + safe_free(list); return ERROR_INVALID_LEVEL; } } @@ -6183,12 +6177,14 @@ uint32 _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM return ERROR_INVALID_HANDLE; } - count=get_ntforms(p->mem_ctx, &list); - if(!add_a_form(p->mem_ctx, &list, form, &count)) + count=get_ntforms(&list); + if(!add_a_form(&list, form, &count)) return ERROR_NOT_ENOUGH_MEMORY; write_ntforms(&list, count); - return NT_STATUS_NOPROBLEMO; + safe_free(list); + + return 0x0; } /**************************************************************************** @@ -6211,10 +6207,12 @@ uint32 _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE return ERROR_INVALID_HANDLE; } - count = get_ntforms(p->mem_ctx, &list); + count = get_ntforms(&list); if(!delete_a_form(&list, form_name, &count, &ret)) return ERROR_INVALID_PARAMETER; + safe_free(list); + return ret; } @@ -6238,10 +6236,12 @@ uint32 _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM * DEBUG(0,("_spoolss_setform: Invalid handle (%s).\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; } - count=get_ntforms(p->mem_ctx, &list); + count=get_ntforms(&list); update_a_form(&list, form, count); write_ntforms(&list, count); + safe_free(list); + return 0x0; } -- cgit From e2e56e84f07c9427990a2269c5970c1acb4c3967 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 3 Mar 2001 06:47:37 +0000 Subject: Fixed up overrun read when marshelling SYSTEMTIME struct. This was a subtle one... Jeremy. (This used to be commit 65275e73ee7c58352ee20175cbbb43378e16f417) --- source3/rpc_server/srv_spoolss_nt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 830f5cdcf4..5c40052295 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1996,12 +1996,13 @@ static void spoolss_notify_submitted_time(int snum, { struct tm *t; uint32 len; + SYSTEMTIME st; t=gmtime(&queue->time); len = sizeof(SYSTEMTIME); - data->notify_data.data.length = len; + data->notify_data.data.length = len/2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -2009,7 +2010,8 @@ static void spoolss_notify_submitted_time(int snum, return; } - make_systemtime((SYSTEMTIME*)(data->notify_data.data.string), t); + make_systemtime(&st, t); + memcpy(data->notify_data.data.string,&st,len); } #define END 65535 -- cgit From 393bede7db6af546431cd5255e465b7b7b0e7c81 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 7 Mar 2001 23:59:13 +0000 Subject: Sync up handle creation with 2.2 branch. We can now join AS/U domains and authenticate against them. Big/little endian issues fixed. Jeremy. (This used to be commit 0e6a34510ed598eaec7fe71a9c91fda528a4675c) --- source3/rpc_server/srv_spoolss_nt.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 5c40052295..0fb38b84db 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -84,8 +84,8 @@ static ubi_dlList counter_list; static struct cli_state cli; static uint32 smb_connections=0; -#define OPEN_HANDLE(pnum) ((pnum!=NULL) && (pnum->open!=False) && (IVAL(pnum->printer_hnd.data,16)==(uint32)sys_getpid())) -#define OUR_HANDLE(pnum) ((pnum==NULL)?"NULL":(IVAL(pnum->data,16)==sys_getpid()?"OURS":"OTHER")) +#define OPEN_HANDLE(pnum) ((pnum!=NULL) && (pnum->open!=False) && (IVAL(pnum->printer_hnd.data5,4)==(uint32)sys_getpid())) +#define OUR_HANDLE(pnum) ((pnum==NULL)?"NULL":(IVAL(pnum->data5,4)==(uint32)sys_getpid()?"OURS":"OTHER")) /* translate between internal status numbers and NT status numbers */ static int nt_printj_status(int v) @@ -215,15 +215,7 @@ static void create_printer_hnd(POLICY_HND *hnd) if (hnd == NULL) return; - /* i severely doubt that prt_hnd_high will ever be non-zero... */ - prt_hnd_low++; - if (prt_hnd_low == 0) prt_hnd_high++; - - SIVAL(hnd->data, 0 , 0x0); /* first bit must be null */ - SIVAL(hnd->data, 4 , prt_hnd_low ); /* second bit is incrementing */ - SIVAL(hnd->data, 8 , prt_hnd_high); /* second bit is incrementing */ - SIVAL(hnd->data, 12, time(NULL)); /* something random */ - SIVAL(hnd->data, 16, sys_getpid()); /* something more random */ + create_policy_handle(hnd, &prt_hnd_low, &prt_hnd_high); } /**************************************************************************** -- cgit From da3053048c3d224a20d6383ac6682d31059cd46c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 11 Mar 2001 00:32:10 +0000 Subject: Merge of new 2.2 code into HEAD (Gerald I hate you :-) :-). Allows new SAMR RPC code to merge with new passdb code. Currently rpcclient doesn't compile. I'm working on it... Jeremy. (This used to be commit 0be41d5158ea4e645e93e8cd30617c038416e549) --- source3/rpc_server/srv_spoolss_nt.c | 434 ++++++++++++++++-------------------- 1 file changed, 198 insertions(+), 236 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 0fb38b84db..9fcf9930bf 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1,4 +1,3 @@ -#define OLD_NTDOMAIN 1 /* * Unix SMB/Netbios implementation. * Version 1.9. @@ -40,14 +39,9 @@ extern pstring global_myname; /* and the notify info asked about */ /* that's the central struct */ typedef struct _Printer{ - ubi_dlNode Next; - ubi_dlNode Prev; - - BOOL open; BOOL document_started; BOOL page_started; int jobid; /* jobid in printing backend */ - POLICY_HND printer_hnd; BOOL printer_type; union { fstring handlename; @@ -78,14 +72,12 @@ typedef struct _counter_printer_0 { uint32 counter; } counter_printer_0; -static ubi_dlList Printer_list; static ubi_dlList counter_list; static struct cli_state cli; static uint32 smb_connections=0; -#define OPEN_HANDLE(pnum) ((pnum!=NULL) && (pnum->open!=False) && (IVAL(pnum->printer_hnd.data5,4)==(uint32)sys_getpid())) -#define OUR_HANDLE(pnum) ((pnum==NULL)?"NULL":(IVAL(pnum->data5,4)==(uint32)sys_getpid()?"OURS":"OTHER")) +#define OUR_HANDLE(hnd) ((hnd==NULL)?"NULL":(IVAL(hnd->data5,4)==(uint32)sys_getpid()?"OURS":"OTHER")) /* translate between internal status numbers and NT status numbers */ static int nt_printj_status(int v) @@ -151,6 +143,56 @@ static void free_spool_notify_option(SPOOL_NOTIFY_OPTION **pp) free(sp); } +/*************************************************************************** + Disconnect from the client +****************************************************************************/ + +static void srv_spoolss_replycloseprinter(POLICY_HND *handle) +{ + uint32 status; + + /* weird if the test succeds !!! */ + if (smb_connections==0) { + DEBUG(0,("srv_spoolss_replycloseprinter:Trying to close non-existant notify backchannel !\n")); + return; + } + + if(!cli_spoolss_reply_close_printer(&cli, handle, &status)) + DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed.\n")); + + /* if it's the last connection, deconnect the IPC$ share */ + if (smb_connections==1) { + if(!spoolss_disconnect_from_client(&cli)) + return; + + message_deregister(MSG_PRINTER_NOTIFY); + } + + smb_connections--; +} + +/**************************************************************************** + Functions to free a printer entry datastruct. +****************************************************************************/ + +static void free_printer_entry(void *ptr) +{ + Printer_entry *Printer = (Printer_entry *)ptr; + + if (Printer->notify.client_connected==True) + srv_spoolss_replycloseprinter(&Printer->notify.client_hnd); + + Printer->notify.flags=0; + Printer->notify.options=0; + Printer->notify.localmachine[0]='\0'; + Printer->notify.printerlocal=0; + free_spool_notify_option(&Printer->notify.option); + Printer->notify.option=NULL; + Printer->notify.client_connected=False; + + safe_free(Printer); +} + /**************************************************************************** Functions to duplicate a SPOOL_NOTIFY_OPTION struct stored in Printer_entry. ****************************************************************************/ @@ -180,15 +222,6 @@ SPOOL_NOTIFY_OPTION *dup_spool_notify_option(SPOOL_NOTIFY_OPTION *sp) return new_sp; } -/**************************************************************************** - initialise printer handle states... -****************************************************************************/ -void init_printer_hnd(void) -{ - ubi_dlInitList(&Printer_list); - ubi_dlInitList(&counter_list); -} - /**************************************************************************** Return a user struct for a pipe user. ****************************************************************************/ @@ -205,109 +238,36 @@ static struct current_user *get_current_user(struct current_user *user, pipes_st return user; } -/**************************************************************************** - create a unique printer handle -****************************************************************************/ -static void create_printer_hnd(POLICY_HND *hnd) -{ - static uint32 prt_hnd_low = 0; - static uint32 prt_hnd_high = 0; - - if (hnd == NULL) return; - - create_policy_handle(hnd, &prt_hnd_low, &prt_hnd_high); -} - /**************************************************************************** find printer index by handle ****************************************************************************/ -static Printer_entry *find_printer_index_by_hnd(const POLICY_HND *hnd) -{ - Printer_entry *find_printer; - find_printer = (Printer_entry *)ubi_dlFirst(&Printer_list); - - for(; find_printer; find_printer = (Printer_entry *)ubi_dlNext(find_printer)) { - - if (memcmp(&(find_printer->printer_hnd), hnd, sizeof(*hnd)) == 0) { - DEBUG(4,("Found printer handle \n")); - /*dump_data(4, hnd->data, sizeof(hnd->data));*/ - return find_printer; - } - } - - DEBUG(3,("Whoops, Printer handle not found: ")); - /*dump_data(4, hnd->data, sizeof(hnd->data));*/ - return NULL; -} - -/**************************************************************************** - clear an handle -****************************************************************************/ -static void clear_handle(POLICY_HND *hnd) -{ - ZERO_STRUCTP(hnd); -} - -/*************************************************************************** - Disconnect from the client -****************************************************************************/ -static BOOL srv_spoolss_replycloseprinter(POLICY_HND *handle) +static Printer_entry *find_printer_index_by_hnd(pipes_struct *p, POLICY_HND *hnd) { - uint32 status; - - /* weird if the test succeds !!! */ - if (smb_connections==0) { - DEBUG(0,("srv_spoolss_replycloseprinter:Trying to close non-existant notify backchannel !\n")); - return False; - } - - if(!cli_spoolss_reply_close_printer(&cli, handle, &status)) - return False; - - /* if it's the last connection, deconnect the IPC$ share */ - if (smb_connections==1) { - if(!spoolss_disconnect_from_client(&cli)) - return False; + Printer_entry *find_printer = NULL; - message_deregister(MSG_PRINTER_NOTIFY); + if(!find_policy_by_hnd(p,hnd,(void **)&find_printer)) { + DEBUG(3,("find_printer_index_by_hnd: Printer handle not found: ")); + return NULL; } - smb_connections--; - - return True; + return find_printer; } /**************************************************************************** close printer index by handle ****************************************************************************/ -static BOOL close_printer_handle(POLICY_HND *hnd) + +static BOOL close_printer_handle(pipes_struct *p, POLICY_HND *hnd) { - Printer_entry *Printer = find_printer_index_by_hnd(hnd); + Printer_entry *Printer = find_printer_index_by_hnd(p, hnd); - if (!OPEN_HANDLE(Printer)) { + if (!Printer) { DEBUG(0,("close_printer_handle: Invalid handle (%s)\n", OUR_HANDLE(hnd))); return False; } - if (Printer->notify.client_connected==True) - if(!srv_spoolss_replycloseprinter(&Printer->notify.client_hnd)) - return ERROR_INVALID_HANDLE; - - Printer->open=False; - Printer->notify.flags=0; - Printer->notify.options=0; - Printer->notify.localmachine[0]='\0'; - Printer->notify.printerlocal=0; - free_spool_notify_option(&Printer->notify.option); - Printer->notify.option=NULL; - Printer->notify.client_connected=False; - - clear_handle(hnd); - - ubi_dlRemThis(&Printer_list, Printer); - - safe_free(Printer); + close_policy_hnd(p, hnd); return True; } @@ -315,11 +275,11 @@ static BOOL close_printer_handle(POLICY_HND *hnd) /**************************************************************************** delete a printer given a handle ****************************************************************************/ -static uint32 delete_printer_handle(POLICY_HND *hnd) +static uint32 delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) { - Printer_entry *Printer = find_printer_index_by_hnd(hnd); + Printer_entry *Printer = find_printer_index_by_hnd(p, hnd); - if (!OPEN_HANDLE(Printer)) { + if (!Printer) { DEBUG(0,("delete_printer_handle: Invalid handle (%s)\n", OUR_HANDLE(hnd))); return ERROR_INVALID_HANDLE; } @@ -387,11 +347,11 @@ static uint32 delete_printer_handle(POLICY_HND *hnd) /**************************************************************************** return the snum of a printer corresponding to an handle ****************************************************************************/ -static BOOL get_printer_snum(POLICY_HND *hnd, int *number) +static BOOL get_printer_snum(pipes_struct *p, POLICY_HND *hnd, int *number) { - Printer_entry *Printer = find_printer_index_by_hnd(hnd); + Printer_entry *Printer = find_printer_index_by_hnd(p, hnd); - if (!OPEN_HANDLE(Printer)) { + if (!Printer) { DEBUG(0,("get_printer_snum: Invalid handle (%s)\n", OUR_HANDLE(hnd))); return False; } @@ -411,11 +371,11 @@ static BOOL get_printer_snum(POLICY_HND *hnd, int *number) /**************************************************************************** set printer handle type. ****************************************************************************/ -static BOOL set_printer_hnd_accesstype(POLICY_HND *hnd, uint32 access_required) +static BOOL set_printer_hnd_accesstype(pipes_struct *p, POLICY_HND *hnd, uint32 access_required) { - Printer_entry *Printer = find_printer_index_by_hnd(hnd); + Printer_entry *Printer = find_printer_index_by_hnd(p, hnd); - if (!OPEN_HANDLE(Printer)) { + if (!Printer) { DEBUG(0,("set_printer_hnd_accesstype: Invalid handle (%s)", OUR_HANDLE(hnd))); return False; } @@ -581,38 +541,35 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) find first available printer slot. creates a printer handle for you. ****************************************************************************/ -static BOOL open_printer_hnd(POLICY_HND *hnd, char *name) +static BOOL open_printer_hnd(pipes_struct *p, POLICY_HND *hnd, char *name) { Printer_entry *new_printer; DEBUG(10,("open_printer_hnd: name [%s]\n", name)); - clear_handle(hnd); - create_printer_hnd(hnd); if((new_printer=(Printer_entry *)malloc(sizeof(Printer_entry))) == NULL) return False; ZERO_STRUCTP(new_printer); - new_printer->open = True; new_printer->notify.option=NULL; - memcpy(&new_printer->printer_hnd, hnd, sizeof(*hnd)); - - ubi_dlAddHead( &Printer_list, (ubi_dlNode *)new_printer); + if (!create_policy_hnd(p, hnd, free_printer_entry, new_printer)) { + safe_free(new_printer); + return False; + } if (!set_printer_hnd_printertype(new_printer, name)) { - close_printer_handle(hnd); + close_printer_handle(p, hnd); return False; } if (!set_printer_hnd_name(new_printer, name)) { - close_printer_handle(hnd); + close_printer_handle(p, hnd); return False; } - DEBUG(5, ("%d printer handles active\n", - (int)ubi_dlCount(&Printer_list))); + DEBUG(5, ("%d printer handles active\n", (int)p->pipe_handles.count )); return True; } @@ -620,11 +577,12 @@ static BOOL open_printer_hnd(POLICY_HND *hnd, char *name) /******************************************************************** Return True is the handle is a print server. ********************************************************************/ -static BOOL handle_is_printserver(const POLICY_HND *handle) + +static BOOL handle_is_printserver(pipes_struct *p, POLICY_HND *handle) { - Printer_entry *Printer=find_printer_index_by_hnd(handle); + Printer_entry *Printer=find_printer_index_by_hnd(p,handle); - if (!OPEN_HANDLE(Printer)) + if (!Printer) return False; if (Printer->printer_type != PRINTER_HANDLE_IS_PRINTSERVER) @@ -670,11 +628,12 @@ static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size) /*************************************************************************** receive the notify message ****************************************************************************/ + void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size_t len) { fstring printer; uint32 status; - Printer_entry *find_printer; + struct pipes_struct *p; *printer = '\0'; fstrcpy(printer,buf); @@ -686,36 +645,45 @@ void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size_t len) DEBUG(10,("srv_spoolss_receive_message: Got message about printer %s\n", printer )); - find_printer = (Printer_entry *)ubi_dlFirst(&Printer_list); + /* We need to enumerate all our pipes and all printers on them. */ + for ( p = get_first_pipe(); p; get_next_pipe(p)) { + struct policy *pol; - /* Iterate the printer list. */ - for(; find_printer; find_printer = (Printer_entry *)ubi_dlNext(find_printer)) { + if (!strequal(p->name, "spoolss")) + continue; - /* - * if the entry is the given printer or if it's a printerserver - * we send the message - */ + /* Iterate the printer list on this pipe. */ + for (pol = p->pipe_handles.Policy; pol; pol = pol->next ) { + Printer_entry *find_printer = (Printer_entry *)pol->data_ptr; - if (find_printer->printer_type==PRINTER_HANDLE_IS_PRINTER) - if (strcmp(find_printer->dev.handlename, printer)) + if (!find_printer) continue; - if (find_printer->notify.client_connected==True) - cli_spoolss_reply_rrpcn(&cli, &find_printer->notify.client_hnd, PRINTER_CHANGE_ALL, 0x0, &status); + /* + * if the entry is the given printer or if it's a printerserver + * we send the message + */ + + if (find_printer->printer_type==PRINTER_HANDLE_IS_PRINTER) + if (strcmp(find_printer->dev.handlename, printer)) + continue; + if (find_printer->notify.client_connected==True) + cli_spoolss_reply_rrpcn(&cli, &find_printer->notify.client_hnd, PRINTER_CHANGE_ALL, 0x0, &status); + } } } /*************************************************************************** send a notify event ****************************************************************************/ -static BOOL srv_spoolss_sendnotify(POLICY_HND *handle) +static BOOL srv_spoolss_sendnotify(pipes_struct *p, POLICY_HND *handle) { fstring printer; - Printer_entry *Printer=find_printer_index_by_hnd(handle); + Printer_entry *Printer=find_printer_index_by_hnd(p, handle); - if (!OPEN_HANDLE(Printer)) { + if (!Printer) { DEBUG(0,("srv_spoolss_sendnotify: Invalid handle (%s).\n", OUR_HANDLE(handle))); return False; } @@ -767,7 +735,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, DEBUGADD(3,("checking name: %s\n",name)); - if (!open_printer_hnd(handle, name)) + if (!open_printer_hnd(p, handle, name)) return ERROR_INVALID_PRINTER_NAME; /* @@ -780,8 +748,8 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, set_printer_hnd_datatype(handle, ""); */ - if (!set_printer_hnd_accesstype(handle, printer_default->access_required)) { - close_printer_handle(handle); + if (!set_printer_hnd_accesstype(p, handle, printer_default->access_required)) { + close_printer_handle(p, handle); return ERROR_ACCESS_DENIED; } @@ -810,7 +778,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, get_current_user(&user, p); - if (handle_is_printserver(handle)) { + if (handle_is_printserver(p, handle)) { if (printer_default->access_required == 0) { return NT_STATUS_NO_PROBLEMO; } @@ -820,14 +788,14 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, snum = -1; if (!lp_ms_add_printer_wizard()) { - close_printer_handle(handle); + close_printer_handle(p, handle); return ERROR_ACCESS_DENIED; } else if (user.uid == 0 || user_in_list(uidtoname(user.uid), lp_printer_admin(snum))) { return NT_STATUS_NO_PROBLEMO; } else { - close_printer_handle(handle); + close_printer_handle(p, handle); return ERROR_ACCESS_DENIED; } } @@ -837,7 +805,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, /* NT doesn't let us connect to a printer if the connecting user doesn't have print permission. */ - if (!get_printer_snum(handle, &snum)) + if (!get_printer_snum(p, handle, &snum)) return ERROR_INVALID_HANDLE; /* map an empty access mask to the minimum access mask */ @@ -846,7 +814,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, if (!print_access_check(&user, snum, printer_default->access_required)) { DEBUG(3, ("access DENIED for printer open\n")); - close_printer_handle(handle); + close_printer_handle(p, handle); return ERROR_ACCESS_DENIED; } @@ -919,7 +887,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, if (printer_default->devmode_cont.devmode != NULL) { result = printer_write_default_dev( snum, printer_default); if (result != 0) { - close_printer_handle(handle); + close_printer_handle(p, handle); return result; } } @@ -1038,11 +1006,11 @@ BOOL convert_devicemode(char *printername, const DEVICEMODE *devmode, * _spoolss_enddocprinter_internal. ********************************************************************/ -static uint32 _spoolss_enddocprinter_internal(POLICY_HND *handle) +static uint32 _spoolss_enddocprinter_internal(pipes_struct *p, POLICY_HND *handle) { - Printer_entry *Printer=find_printer_index_by_hnd(handle); + Printer_entry *Printer=find_printer_index_by_hnd(p, handle); - if (!OPEN_HANDLE(Printer)) { + if (!Printer) { DEBUG(0,("_spoolss_enddocprinter_internal: Invalid handle (%s)\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; } @@ -1062,14 +1030,14 @@ uint32 _spoolss_closeprinter(pipes_struct *p, SPOOL_Q_CLOSEPRINTER *q_u, SPOOL_R { POLICY_HND *handle = &q_u->handle; - Printer_entry *Printer=find_printer_index_by_hnd(handle); + Printer_entry *Printer=find_printer_index_by_hnd(p, handle); if (Printer && Printer->document_started) - _spoolss_enddocprinter_internal(handle); /* print job was not closed */ + _spoolss_enddocprinter_internal(p, handle); /* print job was not closed */ memcpy(&r_u->handle, &q_u->handle, sizeof(r_u->handle)); - if (!close_printer_handle(handle)) + if (!close_printer_handle(p, handle)) return ERROR_INVALID_HANDLE; return NT_STATUS_NO_PROBLEMO; @@ -1084,18 +1052,18 @@ uint32 _spoolss_deleteprinter(pipes_struct *p, SPOOL_Q_DELETEPRINTER *q_u, SPOOL { POLICY_HND *handle = &q_u->handle; - Printer_entry *Printer=find_printer_index_by_hnd(handle); + Printer_entry *Printer=find_printer_index_by_hnd(p, handle); uint32 result; if (Printer && Printer->document_started) - _spoolss_enddocprinter_internal(handle); /* print job was not closed */ + _spoolss_enddocprinter_internal(p, handle); /* print job was not closed */ memcpy(&r_u->handle, &q_u->handle, sizeof(r_u->handle)); - result = delete_printer_handle(handle); + result = delete_printer_handle(p, handle); if (result == ERROR_SUCCESS) { - srv_spoolss_sendnotify(handle); + srv_spoolss_sendnotify(p, handle); } return result; @@ -1182,7 +1150,7 @@ static BOOL getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint32 /******************************************************************** GetPrinterData on a printer Handle. ********************************************************************/ -static BOOL getprinterdata_printer(TALLOC_CTX *ctx, POLICY_HND *handle, +static BOOL getprinterdata_printer(pipes_struct *p, TALLOC_CTX *ctx, POLICY_HND *handle, fstring value, uint32 *type, uint8 **data, uint32 *needed, uint32 in_size ) { @@ -1190,16 +1158,16 @@ static BOOL getprinterdata_printer(TALLOC_CTX *ctx, POLICY_HND *handle, int snum=0; uint8 *idata=NULL; uint32 len; - Printer_entry *Printer = find_printer_index_by_hnd(handle); + Printer_entry *Printer = find_printer_index_by_hnd(p, handle); DEBUG(5,("getprinterdata_printer\n")); - if (!OPEN_HANDLE(Printer)) { + if (!Printer) { DEBUG(0,("getprinterdata_printer: Invalid handle (%s).\n", OUR_HANDLE(handle))); return False; } - if(!get_printer_snum(handle, &snum)) + if(!get_printer_snum(p, handle, &snum)) return False; if(get_a_printer(&printer, 2, lp_servicename(snum)) != 0) @@ -1251,7 +1219,7 @@ uint32 _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO fstring value; BOOL found=False; - Printer_entry *Printer = find_printer_index_by_hnd(handle); + Printer_entry *Printer = find_printer_index_by_hnd(p, handle); /* * Reminder: when it's a string, the length is in BYTES @@ -1268,7 +1236,7 @@ uint32 _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO DEBUG(4,("_spoolss_getprinterdata\n")); - if (!OPEN_HANDLE(Printer)) { + if (!Printer) { if((*data=(uint8 *)malloc(4*sizeof(uint8))) == NULL) return ERROR_NOT_ENOUGH_MEMORY; DEBUG(0,("_spoolss_getprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); @@ -1277,10 +1245,10 @@ uint32 _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO unistr2_to_ascii(value, valuename, sizeof(value)-1); - if (handle_is_printserver(handle)) + if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) found=getprinterdata_printer_server(p->mem_ctx, value, type, data, needed, *out_size); else - found= getprinterdata_printer(p->mem_ctx, handle, value, type, data, needed, *out_size); + found= getprinterdata_printer(p, p->mem_ctx, handle, value, type, data, needed, *out_size); if (found==False) { DEBUG(5, ("value not found, allocating %d\n", *out_size)); @@ -1351,9 +1319,9 @@ uint32 _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE /* store the notify value in the printer struct */ - Printer_entry *Printer=find_printer_index_by_hnd(handle); + Printer_entry *Printer=find_printer_index_by_hnd(p, handle); - if (!OPEN_HANDLE(Printer)) { + if (!Printer) { DEBUG(0,("_spoolss_rffpcnex: Invalid handle (%s).\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; } @@ -1786,13 +1754,11 @@ static void spoolss_notify_status(int snum, NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) { - int count; - print_queue_struct *q=NULL; print_status_struct status; memset(&status, 0, sizeof(status)); - count = print_queue_status(snum, &q, &status); + print_queue_status(snum, &q, &status); data->notify_data.value[0]=(uint32) status.status; safe_free(q); } @@ -2277,20 +2243,19 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, * that's the print server case, the printer case is even worse. */ - - /******************************************************************* * * enumerate all printers on the printserver * fill a notify_info struct with info asked * ********************************************************************/ -static uint32 printserver_notify_info(const POLICY_HND *hnd, + +static uint32 printserver_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info, TALLOC_CTX *mem_ctx) { int snum; - Printer_entry *Printer=find_printer_index_by_hnd(hnd); + Printer_entry *Printer=find_printer_index_by_hnd(p, hnd); int n_services=lp_numservices(); int i; uint32 id; @@ -2341,11 +2306,11 @@ static uint32 printserver_notify_info(const POLICY_HND *hnd, * fill a notify_info struct with info asked * ********************************************************************/ -static uint32 printer_notify_info(POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info, +static uint32 printer_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info, TALLOC_CTX *mem_ctx) { int snum; - Printer_entry *Printer=find_printer_index_by_hnd(hnd); + Printer_entry *Printer=find_printer_index_by_hnd(p, hnd); int i; uint32 id; SPOOL_NOTIFY_OPTION *option; @@ -2362,7 +2327,7 @@ static uint32 printer_notify_info(POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info, info->data=NULL; info->count=0; - get_printer_snum(hnd, &snum); + get_printer_snum(p, hnd, &snum); for (i=0; icount; i++) { option_type=&option->ctr.type[i]; @@ -2430,13 +2395,13 @@ uint32 _spoolss_rfnpcnex( pipes_struct *p, SPOOL_Q_RFNPCNEX *q_u, SPOOL_R_RFNPCN /* SPOOL_NOTIFY_OPTION *option = q_u->option; - notused. */ SPOOL_NOTIFY_INFO *info = &r_u->info; - Printer_entry *Printer=find_printer_index_by_hnd(handle); + Printer_entry *Printer=find_printer_index_by_hnd(p, handle); uint32 result = ERROR_INVALID_HANDLE; /* we always have a NOTIFY_INFO struct */ r_u->info_ptr=0x1; - if (!OPEN_HANDLE(Printer)) { + if (!Printer) { DEBUG(0,("_spoolss_rfnpcnex: Invalid handle (%s).\n", OUR_HANDLE(handle))); goto done; @@ -2459,12 +2424,11 @@ uint32 _spoolss_rfnpcnex( pipes_struct *p, SPOOL_Q_RFNPCNEX *q_u, SPOOL_R_RFNPCN switch (Printer->printer_type) { case PRINTER_HANDLE_IS_PRINTSERVER: - result = printserver_notify_info(handle, info, - p->mem_ctx); + result = printserver_notify_info(p, handle, info, p->mem_ctx); break; case PRINTER_HANDLE_IS_PRINTER: - result = printer_notify_info(handle, info, p->mem_ctx); + result = printer_notify_info(p, handle, info, p->mem_ctx); break; } @@ -3312,7 +3276,7 @@ uint32 _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GET *needed=0; - if (!get_printer_snum(handle, &snum)) + if (!get_printer_snum(p, handle, &snum)) return ERROR_INVALID_HANDLE; switch (level) { @@ -3831,7 +3795,7 @@ uint32 _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_ pstrcpy(servername, global_myname); unistr2_to_ascii(architecture, uni_arch, sizeof(architecture)-1); - if (!get_printer_snum(handle, &snum)) + if (!get_printer_snum(p, handle, &snum)) return ERROR_INVALID_HANDLE; switch (level) { @@ -3855,9 +3819,9 @@ uint32 _spoolss_startpageprinter(pipes_struct *p, SPOOL_Q_STARTPAGEPRINTER *q_u, { POLICY_HND *handle = &q_u->handle; - Printer_entry *Printer = find_printer_index_by_hnd(handle); + Printer_entry *Printer = find_printer_index_by_hnd(p, handle); - if (OPEN_HANDLE(Printer)) { + if (Printer) { Printer->page_started=True; return 0x0; } @@ -3873,9 +3837,9 @@ uint32 _spoolss_endpageprinter(pipes_struct *p, SPOOL_Q_ENDPAGEPRINTER *q_u, SPO { POLICY_HND *handle = &q_u->handle; - Printer_entry *Printer = find_printer_index_by_hnd(handle); + Printer_entry *Printer = find_printer_index_by_hnd(p, handle); - if (!OPEN_HANDLE(Printer)) { + if (!Printer) { DEBUG(0,("_spoolss_endpageprinter: Invalid handle (%s).\n",OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; } @@ -3902,10 +3866,10 @@ uint32 _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, S int snum; pstring jobname; fstring datatype; - Printer_entry *Printer = find_printer_index_by_hnd(handle); + Printer_entry *Printer = find_printer_index_by_hnd(p, handle); struct current_user user; - if (!OPEN_HANDLE(Printer)) { + if (!Printer) { DEBUG(0,("_spoolss_startdocprinter: Invalid handle (%s)\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; } @@ -3933,7 +3897,7 @@ uint32 _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, S } /* get the share number of the printer */ - if (!get_printer_snum(handle, &snum)) { + if (!get_printer_snum(p, handle, &snum)) { return ERROR_INVALID_HANDLE; } @@ -3964,7 +3928,7 @@ uint32 _spoolss_enddocprinter(pipes_struct *p, SPOOL_Q_ENDDOCPRINTER *q_u, SPOOL { POLICY_HND *handle = &q_u->handle; - return _spoolss_enddocprinter_internal(handle); + return _spoolss_enddocprinter_internal(p, handle); } /**************************************************************************** @@ -3977,9 +3941,9 @@ uint32 _spoolss_writeprinter(pipes_struct *p, SPOOL_Q_WRITEPRINTER *q_u, SPOOL_R uint8 *buffer = q_u->buffer; uint32 *buffer_written = &q_u->buffer_size2; - Printer_entry *Printer = find_printer_index_by_hnd(handle); + Printer_entry *Printer = find_printer_index_by_hnd(p, handle); - if (!OPEN_HANDLE(Printer)) { + if (!Printer) { DEBUG(0,("_spoolss_writeprinter: Invalid handle (%s)\n",OUR_HANDLE(handle))); r_u->buffer_written = q_u->buffer_size2; return ERROR_INVALID_HANDLE; @@ -4003,16 +3967,16 @@ static uint32 control_printer(POLICY_HND *handle, uint32 command, { struct current_user user; int snum, errcode = ERROR_INVALID_FUNCTION; - Printer_entry *Printer = find_printer_index_by_hnd(handle); + Printer_entry *Printer = find_printer_index_by_hnd(p, handle); get_current_user(&user, p); - if (!OPEN_HANDLE(Printer)) { + if (!Printer) { DEBUG(0,("control_printer: Invalid handle (%s)\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; } - if (!get_printer_snum(handle, &snum)) + if (!get_printer_snum(p, handle, &snum)) return ERROR_INVALID_HANDLE; switch (command) { @@ -4063,9 +4027,9 @@ static uint32 update_printer_sec(POLICY_HND *handle, uint32 level, uint32 result; int snum; - Printer_entry *Printer = find_printer_index_by_hnd(handle); + Printer_entry *Printer = find_printer_index_by_hnd(p, handle); - if (!OPEN_HANDLE(Printer) || !get_printer_snum(handle, &snum)) { + if (!Printer || !get_printer_snum(p, handle, &snum)) { DEBUG(0,("update_printer_sec: Invalid handle (%s)\n", OUR_HANDLE(handle))); @@ -4478,13 +4442,13 @@ static BOOL nt_printer_info_level_equal(NT_PRINTER_INFO_LEVEL *p1, * when updating a printer description ********************************************************************/ -static uint32 update_printer(POLICY_HND *handle, uint32 level, +static uint32 update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, const SPOOL_PRINTER_INFO_LEVEL *info, DEVICEMODE *devmode) { int snum; NT_PRINTER_INFO_LEVEL *printer = NULL, *old_printer = NULL; - Printer_entry *Printer = find_printer_index_by_hnd(handle); + Printer_entry *Printer = find_printer_index_by_hnd(p, handle); uint32 result; DEBUG(8,("update_printer\n")); @@ -4498,12 +4462,12 @@ static uint32 update_printer(POLICY_HND *handle, uint32 level, goto done; } - if (!OPEN_HANDLE(Printer)) { + if (!Printer) { result = ERROR_INVALID_HANDLE; goto done; } - if (!get_printer_snum(handle, &snum)) { + if (!get_printer_snum(p, handle, &snum)) { result = ERROR_INVALID_HANDLE; goto done; } @@ -4582,7 +4546,7 @@ static uint32 update_printer(POLICY_HND *handle, uint32 level, free_a_printer(&printer, 2); free_a_printer(&old_printer, 2); - srv_spoolss_sendnotify(handle); + srv_spoolss_sendnotify(p, handle); return result; } @@ -4599,9 +4563,9 @@ uint32 _spoolss_setprinter(pipes_struct *p, SPOOL_Q_SETPRINTER *q_u, SPOOL_R_SET SEC_DESC_BUF *secdesc_ctr = q_u->secdesc_ctr; uint32 command = q_u->command; - Printer_entry *Printer = find_printer_index_by_hnd(handle); + Printer_entry *Printer = find_printer_index_by_hnd(p, handle); - if (!OPEN_HANDLE(Printer)) { + if (!Printer) { DEBUG(0,("_spoolss_setprinter: Invalid handle (%s)\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; } @@ -4611,7 +4575,7 @@ uint32 _spoolss_setprinter(pipes_struct *p, SPOOL_Q_SETPRINTER *q_u, SPOOL_R_SET case 0: return control_printer(handle, command, p); case 2: - return update_printer(handle, level, info, devmode_ctr.devmode); + return update_printer(p, handle, level, info, devmode_ctr.devmode); case 3: return update_printer_sec(handle, level, info, p, secdesc_ctr); @@ -4627,16 +4591,15 @@ uint32 _spoolss_fcpn(pipes_struct *p, SPOOL_Q_FCPN *q_u, SPOOL_R_FCPN *r_u) { POLICY_HND *handle = &q_u->handle; - Printer_entry *Printer= find_printer_index_by_hnd(handle); + Printer_entry *Printer= find_printer_index_by_hnd(p, handle); - if (!OPEN_HANDLE(Printer)) { + if (!Printer) { DEBUG(0,("_spoolss_fcpn: Invalid handle (%s)\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; } if (Printer->notify.client_connected==True) - if(!srv_spoolss_replycloseprinter(&Printer->notify.client_hnd)) - return ERROR_INVALID_HANDLE; + srv_spoolss_replycloseprinter(&Printer->notify.client_hnd); Printer->notify.flags=0; Printer->notify.options=0; @@ -4872,7 +4835,7 @@ uint32 _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO *needed=0; *returned=0; - if (!get_printer_snum(handle, &snum)) + if (!get_printer_snum(p, handle, &snum)) return ERROR_INVALID_HANDLE; *returned = print_queue_status(snum, &queue, &prt_status); @@ -4920,7 +4883,7 @@ uint32 _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u memset(&prt_status, 0, sizeof(prt_status)); - if (!get_printer_snum(handle, &snum)) { + if (!get_printer_snum(p, handle, &snum)) { return ERROR_INVALID_HANDLE; } @@ -5647,7 +5610,7 @@ uint32 _spoolss_enumports( pipes_struct *p, SPOOL_Q_ENUMPORTS *q_u, SPOOL_R_ENUM /**************************************************************************** ****************************************************************************/ -static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name, +static uint32 spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_srv_name, const SPOOL_PRINTER_INFO_LEVEL *info, uint32 unk0, uint32 unk1, uint32 unk2, uint32 unk3, uint32 user_switch, const SPOOL_USER_CTR *user, @@ -5702,7 +5665,7 @@ static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name, return ERROR_ACCESS_DENIED; } - if (!open_printer_hnd(handle, name)) { + if (!open_printer_hnd(p, handle, name)) { /* Handle open failed - remove addition. */ del_a_printer(printer->info_2->sharename); free_a_printer(&printer,2); @@ -5711,7 +5674,7 @@ static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name, free_a_printer(&printer,2); - srv_spoolss_sendnotify(handle); + srv_spoolss_sendnotify(p, handle); return NT_STATUS_NO_PROBLEMO; } @@ -5738,7 +5701,7 @@ uint32 _spoolss_addprinterex( pipes_struct *p, SPOOL_Q_ADDPRINTEREX *q_u, SPOOL_ /* but I know what to do ... */ return ERROR_INVALID_LEVEL; case 2: - return spoolss_addprinterex_level_2(uni_srv_name, info, + return spoolss_addprinterex_level_2(p, uni_srv_name, info, unk0, unk1, unk2, unk3, user_switch, user, handle); default: @@ -5886,7 +5849,7 @@ uint32 _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S uint32 biggest_valuesize; uint32 biggest_datasize; uint32 data_len; - Printer_entry *Printer = find_printer_index_by_hnd(handle); + Printer_entry *Printer = find_printer_index_by_hnd(p, handle); int snum; uint8 *data=NULL; uint32 type; @@ -5905,12 +5868,12 @@ uint32 _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S DEBUG(5,("spoolss_enumprinterdata\n")); - if (!OPEN_HANDLE(Printer)) { + if (!Printer) { DEBUG(0,("_spoolss_enumprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; } - if (!get_printer_snum(handle, &snum)) + if (!get_printer_snum(p,handle, &snum)) return ERROR_INVALID_HANDLE; if (get_a_printer(&printer, 2, lp_servicename(snum)) != 0) @@ -6045,16 +6008,16 @@ uint32 _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP NT_PRINTER_PARAM *param = NULL, old_param; int snum=0; uint32 status = 0x0; - Printer_entry *Printer=find_printer_index_by_hnd(handle); + Printer_entry *Printer=find_printer_index_by_hnd(p, handle); DEBUG(5,("spoolss_setprinterdata\n")); - if (!OPEN_HANDLE(Printer)) { + if (!Printer) { DEBUG(0,("_spoolss_setprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; } - if (!get_printer_snum(handle, &snum)) + if (!get_printer_snum(p,handle, &snum)) return ERROR_INVALID_HANDLE; status = get_a_printer(&printer, 2, lp_servicename(snum)); @@ -6117,16 +6080,16 @@ uint32 _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_ NT_PRINTER_PARAM param; int snum=0; uint32 status = 0x0; - Printer_entry *Printer=find_printer_index_by_hnd(handle); + Printer_entry *Printer=find_printer_index_by_hnd(p, handle); DEBUG(5,("spoolss_deleteprinterdata\n")); - if (!OPEN_HANDLE(Printer)) { + if (!Printer) { DEBUG(0,("_spoolss_deleteprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; } - if (!get_printer_snum(handle, &snum)) + if (!get_printer_snum(p, handle, &snum)) return ERROR_INVALID_HANDLE; if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { @@ -6162,11 +6125,11 @@ uint32 _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM int count=0; nt_forms_struct *list=NULL; - Printer_entry *Printer = find_printer_index_by_hnd(handle); + Printer_entry *Printer = find_printer_index_by_hnd(p, handle); DEBUG(5,("spoolss_addform\n")); - if (!OPEN_HANDLE(Printer)) { + if (!Printer) { DEBUG(0,("_spoolss_addform: Invalid handle (%s).\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; } @@ -6192,11 +6155,11 @@ uint32 _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE int count=0; uint32 ret = 0; nt_forms_struct *list=NULL; - Printer_entry *Printer = find_printer_index_by_hnd(handle); + Printer_entry *Printer = find_printer_index_by_hnd(p, handle); DEBUG(5,("spoolss_deleteform\n")); - if (!OPEN_HANDLE(Printer)) { + if (!Printer) { DEBUG(0,("_spoolss_deleteform: Invalid handle (%s).\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; } @@ -6222,11 +6185,11 @@ uint32 _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM * int count=0; nt_forms_struct *list=NULL; - Printer_entry *Printer = find_printer_index_by_hnd(handle); + Printer_entry *Printer = find_printer_index_by_hnd(p, handle); DEBUG(5,("spoolss_setform\n")); - if (!OPEN_HANDLE(Printer)) { + if (!Printer) { DEBUG(0,("_spoolss_setform: Invalid handle (%s).\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; } @@ -6605,7 +6568,7 @@ uint32 _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_ *needed=0; - if (!get_printer_snum(handle, &snum)) + if (!get_printer_snum(p, handle, &snum)) return ERROR_INVALID_HANDLE; count = print_queue_status(snum, &queue, &prt_status); @@ -6623,4 +6586,3 @@ uint32 _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_ return ERROR_INVALID_LEVEL; } } -#undef OLD_NTDOMAIN -- cgit From e532d96a26055d23450bfb3e9c28e0179ee9f2d2 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 13 Mar 2001 20:18:45 +0000 Subject: Move to a handle database per pipe name, not per pipe. Jeremy. (This used to be commit a24b248a77ccac364832ff7d4df083d437caf9ed) --- source3/rpc_server/srv_spoolss_nt.c | 53 +++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 20 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 9fcf9930bf..804fe8a523 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -569,7 +569,7 @@ static BOOL open_printer_hnd(pipes_struct *p, POLICY_HND *hnd, char *name) return False; } - DEBUG(5, ("%d printer handles active\n", (int)p->pipe_handles.count )); + DEBUG(5, ("%d printer handles active\n", (int)p->pipe_handles->count )); return True; } @@ -634,6 +634,8 @@ void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size_t len) fstring printer; uint32 status; struct pipes_struct *p; + struct policy *pol; + struct handle_list *hl; *printer = '\0'; fstrcpy(printer,buf); @@ -645,32 +647,43 @@ void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size_t len) DEBUG(10,("srv_spoolss_receive_message: Got message about printer %s\n", printer )); - /* We need to enumerate all our pipes and all printers on them. */ + /* + * We need to enumerate all printers. The handle list is shared + * across pipes of the same name, so just find the first open + * spoolss pipe. + */ + + hl = NULL; for ( p = get_first_pipe(); p; get_next_pipe(p)) { - struct policy *pol; + if (strequal(p->name, "spoolss")) { + hl = p->pipe_handles; + break; + } + } - if (!strequal(p->name, "spoolss")) - continue; + if (!hl) { + DEBUG(0,("srv_spoolss_receive_message: no handle list on spoolss pipe !\n")); + return; + } - /* Iterate the printer list on this pipe. */ - for (pol = p->pipe_handles.Policy; pol; pol = pol->next ) { - Printer_entry *find_printer = (Printer_entry *)pol->data_ptr; + /* Iterate the printer list on this pipe. */ + for (pol = hl->Policy; pol; pol = pol->next ) { + Printer_entry *find_printer = (Printer_entry *)pol->data_ptr; - if (!find_printer) - continue; + if (!find_printer) + continue; - /* - * if the entry is the given printer or if it's a printerserver - * we send the message - */ + /* + * if the entry is the given printer or if it's a printerserver + * we send the message + */ - if (find_printer->printer_type==PRINTER_HANDLE_IS_PRINTER) - if (strcmp(find_printer->dev.handlename, printer)) - continue; + if (find_printer->printer_type==PRINTER_HANDLE_IS_PRINTER) + if (strcmp(find_printer->dev.handlename, printer)) + continue; - if (find_printer->notify.client_connected==True) - cli_spoolss_reply_rrpcn(&cli, &find_printer->notify.client_hnd, PRINTER_CHANGE_ALL, 0x0, &status); - } + if (find_printer->notify.client_connected==True) + cli_spoolss_reply_rrpcn(&cli, &find_printer->notify.client_hnd, PRINTER_CHANGE_ALL, 0x0, &status); } } -- cgit From 25d975e5500243dff4918fe04416695cd3e79a72 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 27 Mar 2001 18:19:01 +0000 Subject: merge from 2.2. (This used to be commit 817258f1174d27d74e8b21ffb5f1384db2238007) --- source3/rpc_server/srv_spoolss_nt.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 804fe8a523..5234fa3366 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3103,7 +3103,7 @@ uint32 _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOOL_ fstring name; /* that's an [in out] buffer */ - new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + spoolss_move_buffer(q_u->buffer, &r_u->buffer); buffer = r_u->buffer; DEBUG(4,("_spoolss_enumprinters\n")); @@ -3284,7 +3284,7 @@ uint32 _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GET int snum; /* that's an [in out] buffer */ - new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + spoolss_move_buffer(q_u->buffer, &r_u->buffer); buffer = r_u->buffer; *needed=0; @@ -3796,7 +3796,7 @@ uint32 _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_ int snum; /* that's an [in out] buffer */ - new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + spoolss_move_buffer(q_u->buffer, &r_u->buffer); buffer = r_u->buffer; DEBUG(4,("_spoolss_getprinterdriver2\n")); @@ -4631,7 +4631,7 @@ uint32 _spoolss_fcpn(pipes_struct *p, SPOOL_Q_FCPN *q_u, SPOOL_R_FCPN *r_u) uint32 _spoolss_addjob(pipes_struct *p, SPOOL_Q_ADDJOB *q_u, SPOOL_R_ADDJOB *r_u) { /* that's an [in out] buffer (despite appearences to the contrary) */ - new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + spoolss_move_buffer(q_u->buffer, &r_u->buffer); r_u->needed = 0; return ERROR_INVALID_PARAMETER; /* this is what a NT server @@ -4838,7 +4838,7 @@ uint32 _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO print_status_struct prt_status; /* that's an [in out] buffer */ - new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + spoolss_move_buffer(q_u->buffer, &r_u->buffer); buffer = r_u->buffer; DEBUG(4,("_spoolss_enumjobs\n")); @@ -5180,7 +5180,7 @@ uint32 _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS fstring architecture; /* that's an [in out] buffer */ - new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + spoolss_move_buffer(q_u->buffer, &r_u->buffer); buffer = r_u->buffer; DEBUG(4,("_spoolss_enumprinterdrivers\n")); @@ -5222,7 +5222,7 @@ static void fill_form_1(FORM_1 *form, nt_forms_struct *list) /**************************************************************************** ****************************************************************************/ -uint32 _new_spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMFORMS *r_u) +uint32 _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMFORMS *r_u) { /* POLICY_HND *handle = &q_u->handle; - notused. */ uint32 level = q_u->level; @@ -5237,10 +5237,10 @@ uint32 _new_spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_E int i; /* that's an [in out] buffer */ - new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + spoolss_move_buffer(q_u->buffer, &r_u->buffer); buffer = r_u->buffer; - DEBUG(4,("_new_spoolss_enumforms\n")); + DEBUG(4,("_spoolss_enumforms\n")); DEBUGADD(5,("Offered buffer size [%d]\n", offered)); DEBUGADD(5,("Info level [%d]\n", level)); @@ -5318,7 +5318,7 @@ uint32 _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * int numofforms, i; /* that's an [in out] buffer */ - new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + spoolss_move_buffer(q_u->buffer, &r_u->buffer); buffer = r_u->buffer; unistr2_to_ascii(form_name, uni_formname, sizeof(form_name)-1); @@ -5603,7 +5603,7 @@ uint32 _spoolss_enumports( pipes_struct *p, SPOOL_Q_ENUMPORTS *q_u, SPOOL_R_ENUM uint32 *returned = &r_u->returned; /* that's an [in out] buffer */ - new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + spoolss_move_buffer(q_u->buffer, &r_u->buffer); buffer = r_u->buffer; DEBUG(4,("_spoolss_enumports\n")); @@ -5822,7 +5822,7 @@ uint32 _spoolss_getprinterdriverdirectory(pipes_struct *p, SPOOL_Q_GETPRINTERDRI uint32 *needed = &r_u->needed; /* that's an [in out] buffer */ - new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + spoolss_move_buffer(q_u->buffer, &r_u->buffer); buffer = r_u->buffer; DEBUG(4,("_spoolss_getprinterdriverdirectory\n")); @@ -6260,7 +6260,7 @@ uint32 _spoolss_enumprintprocessors(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCESSORS uint32 *returned = &r_u->returned; /* that's an [in out] buffer */ - new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + spoolss_move_buffer(q_u->buffer, &r_u->buffer); buffer = r_u->buffer; DEBUG(5,("spoolss_enumprintprocessors\n")); @@ -6328,7 +6328,7 @@ uint32 _spoolss_enumprintprocdatatypes(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCDAT uint32 *returned = &r_u->returned; /* that's an [in out] buffer */ - new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + spoolss_move_buffer(q_u->buffer, &r_u->buffer); buffer = r_u->buffer; DEBUG(5,("_spoolss_enumprintprocdatatypes\n")); @@ -6422,7 +6422,7 @@ uint32 _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS *q_ uint32 *returned = &r_u->returned; /* that's an [in out] buffer */ - new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + spoolss_move_buffer(q_u->buffer, &r_u->buffer); buffer = r_u->buffer; DEBUG(5,("spoolss_enumprintmonitors\n")); @@ -6572,7 +6572,7 @@ uint32 _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_ print_status_struct prt_status; /* that's an [in out] buffer */ - new_spoolss_move_buffer(q_u->buffer, &r_u->buffer); + spoolss_move_buffer(q_u->buffer, &r_u->buffer); buffer = r_u->buffer; DEBUG(5,("spoolss_getjob\n")); -- cgit From 738a83a14f1eba8fceeec41ab81c7e9da944ccda Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 28 Mar 2001 16:08:00 +0000 Subject: rename of 16 new_smb_io functions to smb_io_* for consistency sake (merge from 2.2) (This used to be commit ea963a648b889da9e47661c61c7fafe13b277e75) --- source3/rpc_server/srv_spoolss_nt.c | 46 ++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 5234fa3366..1360e14db0 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2853,7 +2853,7 @@ static BOOL enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 of /* fill the buffer with the structures */ for (i=0; i<*returned; i++) - new_smb_io_printer_info_1("", buffer, &printers[i], 0); + smb_io_printer_info_1("", buffer, &printers[i], 0); /* clear memory */ safe_free(printers); @@ -2935,7 +2935,7 @@ static BOOL enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, ui } /* fill the buffer with the structures */ - new_smb_io_printer_info_1("", buffer, printer, 0); + smb_io_printer_info_1("", buffer, printer, 0); /* clear memory */ safe_free(printer); @@ -3001,7 +3001,7 @@ static BOOL enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint32 /* fill the buffer with the structures */ for (i=0; i<*returned; i++) - new_smb_io_printer_info_2("", buffer, &(printers[i]), 0); + smb_io_printer_info_2("", buffer, &(printers[i]), 0); /* clear memory */ for (i=0; i<*returned; i++) { @@ -3161,7 +3161,7 @@ static uint32 getprinter_level_0(int snum, NEW_BUFFER *buffer, uint32 offered, u } /* fill the buffer with the structures */ - new_smb_io_printer_info_0("", buffer, printer, 0); + smb_io_printer_info_0("", buffer, printer, 0); /* clear memory */ safe_free(printer); @@ -3193,7 +3193,7 @@ static uint32 getprinter_level_1(int snum, NEW_BUFFER *buffer, uint32 offered, u } /* fill the buffer with the structures */ - new_smb_io_printer_info_1("", buffer, printer, 0); + smb_io_printer_info_1("", buffer, printer, 0); /* clear memory */ safe_free(printer); @@ -3225,7 +3225,7 @@ static uint32 getprinter_level_2(int snum, NEW_BUFFER *buffer, uint32 offered, u } /* fill the buffer with the structures */ - if (!new_smb_io_printer_info_2("", buffer, printer, 0)) { + if (!smb_io_printer_info_2("", buffer, printer, 0)) { free_printer_info_2(printer); return ERROR_NOT_ENOUGH_MEMORY; } @@ -3258,7 +3258,7 @@ static uint32 getprinter_level_3(int snum, NEW_BUFFER *buffer, uint32 offered, u } /* fill the buffer with the structures */ - new_smb_io_printer_info_3("", buffer, printer, 0); + smb_io_printer_info_3("", buffer, printer, 0); /* clear memory */ free_printer_info_3(printer); @@ -3662,7 +3662,7 @@ static uint32 getprinterdriver2_level1(fstring servername, fstring architecture, } /* fill the buffer with the structures */ - new_smb_io_printer_driver_info_1("", buffer, info, 0); + smb_io_printer_driver_info_1("", buffer, info, 0); /* clear memory */ safe_free(info); @@ -3698,7 +3698,7 @@ static uint32 getprinterdriver2_level2(fstring servername, fstring architecture, } /* fill the buffer with the structures */ - new_smb_io_printer_driver_info_2("", buffer, info, 0); + smb_io_printer_driver_info_2("", buffer, info, 0); /* clear memory */ safe_free(info); @@ -3732,7 +3732,7 @@ static uint32 getprinterdriver2_level3(fstring servername, fstring architecture, } /* fill the buffer with the structures */ - new_smb_io_printer_driver_info_3("", buffer, &info, 0); + smb_io_printer_driver_info_3("", buffer, &info, 0); free_printer_driver_info_3(&info); @@ -3765,7 +3765,7 @@ static uint32 getprinterdriver2_level6(fstring servername, fstring architecture, } /* fill the buffer with the structures */ - new_smb_io_printer_driver_info_6("", buffer, &info, 0); + smb_io_printer_driver_info_6("", buffer, &info, 0); free_printer_driver_info_6(&info); @@ -4750,7 +4750,7 @@ static uint32 enumjobs_level1(print_queue_struct *queue, int snum, /* fill the buffer with the structures */ for (i=0; i<*returned; i++) - new_smb_io_job_info_1("", buffer, &info[i], 0); + smb_io_job_info_1("", buffer, &info[i], 0); /* clear memory */ safe_free(info); @@ -4802,7 +4802,7 @@ static uint32 enumjobs_level2(print_queue_struct *queue, int snum, /* fill the buffer with the structures */ for (i=0; i<*returned; i++) - new_smb_io_job_info_2("", buffer, &info[i], 0); + smb_io_job_info_2("", buffer, &info[i], 0); /* clear memory */ for (i = 0; i < *returned; i++) @@ -4993,7 +4993,7 @@ static uint32 enumprinterdrivers_level1(fstring servername, fstring architecture /* fill the buffer with the driver structures */ for (i=0; i<*returned; i++) { DEBUGADD(6,("adding driver [%d] to buffer\n",i)); - new_smb_io_printer_driver_info_1("", buffer, &driver_info_1[i], 0); + smb_io_printer_driver_info_1("", buffer, &driver_info_1[i], 0); } safe_free(driver_info_1); @@ -5069,7 +5069,7 @@ static uint32 enumprinterdrivers_level2(fstring servername, fstring architecture /* fill the buffer with the form structures */ for (i=0; i<*returned; i++) { DEBUGADD(6,("adding driver [%d] to buffer\n",i)); - new_smb_io_printer_driver_info_2("", buffer, &(driver_info_2[i]), 0); + smb_io_printer_driver_info_2("", buffer, &(driver_info_2[i]), 0); } safe_free(driver_info_2); @@ -5145,7 +5145,7 @@ static uint32 enumprinterdrivers_level3(fstring servername, fstring architecture /* fill the buffer with the driver structures */ for (i=0; i<*returned; i++) { DEBUGADD(6,("adding driver [%d] to buffer\n",i)); - new_smb_io_printer_driver_info_3("", buffer, &driver_info_3[i], 0); + smb_io_printer_driver_info_3("", buffer, &driver_info_3[i], 0); } for (i=0; i<*returned; i++) @@ -5280,7 +5280,7 @@ uint32 _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMF /* fill the buffer with the form structures */ for (i=0; i<*numofforms; i++) { DEBUGADD(6,("adding form [%d] to buffer\n",i)); - new_smb_io_form_1("", buffer, &forms_1[i], 0); + smb_io_form_1("", buffer, &forms_1[i], 0); } safe_free(forms_1); @@ -5364,7 +5364,7 @@ uint32 _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * /* fill the buffer with the form structures */ DEBUGADD(6,("adding form %s [%d] to buffer\n", form_name, i)); - new_smb_io_form_1("", buffer, &form_1, 0); + smb_io_form_1("", buffer, &form_1, 0); return NT_STATUS_NO_PROBLEMO; @@ -5477,7 +5477,7 @@ static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need /* fill the buffer with the ports structures */ for (i=0; i<*returned; i++) { DEBUGADD(6,("adding port [%d] to buffer\n", i)); - new_smb_io_port_1("", buffer, &ports[i], 0); + smb_io_port_1("", buffer, &ports[i], 0); } safe_free(ports); @@ -5576,7 +5576,7 @@ static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need /* fill the buffer with the ports structures */ for (i=0; i<*returned; i++) { DEBUGADD(6,("adding port [%d] to buffer\n", i)); - new_smb_io_port_2("", buffer, &ports[i], 0); + smb_io_port_2("", buffer, &ports[i], 0); } safe_free(ports); @@ -5799,7 +5799,7 @@ static uint32 getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen return ERROR_INSUFFICIENT_BUFFER; } - new_smb_io_driverdir_1("", buffer, info, 0); + smb_io_driverdir_1("", buffer, info, 0); safe_free(info); @@ -6485,7 +6485,7 @@ static uint32 getjob_level_1(print_queue_struct *queue, int count, int snum, uin return ERROR_INSUFFICIENT_BUFFER; } - new_smb_io_job_info_1("", buffer, info_1, 0); + smb_io_job_info_1("", buffer, info_1, 0); safe_free(info_1); @@ -6543,7 +6543,7 @@ static uint32 getjob_level_2(print_queue_struct *queue, int count, int snum, uin return ERROR_INSUFFICIENT_BUFFER; } - new_smb_io_job_info_2("", buffer, info_2, 0); + smb_io_job_info_2("", buffer, info_2, 0); free_job_info_2(info_2); free(info_2); -- cgit From 24a4483a9c77041d5c188935cbf688f25f1f2f54 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 3 Apr 2001 22:52:38 +0000 Subject: test commit for jeremy (This used to be commit d747ab8ab37ca20635f99a9dff64a635461852a6) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 1360e14db0..f01de4570c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -41,7 +41,7 @@ extern pstring global_myname; typedef struct _Printer{ BOOL document_started; BOOL page_started; - int jobid; /* jobid in printing backend */ + int jobid; /* jobid in printing backend */ BOOL printer_type; union { fstring handlename; -- cgit From 5948fa9fe1992b54378e73f9bd17ef64f6b96ece Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 3 Apr 2001 23:09:04 +0000 Subject: Missed forms update - my CVS mistake. Jeremy. (This used to be commit 06dee898607ff2bf194d53fb55ad6d82e8f305e8) --- source3/rpc_server/srv_spoolss_nt.c | 91 ++++++++++++++++++++++++++++--------- 1 file changed, 70 insertions(+), 21 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index f01de4570c..90147c868a 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -41,7 +41,7 @@ extern pstring global_myname; typedef struct _Printer{ BOOL document_started; BOOL page_started; - int jobid; /* jobid in printing backend */ + int jobid; /* jobid in printing backend */ BOOL printer_type; union { fstring handlename; @@ -5230,8 +5230,10 @@ uint32 _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMF uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; uint32 *numofforms = &r_u->numofforms; + uint32 numbuiltinforms; nt_forms_struct *list=NULL; + nt_forms_struct *builtinlist=NULL; FORM_1 *forms_1; int buffer_size=0; int i; @@ -5244,8 +5246,11 @@ uint32 _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMF DEBUGADD(5,("Offered buffer size [%d]\n", offered)); DEBUGADD(5,("Info level [%d]\n", level)); + numbuiltinforms = get_builtin_ntforms(&builtinlist); + DEBUGADD(5,("Number of builtin forms [%d]\n", numbuiltinforms)); *numofforms = get_ntforms(&list); - DEBUGADD(5,("Number of forms [%d]\n", *numofforms)); + DEBUGADD(5,("Number of user forms [%d]\n", *numofforms)); + *numofforms += numbuiltinforms; if (*numofforms == 0) return ERROR_NO_MORE_ITEMS; @@ -5257,15 +5262,26 @@ uint32 _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMF } /* construct the list of form structures */ - for (i=0; i<*numofforms; i++) { + for (i=0; ineeded; nt_forms_struct *list=NULL; + nt_forms_struct builtin_form; + BOOL foundBuiltin; FORM_1 form_1; fstring form_name; int buffer_size=0; @@ -5327,29 +5350,38 @@ uint32 _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * DEBUGADD(5,("Offered buffer size [%d]\n", offered)); DEBUGADD(5,("Info level [%d]\n", level)); - numofforms = get_ntforms(&list); - DEBUGADD(5,("Number of forms [%d]\n", numofforms)); + foundBuiltin = get_a_builtin_ntform(uni_formname,&builtin_form); + if (!foundBuiltin) { + numofforms = get_ntforms(&list); + DEBUGADD(5,("Number of forms [%d]\n", numofforms)); - if (numofforms == 0) - return ERROR_NO_MORE_ITEMS; + if (numofforms == 0) + return ERROR_INVALID_HANDLE; + } switch (level) { case 1: + if (foundBuiltin) { + fill_form_1(&form_1, &builtin_form); + } else { - /* Check if the requested name is in the list of form structures */ - for (i=0; ihandle; /* uint32 level = q_u->level; - notused. */ FORM *form = &q_u->form; + nt_forms_struct tmpForm; int count=0; nt_forms_struct *list=NULL; @@ -6147,6 +6180,11 @@ uint32 _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM return ERROR_INVALID_HANDLE; } + /* can't add if builtin */ + if (get_a_builtin_ntform(&form->name,&tmpForm)) { + return ERROR_INVALID_PARAMETER; + } + count=get_ntforms(&list); if(!add_a_form(&list, form, &count)) return ERROR_NOT_ENOUGH_MEMORY; @@ -6164,7 +6202,7 @@ uint32 _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE { POLICY_HND *handle = &q_u->handle; UNISTR2 *form_name = &q_u->name; - + nt_forms_struct tmpForm; int count=0; uint32 ret = 0; nt_forms_struct *list=NULL; @@ -6177,6 +6215,11 @@ uint32 _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE return ERROR_INVALID_HANDLE; } + /* can't delete if builtin */ + if (get_a_builtin_ntform(form_name,&tmpForm)) { + return ERROR_INVALID_PARAMETER; + } + count = get_ntforms(&list); if(!delete_a_form(&list, form_name, &count, &ret)) return ERROR_INVALID_PARAMETER; @@ -6195,6 +6238,7 @@ uint32 _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM * /* UNISTR2 *uni_name = &q_u->name; - notused. */ /* uint32 level = q_u->level; - notused. */ FORM *form = &q_u->form; + nt_forms_struct tmpForm; int count=0; nt_forms_struct *list=NULL; @@ -6206,6 +6250,11 @@ uint32 _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM * DEBUG(0,("_spoolss_setform: Invalid handle (%s).\n", OUR_HANDLE(handle))); return ERROR_INVALID_HANDLE; } + /* can't set if builtin */ + if (get_a_builtin_ntform(&form->name,&tmpForm)) { + return ERROR_INVALID_PARAMETER; + } + count=get_ntforms(&list); update_a_form(&list, form, count); write_ntforms(&list, count); -- cgit From 950f1d9605179d75ab0755cecffbabbde769beb9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 7 Apr 2001 00:36:38 +0000 Subject: Added 3 params to manipulate shares. "add share command/change share command/ delete share command". Implemented "delete" - more work to come on add and change. Jeremy. (This used to be commit 2e6b1759e14456421066ee131af70a495f862f2b) --- source3/rpc_server/srv_spoolss_nt.c | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 90147c868a..c75af92902 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -222,22 +222,6 @@ SPOOL_NOTIFY_OPTION *dup_spool_notify_option(SPOOL_NOTIFY_OPTION *sp) return new_sp; } -/**************************************************************************** - Return a user struct for a pipe user. -****************************************************************************/ - -static struct current_user *get_current_user(struct current_user *user, pipes_struct *p) -{ - if (p->ntlmssp_auth_validated) { - memcpy(user, &p->pipe_user, sizeof(struct current_user)); - } else { - extern struct current_user current_user; - memcpy(user, ¤t_user, sizeof(struct current_user)); - } - - return user; -} - /**************************************************************************** find printer index by handle ****************************************************************************/ -- cgit From 09a5daf032b6e206e9371e63ca06ef60ef841b6a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 12 Apr 2001 07:00:08 +0000 Subject: Changed lp_add/delete/enum scripts to use lockdir if spool dir doesn't exist for printer. Rather than using pid for suffix, use a 16 byte random string. Created generate_random_str() function in genrand.c. Still needs more testing but this is the way to go. Jeremy. (This used to be commit 71a330987f990007beb16f00fc468107361b5e9d) --- source3/rpc_server/srv_spoolss_nt.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index c75af92902..f91168d3e4 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -285,7 +285,6 @@ static uint32 delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) if (*lp_deleteprinter_cmd()) { - pid_t local_pid = sys_getpid(); char *cmd = lp_deleteprinter_cmd(); char *path; pstring tmp_file; @@ -296,13 +295,13 @@ static uint32 delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) if (*lp_pathname(lp_servicenumber(PRINTERS_NAME))) path = lp_pathname(lp_servicenumber(PRINTERS_NAME)); else - path = tmpdir(); + path = lp_lockdir(); /* Printer->dev.handlename equals portname equals sharename */ slprintf(command, sizeof(command)-1, "%s \"%s\"", cmd, Printer->dev.handlename); dos_to_unix(command, True); /* Convert printername to unix-codepage */ - slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%d", path, local_pid); + slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%s", path, generate_random_str(16)); unlink(tmp_file); DEBUG(10,("Running [%s > %s]\n", command,tmp_file)); @@ -4133,7 +4132,6 @@ static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) ****************************************************************************/ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) { - pid_t local_pid = sys_getpid(); char *cmd = lp_addprinter_cmd(); char *path; char **qlines; @@ -4146,15 +4144,15 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) if (*lp_pathname(lp_servicenumber(PRINTERS_NAME))) path = lp_pathname(lp_servicenumber(PRINTERS_NAME)); else - path = tmpdir(); + path = lp_lockdir(); /* build driver path... only 9X architecture is needed for legacy reasons */ slprintf(driverlocation, sizeof(driverlocation)-1, "\\\\%s\\print$\\WIN40\\0", global_myname); /* change \ to \\ for the shell */ all_string_sub(driverlocation,"\\","\\\\",sizeof(pstring)); - - slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%d", path, local_pid); + + slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%s", path, generate_random_str(16)); slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"", cmd, printer->info_2->printername, printer->info_2->sharename, printer->info_2->portname, printer->info_2->drivername, @@ -5418,7 +5416,6 @@ static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need int i=0; if (*lp_enumports_cmd()) { - pid_t local_pid = sys_getpid(); char *cmd = lp_enumports_cmd(); char *path; char **qlines; @@ -5430,9 +5427,9 @@ static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need if (*lp_pathname(lp_servicenumber(PRINTERS_NAME))) path = lp_pathname(lp_servicenumber(PRINTERS_NAME)); else - path = tmpdir(); + path = lp_lockdir(); - slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%d", path, local_pid); + slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%s", path, generate_random_str(16)); slprintf(command, sizeof(command)-1, "%s \"%d\"", cmd, 1); unlink(tmp_file); @@ -5516,7 +5513,6 @@ static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need int i=0; if (*lp_enumports_cmd()) { - pid_t local_pid = sys_getpid(); char *cmd = lp_enumports_cmd(); char *path; char **qlines; @@ -5528,9 +5524,9 @@ static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need if (*lp_pathname(lp_servicenumber(PRINTERS_NAME))) path = lp_pathname(lp_servicenumber(PRINTERS_NAME)); else - path = tmpdir(); + path = lp_lockdir(); - slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%d", path, local_pid); + slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%s", path, generate_random_str(16)); slprintf(command, sizeof(command)-1, "%s \"%d\"", cmd, 2); unlink(tmp_file); -- cgit From 50e78a9ac8cf0949c2471fafde844c674f97d73d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 13 Apr 2001 00:37:00 +0000 Subject: As Andrew suggested, make smbrun return a fd for a deleted file which can then be read. Jeremy. (This used to be commit e7d59d6de89a5fdd201e4b5c6072dab08b1519db) --- source3/rpc_server/srv_spoolss_nt.c | 58 +++++++++++++++---------------------- 1 file changed, 23 insertions(+), 35 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index f91168d3e4..3bf44cd041 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -286,33 +286,21 @@ static uint32 delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) if (*lp_deleteprinter_cmd()) { 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 = lp_lockdir(); - /* Printer->dev.handlename equals portname equals sharename */ slprintf(command, sizeof(command)-1, "%s \"%s\"", cmd, Printer->dev.handlename); dos_to_unix(command, True); /* Convert printername to unix-codepage */ - slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%s", path, generate_random_str(16)); - unlink(tmp_file); - DEBUG(10,("Running [%s > %s]\n", command,tmp_file)); - ret = smbrun(command, tmp_file, False); + DEBUG(10,("Running [%s]\n", command)); + ret = smbrun(command, NULL, NULL); if (ret != 0) { - unlink(tmp_file); return ERROR_INVALID_HANDLE; /* What to return here? */ } DEBUGADD(10,("returned [%d]\n", ret)); - DEBUGADD(10,("Unlinking output file [%s]\n", tmp_file)); - unlink(tmp_file); /* Send SIGHUP to process group... is there a better way? */ kill(0, SIGHUP); @@ -4140,6 +4128,7 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) pstring driverlocation; int numlines; int ret; + int fd; if (*lp_pathname(lp_servicenumber(PRINTERS_NAME))) path = lp_pathname(lp_servicenumber(PRINTERS_NAME)); @@ -4152,31 +4141,29 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) /* change \ to \\ for the shell */ all_string_sub(driverlocation,"\\","\\\\",sizeof(pstring)); - slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%s", path, generate_random_str(16)); + slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%d.", path, sys_getpid()); slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"", cmd, printer->info_2->printername, printer->info_2->sharename, printer->info_2->portname, printer->info_2->drivername, printer->info_2->location, driverlocation); - unlink(tmp_file); - /* Convert script args to unix-codepage */ dos_to_unix(command, True); DEBUG(10,("Running [%s > %s]\n", command,tmp_file)); - ret = smbrun(command, tmp_file, False); + ret = smbrun(command, &fd, tmp_file); DEBUGADD(10,("returned [%d]\n", ret)); if ( ret != 0 ) { - unlink(tmp_file); + if (fd != -1) + close(fd); return False; } numlines = 0; /* Get lines and convert them back to dos-codepage */ - qlines = file_lines_load(tmp_file, &numlines, True); + qlines = fd_lines_load(fd, &numlines, True); DEBUGADD(10,("Lines returned = [%d]\n", numlines)); - DEBUGADD(10,("Unlinking script output file [%s]\n", tmp_file)); - unlink(tmp_file); + close(fd); if(numlines) { /* Set the portname to what the script says the portname should be. */ @@ -5423,30 +5410,30 @@ static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need pstring command; int numlines; int ret; + int fd; if (*lp_pathname(lp_servicenumber(PRINTERS_NAME))) path = lp_pathname(lp_servicenumber(PRINTERS_NAME)); else path = lp_lockdir(); - slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%s", path, generate_random_str(16)); + slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%d.", path, sys_getpid()); slprintf(command, sizeof(command)-1, "%s \"%d\"", cmd, 1); - unlink(tmp_file); DEBUG(10,("Running [%s > %s]\n", command,tmp_file)); - ret = smbrun(command, tmp_file, False); + ret = smbrun(command, &fd, tmp_file); DEBUG(10,("Returned [%d]\n", ret)); if (ret != 0) { - unlink(tmp_file); + if (fd != -1) + close(fd); /* Is this the best error to return here? */ return ERROR_ACCESS_DENIED; } numlines = 0; - qlines = file_lines_load(tmp_file, &numlines,True); + qlines = fd_lines_load(fd, &numlines,True); DEBUGADD(10,("Lines returned = [%d]\n", numlines)); - DEBUGADD(10,("Unlinking port file [%s]\n", tmp_file)); - unlink(tmp_file); + close(fd); if(numlines) { if((ports=(PORT_INFO_1 *)malloc( numlines * sizeof(PORT_INFO_1) )) == NULL) { @@ -5520,30 +5507,31 @@ static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need pstring command; int numlines; int ret; + int fd; if (*lp_pathname(lp_servicenumber(PRINTERS_NAME))) path = lp_pathname(lp_servicenumber(PRINTERS_NAME)); else path = lp_lockdir(); - slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%s", path, generate_random_str(16)); + slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%d.", path, sys_getpid()); slprintf(command, sizeof(command)-1, "%s \"%d\"", cmd, 2); unlink(tmp_file); DEBUG(10,("Running [%s > %s]\n", command,tmp_file)); - ret = smbrun(command, tmp_file, False); + ret = smbrun(command, &fd, tmp_file); DEBUGADD(10,("returned [%d]\n", ret)); if (ret != 0) { - unlink(tmp_file); + if (fd != -1) + close(fd); /* Is this the best error to return here? */ return ERROR_ACCESS_DENIED; } numlines = 0; - qlines = file_lines_load(tmp_file, &numlines,True); + qlines = fd_lines_load(fd, &numlines,True); DEBUGADD(10,("Lines returned = [%d]\n", numlines)); - DEBUGADD(10,("Unlinking port file [%s]\n", tmp_file)); - unlink(tmp_file); + close(fd); if(numlines) { if((ports=(PORT_INFO_2 *)malloc( numlines * sizeof(PORT_INFO_2) )) == NULL) { -- cgit From 2ef68c7e92d4661664f0410509f7cb551e74a198 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 13 Apr 2001 19:12:06 +0000 Subject: Merge of Andrew's changes in 2.2. Jeremy. (This used to be commit fc76681812b1469208ad6c8847afdfc68bc6db49) --- source3/rpc_server/srv_spoolss_nt.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 3bf44cd041..917885eafb 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -296,7 +296,7 @@ static uint32 delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) dos_to_unix(command, True); /* Convert printername to unix-codepage */ DEBUG(10,("Running [%s]\n", command)); - ret = smbrun(command, NULL, NULL); + ret = smbrun(command, NULL); if (ret != 0) { return ERROR_INVALID_HANDLE; /* What to return here? */ } @@ -4123,7 +4123,6 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) char *cmd = lp_addprinter_cmd(); char *path; char **qlines; - pstring tmp_file; pstring command; pstring driverlocation; int numlines; @@ -4141,16 +4140,15 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) /* change \ to \\ for the shell */ all_string_sub(driverlocation,"\\","\\\\",sizeof(pstring)); - slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%d.", path, sys_getpid()); slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"", cmd, printer->info_2->printername, printer->info_2->sharename, printer->info_2->portname, printer->info_2->drivername, printer->info_2->location, driverlocation); - /* Convert script args to unix-codepage */ - dos_to_unix(command, True); - DEBUG(10,("Running [%s > %s]\n", command,tmp_file)); - ret = smbrun(command, &fd, tmp_file); + /* Convert script args to unix-codepage */ + dos_to_unix(command, True); + DEBUG(10,("Running [%s]\n", command)); + ret = smbrun(command, &fd); DEBUGADD(10,("returned [%d]\n", ret)); if ( ret != 0 ) { @@ -4160,7 +4158,7 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) } numlines = 0; - /* Get lines and convert them back to dos-codepage */ + /* Get lines and convert them back to dos-codepage */ qlines = fd_lines_load(fd, &numlines, True); DEBUGADD(10,("Lines returned = [%d]\n", numlines)); close(fd); @@ -5307,7 +5305,7 @@ uint32 _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * FORM_1 form_1; fstring form_name; int buffer_size=0; - int numofforms, i; + int numofforms=0, i; /* that's an [in out] buffer */ spoolss_move_buffer(q_u->buffer, &r_u->buffer); @@ -5406,7 +5404,6 @@ static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need char *cmd = lp_enumports_cmd(); char *path; char **qlines; - pstring tmp_file; pstring command; int numlines; int ret; @@ -5417,11 +5414,10 @@ static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need else path = lp_lockdir(); - slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%d.", path, sys_getpid()); slprintf(command, sizeof(command)-1, "%s \"%d\"", cmd, 1); - DEBUG(10,("Running [%s > %s]\n", command,tmp_file)); - ret = smbrun(command, &fd, tmp_file); + DEBUG(10,("Running [%s]\n", command)); + ret = smbrun(command, &fd); DEBUG(10,("Returned [%d]\n", ret)); if (ret != 0) { if (fd != -1) @@ -5519,7 +5515,7 @@ static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need unlink(tmp_file); DEBUG(10,("Running [%s > %s]\n", command,tmp_file)); - ret = smbrun(command, &fd, tmp_file); + ret = smbrun(command, &fd); DEBUGADD(10,("returned [%d]\n", ret)); if (ret != 0) { if (fd != -1) @@ -6045,7 +6041,7 @@ uint32 _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP ZERO_STRUCT(old_param); if (get_specific_param(*printer, 2, param->value, &old_param.data, - &old_param.type, (unsigned int *)&old_param.data_len)) { + &old_param.type, (uint32 *)&old_param.data_len)) { if (param->type == old_param.type && param->data_len == old_param.data_len && -- cgit From af08cd21eb714abc019656bc8cee86fd7a3f20d6 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 16 Apr 2001 02:35:35 +0000 Subject: Getting medieval with compiler warnings as Jeremy puts it. (This used to be commit d05c3cf0f47a3c863adbed7ad4ab8f3248cd072d) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 917885eafb..57f95873fc 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -5305,7 +5305,7 @@ uint32 _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * FORM_1 form_1; fstring form_name; int buffer_size=0; - int numofforms=0, i; + int numofforms=0, i=0; /* that's an [in out] buffer */ spoolss_move_buffer(q_u->buffer, &r_u->buffer); -- cgit From 30c0777c1f5cd6953f8e0f279458c73700a206b9 Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Fri, 27 Apr 2001 17:08:33 +0000 Subject: fix a bug in printer name handling that jerry reported. names can be \\server -> print server \\server\printer -> printer printer -> printer J.F. (This used to be commit ec576722b79e3c5384dd40c532d4233dd6b1b9a8) --- source3/rpc_server/srv_spoolss_nt.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 57f95873fc..6dbf90ba8a 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -371,7 +371,7 @@ static BOOL set_printer_hnd_printertype(Printer_entry *Printer, char *handlename } /* it's a print server */ - if (!strchr(handlename+2, '\\')) { + if (*handlename=='\\' && *(handlename+1)=='\\' && !strchr(handlename+2, '\\')) { DEBUGADD(4,("Printer is a print server\n")); Printer->printer_type = PRINTER_HANDLE_IS_PRINTSERVER; } @@ -407,8 +407,13 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) if (Printer->printer_type!=PRINTER_HANDLE_IS_PRINTER) return False; - aprinter=strchr(handlename+2, '\\'); - aprinter++; + if (*handlename=='\\') { + aprinter=strchr(handlename+2, '\\'); + aprinter++; + } + else { + aprinter=handlename; + } DEBUGADD(5,("searching for [%s] (len=%d)\n", aprinter, strlen(aprinter))); -- cgit From 9b783398750cbf6e8b6b6bbb76dd393b432403c7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 27 Apr 2001 21:49:22 +0000 Subject: More acl -> the_acl, %d with uid_t issues. Jeremy. (This used to be commit 30edd7fdf1d791d76351a7cc23a83f97386c3087) --- source3/rpc_server/srv_spoolss_nt.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 6dbf90ba8a..d714972179 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4034,35 +4034,35 @@ static uint32 update_printer_sec(POLICY_HND *handle, uint32 level, nt_printing_getsec(p->mem_ctx, Printer->dev.handlename, &old_secdesc_ctr); if (DEBUGLEVEL >= 10) { - SEC_ACL *acl; + SEC_ACL *the_acl; int i; - acl = old_secdesc_ctr->sec->dacl; + the_acl = old_secdesc_ctr->sec->dacl; DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n", - PRINTERNAME(snum), acl->num_aces)); + PRINTERNAME(snum), the_acl->num_aces)); - for (i = 0; i < acl->num_aces; i++) { + for (i = 0; i < the_acl->num_aces; i++) { fstring sid_str; - sid_to_string(sid_str, &acl->ace[i].sid); + sid_to_string(sid_str, &the_acl->ace[i].sid); DEBUG(10, ("%s 0x%08x\n", sid_str, - acl->ace[i].info.mask)); + the_acl->ace[i].info.mask)); } - acl = secdesc_ctr->sec->dacl; + the_acl = secdesc_ctr->sec->dacl; - if (acl) { + if (the_acl) { DEBUG(10, ("secdesc_ctr for %s has %d aces:\n", - PRINTERNAME(snum), acl->num_aces)); + PRINTERNAME(snum), the_acl->num_aces)); - for (i = 0; i < acl->num_aces; i++) { + for (i = 0; i < the_acl->num_aces; i++) { fstring sid_str; - sid_to_string(sid_str, &acl->ace[i].sid); + sid_to_string(sid_str, &the_acl->ace[i].sid); DEBUG(10, ("%s 0x%08x\n", sid_str, - acl->ace[i].info.mask)); + the_acl->ace[i].info.mask)); } } else { DEBUG(10, ("dacl for secdesc_ctr is NULL\n")); @@ -5515,7 +5515,7 @@ static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need else path = lp_lockdir(); - slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%d.", path, sys_getpid()); + slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%u.", path, (unsigned int)sys_getpid()); slprintf(command, sizeof(command)-1, "%s \"%d\"", cmd, 2); unlink(tmp_file); -- cgit From 43000d8d0662d4979ae2aa574c10aef0952cd49a Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 18 May 2001 04:11:17 +0000 Subject: merge from 2.2 (deleteprinterdriver RPC) (This used to be commit 515caaf7b448e55206433a9ca04fb5078f91cde2) --- source3/rpc_server/srv_spoolss_nt.c | 82 +++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index d714972179..1d1eced2ea 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -34,6 +34,13 @@ extern pstring global_myname; #define PRINTER_HANDLE_IS_PRINTER 0 #define PRINTER_HANDLE_IS_PRINTSERVER 1 +struct table_node { + char *long_archi; + char *short_archi; + int version; +}; + + /* structure to store the printer handles */ /* and a reference to what it's pointing to */ /* and the notify info asked about */ @@ -1058,6 +1065,81 @@ uint32 _spoolss_deleteprinter(pipes_struct *p, SPOOL_Q_DELETEPRINTER *q_u, SPOOL return result; } +/******************************************************************* + * static function to lookup the version id corresponding to an + * long architecture string + ******************************************************************/ +static int get_version_id (char * arch) +{ + int i; + struct table_node archi_table[]= { + + {"Windows 4.0", "WIN40", 0 }, + {"Windows NT x86", "W32X86", 2 }, + {"Windows NT R4000", "W32MIPS", 2 }, + {"Windows NT Alpha_AXP", "W32ALPHA", 2 }, + {"Windows NT PowerPC", "W32PPC", 2 }, + {NULL, "", -1 } + }; + + for (i=0; archi_table[i].long_archi != NULL; i++) + { + if (strcmp(arch, archi_table[i].long_archi) == 0) + return (archi_table[i].version); + } + + return -1; +} + +/******************************************************************** + * _spoolss_deleteprinterdriver + * + * We currently delete the driver for the architecture only. + * This can leave the driver for other archtectures. However, + * since every printer associates a "Windows NT x86" driver name + * and we cannot delete that one while it is in use, **and** since + * it is impossible to assign a driver to a Samba printer without + * having the "Windows NT x86" driver installed,... + * + * ....we should not get into trouble here. + * + * --jerry + ********************************************************************/ + +uint32 _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER *q_u, + SPOOL_R_DELETEPRINTERDRIVER *r_u) +{ + fstring driver; + fstring arch; + NT_PRINTER_DRIVER_INFO_LEVEL info; + int version; + + unistr2_to_ascii(driver, &q_u->driver, sizeof(driver)-1 ); + unistr2_to_ascii(arch, &q_u->arch, sizeof(arch)-1 ); + + /* check that we have a valid driver name first */ + if ((version=get_version_id(arch)) == -1) { + /* this is what NT returns */ + return ERROR_INVALID_ENVIRONMENT; + } + + ZERO_STRUCT(info); + if (get_a_printer_driver (&info, 3, driver, arch, version) != 0) { + /* this is what NT returns */ + return ERROR_UNKNOWN_PRINTER_DRIVER; + } + + + if (printer_driver_in_use(arch, driver)) + { + /* this is what NT returns */ + return ERROR_PRINTER_DRIVER_IN_USE; + } + + return delete_printer_driver(info.info_3); +} + + /******************************************************************** GetPrinterData on a printer server Handle. ********************************************************************/ -- cgit From 2eef56f9fa056766922ca05cc0a2cb0615e7faca Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sat, 2 Jun 2001 03:03:28 +0000 Subject: i18n bugfix merge from appliance. (This used to be commit 73eb539da641ce806690bbd893f126859d531c98) --- source3/rpc_server/srv_spoolss_nt.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 1d1eced2ea..74f40d80ff 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1353,7 +1353,12 @@ static BOOL srv_spoolss_replyopenprinter(char *printer, uint32 localprinter, uin * and connect to the IPC$ share anonumously */ if (smb_connections==0) { - if(!spoolss_connect_to_client(&cli, printer+2)) /* the +2 is to strip the leading 2 backslashs */ + fstring unix_printer; + + fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */ + dos_to_unix(unix_printer, True); + + if(!spoolss_connect_to_client(&cli, unix_printer)) return False; message_register(MSG_PRINTER_NOTIFY, srv_spoolss_receive_message); -- cgit From 8209eda7742653ea7bb20ffa96b61bdb0c4dce87 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 13 Jun 2001 01:08:27 +0000 Subject: Make message receive fn static. Jeremy. (This used to be commit d8807b19228b12ddd6d93c02d1646a470a8e71ef) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 74f40d80ff..99830c035b 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -612,7 +612,7 @@ static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size) receive the notify message ****************************************************************************/ -void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size_t len) +static void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size_t len) { fstring printer; uint32 status; -- cgit From c2cfcb34e1fdef24ac7979bb0f77340d27fc6926 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Tue, 26 Jun 2001 20:23:45 +0000 Subject: SGI compiler fixes. Jeremy (This used to be commit 45bf995bf62aa6cc176d57e2f954cc2d379717ef) --- source3/rpc_server/srv_spoolss_nt.c | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 99830c035b..3fcb08891d 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4213,7 +4213,6 @@ static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) { char *cmd = lp_addprinter_cmd(); - char *path; char **qlines; pstring command; pstring driverlocation; @@ -4221,11 +4220,6 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) int ret; int fd; - if (*lp_pathname(lp_servicenumber(PRINTERS_NAME))) - path = lp_pathname(lp_servicenumber(PRINTERS_NAME)); - else - path = lp_lockdir(); - /* build driver path... only 9X architecture is needed for legacy reasons */ slprintf(driverlocation, sizeof(driverlocation)-1, "\\\\%s\\print$\\WIN40\\0", global_myname); @@ -5494,18 +5488,12 @@ static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need if (*lp_enumports_cmd()) { char *cmd = lp_enumports_cmd(); - char *path; char **qlines; pstring command; int numlines; int ret; int fd; - if (*lp_pathname(lp_servicenumber(PRINTERS_NAME))) - path = lp_pathname(lp_servicenumber(PRINTERS_NAME)); - else - path = lp_lockdir(); - slprintf(command, sizeof(command)-1, "%s \"%d\"", cmd, 1); DEBUG(10,("Running [%s]\n", command)); -- cgit From 87fbb7092b8f8b2f0db0f361c3d625e19de57cd9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 4 Jul 2001 07:15:53 +0000 Subject: The big character set handling changeover! This commit gets rid of all our old codepage handling and replaces it with iconv. All internal strings in Samba are now in "unix" charset, which may be multi-byte. See internals.doc and my posting to samba-technical for a more complete explanation. (This used to be commit debb471267960e56005a741817ebd227ecfc512a) --- source3/rpc_server/srv_spoolss_nt.c | 67 ++++++++++++++----------------------- 1 file changed, 26 insertions(+), 41 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 3fcb08891d..7002241a00 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -300,7 +300,6 @@ static uint32 delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) /* Printer->dev.handlename equals portname equals sharename */ slprintf(command, sizeof(command)-1, "%s \"%s\"", cmd, Printer->dev.handlename); - dos_to_unix(command, True); /* Convert printername to unix-codepage */ DEBUG(10,("Running [%s]\n", command)); ret = smbrun(command, NULL); @@ -944,8 +943,8 @@ BOOL convert_devicemode(char *printername, const DEVICEMODE *devmode, return False; } - unistr_to_dos(nt_devmode->devicename, (const char *)devmode->devicename.buffer, 31); - unistr_to_dos(nt_devmode->formname, (const char *)devmode->formname.buffer, 31); + rpcstr_pull(nt_devmode->devicename,devmode->devicename.buffer, 31, -1, 0); + rpcstr_pull(nt_devmode->formname,devmode->formname.buffer, 31, -1, 0); nt_devmode->specversion=devmode->specversion; nt_devmode->driverversion=devmode->driverversion; @@ -1356,7 +1355,6 @@ static BOOL srv_spoolss_replyopenprinter(char *printer, uint32 localprinter, uin fstring unix_printer; fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */ - dos_to_unix(unix_printer, True); if(!spoolss_connect_to_client(&cli, unix_printer)) return False; @@ -1437,7 +1435,7 @@ static void spoolss_notify_server_name(int snum, slprintf(temp_name, sizeof(temp_name)-1, "\\\\%s", global_myname); - len = (uint32)dos_PutUniCode(temp, temp_name, sizeof(temp) - 2, True); + len = rpcstr_push(temp, temp_name, sizeof(temp)-2, 0); data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); @@ -1471,8 +1469,7 @@ static void spoolss_notify_printer_name(int snum, p++; } - len = (uint32)dos_PutUniCode(temp, p, sizeof(temp) - 2, True); - + len = rpcstr_push(temp, p, sizeof(temp)-2, 0); data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); @@ -1496,8 +1493,7 @@ static void spoolss_notify_share_name(int snum, pstring temp; uint32 len; - len = (uint32)dos_PutUniCode(temp, lp_servicename(snum), - sizeof(temp) - 2, True); + len = rpcstr_push(temp, lp_servicename(snum), sizeof(temp) - 2, 0); data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); @@ -1524,8 +1520,7 @@ static void spoolss_notify_port_name(int snum, /* even if it's strange, that's consistant in all the code */ - len = (uint32)dos_PutUniCode(temp, printer->info_2->portname, - sizeof(temp) - 2, True); + len = rpcstr_push(temp, printer->info_2->portname, sizeof(temp) - 2, 0); data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); @@ -1552,9 +1547,7 @@ static void spoolss_notify_driver_name(int snum, pstring temp; uint32 len; - len = (uint32)dos_PutUniCode(temp, printer->info_2->drivername, - sizeof(temp) - 2, True); - + len = rpcstr_push(temp, printer->info_2->drivername, sizeof(temp) - 2, 0); data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); @@ -1579,11 +1572,10 @@ static void spoolss_notify_comment(int snum, uint32 len; if (*printer->info_2->comment == '\0') - len = (uint32)dos_PutUniCode(temp, lp_comment(snum), - sizeof(temp) - 2, True); + len = rpcstr_push(temp, lp_comment(snum), sizeof(temp) - 2, 0); + else - len = (uint32)dos_PutUniCode(temp, printer->info_2->comment, - sizeof(temp) - 2, True); + len = rpcstr_push(temp, printer->info_2->comment, sizeof(temp) - 2, 0); data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); @@ -1610,8 +1602,7 @@ static void spoolss_notify_location(int snum, pstring temp; uint32 len; - len = (uint32)dos_PutUniCode(temp, printer->info_2->location, - sizeof(temp) - 2, True); + len = rpcstr_push(temp, printer->info_2->location,sizeof(temp) - 2, 0); data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); @@ -1650,8 +1641,7 @@ static void spoolss_notify_sepfile(int snum, pstring temp; uint32 len; - len = (uint32)dos_PutUniCode(temp, printer->info_2->sepfile, - sizeof(temp) - 2, True); + len = rpcstr_push(temp, printer->info_2->sepfile, sizeof(temp) - 2, 0); data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); @@ -1677,8 +1667,7 @@ static void spoolss_notify_print_processor(int snum, pstring temp; uint32 len; - len = (uint32)dos_PutUniCode(temp, printer->info_2->printprocessor, - sizeof(temp) - 2, True); + len = rpcstr_push(temp, printer->info_2->printprocessor, sizeof(temp) - 2, 0); data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); @@ -1704,8 +1693,8 @@ static void spoolss_notify_parameters(int snum, pstring temp; uint32 len; - len = (uint32)dos_PutUniCode(temp, printer->info_2->parameters, - sizeof(temp) - 2, True); + len = rpcstr_push(temp, printer->info_2->parameters, sizeof(temp) - + 2, 0); data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); @@ -1731,8 +1720,7 @@ static void spoolss_notify_datatype(int snum, pstring temp; uint32 len; - len = (uint32)dos_PutUniCode(temp, printer->info_2->datatype, - sizeof(pstring) - 2, True); + len = rpcstr_push(temp, printer->info_2->datatype, sizeof(pstring)-2, 0); data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); @@ -1882,8 +1870,8 @@ static void spoolss_notify_username(int snum, pstring temp; uint32 len; - len = (uint32)dos_PutUniCode(temp, queue->user, - sizeof(temp) - 2, True); + len = rpcstr_push(temp, queue->user, sizeof(temp) - 2, 0); + data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); @@ -1920,9 +1908,8 @@ static void spoolss_notify_job_name(int snum, pstring temp; uint32 len; - len = (uint32)dos_PutUniCode(temp, queue->file, sizeof(temp) - 2, - True); - + len = rpcstr_push(temp, queue->file, sizeof(temp) - 2, 0); + data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); @@ -1970,7 +1957,7 @@ static void spoolss_notify_job_status_string(int snum, } #endif /* NO LONGER NEEDED. */ - len = (uint32)dos_PutUniCode(temp, p, sizeof(temp) - 2, True); + len = rpcstr_push(temp, p, sizeof(temp) - 2, 0); data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); @@ -3487,7 +3474,7 @@ static void init_unistr_array(uint16 **uni_array, fstring *char_array, char *ser DEBUG(0,("init_unistr_array: Realloc error\n" )); return; } - j += (dos_PutUniCode((char *)(*uni_array+j), line , sizeof(uint16)*strlen(line), True) / sizeof(uint16) ); + j += (rpcstr_push((*uni_array+j), line, sizeof(uint16)*strlen(line)+2, 0)/ sizeof(uint16)); i++; } @@ -4231,8 +4218,6 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) printer->info_2->portname, printer->info_2->drivername, printer->info_2->location, driverlocation); - /* Convert script args to unix-codepage */ - dos_to_unix(command, True); DEBUG(10,("Running [%s]\n", command)); ret = smbrun(command, &fd); DEBUGADD(10,("returned [%d]\n", ret)); @@ -4245,7 +4230,7 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) numlines = 0; /* Get lines and convert them back to dos-codepage */ - qlines = fd_lines_load(fd, &numlines, True); + qlines = fd_lines_load(fd, &numlines); DEBUGADD(10,("Lines returned = [%d]\n", numlines)); close(fd); @@ -5507,7 +5492,7 @@ static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need } numlines = 0; - qlines = fd_lines_load(fd, &numlines,True); + qlines = fd_lines_load(fd, &numlines); DEBUGADD(10,("Lines returned = [%d]\n", numlines)); close(fd); @@ -5605,7 +5590,7 @@ static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need } numlines = 0; - qlines = fd_lines_load(fd, &numlines,True); + qlines = fd_lines_load(fd, &numlines); DEBUGADD(10,("Lines returned = [%d]\n", numlines)); close(fd); @@ -6061,7 +6046,7 @@ uint32 _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S return ERROR_NOT_ENOUGH_MEMORY; } - *out_value_len = (uint32)dos_PutUniCode((char *)*out_value, value, in_value_len, True); + *out_value_len = rpcstr_push((char *)*out_value,value, in_value_len, 0); *out_type=type; -- cgit From 527e824293ee934ca5da0ef5424efe5ab7757248 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 4 Jul 2001 07:36:09 +0000 Subject: strchr and strrchr are macros when compiling with optimisation in gcc, so we can't redefine them. damn. (This used to be commit c41fc06376d1a2b83690612304e85010b5e5f3cf) --- source3/rpc_server/srv_spoolss_nt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 7002241a00..79c788e67b 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -377,7 +377,7 @@ static BOOL set_printer_hnd_printertype(Printer_entry *Printer, char *handlename } /* it's a print server */ - if (*handlename=='\\' && *(handlename+1)=='\\' && !strchr(handlename+2, '\\')) { + if (*handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) { DEBUGADD(4,("Printer is a print server\n")); Printer->printer_type = PRINTER_HANDLE_IS_PRINTSERVER; } @@ -414,7 +414,7 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) return False; if (*handlename=='\\') { - aprinter=strchr(handlename+2, '\\'); + aprinter=strchr_m(handlename+2, '\\'); aprinter++; } else { @@ -442,7 +442,7 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) if (get_a_printer(&printer, 2, lp_servicename(snum))!=0) continue; - printername=strchr(printer->info_2->printername+2, '\\'); + printername=strchr_m(printer->info_2->printername+2, '\\'); printername++; DEBUG(10,("set_printer_hnd_name: name [%s], aprinter [%s]\n", @@ -1461,7 +1461,7 @@ static void spoolss_notify_printer_name(int snum, uint32 len; /* the notify name should not contain the \\server\ part */ - char *p = strrchr(printer->info_2->printername, '\\'); + char *p = strrchr_m(printer->info_2->printername, '\\'); if (!p) { p = printer->info_2->printername; -- cgit From 648528196ca136469d82b83cd2ba89b1b30290ae Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 25 Jul 2001 06:42:05 +0000 Subject: Held a shoot-out between NT_STATUS_NO_PROBLEMO and NT_STATUS_NOPROBLEMO. According to the incorruptible judges find and grep, the latter won. Mmm - procrastination. (-: (This used to be commit 2e339403605177b15d5185a8fdd1b06f3f043168) --- source3/rpc_server/srv_spoolss_nt.c | 122 ++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 61 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 79c788e67b..d93f320e2f 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -705,7 +705,7 @@ static BOOL srv_spoolss_sendnotify(pipes_struct *p, POLICY_HND *handle) uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, SPOOL_R_OPEN_PRINTER_EX *r_u) { #if 0 - uint32 result = NT_STATUS_NO_PROBLEMO; + uint32 result = NT_STATUS_NOPROBLEMO; #endif UNISTR2 *printername = NULL; @@ -775,7 +775,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, if (handle_is_printserver(p, handle)) { if (printer_default->access_required == 0) { - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } else if ((printer_default->access_required & SERVER_ACCESS_ADMINISTER ) == SERVER_ACCESS_ADMINISTER) { @@ -787,7 +787,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, return ERROR_ACCESS_DENIED; } else if (user.uid == 0 || user_in_list(uidtoname(user.uid), lp_printer_admin(snum))) { - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } else { close_printer_handle(p, handle); @@ -889,7 +889,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, #endif } - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** @@ -1035,7 +1035,7 @@ uint32 _spoolss_closeprinter(pipes_struct *p, SPOOL_Q_CLOSEPRINTER *q_u, SPOOL_R if (!close_printer_handle(p, handle)) return ERROR_INVALID_HANDLE; - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /******************************************************************** @@ -1336,7 +1336,7 @@ uint32 _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO if (*needed > *out_size) return ERROR_MORE_DATA; else { - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } } @@ -1417,7 +1417,7 @@ uint32 _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE &Printer->notify.client_hnd)) Printer->notify.client_connected=True; - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /******************************************************************* @@ -2361,7 +2361,7 @@ static uint32 printserver_notify_info(pipes_struct *p, POLICY_HND *hnd, } */ - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /******************************************************************* @@ -2444,7 +2444,7 @@ static uint32 printer_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY info->data[i].id, info->data[i].size, info->data[i].enc_type)); } */ - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /******************************************************************** @@ -2913,7 +2913,7 @@ static BOOL enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 of return ERROR_INSUFFICIENT_BUFFER; } else - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /******************************************************************** @@ -2995,7 +2995,7 @@ static BOOL enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, ui return ERROR_INSUFFICIENT_BUFFER; } else - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /******************************************************************** @@ -3064,7 +3064,7 @@ static BOOL enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint32 return ERROR_INSUFFICIENT_BUFFER; } else - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /******************************************************************** @@ -3088,7 +3088,7 @@ static uint32 enumprinters_level1( uint32 flags, fstring name, if (flags & PRINTER_ENUM_NETWORK) return enum_all_printers_info_1_network(buffer, offered, needed, returned); - return NT_STATUS_NO_PROBLEMO; /* NT4sp5 does that */ + return NT_STATUS_NOPROBLEMO; /* NT4sp5 does that */ } /******************************************************************** @@ -3120,7 +3120,7 @@ static uint32 enumprinters_level2( uint32 flags, fstring servername, if (flags & PRINTER_ENUM_REMOTE) return ERROR_INVALID_LEVEL; - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /******************************************************************** @@ -3131,7 +3131,7 @@ static uint32 enumprinters_level5( uint32 flags, fstring servername, uint32 *needed, uint32 *returned) { /* return enum_all_printers_info_5(buffer, offered, needed, returned);*/ - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /******************************************************************** @@ -3220,7 +3220,7 @@ static uint32 getprinter_level_0(int snum, NEW_BUFFER *buffer, uint32 offered, u return ERROR_INSUFFICIENT_BUFFER; } else - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** @@ -3252,7 +3252,7 @@ static uint32 getprinter_level_1(int snum, NEW_BUFFER *buffer, uint32 offered, u return ERROR_INSUFFICIENT_BUFFER; } else - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** @@ -3287,7 +3287,7 @@ static uint32 getprinter_level_2(int snum, NEW_BUFFER *buffer, uint32 offered, u return ERROR_INSUFFICIENT_BUFFER; } else - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** @@ -3317,7 +3317,7 @@ static uint32 getprinter_level_3(int snum, NEW_BUFFER *buffer, uint32 offered, u return ERROR_INSUFFICIENT_BUFFER; } else - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** @@ -3384,7 +3384,7 @@ static uint32 construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, fst free_a_printer(&printer,2); - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /******************************************************************** @@ -3442,7 +3442,7 @@ static uint32 construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fst free_a_printer(&printer,2); - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /******************************************************************** @@ -3558,7 +3558,7 @@ static uint32 construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fst free_a_printer(&printer,2); - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /******************************************************************** @@ -3667,7 +3667,7 @@ static uint32 construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, fst free_a_printer(&printer,2); - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** @@ -3698,7 +3698,7 @@ static uint32 getprinterdriver2_level1(fstring servername, fstring architecture, return ERROR_NOT_ENOUGH_MEMORY; status=construct_printer_driver_info_1(info, snum, servername, architecture, version); - if (status != NT_STATUS_NO_PROBLEMO) { + if (status != NT_STATUS_NOPROBLEMO) { safe_free(info); return status; } @@ -3720,7 +3720,7 @@ static uint32 getprinterdriver2_level1(fstring servername, fstring architecture, if (*needed > offered) return ERROR_INSUFFICIENT_BUFFER; else - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** @@ -3734,7 +3734,7 @@ static uint32 getprinterdriver2_level2(fstring servername, fstring architecture, return ERROR_NOT_ENOUGH_MEMORY; status=construct_printer_driver_info_2(info, snum, servername, architecture, version); - if (status != NT_STATUS_NO_PROBLEMO) { + if (status != NT_STATUS_NOPROBLEMO) { safe_free(info); return status; } @@ -3756,7 +3756,7 @@ static uint32 getprinterdriver2_level2(fstring servername, fstring architecture, if (*needed > offered) return ERROR_INSUFFICIENT_BUFFER; else - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** @@ -3769,7 +3769,7 @@ static uint32 getprinterdriver2_level3(fstring servername, fstring architecture, ZERO_STRUCT(info); status=construct_printer_driver_info_3(&info, snum, servername, architecture, version); - if (status != NT_STATUS_NO_PROBLEMO) { + if (status != NT_STATUS_NOPROBLEMO) { return status; } @@ -3789,7 +3789,7 @@ static uint32 getprinterdriver2_level3(fstring servername, fstring architecture, if (*needed > offered) return ERROR_INSUFFICIENT_BUFFER; else - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** @@ -3802,7 +3802,7 @@ static uint32 getprinterdriver2_level6(fstring servername, fstring architecture, ZERO_STRUCT(info); status=construct_printer_driver_info_6(&info, snum, servername, architecture, version); - if (status != NT_STATUS_NO_PROBLEMO) { + if (status != NT_STATUS_NOPROBLEMO) { return status; } @@ -3822,7 +3822,7 @@ static uint32 getprinterdriver2_level6(fstring servername, fstring architecture, if (*needed > offered) return ERROR_INSUFFICIENT_BUFFER; else - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** @@ -3909,7 +3909,7 @@ uint32 _spoolss_endpageprinter(pipes_struct *p, SPOOL_Q_ENDPAGEPRINTER *q_u, SPO Printer->page_started=False; - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /******************************************************************** @@ -4146,7 +4146,7 @@ static uint32 update_printer_sec(POLICY_HND *handle, uint32 level, new_secdesc_ctr = sec_desc_merge(p->mem_ctx, secdesc_ctr, old_secdesc_ctr); if (sec_desc_equal(new_secdesc_ctr->sec, old_secdesc_ctr->sec)) { - result = NT_STATUS_NO_PROBLEMO; + result = NT_STATUS_NOPROBLEMO; goto done; } @@ -4504,7 +4504,7 @@ static uint32 update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, DEBUG(8,("update_printer\n")); - result = NT_STATUS_NO_PROBLEMO; + result = NT_STATUS_NOPROBLEMO; if (level!=2) { DEBUG(0,("Send a mail to samba@samba.org\n")); @@ -4564,7 +4564,7 @@ static uint32 update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, if (nt_printer_info_level_equal(printer, old_printer)) { DEBUG(3, ("printer info has not changed\n")); - result = NT_STATUS_NO_PROBLEMO; + result = NT_STATUS_NOPROBLEMO; goto done; } @@ -4660,7 +4660,7 @@ uint32 _spoolss_fcpn(pipes_struct *p, SPOOL_Q_FCPN *q_u, SPOOL_R_FCPN *r_u) free_spool_notify_option(&Printer->notify.option); Printer->notify.client_connected=False; - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** @@ -4798,7 +4798,7 @@ static uint32 enumjobs_level1(print_queue_struct *queue, int snum, return ERROR_INSUFFICIENT_BUFFER; } else - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** @@ -4853,7 +4853,7 @@ static uint32 enumjobs_level2(print_queue_struct *queue, int snum, return ERROR_INSUFFICIENT_BUFFER; } else - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** @@ -4894,7 +4894,7 @@ uint32 _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO if (*returned == 0) { safe_free(queue); - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } switch (level) { @@ -5041,7 +5041,7 @@ static uint32 enumprinterdrivers_level1(fstring servername, fstring architecture return ERROR_INSUFFICIENT_BUFFER; } else - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** @@ -5117,7 +5117,7 @@ static uint32 enumprinterdrivers_level2(fstring servername, fstring architecture return ERROR_INSUFFICIENT_BUFFER; } else - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** @@ -5196,7 +5196,7 @@ static uint32 enumprinterdrivers_level3(fstring servername, fstring architecture return ERROR_INSUFFICIENT_BUFFER; } else - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** @@ -5348,7 +5348,7 @@ uint32 _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMF return ERROR_INSUFFICIENT_BUFFER; } else - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; default: safe_free(list); @@ -5436,7 +5436,7 @@ uint32 _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * DEBUGADD(6,("adding form %s [%d] to buffer\n", form_name, i)); smb_io_form_1("", buffer, &form_1, 0); - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; default: safe_free(list); @@ -5548,7 +5548,7 @@ static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need return ERROR_INSUFFICIENT_BUFFER; } else - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** @@ -5647,7 +5647,7 @@ static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need return ERROR_INSUFFICIENT_BUFFER; } else - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** @@ -5750,7 +5750,7 @@ static uint32 spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ srv_spoolss_sendnotify(p, handle); - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** @@ -5792,7 +5792,7 @@ uint32 _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u, uint32 level = q_u->level; SPOOL_PRINTER_DRIVER_INFO_LEVEL *info = &q_u->info; - uint32 err = NT_STATUS_NO_PROBLEMO; + uint32 err = NT_STATUS_NOPROBLEMO; NT_PRINTER_DRIVER_INFO_LEVEL driver; struct current_user user; @@ -5803,7 +5803,7 @@ uint32 _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u, convert_printer_driver_info(info, &driver, level); DEBUG(5,("Cleaning driver's information\n")); - if ((err = clean_up_driver_struct(driver, level, &user)) != NT_STATUS_NO_PROBLEMO ) + if ((err = clean_up_driver_struct(driver, level, &user)) != NT_STATUS_NOPROBLEMO ) goto done; DEBUG(5,("Moving driver to final destination\n")); @@ -5867,7 +5867,7 @@ static uint32 getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen if (*needed > offered) return ERROR_INSUFFICIENT_BUFFER; else - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** @@ -6015,7 +6015,7 @@ uint32 _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S DEBUG(6,("final values: [%d], [%d]\n", *out_value_len, *out_data_len)); free_a_printer(&printer, 2); - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /* @@ -6062,7 +6062,7 @@ uint32 _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S safe_free(data); - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** @@ -6114,7 +6114,7 @@ uint32 _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP old_param.data_len) == 0) { DEBUG(3, ("setprinterdata hasn't changed\n")); - status = NT_STATUS_NO_PROBLEMO; + status = NT_STATUS_NOPROBLEMO; goto done; } } @@ -6321,7 +6321,7 @@ static uint32 enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, ui return ERROR_INSUFFICIENT_BUFFER; } else - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** @@ -6389,7 +6389,7 @@ static uint32 enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered, return ERROR_INSUFFICIENT_BUFFER; } else - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** @@ -6451,7 +6451,7 @@ static uint32 enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, uint return ERROR_INSUFFICIENT_BUFFER; } else - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** @@ -6484,7 +6484,7 @@ static uint32 enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint return ERROR_INSUFFICIENT_BUFFER; } else - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** @@ -6549,7 +6549,7 @@ static uint32 getjob_level_1(print_queue_struct *queue, int count, int snum, uin safe_free(queue); safe_free(info_1); /* I shoud reply something else ... I can't find the good one */ - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } fill_job_info_1(info_1, &(queue[i-1]), i, snum); @@ -6570,7 +6570,7 @@ static uint32 getjob_level_1(print_queue_struct *queue, int count, int snum, uin if (*needed > offered) return ERROR_INSUFFICIENT_BUFFER; else - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } @@ -6601,7 +6601,7 @@ static uint32 getjob_level_2(print_queue_struct *queue, int count, int snum, uin safe_free(queue); safe_free(info_2); /* I shoud reply something else ... I can't find the good one */ - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0) { @@ -6629,7 +6629,7 @@ static uint32 getjob_level_2(print_queue_struct *queue, int count, int snum, uin if (*needed > offered) return ERROR_INSUFFICIENT_BUFFER; else - return NT_STATUS_NO_PROBLEMO; + return NT_STATUS_NOPROBLEMO; } /**************************************************************************** -- cgit From 047a7c88d7d004f1581f585dd31caea388ab6f0d Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 10 Aug 2001 05:41:53 +0000 Subject: Replaced the duplicate DOS constants with appropriate ones from doserr.h to emphasise the fact that the spoolss pipe returns DOS error codes instead of 32-bit nt status codes. (This used to be commit 5f5ed41ee872d842e944cd2e84a80de714ad4385) --- source3/rpc_server/srv_spoolss_nt.c | 555 ++++++++++++++++++------------------ 1 file changed, 279 insertions(+), 276 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index d93f320e2f..a0f14a9e64 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -22,6 +22,9 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +/* Since the SPOOLSS rpc routines are basically DOS 16-bit calls wrapped + up, all the errors returned are DOS errors, not NT status codes. */ + #include "includes.h" extern int DEBUGLEVEL; @@ -272,12 +275,12 @@ static uint32 delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) if (!Printer) { DEBUG(0,("delete_printer_handle: Invalid handle (%s)\n", OUR_HANDLE(hnd))); - return ERROR_INVALID_HANDLE; + return ERRbadfid; } if (del_a_printer(Printer->dev.handlename) != 0) { DEBUG(3,("Error deleting printer %s\n", Printer->dev.handlename)); - return ERROR_INVALID_HANDLE; + return ERRbadfid; } /* Check calling user has permission to delete printer. Note that @@ -287,7 +290,7 @@ static uint32 delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) if (!print_access_check(NULL, -1, PRINTER_ACCESS_ADMINISTER)) { DEBUG(3, ("printer delete denied by security descriptor\n")); - return ERROR_ACCESS_DENIED; + return ERRnoaccess; } if (*lp_deleteprinter_cmd()) { @@ -304,7 +307,7 @@ static uint32 delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) DEBUG(10,("Running [%s]\n", command)); ret = smbrun(command, NULL); if (ret != 0) { - return ERROR_INVALID_HANDLE; /* What to return here? */ + return ERRbadfid; /* What to return here? */ } DEBUGADD(10,("returned [%d]\n", ret)); @@ -313,12 +316,12 @@ static uint32 delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) if ( ( i = lp_servicenumber( Printer->dev.handlename ) ) >= 0 ) { lp_killservice( i ); - return ERROR_SUCCESS; + return ERRsuccess; } else - return ERROR_ACCESS_DENIED; + return ERRnoaccess; } - return ERROR_SUCCESS; + return ERRsuccess; } /**************************************************************************** @@ -705,7 +708,7 @@ static BOOL srv_spoolss_sendnotify(pipes_struct *p, POLICY_HND *handle) uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, SPOOL_R_OPEN_PRINTER_EX *r_u) { #if 0 - uint32 result = NT_STATUS_NOPROBLEMO; + uint32 result = ERRsuccess; #endif UNISTR2 *printername = NULL; @@ -722,7 +725,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, printername = &q_u->printername; if (printername == NULL) - return ERROR_INVALID_PRINTER_NAME; + return ERRinvalidprintername; /* some sanity check because you can open a printer or a print server */ /* aka: \\server\printer or \\server */ @@ -731,7 +734,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, DEBUGADD(3,("checking name: %s\n",name)); if (!open_printer_hnd(p, handle, name)) - return ERROR_INVALID_PRINTER_NAME; + return ERRinvalidprintername; /* if (printer_default->datatype_ptr != NULL) @@ -745,7 +748,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, if (!set_printer_hnd_accesstype(p, handle, printer_default->access_required)) { close_printer_handle(p, handle); - return ERROR_ACCESS_DENIED; + return ERRnoaccess; } /* @@ -775,7 +778,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, if (handle_is_printserver(p, handle)) { if (printer_default->access_required == 0) { - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } else if ((printer_default->access_required & SERVER_ACCESS_ADMINISTER ) == SERVER_ACCESS_ADMINISTER) { @@ -784,14 +787,14 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, if (!lp_ms_add_printer_wizard()) { close_printer_handle(p, handle); - return ERROR_ACCESS_DENIED; + return ERRnoaccess; } else if (user.uid == 0 || user_in_list(uidtoname(user.uid), lp_printer_admin(snum))) { - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } else { close_printer_handle(p, handle); - return ERROR_ACCESS_DENIED; + return ERRnoaccess; } } } @@ -801,7 +804,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, doesn't have print permission. */ if (!get_printer_snum(p, handle, &snum)) - return ERROR_INVALID_HANDLE; + return ERRbadfid; /* map an empty access mask to the minimum access mask */ if (printer_default->access_required == 0x0) @@ -810,7 +813,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, if (!print_access_check(&user, snum, printer_default->access_required)) { DEBUG(3, ("access DENIED for printer open\n")); close_printer_handle(p, handle); - return ERROR_ACCESS_DENIED; + return ERRnoaccess; } /* @@ -889,7 +892,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, #endif } - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /**************************************************************************** @@ -1007,7 +1010,7 @@ static uint32 _spoolss_enddocprinter_internal(pipes_struct *p, POLICY_HND *handl if (!Printer) { DEBUG(0,("_spoolss_enddocprinter_internal: Invalid handle (%s)\n", OUR_HANDLE(handle))); - return ERROR_INVALID_HANDLE; + return ERRbadfid; } Printer->document_started=False; @@ -1033,9 +1036,9 @@ uint32 _spoolss_closeprinter(pipes_struct *p, SPOOL_Q_CLOSEPRINTER *q_u, SPOOL_R memcpy(&r_u->handle, &q_u->handle, sizeof(r_u->handle)); if (!close_printer_handle(p, handle)) - return ERROR_INVALID_HANDLE; + return ERRbadfid; - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /******************************************************************** @@ -1057,7 +1060,7 @@ uint32 _spoolss_deleteprinter(pipes_struct *p, SPOOL_Q_DELETEPRINTER *q_u, SPOOL result = delete_printer_handle(p, handle); - if (result == ERROR_SUCCESS) { + if (result == ERRsuccess) { srv_spoolss_sendnotify(p, handle); } @@ -1119,20 +1122,20 @@ uint32 _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER /* check that we have a valid driver name first */ if ((version=get_version_id(arch)) == -1) { /* this is what NT returns */ - return ERROR_INVALID_ENVIRONMENT; + return ERRinvalidenvironment; } ZERO_STRUCT(info); if (get_a_printer_driver (&info, 3, driver, arch, version) != 0) { /* this is what NT returns */ - return ERROR_UNKNOWN_PRINTER_DRIVER; + return ERRunknownprinterdriver; } if (printer_driver_in_use(arch, driver)) { /* this is what NT returns */ - return ERROR_PRINTER_DRIVER_IN_USE; + return ERRprinterdriverinuse; } return delete_printer_driver(info.info_3); @@ -1308,9 +1311,9 @@ uint32 _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO if (!Printer) { if((*data=(uint8 *)malloc(4*sizeof(uint8))) == NULL) - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; DEBUG(0,("_spoolss_getprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); - return ERROR_INVALID_HANDLE; + return ERRbadfid; } unistr2_to_ascii(value, valuename, sizeof(value)-1); @@ -1325,18 +1328,18 @@ uint32 _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO /* reply this param doesn't exist */ if (*out_size) { if((*data=(uint8 *)talloc_zero(p->mem_ctx, *out_size*sizeof(uint8))) == NULL) - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; } else { *data = NULL; } - return ERROR_INVALID_PARAMETER; + return ERRinvalidparam; } if (*needed > *out_size) - return ERROR_MORE_DATA; + return ERRmoredata; else { - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } } @@ -1397,7 +1400,7 @@ uint32 _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE if (!Printer) { DEBUG(0,("_spoolss_rffpcnex: Invalid handle (%s).\n", OUR_HANDLE(handle))); - return ERROR_INVALID_HANDLE; + return ERRbadfid; } Printer->notify.flags=flags; @@ -1417,7 +1420,7 @@ uint32 _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE &Printer->notify.client_hnd)) Printer->notify.client_connected=True; - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /******************************************************************* @@ -2361,7 +2364,7 @@ static uint32 printserver_notify_info(pipes_struct *p, POLICY_HND *hnd, } */ - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /******************************************************************* @@ -2444,7 +2447,7 @@ static uint32 printer_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY info->data[i].id, info->data[i].size, info->data[i].enc_type)); } */ - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /******************************************************************** @@ -2459,7 +2462,7 @@ uint32 _spoolss_rfnpcnex( pipes_struct *p, SPOOL_Q_RFNPCNEX *q_u, SPOOL_R_RFNPCN SPOOL_NOTIFY_INFO *info = &r_u->info; Printer_entry *Printer=find_printer_index_by_hnd(p, handle); - uint32 result = ERROR_INVALID_HANDLE; + uint32 result = ERRbadfid; /* we always have a NOTIFY_INFO struct */ r_u->info_ptr=0x1; @@ -2885,7 +2888,7 @@ static BOOL enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 of if (construct_printer_info_1(flags, ¤t_prt, snum)) { if((printers=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_1))) == NULL) { *returned=0; - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; } DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_1\n", *returned)); memcpy(&printers[*returned], ¤t_prt, sizeof(PRINTER_INFO_1)); @@ -2899,7 +2902,7 @@ static BOOL enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 of (*needed) += spoolss_size_printer_info_1(&printers[i]); if (!alloc_buffer_size(buffer, *needed)) - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; /* fill the buffer with the structures */ for (i=0; i<*returned; i++) @@ -2910,10 +2913,10 @@ static BOOL enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 of if (*needed > offered) { *returned=0; - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } else - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /******************************************************************** @@ -2941,7 +2944,7 @@ static BOOL enum_all_printers_info_1_name(fstring name, NEW_BUFFER *buffer, uint return enum_all_printers_info_1(PRINTER_ENUM_ICON8, buffer, offered, needed, returned); } else - return ERROR_INVALID_NAME; + return ERRinvalidname; } /******************************************************************** @@ -2963,7 +2966,7 @@ static BOOL enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, ui */ if((printer=(PRINTER_INFO_1 *)malloc(sizeof(PRINTER_INFO_1))) == NULL) - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; *returned=1; @@ -2981,7 +2984,7 @@ static BOOL enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, ui if (!alloc_buffer_size(buffer, *needed)) { safe_free(printer); - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } /* fill the buffer with the structures */ @@ -2992,10 +2995,10 @@ static BOOL enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, ui if (*needed > offered) { *returned=0; - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } else - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /******************************************************************** @@ -3029,7 +3032,7 @@ static BOOL enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint32 if (construct_printer_info_2(¤t_prt, snum)) { if((printers=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_2))) == NULL) - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_2\n", *returned)); memcpy(&printers[*returned], ¤t_prt, sizeof(PRINTER_INFO_2)); (*returned)++; @@ -3046,7 +3049,7 @@ static BOOL enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint32 free_devmode(printers[i].devmode); } safe_free(printers); - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } /* fill the buffer with the structures */ @@ -3061,10 +3064,10 @@ static BOOL enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint32 if (*needed > offered) { *returned=0; - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } else - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /******************************************************************** @@ -3088,7 +3091,7 @@ static uint32 enumprinters_level1( uint32 flags, fstring name, if (flags & PRINTER_ENUM_NETWORK) return enum_all_printers_info_1_network(buffer, offered, needed, returned); - return NT_STATUS_NOPROBLEMO; /* NT4sp5 does that */ + return ERRsuccess; /* NT4sp5 does that */ } /******************************************************************** @@ -3114,13 +3117,13 @@ static uint32 enumprinters_level2( uint32 flags, fstring servername, if (strequal(servername, temp)) return enum_all_printers_info_2(buffer, offered, needed, returned); else - return ERROR_INVALID_NAME; + return ERRinvalidname; } if (flags & PRINTER_ENUM_REMOTE) - return ERROR_INVALID_LEVEL; + return ERRunknownlevel; - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /******************************************************************** @@ -3131,7 +3134,7 @@ static uint32 enumprinters_level5( uint32 flags, fstring servername, uint32 *needed, uint32 *returned) { /* return enum_all_printers_info_5(buffer, offered, needed, returned);*/ - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /******************************************************************** @@ -3187,7 +3190,7 @@ uint32 _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOOL_ case 3: case 4: default: - return ERROR_INVALID_LEVEL; + return ERRunknownlevel; } } @@ -3198,7 +3201,7 @@ static uint32 getprinter_level_0(int snum, NEW_BUFFER *buffer, uint32 offered, u PRINTER_INFO_0 *printer=NULL; if((printer=(PRINTER_INFO_0*)malloc(sizeof(PRINTER_INFO_0))) == NULL) - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; construct_printer_info_0(printer, snum); @@ -3207,7 +3210,7 @@ static uint32 getprinter_level_0(int snum, NEW_BUFFER *buffer, uint32 offered, u if (!alloc_buffer_size(buffer, *needed)) { safe_free(printer); - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } /* fill the buffer with the structures */ @@ -3217,10 +3220,10 @@ static uint32 getprinter_level_0(int snum, NEW_BUFFER *buffer, uint32 offered, u safe_free(printer); if (*needed > offered) { - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } else - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /**************************************************************************** @@ -3230,7 +3233,7 @@ static uint32 getprinter_level_1(int snum, NEW_BUFFER *buffer, uint32 offered, u PRINTER_INFO_1 *printer=NULL; if((printer=(PRINTER_INFO_1*)malloc(sizeof(PRINTER_INFO_1))) == NULL) - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; construct_printer_info_1(PRINTER_ENUM_ICON8, printer, snum); @@ -3239,7 +3242,7 @@ static uint32 getprinter_level_1(int snum, NEW_BUFFER *buffer, uint32 offered, u if (!alloc_buffer_size(buffer, *needed)) { safe_free(printer); - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } /* fill the buffer with the structures */ @@ -3249,10 +3252,10 @@ static uint32 getprinter_level_1(int snum, NEW_BUFFER *buffer, uint32 offered, u safe_free(printer); if (*needed > offered) { - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } else - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /**************************************************************************** @@ -3262,7 +3265,7 @@ static uint32 getprinter_level_2(int snum, NEW_BUFFER *buffer, uint32 offered, u PRINTER_INFO_2 *printer=NULL; if((printer=(PRINTER_INFO_2*)malloc(sizeof(PRINTER_INFO_2)))==NULL) - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; construct_printer_info_2(printer, snum); @@ -3271,23 +3274,23 @@ static uint32 getprinter_level_2(int snum, NEW_BUFFER *buffer, uint32 offered, u if (!alloc_buffer_size(buffer, *needed)) { free_printer_info_2(printer); - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } /* fill the buffer with the structures */ if (!smb_io_printer_info_2("", buffer, printer, 0)) { free_printer_info_2(printer); - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; } /* clear memory */ free_printer_info_2(printer); if (*needed > offered) { - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } else - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /**************************************************************************** @@ -3297,14 +3300,14 @@ static uint32 getprinter_level_3(int snum, NEW_BUFFER *buffer, uint32 offered, u PRINTER_INFO_3 *printer=NULL; if (!construct_printer_info_3(&printer, snum)) - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; /* check the required size. */ *needed += spoolss_size_printer_info_3(printer); if (!alloc_buffer_size(buffer, *needed)) { free_printer_info_3(printer); - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } /* fill the buffer with the structures */ @@ -3314,10 +3317,10 @@ static uint32 getprinter_level_3(int snum, NEW_BUFFER *buffer, uint32 offered, u free_printer_info_3(printer); if (*needed > offered) { - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } else - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /**************************************************************************** @@ -3340,7 +3343,7 @@ uint32 _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GET *needed=0; if (!get_printer_snum(p, handle, &snum)) - return ERROR_INVALID_HANDLE; + return ERRbadfid; switch (level) { case 0: @@ -3352,7 +3355,7 @@ uint32 _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GET case 3: return getprinter_level_3(snum, buffer, offered, needed); default: - return ERROR_INVALID_LEVEL; + return ERRunknownlevel; } } @@ -3375,16 +3378,16 @@ static uint32 construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, fst ZERO_STRUCT(driver); if (get_a_printer(&printer, 2, lp_servicename(snum)) != 0) - return ERROR_INVALID_PRINTER_NAME; + return ERRinvalidprintername; if (get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version) != 0) - return ERROR_UNKNOWN_PRINTER_DRIVER; + return ERRunknownprinterdriver; fill_printer_driver_info_1(info, driver, servername, architecture); free_a_printer(&printer,2); - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /******************************************************************** @@ -3433,16 +3436,16 @@ static uint32 construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fst ZERO_STRUCT(driver); if (!get_a_printer(&printer, 2, lp_servicename(snum)) != 0) - return ERROR_INVALID_PRINTER_NAME; + return ERRinvalidprintername; if (!get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version) != 0) - return ERROR_UNKNOWN_PRINTER_DRIVER; + return ERRunknownprinterdriver; fill_printer_driver_info_2(info, driver, servername); free_a_printer(&printer,2); - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /******************************************************************** @@ -3545,20 +3548,20 @@ static uint32 construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fst status=get_a_printer(&printer, 2, lp_servicename(snum) ); DEBUG(8,("construct_printer_driver_info_3: status: %d\n", status)); if (status != 0) - return ERROR_INVALID_PRINTER_NAME; + return ERRinvalidprintername; status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version); DEBUG(8,("construct_printer_driver_info_3: status: %d\n", status)); if (status != 0) { free_a_printer(&printer,2); - return ERROR_UNKNOWN_PRINTER_DRIVER; + return ERRunknownprinterdriver; } fill_printer_driver_info_3(info, driver, servername); free_a_printer(&printer,2); - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /******************************************************************** @@ -3639,7 +3642,7 @@ static uint32 construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, fst status=get_a_printer(&printer, 2, lp_servicename(snum) ); DEBUG(8,("construct_printer_driver_info_6: status: %d\n", status)); if (status != 0) - return ERROR_INVALID_PRINTER_NAME; + return ERRinvalidprintername; status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version); DEBUG(8,("construct_printer_driver_info_6: status: %d\n", status)); @@ -3650,7 +3653,7 @@ static uint32 construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, fst if (version < 3) { free_a_printer(&printer,2); - return ERROR_UNKNOWN_PRINTER_DRIVER; + return ERRunknownprinterdriver; } /* Yes - try again with a WinNT driver. */ @@ -3659,7 +3662,7 @@ static uint32 construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, fst DEBUG(8,("construct_printer_driver_info_6: status: %d\n", status)); if (status != 0) { free_a_printer(&printer,2); - return ERROR_UNKNOWN_PRINTER_DRIVER; + return ERRunknownprinterdriver; } } @@ -3667,7 +3670,7 @@ static uint32 construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, fst free_a_printer(&printer,2); - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /**************************************************************************** @@ -3695,10 +3698,10 @@ static uint32 getprinterdriver2_level1(fstring servername, fstring architecture, uint32 status; if((info=(DRIVER_INFO_1 *)malloc(sizeof(DRIVER_INFO_1))) == NULL) - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; status=construct_printer_driver_info_1(info, snum, servername, architecture, version); - if (status != NT_STATUS_NOPROBLEMO) { + if (status != ERRsuccess) { safe_free(info); return status; } @@ -3708,7 +3711,7 @@ static uint32 getprinterdriver2_level1(fstring servername, fstring architecture, if (!alloc_buffer_size(buffer, *needed)) { safe_free(info); - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } /* fill the buffer with the structures */ @@ -3718,9 +3721,9 @@ static uint32 getprinterdriver2_level1(fstring servername, fstring architecture, safe_free(info); if (*needed > offered) - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; else - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /**************************************************************************** @@ -3731,10 +3734,10 @@ static uint32 getprinterdriver2_level2(fstring servername, fstring architecture, uint32 status; if((info=(DRIVER_INFO_2 *)malloc(sizeof(DRIVER_INFO_2))) == NULL) - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; status=construct_printer_driver_info_2(info, snum, servername, architecture, version); - if (status != NT_STATUS_NOPROBLEMO) { + if (status != ERRsuccess) { safe_free(info); return status; } @@ -3744,7 +3747,7 @@ static uint32 getprinterdriver2_level2(fstring servername, fstring architecture, if (!alloc_buffer_size(buffer, *needed)) { safe_free(info); - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } /* fill the buffer with the structures */ @@ -3754,9 +3757,9 @@ static uint32 getprinterdriver2_level2(fstring servername, fstring architecture, safe_free(info); if (*needed > offered) - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; else - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /**************************************************************************** @@ -3769,7 +3772,7 @@ static uint32 getprinterdriver2_level3(fstring servername, fstring architecture, ZERO_STRUCT(info); status=construct_printer_driver_info_3(&info, snum, servername, architecture, version); - if (status != NT_STATUS_NOPROBLEMO) { + if (status != ERRsuccess) { return status; } @@ -3778,7 +3781,7 @@ static uint32 getprinterdriver2_level3(fstring servername, fstring architecture, if (!alloc_buffer_size(buffer, *needed)) { free_printer_driver_info_3(&info); - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } /* fill the buffer with the structures */ @@ -3787,9 +3790,9 @@ static uint32 getprinterdriver2_level3(fstring servername, fstring architecture, free_printer_driver_info_3(&info); if (*needed > offered) - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; else - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /**************************************************************************** @@ -3802,7 +3805,7 @@ static uint32 getprinterdriver2_level6(fstring servername, fstring architecture, ZERO_STRUCT(info); status=construct_printer_driver_info_6(&info, snum, servername, architecture, version); - if (status != NT_STATUS_NOPROBLEMO) { + if (status != ERRsuccess) { return status; } @@ -3811,7 +3814,7 @@ static uint32 getprinterdriver2_level6(fstring servername, fstring architecture, if (!alloc_buffer_size(buffer, *needed)) { free_printer_driver_info_6(&info); - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } /* fill the buffer with the structures */ @@ -3820,9 +3823,9 @@ static uint32 getprinterdriver2_level6(fstring servername, fstring architecture, free_printer_driver_info_6(&info); if (*needed > offered) - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; else - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /**************************************************************************** @@ -3859,7 +3862,7 @@ uint32 _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_ unistr2_to_ascii(architecture, uni_arch, sizeof(architecture)-1); if (!get_printer_snum(p, handle, &snum)) - return ERROR_INVALID_HANDLE; + return ERRbadfid; switch (level) { case 1: @@ -3871,7 +3874,7 @@ uint32 _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_ case 6: return getprinterdriver2_level6(servername, architecture, clientmajorversion, snum, buffer, offered, needed); default: - return ERROR_INVALID_LEVEL; + return ERRunknownlevel; } } @@ -3890,7 +3893,7 @@ uint32 _spoolss_startpageprinter(pipes_struct *p, SPOOL_Q_STARTPAGEPRINTER *q_u, } DEBUG(3,("Error in startpageprinter printer handle\n")); - return ERROR_INVALID_HANDLE; + return ERRbadfid; } /**************************************************************************** @@ -3904,12 +3907,12 @@ uint32 _spoolss_endpageprinter(pipes_struct *p, SPOOL_Q_ENDPAGEPRINTER *q_u, SPO if (!Printer) { DEBUG(0,("_spoolss_endpageprinter: Invalid handle (%s).\n",OUR_HANDLE(handle))); - return ERROR_INVALID_HANDLE; + return ERRbadfid; } Printer->page_started=False; - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /******************************************************************** @@ -3934,7 +3937,7 @@ uint32 _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, S if (!Printer) { DEBUG(0,("_spoolss_startdocprinter: Invalid handle (%s)\n", OUR_HANDLE(handle))); - return ERROR_INVALID_HANDLE; + return ERRbadfid; } get_current_user(&user, p); @@ -3955,13 +3958,13 @@ uint32 _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, S unistr2_to_ascii(datatype, &info_1->datatype, sizeof(datatype)); if (strcmp(datatype, "RAW") != 0) { (*jobid)=0; - return ERROR_INVALID_DATATYPE; + return ERRinvaliddatatype; } } /* get the share number of the printer */ if (!get_printer_snum(p, handle, &snum)) { - return ERROR_INVALID_HANDLE; + return ERRbadfid; } unistr2_to_ascii(jobname, &info_1->docname, sizeof(jobname)); @@ -4009,7 +4012,7 @@ uint32 _spoolss_writeprinter(pipes_struct *p, SPOOL_Q_WRITEPRINTER *q_u, SPOOL_R if (!Printer) { DEBUG(0,("_spoolss_writeprinter: Invalid handle (%s)\n",OUR_HANDLE(handle))); r_u->buffer_written = q_u->buffer_size2; - return ERROR_INVALID_HANDLE; + return ERRbadfid; } (*buffer_written) = print_job_write(Printer->jobid, (char *)buffer, buffer_size); @@ -4029,18 +4032,18 @@ static uint32 control_printer(POLICY_HND *handle, uint32 command, pipes_struct *p) { struct current_user user; - int snum, errcode = ERROR_INVALID_FUNCTION; + int snum, errcode = ERRbadfunc; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); get_current_user(&user, p); if (!Printer) { DEBUG(0,("control_printer: Invalid handle (%s)\n", OUR_HANDLE(handle))); - return ERROR_INVALID_HANDLE; + return ERRbadfid; } if (!get_printer_snum(p, handle, &snum)) - return ERROR_INVALID_HANDLE; + return ERRbadfid; switch (command) { case PRINTER_CONTROL_PAUSE: @@ -4060,7 +4063,7 @@ static uint32 control_printer(POLICY_HND *handle, uint32 command, } break; default: - return ERROR_INVALID_LEVEL; + return ERRunknownlevel; } return errcode; @@ -4096,7 +4099,7 @@ static uint32 update_printer_sec(POLICY_HND *handle, uint32 level, DEBUG(0,("update_printer_sec: Invalid handle (%s)\n", OUR_HANDLE(handle))); - result = ERROR_INVALID_HANDLE; + result = ERRbadfid; goto done; } @@ -4146,7 +4149,7 @@ static uint32 update_printer_sec(POLICY_HND *handle, uint32 level, new_secdesc_ctr = sec_desc_merge(p->mem_ctx, secdesc_ctr, old_secdesc_ctr); if (sec_desc_equal(new_secdesc_ctr->sec, old_secdesc_ctr->sec)) { - result = NT_STATUS_NOPROBLEMO; + result = ERRsuccess; goto done; } @@ -4160,7 +4163,7 @@ static uint32 update_printer_sec(POLICY_HND *handle, uint32 level, information. */ if (!print_access_check(&user, snum, PRINTER_ACCESS_ADMINISTER)) { - result = ERROR_ACCESS_DENIED; + result = ERRnoaccess; goto done; } @@ -4504,28 +4507,28 @@ static uint32 update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, DEBUG(8,("update_printer\n")); - result = NT_STATUS_NOPROBLEMO; + result = ERRsuccess; if (level!=2) { DEBUG(0,("Send a mail to samba@samba.org\n")); DEBUGADD(0,("with the following message: update_printer: level!=2\n")); - result = ERROR_INVALID_LEVEL; + result = ERRunknownlevel; goto done; } if (!Printer) { - result = ERROR_INVALID_HANDLE; + result = ERRbadfid; goto done; } if (!get_printer_snum(p, handle, &snum)) { - result = ERROR_INVALID_HANDLE; + result = ERRbadfid; goto done; } if((get_a_printer(&printer, 2, lp_servicename(snum)) != 0) || (get_a_printer(&old_printer, 2, lp_servicename(snum)) != 0)) { - result = ERROR_INVALID_HANDLE; + result = ERRbadfid; goto done; } @@ -4546,7 +4549,7 @@ static uint32 update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, DEBUGADD(8,("Converting the devicemode struct\n")); if (!convert_devicemode(printer->info_2->printername, devmode, &printer->info_2->devmode)) { - result = ERROR_NOT_ENOUGH_MEMORY; + result = ERRnomem; goto done; } } @@ -4554,7 +4557,7 @@ static uint32 update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, /* Do sanity check on the requested changes for Samba */ if (!check_printer_ok(printer->info_2, snum)) { - result = ERROR_INVALID_PARAMETER; + result = ERRinvalidparam; goto done; } @@ -4564,7 +4567,7 @@ static uint32 update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, if (nt_printer_info_level_equal(printer, old_printer)) { DEBUG(3, ("printer info has not changed\n")); - result = NT_STATUS_NOPROBLEMO; + result = ERRsuccess; goto done; } @@ -4573,7 +4576,7 @@ static uint32 update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { DEBUG(3, ("printer property change denied by security " "descriptor\n")); - result = ERROR_ACCESS_DENIED; + result = ERRnoaccess; goto done; } @@ -4581,7 +4584,7 @@ static uint32 update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, if (*lp_addprinter_cmd() ) if ( !add_printer_hook(printer) ) { - result = ERROR_ACCESS_DENIED; + result = ERRnoaccess; goto done; } @@ -4589,7 +4592,7 @@ static uint32 update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, if (add_a_printer(*printer, 2)!=0) { /* I don't really know what to return here !!! */ - result = ERROR_ACCESS_DENIED; + result = ERRnoaccess; goto done; } @@ -4618,7 +4621,7 @@ uint32 _spoolss_setprinter(pipes_struct *p, SPOOL_Q_SETPRINTER *q_u, SPOOL_R_SET if (!Printer) { DEBUG(0,("_spoolss_setprinter: Invalid handle (%s)\n", OUR_HANDLE(handle))); - return ERROR_INVALID_HANDLE; + return ERRbadfid; } /* check the level */ @@ -4631,7 +4634,7 @@ uint32 _spoolss_setprinter(pipes_struct *p, SPOOL_Q_SETPRINTER *q_u, SPOOL_R_SET return update_printer_sec(handle, level, info, p, secdesc_ctr); default: - return ERROR_INVALID_LEVEL; + return ERRunknownlevel; } } @@ -4646,7 +4649,7 @@ uint32 _spoolss_fcpn(pipes_struct *p, SPOOL_Q_FCPN *q_u, SPOOL_R_FCPN *r_u) if (!Printer) { DEBUG(0,("_spoolss_fcpn: Invalid handle (%s)\n", OUR_HANDLE(handle))); - return ERROR_INVALID_HANDLE; + return ERRbadfid; } if (Printer->notify.client_connected==True) @@ -4660,7 +4663,7 @@ uint32 _spoolss_fcpn(pipes_struct *p, SPOOL_Q_FCPN *q_u, SPOOL_R_FCPN *r_u) free_spool_notify_option(&Printer->notify.option); Printer->notify.client_connected=False; - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /**************************************************************************** @@ -4672,7 +4675,7 @@ uint32 _spoolss_addjob(pipes_struct *p, SPOOL_Q_ADDJOB *q_u, SPOOL_R_ADDJOB *r_u spoolss_move_buffer(q_u->buffer, &r_u->buffer); r_u->needed = 0; - return ERROR_INVALID_PARAMETER; /* this is what a NT server + return ERRinvalidparam; /* this is what a NT server returns for AddJob. AddJob must fail on non-local printers */ @@ -4769,7 +4772,7 @@ static uint32 enumjobs_level1(print_queue_struct *queue, int snum, if (info==NULL) { safe_free(queue); *returned=0; - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; } for (i=0; i<*returned; i++) @@ -4783,7 +4786,7 @@ static uint32 enumjobs_level1(print_queue_struct *queue, int snum, if (!alloc_buffer_size(buffer, *needed)) { safe_free(info); - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } /* fill the buffer with the structures */ @@ -4795,10 +4798,10 @@ static uint32 enumjobs_level1(print_queue_struct *queue, int snum, if (*needed > offered) { *returned=0; - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } else - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /**************************************************************************** @@ -4815,12 +4818,12 @@ static uint32 enumjobs_level2(print_queue_struct *queue, int snum, info=(JOB_INFO_2 *)malloc(*returned*sizeof(JOB_INFO_2)); if (info==NULL) { *returned=0; - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; } if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0) { *returned = 0; - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; } for (i=0; i<*returned; i++) @@ -4835,7 +4838,7 @@ static uint32 enumjobs_level2(print_queue_struct *queue, int snum, if (!alloc_buffer_size(buffer, *needed)) { safe_free(info); - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } /* fill the buffer with the structures */ @@ -4850,10 +4853,10 @@ static uint32 enumjobs_level2(print_queue_struct *queue, int snum, if (*needed > offered) { *returned=0; - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } else - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /**************************************************************************** @@ -4887,14 +4890,14 @@ uint32 _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO *returned=0; if (!get_printer_snum(p, handle, &snum)) - return ERROR_INVALID_HANDLE; + return ERRbadfid; *returned = print_queue_status(snum, &queue, &prt_status); DEBUGADD(4,("count:[%d], status:[%d], [%s]\n", *returned, prt_status.status, prt_status.message)); if (*returned == 0) { safe_free(queue); - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } switch (level) { @@ -4905,7 +4908,7 @@ uint32 _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO default: safe_free(queue); *returned=0; - return ERROR_INVALID_LEVEL; + return ERRunknownlevel; } } @@ -4930,16 +4933,16 @@ uint32 _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u struct current_user user; print_status_struct prt_status; - int snum, errcode = ERROR_INVALID_FUNCTION; + int snum, errcode = ERRbadfunc; memset(&prt_status, 0, sizeof(prt_status)); if (!get_printer_snum(p, handle, &snum)) { - return ERROR_INVALID_HANDLE; + return ERRbadfid; } if (!print_job_exists(jobid)) { - return ERROR_INVALID_PRINTER_NAME; + return ERRinvalidprintername; } get_current_user(&user, p); @@ -4963,7 +4966,7 @@ uint32 _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u } break; default: - return ERROR_INVALID_LEVEL; + return ERRunknownlevel; } return errcode; @@ -4992,12 +4995,12 @@ static uint32 enumprinterdrivers_level1(fstring servername, fstring architecture DEBUGADD(4,("we have:[%d] drivers in environment [%s] and version [%d]\n", ndrivers, architecture, version)); if(ndrivers == -1) - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; if(ndrivers != 0) { if((driver_info_1=(DRIVER_INFO_1 *)Realloc(driver_info_1, (*returned+ndrivers) * sizeof(DRIVER_INFO_1))) == NULL) { safe_free(list); - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; } } @@ -5025,7 +5028,7 @@ static uint32 enumprinterdrivers_level1(fstring servername, fstring architecture if (!alloc_buffer_size(buffer, *needed)) { safe_free(driver_info_1); - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } /* fill the buffer with the driver structures */ @@ -5038,10 +5041,10 @@ static uint32 enumprinterdrivers_level1(fstring servername, fstring architecture if (*needed > offered) { *returned=0; - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } else - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /**************************************************************************** @@ -5067,12 +5070,12 @@ static uint32 enumprinterdrivers_level2(fstring servername, fstring architecture DEBUGADD(4,("we have:[%d] drivers in environment [%s] and version [%d]\n", ndrivers, architecture, version)); if(ndrivers == -1) - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; if(ndrivers != 0) { if((driver_info_2=(DRIVER_INFO_2 *)Realloc(driver_info_2, (*returned+ndrivers) * sizeof(DRIVER_INFO_2))) == NULL) { safe_free(list); - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; } } @@ -5101,7 +5104,7 @@ static uint32 enumprinterdrivers_level2(fstring servername, fstring architecture if (!alloc_buffer_size(buffer, *needed)) { safe_free(driver_info_2); - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } /* fill the buffer with the form structures */ @@ -5114,10 +5117,10 @@ static uint32 enumprinterdrivers_level2(fstring servername, fstring architecture if (*needed > offered) { *returned=0; - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } else - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /**************************************************************************** @@ -5143,12 +5146,12 @@ static uint32 enumprinterdrivers_level3(fstring servername, fstring architecture DEBUGADD(4,("we have:[%d] drivers in environment [%s] and version [%d]\n", ndrivers, architecture, version)); if(ndrivers == -1) - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; if(ndrivers != 0) { if((driver_info_3=(DRIVER_INFO_3 *)Realloc(driver_info_3, (*returned+ndrivers) * sizeof(DRIVER_INFO_3))) == NULL) { safe_free(list); - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; } } @@ -5177,7 +5180,7 @@ static uint32 enumprinterdrivers_level3(fstring servername, fstring architecture if (!alloc_buffer_size(buffer, *needed)) { safe_free(driver_info_3); - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } /* fill the buffer with the driver structures */ @@ -5193,10 +5196,10 @@ static uint32 enumprinterdrivers_level3(fstring servername, fstring architecture if (*needed > offered) { *returned=0; - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } else - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /**************************************************************************** @@ -5238,7 +5241,7 @@ uint32 _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS default: *returned=0; safe_free(list); - return ERROR_INVALID_LEVEL; + return ERRunknownlevel; } } @@ -5290,13 +5293,13 @@ uint32 _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMF DEBUGADD(5,("Number of user forms [%d]\n", *numofforms)); *numofforms += numbuiltinforms; - if (*numofforms == 0) return ERROR_NO_MORE_ITEMS; + if (*numofforms == 0) return ERRnomoreitems; switch (level) { case 1: if ((forms_1=(FORM_1 *)malloc(*numofforms * sizeof(FORM_1))) == NULL) { *numofforms=0; - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; } /* construct the list of form structures */ @@ -5328,7 +5331,7 @@ uint32 _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMF if (!alloc_buffer_size(buffer, buffer_size)){ safe_free(forms_1); - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } /* fill the buffer with the form structures */ @@ -5345,15 +5348,15 @@ uint32 _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMF if (*needed > offered) { *numofforms=0; - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } else - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; default: safe_free(list); safe_free(builtinlist); - return ERROR_INVALID_LEVEL; + return ERRunknownlevel; } } @@ -5394,7 +5397,7 @@ uint32 _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * DEBUGADD(5,("Number of forms [%d]\n", numofforms)); if (numofforms == 0) - return ERROR_INVALID_HANDLE; + return ERRbadfid; } switch (level) { @@ -5417,7 +5420,7 @@ uint32 _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * safe_free(list); if (i == numofforms) { - return ERROR_INVALID_HANDLE; + return ERRbadfid; } } /* check the required size. */ @@ -5425,22 +5428,22 @@ uint32 _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * *needed=spoolss_size_form_1(&form_1); if (!alloc_buffer_size(buffer, buffer_size)){ - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } if (*needed > offered) { - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } /* fill the buffer with the form structures */ DEBUGADD(6,("adding form %s [%d] to buffer\n", form_name, i)); smb_io_form_1("", buffer, &form_1, 0); - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; default: safe_free(list); - return ERROR_INVALID_LEVEL; + return ERRunknownlevel; } } @@ -5488,7 +5491,7 @@ static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need if (fd != -1) close(fd); /* Is this the best error to return here? */ - return ERROR_ACCESS_DENIED; + return ERRnoaccess; } numlines = 0; @@ -5498,9 +5501,9 @@ static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need if(numlines) { if((ports=(PORT_INFO_1 *)malloc( numlines * sizeof(PORT_INFO_1) )) == NULL) { - DEBUG(10,("Returning ERROR_NOT_ENOUGH_MEMORY [%x]\n", ERROR_NOT_ENOUGH_MEMORY)); + DEBUG(10,("Returning ERRnomem [%x]\n", ERRnomem)); file_lines_free(qlines); - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; } for (i=0; i offered) { *returned=0; - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } else - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /**************************************************************************** @@ -5586,7 +5589,7 @@ static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need if (fd != -1) close(fd); /* Is this the best error to return here? */ - return ERROR_ACCESS_DENIED; + return ERRnoaccess; } numlines = 0; @@ -5596,9 +5599,9 @@ static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need if(numlines) { if((ports=(PORT_INFO_2 *)malloc( numlines * sizeof(PORT_INFO_2) )) == NULL) { - DEBUG(10,("Returning ERROR_NOT_ENOUGH_MEMORY [%x]\n", ERROR_NOT_ENOUGH_MEMORY)); + DEBUG(10,("Returning ERRnomem [%x]\n", ERRnomem)); file_lines_free(qlines); - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; } for (i=0; i offered) { *returned=0; - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } else - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /**************************************************************************** @@ -5678,7 +5681,7 @@ uint32 _spoolss_enumports( pipes_struct *p, SPOOL_Q_ENUMPORTS *q_u, SPOOL_R_ENUM case 2: return enumports_level_2(buffer, offered, needed, returned); default: - return ERROR_INVALID_LEVEL; + return ERRunknownlevel; } } @@ -5696,7 +5699,7 @@ static uint32 spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ if ((printer = (NT_PRINTER_INFO_LEVEL *)malloc(sizeof(NT_PRINTER_INFO_LEVEL))) == NULL) { DEBUG(0,("spoolss_addprinterex_level_2: malloc fail.\n")); - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; } ZERO_STRUCTP(printer); @@ -5707,7 +5710,7 @@ static uint32 spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ if (*lp_addprinter_cmd() ) if ( !add_printer_hook(printer) ) { free_a_printer(&printer,2); - return ERROR_ACCESS_DENIED; + return ERRnoaccess; } slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname, @@ -5715,13 +5718,13 @@ static uint32 spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ if ((snum = print_queue_snum(printer->info_2->sharename)) == -1) { free_a_printer(&printer,2); - return ERROR_ACCESS_DENIED; + return ERRnoaccess; } /* you must be a printer admin to add a new printer */ if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { free_a_printer(&printer,2); - return ERROR_ACCESS_DENIED; + return ERRnoaccess; } /* @@ -5730,27 +5733,27 @@ static uint32 spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ if (!check_printer_ok(printer->info_2, snum)) { free_a_printer(&printer,2); - return ERROR_INVALID_PARAMETER; + return ERRinvalidparam; } /* write the ASCII on disk */ if (add_a_printer(*printer, 2) != 0) { free_a_printer(&printer,2); - return ERROR_ACCESS_DENIED; + return ERRnoaccess; } if (!open_printer_hnd(p, handle, name)) { /* Handle open failed - remove addition. */ del_a_printer(printer->info_2->sharename); free_a_printer(&printer,2); - return ERROR_ACCESS_DENIED; + return ERRnoaccess; } free_a_printer(&printer,2); srv_spoolss_sendnotify(p, handle); - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /**************************************************************************** @@ -5773,13 +5776,13 @@ uint32 _spoolss_addprinterex( pipes_struct *p, SPOOL_Q_ADDPRINTEREX *q_u, SPOOL_ case 1: /* we don't handle yet */ /* but I know what to do ... */ - return ERROR_INVALID_LEVEL; + return ERRunknownlevel; case 2: return spoolss_addprinterex_level_2(p, uni_srv_name, info, unk0, unk1, unk2, unk3, user_switch, user, handle); default: - return ERROR_INVALID_LEVEL; + return ERRunknownlevel; } } @@ -5792,7 +5795,7 @@ uint32 _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u, uint32 level = q_u->level; SPOOL_PRINTER_DRIVER_INFO_LEVEL *info = &q_u->info; - uint32 err = NT_STATUS_NOPROBLEMO; + uint32 err = ERRsuccess; NT_PRINTER_DRIVER_INFO_LEVEL driver; struct current_user user; @@ -5803,18 +5806,18 @@ uint32 _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u, convert_printer_driver_info(info, &driver, level); DEBUG(5,("Cleaning driver's information\n")); - if ((err = clean_up_driver_struct(driver, level, &user)) != NT_STATUS_NOPROBLEMO ) + if ((err = clean_up_driver_struct(driver, level, &user)) != ERRsuccess ) goto done; DEBUG(5,("Moving driver to final destination\n")); if(!move_driver_to_download_area(driver, level, &user, &err)) { if (err == 0) - err = ERROR_ACCESS_DENIED; + err = ERRnoaccess; goto done; } if (add_a_printer_driver(driver, level)!=0) { - err = ERROR_ACCESS_DENIED; + err = ERRnoaccess; goto done; } @@ -5842,10 +5845,10 @@ static uint32 getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)-1); if (get_short_archi(short_archi, long_archi)==FALSE) - return ERROR_INVALID_ENVIRONMENT; + return ERRinvalidenvironment; if((info=(DRIVER_DIRECTORY_1 *)malloc(sizeof(DRIVER_DIRECTORY_1))) == NULL) - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", global_myname, short_archi); @@ -5857,7 +5860,7 @@ static uint32 getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen if (!alloc_buffer_size(buffer, *needed)) { safe_free(info); - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } smb_io_driverdir_1("", buffer, info, 0); @@ -5865,9 +5868,9 @@ static uint32 getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen safe_free(info); if (*needed > offered) - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; else - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /**************************************************************************** @@ -5894,7 +5897,7 @@ uint32 _spoolss_getprinterdriverdirectory(pipes_struct *p, SPOOL_Q_GETPRINTERDRI case 1: return getprinterdriverdir_level_1(name, uni_environment, buffer, offered, needed); default: - return ERROR_INVALID_LEVEL; + return ERRunknownlevel; } } @@ -5944,14 +5947,14 @@ uint32 _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S if (!Printer) { DEBUG(0,("_spoolss_enumprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); - return ERROR_INVALID_HANDLE; + return ERRbadfid; } if (!get_printer_snum(p,handle, &snum)) - return ERROR_INVALID_HANDLE; + return ERRbadfid; if (get_a_printer(&printer, 2, lp_servicename(snum)) != 0) - return ERROR_INVALID_HANDLE; + return ERRbadfid; /* * The NT machine wants to know the biggest size of value and data @@ -5974,7 +5977,7 @@ uint32 _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S if (!get_specific_param_by_index(*printer, 2, idx, value, &data, &type, &data_len)) { safe_free(data); free_a_printer(&printer, 2); - return ERROR_NO_MORE_ITEMS; + return ERRnomoreitems; } #endif @@ -6005,7 +6008,7 @@ uint32 _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S if (param_index == 0) { /* No parameters found. */ free_a_printer(&printer, 2); - return ERROR_NO_MORE_ITEMS; + return ERRnomoreitems; } /* the value is an UNICODE string but realvaluesize is the length in bytes including the leading 0 */ @@ -6015,7 +6018,7 @@ uint32 _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S DEBUG(6,("final values: [%d], [%d]\n", *out_value_len, *out_data_len)); free_a_printer(&printer, 2); - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /* @@ -6026,7 +6029,7 @@ uint32 _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S if (!get_specific_param_by_index(*printer, 2, idx, value, &data, &type, &data_len)) { safe_free(data); free_a_printer(&printer, 2); - return ERROR_NO_MORE_ITEMS; + return ERRnomoreitems; } free_a_printer(&printer, 2); @@ -6043,7 +6046,7 @@ uint32 _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S *out_max_value_len=(in_value_len/sizeof(uint16)); if((*out_value=(uint16 *)talloc_zero(p->mem_ctx,in_value_len*sizeof(uint8))) == NULL) { safe_free(data); - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; } *out_value_len = rpcstr_push((char *)*out_value,value, in_value_len, 0); @@ -6054,7 +6057,7 @@ uint32 _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S *out_max_data_len=in_data_len; if((*data_out=(uint8 *)talloc_zero(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) { safe_free(data); - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; } memcpy(*data_out, data, (size_t)data_len); @@ -6062,7 +6065,7 @@ uint32 _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S safe_free(data); - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /**************************************************************************** @@ -6088,15 +6091,15 @@ uint32 _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP if (!Printer) { DEBUG(0,("_spoolss_setprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); - return ERROR_INVALID_HANDLE; + return ERRbadfid; } if (!get_printer_snum(p,handle, &snum)) - return ERROR_INVALID_HANDLE; + return ERRbadfid; status = get_a_printer(&printer, 2, lp_servicename(snum)); if (status != 0x0) - return ERROR_INVALID_NAME; + return ERRinvalidname; convert_specific_param(¶m, value , type, data, real_len); @@ -6114,7 +6117,7 @@ uint32 _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP old_param.data_len) == 0) { DEBUG(3, ("setprinterdata hasn't changed\n")); - status = NT_STATUS_NOPROBLEMO; + status = ERRsuccess; goto done; } } @@ -6124,7 +6127,7 @@ uint32 _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { DEBUG(3, ("security descriptor change denied by existing " "security descriptor\n")); - status = ERROR_ACCESS_DENIED; + status = ERRnoaccess; goto done; } @@ -6160,27 +6163,27 @@ uint32 _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_ if (!Printer) { DEBUG(0,("_spoolss_deleteprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); - return ERROR_INVALID_HANDLE; + return ERRbadfid; } if (!get_printer_snum(p, handle, &snum)) - return ERROR_INVALID_HANDLE; + return ERRbadfid; if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { DEBUG(3, ("_spoolss_deleteprinterdata: printer properties " "change denied by existing security descriptor\n")); - return ERROR_ACCESS_DENIED; + return ERRnoaccess; } status = get_a_printer(&printer, 2, lp_servicename(snum)); if (status != 0x0) - return ERROR_INVALID_NAME; + return ERRinvalidname; ZERO_STRUCTP(¶m); unistr2_to_ascii(param.value, value, sizeof(param.value)-1); if(!unlink_specific_param_if_exist(printer->info_2, ¶m)) - status = ERROR_INVALID_PARAMETER; + status = ERRinvalidparam; else status = mod_a_printer(*printer, 2); @@ -6206,17 +6209,17 @@ uint32 _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM if (!Printer) { DEBUG(0,("_spoolss_addform: Invalid handle (%s).\n", OUR_HANDLE(handle))); - return ERROR_INVALID_HANDLE; + return ERRbadfid; } /* can't add if builtin */ if (get_a_builtin_ntform(&form->name,&tmpForm)) { - return ERROR_INVALID_PARAMETER; + return ERRinvalidparam; } count=get_ntforms(&list); if(!add_a_form(&list, form, &count)) - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; write_ntforms(&list, count); safe_free(list); @@ -6241,17 +6244,17 @@ uint32 _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE if (!Printer) { DEBUG(0,("_spoolss_deleteform: Invalid handle (%s).\n", OUR_HANDLE(handle))); - return ERROR_INVALID_HANDLE; + return ERRbadfid; } /* can't delete if builtin */ if (get_a_builtin_ntform(form_name,&tmpForm)) { - return ERROR_INVALID_PARAMETER; + return ERRinvalidparam; } count = get_ntforms(&list); if(!delete_a_form(&list, form_name, &count, &ret)) - return ERROR_INVALID_PARAMETER; + return ERRinvalidparam; safe_free(list); @@ -6277,11 +6280,11 @@ uint32 _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM * if (!Printer) { DEBUG(0,("_spoolss_setform: Invalid handle (%s).\n", OUR_HANDLE(handle))); - return ERROR_INVALID_HANDLE; + return ERRbadfid; } /* can't set if builtin */ if (get_a_builtin_ntform(&form->name,&tmpForm)) { - return ERROR_INVALID_PARAMETER; + return ERRinvalidparam; } count=get_ntforms(&list); @@ -6301,7 +6304,7 @@ static uint32 enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, ui PRINTPROCESSOR_1 *info_1=NULL; if((info_1 = (PRINTPROCESSOR_1 *)malloc(sizeof(PRINTPROCESSOR_1))) == NULL) - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; (*returned) = 0x1; @@ -6310,7 +6313,7 @@ static uint32 enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, ui *needed += spoolss_size_printprocessor_info_1(info_1); if (!alloc_buffer_size(buffer, *needed)) - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; smb_io_printprocessor_info_1("", buffer, info_1, 0); @@ -6318,10 +6321,10 @@ static uint32 enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, ui if (*needed > offered) { *returned=0; - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } else - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /**************************************************************************** @@ -6357,7 +6360,7 @@ uint32 _spoolss_enumprintprocessors(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCESSORS case 1: return enumprintprocessors_level_1(buffer, offered, needed, returned); default: - return ERROR_INVALID_LEVEL; + return ERRunknownlevel; } } @@ -6369,7 +6372,7 @@ static uint32 enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered, PRINTPROCDATATYPE_1 *info_1=NULL; if((info_1 = (PRINTPROCDATATYPE_1 *)malloc(sizeof(PRINTPROCDATATYPE_1))) == NULL) - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; (*returned) = 0x1; @@ -6378,7 +6381,7 @@ static uint32 enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered, *needed += spoolss_size_printprocdatatype_info_1(info_1); if (!alloc_buffer_size(buffer, *needed)) - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; smb_io_printprocdatatype_info_1("", buffer, info_1, 0); @@ -6386,10 +6389,10 @@ static uint32 enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered, if (*needed > offered) { *returned=0; - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } else - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /**************************************************************************** @@ -6418,7 +6421,7 @@ uint32 _spoolss_enumprintprocdatatypes(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCDAT case 1: return enumprintprocdatatypes_level_1(buffer, offered, needed, returned); default: - return ERROR_INVALID_LEVEL; + return ERRunknownlevel; } } @@ -6431,7 +6434,7 @@ static uint32 enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, uint PRINTMONITOR_1 *info_1=NULL; if((info_1 = (PRINTMONITOR_1 *)malloc(sizeof(PRINTMONITOR_1))) == NULL) - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; (*returned) = 0x1; @@ -6440,7 +6443,7 @@ static uint32 enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, uint *needed += spoolss_size_printmonitor_info_1(info_1); if (!alloc_buffer_size(buffer, *needed)) - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; smb_io_printmonitor_info_1("", buffer, info_1, 0); @@ -6448,10 +6451,10 @@ static uint32 enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, uint if (*needed > offered) { *returned=0; - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } else - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /**************************************************************************** @@ -6462,7 +6465,7 @@ static uint32 enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint PRINTMONITOR_2 *info_2=NULL; if((info_2 = (PRINTMONITOR_2 *)malloc(sizeof(PRINTMONITOR_2))) == NULL) - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; (*returned) = 0x1; @@ -6473,7 +6476,7 @@ static uint32 enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint *needed += spoolss_size_printmonitor_info_2(info_2); if (!alloc_buffer_size(buffer, *needed)) - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; smb_io_printmonitor_info_2("", buffer, info_2, 0); @@ -6481,10 +6484,10 @@ static uint32 enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint if (*needed > offered) { *returned=0; - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; } else - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /**************************************************************************** @@ -6521,7 +6524,7 @@ uint32 _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS *q_ case 2: return enumprintmonitors_level_2(buffer, offered, needed, returned); default: - return ERROR_INVALID_LEVEL; + return ERRunknownlevel; } } @@ -6537,7 +6540,7 @@ static uint32 getjob_level_1(print_queue_struct *queue, int count, int snum, uin if (info_1 == NULL) { safe_free(queue); - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; } for (i=0; i offered) - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; else - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } @@ -6589,7 +6592,7 @@ static uint32 getjob_level_2(print_queue_struct *queue, int count, int snum, uin if (info_2 == NULL) { safe_free(queue); - return ERROR_NOT_ENOUGH_MEMORY; + return ERRnomem; } for (i=0; i offered) - return ERROR_INSUFFICIENT_BUFFER; + return ERRinsufficientbuffer; else - return NT_STATUS_NOPROBLEMO; + return ERRsuccess; } /**************************************************************************** @@ -6660,7 +6663,7 @@ uint32 _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_ *needed=0; if (!get_printer_snum(p, handle, &snum)) - return ERROR_INVALID_HANDLE; + return ERRbadfid; count = print_queue_status(snum, &queue, &prt_status); @@ -6674,6 +6677,6 @@ uint32 _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_ return getjob_level_2(queue, count, snum, jobid, buffer, offered, needed); default: safe_free(queue); - return ERROR_INVALID_LEVEL; + return ERRunknownlevel; } } -- cgit From 4b2016305b7c43c61198f25175531d149db5e989 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 10 Aug 2001 19:38:53 +0000 Subject: Merge in the NT drivers changes from 2.2. Jeremy. (This used to be commit a3781ad38ff6c70238e7e9b83324477e5c9780d5) --- source3/rpc_server/srv_spoolss_nt.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a0f14a9e64..f002ceabd2 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -34,6 +34,7 @@ extern pstring global_myname; #define MAX_OPEN_PRINTER_EXS 50 #endif +#define PHANTOM_DEVMODE_KEY "_p_f_a_n_t_0_m_" #define PRINTER_HANDLE_IS_PRINTER 0 #define PRINTER_HANDLE_IS_PRINTSERVER 1 @@ -5736,6 +5737,13 @@ static uint32 spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ return ERRinvalidparam; } + /* + * When a printer is created, the drivername bound to the printer is used + * to lookup previously saved driver initialization info, which is then + * bound to the new printer, simulating what happens in the Windows arch. + */ + set_driver_init(printer, 2); + /* write the ASCII on disk */ if (add_a_printer(*printer, 2) != 0) { free_a_printer(&printer,2); @@ -6132,10 +6140,23 @@ uint32 _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP } unlink_specific_param_if_exist(printer->info_2, param); - - add_a_specific_param(printer->info_2, ¶m); - status = mod_a_printer(*printer, 2); + /* + * When client side code sets a magic printer data key, detect it and save + * the current printer data and the magic key's data (its the DEVMODE) for + * future printer/driver initializations. + */ + if (param->type==3 && !strcmp( param->value, PHANTOM_DEVMODE_KEY)) { + /* + * Set devmode and printer initialization info + */ + status = save_driver_init(printer, 2, param); + } + else { + add_a_specific_param(printer->info_2, ¶m); + status = mod_a_printer(*printer, 2); + } + done: free_a_printer(&printer, 2); if (param) -- cgit From 2e783a47076bd0994b6ce86df7ec967bc1c2da63 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 12 Aug 2001 17:30:01 +0000 Subject: this is a big global fix for the ptr = Realloc(ptr, size) bug. many possible mem leaks, and segfaults fixed. someone should port this fix to 2.2 also. (This used to be commit fa8e55b8b465114ce209344965c1ca0333b84db9) --- source3/rpc_server/srv_spoolss_nt.c | 69 +++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 19 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index f002ceabd2..023c9a1203 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -915,20 +915,24 @@ static BOOL convert_printer_info(const SPOOL_PRINTER_INFO_LEVEL *uni, static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL *uni, NT_PRINTER_DRIVER_INFO_LEVEL *printer, uint32 level) { + BOOL result = True; + switch (level) { case 3: printer->info_3=NULL; - uni_2_asc_printer_driver_3(uni->info_3, &printer->info_3); + if (!uni_2_asc_printer_driver_3(uni->info_3, &printer->info_3)) + result = False; break; case 6: printer->info_6=NULL; - uni_2_asc_printer_driver_6(uni->info_6, &printer->info_6); + if (!uni_2_asc_printer_driver_6(uni->info_6, &printer->info_6)) + result = False; break; default: break; } - return True; + return result; } BOOL convert_devicemode(char *printername, const DEVICEMODE *devmode, @@ -2200,7 +2204,7 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int uint16 type; uint16 field; - SPOOL_NOTIFY_INFO_DATA *current_data; + SPOOL_NOTIFY_INFO_DATA *current_data, *tid; NT_PRINTER_INFO_LEVEL *printer = NULL; print_queue_struct *queue=NULL; @@ -2220,9 +2224,12 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int if (!search_notify(type, field, &j) ) continue; - if((info->data=(SPOOL_NOTIFY_INFO_DATA *)Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) { + if((tid=(SPOOL_NOTIFY_INFO_DATA *)Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) { + DEBUG(0,("construct_notify_printer_info: failed to enlarge buffer info->data!\n")); return False; } + else info->data = tid; + current_data=&info->data[info->count]; construct_info_data(current_data, type, field, id); @@ -2256,7 +2263,7 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, uint16 type; uint16 field; - SPOOL_NOTIFY_INFO_DATA *current_data; + SPOOL_NOTIFY_INFO_DATA *current_data, *tid; DEBUG(4,("construct_notify_jobs_info\n")); @@ -2272,9 +2279,11 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, if (!search_notify(type, field, &j) ) continue; - if((info->data=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) { + if((tid=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) { + DEBUG(0,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n")); return False; } + else info->data = tid; current_data=&(info->data[info->count]); @@ -2877,7 +2886,7 @@ static BOOL enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 of int snum; int i; int n_services=lp_numservices(); - PRINTER_INFO_1 *printers=NULL; + PRINTER_INFO_1 *tp, *printers=NULL; PRINTER_INFO_1 current_prt; DEBUG(4,("enum_all_printers_info_1\n")); @@ -2887,10 +2896,13 @@ static BOOL enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 of DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum)); if (construct_printer_info_1(flags, ¤t_prt, snum)) { - if((printers=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_1))) == NULL) { + if((tp=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_1))) == NULL) { + DEBUG(0,("enum_all_printers_info_1: failed to enlarge printers buffer!\n")); + safe_free(printers); *returned=0; return ERRnomem; } + else printers = tp; DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_1\n", *returned)); memcpy(&printers[*returned], ¤t_prt, sizeof(PRINTER_INFO_1)); (*returned)++; @@ -3024,7 +3036,7 @@ static BOOL enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint32 int snum; int i; int n_services=lp_numservices(); - PRINTER_INFO_2 *printers=NULL; + PRINTER_INFO_2 *tp, *printers=NULL; PRINTER_INFO_2 current_prt; for (snum=0; snum Date: Mon, 13 Aug 2001 21:30:27 +0000 Subject: merge from 2.2 (This used to be commit 7049217eb40dbe3de6c05fe43742d2f684501723) --- source3/rpc_server/srv_spoolss_nt.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 023c9a1203..0710f05870 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -811,6 +811,18 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, if (printer_default->access_required == 0x0) printer_default->access_required = PRINTER_ACCESS_USE; + /* + * If we are not serving the printer driver for this printer, + * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This + * will keep NT clients happy --jerry + */ + + if (lp_use_client_driver(snum) + && (printer_default->access_required & PRINTER_ACCESS_ADMINISTER)) + { + printer_default->access_required = PRINTER_ACCESS_USE; + } + if (!print_access_check(&user, snum, printer_default->access_required)) { DEBUG(3, ("access DENIED for printer open\n")); close_printer_handle(p, handle); -- cgit From b031af348c7dcc8c74bf49945211c466b8eca079 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 27 Aug 2001 19:46:22 +0000 Subject: converted another bunch of stuff to NTSTATUS (This used to be commit 1d36250e338ae0ff9fbbf86019809205dd97d05e) --- source3/rpc_server/srv_spoolss_nt.c | 452 ++++++++++++++++++------------------ 1 file changed, 224 insertions(+), 228 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 0710f05870..0ebbc2aada 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -160,7 +160,7 @@ static void free_spool_notify_option(SPOOL_NOTIFY_OPTION **pp) static void srv_spoolss_replycloseprinter(POLICY_HND *handle) { - uint32 status; + NTSTATUS status; /* weird if the test succeds !!! */ if (smb_connections==0) { @@ -270,18 +270,18 @@ static BOOL close_printer_handle(pipes_struct *p, POLICY_HND *hnd) /**************************************************************************** delete a printer given a handle ****************************************************************************/ -static uint32 delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) +static NTSTATUS delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) { Printer_entry *Printer = find_printer_index_by_hnd(p, hnd); if (!Printer) { DEBUG(0,("delete_printer_handle: Invalid handle (%s)\n", OUR_HANDLE(hnd))); - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; } if (del_a_printer(Printer->dev.handlename) != 0) { DEBUG(3,("Error deleting printer %s\n", Printer->dev.handlename)); - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; } /* Check calling user has permission to delete printer. Note that @@ -291,7 +291,7 @@ static uint32 delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) if (!print_access_check(NULL, -1, PRINTER_ACCESS_ADMINISTER)) { DEBUG(3, ("printer delete denied by security descriptor\n")); - return ERRnoaccess; + return NT_STATUS_ACCESS_DENIED; } if (*lp_deleteprinter_cmd()) { @@ -308,7 +308,7 @@ static uint32 delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) DEBUG(10,("Running [%s]\n", command)); ret = smbrun(command, NULL); if (ret != 0) { - return ERRbadfid; /* What to return here? */ + return NT_STATUS_INVALID_HANDLE; /* What to return here? */ } DEBUGADD(10,("returned [%d]\n", ret)); @@ -317,12 +317,12 @@ static uint32 delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) if ( ( i = lp_servicenumber( Printer->dev.handlename ) ) >= 0 ) { lp_killservice( i ); - return ERRsuccess; + return NT_STATUS_OK; } else - return ERRnoaccess; + return NT_STATUS_ACCESS_DENIED; } - return ERRsuccess; + return NT_STATUS_OK; } /**************************************************************************** @@ -618,7 +618,7 @@ static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size) static void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size_t len) { fstring printer; - uint32 status; + NTSTATUS status; struct pipes_struct *p; struct policy *pol; struct handle_list *hl; @@ -706,10 +706,10 @@ static BOOL srv_spoolss_sendnotify(pipes_struct *p, POLICY_HND *handle) * called from the spoolss dispatcher ********************************************************************/ -uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, SPOOL_R_OPEN_PRINTER_EX *r_u) +NTSTATUS _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, SPOOL_R_OPEN_PRINTER_EX *r_u) { #if 0 - uint32 result = ERRsuccess; + uint32 result = NT_STATUS_OK; #endif UNISTR2 *printername = NULL; @@ -726,7 +726,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, printername = &q_u->printername; if (printername == NULL) - return ERRinvalidprintername; + return NT_STATUS_OBJECT_NAME_INVALID; /* some sanity check because you can open a printer or a print server */ /* aka: \\server\printer or \\server */ @@ -735,7 +735,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, DEBUGADD(3,("checking name: %s\n",name)); if (!open_printer_hnd(p, handle, name)) - return ERRinvalidprintername; + return NT_STATUS_OBJECT_NAME_INVALID; /* if (printer_default->datatype_ptr != NULL) @@ -749,7 +749,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, if (!set_printer_hnd_accesstype(p, handle, printer_default->access_required)) { close_printer_handle(p, handle); - return ERRnoaccess; + return NT_STATUS_ACCESS_DENIED; } /* @@ -779,7 +779,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, if (handle_is_printserver(p, handle)) { if (printer_default->access_required == 0) { - return ERRsuccess; + return NT_STATUS_OK; } else if ((printer_default->access_required & SERVER_ACCESS_ADMINISTER ) == SERVER_ACCESS_ADMINISTER) { @@ -788,14 +788,14 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, if (!lp_ms_add_printer_wizard()) { close_printer_handle(p, handle); - return ERRnoaccess; + return NT_STATUS_ACCESS_DENIED; } else if (user.uid == 0 || user_in_list(uidtoname(user.uid), lp_printer_admin(snum))) { - return ERRsuccess; + return NT_STATUS_OK; } else { close_printer_handle(p, handle); - return ERRnoaccess; + return NT_STATUS_ACCESS_DENIED; } } } @@ -805,7 +805,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, doesn't have print permission. */ if (!get_printer_snum(p, handle, &snum)) - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; /* map an empty access mask to the minimum access mask */ if (printer_default->access_required == 0x0) @@ -826,7 +826,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, if (!print_access_check(&user, snum, printer_default->access_required)) { DEBUG(3, ("access DENIED for printer open\n")); close_printer_handle(p, handle); - return ERRnoaccess; + return NT_STATUS_ACCESS_DENIED; } /* @@ -905,7 +905,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, #endif } - return ERRsuccess; + return NT_STATUS_OK; } /**************************************************************************** @@ -1021,27 +1021,27 @@ BOOL convert_devicemode(char *printername, const DEVICEMODE *devmode, * _spoolss_enddocprinter_internal. ********************************************************************/ -static uint32 _spoolss_enddocprinter_internal(pipes_struct *p, POLICY_HND *handle) +static NTSTATUS _spoolss_enddocprinter_internal(pipes_struct *p, POLICY_HND *handle) { Printer_entry *Printer=find_printer_index_by_hnd(p, handle); if (!Printer) { DEBUG(0,("_spoolss_enddocprinter_internal: Invalid handle (%s)\n", OUR_HANDLE(handle))); - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; } Printer->document_started=False; print_job_end(Printer->jobid,True); /* error codes unhandled so far ... */ - return 0x0; + return NT_STATUS_OK; } /******************************************************************** * api_spoolss_closeprinter ********************************************************************/ -uint32 _spoolss_closeprinter(pipes_struct *p, SPOOL_Q_CLOSEPRINTER *q_u, SPOOL_R_CLOSEPRINTER *r_u) +NTSTATUS _spoolss_closeprinter(pipes_struct *p, SPOOL_Q_CLOSEPRINTER *q_u, SPOOL_R_CLOSEPRINTER *r_u) { POLICY_HND *handle = &q_u->handle; @@ -1053,9 +1053,9 @@ uint32 _spoolss_closeprinter(pipes_struct *p, SPOOL_Q_CLOSEPRINTER *q_u, SPOOL_R memcpy(&r_u->handle, &q_u->handle, sizeof(r_u->handle)); if (!close_printer_handle(p, handle)) - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; - return ERRsuccess; + return NT_STATUS_OK; } /******************************************************************** @@ -1063,12 +1063,11 @@ uint32 _spoolss_closeprinter(pipes_struct *p, SPOOL_Q_CLOSEPRINTER *q_u, SPOOL_R ********************************************************************/ -uint32 _spoolss_deleteprinter(pipes_struct *p, SPOOL_Q_DELETEPRINTER *q_u, SPOOL_R_DELETEPRINTER *r_u) +NTSTATUS _spoolss_deleteprinter(pipes_struct *p, SPOOL_Q_DELETEPRINTER *q_u, SPOOL_R_DELETEPRINTER *r_u) { POLICY_HND *handle = &q_u->handle; - Printer_entry *Printer=find_printer_index_by_hnd(p, handle); - uint32 result; + NTSTATUS result; if (Printer && Printer->document_started) _spoolss_enddocprinter_internal(p, handle); /* print job was not closed */ @@ -1077,7 +1076,7 @@ uint32 _spoolss_deleteprinter(pipes_struct *p, SPOOL_Q_DELETEPRINTER *q_u, SPOOL result = delete_printer_handle(p, handle); - if (result == ERRsuccess) { + if (NT_STATUS_IS_OK(result)) { srv_spoolss_sendnotify(p, handle); } @@ -1125,7 +1124,7 @@ static int get_version_id (char * arch) * --jerry ********************************************************************/ -uint32 _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER *q_u, +NTSTATUS _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER *q_u, SPOOL_R_DELETEPRINTERDRIVER *r_u) { fstring driver; @@ -1138,21 +1137,18 @@ uint32 _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER /* check that we have a valid driver name first */ if ((version=get_version_id(arch)) == -1) { - /* this is what NT returns */ - return ERRinvalidenvironment; + return NT_STATUS_REVISION_MISMATCH; } ZERO_STRUCT(info); if (get_a_printer_driver (&info, 3, driver, arch, version) != 0) { - /* this is what NT returns */ - return ERRunknownprinterdriver; + return NT_STATUS_DRIVER_ORDINAL_NOT_FOUND; } if (printer_driver_in_use(arch, driver)) { - /* this is what NT returns */ - return ERRprinterdriverinuse; + return NT_STATUS_NETWORK_BUSY; } return delete_printer_driver(info.info_3); @@ -1297,7 +1293,7 @@ static BOOL getprinterdata_printer(pipes_struct *p, TALLOC_CTX *ctx, POLICY_HND * spoolss_getprinterdata ********************************************************************/ -uint32 _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPOOL_R_GETPRINTERDATA *r_u) +NTSTATUS _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPOOL_R_GETPRINTERDATA *r_u) { POLICY_HND *handle = &q_u->handle; UNISTR2 *valuename = &q_u->valuename; @@ -1328,9 +1324,9 @@ uint32 _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO if (!Printer) { if((*data=(uint8 *)malloc(4*sizeof(uint8))) == NULL) - return ERRnomem; + return NT_STATUS_NO_MEMORY; DEBUG(0,("_spoolss_getprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; } unistr2_to_ascii(value, valuename, sizeof(value)-1); @@ -1345,18 +1341,18 @@ uint32 _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO /* reply this param doesn't exist */ if (*out_size) { if((*data=(uint8 *)talloc_zero(p->mem_ctx, *out_size*sizeof(uint8))) == NULL) - return ERRnomem; + return NT_STATUS_NO_MEMORY; } else { *data = NULL; } - return ERRinvalidparam; + return NT_STATUS_INVALID_PARAMETER; } if (*needed > *out_size) - return ERRmoredata; + return STATUS_MORE_ENTRIES; else { - return ERRsuccess; + return NT_STATUS_OK; } } @@ -1365,7 +1361,7 @@ uint32 _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO ****************************************************************************/ static BOOL srv_spoolss_replyopenprinter(char *printer, uint32 localprinter, uint32 type, POLICY_HND *handle) { - uint32 status; + NTSTATUS status; /* * If it's the first connection, contact the client @@ -1402,7 +1398,7 @@ static BOOL srv_spoolss_replyopenprinter(char *printer, uint32 localprinter, uin * called from api_spoolss_rffpcnex ********************************************************************/ -uint32 _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNEX *r_u) +NTSTATUS _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNEX *r_u) { POLICY_HND *handle = &q_u->handle; uint32 flags = q_u->flags; @@ -1417,7 +1413,7 @@ uint32 _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE if (!Printer) { DEBUG(0,("_spoolss_rffpcnex: Invalid handle (%s).\n", OUR_HANDLE(handle))); - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; } Printer->notify.flags=flags; @@ -1437,7 +1433,7 @@ uint32 _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE &Printer->notify.client_hnd)) Printer->notify.client_connected=True; - return ERRsuccess; + return NT_STATUS_OK; } /******************************************************************* @@ -2338,7 +2334,7 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, * ********************************************************************/ -static uint32 printserver_notify_info(pipes_struct *p, POLICY_HND *hnd, +static NTSTATUS printserver_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info, TALLOC_CTX *mem_ctx) { @@ -2386,7 +2382,7 @@ static uint32 printserver_notify_info(pipes_struct *p, POLICY_HND *hnd, } */ - return ERRsuccess; + return NT_STATUS_OK; } /******************************************************************* @@ -2469,14 +2465,14 @@ static uint32 printer_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY info->data[i].id, info->data[i].size, info->data[i].enc_type)); } */ - return ERRsuccess; + return NT_STATUS_OK; } /******************************************************************** * spoolss_rfnpcnex ********************************************************************/ -uint32 _spoolss_rfnpcnex( pipes_struct *p, SPOOL_Q_RFNPCNEX *q_u, SPOOL_R_RFNPCNEX *r_u) +NTSTATUS _spoolss_rfnpcnex( pipes_struct *p, SPOOL_Q_RFNPCNEX *q_u, SPOOL_R_RFNPCNEX *r_u) { POLICY_HND *handle = &q_u->handle; /* uint32 change = q_u->change; - notused. */ @@ -2484,7 +2480,7 @@ uint32 _spoolss_rfnpcnex( pipes_struct *p, SPOOL_Q_RFNPCNEX *q_u, SPOOL_R_RFNPCN SPOOL_NOTIFY_INFO *info = &r_u->info; Printer_entry *Printer=find_printer_index_by_hnd(p, handle); - uint32 result = ERRbadfid; + NTSTATUS result = NT_STATUS_INVALID_HANDLE; /* we always have a NOTIFY_INFO struct */ r_u->info_ptr=0x1; @@ -2941,7 +2937,7 @@ static BOOL enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 of return ERRinsufficientbuffer; } else - return ERRsuccess; + return NT_STATUS_OK; } /******************************************************************** @@ -3023,7 +3019,7 @@ static BOOL enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, ui return ERRinsufficientbuffer; } else - return ERRsuccess; + return NT_STATUS_OK; } /******************************************************************** @@ -3097,13 +3093,13 @@ static BOOL enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint32 return ERRinsufficientbuffer; } else - return ERRsuccess; + return NT_STATUS_OK; } /******************************************************************** * handle enumeration of printers at level 1 ********************************************************************/ -static uint32 enumprinters_level1( uint32 flags, fstring name, +static NTSTATUS enumprinters_level1( uint32 flags, fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { @@ -3121,13 +3117,13 @@ static uint32 enumprinters_level1( uint32 flags, fstring name, if (flags & PRINTER_ENUM_NETWORK) return enum_all_printers_info_1_network(buffer, offered, needed, returned); - return ERRsuccess; /* NT4sp5 does that */ + return NT_STATUS_OK; /* NT4sp5 does that */ } /******************************************************************** * handle enumeration of printers at level 2 ********************************************************************/ -static uint32 enumprinters_level2( uint32 flags, fstring servername, +static NTSTATUS enumprinters_level2( uint32 flags, fstring servername, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { @@ -3153,18 +3149,18 @@ static uint32 enumprinters_level2( uint32 flags, fstring servername, if (flags & PRINTER_ENUM_REMOTE) return ERRunknownlevel; - return ERRsuccess; + return NT_STATUS_OK; } /******************************************************************** * handle enumeration of printers at level 5 ********************************************************************/ -static uint32 enumprinters_level5( uint32 flags, fstring servername, +static NTSTATUS enumprinters_level5( uint32 flags, fstring servername, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { /* return enum_all_printers_info_5(buffer, offered, needed, returned);*/ - return ERRsuccess; + return NT_STATUS_OK; } /******************************************************************** @@ -3173,7 +3169,7 @@ static uint32 enumprinters_level5( uint32 flags, fstring servername, * called from api_spoolss_enumprinters (see this to understand) ********************************************************************/ -uint32 _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOOL_R_ENUMPRINTERS *r_u) +NTSTATUS _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOOL_R_ENUMPRINTERS *r_u) { uint32 flags = q_u->flags; UNISTR2 *servername = &q_u->servername; @@ -3226,7 +3222,7 @@ uint32 _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOOL_ /**************************************************************************** ****************************************************************************/ -static uint32 getprinter_level_0(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static NTSTATUS getprinter_level_0(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_0 *printer=NULL; @@ -3253,12 +3249,12 @@ static uint32 getprinter_level_0(int snum, NEW_BUFFER *buffer, uint32 offered, u return ERRinsufficientbuffer; } else - return ERRsuccess; + return NT_STATUS_OK; } /**************************************************************************** ****************************************************************************/ -static uint32 getprinter_level_1(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static NTSTATUS getprinter_level_1(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_1 *printer=NULL; @@ -3285,12 +3281,12 @@ static uint32 getprinter_level_1(int snum, NEW_BUFFER *buffer, uint32 offered, u return ERRinsufficientbuffer; } else - return ERRsuccess; + return NT_STATUS_OK; } /**************************************************************************** ****************************************************************************/ -static uint32 getprinter_level_2(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static NTSTATUS getprinter_level_2(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_2 *printer=NULL; @@ -3320,12 +3316,12 @@ static uint32 getprinter_level_2(int snum, NEW_BUFFER *buffer, uint32 offered, u return ERRinsufficientbuffer; } else - return ERRsuccess; + return NT_STATUS_OK; } /**************************************************************************** ****************************************************************************/ -static uint32 getprinter_level_3(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static NTSTATUS getprinter_level_3(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_3 *printer=NULL; @@ -3350,13 +3346,13 @@ static uint32 getprinter_level_3(int snum, NEW_BUFFER *buffer, uint32 offered, u return ERRinsufficientbuffer; } else - return ERRsuccess; + return NT_STATUS_OK; } /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GETPRINTER *r_u) +NTSTATUS _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GETPRINTER *r_u) { POLICY_HND *handle = &q_u->handle; uint32 level = q_u->level; @@ -3373,7 +3369,7 @@ uint32 _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GET *needed=0; if (!get_printer_snum(p, handle, &snum)) - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; switch (level) { case 0: @@ -3400,7 +3396,7 @@ static void fill_printer_driver_info_1(DRIVER_INFO_1 *info, NT_PRINTER_DRIVER_IN /******************************************************************** * construct_printer_driver_info_1 ********************************************************************/ -static uint32 construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, fstring servername, fstring architecture, uint32 version) +static NTSTATUS construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, fstring servername, fstring architecture, uint32 version) { NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; @@ -3417,7 +3413,7 @@ static uint32 construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, fst free_a_printer(&printer,2); - return ERRsuccess; + return NT_STATUS_OK; } /******************************************************************** @@ -3457,7 +3453,7 @@ static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, NT_PRINTER_DRIVER_IN * construct_printer_driver_info_2 * fill a printer_info_2 struct ********************************************************************/ -static uint32 construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fstring servername, fstring architecture, uint32 version) +static NTSTATUS construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fstring servername, fstring architecture, uint32 version) { NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; @@ -3475,7 +3471,7 @@ static uint32 construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fst free_a_printer(&printer,2); - return ERRsuccess; + return NT_STATUS_OK; } /******************************************************************** @@ -3570,11 +3566,11 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_IN * construct_printer_info_3 * fill a printer_info_3 struct ********************************************************************/ -static uint32 construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fstring servername, fstring architecture, uint32 version) +static NTSTATUS construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fstring servername, fstring architecture, uint32 version) { NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; - uint32 status=0; + NTSTATUS status=0; ZERO_STRUCT(driver); status=get_a_printer(&printer, 2, lp_servicename(snum) ); @@ -3593,7 +3589,7 @@ static uint32 construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fst free_a_printer(&printer,2); - return ERRsuccess; + return NT_STATUS_OK; } /******************************************************************** @@ -3664,11 +3660,11 @@ static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_IN * construct_printer_info_6 * fill a printer_info_6 struct ********************************************************************/ -static uint32 construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, fstring servername, fstring architecture, uint32 version) +static NTSTATUS construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, fstring servername, fstring architecture, uint32 version) { NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; - uint32 status=0; + NTSTATUS status=0; ZERO_STRUCT(driver); status=get_a_printer(&printer, 2, lp_servicename(snum) ); @@ -3702,7 +3698,7 @@ static uint32 construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, fst free_a_printer(&printer,2); - return ERRsuccess; + return NT_STATUS_OK; } /**************************************************************************** @@ -3724,16 +3720,16 @@ static void free_printer_driver_info_6(DRIVER_INFO_6 *info) /**************************************************************************** ****************************************************************************/ -static uint32 getprinterdriver2_level1(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static NTSTATUS getprinterdriver2_level1(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_1 *info=NULL; - uint32 status; + NTSTATUS status; if((info=(DRIVER_INFO_1 *)malloc(sizeof(DRIVER_INFO_1))) == NULL) return ERRnomem; status=construct_printer_driver_info_1(info, snum, servername, architecture, version); - if (status != ERRsuccess) { + if (status != NT_STATUS_OK) { safe_free(info); return status; } @@ -3755,21 +3751,21 @@ static uint32 getprinterdriver2_level1(fstring servername, fstring architecture, if (*needed > offered) return ERRinsufficientbuffer; else - return ERRsuccess; + return NT_STATUS_OK; } /**************************************************************************** ****************************************************************************/ -static uint32 getprinterdriver2_level2(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static NTSTATUS getprinterdriver2_level2(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_2 *info=NULL; - uint32 status; + NTSTATUS status; if((info=(DRIVER_INFO_2 *)malloc(sizeof(DRIVER_INFO_2))) == NULL) return ERRnomem; status=construct_printer_driver_info_2(info, snum, servername, architecture, version); - if (status != ERRsuccess) { + if (status != NT_STATUS_OK) { safe_free(info); return status; } @@ -3791,20 +3787,20 @@ static uint32 getprinterdriver2_level2(fstring servername, fstring architecture, if (*needed > offered) return ERRinsufficientbuffer; else - return ERRsuccess; + return NT_STATUS_OK; } /**************************************************************************** ****************************************************************************/ -static uint32 getprinterdriver2_level3(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static NTSTATUS getprinterdriver2_level3(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_3 info; - uint32 status; + NTSTATUS status; ZERO_STRUCT(info); status=construct_printer_driver_info_3(&info, snum, servername, architecture, version); - if (status != ERRsuccess) { + if (status != NT_STATUS_OK) { return status; } @@ -3824,20 +3820,20 @@ static uint32 getprinterdriver2_level3(fstring servername, fstring architecture, if (*needed > offered) return ERRinsufficientbuffer; else - return ERRsuccess; + return NT_STATUS_OK; } /**************************************************************************** ****************************************************************************/ -static uint32 getprinterdriver2_level6(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static NTSTATUS getprinterdriver2_level6(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_6 info; - uint32 status; + NTSTATUS status; ZERO_STRUCT(info); status=construct_printer_driver_info_6(&info, snum, servername, architecture, version); - if (status != ERRsuccess) { + if (status != NT_STATUS_OK) { return status; } @@ -3857,13 +3853,13 @@ static uint32 getprinterdriver2_level6(fstring servername, fstring architecture, if (*needed > offered) return ERRinsufficientbuffer; else - return ERRsuccess; + return NT_STATUS_OK; } /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_u, SPOOL_R_GETPRINTERDRIVER2 *r_u) +NTSTATUS _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_u, SPOOL_R_GETPRINTERDRIVER2 *r_u) { POLICY_HND *handle = &q_u->handle; UNISTR2 *uni_arch = &q_u->architecture; @@ -3894,7 +3890,7 @@ uint32 _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_ unistr2_to_ascii(architecture, uni_arch, sizeof(architecture)-1); if (!get_printer_snum(p, handle, &snum)) - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; switch (level) { case 1: @@ -3913,7 +3909,7 @@ uint32 _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_ /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_startpageprinter(pipes_struct *p, SPOOL_Q_STARTPAGEPRINTER *q_u, SPOOL_R_STARTPAGEPRINTER *r_u) +NTSTATUS _spoolss_startpageprinter(pipes_struct *p, SPOOL_Q_STARTPAGEPRINTER *q_u, SPOOL_R_STARTPAGEPRINTER *r_u) { POLICY_HND *handle = &q_u->handle; @@ -3925,13 +3921,13 @@ uint32 _spoolss_startpageprinter(pipes_struct *p, SPOOL_Q_STARTPAGEPRINTER *q_u, } DEBUG(3,("Error in startpageprinter printer handle\n")); - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; } /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_endpageprinter(pipes_struct *p, SPOOL_Q_ENDPAGEPRINTER *q_u, SPOOL_R_ENDPAGEPRINTER *r_u) +NTSTATUS _spoolss_endpageprinter(pipes_struct *p, SPOOL_Q_ENDPAGEPRINTER *q_u, SPOOL_R_ENDPAGEPRINTER *r_u) { POLICY_HND *handle = &q_u->handle; @@ -3939,12 +3935,12 @@ uint32 _spoolss_endpageprinter(pipes_struct *p, SPOOL_Q_ENDPAGEPRINTER *q_u, SPO if (!Printer) { DEBUG(0,("_spoolss_endpageprinter: Invalid handle (%s).\n",OUR_HANDLE(handle))); - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; } Printer->page_started=False; - return ERRsuccess; + return NT_STATUS_OK; } /******************************************************************** @@ -3953,7 +3949,7 @@ uint32 _spoolss_endpageprinter(pipes_struct *p, SPOOL_Q_ENDPAGEPRINTER *q_u, SPO * ********************************************************************/ -uint32 _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, SPOOL_R_STARTDOCPRINTER *r_u) +NTSTATUS _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, SPOOL_R_STARTDOCPRINTER *r_u) { POLICY_HND *handle = &q_u->handle; /* uint32 level = q_u->doc_info_container.level; - notused. */ @@ -3969,7 +3965,7 @@ uint32 _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, S if (!Printer) { DEBUG(0,("_spoolss_startdocprinter: Invalid handle (%s)\n", OUR_HANDLE(handle))); - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; } get_current_user(&user, p); @@ -3996,7 +3992,7 @@ uint32 _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, S /* get the share number of the printer */ if (!get_printer_snum(p, handle, &snum)) { - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; } unistr2_to_ascii(jobname, &info_1->docname, sizeof(jobname)); @@ -4022,7 +4018,7 @@ uint32 _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, S * ********************************************************************/ -uint32 _spoolss_enddocprinter(pipes_struct *p, SPOOL_Q_ENDDOCPRINTER *q_u, SPOOL_R_ENDDOCPRINTER *r_u) +NTSTATUS _spoolss_enddocprinter(pipes_struct *p, SPOOL_Q_ENDDOCPRINTER *q_u, SPOOL_R_ENDDOCPRINTER *r_u) { POLICY_HND *handle = &q_u->handle; @@ -4032,7 +4028,7 @@ uint32 _spoolss_enddocprinter(pipes_struct *p, SPOOL_Q_ENDDOCPRINTER *q_u, SPOOL /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_writeprinter(pipes_struct *p, SPOOL_Q_WRITEPRINTER *q_u, SPOOL_R_WRITEPRINTER *r_u) +NTSTATUS _spoolss_writeprinter(pipes_struct *p, SPOOL_Q_WRITEPRINTER *q_u, SPOOL_R_WRITEPRINTER *r_u) { POLICY_HND *handle = &q_u->handle; uint32 buffer_size = q_u->buffer_size; @@ -4044,7 +4040,7 @@ uint32 _spoolss_writeprinter(pipes_struct *p, SPOOL_Q_WRITEPRINTER *q_u, SPOOL_R if (!Printer) { DEBUG(0,("_spoolss_writeprinter: Invalid handle (%s)\n",OUR_HANDLE(handle))); r_u->buffer_written = q_u->buffer_size2; - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; } (*buffer_written) = print_job_write(Printer->jobid, (char *)buffer, buffer_size); @@ -4060,7 +4056,7 @@ uint32 _spoolss_writeprinter(pipes_struct *p, SPOOL_Q_WRITEPRINTER *q_u, SPOOL_R * called from the spoolss dispatcher * ********************************************************************/ -static uint32 control_printer(POLICY_HND *handle, uint32 command, +static NTSTATUS control_printer(POLICY_HND *handle, uint32 command, pipes_struct *p) { struct current_user user; @@ -4071,11 +4067,11 @@ static uint32 control_printer(POLICY_HND *handle, uint32 command, if (!Printer) { DEBUG(0,("control_printer: Invalid handle (%s)\n", OUR_HANDLE(handle))); - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; } if (!get_printer_snum(p, handle, &snum)) - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; switch (command) { case PRINTER_CONTROL_PAUSE: @@ -4105,7 +4101,7 @@ static uint32 control_printer(POLICY_HND *handle, uint32 command, * api_spoolss_abortprinter ********************************************************************/ -uint32 _spoolss_abortprinter(pipes_struct *p, SPOOL_Q_ABORTPRINTER *q_u, SPOOL_R_ABORTPRINTER *r_u) +NTSTATUS _spoolss_abortprinter(pipes_struct *p, SPOOL_Q_ABORTPRINTER *q_u, SPOOL_R_ABORTPRINTER *r_u) { POLICY_HND *handle = &q_u->handle; @@ -4116,7 +4112,7 @@ uint32 _spoolss_abortprinter(pipes_struct *p, SPOOL_Q_ABORTPRINTER *q_u, SPOOL_R * called by spoolss_api_setprinter * when updating a printer description ********************************************************************/ -static uint32 update_printer_sec(POLICY_HND *handle, uint32 level, +static NTSTATUS update_printer_sec(POLICY_HND *handle, uint32 level, const SPOOL_PRINTER_INFO_LEVEL *info, pipes_struct *p, SEC_DESC_BUF *secdesc_ctr) { @@ -4131,7 +4127,7 @@ static uint32 update_printer_sec(POLICY_HND *handle, uint32 level, DEBUG(0,("update_printer_sec: Invalid handle (%s)\n", OUR_HANDLE(handle))); - result = ERRbadfid; + result = NT_STATUS_INVALID_HANDLE; goto done; } @@ -4181,7 +4177,7 @@ static uint32 update_printer_sec(POLICY_HND *handle, uint32 level, new_secdesc_ctr = sec_desc_merge(p->mem_ctx, secdesc_ctr, old_secdesc_ctr); if (sec_desc_equal(new_secdesc_ctr->sec, old_secdesc_ctr->sec)) { - result = ERRsuccess; + result = NT_STATUS_OK; goto done; } @@ -4195,7 +4191,7 @@ static uint32 update_printer_sec(POLICY_HND *handle, uint32 level, information. */ if (!print_access_check(&user, snum, PRINTER_ACCESS_ADMINISTER)) { - result = ERRnoaccess; + result = NT_STATUS_ACCESS_DENIED; goto done; } @@ -4528,7 +4524,7 @@ static BOOL nt_printer_info_level_equal(NT_PRINTER_INFO_LEVEL *p1, * when updating a printer description ********************************************************************/ -static uint32 update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, +static NTSTATUS update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, const SPOOL_PRINTER_INFO_LEVEL *info, DEVICEMODE *devmode) { @@ -4539,7 +4535,7 @@ static uint32 update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, DEBUG(8,("update_printer\n")); - result = ERRsuccess; + result = NT_STATUS_OK; if (level!=2) { DEBUG(0,("Send a mail to samba@samba.org\n")); @@ -4549,18 +4545,18 @@ static uint32 update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, } if (!Printer) { - result = ERRbadfid; + result = NT_STATUS_INVALID_HANDLE; goto done; } if (!get_printer_snum(p, handle, &snum)) { - result = ERRbadfid; + result = NT_STATUS_INVALID_HANDLE; goto done; } if((get_a_printer(&printer, 2, lp_servicename(snum)) != 0) || (get_a_printer(&old_printer, 2, lp_servicename(snum)) != 0)) { - result = ERRbadfid; + result = NT_STATUS_INVALID_HANDLE; goto done; } @@ -4599,7 +4595,7 @@ static uint32 update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, if (nt_printer_info_level_equal(printer, old_printer)) { DEBUG(3, ("printer info has not changed\n")); - result = ERRsuccess; + result = NT_STATUS_OK; goto done; } @@ -4608,7 +4604,7 @@ static uint32 update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { DEBUG(3, ("printer property change denied by security " "descriptor\n")); - result = ERRnoaccess; + result = NT_STATUS_ACCESS_DENIED; goto done; } @@ -4616,7 +4612,7 @@ static uint32 update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, if (*lp_addprinter_cmd() ) if ( !add_printer_hook(printer) ) { - result = ERRnoaccess; + result = NT_STATUS_ACCESS_DENIED; goto done; } @@ -4624,7 +4620,7 @@ static uint32 update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, if (add_a_printer(*printer, 2)!=0) { /* I don't really know what to return here !!! */ - result = ERRnoaccess; + result = NT_STATUS_ACCESS_DENIED; goto done; } @@ -4640,7 +4636,7 @@ static uint32 update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_setprinter(pipes_struct *p, SPOOL_Q_SETPRINTER *q_u, SPOOL_R_SETPRINTER *r_u) +NTSTATUS _spoolss_setprinter(pipes_struct *p, SPOOL_Q_SETPRINTER *q_u, SPOOL_R_SETPRINTER *r_u) { POLICY_HND *handle = &q_u->handle; uint32 level = q_u->level; @@ -4653,7 +4649,7 @@ uint32 _spoolss_setprinter(pipes_struct *p, SPOOL_Q_SETPRINTER *q_u, SPOOL_R_SET if (!Printer) { DEBUG(0,("_spoolss_setprinter: Invalid handle (%s)\n", OUR_HANDLE(handle))); - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; } /* check the level */ @@ -4673,7 +4669,7 @@ uint32 _spoolss_setprinter(pipes_struct *p, SPOOL_Q_SETPRINTER *q_u, SPOOL_R_SET /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_fcpn(pipes_struct *p, SPOOL_Q_FCPN *q_u, SPOOL_R_FCPN *r_u) +NTSTATUS _spoolss_fcpn(pipes_struct *p, SPOOL_Q_FCPN *q_u, SPOOL_R_FCPN *r_u) { POLICY_HND *handle = &q_u->handle; @@ -4681,7 +4677,7 @@ uint32 _spoolss_fcpn(pipes_struct *p, SPOOL_Q_FCPN *q_u, SPOOL_R_FCPN *r_u) if (!Printer) { DEBUG(0,("_spoolss_fcpn: Invalid handle (%s)\n", OUR_HANDLE(handle))); - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; } if (Printer->notify.client_connected==True) @@ -4695,13 +4691,13 @@ uint32 _spoolss_fcpn(pipes_struct *p, SPOOL_Q_FCPN *q_u, SPOOL_R_FCPN *r_u) free_spool_notify_option(&Printer->notify.option); Printer->notify.client_connected=False; - return ERRsuccess; + return NT_STATUS_OK; } /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_addjob(pipes_struct *p, SPOOL_Q_ADDJOB *q_u, SPOOL_R_ADDJOB *r_u) +NTSTATUS _spoolss_addjob(pipes_struct *p, SPOOL_Q_ADDJOB *q_u, SPOOL_R_ADDJOB *r_u) { /* that's an [in out] buffer (despite appearences to the contrary) */ spoolss_move_buffer(q_u->buffer, &r_u->buffer); @@ -4793,7 +4789,7 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, /**************************************************************************** Enumjobs at level 1. ****************************************************************************/ -static uint32 enumjobs_level1(print_queue_struct *queue, int snum, +static NTSTATUS enumjobs_level1(print_queue_struct *queue, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { @@ -4833,13 +4829,13 @@ static uint32 enumjobs_level1(print_queue_struct *queue, int snum, return ERRinsufficientbuffer; } else - return ERRsuccess; + return NT_STATUS_OK; } /**************************************************************************** Enumjobs at level 2. ****************************************************************************/ -static uint32 enumjobs_level2(print_queue_struct *queue, int snum, +static NTSTATUS enumjobs_level2(print_queue_struct *queue, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { @@ -4888,14 +4884,14 @@ static uint32 enumjobs_level2(print_queue_struct *queue, int snum, return ERRinsufficientbuffer; } else - return ERRsuccess; + return NT_STATUS_OK; } /**************************************************************************** Enumjobs. ****************************************************************************/ -uint32 _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJOBS *r_u) +NTSTATUS _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJOBS *r_u) { POLICY_HND *handle = &q_u->handle; /* uint32 firstjob = q_u->firstjob; - notused. */ @@ -4922,14 +4918,14 @@ uint32 _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO *returned=0; if (!get_printer_snum(p, handle, &snum)) - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; *returned = print_queue_status(snum, &queue, &prt_status); DEBUGADD(4,("count:[%d], status:[%d], [%s]\n", *returned, prt_status.status, prt_status.message)); if (*returned == 0) { safe_free(queue); - return ERRsuccess; + return NT_STATUS_OK; } switch (level) { @@ -4947,7 +4943,7 @@ uint32 _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_schedulejob( pipes_struct *p, SPOOL_Q_SCHEDULEJOB *q_u, SPOOL_R_SCHEDULEJOB *r_u) +NTSTATUS _spoolss_schedulejob( pipes_struct *p, SPOOL_Q_SCHEDULEJOB *q_u, SPOOL_R_SCHEDULEJOB *r_u) { return 0x0; } @@ -4955,7 +4951,7 @@ uint32 _spoolss_schedulejob( pipes_struct *p, SPOOL_Q_SCHEDULEJOB *q_u, SPOOL_R_ /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u) +NTSTATUS _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u) { POLICY_HND *handle = &q_u->handle; uint32 jobid = q_u->jobid; @@ -4970,7 +4966,7 @@ uint32 _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u memset(&prt_status, 0, sizeof(prt_status)); if (!get_printer_snum(p, handle, &snum)) { - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; } if (!print_job_exists(jobid)) { @@ -5007,7 +5003,7 @@ uint32 _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u /**************************************************************************** Enumerates all printer drivers at level 1. ****************************************************************************/ -static uint32 enumprinterdrivers_level1(fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static NTSTATUS enumprinterdrivers_level1(fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int i; int ndrivers; @@ -5040,7 +5036,7 @@ static uint32 enumprinterdrivers_level1(fstring servername, fstring architecture } for (i=0; iname; - notused. */ UNISTR2 *environment = &q_u->environment; @@ -5304,7 +5300,7 @@ static void fill_form_1(FORM_1 *form, nt_forms_struct *list) /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMFORMS *r_u) +NTSTATUS _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMFORMS *r_u) { /* POLICY_HND *handle = &q_u->handle; - notused. */ uint32 level = q_u->level; @@ -5392,7 +5388,7 @@ uint32 _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMF return ERRinsufficientbuffer; } else - return ERRsuccess; + return NT_STATUS_OK; default: safe_free(list); @@ -5405,7 +5401,7 @@ uint32 _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMF /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM *r_u) +NTSTATUS _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM *r_u) { /* POLICY_HND *handle = &q_u->handle; - notused. */ uint32 level = q_u->level; @@ -5438,7 +5434,7 @@ uint32 _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * DEBUGADD(5,("Number of forms [%d]\n", numofforms)); if (numofforms == 0) - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; } switch (level) { @@ -5461,7 +5457,7 @@ uint32 _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * safe_free(list); if (i == numofforms) { - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; } } /* check the required size. */ @@ -5480,7 +5476,7 @@ uint32 _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * DEBUGADD(6,("adding form %s [%d] to buffer\n", form_name, i)); smb_io_form_1("", buffer, &form_1, 0); - return ERRsuccess; + return NT_STATUS_OK; default: safe_free(list); @@ -5510,7 +5506,7 @@ static void fill_port_2(PORT_INFO_2 *port, char *name) /**************************************************************************** enumports level 1. ****************************************************************************/ -static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static NTSTATUS enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PORT_INFO_1 *ports=NULL; int i=0; @@ -5532,7 +5528,7 @@ static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need if (fd != -1) close(fd); /* Is this the best error to return here? */ - return ERRnoaccess; + return NT_STATUS_ACCESS_DENIED; } numlines = 0; @@ -5592,14 +5588,14 @@ static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need return ERRinsufficientbuffer; } else - return ERRsuccess; + return NT_STATUS_OK; } /**************************************************************************** enumports level 2. ****************************************************************************/ -static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static NTSTATUS enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PORT_INFO_2 *ports=NULL; int i=0; @@ -5630,7 +5626,7 @@ static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need if (fd != -1) close(fd); /* Is this the best error to return here? */ - return ERRnoaccess; + return NT_STATUS_ACCESS_DENIED; } numlines = 0; @@ -5691,14 +5687,14 @@ static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need return ERRinsufficientbuffer; } else - return ERRsuccess; + return NT_STATUS_OK; } /**************************************************************************** enumports. ****************************************************************************/ -uint32 _spoolss_enumports( pipes_struct *p, SPOOL_Q_ENUMPORTS *q_u, SPOOL_R_ENUMPORTS *r_u) +NTSTATUS _spoolss_enumports( pipes_struct *p, SPOOL_Q_ENUMPORTS *q_u, SPOOL_R_ENUMPORTS *r_u) { /* UNISTR2 *name = &q_u->name; - notused. */ uint32 level = q_u->level; @@ -5728,7 +5724,7 @@ uint32 _spoolss_enumports( pipes_struct *p, SPOOL_Q_ENUMPORTS *q_u, SPOOL_R_ENUM /**************************************************************************** ****************************************************************************/ -static uint32 spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_srv_name, +static NTSTATUS spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_srv_name, const SPOOL_PRINTER_INFO_LEVEL *info, uint32 unk0, uint32 unk1, uint32 unk2, uint32 unk3, uint32 user_switch, const SPOOL_USER_CTR *user, @@ -5751,7 +5747,7 @@ static uint32 spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ if (*lp_addprinter_cmd() ) if ( !add_printer_hook(printer) ) { free_a_printer(&printer,2); - return ERRnoaccess; + return NT_STATUS_ACCESS_DENIED; } slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname, @@ -5759,13 +5755,13 @@ static uint32 spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ if ((snum = print_queue_snum(printer->info_2->sharename)) == -1) { free_a_printer(&printer,2); - return ERRnoaccess; + return NT_STATUS_ACCESS_DENIED; } /* you must be a printer admin to add a new printer */ if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { free_a_printer(&printer,2); - return ERRnoaccess; + return NT_STATUS_ACCESS_DENIED; } /* @@ -5787,27 +5783,27 @@ static uint32 spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ /* write the ASCII on disk */ if (add_a_printer(*printer, 2) != 0) { free_a_printer(&printer,2); - return ERRnoaccess; + return NT_STATUS_ACCESS_DENIED; } if (!open_printer_hnd(p, handle, name)) { /* Handle open failed - remove addition. */ del_a_printer(printer->info_2->sharename); free_a_printer(&printer,2); - return ERRnoaccess; + return NT_STATUS_ACCESS_DENIED; } free_a_printer(&printer,2); srv_spoolss_sendnotify(p, handle); - return ERRsuccess; + return NT_STATUS_OK; } /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_addprinterex( pipes_struct *p, SPOOL_Q_ADDPRINTEREX *q_u, SPOOL_R_ADDPRINTEREX *r_u) +NTSTATUS _spoolss_addprinterex( pipes_struct *p, SPOOL_Q_ADDPRINTEREX *q_u, SPOOL_R_ADDPRINTEREX *r_u) { UNISTR2 *uni_srv_name = &q_u->server_name; uint32 level = q_u->level; @@ -5837,13 +5833,13 @@ uint32 _spoolss_addprinterex( pipes_struct *p, SPOOL_Q_ADDPRINTEREX *q_u, SPOOL_ /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u, SPOOL_R_ADDPRINTERDRIVER *r_u) +NTSTATUS _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u, SPOOL_R_ADDPRINTERDRIVER *r_u) { /* UNISTR2 *server_name = &q_u->server_name; - notused. */ uint32 level = q_u->level; SPOOL_PRINTER_DRIVER_INFO_LEVEL *info = &q_u->info; - uint32 err = ERRsuccess; + uint32 err = NT_STATUS_OK; NT_PRINTER_DRIVER_INFO_LEVEL driver; struct current_user user; @@ -5857,18 +5853,18 @@ uint32 _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u, } DEBUG(5,("Cleaning driver's information\n")); - if ((err = clean_up_driver_struct(driver, level, &user)) != ERRsuccess ) + if ((err = clean_up_driver_struct(driver, level, &user)) != NT_STATUS_OK ) goto done; DEBUG(5,("Moving driver to final destination\n")); if(!move_driver_to_download_area(driver, level, &user, &err)) { if (err == 0) - err = ERRnoaccess; + err = NT_STATUS_ACCESS_DENIED; goto done; } if (add_a_printer_driver(driver, level)!=0) { - err = ERRnoaccess; + err = NT_STATUS_ACCESS_DENIED; goto done; } @@ -5886,7 +5882,7 @@ static void fill_driverdir_1(DRIVER_DIRECTORY_1 *info, char *name) /**************************************************************************** ****************************************************************************/ -static uint32 getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environment, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static NTSTATUS getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environment, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { pstring path; pstring long_archi; @@ -5921,13 +5917,13 @@ static uint32 getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen if (*needed > offered) return ERRinsufficientbuffer; else - return ERRsuccess; + return NT_STATUS_OK; } /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_getprinterdriverdirectory(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVERDIR *q_u, SPOOL_R_GETPRINTERDRIVERDIR *r_u) +NTSTATUS _spoolss_getprinterdriverdirectory(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVERDIR *q_u, SPOOL_R_GETPRINTERDRIVERDIR *r_u) { UNISTR2 *name = &q_u->name; UNISTR2 *uni_environment = &q_u->environment; @@ -5955,7 +5951,7 @@ uint32 _spoolss_getprinterdriverdirectory(pipes_struct *p, SPOOL_Q_GETPRINTERDRI /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, SPOOL_R_ENUMPRINTERDATA *r_u) +NTSTATUS _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, SPOOL_R_ENUMPRINTERDATA *r_u) { POLICY_HND *handle = &q_u->handle; uint32 idx = q_u->index; @@ -5998,14 +5994,14 @@ uint32 _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S if (!Printer) { DEBUG(0,("_spoolss_enumprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; } if (!get_printer_snum(p,handle, &snum)) - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; if (get_a_printer(&printer, 2, lp_servicename(snum)) != 0) - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; /* * The NT machine wants to know the biggest size of value and data @@ -6069,7 +6065,7 @@ uint32 _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S DEBUG(6,("final values: [%d], [%d]\n", *out_value_len, *out_data_len)); free_a_printer(&printer, 2); - return ERRsuccess; + return NT_STATUS_OK; } /* @@ -6116,13 +6112,13 @@ uint32 _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S safe_free(data); - return ERRsuccess; + return NT_STATUS_OK; } /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SPOOL_R_SETPRINTERDATA *r_u) +NTSTATUS _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SPOOL_R_SETPRINTERDATA *r_u) { POLICY_HND *handle = &q_u->handle; UNISTR2 *value = &q_u->value; @@ -6135,18 +6131,18 @@ uint32 _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_PARAM *param = NULL, old_param; int snum=0; - uint32 status = 0x0; + NTSTATUS status = 0x0; Printer_entry *Printer=find_printer_index_by_hnd(p, handle); DEBUG(5,("spoolss_setprinterdata\n")); if (!Printer) { DEBUG(0,("_spoolss_setprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; } if (!get_printer_snum(p,handle, &snum)) - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; status = get_a_printer(&printer, 2, lp_servicename(snum)); if (status != 0x0) @@ -6168,7 +6164,7 @@ uint32 _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP old_param.data_len) == 0) { DEBUG(3, ("setprinterdata hasn't changed\n")); - status = ERRsuccess; + status = NT_STATUS_OK; goto done; } } @@ -6178,7 +6174,7 @@ uint32 _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { DEBUG(3, ("security descriptor change denied by existing " "security descriptor\n")); - status = ERRnoaccess; + status = NT_STATUS_ACCESS_DENIED; goto done; } @@ -6212,7 +6208,7 @@ uint32 _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_u, SPOOL_R_DELETEPRINTERDATA *r_u) +NTSTATUS _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_u, SPOOL_R_DELETEPRINTERDATA *r_u) { POLICY_HND *handle = &q_u->handle; UNISTR2 *value = &q_u->valuename; @@ -6220,23 +6216,23 @@ uint32 _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_ NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_PARAM param; int snum=0; - uint32 status = 0x0; + NTSTATUS status = 0x0; Printer_entry *Printer=find_printer_index_by_hnd(p, handle); DEBUG(5,("spoolss_deleteprinterdata\n")); if (!Printer) { DEBUG(0,("_spoolss_deleteprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; } if (!get_printer_snum(p, handle, &snum)) - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { DEBUG(3, ("_spoolss_deleteprinterdata: printer properties " "change denied by existing security descriptor\n")); - return ERRnoaccess; + return NT_STATUS_ACCESS_DENIED; } status = get_a_printer(&printer, 2, lp_servicename(snum)); @@ -6258,7 +6254,7 @@ uint32 _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_ /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM *r_u) +NTSTATUS _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM *r_u) { POLICY_HND *handle = &q_u->handle; /* uint32 level = q_u->level; - notused. */ @@ -6273,7 +6269,7 @@ uint32 _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM if (!Printer) { DEBUG(0,("_spoolss_addform: Invalid handle (%s).\n", OUR_HANDLE(handle))); - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; } /* can't add if builtin */ @@ -6294,7 +6290,7 @@ uint32 _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DELETEFORM *r_u) +NTSTATUS _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DELETEFORM *r_u) { POLICY_HND *handle = &q_u->handle; UNISTR2 *form_name = &q_u->name; @@ -6308,7 +6304,7 @@ uint32 _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE if (!Printer) { DEBUG(0,("_spoolss_deleteform: Invalid handle (%s).\n", OUR_HANDLE(handle))); - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; } /* can't delete if builtin */ @@ -6328,7 +6324,7 @@ uint32 _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM *r_u) +NTSTATUS _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM *r_u) { POLICY_HND *handle = &q_u->handle; /* UNISTR2 *uni_name = &q_u->name; - notused. */ @@ -6344,7 +6340,7 @@ uint32 _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM * if (!Printer) { DEBUG(0,("_spoolss_setform: Invalid handle (%s).\n", OUR_HANDLE(handle))); - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; } /* can't set if builtin */ if (get_a_builtin_ntform(&form->name,&tmpForm)) { @@ -6363,7 +6359,7 @@ uint32 _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM * /**************************************************************************** enumprintprocessors level 1. ****************************************************************************/ -static uint32 enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static NTSTATUS enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PRINTPROCESSOR_1 *info_1=NULL; @@ -6388,13 +6384,13 @@ static uint32 enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, ui return ERRinsufficientbuffer; } else - return ERRsuccess; + return NT_STATUS_OK; } /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_enumprintprocessors(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCESSORS *q_u, SPOOL_R_ENUMPRINTPROCESSORS *r_u) +NTSTATUS _spoolss_enumprintprocessors(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCESSORS *q_u, SPOOL_R_ENUMPRINTPROCESSORS *r_u) { /* UNISTR2 *name = &q_u->name; - notused. */ /* UNISTR2 *environment = &q_u->environment; - notused. */ @@ -6431,7 +6427,7 @@ uint32 _spoolss_enumprintprocessors(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCESSORS /**************************************************************************** enumprintprocdatatypes level 1. ****************************************************************************/ -static uint32 enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static NTSTATUS enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PRINTPROCDATATYPE_1 *info_1=NULL; @@ -6456,13 +6452,13 @@ static uint32 enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered, return ERRinsufficientbuffer; } else - return ERRsuccess; + return NT_STATUS_OK; } /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_enumprintprocdatatypes(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCDATATYPES *q_u, SPOOL_R_ENUMPRINTPROCDATATYPES *r_u) +NTSTATUS _spoolss_enumprintprocdatatypes(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCDATATYPES *q_u, SPOOL_R_ENUMPRINTPROCDATATYPES *r_u) { /* UNISTR2 *name = &q_u->name; - notused. */ /* UNISTR2 *processor = &q_u->processor; - notused. */ @@ -6493,7 +6489,7 @@ uint32 _spoolss_enumprintprocdatatypes(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCDAT enumprintmonitors level 1. ****************************************************************************/ -static uint32 enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static NTSTATUS enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PRINTMONITOR_1 *info_1=NULL; @@ -6518,13 +6514,13 @@ static uint32 enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, uint return ERRinsufficientbuffer; } else - return ERRsuccess; + return NT_STATUS_OK; } /**************************************************************************** enumprintmonitors level 2. ****************************************************************************/ -static uint32 enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static NTSTATUS enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PRINTMONITOR_2 *info_2=NULL; @@ -6551,13 +6547,13 @@ static uint32 enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint return ERRinsufficientbuffer; } else - return ERRsuccess; + return NT_STATUS_OK; } /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS *q_u, SPOOL_R_ENUMPRINTMONITORS *r_u) +NTSTATUS _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS *q_u, SPOOL_R_ENUMPRINTMONITORS *r_u) { /* UNISTR2 *name = &q_u->name; - notused. */ uint32 level = q_u->level; @@ -6594,7 +6590,7 @@ uint32 _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS *q_ /**************************************************************************** ****************************************************************************/ -static uint32 getjob_level_1(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static NTSTATUS getjob_level_1(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { int i=0; BOOL found=False; @@ -6616,7 +6612,7 @@ static uint32 getjob_level_1(print_queue_struct *queue, int count, int snum, uin safe_free(queue); safe_free(info_1); /* I shoud reply something else ... I can't find the good one */ - return ERRsuccess; + return NT_STATUS_OK; } fill_job_info_1(info_1, &(queue[i-1]), i, snum); @@ -6637,13 +6633,13 @@ static uint32 getjob_level_1(print_queue_struct *queue, int count, int snum, uin if (*needed > offered) return ERRinsufficientbuffer; else - return ERRsuccess; + return NT_STATUS_OK; } /**************************************************************************** ****************************************************************************/ -static uint32 getjob_level_2(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static NTSTATUS getjob_level_2(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { int i=0; BOOL found=False; @@ -6668,7 +6664,7 @@ static uint32 getjob_level_2(print_queue_struct *queue, int count, int snum, uin safe_free(queue); safe_free(info_2); /* I shoud reply something else ... I can't find the good one */ - return ERRsuccess; + return NT_STATUS_OK; } if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0) { @@ -6696,13 +6692,13 @@ static uint32 getjob_level_2(print_queue_struct *queue, int count, int snum, uin if (*needed > offered) return ERRinsufficientbuffer; else - return ERRsuccess; + return NT_STATUS_OK; } /**************************************************************************** ****************************************************************************/ -uint32 _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_u) +NTSTATUS _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_u) { POLICY_HND *handle = &q_u->handle; uint32 jobid = q_u->jobid; @@ -6727,7 +6723,7 @@ uint32 _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_ *needed=0; if (!get_printer_snum(p, handle, &snum)) - return ERRbadfid; + return NT_STATUS_INVALID_HANDLE; count = print_queue_status(snum, &queue, &prt_status); -- cgit From fd6ea431617d91c5f5c6b07cb26910f4900c1515 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 3 Sep 2001 08:50:59 +0000 Subject: the next step in our error code handling change - added WERROR for win32 error codes - added a configure test for immediate structures still lots to do, so its not enabled by default, but the main structure is there (This used to be commit 24f9ab683dec52587ee56717e821b49c0fa3d70f) --- source3/rpc_server/srv_spoolss_nt.c | 461 ++++++++++++++++++------------------ 1 file changed, 229 insertions(+), 232 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 0ebbc2aada..140eed5c05 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -443,7 +443,7 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) DEBUGADD(5,("share:%s\n",lp_servicename(snum))); - if (get_a_printer(&printer, 2, lp_servicename(snum))!=0) + if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, lp_servicename(snum)))) continue; printername=strchr_m(printer->info_2->printername+2, '\\'); @@ -486,7 +486,7 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) DEBUGADD(5,("set_printer_hnd_name: share:%s\n",lp_servicename(snum))); - if (get_a_printer(&printer, 2, lp_servicename(snum))!=0) + if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, lp_servicename(snum)))) continue; DEBUG(10,("set_printer_hnd_name: printername [%s], aprinter [%s]\n", @@ -1141,7 +1141,7 @@ NTSTATUS _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIV } ZERO_STRUCT(info); - if (get_a_printer_driver (&info, 3, driver, arch, version) != 0) { + if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, driver, arch, version))) { return NT_STATUS_DRIVER_ORDINAL_NOT_FOUND; } @@ -1256,7 +1256,7 @@ static BOOL getprinterdata_printer(pipes_struct *p, TALLOC_CTX *ctx, POLICY_HND if(!get_printer_snum(p, handle, &snum)) return False; - if(get_a_printer(&printer, 2, lp_servicename(snum)) != 0) + if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, lp_servicename(snum)))) return False; if (!get_specific_param(*printer, 2, value, &idata, type, &len)) { @@ -2222,7 +2222,7 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int (option_type->type==PRINTER_NOTIFY_TYPE?"PRINTER_NOTIFY_TYPE":"JOB_NOTIFY_TYPE"), option_type->count, lp_servicename(snum))); - if (get_a_printer(&printer, 2, lp_servicename(snum))!=0) + if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, lp_servicename(snum)))) return False; for(field_num=0; field_numcount; field_num++) { @@ -2334,7 +2334,7 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, * ********************************************************************/ -static NTSTATUS printserver_notify_info(pipes_struct *p, POLICY_HND *hnd, +static WERROR printserver_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info, TALLOC_CTX *mem_ctx) { @@ -2382,7 +2382,7 @@ static NTSTATUS printserver_notify_info(pipes_struct *p, POLICY_HND *hnd, } */ - return NT_STATUS_OK; + return WERR_OK; } /******************************************************************* @@ -2390,7 +2390,7 @@ static NTSTATUS printserver_notify_info(pipes_struct *p, POLICY_HND *hnd, * fill a notify_info struct with info asked * ********************************************************************/ -static uint32 printer_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info, +static WERROR printer_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info, TALLOC_CTX *mem_ctx) { int snum; @@ -2430,8 +2430,8 @@ static uint32 printer_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY memset(&status, 0, sizeof(status)); count = print_queue_status(snum, &queue, &status); - if (get_a_printer(&printer, 2, - lp_servicename(snum)) != 0) + if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, + lp_servicename(snum)))) goto done; for (j=0; jdata[i].id, info->data[i].size, info->data[i].enc_type)); } */ - return NT_STATUS_OK; + return WERR_OK; } /******************************************************************** * spoolss_rfnpcnex ********************************************************************/ -NTSTATUS _spoolss_rfnpcnex( pipes_struct *p, SPOOL_Q_RFNPCNEX *q_u, SPOOL_R_RFNPCNEX *r_u) +WERROR _spoolss_rfnpcnex( pipes_struct *p, SPOOL_Q_RFNPCNEX *q_u, SPOOL_R_RFNPCNEX *r_u) { POLICY_HND *handle = &q_u->handle; /* uint32 change = q_u->change; - notused. */ @@ -2480,7 +2480,7 @@ NTSTATUS _spoolss_rfnpcnex( pipes_struct *p, SPOOL_Q_RFNPCNEX *q_u, SPOOL_R_RFNP SPOOL_NOTIFY_INFO *info = &r_u->info; Printer_entry *Printer=find_printer_index_by_hnd(p, handle); - NTSTATUS result = NT_STATUS_INVALID_HANDLE; + WERROR result = WERR_BADFID; /* we always have a NOTIFY_INFO struct */ r_u->info_ptr=0x1; @@ -2539,7 +2539,7 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum) memset(&status, 0, sizeof(status)); - if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) != 0) + if (!W_ERROR_IS_OK(get_a_printer(&ntprinter, 2, lp_servicename(snum)))) return False; count = print_queue_status(snum, &queue, &status); @@ -2639,7 +2639,7 @@ static BOOL construct_printer_info_1(uint32 flags, PRINTER_INFO_1 *printer, int pstring chaine2; NT_PRINTER_INFO_LEVEL *ntprinter = NULL; - if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) != 0) + if (!W_ERROR_IS_OK(get_a_printer(&ntprinter, 2, lp_servicename(snum)))) return False; printer->flags=flags; @@ -2703,7 +2703,7 @@ static DEVICEMODE *construct_dev_mode(int snum) ZERO_STRUCTP(devmode); - if(get_a_printer(&printer, 2, lp_servicename(snum)) != 0) + if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, lp_servicename(snum)))) goto fail; if (printer->info_2->devmode) @@ -2779,7 +2779,7 @@ static BOOL construct_printer_info_2(PRINTER_INFO_2 *printer, int snum) print_status_struct status; memset(&status, 0, sizeof(status)); - if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0 ) + if (!W_ERROR_IS_OK(get_a_printer(&ntprinter, 2, lp_servicename(snum)))) return False; memset(&status, 0, sizeof(status)); @@ -2841,7 +2841,7 @@ static BOOL construct_printer_info_3(PRINTER_INFO_3 **pp_printer, int snum) NT_PRINTER_INFO_LEVEL *ntprinter = NULL; PRINTER_INFO_3 *printer = NULL; - if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0 ) + if (!W_ERROR_IS_OK(get_a_printer(&ntprinter, 2, lp_servicename(snum)))) return False; *pp_printer = NULL; @@ -2889,7 +2889,7 @@ static BOOL construct_printer_info_3(PRINTER_INFO_3 **pp_printer, int snum) /******************************************************************** Spoolss_enumprinters. ********************************************************************/ -static BOOL enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int snum; int i; @@ -2908,7 +2908,7 @@ static BOOL enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 of DEBUG(0,("enum_all_printers_info_1: failed to enlarge printers buffer!\n")); safe_free(printers); *returned=0; - return ERRnomem; + return WERR_NOMEM; } else printers = tp; DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_1\n", *returned)); @@ -2923,7 +2923,7 @@ static BOOL enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 of (*needed) += spoolss_size_printer_info_1(&printers[i]); if (!alloc_buffer_size(buffer, *needed)) - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; /* fill the buffer with the structures */ for (i=0; i<*returned; i++) @@ -2934,16 +2934,16 @@ static BOOL enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 of if (*needed > offered) { *returned=0; - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } else - return NT_STATUS_OK; + return WERR_OK; } /******************************************************************** enum_all_printers_info_1_local. *********************************************************************/ -static BOOL enum_all_printers_info_1_local(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enum_all_printers_info_1_local(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { DEBUG(4,("enum_all_printers_info_1_local\n")); @@ -2953,7 +2953,7 @@ static BOOL enum_all_printers_info_1_local(NEW_BUFFER *buffer, uint32 offered, u /******************************************************************** enum_all_printers_info_1_name. *********************************************************************/ -static BOOL enum_all_printers_info_1_name(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enum_all_printers_info_1_name(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { fstring temp; DEBUG(4,("enum_all_printers_info_1_name\n")); @@ -2965,13 +2965,13 @@ static BOOL enum_all_printers_info_1_name(fstring name, NEW_BUFFER *buffer, uint return enum_all_printers_info_1(PRINTER_ENUM_ICON8, buffer, offered, needed, returned); } else - return ERRinvalidname; + return WERR_INVALID_NAME; } /******************************************************************** enum_all_printers_info_1_remote. *********************************************************************/ -static BOOL enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PRINTER_INFO_1 *printer; fstring printername; @@ -2987,7 +2987,7 @@ static BOOL enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, ui */ if((printer=(PRINTER_INFO_1 *)malloc(sizeof(PRINTER_INFO_1))) == NULL) - return ERRnomem; + return WERR_NOMEM; *returned=1; @@ -3005,7 +3005,7 @@ static BOOL enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, ui if (!alloc_buffer_size(buffer, *needed)) { safe_free(printer); - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } /* fill the buffer with the structures */ @@ -3016,17 +3016,17 @@ static BOOL enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, ui if (*needed > offered) { *returned=0; - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } else - return NT_STATUS_OK; + return WERR_OK; } /******************************************************************** enum_all_printers_info_1_network. *********************************************************************/ -static BOOL enum_all_printers_info_1_network(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enum_all_printers_info_1_network(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { DEBUG(4,("enum_all_printers_info_1_network\n")); @@ -3039,7 +3039,7 @@ static BOOL enum_all_printers_info_1_network(NEW_BUFFER *buffer, uint32 offered, * called from api_spoolss_enumprinters (see this to understand) ********************************************************************/ -static BOOL enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int snum; int i; @@ -3056,7 +3056,7 @@ static BOOL enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint32 DEBUG(0,("enum_all_printers_info_2: failed to enlarge printers buffer!\n")); safe_free(printers); *returned = 0; - return ERRnomem; + return WERR_NOMEM; } else printers = tp; DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_2\n", *returned)); @@ -3075,7 +3075,7 @@ static BOOL enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint32 free_devmode(printers[i].devmode); } safe_free(printers); - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } /* fill the buffer with the structures */ @@ -3090,16 +3090,16 @@ static BOOL enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint32 if (*needed > offered) { *returned=0; - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } else - return NT_STATUS_OK; + return WERR_OK; } /******************************************************************** * handle enumeration of printers at level 1 ********************************************************************/ -static NTSTATUS enumprinters_level1( uint32 flags, fstring name, +static WERROR enumprinters_level1( uint32 flags, fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { @@ -3117,13 +3117,13 @@ static NTSTATUS enumprinters_level1( uint32 flags, fstring name, if (flags & PRINTER_ENUM_NETWORK) return enum_all_printers_info_1_network(buffer, offered, needed, returned); - return NT_STATUS_OK; /* NT4sp5 does that */ + return WERR_OK; /* NT4sp5 does that */ } /******************************************************************** * handle enumeration of printers at level 2 ********************************************************************/ -static NTSTATUS enumprinters_level2( uint32 flags, fstring servername, +static WERROR enumprinters_level2( uint32 flags, fstring servername, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { @@ -3143,24 +3143,24 @@ static NTSTATUS enumprinters_level2( uint32 flags, fstring servername, if (strequal(servername, temp)) return enum_all_printers_info_2(buffer, offered, needed, returned); else - return ERRinvalidname; + return WERR_INVALID_NAME; } if (flags & PRINTER_ENUM_REMOTE) - return ERRunknownlevel; + return WERR_UNKNOWN_LEVEL; - return NT_STATUS_OK; + return WERR_OK; } /******************************************************************** * handle enumeration of printers at level 5 ********************************************************************/ -static NTSTATUS enumprinters_level5( uint32 flags, fstring servername, +static WERROR enumprinters_level5( uint32 flags, fstring servername, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { /* return enum_all_printers_info_5(buffer, offered, needed, returned);*/ - return NT_STATUS_OK; + return WERR_OK; } /******************************************************************** @@ -3169,7 +3169,7 @@ static NTSTATUS enumprinters_level5( uint32 flags, fstring servername, * called from api_spoolss_enumprinters (see this to understand) ********************************************************************/ -NTSTATUS _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOOL_R_ENUMPRINTERS *r_u) +WERROR _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOOL_R_ENUMPRINTERS *r_u) { uint32 flags = q_u->flags; UNISTR2 *servername = &q_u->servername; @@ -3178,7 +3178,6 @@ NTSTATUS _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOO uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; uint32 *returned = &r_u->returned; - fstring name; /* that's an [in out] buffer */ @@ -3216,18 +3215,18 @@ NTSTATUS _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOO case 3: case 4: default: - return ERRunknownlevel; } + return WERR_UNKNOWN_LEVEL; } /**************************************************************************** ****************************************************************************/ -static NTSTATUS getprinter_level_0(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinter_level_0(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_0 *printer=NULL; if((printer=(PRINTER_INFO_0*)malloc(sizeof(PRINTER_INFO_0))) == NULL) - return ERRnomem; + return WERR_NOMEM; construct_printer_info_0(printer, snum); @@ -3236,7 +3235,7 @@ static NTSTATUS getprinter_level_0(int snum, NEW_BUFFER *buffer, uint32 offered, if (!alloc_buffer_size(buffer, *needed)) { safe_free(printer); - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } /* fill the buffer with the structures */ @@ -3246,20 +3245,20 @@ static NTSTATUS getprinter_level_0(int snum, NEW_BUFFER *buffer, uint32 offered, safe_free(printer); if (*needed > offered) { - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } - else - return NT_STATUS_OK; + + return WERR_OK; } /**************************************************************************** ****************************************************************************/ -static NTSTATUS getprinter_level_1(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinter_level_1(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_1 *printer=NULL; if((printer=(PRINTER_INFO_1*)malloc(sizeof(PRINTER_INFO_1))) == NULL) - return ERRnomem; + return WERR_NOMEM; construct_printer_info_1(PRINTER_ENUM_ICON8, printer, snum); @@ -3268,7 +3267,7 @@ static NTSTATUS getprinter_level_1(int snum, NEW_BUFFER *buffer, uint32 offered, if (!alloc_buffer_size(buffer, *needed)) { safe_free(printer); - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } /* fill the buffer with the structures */ @@ -3278,20 +3277,20 @@ static NTSTATUS getprinter_level_1(int snum, NEW_BUFFER *buffer, uint32 offered, safe_free(printer); if (*needed > offered) { - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } - else - return NT_STATUS_OK; + + return WERR_OK; } /**************************************************************************** ****************************************************************************/ -static NTSTATUS getprinter_level_2(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinter_level_2(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_2 *printer=NULL; if((printer=(PRINTER_INFO_2*)malloc(sizeof(PRINTER_INFO_2)))==NULL) - return ERRnomem; + return WERR_NOMEM; construct_printer_info_2(printer, snum); @@ -3300,40 +3299,40 @@ static NTSTATUS getprinter_level_2(int snum, NEW_BUFFER *buffer, uint32 offered, if (!alloc_buffer_size(buffer, *needed)) { free_printer_info_2(printer); - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } /* fill the buffer with the structures */ if (!smb_io_printer_info_2("", buffer, printer, 0)) { free_printer_info_2(printer); - return ERRnomem; + return WERR_NOMEM; } /* clear memory */ free_printer_info_2(printer); if (*needed > offered) { - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } - else - return NT_STATUS_OK; + + return WERR_OK; } /**************************************************************************** ****************************************************************************/ -static NTSTATUS getprinter_level_3(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinter_level_3(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_3 *printer=NULL; if (!construct_printer_info_3(&printer, snum)) - return ERRnomem; + return WERR_NOMEM; /* check the required size. */ *needed += spoolss_size_printer_info_3(printer); if (!alloc_buffer_size(buffer, *needed)) { free_printer_info_3(printer); - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } /* fill the buffer with the structures */ @@ -3343,16 +3342,16 @@ static NTSTATUS getprinter_level_3(int snum, NEW_BUFFER *buffer, uint32 offered, free_printer_info_3(printer); if (*needed > offered) { - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } - else - return NT_STATUS_OK; + + return WERR_OK; } /**************************************************************************** ****************************************************************************/ -NTSTATUS _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GETPRINTER *r_u) +WERROR _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GETPRINTER *r_u) { POLICY_HND *handle = &q_u->handle; uint32 level = q_u->level; @@ -3369,7 +3368,7 @@ NTSTATUS _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_G *needed=0; if (!get_printer_snum(p, handle, &snum)) - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; switch (level) { case 0: @@ -3380,9 +3379,8 @@ NTSTATUS _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_G return getprinter_level_2(snum, buffer, offered, needed); case 3: return getprinter_level_3(snum, buffer, offered, needed); - default: - return ERRunknownlevel; } + return WERR_UNKNOWN_LEVEL; } /******************************************************************** @@ -3396,24 +3394,24 @@ static void fill_printer_driver_info_1(DRIVER_INFO_1 *info, NT_PRINTER_DRIVER_IN /******************************************************************** * construct_printer_driver_info_1 ********************************************************************/ -static NTSTATUS construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, fstring servername, fstring architecture, uint32 version) +static WERROR construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, fstring servername, fstring architecture, uint32 version) { NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; ZERO_STRUCT(driver); - if (get_a_printer(&printer, 2, lp_servicename(snum)) != 0) - return ERRinvalidprintername; + if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, lp_servicename(snum)))) + return WERR_INVALID_PRINTER_NAME; - if (get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version) != 0) - return ERRunknownprinterdriver; + if (!W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version))) + return WERR_UNKNOWN_PRINTER_DRIVER; fill_printer_driver_info_1(info, driver, servername, architecture); free_a_printer(&printer,2); - return NT_STATUS_OK; + return WERR_OK; } /******************************************************************** @@ -3453,7 +3451,7 @@ static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, NT_PRINTER_DRIVER_IN * construct_printer_driver_info_2 * fill a printer_info_2 struct ********************************************************************/ -static NTSTATUS construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fstring servername, fstring architecture, uint32 version) +static WERROR construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fstring servername, fstring architecture, uint32 version) { NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; @@ -3461,17 +3459,17 @@ static NTSTATUS construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, f ZERO_STRUCT(printer); ZERO_STRUCT(driver); - if (!get_a_printer(&printer, 2, lp_servicename(snum)) != 0) - return ERRinvalidprintername; + if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, lp_servicename(snum)))) + return WERR_INVALID_PRINTER_NAME; - if (!get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version) != 0) - return ERRunknownprinterdriver; + if (!W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version))) + return WERR_UNKNOWN_PRINTER_DRIVER; fill_printer_driver_info_2(info, driver, servername); free_a_printer(&printer,2); - return NT_STATUS_OK; + return WERR_OK; } /******************************************************************** @@ -3566,30 +3564,30 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_IN * construct_printer_info_3 * fill a printer_info_3 struct ********************************************************************/ -static NTSTATUS construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fstring servername, fstring architecture, uint32 version) +static WERROR construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fstring servername, fstring architecture, uint32 version) { NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; - NTSTATUS status=0; + WERROR status; ZERO_STRUCT(driver); status=get_a_printer(&printer, 2, lp_servicename(snum) ); - DEBUG(8,("construct_printer_driver_info_3: status: %d\n", status)); - if (status != 0) - return ERRinvalidprintername; + DEBUG(8,("construct_printer_driver_info_3: status: %s\n", werror_str(status))); + if (!W_ERROR_IS_OK(status)) + return WERR_INVALID_PRINTER_NAME; status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version); - DEBUG(8,("construct_printer_driver_info_3: status: %d\n", status)); - if (status != 0) { + DEBUG(8,("construct_printer_driver_info_3: status: %s\n", werror_str(status))); + if (!W_ERROR_IS_OK(status)) { free_a_printer(&printer,2); - return ERRunknownprinterdriver; + return WERR_UNKNOWN_PRINTER_DRIVER; } fill_printer_driver_info_3(info, driver, servername); free_a_printer(&printer,2); - return NT_STATUS_OK; + return WERR_OK; } /******************************************************************** @@ -3660,37 +3658,37 @@ static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_IN * construct_printer_info_6 * fill a printer_info_6 struct ********************************************************************/ -static NTSTATUS construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, fstring servername, fstring architecture, uint32 version) +static WERROR construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, fstring servername, fstring architecture, uint32 version) { NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; - NTSTATUS status=0; + WERROR status; ZERO_STRUCT(driver); status=get_a_printer(&printer, 2, lp_servicename(snum) ); - DEBUG(8,("construct_printer_driver_info_6: status: %d\n", status)); - if (status != 0) - return ERRinvalidprintername; + DEBUG(8,("construct_printer_driver_info_6: status: %s\n", werror_str(status))); + if (!W_ERROR_IS_OK(status)) + return WERR_INVALID_PRINTER_NAME; status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version); - DEBUG(8,("construct_printer_driver_info_6: status: %d\n", status)); - if (status != 0) { + DEBUG(8,("construct_printer_driver_info_6: status: %s\n", werror_str(status))); + if (!W_ERROR_IS_OK(status)) { /* * Is this a W2k client ? */ if (version < 3) { free_a_printer(&printer,2); - return ERRunknownprinterdriver; + return WERR_UNKNOWN_PRINTER_DRIVER; } /* Yes - try again with a WinNT driver. */ version = 2; status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version); - DEBUG(8,("construct_printer_driver_info_6: status: %d\n", status)); - if (status != 0) { + DEBUG(8,("construct_printer_driver_info_6: status: %s\n", werror_str(status))); + if (!W_ERROR_IS_OK(status)) { free_a_printer(&printer,2); - return ERRunknownprinterdriver; + return WERR_UNKNOWN_PRINTER_DRIVER; } } @@ -3698,7 +3696,7 @@ static NTSTATUS construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, f free_a_printer(&printer,2); - return NT_STATUS_OK; + return WERR_OK; } /**************************************************************************** @@ -3720,16 +3718,16 @@ static void free_printer_driver_info_6(DRIVER_INFO_6 *info) /**************************************************************************** ****************************************************************************/ -static NTSTATUS getprinterdriver2_level1(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinterdriver2_level1(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_1 *info=NULL; - NTSTATUS status; + WERROR status; if((info=(DRIVER_INFO_1 *)malloc(sizeof(DRIVER_INFO_1))) == NULL) - return ERRnomem; + return WERR_NOMEM; status=construct_printer_driver_info_1(info, snum, servername, architecture, version); - if (status != NT_STATUS_OK) { + if (!W_ERROR_IS_OK(status)) { safe_free(info); return status; } @@ -3739,7 +3737,7 @@ static NTSTATUS getprinterdriver2_level1(fstring servername, fstring architectur if (!alloc_buffer_size(buffer, *needed)) { safe_free(info); - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } /* fill the buffer with the structures */ @@ -3749,23 +3747,23 @@ static NTSTATUS getprinterdriver2_level1(fstring servername, fstring architectur safe_free(info); if (*needed > offered) - return ERRinsufficientbuffer; - else - return NT_STATUS_OK; + return WERR_INSUFFICIENT_BUFFER; + + return WERR_OK; } /**************************************************************************** ****************************************************************************/ -static NTSTATUS getprinterdriver2_level2(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinterdriver2_level2(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_2 *info=NULL; - NTSTATUS status; + WERROR status; if((info=(DRIVER_INFO_2 *)malloc(sizeof(DRIVER_INFO_2))) == NULL) - return ERRnomem; + return WERR_NOMEM; status=construct_printer_driver_info_2(info, snum, servername, architecture, version); - if (status != NT_STATUS_OK) { + if (!W_ERROR_IS_OK(status)) { safe_free(info); return status; } @@ -3775,7 +3773,7 @@ static NTSTATUS getprinterdriver2_level2(fstring servername, fstring architectur if (!alloc_buffer_size(buffer, *needed)) { safe_free(info); - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } /* fill the buffer with the structures */ @@ -3785,22 +3783,22 @@ static NTSTATUS getprinterdriver2_level2(fstring servername, fstring architectur safe_free(info); if (*needed > offered) - return ERRinsufficientbuffer; - else - return NT_STATUS_OK; + return WERR_INSUFFICIENT_BUFFER; + + return WERR_OK; } /**************************************************************************** ****************************************************************************/ -static NTSTATUS getprinterdriver2_level3(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinterdriver2_level3(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_3 info; - NTSTATUS status; + WERROR status; ZERO_STRUCT(info); status=construct_printer_driver_info_3(&info, snum, servername, architecture, version); - if (status != NT_STATUS_OK) { + if (!W_ERROR_IS_OK(status)) { return status; } @@ -3809,7 +3807,7 @@ static NTSTATUS getprinterdriver2_level3(fstring servername, fstring architectur if (!alloc_buffer_size(buffer, *needed)) { free_printer_driver_info_3(&info); - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } /* fill the buffer with the structures */ @@ -3818,22 +3816,22 @@ static NTSTATUS getprinterdriver2_level3(fstring servername, fstring architectur free_printer_driver_info_3(&info); if (*needed > offered) - return ERRinsufficientbuffer; - else - return NT_STATUS_OK; + return WERR_INSUFFICIENT_BUFFER; + + return WERR_OK; } /**************************************************************************** ****************************************************************************/ -static NTSTATUS getprinterdriver2_level6(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinterdriver2_level6(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_6 info; - NTSTATUS status; + WERROR status; ZERO_STRUCT(info); status=construct_printer_driver_info_6(&info, snum, servername, architecture, version); - if (status != NT_STATUS_OK) { + if (!W_ERROR_IS_OK(status)) { return status; } @@ -3842,7 +3840,7 @@ static NTSTATUS getprinterdriver2_level6(fstring servername, fstring architectur if (!alloc_buffer_size(buffer, *needed)) { free_printer_driver_info_6(&info); - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } /* fill the buffer with the structures */ @@ -3851,15 +3849,15 @@ static NTSTATUS getprinterdriver2_level6(fstring servername, fstring architectur free_printer_driver_info_6(&info); if (*needed > offered) - return ERRinsufficientbuffer; - else - return NT_STATUS_OK; + return WERR_INSUFFICIENT_BUFFER; + + return WERR_OK; } /**************************************************************************** ****************************************************************************/ -NTSTATUS _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_u, SPOOL_R_GETPRINTERDRIVER2 *r_u) +WERROR _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_u, SPOOL_R_GETPRINTERDRIVER2 *r_u) { POLICY_HND *handle = &q_u->handle; UNISTR2 *uni_arch = &q_u->architecture; @@ -3890,7 +3888,7 @@ NTSTATUS _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 * unistr2_to_ascii(architecture, uni_arch, sizeof(architecture)-1); if (!get_printer_snum(p, handle, &snum)) - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; switch (level) { case 1: @@ -3901,9 +3899,8 @@ NTSTATUS _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 * return getprinterdriver2_level3(servername, architecture, clientmajorversion, snum, buffer, offered, needed); case 6: return getprinterdriver2_level6(servername, architecture, clientmajorversion, snum, buffer, offered, needed); - default: - return ERRunknownlevel; } + return WERR_UNKNOWN_LEVEL; } /**************************************************************************** @@ -3917,7 +3914,7 @@ NTSTATUS _spoolss_startpageprinter(pipes_struct *p, SPOOL_Q_STARTPAGEPRINTER *q_ if (Printer) { Printer->page_started=True; - return 0x0; + return NT_STATUS_OK; } DEBUG(3,("Error in startpageprinter printer handle\n")); @@ -3949,7 +3946,7 @@ NTSTATUS _spoolss_endpageprinter(pipes_struct *p, SPOOL_Q_ENDPAGEPRINTER *q_u, S * ********************************************************************/ -NTSTATUS _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, SPOOL_R_STARTDOCPRINTER *r_u) +WERROR _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, SPOOL_R_STARTDOCPRINTER *r_u) { POLICY_HND *handle = &q_u->handle; /* uint32 level = q_u->doc_info_container.level; - notused. */ @@ -3965,7 +3962,7 @@ NTSTATUS _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, if (!Printer) { DEBUG(0,("_spoolss_startdocprinter: Invalid handle (%s)\n", OUR_HANDLE(handle))); - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; } get_current_user(&user, p); @@ -3986,13 +3983,13 @@ NTSTATUS _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, unistr2_to_ascii(datatype, &info_1->datatype, sizeof(datatype)); if (strcmp(datatype, "RAW") != 0) { (*jobid)=0; - return ERRinvaliddatatype; + return WERR_INVALID_DATATYPE; } } /* get the share number of the printer */ if (!get_printer_snum(p, handle, &snum)) { - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; } unistr2_to_ascii(jobname, &info_1->docname, sizeof(jobname)); @@ -4009,7 +4006,7 @@ NTSTATUS _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, Printer->document_started=True; (*jobid) = Printer->jobid; - return 0x0; + return WERR_OK; } /******************************************************************** @@ -4091,7 +4088,7 @@ static NTSTATUS control_printer(POLICY_HND *handle, uint32 command, } break; default: - return ERRunknownlevel; + return WERR_UNKNOWN_LEVEL; } return errcode; @@ -4540,7 +4537,7 @@ static NTSTATUS update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level if (level!=2) { DEBUG(0,("Send a mail to samba@samba.org\n")); DEBUGADD(0,("with the following message: update_printer: level!=2\n")); - result = ERRunknownlevel; + result = WERR_UNKNOWN_LEVEL; goto done; } @@ -4577,7 +4574,7 @@ static NTSTATUS update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level DEBUGADD(8,("Converting the devicemode struct\n")); if (!convert_devicemode(printer->info_2->printername, devmode, &printer->info_2->devmode)) { - result = ERRnomem; + result = WERR_NOMEM; goto done; } } @@ -4662,7 +4659,7 @@ NTSTATUS _spoolss_setprinter(pipes_struct *p, SPOOL_Q_SETPRINTER *q_u, SPOOL_R_S return update_printer_sec(handle, level, info, p, secdesc_ctr); default: - return ERRunknownlevel; + return WERR_UNKNOWN_LEVEL; } } @@ -4800,7 +4797,7 @@ static NTSTATUS enumjobs_level1(print_queue_struct *queue, int snum, if (info==NULL) { safe_free(queue); *returned=0; - return ERRnomem; + return WERR_NOMEM; } for (i=0; i<*returned; i++) @@ -4814,7 +4811,7 @@ static NTSTATUS enumjobs_level1(print_queue_struct *queue, int snum, if (!alloc_buffer_size(buffer, *needed)) { safe_free(info); - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } /* fill the buffer with the structures */ @@ -4826,7 +4823,7 @@ static NTSTATUS enumjobs_level1(print_queue_struct *queue, int snum, if (*needed > offered) { *returned=0; - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } else return NT_STATUS_OK; @@ -4846,12 +4843,12 @@ static NTSTATUS enumjobs_level2(print_queue_struct *queue, int snum, info=(JOB_INFO_2 *)malloc(*returned*sizeof(JOB_INFO_2)); if (info==NULL) { *returned=0; - return ERRnomem; + return WERR_NOMEM; } if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0) { *returned = 0; - return ERRnomem; + return WERR_NOMEM; } for (i=0; i<*returned; i++) @@ -4866,7 +4863,7 @@ static NTSTATUS enumjobs_level2(print_queue_struct *queue, int snum, if (!alloc_buffer_size(buffer, *needed)) { safe_free(info); - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } /* fill the buffer with the structures */ @@ -4881,7 +4878,7 @@ static NTSTATUS enumjobs_level2(print_queue_struct *queue, int snum, if (*needed > offered) { *returned=0; - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } else return NT_STATUS_OK; @@ -4936,7 +4933,7 @@ NTSTATUS _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUM default: safe_free(queue); *returned=0; - return ERRunknownlevel; + return WERR_UNKNOWN_LEVEL; } } @@ -4970,7 +4967,7 @@ NTSTATUS _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r } if (!print_job_exists(jobid)) { - return ERRinvalidprintername; + return WERR_INVALID_PRINTER_NAME; } get_current_user(&user, p); @@ -4994,7 +4991,7 @@ NTSTATUS _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r } break; default: - return ERRunknownlevel; + return WERR_UNKNOWN_LEVEL; } return errcode; @@ -5023,14 +5020,14 @@ static NTSTATUS enumprinterdrivers_level1(fstring servername, fstring architectu DEBUGADD(4,("we have:[%d] drivers in environment [%s] and version [%d]\n", ndrivers, architecture, version)); if(ndrivers == -1) - return ERRnomem; + return WERR_NOMEM; if(ndrivers != 0) { if((tdi1=(DRIVER_INFO_1 *)Realloc(driver_info_1, (*returned+ndrivers) * sizeof(DRIVER_INFO_1))) == NULL) { DEBUG(0,("enumprinterdrivers_level1: failed to enlarge driver info buffer!\n")); safe_free(driver_info_1); safe_free(list); - return ERRnomem; + return WERR_NOMEM; } else driver_info_1 = tdi1; } @@ -5059,7 +5056,7 @@ static NTSTATUS enumprinterdrivers_level1(fstring servername, fstring architectu if (!alloc_buffer_size(buffer, *needed)) { safe_free(driver_info_1); - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } /* fill the buffer with the driver structures */ @@ -5072,7 +5069,7 @@ static NTSTATUS enumprinterdrivers_level1(fstring servername, fstring architectu if (*needed > offered) { *returned=0; - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } else return NT_STATUS_OK; @@ -5101,14 +5098,14 @@ static NTSTATUS enumprinterdrivers_level2(fstring servername, fstring architectu DEBUGADD(4,("we have:[%d] drivers in environment [%s] and version [%d]\n", ndrivers, architecture, version)); if(ndrivers == -1) - return ERRnomem; + return WERR_NOMEM; if(ndrivers != 0) { if((tdi2=(DRIVER_INFO_2 *)Realloc(driver_info_2, (*returned+ndrivers) * sizeof(DRIVER_INFO_2))) == NULL) { DEBUG(0,("enumprinterdrivers_level2: failed to enlarge driver info buffer!\n")); safe_free(driver_info_2); safe_free(list); - return ERRnomem; + return WERR_NOMEM; } else driver_info_2 = tdi2; } @@ -5138,7 +5135,7 @@ static NTSTATUS enumprinterdrivers_level2(fstring servername, fstring architectu if (!alloc_buffer_size(buffer, *needed)) { safe_free(driver_info_2); - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } /* fill the buffer with the form structures */ @@ -5151,7 +5148,7 @@ static NTSTATUS enumprinterdrivers_level2(fstring servername, fstring architectu if (*needed > offered) { *returned=0; - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } else return NT_STATUS_OK; @@ -5180,14 +5177,14 @@ static NTSTATUS enumprinterdrivers_level3(fstring servername, fstring architectu DEBUGADD(4,("we have:[%d] drivers in environment [%s] and version [%d]\n", ndrivers, architecture, version)); if(ndrivers == -1) - return ERRnomem; + return WERR_NOMEM; if(ndrivers != 0) { if((tdi3=(DRIVER_INFO_3 *)Realloc(driver_info_3, (*returned+ndrivers) * sizeof(DRIVER_INFO_3))) == NULL) { DEBUG(0,("enumprinterdrivers_level3: failed to enlarge driver info buffer!\n")); safe_free(driver_info_3); safe_free(list); - return ERRnomem; + return WERR_NOMEM; } else driver_info_3 = tdi3; } @@ -5217,7 +5214,7 @@ static NTSTATUS enumprinterdrivers_level3(fstring servername, fstring architectu if (!alloc_buffer_size(buffer, *needed)) { safe_free(driver_info_3); - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } /* fill the buffer with the driver structures */ @@ -5233,7 +5230,7 @@ static NTSTATUS enumprinterdrivers_level3(fstring servername, fstring architectu if (*needed > offered) { *returned=0; - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } else return NT_STATUS_OK; @@ -5278,7 +5275,7 @@ NTSTATUS _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVER default: *returned=0; safe_free(list); - return ERRunknownlevel; + return WERR_UNKNOWN_LEVEL; } } @@ -5336,7 +5333,7 @@ NTSTATUS _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENU case 1: if ((forms_1=(FORM_1 *)malloc(*numofforms * sizeof(FORM_1))) == NULL) { *numofforms=0; - return ERRnomem; + return WERR_NOMEM; } /* construct the list of form structures */ @@ -5368,7 +5365,7 @@ NTSTATUS _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENU if (!alloc_buffer_size(buffer, buffer_size)){ safe_free(forms_1); - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } /* fill the buffer with the form structures */ @@ -5385,7 +5382,7 @@ NTSTATUS _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENU if (*needed > offered) { *numofforms=0; - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } else return NT_STATUS_OK; @@ -5393,7 +5390,7 @@ NTSTATUS _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENU default: safe_free(list); safe_free(builtinlist); - return ERRunknownlevel; + return WERR_UNKNOWN_LEVEL; } } @@ -5465,11 +5462,11 @@ NTSTATUS _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM *needed=spoolss_size_form_1(&form_1); if (!alloc_buffer_size(buffer, buffer_size)){ - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } if (*needed > offered) { - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } /* fill the buffer with the form structures */ @@ -5480,7 +5477,7 @@ NTSTATUS _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM default: safe_free(list); - return ERRunknownlevel; + return WERR_UNKNOWN_LEVEL; } } @@ -5538,9 +5535,9 @@ static NTSTATUS enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *ne if(numlines) { if((ports=(PORT_INFO_1 *)malloc( numlines * sizeof(PORT_INFO_1) )) == NULL) { - DEBUG(10,("Returning ERRnomem [%x]\n", ERRnomem)); + DEBUG(10,("Returning WERR_NOMEM [%x]\n", WERR_NOMEM)); file_lines_free(qlines); - return ERRnomem; + return WERR_NOMEM; } for (i=0; i offered) { *returned=0; - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } else return NT_STATUS_OK; @@ -5636,9 +5633,9 @@ static NTSTATUS enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *ne if(numlines) { if((ports=(PORT_INFO_2 *)malloc( numlines * sizeof(PORT_INFO_2) )) == NULL) { - DEBUG(10,("Returning ERRnomem [%x]\n", ERRnomem)); + DEBUG(10,("Returning WERR_NOMEM [%x]\n", WERR_NOMEM)); file_lines_free(qlines); - return ERRnomem; + return WERR_NOMEM; } for (i=0; i offered) { *returned=0; - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } else return NT_STATUS_OK; @@ -5718,7 +5715,7 @@ NTSTATUS _spoolss_enumports( pipes_struct *p, SPOOL_Q_ENUMPORTS *q_u, SPOOL_R_EN case 2: return enumports_level_2(buffer, offered, needed, returned); default: - return ERRunknownlevel; + return WERR_UNKNOWN_LEVEL; } } @@ -5736,7 +5733,7 @@ static NTSTATUS spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *un if ((printer = (NT_PRINTER_INFO_LEVEL *)malloc(sizeof(NT_PRINTER_INFO_LEVEL))) == NULL) { DEBUG(0,("spoolss_addprinterex_level_2: malloc fail.\n")); - return ERRnomem; + return WERR_NOMEM; } ZERO_STRUCTP(printer); @@ -5820,13 +5817,13 @@ NTSTATUS _spoolss_addprinterex( pipes_struct *p, SPOOL_Q_ADDPRINTEREX *q_u, SPOO case 1: /* we don't handle yet */ /* but I know what to do ... */ - return ERRunknownlevel; + return WERR_UNKNOWN_LEVEL; case 2: return spoolss_addprinterex_level_2(p, uni_srv_name, info, unk0, unk1, unk2, unk3, user_switch, user, handle); default: - return ERRunknownlevel; + return WERR_UNKNOWN_LEVEL; } } @@ -5848,7 +5845,7 @@ NTSTATUS _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_ get_current_user(&user, p); if (!convert_printer_driver_info(info, &driver, level)) { - err = ERRnomem; + err = WERR_NOMEM; goto done; } @@ -5892,10 +5889,10 @@ static NTSTATUS getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environm unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)-1); if (get_short_archi(short_archi, long_archi)==FALSE) - return ERRinvalidenvironment; + return WERR_INVALID_ENVIRONMENT; if((info=(DRIVER_DIRECTORY_1 *)malloc(sizeof(DRIVER_DIRECTORY_1))) == NULL) - return ERRnomem; + return WERR_NOMEM; slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", global_myname, short_archi); @@ -5907,7 +5904,7 @@ static NTSTATUS getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environm if (!alloc_buffer_size(buffer, *needed)) { safe_free(info); - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } smb_io_driverdir_1("", buffer, info, 0); @@ -5915,7 +5912,7 @@ static NTSTATUS getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environm safe_free(info); if (*needed > offered) - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; else return NT_STATUS_OK; } @@ -5944,7 +5941,7 @@ NTSTATUS _spoolss_getprinterdriverdirectory(pipes_struct *p, SPOOL_Q_GETPRINTERD case 1: return getprinterdriverdir_level_1(name, uni_environment, buffer, offered, needed); default: - return ERRunknownlevel; + return WERR_UNKNOWN_LEVEL; } } @@ -6093,7 +6090,7 @@ NTSTATUS _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, *out_max_value_len=(in_value_len/sizeof(uint16)); if((*out_value=(uint16 *)talloc_zero(p->mem_ctx,in_value_len*sizeof(uint8))) == NULL) { safe_free(data); - return ERRnomem; + return WERR_NOMEM; } *out_value_len = rpcstr_push((char *)*out_value,value, in_value_len, 0); @@ -6104,7 +6101,7 @@ NTSTATUS _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, *out_max_data_len=in_data_len; if((*data_out=(uint8 *)talloc_zero(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) { safe_free(data); - return ERRnomem; + return WERR_NOMEM; } memcpy(*data_out, data, (size_t)data_len); @@ -6146,7 +6143,7 @@ NTSTATUS _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, status = get_a_printer(&printer, 2, lp_servicename(snum)); if (status != 0x0) - return ERRinvalidname; + return WERR_INVALID_NAME; convert_specific_param(¶m, value , type, data, real_len); @@ -6237,7 +6234,7 @@ NTSTATUS _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA * status = get_a_printer(&printer, 2, lp_servicename(snum)); if (status != 0x0) - return ERRinvalidname; + return WERR_INVALID_NAME; ZERO_STRUCTP(¶m); unistr2_to_ascii(param.value, value, sizeof(param.value)-1); @@ -6279,7 +6276,7 @@ NTSTATUS _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFOR count=get_ntforms(&list); if(!add_a_form(&list, form, &count)) - return ERRnomem; + return WERR_NOMEM; write_ntforms(&list, count); safe_free(list); @@ -6364,7 +6361,7 @@ static NTSTATUS enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, PRINTPROCESSOR_1 *info_1=NULL; if((info_1 = (PRINTPROCESSOR_1 *)malloc(sizeof(PRINTPROCESSOR_1))) == NULL) - return ERRnomem; + return WERR_NOMEM; (*returned) = 0x1; @@ -6373,7 +6370,7 @@ static NTSTATUS enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, *needed += spoolss_size_printprocessor_info_1(info_1); if (!alloc_buffer_size(buffer, *needed)) - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; smb_io_printprocessor_info_1("", buffer, info_1, 0); @@ -6381,7 +6378,7 @@ static NTSTATUS enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, if (*needed > offered) { *returned=0; - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } else return NT_STATUS_OK; @@ -6420,7 +6417,7 @@ NTSTATUS _spoolss_enumprintprocessors(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCESSO case 1: return enumprintprocessors_level_1(buffer, offered, needed, returned); default: - return ERRunknownlevel; + return WERR_UNKNOWN_LEVEL; } } @@ -6432,7 +6429,7 @@ static NTSTATUS enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offere PRINTPROCDATATYPE_1 *info_1=NULL; if((info_1 = (PRINTPROCDATATYPE_1 *)malloc(sizeof(PRINTPROCDATATYPE_1))) == NULL) - return ERRnomem; + return WERR_NOMEM; (*returned) = 0x1; @@ -6441,7 +6438,7 @@ static NTSTATUS enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offere *needed += spoolss_size_printprocdatatype_info_1(info_1); if (!alloc_buffer_size(buffer, *needed)) - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; smb_io_printprocdatatype_info_1("", buffer, info_1, 0); @@ -6449,7 +6446,7 @@ static NTSTATUS enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offere if (*needed > offered) { *returned=0; - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } else return NT_STATUS_OK; @@ -6481,7 +6478,7 @@ NTSTATUS _spoolss_enumprintprocdatatypes(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCD case 1: return enumprintprocdatatypes_level_1(buffer, offered, needed, returned); default: - return ERRunknownlevel; + return WERR_UNKNOWN_LEVEL; } } @@ -6494,7 +6491,7 @@ static NTSTATUS enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, ui PRINTMONITOR_1 *info_1=NULL; if((info_1 = (PRINTMONITOR_1 *)malloc(sizeof(PRINTMONITOR_1))) == NULL) - return ERRnomem; + return WERR_NOMEM; (*returned) = 0x1; @@ -6503,7 +6500,7 @@ static NTSTATUS enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, ui *needed += spoolss_size_printmonitor_info_1(info_1); if (!alloc_buffer_size(buffer, *needed)) - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; smb_io_printmonitor_info_1("", buffer, info_1, 0); @@ -6511,7 +6508,7 @@ static NTSTATUS enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, ui if (*needed > offered) { *returned=0; - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } else return NT_STATUS_OK; @@ -6525,7 +6522,7 @@ static NTSTATUS enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, ui PRINTMONITOR_2 *info_2=NULL; if((info_2 = (PRINTMONITOR_2 *)malloc(sizeof(PRINTMONITOR_2))) == NULL) - return ERRnomem; + return WERR_NOMEM; (*returned) = 0x1; @@ -6536,7 +6533,7 @@ static NTSTATUS enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, ui *needed += spoolss_size_printmonitor_info_2(info_2); if (!alloc_buffer_size(buffer, *needed)) - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; smb_io_printmonitor_info_2("", buffer, info_2, 0); @@ -6544,7 +6541,7 @@ static NTSTATUS enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, ui if (*needed > offered) { *returned=0; - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; } else return NT_STATUS_OK; @@ -6584,7 +6581,7 @@ NTSTATUS _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS * case 2: return enumprintmonitors_level_2(buffer, offered, needed, returned); default: - return ERRunknownlevel; + return WERR_UNKNOWN_LEVEL; } } @@ -6600,7 +6597,7 @@ static NTSTATUS getjob_level_1(print_queue_struct *queue, int count, int snum, u if (info_1 == NULL) { safe_free(queue); - return ERRnomem; + return WERR_NOMEM; } for (i=0; i offered) - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; else return NT_STATUS_OK; } @@ -6652,7 +6649,7 @@ static NTSTATUS getjob_level_2(print_queue_struct *queue, int count, int snum, u if (info_2 == NULL) { safe_free(queue); - return ERRnomem; + return WERR_NOMEM; } for (i=0; i offered) - return ERRinsufficientbuffer; + return WERR_INSUFFICIENT_BUFFER; else return NT_STATUS_OK; } @@ -6737,6 +6734,6 @@ NTSTATUS _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB * return getjob_level_2(queue, count, snum, jobid, buffer, offered, needed); default: safe_free(queue); - return ERRunknownlevel; + return WERR_UNKNOWN_LEVEL; } } -- cgit From fbc1f326f445a2826a10155fe0122c779bb1f80e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 3 Sep 2001 10:38:13 +0000 Subject: more NTSTATUS/WERROR conversion (This used to be commit ad648c5cd8ebe4be8304379117f403d7673dcbc8) --- source3/rpc_server/srv_spoolss_nt.c | 314 ++++++++++++++++++------------------ 1 file changed, 156 insertions(+), 158 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 140eed5c05..80c809047c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4000,7 +4000,7 @@ WERROR _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, S NT error code. */ if (Printer->jobid == -1) { - return map_nt_error_from_unix(errno); + return map_werror_from_unix(errno); } Printer->document_started=True; @@ -4045,7 +4045,7 @@ NTSTATUS _spoolss_writeprinter(pipes_struct *p, SPOOL_Q_WRITEPRINTER *q_u, SPOOL r_u->buffer_written = q_u->buffer_size2; - return 0x0; + return NT_STATUS_OK; } /******************************************************************** @@ -4053,38 +4053,39 @@ NTSTATUS _spoolss_writeprinter(pipes_struct *p, SPOOL_Q_WRITEPRINTER *q_u, SPOOL * called from the spoolss dispatcher * ********************************************************************/ -static NTSTATUS control_printer(POLICY_HND *handle, uint32 command, +static WERROR control_printer(POLICY_HND *handle, uint32 command, pipes_struct *p) { struct current_user user; - int snum, errcode = ERRbadfunc; + int snum; + WERROR errcode = WERR_BADFUNC; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); get_current_user(&user, p); if (!Printer) { DEBUG(0,("control_printer: Invalid handle (%s)\n", OUR_HANDLE(handle))); - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; } if (!get_printer_snum(p, handle, &snum)) - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; switch (command) { case PRINTER_CONTROL_PAUSE: if (print_queue_pause(&user, snum, &errcode)) { - errcode = 0; + errcode = WERR_OK; } break; case PRINTER_CONTROL_RESUME: case PRINTER_CONTROL_UNPAUSE: if (print_queue_resume(&user, snum, &errcode)) { - errcode = 0; + errcode = WERR_OK; } break; case PRINTER_CONTROL_PURGE: if (print_queue_purge(&user, snum, &errcode)) { - errcode = 0; + errcode = WERR_OK; } break; default: @@ -4098,7 +4099,7 @@ static NTSTATUS control_printer(POLICY_HND *handle, uint32 command, * api_spoolss_abortprinter ********************************************************************/ -NTSTATUS _spoolss_abortprinter(pipes_struct *p, SPOOL_Q_ABORTPRINTER *q_u, SPOOL_R_ABORTPRINTER *r_u) +WERROR _spoolss_abortprinter(pipes_struct *p, SPOOL_Q_ABORTPRINTER *q_u, SPOOL_R_ABORTPRINTER *r_u) { POLICY_HND *handle = &q_u->handle; @@ -4109,13 +4110,13 @@ NTSTATUS _spoolss_abortprinter(pipes_struct *p, SPOOL_Q_ABORTPRINTER *q_u, SPOOL * called by spoolss_api_setprinter * when updating a printer description ********************************************************************/ -static NTSTATUS update_printer_sec(POLICY_HND *handle, uint32 level, +static WERROR update_printer_sec(POLICY_HND *handle, uint32 level, const SPOOL_PRINTER_INFO_LEVEL *info, pipes_struct *p, SEC_DESC_BUF *secdesc_ctr) { SEC_DESC_BUF *new_secdesc_ctr = NULL, *old_secdesc_ctr = NULL; struct current_user user; - uint32 result; + WERROR result; int snum; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); @@ -4124,7 +4125,7 @@ static NTSTATUS update_printer_sec(POLICY_HND *handle, uint32 level, DEBUG(0,("update_printer_sec: Invalid handle (%s)\n", OUR_HANDLE(handle))); - result = NT_STATUS_INVALID_HANDLE; + result = WERR_BADFID; goto done; } @@ -4174,7 +4175,7 @@ static NTSTATUS update_printer_sec(POLICY_HND *handle, uint32 level, new_secdesc_ctr = sec_desc_merge(p->mem_ctx, secdesc_ctr, old_secdesc_ctr); if (sec_desc_equal(new_secdesc_ctr->sec, old_secdesc_ctr->sec)) { - result = NT_STATUS_OK; + result = WERR_OK; goto done; } @@ -4188,7 +4189,7 @@ static NTSTATUS update_printer_sec(POLICY_HND *handle, uint32 level, information. */ if (!print_access_check(&user, snum, PRINTER_ACCESS_ADMINISTER)) { - result = NT_STATUS_ACCESS_DENIED; + result = WERR_ACCESS_DENIED; goto done; } @@ -4521,18 +4522,18 @@ static BOOL nt_printer_info_level_equal(NT_PRINTER_INFO_LEVEL *p1, * when updating a printer description ********************************************************************/ -static NTSTATUS update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, +static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, const SPOOL_PRINTER_INFO_LEVEL *info, DEVICEMODE *devmode) { int snum; NT_PRINTER_INFO_LEVEL *printer = NULL, *old_printer = NULL; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); - uint32 result; + WERROR result; DEBUG(8,("update_printer\n")); - result = NT_STATUS_OK; + result = WERR_OK; if (level!=2) { DEBUG(0,("Send a mail to samba@samba.org\n")); @@ -4542,18 +4543,18 @@ static NTSTATUS update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level } if (!Printer) { - result = NT_STATUS_INVALID_HANDLE; + result = WERR_BADFID; goto done; } if (!get_printer_snum(p, handle, &snum)) { - result = NT_STATUS_INVALID_HANDLE; + result = WERR_BADFID; goto done; } - if((get_a_printer(&printer, 2, lp_servicename(snum)) != 0) || - (get_a_printer(&old_printer, 2, lp_servicename(snum)) != 0)) { - result = NT_STATUS_INVALID_HANDLE; + if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, lp_servicename(snum))) || + (!W_ERROR_IS_OK(get_a_printer(&old_printer, 2, lp_servicename(snum))))) { + result = WERR_BADFID; goto done; } @@ -4582,7 +4583,7 @@ static NTSTATUS update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level /* Do sanity check on the requested changes for Samba */ if (!check_printer_ok(printer->info_2, snum)) { - result = ERRinvalidparam; + result = WERR_INVALID_PARAM; goto done; } @@ -4592,7 +4593,7 @@ static NTSTATUS update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level if (nt_printer_info_level_equal(printer, old_printer)) { DEBUG(3, ("printer info has not changed\n")); - result = NT_STATUS_OK; + result = WERR_OK; goto done; } @@ -4601,7 +4602,7 @@ static NTSTATUS update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { DEBUG(3, ("printer property change denied by security " "descriptor\n")); - result = NT_STATUS_ACCESS_DENIED; + result = WERR_ACCESS_DENIED; goto done; } @@ -4609,7 +4610,7 @@ static NTSTATUS update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level if (*lp_addprinter_cmd() ) if ( !add_printer_hook(printer) ) { - result = NT_STATUS_ACCESS_DENIED; + result = WERR_ACCESS_DENIED; goto done; } @@ -4617,7 +4618,7 @@ static NTSTATUS update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level if (add_a_printer(*printer, 2)!=0) { /* I don't really know what to return here !!! */ - result = NT_STATUS_ACCESS_DENIED; + result = WERR_ACCESS_DENIED; goto done; } @@ -4633,7 +4634,7 @@ static NTSTATUS update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level /**************************************************************************** ****************************************************************************/ -NTSTATUS _spoolss_setprinter(pipes_struct *p, SPOOL_Q_SETPRINTER *q_u, SPOOL_R_SETPRINTER *r_u) +WERROR _spoolss_setprinter(pipes_struct *p, SPOOL_Q_SETPRINTER *q_u, SPOOL_R_SETPRINTER *r_u) { POLICY_HND *handle = &q_u->handle; uint32 level = q_u->level; @@ -4646,7 +4647,7 @@ NTSTATUS _spoolss_setprinter(pipes_struct *p, SPOOL_Q_SETPRINTER *q_u, SPOOL_R_S if (!Printer) { DEBUG(0,("_spoolss_setprinter: Invalid handle (%s)\n", OUR_HANDLE(handle))); - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; } /* check the level */ @@ -4694,16 +4695,16 @@ NTSTATUS _spoolss_fcpn(pipes_struct *p, SPOOL_Q_FCPN *q_u, SPOOL_R_FCPN *r_u) /**************************************************************************** ****************************************************************************/ -NTSTATUS _spoolss_addjob(pipes_struct *p, SPOOL_Q_ADDJOB *q_u, SPOOL_R_ADDJOB *r_u) +WERROR _spoolss_addjob(pipes_struct *p, SPOOL_Q_ADDJOB *q_u, SPOOL_R_ADDJOB *r_u) { /* that's an [in out] buffer (despite appearences to the contrary) */ spoolss_move_buffer(q_u->buffer, &r_u->buffer); r_u->needed = 0; - return ERRinvalidparam; /* this is what a NT server - returns for AddJob. AddJob - must fail on non-local - printers */ + return WERR_INVALID_PARAM; /* this is what a NT server + returns for AddJob. AddJob + must fail on non-local + printers */ } /**************************************************************************** @@ -4786,7 +4787,7 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, /**************************************************************************** Enumjobs at level 1. ****************************************************************************/ -static NTSTATUS enumjobs_level1(print_queue_struct *queue, int snum, +static WERROR enumjobs_level1(print_queue_struct *queue, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { @@ -4825,14 +4826,14 @@ static NTSTATUS enumjobs_level1(print_queue_struct *queue, int snum, *returned=0; return WERR_INSUFFICIENT_BUFFER; } - else - return NT_STATUS_OK; + + return WERR_OK; } /**************************************************************************** Enumjobs at level 2. ****************************************************************************/ -static NTSTATUS enumjobs_level2(print_queue_struct *queue, int snum, +static WERROR enumjobs_level2(print_queue_struct *queue, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { @@ -4880,15 +4881,15 @@ static NTSTATUS enumjobs_level2(print_queue_struct *queue, int snum, *returned=0; return WERR_INSUFFICIENT_BUFFER; } - else - return NT_STATUS_OK; + + return WERR_OK; } /**************************************************************************** Enumjobs. ****************************************************************************/ -NTSTATUS _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJOBS *r_u) +WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJOBS *r_u) { POLICY_HND *handle = &q_u->handle; /* uint32 firstjob = q_u->firstjob; - notused. */ @@ -4915,14 +4916,14 @@ NTSTATUS _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUM *returned=0; if (!get_printer_snum(p, handle, &snum)) - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; *returned = print_queue_status(snum, &queue, &prt_status); DEBUGADD(4,("count:[%d], status:[%d], [%s]\n", *returned, prt_status.status, prt_status.message)); if (*returned == 0) { safe_free(queue); - return NT_STATUS_OK; + return WERR_OK; } switch (level) { @@ -4940,15 +4941,15 @@ NTSTATUS _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUM /**************************************************************************** ****************************************************************************/ -NTSTATUS _spoolss_schedulejob( pipes_struct *p, SPOOL_Q_SCHEDULEJOB *q_u, SPOOL_R_SCHEDULEJOB *r_u) +WERROR _spoolss_schedulejob( pipes_struct *p, SPOOL_Q_SCHEDULEJOB *q_u, SPOOL_R_SCHEDULEJOB *r_u) { - return 0x0; + return WERR_OK; } /**************************************************************************** ****************************************************************************/ -NTSTATUS _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u) +WERROR _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u) { POLICY_HND *handle = &q_u->handle; uint32 jobid = q_u->jobid; @@ -4958,12 +4959,13 @@ NTSTATUS _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r struct current_user user; print_status_struct prt_status; - int snum, errcode = ERRbadfunc; + int snum; + WERROR errcode = WERR_BADFUNC; memset(&prt_status, 0, sizeof(prt_status)); if (!get_printer_snum(p, handle, &snum)) { - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; } if (!print_job_exists(jobid)) { @@ -5000,13 +5002,12 @@ NTSTATUS _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r /**************************************************************************** Enumerates all printer drivers at level 1. ****************************************************************************/ -static NTSTATUS enumprinterdrivers_level1(fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int i; int ndrivers; uint32 version; fstring *list = NULL; - NT_PRINTER_DRIVER_INFO_LEVEL driver; DRIVER_INFO_1 *tdi1, *driver_info_1=NULL; @@ -5071,20 +5072,19 @@ static NTSTATUS enumprinterdrivers_level1(fstring servername, fstring architectu *returned=0; return WERR_INSUFFICIENT_BUFFER; } - else - return NT_STATUS_OK; + + return WERR_OK; } /**************************************************************************** Enumerates all printer drivers at level 2. ****************************************************************************/ -static NTSTATUS enumprinterdrivers_level2(fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enumprinterdrivers_level2(fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int i; int ndrivers; uint32 version; fstring *list = NULL; - NT_PRINTER_DRIVER_INFO_LEVEL driver; DRIVER_INFO_2 *tdi2, *driver_info_2=NULL; @@ -5150,20 +5150,19 @@ static NTSTATUS enumprinterdrivers_level2(fstring servername, fstring architectu *returned=0; return WERR_INSUFFICIENT_BUFFER; } - else - return NT_STATUS_OK; + + return WERR_OK; } /**************************************************************************** Enumerates all printer drivers at level 3. ****************************************************************************/ -static NTSTATUS enumprinterdrivers_level3(fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enumprinterdrivers_level3(fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int i; int ndrivers; uint32 version; fstring *list = NULL; - NT_PRINTER_DRIVER_INFO_LEVEL driver; DRIVER_INFO_3 *tdi3, *driver_info_3=NULL; @@ -5232,15 +5231,15 @@ static NTSTATUS enumprinterdrivers_level3(fstring servername, fstring architectu *returned=0; return WERR_INSUFFICIENT_BUFFER; } - else - return NT_STATUS_OK; + + return WERR_OK; } /**************************************************************************** Enumerates all printer drivers. ****************************************************************************/ -NTSTATUS _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS *q_u, SPOOL_R_ENUMPRINTERDRIVERS *r_u) +WERROR _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS *q_u, SPOOL_R_ENUMPRINTERDRIVERS *r_u) { /* UNISTR2 *name = &q_u->name; - notused. */ UNISTR2 *environment = &q_u->environment; @@ -5297,7 +5296,7 @@ static void fill_form_1(FORM_1 *form, nt_forms_struct *list) /**************************************************************************** ****************************************************************************/ -NTSTATUS _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMFORMS *r_u) +WERROR _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMFORMS *r_u) { /* POLICY_HND *handle = &q_u->handle; - notused. */ uint32 level = q_u->level; @@ -5385,7 +5384,7 @@ NTSTATUS _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENU return WERR_INSUFFICIENT_BUFFER; } else - return NT_STATUS_OK; + return WERR_OK; default: safe_free(list); @@ -5398,7 +5397,7 @@ NTSTATUS _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENU /**************************************************************************** ****************************************************************************/ -NTSTATUS _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM *r_u) +WERROR _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM *r_u) { /* POLICY_HND *handle = &q_u->handle; - notused. */ uint32 level = q_u->level; @@ -5431,7 +5430,7 @@ NTSTATUS _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM DEBUGADD(5,("Number of forms [%d]\n", numofforms)); if (numofforms == 0) - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; } switch (level) { @@ -5473,7 +5472,7 @@ NTSTATUS _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM DEBUGADD(6,("adding form %s [%d] to buffer\n", form_name, i)); smb_io_form_1("", buffer, &form_1, 0); - return NT_STATUS_OK; + return WERR_OK; default: safe_free(list); @@ -5503,7 +5502,7 @@ static void fill_port_2(PORT_INFO_2 *port, char *name) /**************************************************************************** enumports level 1. ****************************************************************************/ -static NTSTATUS enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PORT_INFO_1 *ports=NULL; int i=0; @@ -5525,7 +5524,7 @@ static NTSTATUS enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *ne if (fd != -1) close(fd); /* Is this the best error to return here? */ - return NT_STATUS_ACCESS_DENIED; + return WERR_ACCESS_DENIED; } numlines = 0; @@ -5584,15 +5583,15 @@ static NTSTATUS enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *ne *returned=0; return WERR_INSUFFICIENT_BUFFER; } - else - return NT_STATUS_OK; + + return WERR_OK; } /**************************************************************************** enumports level 2. ****************************************************************************/ -static NTSTATUS enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PORT_INFO_2 *ports=NULL; int i=0; @@ -5623,7 +5622,7 @@ static NTSTATUS enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *ne if (fd != -1) close(fd); /* Is this the best error to return here? */ - return NT_STATUS_ACCESS_DENIED; + return WERR_ACCESS_DENIED; } numlines = 0; @@ -5683,15 +5682,15 @@ static NTSTATUS enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *ne *returned=0; return WERR_INSUFFICIENT_BUFFER; } - else - return NT_STATUS_OK; + + return WERR_OK; } /**************************************************************************** enumports. ****************************************************************************/ -NTSTATUS _spoolss_enumports( pipes_struct *p, SPOOL_Q_ENUMPORTS *q_u, SPOOL_R_ENUMPORTS *r_u) +WERROR _spoolss_enumports( pipes_struct *p, SPOOL_Q_ENUMPORTS *q_u, SPOOL_R_ENUMPORTS *r_u) { /* UNISTR2 *name = &q_u->name; - notused. */ uint32 level = q_u->level; @@ -5721,7 +5720,7 @@ NTSTATUS _spoolss_enumports( pipes_struct *p, SPOOL_Q_ENUMPORTS *q_u, SPOOL_R_EN /**************************************************************************** ****************************************************************************/ -static NTSTATUS spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_srv_name, +static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_srv_name, const SPOOL_PRINTER_INFO_LEVEL *info, uint32 unk0, uint32 unk1, uint32 unk2, uint32 unk3, uint32 user_switch, const SPOOL_USER_CTR *user, @@ -5744,7 +5743,7 @@ static NTSTATUS spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *un if (*lp_addprinter_cmd() ) if ( !add_printer_hook(printer) ) { free_a_printer(&printer,2); - return NT_STATUS_ACCESS_DENIED; + return WERR_ACCESS_DENIED; } slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname, @@ -5752,13 +5751,13 @@ static NTSTATUS spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *un if ((snum = print_queue_snum(printer->info_2->sharename)) == -1) { free_a_printer(&printer,2); - return NT_STATUS_ACCESS_DENIED; + return WERR_ACCESS_DENIED; } /* you must be a printer admin to add a new printer */ if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { free_a_printer(&printer,2); - return NT_STATUS_ACCESS_DENIED; + return WERR_ACCESS_DENIED; } /* @@ -5767,7 +5766,7 @@ static NTSTATUS spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *un if (!check_printer_ok(printer->info_2, snum)) { free_a_printer(&printer,2); - return ERRinvalidparam; + return WERR_INVALID_PARAM; } /* @@ -5780,27 +5779,27 @@ static NTSTATUS spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *un /* write the ASCII on disk */ if (add_a_printer(*printer, 2) != 0) { free_a_printer(&printer,2); - return NT_STATUS_ACCESS_DENIED; + return WERR_ACCESS_DENIED; } if (!open_printer_hnd(p, handle, name)) { /* Handle open failed - remove addition. */ del_a_printer(printer->info_2->sharename); free_a_printer(&printer,2); - return NT_STATUS_ACCESS_DENIED; + return WERR_ACCESS_DENIED; } free_a_printer(&printer,2); srv_spoolss_sendnotify(p, handle); - return NT_STATUS_OK; + return WERR_OK; } /**************************************************************************** ****************************************************************************/ -NTSTATUS _spoolss_addprinterex( pipes_struct *p, SPOOL_Q_ADDPRINTEREX *q_u, SPOOL_R_ADDPRINTEREX *r_u) +WERROR _spoolss_addprinterex( pipes_struct *p, SPOOL_Q_ADDPRINTEREX *q_u, SPOOL_R_ADDPRINTEREX *r_u) { UNISTR2 *uni_srv_name = &q_u->server_name; uint32 level = q_u->level; @@ -5830,13 +5829,12 @@ NTSTATUS _spoolss_addprinterex( pipes_struct *p, SPOOL_Q_ADDPRINTEREX *q_u, SPOO /**************************************************************************** ****************************************************************************/ -NTSTATUS _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u, SPOOL_R_ADDPRINTERDRIVER *r_u) +WERROR _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u, SPOOL_R_ADDPRINTERDRIVER *r_u) { /* UNISTR2 *server_name = &q_u->server_name; - notused. */ uint32 level = q_u->level; SPOOL_PRINTER_DRIVER_INFO_LEVEL *info = &q_u->info; - - uint32 err = NT_STATUS_OK; + WERROR err = WERR_OK; NT_PRINTER_DRIVER_INFO_LEVEL driver; struct current_user user; @@ -5856,12 +5854,12 @@ NTSTATUS _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_ DEBUG(5,("Moving driver to final destination\n")); if(!move_driver_to_download_area(driver, level, &user, &err)) { if (err == 0) - err = NT_STATUS_ACCESS_DENIED; + err = WERR_ACCESS_DENIED; goto done; } if (add_a_printer_driver(driver, level)!=0) { - err = NT_STATUS_ACCESS_DENIED; + err = WERR_ACCESS_DENIED; goto done; } @@ -5879,7 +5877,7 @@ static void fill_driverdir_1(DRIVER_DIRECTORY_1 *info, char *name) /**************************************************************************** ****************************************************************************/ -static NTSTATUS getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environment, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environment, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { pstring path; pstring long_archi; @@ -5913,14 +5911,14 @@ static NTSTATUS getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environm if (*needed > offered) return WERR_INSUFFICIENT_BUFFER; - else - return NT_STATUS_OK; + + return WERR_OK; } /**************************************************************************** ****************************************************************************/ -NTSTATUS _spoolss_getprinterdriverdirectory(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVERDIR *q_u, SPOOL_R_GETPRINTERDRIVERDIR *r_u) +WERROR _spoolss_getprinterdriverdirectory(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVERDIR *q_u, SPOOL_R_GETPRINTERDRIVERDIR *r_u) { UNISTR2 *name = &q_u->name; UNISTR2 *uni_environment = &q_u->environment; @@ -5948,7 +5946,7 @@ NTSTATUS _spoolss_getprinterdriverdirectory(pipes_struct *p, SPOOL_Q_GETPRINTERD /**************************************************************************** ****************************************************************************/ -NTSTATUS _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, SPOOL_R_ENUMPRINTERDATA *r_u) +WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, SPOOL_R_ENUMPRINTERDATA *r_u) { POLICY_HND *handle = &q_u->handle; uint32 idx = q_u->index; @@ -5991,14 +5989,14 @@ NTSTATUS _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, if (!Printer) { DEBUG(0,("_spoolss_enumprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; } if (!get_printer_snum(p,handle, &snum)) - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; if (get_a_printer(&printer, 2, lp_servicename(snum)) != 0) - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; /* * The NT machine wants to know the biggest size of value and data @@ -6021,7 +6019,7 @@ NTSTATUS _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, if (!get_specific_param_by_index(*printer, 2, idx, value, &data, &type, &data_len)) { safe_free(data); free_a_printer(&printer, 2); - return ERRnomoreitems; + return WERR_NO_MORE_ITEMS; } #endif @@ -6052,7 +6050,7 @@ NTSTATUS _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, if (param_index == 0) { /* No parameters found. */ free_a_printer(&printer, 2); - return ERRnomoreitems; + return WERR_NO_MORE_ITEMS; } /* the value is an UNICODE string but realvaluesize is the length in bytes including the leading 0 */ @@ -6062,7 +6060,7 @@ NTSTATUS _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, DEBUG(6,("final values: [%d], [%d]\n", *out_value_len, *out_data_len)); free_a_printer(&printer, 2); - return NT_STATUS_OK; + return WERR_OK; } /* @@ -6073,7 +6071,7 @@ NTSTATUS _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, if (!get_specific_param_by_index(*printer, 2, idx, value, &data, &type, &data_len)) { safe_free(data); free_a_printer(&printer, 2); - return ERRnomoreitems; + return WERR_NO_MORE_ITEMS; } free_a_printer(&printer, 2); @@ -6109,13 +6107,13 @@ NTSTATUS _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, safe_free(data); - return NT_STATUS_OK; + return WERR_OK; } /**************************************************************************** ****************************************************************************/ -NTSTATUS _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SPOOL_R_SETPRINTERDATA *r_u) +WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SPOOL_R_SETPRINTERDATA *r_u) { POLICY_HND *handle = &q_u->handle; UNISTR2 *value = &q_u->value; @@ -6128,18 +6126,18 @@ NTSTATUS _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_PARAM *param = NULL, old_param; int snum=0; - NTSTATUS status = 0x0; + WERROR status = WERR_OK; Printer_entry *Printer=find_printer_index_by_hnd(p, handle); DEBUG(5,("spoolss_setprinterdata\n")); if (!Printer) { DEBUG(0,("_spoolss_setprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; } if (!get_printer_snum(p,handle, &snum)) - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; status = get_a_printer(&printer, 2, lp_servicename(snum)); if (status != 0x0) @@ -6150,7 +6148,7 @@ NTSTATUS _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, /* Check if we are making any changes or not. Return true if nothing is actually changing. */ - ZERO_STRUCT(old_param); + ZERO_STRUCT(old_param); if (get_specific_param(*printer, 2, param->value, &old_param.data, &old_param.type, (uint32 *)&old_param.data_len)) { @@ -6161,7 +6159,7 @@ NTSTATUS _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, old_param.data_len) == 0) { DEBUG(3, ("setprinterdata hasn't changed\n")); - status = NT_STATUS_OK; + status = WERR_OK; goto done; } } @@ -6171,7 +6169,7 @@ NTSTATUS _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { DEBUG(3, ("security descriptor change denied by existing " "security descriptor\n")); - status = NT_STATUS_ACCESS_DENIED; + status = WERR_ACCESS_DENIED; goto done; } @@ -6205,7 +6203,7 @@ NTSTATUS _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, /**************************************************************************** ****************************************************************************/ -NTSTATUS _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_u, SPOOL_R_DELETEPRINTERDATA *r_u) +WERROR _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_u, SPOOL_R_DELETEPRINTERDATA *r_u) { POLICY_HND *handle = &q_u->handle; UNISTR2 *value = &q_u->valuename; @@ -6213,23 +6211,23 @@ NTSTATUS _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA * NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_PARAM param; int snum=0; - NTSTATUS status = 0x0; + WERROR status = WERR_OK; Printer_entry *Printer=find_printer_index_by_hnd(p, handle); DEBUG(5,("spoolss_deleteprinterdata\n")); if (!Printer) { DEBUG(0,("_spoolss_deleteprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; } if (!get_printer_snum(p, handle, &snum)) - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { DEBUG(3, ("_spoolss_deleteprinterdata: printer properties " "change denied by existing security descriptor\n")); - return NT_STATUS_ACCESS_DENIED; + return WERR_ACCESS_DENIED; } status = get_a_printer(&printer, 2, lp_servicename(snum)); @@ -6240,7 +6238,7 @@ NTSTATUS _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA * unistr2_to_ascii(param.value, value, sizeof(param.value)-1); if(!unlink_specific_param_if_exist(printer->info_2, ¶m)) - status = ERRinvalidparam; + status = WERR_INVALID_PARAM; else status = mod_a_printer(*printer, 2); @@ -6251,7 +6249,7 @@ NTSTATUS _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA * /**************************************************************************** ****************************************************************************/ -NTSTATUS _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM *r_u) +WERROR _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM *r_u) { POLICY_HND *handle = &q_u->handle; /* uint32 level = q_u->level; - notused. */ @@ -6266,12 +6264,12 @@ NTSTATUS _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFOR if (!Printer) { DEBUG(0,("_spoolss_addform: Invalid handle (%s).\n", OUR_HANDLE(handle))); - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; } /* can't add if builtin */ if (get_a_builtin_ntform(&form->name,&tmpForm)) { - return ERRinvalidparam; + return WERR_INVALID_PARAM; } count=get_ntforms(&list); @@ -6281,19 +6279,19 @@ NTSTATUS _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFOR safe_free(list); - return 0x0; + return WERR_OK; } /**************************************************************************** ****************************************************************************/ -NTSTATUS _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DELETEFORM *r_u) +WERROR _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DELETEFORM *r_u) { POLICY_HND *handle = &q_u->handle; UNISTR2 *form_name = &q_u->name; nt_forms_struct tmpForm; int count=0; - uint32 ret = 0; + WERROR ret = 0; nt_forms_struct *list=NULL; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); @@ -6301,17 +6299,17 @@ NTSTATUS _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_ if (!Printer) { DEBUG(0,("_spoolss_deleteform: Invalid handle (%s).\n", OUR_HANDLE(handle))); - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; } /* can't delete if builtin */ if (get_a_builtin_ntform(form_name,&tmpForm)) { - return ERRinvalidparam; + return WERR_INVALID_PARAM; } count = get_ntforms(&list); if(!delete_a_form(&list, form_name, &count, &ret)) - return ERRinvalidparam; + return WERR_INVALID_PARAM; safe_free(list); @@ -6321,7 +6319,7 @@ NTSTATUS _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_ /**************************************************************************** ****************************************************************************/ -NTSTATUS _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM *r_u) +WERROR _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM *r_u) { POLICY_HND *handle = &q_u->handle; /* UNISTR2 *uni_name = &q_u->name; - notused. */ @@ -6337,11 +6335,11 @@ NTSTATUS _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM if (!Printer) { DEBUG(0,("_spoolss_setform: Invalid handle (%s).\n", OUR_HANDLE(handle))); - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; } /* can't set if builtin */ if (get_a_builtin_ntform(&form->name,&tmpForm)) { - return ERRinvalidparam; + return WERR_INVALID_PARAM; } count=get_ntforms(&list); @@ -6350,13 +6348,13 @@ NTSTATUS _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM safe_free(list); - return 0x0; + return WERR_OK; } /**************************************************************************** enumprintprocessors level 1. ****************************************************************************/ -static NTSTATUS enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PRINTPROCESSOR_1 *info_1=NULL; @@ -6380,21 +6378,21 @@ static NTSTATUS enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, *returned=0; return WERR_INSUFFICIENT_BUFFER; } - else - return NT_STATUS_OK; + + return WERR_OK; } /**************************************************************************** ****************************************************************************/ -NTSTATUS _spoolss_enumprintprocessors(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCESSORS *q_u, SPOOL_R_ENUMPRINTPROCESSORS *r_u) +WERROR _spoolss_enumprintprocessors(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCESSORS *q_u, SPOOL_R_ENUMPRINTPROCESSORS *r_u) { /* UNISTR2 *name = &q_u->name; - notused. */ /* UNISTR2 *environment = &q_u->environment; - notused. */ uint32 level = q_u->level; - NEW_BUFFER *buffer = NULL; + NEW_BUFFER *buffer = NULL; uint32 offered = q_u->offered; - uint32 *needed = &r_u->needed; + uint32 *needed = &r_u->needed; uint32 *returned = &r_u->returned; /* that's an [in out] buffer */ @@ -6424,7 +6422,7 @@ NTSTATUS _spoolss_enumprintprocessors(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCESSO /**************************************************************************** enumprintprocdatatypes level 1. ****************************************************************************/ -static NTSTATUS enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PRINTPROCDATATYPE_1 *info_1=NULL; @@ -6448,14 +6446,14 @@ static NTSTATUS enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offere *returned=0; return WERR_INSUFFICIENT_BUFFER; } - else - return NT_STATUS_OK; + + return WERR_OK; } /**************************************************************************** ****************************************************************************/ -NTSTATUS _spoolss_enumprintprocdatatypes(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCDATATYPES *q_u, SPOOL_R_ENUMPRINTPROCDATATYPES *r_u) +WERROR _spoolss_enumprintprocdatatypes(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCDATATYPES *q_u, SPOOL_R_ENUMPRINTPROCDATATYPES *r_u) { /* UNISTR2 *name = &q_u->name; - notused. */ /* UNISTR2 *processor = &q_u->processor; - notused. */ @@ -6486,7 +6484,7 @@ NTSTATUS _spoolss_enumprintprocdatatypes(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCD enumprintmonitors level 1. ****************************************************************************/ -static NTSTATUS enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PRINTMONITOR_1 *info_1=NULL; @@ -6510,14 +6508,14 @@ static NTSTATUS enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, ui *returned=0; return WERR_INSUFFICIENT_BUFFER; } - else - return NT_STATUS_OK; + + return WERR_OK; } /**************************************************************************** enumprintmonitors level 2. ****************************************************************************/ -static NTSTATUS enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PRINTMONITOR_2 *info_2=NULL; @@ -6543,20 +6541,20 @@ static NTSTATUS enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, ui *returned=0; return WERR_INSUFFICIENT_BUFFER; } - else - return NT_STATUS_OK; + + return WERR_OK; } /**************************************************************************** ****************************************************************************/ -NTSTATUS _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS *q_u, SPOOL_R_ENUMPRINTMONITORS *r_u) +WERROR _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS *q_u, SPOOL_R_ENUMPRINTMONITORS *r_u) { /* UNISTR2 *name = &q_u->name; - notused. */ uint32 level = q_u->level; - NEW_BUFFER *buffer = NULL; + NEW_BUFFER *buffer = NULL; uint32 offered = q_u->offered; - uint32 *needed = &r_u->needed; + uint32 *needed = &r_u->needed; uint32 *returned = &r_u->returned; /* that's an [in out] buffer */ @@ -6587,7 +6585,7 @@ NTSTATUS _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS * /**************************************************************************** ****************************************************************************/ -static NTSTATUS getjob_level_1(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getjob_level_1(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { int i=0; BOOL found=False; @@ -6609,7 +6607,7 @@ static NTSTATUS getjob_level_1(print_queue_struct *queue, int count, int snum, u safe_free(queue); safe_free(info_1); /* I shoud reply something else ... I can't find the good one */ - return NT_STATUS_OK; + return WERR_OK; } fill_job_info_1(info_1, &(queue[i-1]), i, snum); @@ -6629,14 +6627,14 @@ static NTSTATUS getjob_level_1(print_queue_struct *queue, int count, int snum, u if (*needed > offered) return WERR_INSUFFICIENT_BUFFER; - else - return NT_STATUS_OK; + + return WERR_OK; } /**************************************************************************** ****************************************************************************/ -static NTSTATUS getjob_level_2(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getjob_level_2(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { int i=0; BOOL found=False; @@ -6661,7 +6659,7 @@ static NTSTATUS getjob_level_2(print_queue_struct *queue, int count, int snum, u safe_free(queue); safe_free(info_2); /* I shoud reply something else ... I can't find the good one */ - return NT_STATUS_OK; + return WERR_OK; } if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0) { @@ -6688,14 +6686,14 @@ static NTSTATUS getjob_level_2(print_queue_struct *queue, int count, int snum, u if (*needed > offered) return WERR_INSUFFICIENT_BUFFER; - else - return NT_STATUS_OK; + + return WERR_OK; } /**************************************************************************** ****************************************************************************/ -NTSTATUS _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_u) +WERROR _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_u) { POLICY_HND *handle = &q_u->handle; uint32 jobid = q_u->jobid; @@ -6720,7 +6718,7 @@ NTSTATUS _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB * *needed=0; if (!get_printer_snum(p, handle, &snum)) - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; count = print_queue_status(snum, &queue, &prt_status); -- cgit From 19fea3242cf6234786b6cbb60631e0071f31ff9f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 4 Sep 2001 07:13:01 +0000 Subject: the next stage in the NTSTATUS/WERROR change. smbd and nmbd now compile, but the client code still needs some work (This used to be commit dcd6e735f709a9231860ceb9682db40ff26c9a66) --- source3/rpc_server/srv_spoolss_nt.c | 203 +++++++++++++++++++----------------- 1 file changed, 107 insertions(+), 96 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 80c809047c..c12df62913 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -160,7 +160,7 @@ static void free_spool_notify_option(SPOOL_NOTIFY_OPTION **pp) static void srv_spoolss_replycloseprinter(POLICY_HND *handle) { - NTSTATUS status; + WERROR status; /* weird if the test succeds !!! */ if (smb_connections==0) { @@ -270,18 +270,18 @@ static BOOL close_printer_handle(pipes_struct *p, POLICY_HND *hnd) /**************************************************************************** delete a printer given a handle ****************************************************************************/ -static NTSTATUS delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) +static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) { Printer_entry *Printer = find_printer_index_by_hnd(p, hnd); if (!Printer) { DEBUG(0,("delete_printer_handle: Invalid handle (%s)\n", OUR_HANDLE(hnd))); - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; } if (del_a_printer(Printer->dev.handlename) != 0) { DEBUG(3,("Error deleting printer %s\n", Printer->dev.handlename)); - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; } /* Check calling user has permission to delete printer. Note that @@ -291,7 +291,7 @@ static NTSTATUS delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) if (!print_access_check(NULL, -1, PRINTER_ACCESS_ADMINISTER)) { DEBUG(3, ("printer delete denied by security descriptor\n")); - return NT_STATUS_ACCESS_DENIED; + return WERR_ACCESS_DENIED; } if (*lp_deleteprinter_cmd()) { @@ -308,7 +308,7 @@ static NTSTATUS delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) DEBUG(10,("Running [%s]\n", command)); ret = smbrun(command, NULL); if (ret != 0) { - return NT_STATUS_INVALID_HANDLE; /* What to return here? */ + return WERR_BADFID; /* What to return here? */ } DEBUGADD(10,("returned [%d]\n", ret)); @@ -317,12 +317,12 @@ static NTSTATUS delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) if ( ( i = lp_servicenumber( Printer->dev.handlename ) ) >= 0 ) { lp_killservice( i ); - return NT_STATUS_OK; + return WERR_OK; } else - return NT_STATUS_ACCESS_DENIED; + return WERR_ACCESS_DENIED; } - return NT_STATUS_OK; + return WERR_OK; } /**************************************************************************** @@ -618,7 +618,7 @@ static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size) static void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size_t len) { fstring printer; - NTSTATUS status; + WERROR status; struct pipes_struct *p; struct policy *pol; struct handle_list *hl; @@ -706,10 +706,10 @@ static BOOL srv_spoolss_sendnotify(pipes_struct *p, POLICY_HND *handle) * called from the spoolss dispatcher ********************************************************************/ -NTSTATUS _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, SPOOL_R_OPEN_PRINTER_EX *r_u) +WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, SPOOL_R_OPEN_PRINTER_EX *r_u) { #if 0 - uint32 result = NT_STATUS_OK; + WERROR result = WERR_OK; #endif UNISTR2 *printername = NULL; @@ -726,7 +726,7 @@ NTSTATUS _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u printername = &q_u->printername; if (printername == NULL) - return NT_STATUS_OBJECT_NAME_INVALID; + return WERR_INVALID_PRINTER_NAME; /* some sanity check because you can open a printer or a print server */ /* aka: \\server\printer or \\server */ @@ -735,7 +735,7 @@ NTSTATUS _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u DEBUGADD(3,("checking name: %s\n",name)); if (!open_printer_hnd(p, handle, name)) - return NT_STATUS_OBJECT_NAME_INVALID; + return WERR_INVALID_PRINTER_NAME; /* if (printer_default->datatype_ptr != NULL) @@ -749,7 +749,7 @@ NTSTATUS _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u if (!set_printer_hnd_accesstype(p, handle, printer_default->access_required)) { close_printer_handle(p, handle); - return NT_STATUS_ACCESS_DENIED; + return WERR_ACCESS_DENIED; } /* @@ -779,7 +779,7 @@ NTSTATUS _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u if (handle_is_printserver(p, handle)) { if (printer_default->access_required == 0) { - return NT_STATUS_OK; + return WERR_OK; } else if ((printer_default->access_required & SERVER_ACCESS_ADMINISTER ) == SERVER_ACCESS_ADMINISTER) { @@ -788,14 +788,14 @@ NTSTATUS _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u if (!lp_ms_add_printer_wizard()) { close_printer_handle(p, handle); - return NT_STATUS_ACCESS_DENIED; + return WERR_ACCESS_DENIED; } else if (user.uid == 0 || user_in_list(uidtoname(user.uid), lp_printer_admin(snum))) { - return NT_STATUS_OK; + return WERR_OK; } else { close_printer_handle(p, handle); - return NT_STATUS_ACCESS_DENIED; + return WERR_ACCESS_DENIED; } } } @@ -805,7 +805,7 @@ NTSTATUS _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u doesn't have print permission. */ if (!get_printer_snum(p, handle, &snum)) - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; /* map an empty access mask to the minimum access mask */ if (printer_default->access_required == 0x0) @@ -826,7 +826,7 @@ NTSTATUS _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u if (!print_access_check(&user, snum, printer_default->access_required)) { DEBUG(3, ("access DENIED for printer open\n")); close_printer_handle(p, handle); - return NT_STATUS_ACCESS_DENIED; + return WERR_ACCESS_DENIED; } /* @@ -905,7 +905,7 @@ NTSTATUS _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u #endif } - return NT_STATUS_OK; + return WERR_OK; } /**************************************************************************** @@ -1021,27 +1021,27 @@ BOOL convert_devicemode(char *printername, const DEVICEMODE *devmode, * _spoolss_enddocprinter_internal. ********************************************************************/ -static NTSTATUS _spoolss_enddocprinter_internal(pipes_struct *p, POLICY_HND *handle) +static WERROR _spoolss_enddocprinter_internal(pipes_struct *p, POLICY_HND *handle) { Printer_entry *Printer=find_printer_index_by_hnd(p, handle); if (!Printer) { DEBUG(0,("_spoolss_enddocprinter_internal: Invalid handle (%s)\n", OUR_HANDLE(handle))); - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; } Printer->document_started=False; print_job_end(Printer->jobid,True); /* error codes unhandled so far ... */ - return NT_STATUS_OK; + return WERR_OK; } /******************************************************************** * api_spoolss_closeprinter ********************************************************************/ -NTSTATUS _spoolss_closeprinter(pipes_struct *p, SPOOL_Q_CLOSEPRINTER *q_u, SPOOL_R_CLOSEPRINTER *r_u) +WERROR _spoolss_closeprinter(pipes_struct *p, SPOOL_Q_CLOSEPRINTER *q_u, SPOOL_R_CLOSEPRINTER *r_u) { POLICY_HND *handle = &q_u->handle; @@ -1053,9 +1053,9 @@ NTSTATUS _spoolss_closeprinter(pipes_struct *p, SPOOL_Q_CLOSEPRINTER *q_u, SPOOL memcpy(&r_u->handle, &q_u->handle, sizeof(r_u->handle)); if (!close_printer_handle(p, handle)) - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; - return NT_STATUS_OK; + return WERR_OK; } /******************************************************************** @@ -1063,11 +1063,11 @@ NTSTATUS _spoolss_closeprinter(pipes_struct *p, SPOOL_Q_CLOSEPRINTER *q_u, SPOOL ********************************************************************/ -NTSTATUS _spoolss_deleteprinter(pipes_struct *p, SPOOL_Q_DELETEPRINTER *q_u, SPOOL_R_DELETEPRINTER *r_u) +WERROR _spoolss_deleteprinter(pipes_struct *p, SPOOL_Q_DELETEPRINTER *q_u, SPOOL_R_DELETEPRINTER *r_u) { POLICY_HND *handle = &q_u->handle; Printer_entry *Printer=find_printer_index_by_hnd(p, handle); - NTSTATUS result; + WERROR result; if (Printer && Printer->document_started) _spoolss_enddocprinter_internal(p, handle); /* print job was not closed */ @@ -1076,7 +1076,7 @@ NTSTATUS _spoolss_deleteprinter(pipes_struct *p, SPOOL_Q_DELETEPRINTER *q_u, SPO result = delete_printer_handle(p, handle); - if (NT_STATUS_IS_OK(result)) { + if (W_ERROR_IS_OK(result)) { srv_spoolss_sendnotify(p, handle); } @@ -1124,7 +1124,7 @@ static int get_version_id (char * arch) * --jerry ********************************************************************/ -NTSTATUS _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER *q_u, +WERROR _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER *q_u, SPOOL_R_DELETEPRINTERDRIVER *r_u) { fstring driver; @@ -1137,18 +1137,18 @@ NTSTATUS _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIV /* check that we have a valid driver name first */ if ((version=get_version_id(arch)) == -1) { - return NT_STATUS_REVISION_MISMATCH; + return WERR_INVALID_ENVIRONMENT; } ZERO_STRUCT(info); if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, driver, arch, version))) { - return NT_STATUS_DRIVER_ORDINAL_NOT_FOUND; + return WERR_UNKNOWN_PRINTER_DRIVER; } if (printer_driver_in_use(arch, driver)) { - return NT_STATUS_NETWORK_BUSY; + return WERR_PRINTER_DRIVER_IN_USE; } return delete_printer_driver(info.info_3); @@ -1293,7 +1293,7 @@ static BOOL getprinterdata_printer(pipes_struct *p, TALLOC_CTX *ctx, POLICY_HND * spoolss_getprinterdata ********************************************************************/ -NTSTATUS _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPOOL_R_GETPRINTERDATA *r_u) +WERROR _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPOOL_R_GETPRINTERDATA *r_u) { POLICY_HND *handle = &q_u->handle; UNISTR2 *valuename = &q_u->valuename; @@ -1324,9 +1324,9 @@ NTSTATUS _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, S if (!Printer) { if((*data=(uint8 *)malloc(4*sizeof(uint8))) == NULL) - return NT_STATUS_NO_MEMORY; + return WERR_NOMEM; DEBUG(0,("_spoolss_getprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; } unistr2_to_ascii(value, valuename, sizeof(value)-1); @@ -1341,18 +1341,18 @@ NTSTATUS _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, S /* reply this param doesn't exist */ if (*out_size) { if((*data=(uint8 *)talloc_zero(p->mem_ctx, *out_size*sizeof(uint8))) == NULL) - return NT_STATUS_NO_MEMORY; + return WERR_NOMEM; } else { *data = NULL; } - return NT_STATUS_INVALID_PARAMETER; + return WERR_INVALID_PARAM; } if (*needed > *out_size) - return STATUS_MORE_ENTRIES; + return WERR_STATUS_MORE_ENTRIES; else { - return NT_STATUS_OK; + return WERR_OK; } } @@ -1361,7 +1361,7 @@ NTSTATUS _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, S ****************************************************************************/ static BOOL srv_spoolss_replyopenprinter(char *printer, uint32 localprinter, uint32 type, POLICY_HND *handle) { - NTSTATUS status; + WERROR status; /* * If it's the first connection, contact the client @@ -1398,7 +1398,7 @@ static BOOL srv_spoolss_replyopenprinter(char *printer, uint32 localprinter, uin * called from api_spoolss_rffpcnex ********************************************************************/ -NTSTATUS _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNEX *r_u) +WERROR _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNEX *r_u) { POLICY_HND *handle = &q_u->handle; uint32 flags = q_u->flags; @@ -1413,7 +1413,7 @@ NTSTATUS _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPC if (!Printer) { DEBUG(0,("_spoolss_rffpcnex: Invalid handle (%s).\n", OUR_HANDLE(handle))); - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; } Printer->notify.flags=flags; @@ -1433,7 +1433,7 @@ NTSTATUS _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPC &Printer->notify.client_hnd)) Printer->notify.client_connected=True; - return NT_STATUS_OK; + return WERR_OK; } /******************************************************************* @@ -3906,7 +3906,7 @@ WERROR _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_ /**************************************************************************** ****************************************************************************/ -NTSTATUS _spoolss_startpageprinter(pipes_struct *p, SPOOL_Q_STARTPAGEPRINTER *q_u, SPOOL_R_STARTPAGEPRINTER *r_u) +WERROR _spoolss_startpageprinter(pipes_struct *p, SPOOL_Q_STARTPAGEPRINTER *q_u, SPOOL_R_STARTPAGEPRINTER *r_u) { POLICY_HND *handle = &q_u->handle; @@ -3914,17 +3914,17 @@ NTSTATUS _spoolss_startpageprinter(pipes_struct *p, SPOOL_Q_STARTPAGEPRINTER *q_ if (Printer) { Printer->page_started=True; - return NT_STATUS_OK; + return WERR_OK; } DEBUG(3,("Error in startpageprinter printer handle\n")); - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; } /**************************************************************************** ****************************************************************************/ -NTSTATUS _spoolss_endpageprinter(pipes_struct *p, SPOOL_Q_ENDPAGEPRINTER *q_u, SPOOL_R_ENDPAGEPRINTER *r_u) +WERROR _spoolss_endpageprinter(pipes_struct *p, SPOOL_Q_ENDPAGEPRINTER *q_u, SPOOL_R_ENDPAGEPRINTER *r_u) { POLICY_HND *handle = &q_u->handle; @@ -3932,12 +3932,12 @@ NTSTATUS _spoolss_endpageprinter(pipes_struct *p, SPOOL_Q_ENDPAGEPRINTER *q_u, S if (!Printer) { DEBUG(0,("_spoolss_endpageprinter: Invalid handle (%s).\n",OUR_HANDLE(handle))); - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; } Printer->page_started=False; - return NT_STATUS_OK; + return WERR_OK; } /******************************************************************** @@ -4015,7 +4015,7 @@ WERROR _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, S * ********************************************************************/ -NTSTATUS _spoolss_enddocprinter(pipes_struct *p, SPOOL_Q_ENDDOCPRINTER *q_u, SPOOL_R_ENDDOCPRINTER *r_u) +WERROR _spoolss_enddocprinter(pipes_struct *p, SPOOL_Q_ENDDOCPRINTER *q_u, SPOOL_R_ENDDOCPRINTER *r_u) { POLICY_HND *handle = &q_u->handle; @@ -4025,7 +4025,7 @@ NTSTATUS _spoolss_enddocprinter(pipes_struct *p, SPOOL_Q_ENDDOCPRINTER *q_u, SPO /**************************************************************************** ****************************************************************************/ -NTSTATUS _spoolss_writeprinter(pipes_struct *p, SPOOL_Q_WRITEPRINTER *q_u, SPOOL_R_WRITEPRINTER *r_u) +WERROR _spoolss_writeprinter(pipes_struct *p, SPOOL_Q_WRITEPRINTER *q_u, SPOOL_R_WRITEPRINTER *r_u) { POLICY_HND *handle = &q_u->handle; uint32 buffer_size = q_u->buffer_size; @@ -4037,7 +4037,7 @@ NTSTATUS _spoolss_writeprinter(pipes_struct *p, SPOOL_Q_WRITEPRINTER *q_u, SPOOL if (!Printer) { DEBUG(0,("_spoolss_writeprinter: Invalid handle (%s)\n",OUR_HANDLE(handle))); r_u->buffer_written = q_u->buffer_size2; - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; } (*buffer_written) = print_job_write(Printer->jobid, (char *)buffer, buffer_size); @@ -4045,7 +4045,7 @@ NTSTATUS _spoolss_writeprinter(pipes_struct *p, SPOOL_Q_WRITEPRINTER *q_u, SPOOL r_u->buffer_written = q_u->buffer_size2; - return NT_STATUS_OK; + return WERR_OK; } /******************************************************************** @@ -4608,19 +4608,15 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, /* Call addprinter hook */ - if (*lp_addprinter_cmd() ) - if ( !add_printer_hook(printer) ) { + if (*lp_addprinter_cmd()) { + if (!add_printer_hook(printer)) { result = WERR_ACCESS_DENIED; goto done; } + } /* Update printer info */ - - if (add_a_printer(*printer, 2)!=0) { - /* I don't really know what to return here !!! */ - result = WERR_ACCESS_DENIED; - goto done; - } + result = add_a_printer(*printer, 2); done: free_a_printer(&printer, 2); @@ -4667,7 +4663,7 @@ WERROR _spoolss_setprinter(pipes_struct *p, SPOOL_Q_SETPRINTER *q_u, SPOOL_R_SET /**************************************************************************** ****************************************************************************/ -NTSTATUS _spoolss_fcpn(pipes_struct *p, SPOOL_Q_FCPN *q_u, SPOOL_R_FCPN *r_u) +WERROR _spoolss_fcpn(pipes_struct *p, SPOOL_Q_FCPN *q_u, SPOOL_R_FCPN *r_u) { POLICY_HND *handle = &q_u->handle; @@ -4675,7 +4671,7 @@ NTSTATUS _spoolss_fcpn(pipes_struct *p, SPOOL_Q_FCPN *q_u, SPOOL_R_FCPN *r_u) if (!Printer) { DEBUG(0,("_spoolss_fcpn: Invalid handle (%s)\n", OUR_HANDLE(handle))); - return NT_STATUS_INVALID_HANDLE; + return WERR_BADFID; } if (Printer->notify.client_connected==True) @@ -4689,7 +4685,7 @@ NTSTATUS _spoolss_fcpn(pipes_struct *p, SPOOL_Q_FCPN *q_u, SPOOL_R_FCPN *r_u) free_spool_notify_option(&Printer->notify.option); Printer->notify.client_connected=False; - return NT_STATUS_OK; + return WERR_OK; } /**************************************************************************** @@ -4840,6 +4836,7 @@ static WERROR enumjobs_level2(print_queue_struct *queue, int snum, NT_PRINTER_INFO_LEVEL *ntprinter = NULL; JOB_INFO_2 *info; int i; + WERROR result; info=(JOB_INFO_2 *)malloc(*returned*sizeof(JOB_INFO_2)); if (info==NULL) { @@ -4847,9 +4844,10 @@ static WERROR enumjobs_level2(print_queue_struct *queue, int snum, return WERR_NOMEM; } - if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0) { + result = get_a_printer(&ntprinter, 2, lp_servicename(snum)); + if (!W_ERROR_IS_OK(result)) { *returned = 0; - return WERR_NOMEM; + return result; } for (i=0; i<*returned; i++) @@ -4978,18 +4976,18 @@ WERROR _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u case JOB_CONTROL_CANCEL: case JOB_CONTROL_DELETE: if (print_job_delete(&user, jobid, &errcode)) { - errcode = 0; + errcode = WERR_OK; } break; case JOB_CONTROL_PAUSE: if (print_job_pause(&user, jobid, &errcode)) { - errcode = 0; + errcode = WERR_OK; } break; case JOB_CONTROL_RESTART: case JOB_CONTROL_RESUME: if (print_job_resume(&user, jobid, &errcode)) { - errcode = 0; + errcode = WERR_OK; } break; default: @@ -5034,10 +5032,12 @@ static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture } for (i=0; iname; nt_forms_struct tmpForm; int count=0; - WERROR ret = 0; + WERROR ret = WERR_OK; nt_forms_struct *list=NULL; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); @@ -6308,7 +6317,7 @@ WERROR _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE } count = get_ntforms(&list); - if(!delete_a_form(&list, form_name, &count, &ret)) + if (!delete_a_form(&list, form_name, &count, &ret)) return WERR_INVALID_PARAM; safe_free(list); @@ -6640,6 +6649,7 @@ static WERROR getjob_level_2(print_queue_struct *queue, int count, int snum, uin BOOL found=False; JOB_INFO_2 *info_2; NT_PRINTER_INFO_LEVEL *ntprinter = NULL; + WERROR ret; info_2=(JOB_INFO_2 *)malloc(sizeof(JOB_INFO_2)); @@ -6662,9 +6672,10 @@ static WERROR getjob_level_2(print_queue_struct *queue, int count, int snum, uin return WERR_OK; } - if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0) { + ret = get_a_printer(&ntprinter, 2, lp_servicename(snum)); + if (!W_ERROR_IS_OK(ret)) { safe_free(queue); - return WERR_NOMEM; + return ret; } fill_job_info_2(info_2, &(queue[i-1]), i, snum, ntprinter); -- cgit From b04933dfbb891532d08e7de42bdcf2eb9186a018 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 4 Sep 2001 11:18:50 +0000 Subject: a fix for fussy compilers (This used to be commit 78f437b5073207606b23be42960e2b10f785a148) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index c12df62913..514aa5b9dd 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3214,7 +3214,7 @@ WERROR _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOOL_ return enumprinters_level5(flags, name, buffer, offered, needed, returned); case 3: case 4: - default: + break; } return WERR_UNKNOWN_LEVEL; } -- cgit From c113b5196f28a9af948e8104f543615c0165fd78 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 10 Sep 2001 19:29:00 +0000 Subject: merge from APPLIANCE_HEAD (This used to be commit 55bd514c4576a273dac1ac5c37207a96b41f6572) --- source3/rpc_server/srv_spoolss_nt.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 514aa5b9dd..2a412ccc98 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6154,11 +6154,29 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP convert_specific_param(¶m, value , type, data, real_len); - /* Check if we are making any changes or not. Return true if - nothing is actually changing. */ - ZERO_STRUCT(old_param); + /* + * Access check : NT returns "access denied" if you make a + * SetPrinterData call without the necessary privildge. + * we were originally returning OK if nothing changed + * which made Win2k issue **a lot** of SetPrinterData + * when connecting to a printer --jerry + */ + + if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { + DEBUG(3, ("security descriptor change denied by existing " + "security descriptor\n")); + status = ERROR_ACCESS_DENIED; + goto done; + } + + + /* Check if we are making any changes or not. Return true if + nothing is actually changing. This is not needed anymore but + has been left in as an optimization to keep from from + writing to disk as often --jerry */ + if (get_specific_param(*printer, 2, param->value, &old_param.data, &old_param.type, (uint32 *)&old_param.data_len)) { @@ -6173,15 +6191,6 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP } } - /* Access check */ - - if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { - DEBUG(3, ("security descriptor change denied by existing " - "security descriptor\n")); - status = WERR_ACCESS_DENIED; - goto done; - } - unlink_specific_param_if_exist(printer->info_2, param); /* -- cgit From cae476a1a2080b2267b7d2efe81b2e80b45a0031 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 10 Sep 2001 19:30:34 +0000 Subject: cut-n-paste error (This used to be commit b2ed211df0cad2013fd8ff67f48bf73962cc1d39) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 2a412ccc98..cffdfb0ff9 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6167,7 +6167,7 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { DEBUG(3, ("security descriptor change denied by existing " "security descriptor\n")); - status = ERROR_ACCESS_DENIED; + status = WERR_ACCESS_DENIED; goto done; } -- cgit From bd7595ec37ab9c2d4290893a99e99856dca0c5cb Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 14 Sep 2001 15:22:49 +0000 Subject: merge from appliance_head (This used to be commit f70b1707e42b3f7aaa38cc5637fcc5cbcdd5a26a) --- source3/rpc_server/srv_spoolss_nt.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index cffdfb0ff9..5fed46deec 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6148,12 +6148,6 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP if (!get_printer_snum(p,handle, &snum)) return WERR_BADFID; - status = get_a_printer(&printer, 2, lp_servicename(snum)); - if (!W_ERROR_IS_OK(status)) - return status; - - convert_specific_param(¶m, value , type, data, real_len); - ZERO_STRUCT(old_param); /* @@ -6177,6 +6171,12 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP has been left in as an optimization to keep from from writing to disk as often --jerry */ + status = get_a_printer(&printer, 2, lp_servicename(snum)); + if (!W_ERROR_IS_OK(status)) + return status; + + convert_specific_param(¶m, value , type, data, real_len); + if (get_specific_param(*printer, 2, param->value, &old_param.data, &old_param.type, (uint32 *)&old_param.data_len)) { -- cgit From 87945989c0383bd012be7ab8bc5920b6d03fa105 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 17 Sep 2001 10:26:23 +0000 Subject: move to SAFE_FREE() (This used to be commit 5ceecc7bef71b455ba7c4efd9928e2433dccc961) --- source3/rpc_server/srv_spoolss_nt.c | 222 +++++++++++++++++------------------- 1 file changed, 106 insertions(+), 116 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 5fed46deec..118a2d64c9 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -141,17 +141,11 @@ static int nt_printq_status(int v) static void free_spool_notify_option(SPOOL_NOTIFY_OPTION **pp) { - SPOOL_NOTIFY_OPTION *sp = *pp; - - *pp = NULL; - - if (!sp) + if (*pp == NULL) return; - if (sp->ctr.type) - safe_free(sp->ctr.type); - - free(sp); + SAFE_FREE((*pp)->ctr.type); + SAFE_FREE(*pp); } /*************************************************************************** @@ -201,7 +195,7 @@ static void free_printer_entry(void *ptr) Printer->notify.option=NULL; Printer->notify.client_connected=False; - safe_free(Printer); + SAFE_FREE(Printer); } /**************************************************************************** @@ -225,7 +219,7 @@ SPOOL_NOTIFY_OPTION *dup_spool_notify_option(SPOOL_NOTIFY_OPTION *sp) new_sp->ctr.type = (SPOOL_NOTIFY_OPTION_TYPE *)memdup(sp->ctr.type, sizeof(SPOOL_NOTIFY_OPTION_TYPE) * sp->ctr.count); if (!new_sp->ctr.type) { - safe_free(new_sp); + SAFE_FREE(new_sp); return NULL; } } @@ -541,7 +535,7 @@ static BOOL open_printer_hnd(pipes_struct *p, POLICY_HND *hnd, char *name) new_printer->notify.option=NULL; if (!create_policy_hnd(p, hnd, free_printer_entry, new_printer)) { - safe_free(new_printer); + SAFE_FREE(new_printer); return False; } @@ -1005,7 +999,7 @@ BOOL convert_devicemode(char *printername, const DEVICEMODE *devmode, */ if ((devmode->driverextra != 0) && (devmode->private != NULL)) { - safe_free(nt_devmode->private); + SAFE_FREE(nt_devmode->private); nt_devmode->driverextra=devmode->driverextra; if((nt_devmode->private=(uint8 *)malloc(nt_devmode->driverextra * sizeof(uint8))) == NULL) return False; @@ -1284,7 +1278,7 @@ static BOOL getprinterdata_printer(pipes_struct *p, TALLOC_CTX *ctx, POLICY_HND DEBUG(5,("getprinterdata_printer:copy done\n")); - safe_free(idata); + SAFE_FREE(idata); return True; } @@ -1840,7 +1834,7 @@ static void spoolss_notify_status(int snum, memset(&status, 0, sizeof(status)); print_queue_status(snum, &q, &status); data->notify_data.value[0]=(uint32) status.status; - safe_free(q); + SAFE_FREE(q); } /******************************************************************* @@ -1857,7 +1851,7 @@ static void spoolss_notify_cjobs(int snum, memset(&status, 0, sizeof(status)); data->notify_data.value[0] = print_queue_status(snum, &q, &status); - safe_free(q); + SAFE_FREE(q); } /******************************************************************* @@ -2445,7 +2439,7 @@ static WERROR printer_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY free_a_printer(&printer, 2); done: - safe_free(queue); + SAFE_FREE(queue); break; } } @@ -2624,7 +2618,7 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum) printer->unknown28 = 0; printer->unknown29 = 0; - safe_free(queue); + SAFE_FREE(queue); free_a_printer(&ntprinter,2); return (True); } @@ -2674,10 +2668,8 @@ static void free_dev_mode(DEVICEMODE *dev) if (dev == NULL) return; - if (dev->private) - safe_free(dev->private); - - safe_free(dev); + SAFE_FREE(dev->private); + SAFE_FREE(dev); } /**************************************************************************** @@ -2828,7 +2820,7 @@ static BOOL construct_printer_info_2(PRINTER_INFO_2 *printer, int snum) } free_a_printer(&ntprinter, 2); - safe_free(queue); + SAFE_FREE(queue); return True; } @@ -2906,7 +2898,7 @@ static WERROR enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 if (construct_printer_info_1(flags, ¤t_prt, snum)) { if((tp=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_1))) == NULL) { DEBUG(0,("enum_all_printers_info_1: failed to enlarge printers buffer!\n")); - safe_free(printers); + SAFE_FREE(printers); *returned=0; return WERR_NOMEM; } @@ -2930,7 +2922,7 @@ static WERROR enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 smb_io_printer_info_1("", buffer, &printers[i], 0); /* clear memory */ - safe_free(printers); + SAFE_FREE(printers); if (*needed > offered) { *returned=0; @@ -3004,7 +2996,7 @@ static WERROR enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, *needed += spoolss_size_printer_info_1(printer); if (!alloc_buffer_size(buffer, *needed)) { - safe_free(printer); + SAFE_FREE(printer); return WERR_INSUFFICIENT_BUFFER; } @@ -3012,7 +3004,7 @@ static WERROR enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, smb_io_printer_info_1("", buffer, printer, 0); /* clear memory */ - safe_free(printer); + SAFE_FREE(printer); if (*needed > offered) { *returned=0; @@ -3054,7 +3046,7 @@ static WERROR enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint3 if (construct_printer_info_2(¤t_prt, snum)) { if((tp=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_2))) == NULL) { DEBUG(0,("enum_all_printers_info_2: failed to enlarge printers buffer!\n")); - safe_free(printers); + SAFE_FREE(printers); *returned = 0; return WERR_NOMEM; } @@ -3074,7 +3066,7 @@ static WERROR enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint3 for (i=0; i<*returned; i++) { free_devmode(printers[i].devmode); } - safe_free(printers); + SAFE_FREE(printers); return WERR_INSUFFICIENT_BUFFER; } @@ -3086,7 +3078,7 @@ static WERROR enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint3 for (i=0; i<*returned; i++) { free_devmode(printers[i].devmode); } - safe_free(printers); + SAFE_FREE(printers); if (*needed > offered) { *returned=0; @@ -3234,7 +3226,7 @@ static WERROR getprinter_level_0(int snum, NEW_BUFFER *buffer, uint32 offered, u *needed += spoolss_size_printer_info_0(printer); if (!alloc_buffer_size(buffer, *needed)) { - safe_free(printer); + SAFE_FREE(printer); return WERR_INSUFFICIENT_BUFFER; } @@ -3242,7 +3234,7 @@ static WERROR getprinter_level_0(int snum, NEW_BUFFER *buffer, uint32 offered, u smb_io_printer_info_0("", buffer, printer, 0); /* clear memory */ - safe_free(printer); + SAFE_FREE(printer); if (*needed > offered) { return WERR_INSUFFICIENT_BUFFER; @@ -3266,7 +3258,7 @@ static WERROR getprinter_level_1(int snum, NEW_BUFFER *buffer, uint32 offered, u *needed += spoolss_size_printer_info_1(printer); if (!alloc_buffer_size(buffer, *needed)) { - safe_free(printer); + SAFE_FREE(printer); return WERR_INSUFFICIENT_BUFFER; } @@ -3274,7 +3266,7 @@ static WERROR getprinter_level_1(int snum, NEW_BUFFER *buffer, uint32 offered, u smb_io_printer_info_1("", buffer, printer, 0); /* clear memory */ - safe_free(printer); + SAFE_FREE(printer); if (*needed > offered) { return WERR_INSUFFICIENT_BUFFER; @@ -3704,7 +3696,7 @@ static WERROR construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, fst static void free_printer_driver_info_3(DRIVER_INFO_3 *info) { - safe_free(info->dependentfiles); + SAFE_FREE(info->dependentfiles); } /**************************************************************************** @@ -3712,7 +3704,7 @@ static void free_printer_driver_info_3(DRIVER_INFO_3 *info) static void free_printer_driver_info_6(DRIVER_INFO_6 *info) { - safe_free(info->dependentfiles); + SAFE_FREE(info->dependentfiles); } @@ -3728,7 +3720,7 @@ static WERROR getprinterdriver2_level1(fstring servername, fstring architecture, status=construct_printer_driver_info_1(info, snum, servername, architecture, version); if (!W_ERROR_IS_OK(status)) { - safe_free(info); + SAFE_FREE(info); return status; } @@ -3736,7 +3728,7 @@ static WERROR getprinterdriver2_level1(fstring servername, fstring architecture, *needed += spoolss_size_printer_driver_info_1(info); if (!alloc_buffer_size(buffer, *needed)) { - safe_free(info); + SAFE_FREE(info); return WERR_INSUFFICIENT_BUFFER; } @@ -3744,7 +3736,7 @@ static WERROR getprinterdriver2_level1(fstring servername, fstring architecture, smb_io_printer_driver_info_1("", buffer, info, 0); /* clear memory */ - safe_free(info); + SAFE_FREE(info); if (*needed > offered) return WERR_INSUFFICIENT_BUFFER; @@ -3764,7 +3756,7 @@ static WERROR getprinterdriver2_level2(fstring servername, fstring architecture, status=construct_printer_driver_info_2(info, snum, servername, architecture, version); if (!W_ERROR_IS_OK(status)) { - safe_free(info); + SAFE_FREE(info); return status; } @@ -3772,7 +3764,7 @@ static WERROR getprinterdriver2_level2(fstring servername, fstring architecture, *needed += spoolss_size_printer_driver_info_2(info); if (!alloc_buffer_size(buffer, *needed)) { - safe_free(info); + SAFE_FREE(info); return WERR_INSUFFICIENT_BUFFER; } @@ -3780,7 +3772,7 @@ static WERROR getprinterdriver2_level2(fstring servername, fstring architecture, smb_io_printer_driver_info_2("", buffer, info, 0); /* clear memory */ - safe_free(info); + SAFE_FREE(info); if (*needed > offered) return WERR_INSUFFICIENT_BUFFER; @@ -4792,7 +4784,7 @@ static WERROR enumjobs_level1(print_queue_struct *queue, int snum, info=(JOB_INFO_1 *)malloc(*returned*sizeof(JOB_INFO_1)); if (info==NULL) { - safe_free(queue); + SAFE_FREE(queue); *returned=0; return WERR_NOMEM; } @@ -4800,14 +4792,14 @@ static WERROR enumjobs_level1(print_queue_struct *queue, int snum, for (i=0; i<*returned; i++) fill_job_info_1(&info[i], &queue[i], i, snum); - safe_free(queue); + SAFE_FREE(queue); /* check the required size. */ for (i=0; i<*returned; i++) (*needed) += spoolss_size_job_info_1(&info[i]); if (!alloc_buffer_size(buffer, *needed)) { - safe_free(info); + SAFE_FREE(info); return WERR_INSUFFICIENT_BUFFER; } @@ -4816,7 +4808,7 @@ static WERROR enumjobs_level1(print_queue_struct *queue, int snum, smb_io_job_info_1("", buffer, &info[i], 0); /* clear memory */ - safe_free(info); + SAFE_FREE(info); if (*needed > offered) { *returned=0; @@ -4854,14 +4846,14 @@ static WERROR enumjobs_level2(print_queue_struct *queue, int snum, fill_job_info_2(&(info[i]), &queue[i], i, snum, ntprinter); free_a_printer(&ntprinter, 2); - safe_free(queue); + SAFE_FREE(queue); /* check the required size. */ for (i=0; i<*returned; i++) (*needed) += spoolss_size_job_info_2(&info[i]); if (!alloc_buffer_size(buffer, *needed)) { - safe_free(info); + SAFE_FREE(info); return WERR_INSUFFICIENT_BUFFER; } @@ -4873,7 +4865,7 @@ static WERROR enumjobs_level2(print_queue_struct *queue, int snum, for (i = 0; i < *returned; i++) free_job_info_2(&info[i]); - free(info); + SAFE_FREE(info); if (*needed > offered) { *returned=0; @@ -4920,7 +4912,7 @@ WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO DEBUGADD(4,("count:[%d], status:[%d], [%s]\n", *returned, prt_status.status, prt_status.message)); if (*returned == 0) { - safe_free(queue); + SAFE_FREE(queue); return WERR_OK; } @@ -4930,7 +4922,7 @@ WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO case 2: return enumjobs_level2(queue, snum, buffer, offered, needed, returned); default: - safe_free(queue); + SAFE_FREE(queue); *returned=0; return WERR_UNKNOWN_LEVEL; } @@ -5024,8 +5016,8 @@ static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture if(ndrivers != 0) { if((tdi1=(DRIVER_INFO_1 *)Realloc(driver_info_1, (*returned+ndrivers) * sizeof(DRIVER_INFO_1))) == NULL) { DEBUG(0,("enumprinterdrivers_level1: failed to enlarge driver info buffer!\n")); - safe_free(driver_info_1); - safe_free(list); + SAFE_FREE(driver_info_1); + SAFE_FREE(list); return WERR_NOMEM; } else driver_info_1 = tdi1; @@ -5038,7 +5030,7 @@ static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture status = get_a_printer_driver(&driver, 3, list[i], architecture, version); if (!W_ERROR_IS_OK(status)) { - safe_free(list); + SAFE_FREE(list); return status; } fill_printer_driver_info_1(&driver_info_1[*returned+i], driver, servername, architecture ); @@ -5046,7 +5038,7 @@ static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture } *returned+=ndrivers; - safe_free(list); + SAFE_FREE(list); } /* check the required size. */ @@ -5056,7 +5048,7 @@ static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture } if (!alloc_buffer_size(buffer, *needed)) { - safe_free(driver_info_1); + SAFE_FREE(driver_info_1); return WERR_INSUFFICIENT_BUFFER; } @@ -5066,7 +5058,7 @@ static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture smb_io_printer_driver_info_1("", buffer, &driver_info_1[i], 0); } - safe_free(driver_info_1); + SAFE_FREE(driver_info_1); if (*needed > offered) { *returned=0; @@ -5103,8 +5095,8 @@ static WERROR enumprinterdrivers_level2(fstring servername, fstring architecture if(ndrivers != 0) { if((tdi2=(DRIVER_INFO_2 *)Realloc(driver_info_2, (*returned+ndrivers) * sizeof(DRIVER_INFO_2))) == NULL) { DEBUG(0,("enumprinterdrivers_level2: failed to enlarge driver info buffer!\n")); - safe_free(driver_info_2); - safe_free(list); + SAFE_FREE(driver_info_2); + SAFE_FREE(list); return WERR_NOMEM; } else driver_info_2 = tdi2; @@ -5118,7 +5110,7 @@ static WERROR enumprinterdrivers_level2(fstring servername, fstring architecture status = get_a_printer_driver(&driver, 3, list[i], architecture, version); if (!W_ERROR_IS_OK(status)) { - safe_free(list); + SAFE_FREE(list); return status; } fill_printer_driver_info_2(&driver_info_2[*returned+i], driver, servername); @@ -5126,7 +5118,7 @@ static WERROR enumprinterdrivers_level2(fstring servername, fstring architecture } *returned+=ndrivers; - safe_free(list); + SAFE_FREE(list); } /* check the required size. */ @@ -5136,7 +5128,7 @@ static WERROR enumprinterdrivers_level2(fstring servername, fstring architecture } if (!alloc_buffer_size(buffer, *needed)) { - safe_free(driver_info_2); + SAFE_FREE(driver_info_2); return WERR_INSUFFICIENT_BUFFER; } @@ -5146,7 +5138,7 @@ static WERROR enumprinterdrivers_level2(fstring servername, fstring architecture smb_io_printer_driver_info_2("", buffer, &(driver_info_2[i]), 0); } - safe_free(driver_info_2); + SAFE_FREE(driver_info_2); if (*needed > offered) { *returned=0; @@ -5183,8 +5175,8 @@ static WERROR enumprinterdrivers_level3(fstring servername, fstring architecture if(ndrivers != 0) { if((tdi3=(DRIVER_INFO_3 *)Realloc(driver_info_3, (*returned+ndrivers) * sizeof(DRIVER_INFO_3))) == NULL) { DEBUG(0,("enumprinterdrivers_level3: failed to enlarge driver info buffer!\n")); - safe_free(driver_info_3); - safe_free(list); + SAFE_FREE(driver_info_3); + SAFE_FREE(list); return WERR_NOMEM; } else driver_info_3 = tdi3; @@ -5198,7 +5190,7 @@ static WERROR enumprinterdrivers_level3(fstring servername, fstring architecture status = get_a_printer_driver(&driver, 3, list[i], architecture, version); if (!W_ERROR_IS_OK(status)) { - safe_free(list); + SAFE_FREE(list); return status; } fill_printer_driver_info_3(&driver_info_3[*returned+i], driver, servername); @@ -5206,7 +5198,7 @@ static WERROR enumprinterdrivers_level3(fstring servername, fstring architecture } *returned+=ndrivers; - safe_free(list); + SAFE_FREE(list); } /* check the required size. */ @@ -5216,7 +5208,7 @@ static WERROR enumprinterdrivers_level3(fstring servername, fstring architecture } if (!alloc_buffer_size(buffer, *needed)) { - safe_free(driver_info_3); + SAFE_FREE(driver_info_3); return WERR_INSUFFICIENT_BUFFER; } @@ -5227,9 +5219,9 @@ static WERROR enumprinterdrivers_level3(fstring servername, fstring architecture } for (i=0; i<*returned; i++) - safe_free(driver_info_3[i].dependentfiles); + SAFE_FREE(driver_info_3[i].dependentfiles); - safe_free(driver_info_3); + SAFE_FREE(driver_info_3); if (*needed > offered) { *returned=0; @@ -5277,7 +5269,7 @@ WERROR _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS return enumprinterdrivers_level3(servername, architecture, buffer, offered, needed, returned); default: *returned=0; - safe_free(list); + SAFE_FREE(list); return WERR_UNKNOWN_LEVEL; } } @@ -5345,14 +5337,14 @@ WERROR _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMF fill_form_1(&forms_1[i], &builtinlist[i]); } - safe_free(builtinlist); + SAFE_FREE(builtinlist); for (; i<*numofforms; i++) { DEBUGADD(6,("Filling form number [%d]\n",i)); fill_form_1(&forms_1[i], &list[i-numbuiltinforms]); } - safe_free(list); + SAFE_FREE(list); /* check the required size. */ for (i=0; i offered) { *numofforms=0; @@ -5391,8 +5383,8 @@ WERROR _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMF return WERR_OK; default: - safe_free(list); - safe_free(builtinlist); + SAFE_FREE(list); + SAFE_FREE(builtinlist); return WERR_UNKNOWN_LEVEL; } @@ -5455,7 +5447,7 @@ WERROR _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * } } - safe_free(list); + SAFE_FREE(list); if (i == numofforms) { return WERR_BADFID; } @@ -5479,7 +5471,7 @@ WERROR _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * return WERR_OK; default: - safe_free(list); + SAFE_FREE(list); return WERR_UNKNOWN_LEVEL; } } @@ -5572,7 +5564,7 @@ static WERROR enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need } if (!alloc_buffer_size(buffer, *needed)) { - safe_free(ports); + SAFE_FREE(ports); return WERR_INSUFFICIENT_BUFFER; } @@ -5582,7 +5574,7 @@ static WERROR enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need smb_io_port_1("", buffer, &ports[i], 0); } - safe_free(ports); + SAFE_FREE(ports); if (*needed > offered) { *returned=0; @@ -5670,7 +5662,7 @@ static WERROR enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need } if (!alloc_buffer_size(buffer, *needed)) { - safe_free(ports); + SAFE_FREE(ports); return WERR_INSUFFICIENT_BUFFER; } @@ -5680,7 +5672,7 @@ static WERROR enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need smb_io_port_2("", buffer, &ports[i], 0); } - safe_free(ports); + SAFE_FREE(ports); if (*needed > offered) { *returned=0; @@ -5908,13 +5900,13 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen *needed += spoolss_size_driverdir_info_1(info); if (!alloc_buffer_size(buffer, *needed)) { - safe_free(info); + SAFE_FREE(info); return WERR_INSUFFICIENT_BUFFER; } smb_io_driverdir_1("", buffer, info, 0); - safe_free(info); + SAFE_FREE(info); if (*needed > offered) return WERR_INSUFFICIENT_BUFFER; @@ -6026,14 +6018,13 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S */ if (!get_specific_param_by_index(*printer, 2, idx, value, &data, &type, &data_len)) { - safe_free(data); + SAFE_FREE(data); free_a_printer(&printer, 2); return WERR_NO_MORE_ITEMS; } #endif - safe_free(data); - data = NULL; + SAFE_FREE(data); param_index=0; biggest_valuesize=0; @@ -6045,8 +6036,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize, biggest_datasize)); - safe_free(data); - data = NULL; + SAFE_FREE(data); param_index++; } @@ -6078,7 +6068,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S */ if (!get_specific_param_by_index(*printer, 2, idx, value, &data, &type, &data_len)) { - safe_free(data); + SAFE_FREE(data); free_a_printer(&printer, 2); return WERR_NO_MORE_ITEMS; } @@ -6096,7 +6086,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S *out_max_value_len=(in_value_len/sizeof(uint16)); if((*out_value=(uint16 *)talloc_zero(p->mem_ctx,in_value_len*sizeof(uint8))) == NULL) { - safe_free(data); + SAFE_FREE(data); return WERR_NOMEM; } @@ -6107,14 +6097,14 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S /* the data is counted in bytes */ *out_max_data_len=in_data_len; if((*data_out=(uint8 *)talloc_zero(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) { - safe_free(data); + SAFE_FREE(data); return WERR_NOMEM; } memcpy(*data_out, data, (size_t)data_len); *out_data_len=data_len; - safe_free(data); + SAFE_FREE(data); return WERR_OK; } @@ -6213,7 +6203,7 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP free_a_printer(&printer, 2); if (param) free_nt_printer_param(¶m); - safe_free(old_param.data); + SAFE_FREE(old_param.data); return status; } @@ -6295,7 +6285,7 @@ WERROR _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM return WERR_NOMEM; write_ntforms(&list, count); - safe_free(list); + SAFE_FREE(list); return WERR_OK; } @@ -6329,7 +6319,7 @@ WERROR _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE if (!delete_a_form(&list, form_name, &count, &ret)) return WERR_INVALID_PARAM; - safe_free(list); + SAFE_FREE(list); return ret; } @@ -6364,7 +6354,7 @@ WERROR _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM * update_a_form(&list, form, count); write_ntforms(&list, count); - safe_free(list); + SAFE_FREE(list); return WERR_OK; } @@ -6390,7 +6380,7 @@ static WERROR enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, ui smb_io_printprocessor_info_1("", buffer, info_1, 0); - safe_free(info_1); + SAFE_FREE(info_1); if (*needed > offered) { *returned=0; @@ -6458,7 +6448,7 @@ static WERROR enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered, smb_io_printprocdatatype_info_1("", buffer, info_1, 0); - safe_free(info_1); + SAFE_FREE(info_1); if (*needed > offered) { *returned=0; @@ -6520,7 +6510,7 @@ static WERROR enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, uint smb_io_printmonitor_info_1("", buffer, info_1, 0); - safe_free(info_1); + SAFE_FREE(info_1); if (*needed > offered) { *returned=0; @@ -6553,7 +6543,7 @@ static WERROR enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint smb_io_printmonitor_info_2("", buffer, info_2, 0); - safe_free(info_2); + SAFE_FREE(info_2); if (*needed > offered) { *returned=0; @@ -6612,7 +6602,7 @@ static WERROR getjob_level_1(print_queue_struct *queue, int count, int snum, uin info_1=(JOB_INFO_1 *)malloc(sizeof(JOB_INFO_1)); if (info_1 == NULL) { - safe_free(queue); + SAFE_FREE(queue); return WERR_NOMEM; } @@ -6622,26 +6612,26 @@ static WERROR getjob_level_1(print_queue_struct *queue, int count, int snum, uin } if (found==False) { - safe_free(queue); - safe_free(info_1); + SAFE_FREE(queue); + SAFE_FREE(info_1); /* I shoud reply something else ... I can't find the good one */ return WERR_OK; } fill_job_info_1(info_1, &(queue[i-1]), i, snum); - safe_free(queue); + SAFE_FREE(queue); *needed += spoolss_size_job_info_1(info_1); if (!alloc_buffer_size(buffer, *needed)) { - safe_free(info_1); + SAFE_FREE(info_1); return WERR_INSUFFICIENT_BUFFER; } smb_io_job_info_1("", buffer, info_1, 0); - safe_free(info_1); + SAFE_FREE(info_1); if (*needed > offered) return WERR_INSUFFICIENT_BUFFER; @@ -6665,7 +6655,7 @@ static WERROR getjob_level_2(print_queue_struct *queue, int count, int snum, uin ZERO_STRUCTP(info_2); if (info_2 == NULL) { - safe_free(queue); + SAFE_FREE(queue); return WERR_NOMEM; } @@ -6675,34 +6665,34 @@ static WERROR getjob_level_2(print_queue_struct *queue, int count, int snum, uin } if (found==False) { - safe_free(queue); - safe_free(info_2); + SAFE_FREE(queue); + SAFE_FREE(info_2); /* I shoud reply something else ... I can't find the good one */ return WERR_OK; } ret = get_a_printer(&ntprinter, 2, lp_servicename(snum)); if (!W_ERROR_IS_OK(ret)) { - safe_free(queue); + SAFE_FREE(queue); return ret; } fill_job_info_2(info_2, &(queue[i-1]), i, snum, ntprinter); free_a_printer(&ntprinter, 2); - safe_free(queue); + SAFE_FREE(queue); *needed += spoolss_size_job_info_2(info_2); if (!alloc_buffer_size(buffer, *needed)) { - safe_free(info_2); + SAFE_FREE(info_2); return WERR_INSUFFICIENT_BUFFER; } smb_io_job_info_2("", buffer, info_2, 0); free_job_info_2(info_2); - free(info_2); + SAFE_FREE(info_2); if (*needed > offered) return WERR_INSUFFICIENT_BUFFER; @@ -6751,7 +6741,7 @@ WERROR _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_ case 2: return getjob_level_2(queue, count, snum, jobid, buffer, offered, needed); default: - safe_free(queue); + SAFE_FREE(queue); return WERR_UNKNOWN_LEVEL; } } -- cgit From dc1fc3ee8ec2199bc73bb5d7ec711c6800f61d65 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 2 Oct 2001 04:29:50 +0000 Subject: Removed 'extern int DEBUGLEVEL' as it is now in the smb.h header. (This used to be commit 2d0922b0eabfdc0aaf1d0797482fef47ed7fde8e) --- source3/rpc_server/srv_spoolss_nt.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 118a2d64c9..b7ccce92d5 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -27,7 +27,6 @@ #include "includes.h" -extern int DEBUGLEVEL; extern pstring global_myname; #ifndef MAX_OPEN_PRINTER_EXS -- cgit From 375dcb9a8b9bd5774fb4a947b07fd4c9f78f8719 Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Tue, 16 Oct 2001 22:42:24 +0000 Subject: Fix some unicode string error. I'm wondering if I have to audit *all* the rpc code for that kind of trouble ;-) Oh well I've done it twice already, I can do it a third time ;-) J.F. (This used to be commit 6be8ea28f98d71e04de18b317f4d7a99b55209e8) --- source3/rpc_server/srv_spoolss_nt.c | 73 +++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 31 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index b7ccce92d5..0be836c944 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1444,9 +1444,9 @@ static void spoolss_notify_server_name(int snum, slprintf(temp_name, sizeof(temp_name)-1, "\\\\%s", global_myname); - len = rpcstr_push(temp, temp_name, sizeof(temp)-2, 0); + len = rpcstr_push(temp, temp_name, sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.length = len / 2; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1478,8 +1478,8 @@ static void spoolss_notify_printer_name(int snum, p++; } - len = rpcstr_push(temp, p, sizeof(temp)-2, 0); - data->notify_data.data.length = len / 2 - 1; + len = rpcstr_push(temp, p, sizeof(temp)-2, STR_TERMINATE); + data->notify_data.data.length = len / 2; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1502,9 +1502,9 @@ static void spoolss_notify_share_name(int snum, pstring temp; uint32 len; - len = rpcstr_push(temp, lp_servicename(snum), sizeof(temp) - 2, 0); + len = rpcstr_push(temp, lp_servicename(snum), sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.length = len / 2; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1529,9 +1529,9 @@ static void spoolss_notify_port_name(int snum, /* even if it's strange, that's consistant in all the code */ - len = rpcstr_push(temp, printer->info_2->portname, sizeof(temp) - 2, 0); + len = rpcstr_push(temp, printer->info_2->portname, sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.length = len / 2; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1556,8 +1556,8 @@ static void spoolss_notify_driver_name(int snum, pstring temp; uint32 len; - len = rpcstr_push(temp, printer->info_2->drivername, sizeof(temp) - 2, 0); - data->notify_data.data.length = len / 2 - 1; + len = rpcstr_push(temp, printer->info_2->drivername, sizeof(temp)-2, STR_TERMINATE); + data->notify_data.data.length = len / 2; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1581,12 +1581,12 @@ static void spoolss_notify_comment(int snum, uint32 len; if (*printer->info_2->comment == '\0') - len = rpcstr_push(temp, lp_comment(snum), sizeof(temp) - 2, 0); + len = rpcstr_push(temp, lp_comment(snum), sizeof(temp)-2, STR_TERMINATE); else - len = rpcstr_push(temp, printer->info_2->comment, sizeof(temp) - 2, 0); + len = rpcstr_push(temp, printer->info_2->comment, sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.length = len / 2; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1611,9 +1611,9 @@ static void spoolss_notify_location(int snum, pstring temp; uint32 len; - len = rpcstr_push(temp, printer->info_2->location,sizeof(temp) - 2, 0); + len = rpcstr_push(temp, printer->info_2->location,sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.length = len / 2; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1650,9 +1650,9 @@ static void spoolss_notify_sepfile(int snum, pstring temp; uint32 len; - len = rpcstr_push(temp, printer->info_2->sepfile, sizeof(temp) - 2, 0); + len = rpcstr_push(temp, printer->info_2->sepfile, sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.length = len / 2; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1676,9 +1676,9 @@ static void spoolss_notify_print_processor(int snum, pstring temp; uint32 len; - len = rpcstr_push(temp, printer->info_2->printprocessor, sizeof(temp) - 2, 0); + len = rpcstr_push(temp, printer->info_2->printprocessor, sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.length = len / 2; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1702,10 +1702,9 @@ static void spoolss_notify_parameters(int snum, pstring temp; uint32 len; - len = rpcstr_push(temp, printer->info_2->parameters, sizeof(temp) - - 2, 0); + len = rpcstr_push(temp, printer->info_2->parameters, sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.length = len / 2; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1729,9 +1728,9 @@ static void spoolss_notify_datatype(int snum, pstring temp; uint32 len; - len = rpcstr_push(temp, printer->info_2->datatype, sizeof(pstring)-2, 0); + len = rpcstr_push(temp, printer->info_2->datatype, sizeof(pstring)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.length = len / 2; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1768,6 +1767,7 @@ static void spoolss_notify_attributes(int snum, TALLOC_CTX *mem_ctx) { data->notify_data.value[0] = printer->info_2->attributes; + data->notify_data.value[1] = 0; } /******************************************************************* @@ -1780,6 +1780,7 @@ static void spoolss_notify_priority(int snum, TALLOC_CTX *mem_ctx) { data->notify_data.value[0] = printer->info_2->priority; + data->notify_data.value[1] = 0; } /******************************************************************* @@ -1792,6 +1793,7 @@ static void spoolss_notify_default_priority(int snum, TALLOC_CTX *mem_ctx) { data->notify_data.value[0] = printer->info_2->default_priority; + data->notify_data.value[1] = 0; } /******************************************************************* @@ -1804,6 +1806,7 @@ static void spoolss_notify_start_time(int snum, TALLOC_CTX *mem_ctx) { data->notify_data.value[0] = printer->info_2->starttime; + data->notify_data.value[1] = 0; } /******************************************************************* @@ -1816,6 +1819,7 @@ static void spoolss_notify_until_time(int snum, TALLOC_CTX *mem_ctx) { data->notify_data.value[0] = printer->info_2->untiltime; + data->notify_data.value[1] = 0; } /******************************************************************* @@ -1833,6 +1837,7 @@ static void spoolss_notify_status(int snum, memset(&status, 0, sizeof(status)); print_queue_status(snum, &q, &status); data->notify_data.value[0]=(uint32) status.status; + data->notify_data.value[1] = 0; SAFE_FREE(q); } @@ -1850,6 +1855,7 @@ static void spoolss_notify_cjobs(int snum, memset(&status, 0, sizeof(status)); data->notify_data.value[0] = print_queue_status(snum, &q, &status); + data->notify_data.value[1] = 0; SAFE_FREE(q); } @@ -1865,6 +1871,7 @@ static void spoolss_notify_average_ppm(int snum, /* always respond 8 pages per minutes */ /* a little hard ! */ data->notify_data.value[0] = printer->info_2->averageppm; + data->notify_data.value[1] = 0; } /******************************************************************* @@ -1879,10 +1886,10 @@ static void spoolss_notify_username(int snum, pstring temp; uint32 len; - len = rpcstr_push(temp, queue->user, sizeof(temp) - 2, 0); + len = rpcstr_push(temp, queue->user, sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.length = len / 2; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1903,6 +1910,7 @@ static void spoolss_notify_job_status(int snum, TALLOC_CTX *mem_ctx) { data->notify_data.value[0]=nt_printj_status(queue->status); + data->notify_data.value[1] = 0; } /******************************************************************* @@ -1917,9 +1925,9 @@ static void spoolss_notify_job_name(int snum, pstring temp; uint32 len; - len = rpcstr_push(temp, queue->file, sizeof(temp) - 2, 0); + len = rpcstr_push(temp, queue->file, sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.length = len / 2; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1966,9 +1974,9 @@ static void spoolss_notify_job_status_string(int snum, } #endif /* NO LONGER NEEDED. */ - len = rpcstr_push(temp, p, sizeof(temp) - 2, 0); + len = rpcstr_push(temp, p, sizeof(temp) - 2, STR_TERMINATE); - data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.length = len / 2; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1989,6 +1997,7 @@ static void spoolss_notify_job_time(int snum, TALLOC_CTX *mem_ctx) { data->notify_data.value[0]=0x0; + data->notify_data.value[1]=0; } /******************************************************************* @@ -2001,6 +2010,7 @@ static void spoolss_notify_job_size(int snum, TALLOC_CTX *mem_ctx) { data->notify_data.value[0]=queue->size; + data->notify_data.value[1]=0; } /******************************************************************* @@ -2013,6 +2023,7 @@ static void spoolss_notify_job_position(int snum, TALLOC_CTX *mem_ctx) { data->notify_data.value[0]=queue->job; + data->notify_data.value[1]=0; } /******************************************************************* @@ -2032,7 +2043,7 @@ static void spoolss_notify_submitted_time(int snum, len = sizeof(SYSTEMTIME); - data->notify_data.data.length = len/2 - 1; + data->notify_data.data.length = len; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { -- cgit From 7623cec4ad5f8eecae1a3c780a7ca89a6a14b93a Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 5 Nov 2001 06:15:02 +0000 Subject: Wrote some stubs for new win2k only spoolss rpc commands: GetPrinterDataEx() and SetPrinterDataEx(). Not sure what the command number is for the latter is - I haven't seen it on the wire yet. (This used to be commit 87614c74b3d66cf2ca706b33e6cf0a32b4166e7a) --- source3/rpc_server/srv_spoolss_nt.c | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 0be836c944..e5ca373479 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6755,3 +6755,41 @@ WERROR _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_ return WERR_UNKNOWN_LEVEL; } } + +/******************************************************************** + * spoolss_getprinterdataex + ********************************************************************/ + +WERROR _spoolss_getprinterdataex(pipes_struct *p, SPOOL_Q_GETPRINTERDATAEX *q_u, SPOOL_R_GETPRINTERDATAEX *r_u) +{ + fstring key; + + /* From MSDN documentation of GetPrinterDataEx: pass request to + GetPrinterData if key is "PrinterDriverData" */ + + unistr2_to_ascii(key, &q_u->keyname, sizeof(key) - 1); + + if (strcmp(key, "PrinterDriverData") == 0) + DEBUG(10, ("pass me to getprinterdata\n")); + + return WERR_INVALID_PARAM; +} + +/******************************************************************** + * spoolss_setprinterdata + ********************************************************************/ + +WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, SPOOL_R_SETPRINTERDATAEX *r_u) +{ + fstring key; + + /* From MSDN documentation of SetPrinterDataEx: pass request to + SetPrinterData if key is "PrinterDriverData" */ + + unistr2_to_ascii(key, &q_u->key, sizeof(key) - 1); + + if (strcmp(key, "PrinterDriverData") == 0) + DEBUG(10, ("pass me to setprinterdata\n")); + + return WERR_INVALID_PARAM; +} -- cgit From 06ff349e21abd9398eaac521c3a23c2ab7a10cb2 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 15 Nov 2001 05:26:22 +0000 Subject: FALSE -> False (This used to be commit 7c6529c081abe051055be5fbf3016fbea2474752) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index e5ca373479..968044b6cd 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -5895,7 +5895,7 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)-1); - if (get_short_archi(short_archi, long_archi)==FALSE) + if (get_short_archi(short_archi, long_archi)==False) return WERR_INVALID_ENVIRONMENT; if((info=(DRIVER_DIRECTORY_1 *)malloc(sizeof(DRIVER_DIRECTORY_1))) == NULL) -- cgit From 116740a5df6294b0a4e244f575108ded87452c18 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 22 Nov 2001 05:56:09 +0000 Subject: merge from 2.2 (This used to be commit 96b3a65a73d403a41bf1b3aba79bd743698344ac) --- source3/rpc_server/srv_spoolss_nt.c | 355 ++++++++++++++++++++++++++++++++---- 1 file changed, 322 insertions(+), 33 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 968044b6cd..10c022962a 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -5,7 +5,8 @@ * Copyright (C) Andrew Tridgell 1992-2000, * Copyright (C) Luke Kenneth Casson Leighton 1996-2000, * Copyright (C) Jean François Micouleau 1998-2000. - * Copyright (C) Jeremy Allison 2001. + * Copyright (C) Jeremy Allison 2001. + * Copyright (C) Gerald Carter 2000-2001. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -803,6 +804,7 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, /* map an empty access mask to the minimum access mask */ if (printer_default->access_required == 0x0) printer_default->access_required = PRINTER_ACCESS_USE; + /* * If we are not serving the printer driver for this printer, @@ -1130,6 +1132,7 @@ WERROR _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER /* check that we have a valid driver name first */ if ((version=get_version_id(arch)) == -1) { + /* this is what NT returns */ return WERR_INVALID_ENVIRONMENT; } @@ -1316,7 +1319,7 @@ WERROR _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO DEBUG(4,("_spoolss_getprinterdata\n")); if (!Printer) { - if((*data=(uint8 *)malloc(4*sizeof(uint8))) == NULL) + if((*data=(uint8 *)talloc_zero(p->mem_ctx, 4*sizeof(uint8))) == NULL) return WERR_NOMEM; DEBUG(0,("_spoolss_getprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); return WERR_BADFID; @@ -1344,9 +1347,8 @@ WERROR _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO if (*needed > *out_size) return WERR_STATUS_MORE_ENTRIES; - else { + else return WERR_OK; - } } /*************************************************************************** @@ -2235,13 +2237,13 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int if (!search_notify(type, field, &j) ) continue; - + if((tid=(SPOOL_NOTIFY_INFO_DATA *)Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) { DEBUG(0,("construct_notify_printer_info: failed to enlarge buffer info->data!\n")); return False; } else info->data = tid; - + current_data=&info->data[info->count]; construct_info_data(current_data, type, field, id); @@ -3180,6 +3182,7 @@ WERROR _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOOL_ uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; uint32 *returned = &r_u->returned; + fstring name; /* that's an [in out] buffer */ @@ -3902,6 +3905,7 @@ WERROR _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_ case 6: return getprinterdriver2_level6(servername, architecture, clientmajorversion, snum, buffer, offered, needed); } + return WERR_UNKNOWN_LEVEL; } @@ -4700,9 +4704,9 @@ WERROR _spoolss_addjob(pipes_struct *p, SPOOL_Q_ADDJOB *q_u, SPOOL_R_ADDJOB *r_u r_u->needed = 0; return WERR_INVALID_PARAM; /* this is what a NT server - returns for AddJob. AddJob - must fail on non-local - printers */ + returns for AddJob. AddJob + must fail on non-local + printers */ } /**************************************************************************** @@ -5008,6 +5012,7 @@ static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture int ndrivers; uint32 version; fstring *list = NULL; + NT_PRINTER_DRIVER_INFO_LEVEL driver; DRIVER_INFO_1 *tdi1, *driver_info_1=NULL; @@ -5087,6 +5092,7 @@ static WERROR enumprinterdrivers_level2(fstring servername, fstring architecture int ndrivers; uint32 version; fstring *list = NULL; + NT_PRINTER_DRIVER_INFO_LEVEL driver; DRIVER_INFO_2 *tdi2, *driver_info_2=NULL; @@ -5167,6 +5173,7 @@ static WERROR enumprinterdrivers_level3(fstring servername, fstring architecture int ndrivers; uint32 version; fstring *list = NULL; + NT_PRINTER_DRIVER_INFO_LEVEL driver; DRIVER_INFO_3 *tdi3, *driver_info_3=NULL; @@ -5776,13 +5783,13 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ return WERR_INVALID_PARAM; } - /* + /* * When a printer is created, the drivername bound to the printer is used - * to lookup previously saved driver initialization info, which is then + * to lookup previously saved driver initialization info, which is then * bound to the new printer, simulating what happens in the Windows arch. */ set_driver_init(printer, 2); - + /* write the ASCII on disk */ err = add_a_printer(*printer, 2); if (!W_ERROR_IS_OK(err)) { @@ -6165,7 +6172,6 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP goto done; } - /* Check if we are making any changes or not. Return true if nothing is actually changing. This is not needed anymore but has been left in as an optimization to keep from from @@ -6177,6 +6183,7 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP convert_specific_param(¶m, value , type, data, real_len); + if (get_specific_param(*printer, 2, param->value, &old_param.data, &old_param.type, (uint32 *)&old_param.data_len)) { @@ -6192,7 +6199,7 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP } unlink_specific_param_if_exist(printer->info_2, param); - + /* * When client side code sets a magic printer data key, detect it and save * the current printer data and the magic key's data (its the DEVMODE) for @@ -6208,7 +6215,7 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP add_a_specific_param(printer->info_2, ¶m); status = mod_a_printer(*printer, 2); } - + done: free_a_printer(&printer, 2); if (param) @@ -6326,7 +6333,7 @@ WERROR _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE } count = get_ntforms(&list); - if (!delete_a_form(&list, form_name, &count, &ret)) + if(!delete_a_form(&list, form_name, &count, &ret)) return WERR_INVALID_PARAM; SAFE_FREE(list); @@ -6408,9 +6415,9 @@ WERROR _spoolss_enumprintprocessors(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCESSORS /* UNISTR2 *name = &q_u->name; - notused. */ /* UNISTR2 *environment = &q_u->environment; - notused. */ uint32 level = q_u->level; - NEW_BUFFER *buffer = NULL; + NEW_BUFFER *buffer = NULL; uint32 offered = q_u->offered; - uint32 *needed = &r_u->needed; + uint32 *needed = &r_u->needed; uint32 *returned = &r_u->returned; /* that's an [in out] buffer */ @@ -6570,9 +6577,9 @@ WERROR _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS *q_ { /* UNISTR2 *name = &q_u->name; - notused. */ uint32 level = q_u->level; - NEW_BUFFER *buffer = NULL; + NEW_BUFFER *buffer = NULL; uint32 offered = q_u->offered; - uint32 *needed = &r_u->needed; + uint32 *needed = &r_u->needed; uint32 *returned = &r_u->returned; /* that's an [in out] buffer */ @@ -6624,8 +6631,8 @@ static WERROR getjob_level_1(print_queue_struct *queue, int count, int snum, uin if (found==False) { SAFE_FREE(queue); SAFE_FREE(info_1); - /* I shoud reply something else ... I can't find the good one */ - return WERR_OK; + /* NT treats not found as bad param... yet another bad choice */ + return WERR_INVALID_PARAM; } fill_job_info_1(info_1, &(queue[i-1]), i, snum); @@ -6677,8 +6684,8 @@ static WERROR getjob_level_2(print_queue_struct *queue, int count, int snum, uin if (found==False) { SAFE_FREE(queue); SAFE_FREE(info_2); - /* I shoud reply something else ... I can't find the good one */ - return WERR_OK; + /* NT treats not found as bad param... yet another bad choice */ + return WERR_INVALID_PARAM; } ret = get_a_printer(&ntprinter, 2, lp_servicename(snum)); @@ -6762,17 +6769,81 @@ WERROR _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_ WERROR _spoolss_getprinterdataex(pipes_struct *p, SPOOL_Q_GETPRINTERDATAEX *q_u, SPOOL_R_GETPRINTERDATAEX *r_u) { - fstring key; + POLICY_HND *handle = &q_u->handle; + uint32 in_size = q_u->size; + uint32 *type = &r_u->type; + uint32 *out_size = &r_u->size; + uint8 **data = &r_u->data; + uint32 *needed = &r_u->needed; - /* From MSDN documentation of GetPrinterDataEx: pass request to - GetPrinterData if key is "PrinterDriverData" */ + fstring key, value; + Printer_entry *Printer = find_printer_index_by_hnd(p, handle); + BOOL found = False; + + DEBUG(4,("_spoolss_getprinterdataex\n")); unistr2_to_ascii(key, &q_u->keyname, sizeof(key) - 1); + unistr2_to_ascii(value, &q_u->valuename, sizeof(value) - 1); - if (strcmp(key, "PrinterDriverData") == 0) - DEBUG(10, ("pass me to getprinterdata\n")); - - return WERR_INVALID_PARAM; + /* in case of problem, return some default values */ + *needed=0; + *type=0; + *out_size=0; + + + if (!Printer) { + if((*data=(uint8 *)talloc_zero(p->mem_ctx, 4*sizeof(uint8))) == NULL) + return WERR_NOMEM; + DEBUG(0,("_spoolss_getprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); + return WERR_BADFID; + } + + + /* Is the handle to a printer or to the server? */ + + if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) + { + DEBUG(10,("_spoolss_getprinterdatex: Not implemented for server handles yet\n")); + return WERR_INVALID_PARAM; + } + else + { + /* + * From MSDN documentation of GetPrinterDataEx: pass request + * to GetPrinterData if key is "PrinterDriverData". This is + * the only key we really support. Other keys to implement: + * (a) DsDriver + * (b) DsSpooler + * (c) PnPData + */ + + if (strcmp(key, "PrinterDriverData") != 0) + return WERR_INVALID_PARAM; + + DEBUG(10, ("_spoolss_getprinterdataex: pass me to getprinterdata\n")); + found = getprinterdata_printer(p, p->mem_ctx, handle, value, + type, data, needed, in_size); + + } + + if (!found) { + DEBUG(5, ("value not found, allocating %d\n", *out_size)); + + /* reply this param doesn't exist */ + if (*out_size) { + if((*data=(uint8 *)talloc_zero(p->mem_ctx, *out_size*sizeof(uint8))) == NULL) + return WERR_NOMEM; + } else { + *data = NULL; + } + + return WERR_INVALID_PARAM; + } + + if (*needed > *out_size) + return WERR_MORE_DATA; + else + return WERR_OK; } /******************************************************************** @@ -6781,15 +6852,233 @@ WERROR _spoolss_getprinterdataex(pipes_struct *p, SPOOL_Q_GETPRINTERDATAEX *q_u, WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, SPOOL_R_SETPRINTERDATAEX *r_u) { + SPOOL_Q_SETPRINTERDATA q_u_local; + SPOOL_R_SETPRINTERDATA r_u_local; fstring key; + DEBUG(4,("_spoolss_setprinterdataex\n")); + /* From MSDN documentation of SetPrinterDataEx: pass request to SetPrinterData if key is "PrinterDriverData" */ unistr2_to_ascii(key, &q_u->key, sizeof(key) - 1); if (strcmp(key, "PrinterDriverData") == 0) - DEBUG(10, ("pass me to setprinterdata\n")); + return WERR_INVALID_PARAM; + + ZERO_STRUCT(q_u_local); + ZERO_STRUCT(r_u_local); + + /* make a copy to call _spoolss_setprinterdata() */ + + memcpy(&q_u_local.handle, &q_u->handle, sizeof(POLICY_HND)); + copy_unistr2(&q_u_local.value, &q_u->value); + q_u_local.type = q_u->type; + q_u_local.max_len = q_u->max_len; + q_u_local.data = q_u->data; + q_u_local.real_len = q_u->real_len; + q_u_local.numeric_data = q_u->numeric_data; + + return _spoolss_setprinterdata(p, &q_u_local, &r_u_local); +} + +/******************************************************************** + * spoolss_enumprinterkey + ********************************************************************/ + +/* constants for EnumPrinterKey() */ +#define ENUMERATED_KEY_SIZE 19 + +WERROR _spoolss_enumprinterkey(pipes_struct *p, SPOOL_Q_ENUMPRINTERKEY *q_u, SPOOL_R_ENUMPRINTERKEY *r_u) +{ + fstring key; + uint16 enumkeys[ENUMERATED_KEY_SIZE+1]; + char* ptr = NULL; + int i; + char *PrinterKey = "PrinterDriverData"; + + DEBUG(4,("_spoolss_enumprinterkey\n")); - return WERR_INVALID_PARAM; + unistr2_to_ascii(key, &q_u->key, sizeof(key) - 1); + + /* + * we only support enumating all keys (key == "") + * Of course, the only key we support is the "PrinterDriverData" + * key + */ + if (strlen(key) == 0) + { + r_u->needed = ENUMERATED_KEY_SIZE *2; + if (q_u->size < r_u->needed) + return WERR_MORE_DATA; + + ptr = PrinterKey; + for (i=0; imem_ctx, &r_u->keys, ENUMERATED_KEY_SIZE, enumkeys)) + return WERR_BADFILE; + + return WERR_OK; + } + + /* The "PrinterDriverData" key should have no subkeys */ + if (strcmp(key, PrinterKey) == 0) + { + r_u-> needed = 2; + if (q_u->size < r_u->needed) + return WERR_MORE_DATA; + enumkeys[0] = 0x0; + if (!make_spoolss_buffer5(p->mem_ctx, &r_u->keys, 1, enumkeys)) + return WERR_BADFILE; + + return WERR_OK; + } + + + /* The return value for an unknown key is documented in MSDN + EnumPrinterKey description */ + return WERR_BADFILE; +} + +/******************************************************************** + * spoolss_enumprinterdataex + ********************************************************************/ + +WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_u, SPOOL_R_ENUMPRINTERDATAEX *r_u) +{ + POLICY_HND *handle = &q_u->handle; + uint32 in_size = q_u->size; + uint32 num_entries, + needed; + NT_PRINTER_INFO_LEVEL *printer = NULL; + PRINTER_ENUM_VALUES *enum_values = NULL; + fstring key, value; + Printer_entry *Printer = find_printer_index_by_hnd(p, handle); + int snum; + uint32 param_index, + data_len, + type; + WERROR result; + uint8 *data=NULL; + uint32 i; + + + DEBUG(4,("_spoolss_enumprinterdataex\n")); + + if (!Printer) { + DEBUG(0,("_spoolss_enumprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); + return WERR_BADFID; + } + + + /* + * The only key we support is "PrinterDriverData". This should return + > an array of all the key/value pairs returned by EnumPrinterDataSee + * _spoolss_getprinterdataex() for details --jerry + */ + + unistr2_to_ascii(key, &q_u->key, sizeof(key) - 1); + if (strcmp(key, "PrinterDriverData") != 0) + { + DEBUG(10,("_spoolss_enumprinterdataex: Unknown keyname [%s]\n", key)); + return WERR_INVALID_PARAM; + } + + + if (!get_printer_snum(p,handle, &snum)) + return WERR_BADFID; + + ZERO_STRUCT(printer); + result = get_a_printer(&printer, 2, lp_servicename(snum)); + if (!W_ERROR_IS_OK(result)) + return result; + + + /* + * loop through all params and build the array to pass + * back to the client + */ + result = WERR_OK; + param_index = 0; + needed = 0; + num_entries = 0; + + while (get_specific_param_by_index(*printer, 2, param_index, value, &data, &type, &data_len)) + { + PRINTER_ENUM_VALUES *ptr; + uint32 add_len = 0; + + DEBUG(10,("retrieved value number [%d] [%s]\n", num_entries, value)); + + if ((ptr=talloc_realloc(p->mem_ctx, enum_values, (num_entries+1) * sizeof(PRINTER_ENUM_VALUES))) == NULL) + { + DEBUG(0,("talloc_realloc failed to allocate more memory!\n")); + result = WERR_NOMEM; + goto done; + } + enum_values = ptr; + + /* copy the data */ + init_unistr(&enum_values[num_entries].valuename, value); + enum_values[num_entries].value_len = (strlen(value)+1) * 2; + enum_values[num_entries].type = type; + + /* + * NULL terminate REG_SZ + * FIXME!!! We should not be correctly problems in the way + * we store PrinterData here. Need to investogate + * SetPrinterData[Ex] --jerry + */ + + if (type == REG_SZ) { + /* fix alignment if the string was stored + in a bizarre fashion */ + if ((data_len % 2) == 0) + add_len = 2; + else + add_len = data_len % 2; + } + + if (!(enum_values[num_entries].data=talloc_zero(p->mem_ctx, data_len+add_len))) { + DEBUG(0,("talloc_realloc failed to allocate more memory for data!\n")); + result = WERR_NOMEM; + goto done; + } + memcpy(enum_values[num_entries].data, data, data_len); + enum_values[num_entries].data_len = data_len + add_len; + + /* keep track of the size of the array in bytes */ + + needed += spoolss_size_printer_enum_values(&enum_values[num_entries]); + + num_entries++; + param_index++; + } + + r_u->needed = needed; + r_u->returned = num_entries; + + if (needed > in_size) { + result = WERR_MORE_DATA; + goto done; + } + + /* copy data into the reply */ + + r_u->ctr.size = r_u->needed; + r_u->ctr.size_of_array = r_u->returned; + r_u->ctr.values = enum_values; + + + +done: + free_a_printer(&printer, 2); + + return result; } + + -- cgit From 59b2e772e254aa567b18309e578ea9af6b1ab1e4 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 22 Nov 2001 06:44:05 +0000 Subject: remove unused variables (This used to be commit 90ed3d47e16a511161532f75b98db3f4b10ba685) --- source3/rpc_server/srv_spoolss_nt.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 10c022962a..2b8ae2de0b 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6964,7 +6964,6 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ type; WERROR result; uint8 *data=NULL; - uint32 i; DEBUG(4,("_spoolss_enumprinterdataex\n")); -- cgit From d919314390ad51384146797de5268b5c842f039b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 27 Nov 2001 20:01:23 +0000 Subject: Added PRINTER_ALREADY_EXISTS error check from Gerry. Jeremy (This used to be commit c7f1d3d6f776da8619f1221d38619d084ffb990b) --- source3/rpc_server/srv_spoolss_nt.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 2b8ae2de0b..71b776f80a 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -5740,9 +5740,10 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ POLICY_HND *handle) { NT_PRINTER_INFO_LEVEL *printer = NULL; - WERROR err; - fstring name; - int snum; + NT_PRINTER_INFO_LEVEL *old_printer = NULL; + fstring name; + int snum; + WERROR err = WERR_OK; if ((printer = (NT_PRINTER_INFO_LEVEL *)malloc(sizeof(NT_PRINTER_INFO_LEVEL))) == NULL) { DEBUG(0,("spoolss_addprinterex_level_2: malloc fail.\n")); @@ -5754,6 +5755,18 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ /* convert from UNICODE to ASCII - this allocates the info_2 struct inside *printer.*/ convert_printer_info(info, printer, 2); + + /* check to see if the printer already exists */ + err = get_a_printer(&old_printer, 2, printer->info_2->sharename); + + /* did we find a printer? */ + if (W_ERROR_IS_OK(err)) { + DEBUG(5, ("_spoolss_addprinterex: Attempted to add a printer named [%s] when one already existed!\n", + printer->info_2->sharename)); + free_a_printer(&old_printer, 2); + return WERR_PRINTER_ALREADY_EXISTS; + } + if (*lp_addprinter_cmd() ) if ( !add_printer_hook(printer) ) { free_a_printer(&printer,2); -- cgit From bd8e916cb520d89a14a1cd13b2b261253729ac9b Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 28 Nov 2001 21:51:11 +0000 Subject: merge from APPLIANCE_HEAD (This used to be commit c60aa6c06f376684b6d6d9a2c14305ca9f4657ef) --- source3/rpc_server/srv_spoolss_nt.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 71b776f80a..3b21726a0f 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2959,13 +2959,14 @@ static WERROR enum_all_printers_info_1_local(NEW_BUFFER *buffer, uint32 offered, *********************************************************************/ static WERROR enum_all_printers_info_1_name(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { - fstring temp; + char *s = name; + DEBUG(4,("enum_all_printers_info_1_name\n")); - fstrcpy(temp, "\\\\"); - fstrcat(temp, global_myname); + if ((name[0] == '\\') && (name[1] == '\\')) + s = name + 2; - if (strequal(name, temp)) { + if (is_myname_or_ipaddr(s)) { return enum_all_printers_info_1(PRINTER_ENUM_ICON8, buffer, offered, needed, returned); } else @@ -3131,20 +3132,16 @@ static WERROR enumprinters_level2( uint32 flags, fstring servername, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { - fstring temp; - - fstrcpy(temp, "\\\\"); - fstrcat(temp, global_myname); + char *s = servername; if (flags & PRINTER_ENUM_LOCAL) { - if (strequal(servername, temp)) - return enum_all_printers_info_2(buffer, offered, needed, returned); - else return enum_all_printers_info_2(buffer, offered, needed, returned); } if (flags & PRINTER_ENUM_NAME) { - if (strequal(servername, temp)) + if ((servername[0] == '\\') && (servername[1] == '\\')) + s = servername + 2; + if (is_myname_or_ipaddr(s)) return enum_all_printers_info_2(buffer, offered, needed, returned); else return WERR_INVALID_NAME; -- cgit From 6d9adfe73c04132ff162d05b0c309395c4a54485 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 30 Nov 2001 01:04:15 +0000 Subject: Renamed sid field in SEC_ACE to trustee to be more in line with MS's definitions. (This used to be commit 9712d3f15a47155f558d0034ef71fd06afb11301) --- source3/rpc_server/srv_spoolss_nt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 3b21726a0f..c64a7a218c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4150,7 +4150,7 @@ static WERROR update_printer_sec(POLICY_HND *handle, uint32 level, for (i = 0; i < the_acl->num_aces; i++) { fstring sid_str; - sid_to_string(sid_str, &the_acl->ace[i].sid); + sid_to_string(sid_str, &the_acl->ace[i].trustee); DEBUG(10, ("%s 0x%08x\n", sid_str, the_acl->ace[i].info.mask)); @@ -4165,7 +4165,7 @@ static WERROR update_printer_sec(POLICY_HND *handle, uint32 level, for (i = 0; i < the_acl->num_aces; i++) { fstring sid_str; - sid_to_string(sid_str, &the_acl->ace[i].sid); + sid_to_string(sid_str, &the_acl->ace[i].trustee); DEBUG(10, ("%s 0x%08x\n", sid_str, the_acl->ace[i].info.mask)); -- cgit From 445ab75ec33db60307a373885efe622ed5c65d02 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 30 Nov 2001 03:38:59 +0000 Subject: Gerald's fix. Jeremy (This used to be commit b0c1fcfc8bae83788c7595931321833bf177ec4b) --- source3/rpc_server/srv_spoolss_nt.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index c64a7a218c..3c7948fd7b 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -5737,7 +5737,6 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ POLICY_HND *handle) { NT_PRINTER_INFO_LEVEL *printer = NULL; - NT_PRINTER_INFO_LEVEL *old_printer = NULL; fstring name; int snum; WERROR err = WERR_OK; @@ -5752,15 +5751,12 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ /* convert from UNICODE to ASCII - this allocates the info_2 struct inside *printer.*/ convert_printer_info(info, printer, 2); - /* check to see if the printer already exists */ - err = get_a_printer(&old_printer, 2, printer->info_2->sharename); - /* did we find a printer? */ - if (W_ERROR_IS_OK(err)) { + if ((snum = print_queue_snum(printer->info_2->sharename)) != -1) { DEBUG(5, ("_spoolss_addprinterex: Attempted to add a printer named [%s] when one already existed!\n", printer->info_2->sharename)); - free_a_printer(&old_printer, 2); + free_a_printer(&printer, 2); return WERR_PRINTER_ALREADY_EXISTS; } -- cgit From 605248abd9cf207d80811e304a61e0417999ac1c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 30 Nov 2001 03:45:21 +0000 Subject: Check error returns. Jeremy. (This used to be commit fc8638e89effb0ebf2e40cee8cd0d7467e49e2a8) --- source3/rpc_server/srv_spoolss_nt.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 3c7948fd7b..7f54867eb4 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -908,15 +908,17 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, static BOOL convert_printer_info(const SPOOL_PRINTER_INFO_LEVEL *uni, NT_PRINTER_INFO_LEVEL *printer, uint32 level) { + BOOL ret = True; + switch (level) { case 2: - uni_2_asc_printer_info_2(uni->info_2, &printer->info_2); + ret = uni_2_asc_printer_info_2(uni->info_2, &printer->info_2); break; default: break; } - return True; + return ret; } static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL *uni, @@ -4569,7 +4571,10 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, * just read from the tdb in the pointer 'printer'. */ - convert_printer_info(info, printer, level); + if (!convert_printer_info(info, printer, level)) { + result = WERR_NOMEM; + goto done; + } if (info->info_2->devmode_ptr != 0) { /* we have a valid devmode @@ -5749,7 +5754,10 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ ZERO_STRUCTP(printer); /* convert from UNICODE to ASCII - this allocates the info_2 struct inside *printer.*/ - convert_printer_info(info, printer, 2); + if (!convert_printer_info(info, printer, 2)) { + free_a_printer(&printer, 2); + return WERR_NOMEM; + } /* check to see if the printer already exists */ -- cgit From 9cc8cb5134b0a4ebf5e985f7319ded295f308c90 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 30 Nov 2001 20:33:35 +0000 Subject: merge from APPLIANCE_HEAD (This used to be commit f8b18b25944135c196c8134100f601e84c583382) --- source3/rpc_server/srv_spoolss_nt.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 7f54867eb4..1d54c92bce 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6006,10 +6006,6 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S ZERO_STRUCT(printer); - *out_max_value_len=0; - *out_value=NULL; - *out_value_len=0; - *out_type=0; *out_max_data_len=0; @@ -6071,18 +6067,6 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S param_index++; } - /* - * I think this is correct, it doesn't break APW and - * allows Gerald's Win32 test programs to work correctly, - * but may need altering.... JRA. - */ - - if (param_index == 0) { - /* No parameters found. */ - free_a_printer(&printer, 2); - return WERR_NO_MORE_ITEMS; - } - /* the value is an UNICODE string but realvaluesize is the length in bytes including the leading 0 */ *out_value_len=2*(1+biggest_valuesize); *out_data_len=biggest_datasize; @@ -6099,8 +6083,28 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S */ if (!get_specific_param_by_index(*printer, 2, idx, value, &data, &type, &data_len)) { + SAFE_FREE(data); free_a_printer(&printer, 2); + + /* out_value should default to "" or else NT4 has + problems unmarshalling the response */ + + *out_max_value_len=(in_value_len/sizeof(uint16)); + if((*out_value=(uint16 *)malloc(in_value_len*sizeof(uint8))) == NULL) + return WERR_NOMEM; + + ZERO_STRUCTP(*out_value); + *out_value_len = rpcstr_push((char *)*out_value, "", in_value_len, 0); + + /* the data is counted in bytes */ + *out_max_data_len = in_data_len; + *out_data_len = in_data_len; + if((*data_out=(uint8 *)malloc(in_data_len*sizeof(uint8))) == NULL) + return WERR_NOMEM; + + memset(*data_out,'\0',in_data_len); + return WERR_NO_MORE_ITEMS; } -- cgit From 547263873017bd7e042f8826b68a3136c4e3b2f8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 5 Dec 2001 00:54:33 +0000 Subject: Improved efficiency of enumerating print queue's under a particular extreme condition... Jeremy. (This used to be commit 425bb0f40526b4eb17a3033892ca907b1d5293a4) --- source3/rpc_server/srv_spoolss_nt.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 1d54c92bce..d49cee0d25 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1835,14 +1835,12 @@ static void spoolss_notify_status(int snum, NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) { - print_queue_struct *q=NULL; print_status_struct status; memset(&status, 0, sizeof(status)); - print_queue_status(snum, &q, &status); + print_queue_length(snum, &status); data->notify_data.value[0]=(uint32) status.status; data->notify_data.value[1] = 0; - SAFE_FREE(q); } /******************************************************************* @@ -1854,13 +1852,8 @@ static void spoolss_notify_cjobs(int snum, NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) { - print_queue_struct *q=NULL; - print_status_struct status; - - memset(&status, 0, sizeof(status)); - data->notify_data.value[0] = print_queue_status(snum, &q, &status); + data->notify_data.value[0] = print_queue_length(snum, NULL); data->notify_data.value[1] = 0; - SAFE_FREE(q); } /******************************************************************* -- cgit From 105f8a1a0fcce360c427a69fd4201c625cedc7d8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 5 Dec 2001 02:11:03 +0000 Subject: Use print_queue_length() by preference if we don't need a queue as it doesn't do a traversal. Jeremy. (This used to be commit 4bf4ee3f14a690592fa2e1b800fc0344522e6b30) --- source3/rpc_server/srv_spoolss_nt.c | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index d49cee0d25..0e98498fe3 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1837,7 +1837,6 @@ static void spoolss_notify_status(int snum, { print_status_struct status; - memset(&status, 0, sizeof(status)); print_queue_length(snum, &status); data->notify_data.value[0]=(uint32) status.status; data->notify_data.value[1] = 0; @@ -2428,7 +2427,6 @@ static WERROR printer_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY case JOB_NOTIFY_TYPE: { NT_PRINTER_INFO_LEVEL *printer = NULL; - memset(&status, 0, sizeof(status)); count = print_queue_status(snum, &queue, &status); if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, @@ -2534,16 +2532,12 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum) uint32 global_counter; struct tm *t; time_t setuptime; - - print_queue_struct *queue=NULL; print_status_struct status; - memset(&status, 0, sizeof(status)); - if (!W_ERROR_IS_OK(get_a_printer(&ntprinter, 2, lp_servicename(snum)))) return False; - count = print_queue_status(snum, &queue, &status); + count = print_queue_length(snum, &status); /* check if we already have a counter for this printer */ session_counter = (counter_printer_0 *)ubi_dlFirst(&counter_list); @@ -2625,7 +2619,6 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum) printer->unknown28 = 0; printer->unknown29 = 0; - SAFE_FREE(queue); free_a_printer(&ntprinter,2); return (True); } @@ -2774,15 +2767,12 @@ static BOOL construct_printer_info_2(PRINTER_INFO_2 *printer, int snum) int count; NT_PRINTER_INFO_LEVEL *ntprinter = NULL; - print_queue_struct *queue=NULL; print_status_struct status; - memset(&status, 0, sizeof(status)); if (!W_ERROR_IS_OK(get_a_printer(&ntprinter, 2, lp_servicename(snum)))) return False; - memset(&status, 0, sizeof(status)); - count = print_queue_status(snum, &queue, &status); + count = print_queue_length(snum, &status); init_unistr(&printer->servername, ntprinter->info_2->servername); /* servername*/ init_unistr(&printer->printername, ntprinter->info_2->printername); /* printername*/ @@ -2827,7 +2817,6 @@ static BOOL construct_printer_info_2(PRINTER_INFO_2 *printer, int snum) } free_a_printer(&ntprinter, 2); - SAFE_FREE(queue); return True; } @@ -4900,8 +4889,8 @@ WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO uint32 *returned = &r_u->returned; int snum; - print_queue_struct *queue=NULL; print_status_struct prt_status; + print_queue_struct *queue=NULL; /* that's an [in out] buffer */ spoolss_move_buffer(q_u->buffer, &r_u->buffer); @@ -4909,8 +4898,6 @@ WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO DEBUG(4,("_spoolss_enumjobs\n")); - ZERO_STRUCT(prt_status); - *needed=0; *returned=0; @@ -4957,12 +4944,9 @@ WERROR _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u uint32 command = q_u->command; struct current_user user; - print_status_struct prt_status; int snum; WERROR errcode = WERR_BADFUNC; - memset(&prt_status, 0, sizeof(prt_status)); - if (!get_printer_snum(p, handle, &snum)) { return WERR_BADFID; } @@ -6751,8 +6735,6 @@ WERROR _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_ DEBUG(5,("spoolss_getjob\n")); - memset(&prt_status, 0, sizeof(prt_status)); - *needed=0; if (!get_printer_snum(p, handle, &snum)) -- cgit From 4f53486d78102d8080293eeafd7b4ed701d81a2e Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 10 Dec 2001 05:03:17 +0000 Subject: Added client and server code for the GetPrintProcessorDirectory SPOOLSS rpc. This was supposed to fix a printer driver download bug but it didn't but it seemed a shame to trash all this code so I'm commiting it #ifdef'ed out in case someone needs it one day. (This used to be commit bef43656471741c6c10b12e7516c15de9ae76394) --- source3/rpc_server/srv_spoolss_nt.c | 86 +++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 0e98498fe3..dae3aa09c9 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -7,6 +7,7 @@ * Copyright (C) Jean François Micouleau 1998-2000. * Copyright (C) Jeremy Allison 2001. * Copyright (C) Gerald Carter 2000-2001. + * Copyright (C) Tim Potter 2001. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -7073,4 +7074,89 @@ done: return result; } +/**************************************************************************** +****************************************************************************/ + +/* Disabled because it doesn't fix the bug I am looking at but it would be + a shame to throw away the code. -tpot */ + +#if 0 + +static void fill_printprocessordirectory_1(PRINTPROCESSOR_DIRECTORY_1 *info, char *name) +{ + init_unistr(&info->name, name); +} + +static WERROR getprintprocessordirectory_level_1(UNISTR2 *name, + UNISTR2 *environment, + NEW_BUFFER *buffer, + uint32 offered, + uint32 *needed) +{ + pstring path; + pstring long_archi; + pstring short_archi; + PRINTPROCESSOR_DIRECTORY_1 *info=NULL; + + unistr2_to_ascii(long_archi, environment, sizeof(long_archi)-1); + + if (get_short_archi(short_archi, long_archi)==FALSE) + return WERR_INVALID_ENVIRONMENT; + + if((info=(PRINTPROCESSOR_DIRECTORY_1 *)malloc(sizeof(PRINTPROCESSOR_DIRECTORY_1))) == NULL) + return WERR_NOMEM; + + /* Not sure what to return here - are UNC names valid here?. + Windows returns the string: C:\WINNT\System32\spool\PRTPROCS\W32X86 + which is pretty bogus for a RPC. */ + + slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", global_myname, short_archi); + + DEBUG(4,("print processor directory: [%s]\n", path)); + + fill_printprocessordirectory_1(info, path); + + *needed += spoolss_size_printprocessordirectory_info_1(info); + + if (!alloc_buffer_size(buffer, *needed)) { + safe_free(info); + return WERR_INSUFFICIENT_BUFFER; + } + + smb_io_printprocessordirectory_1("", buffer, info, 0); + safe_free(info); + + if (*needed > offered) + return WERR_INSUFFICIENT_BUFFER; + else + return WERR_OK; +} + +WERROR _spoolss_getprintprocessordirectory(pipes_struct *p, SPOOL_Q_GETPRINTPROCESSORDIRECTORY *q_u, SPOOL_R_GETPRINTPROCESSORDIRECTORY *r_u) +{ + uint32 level = q_u->level; + NEW_BUFFER *buffer = NULL; + uint32 offered = q_u->offered; + uint32 *needed = &r_u->needed; + + /* that's an [in out] buffer */ + spoolss_move_buffer(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + + DEBUG(5,("_spoolss_getprintprocessordirectory\n")); + + *needed=0; + + switch(level) { + case 1: + return getprintprocessordirectory_level_1 + (&q_u->name, &q_u->environment, buffer, offered, needed); + default: + return WERR_UNKNOWN_LEVEL; + } + + return WERR_ACCESS_DENIED; +} + +#endif -- cgit From 4ad930ad5ea47e9f543fb55a844d1d74fb7912cc Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 13 Dec 2001 16:35:43 +0000 Subject: merge from appliance_head (This used to be commit 423554fd71b3c9718fc3a21006da9ce6371fc845) --- source3/rpc_server/srv_spoolss_nt.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index dae3aa09c9..cd47f6a130 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6912,6 +6912,10 @@ WERROR _spoolss_enumprinterkey(pipes_struct *p, SPOOL_Q_ENUMPRINTERKEY *q_u, SPO enumkeys[i] = (uint16)(*ptr); ptr++; } + + /* tag of with 2 '\0's */ + enumkeys[i++] = '\0'; + enumkeys[i] = '\0'; if (!make_spoolss_buffer5(p->mem_ctx, &r_u->keys, ENUMERATED_KEY_SIZE, enumkeys)) return WERR_BADFILE; -- cgit From 14d7f43590a9384c34d49483c4ee14b4ad3d5fe7 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 14 Dec 2001 04:43:31 +0000 Subject: FALSE -> False (This used to be commit dbdbf7cd077a8a20610ee2c62240170b420ebe6c) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index cd47f6a130..87d076ae8c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -7104,7 +7104,7 @@ static WERROR getprintprocessordirectory_level_1(UNISTR2 *name, unistr2_to_ascii(long_archi, environment, sizeof(long_archi)-1); - if (get_short_archi(short_archi, long_archi)==FALSE) + if (get_short_archi(short_archi, long_archi)==False) return WERR_INVALID_ENVIRONMENT; if((info=(PRINTPROCESSOR_DIRECTORY_1 *)malloc(sizeof(PRINTPROCESSOR_DIRECTORY_1))) == NULL) -- cgit From abcd1cad3af7ee111f711544407222951e33238e Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 14 Dec 2001 20:38:04 +0000 Subject: ChangeID fixe from APPLIANCE_HEAD (This used to be commit 096d06a961e3a3e6f6952754875b83558448f449) --- source3/rpc_server/srv_spoolss_nt.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 87d076ae8c..5794f1de04 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6288,6 +6288,11 @@ WERROR _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM return WERR_BADFID; } + /* + * FIXME!! Feels like there should be an access check here, but haven't + * had time to verify. --jerry + */ + /* can't add if builtin */ if (get_a_builtin_ntform(&form->name,&tmpForm)) { return WERR_INVALID_PARAM; -- cgit From bf65820af242786bd66d814fc3e9d89920a49f8e Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Fri, 21 Dec 2001 00:37:49 +0000 Subject: Add an output parameter to message_send_all that says how many messages were sent, so you know how many replies to expect. Const and doc religion. (This used to be commit 22e510ea0d69356be4fd2fa5ad9e9f4e84f62337) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 5794f1de04..3fe21eb968 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -690,7 +690,7 @@ static BOOL srv_spoolss_sendnotify(pipes_struct *p, POLICY_HND *handle) /*srv_spoolss_receive_message(printer);*/ DEBUG(10,("srv_spoolss_sendnotify: Sending message about printer %s\n", printer )); - message_send_all(conn_tdb_ctx(), MSG_PRINTER_NOTIFY, printer, strlen(printer) + 1, False); /* Null terminate... */ + broadcast_printer_notify(printer); return True; } -- cgit From 4702494dce15d4158fd17720d843ff5211ce1715 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 8 Jan 2002 00:46:56 +0000 Subject: Added get_called_name() function, which replaces global_myname in printing code (one less global, hurrah !) - to allow NetBIOS aliasing to be used with point and print. Jeremy. (This used to be commit 10d72f0b01e5950c667f3f73dff1b4da5b675ea3) --- source3/rpc_server/srv_spoolss_nt.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 3fe21eb968..96f44c4b8b 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -29,8 +29,6 @@ #include "includes.h" -extern pstring global_myname; - #ifndef MAX_OPEN_PRINTER_EXS #define MAX_OPEN_PRINTER_EXS 50 #endif @@ -1447,7 +1445,7 @@ static void spoolss_notify_server_name(int snum, pstring temp_name, temp; uint32 len; - slprintf(temp_name, sizeof(temp_name)-1, "\\\\%s", global_myname); + slprintf(temp_name, sizeof(temp_name)-1, "\\\\%s", get_called_name()); len = rpcstr_push(temp, temp_name, sizeof(temp)-2, STR_TERMINATE); @@ -2573,7 +2571,7 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum) init_unistr(&printer->printername, chaine); - slprintf(chaine,sizeof(chaine)-1,"\\\\%s", global_myname); + slprintf(chaine,sizeof(chaine)-1,"\\\\%s", get_called_name()); init_unistr(&printer->servername, chaine); printer->cjobs = count; @@ -2641,12 +2639,12 @@ static BOOL construct_printer_info_1(uint32 flags, PRINTER_INFO_1 *printer, int if (*ntprinter->info_2->comment == '\0') { init_unistr(&printer->comment, lp_comment(snum)); - slprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",global_myname, ntprinter->info_2->printername, + slprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",get_called_name(), ntprinter->info_2->printername, ntprinter->info_2->drivername, lp_comment(snum)); } else { init_unistr(&printer->comment, ntprinter->info_2->comment); /* saved comment. */ - slprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",global_myname, ntprinter->info_2->printername, + slprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",get_called_name(), ntprinter->info_2->printername, ntprinter->info_2->drivername, ntprinter->info_2->comment); } @@ -2981,8 +2979,8 @@ static WERROR enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, *returned=1; - slprintf(printername, sizeof(printername)-1,"Windows NT Remote Printers!!\\\\%s", global_myname); - slprintf(desc, sizeof(desc)-1,"%s", global_myname); + slprintf(printername, sizeof(printername)-1,"Windows NT Remote Printers!!\\\\%s", get_called_name()); + slprintf(desc, sizeof(desc)-1,"%s", get_called_name()); slprintf(comment, sizeof(comment)-1, "Logged on Domain"); init_unistr(&printer->description, desc); @@ -3871,7 +3869,7 @@ WERROR _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_ *servermajorversion=0; *serverminorversion=0; - pstrcpy(servername, global_myname); + pstrcpy(servername, get_called_name()); unistr2_to_ascii(architecture, uni_arch, sizeof(architecture)-1); if (!get_printer_snum(p, handle, &snum)) @@ -4200,9 +4198,9 @@ static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) info->servername, info->printername, info->sharename, info->portname, info->drivername, info->comment, info->location)); /* we force some elements to "correct" values */ - slprintf(info->servername, sizeof(info->servername)-1, "\\\\%s", global_myname); + slprintf(info->servername, sizeof(info->servername)-1, "\\\\%s", get_called_name()); slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s", - global_myname, lp_servicename(snum)); + get_called_name(), lp_servicename(snum)); fstrcpy(info->sharename, lp_servicename(snum)); info->attributes = PRINTER_ATTRIBUTE_SHARED \ | PRINTER_ATTRIBUTE_LOCAL \ @@ -4226,7 +4224,7 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) /* build driver path... only 9X architecture is needed for legacy reasons */ slprintf(driverlocation, sizeof(driverlocation)-1, "\\\\%s\\print$\\WIN40\\0", - global_myname); + get_called_name()); /* change \ to \\ for the shell */ all_string_sub(driverlocation,"\\","\\\\",sizeof(pstring)); @@ -4704,7 +4702,7 @@ static void fill_job_info_1(JOB_INFO_1 *job_info, print_queue_struct *queue, struct tm *t; t=gmtime(&queue->time); - slprintf(temp_name, sizeof(temp_name)-1, "\\\\%s", global_myname); + slprintf(temp_name, sizeof(temp_name)-1, "\\\\%s", get_called_name()); job_info->jobid=queue->job; init_unistr(&job_info->printername, lp_servicename(snum)); @@ -4733,11 +4731,11 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, struct tm *t; t=gmtime(&queue->time); - slprintf(temp_name, sizeof(temp_name)-1, "\\\\%s", global_myname); + slprintf(temp_name, sizeof(temp_name)-1, "\\\\%s", get_called_name()); job_info->jobid=queue->job; - slprintf(chaine, sizeof(chaine)-1, "\\\\%s\\%s", global_myname, ntprinter->info_2->printername); + slprintf(chaine, sizeof(chaine)-1, "\\\\%s\\%s", get_called_name(), ntprinter->info_2->printername); init_unistr(&job_info->printername, chaine); @@ -5251,7 +5249,7 @@ WERROR _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS buffer = r_u->buffer; DEBUG(4,("_spoolss_enumprinterdrivers\n")); - fstrcpy(servername, global_myname); + fstrcpy(servername, get_called_name()); *needed=0; *returned=0; @@ -5752,7 +5750,7 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ return WERR_ACCESS_DENIED; } - slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname, + slprintf(name, sizeof(name)-1, "\\\\%s\\%s", get_called_name(), printer->info_2->sharename); if ((snum = print_queue_snum(printer->info_2->sharename)) == -1) { @@ -5900,7 +5898,7 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen if((info=(DRIVER_DIRECTORY_1 *)malloc(sizeof(DRIVER_DIRECTORY_1))) == NULL) return WERR_NOMEM; - slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", global_myname, short_archi); + slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", get_called_name(), short_archi); DEBUG(4,("printer driver directory: [%s]\n", path)); @@ -7119,7 +7117,7 @@ static WERROR getprintprocessordirectory_level_1(UNISTR2 *name, Windows returns the string: C:\WINNT\System32\spool\PRTPROCS\W32X86 which is pretty bogus for a RPC. */ - slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", global_myname, short_archi); + slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", get_called_name(), short_archi); DEBUG(4,("print processor directory: [%s]\n", path)); -- cgit From 1d40138232a22b78f088847d0d72d6ddec17a65e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 11 Jan 2002 23:33:12 +0000 Subject: Round and round we go.... Jeremy. (This used to be commit 2603ab3c6870f3697751b887e940910713f08985) --- source3/rpc_server/srv_spoolss_nt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 96f44c4b8b..adc9546530 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6177,7 +6177,7 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP convert_specific_param(¶m, value , type, data, real_len); - +#if 0 if (get_specific_param(*printer, 2, param->value, &old_param.data, &old_param.type, (uint32 *)&old_param.data_len)) { @@ -6191,6 +6191,7 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP goto done; } } +#endif unlink_specific_param_if_exist(printer->info_2, param); -- cgit From c9d350a736ca71f838cf19386b04e972200ee595 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 12 Jan 2002 02:37:54 +0000 Subject: Added PRINTER_INFO_4/PRINTER_INFO_5, we're seeing level 5 requested on the wire... so. Jeremy. (This used to be commit b63b76297835ab8227b98925fa8120ffce1a37d9) --- source3/rpc_server/srv_spoolss_nt.c | 113 ++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index adc9546530..94444e0b13 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2873,6 +2873,49 @@ static BOOL construct_printer_info_3(PRINTER_INFO_3 **pp_printer, int snum) return True; } +/******************************************************************** + * construct_printer_info_4 + * fill a printer_info_4 struct + ********************************************************************/ + +static BOOL construct_printer_info_4(PRINTER_INFO_4 *printer, int snum) +{ + NT_PRINTER_INFO_LEVEL *ntprinter = NULL; + + if (!W_ERROR_IS_OK(get_a_printer(&ntprinter, 2, lp_servicename(snum)))) + return False; + + init_unistr(&printer->printername, ntprinter->info_2->printername); /* printername*/ + init_unistr(&printer->servername, ntprinter->info_2->servername); /* servername*/ + printer->attributes = ntprinter->info_2->attributes; + + free_a_printer(&ntprinter, 2); + return True; +} + +/******************************************************************** + * construct_printer_info_5 + * fill a printer_info_5 struct + ********************************************************************/ + +static BOOL construct_printer_info_5(PRINTER_INFO_5 *printer, int snum) +{ + NT_PRINTER_INFO_LEVEL *ntprinter = NULL; + + if (!W_ERROR_IS_OK(get_a_printer(&ntprinter, 2, lp_servicename(snum)))) + return False; + + init_unistr(&printer->printername, ntprinter->info_2->printername); /* printername*/ + init_unistr(&printer->portname, ntprinter->info_2->portname); /* portname */ + printer->attributes = ntprinter->info_2->attributes; + printer->device_not_selected_timeout = 0x3a98; + printer->transmission_retry_timeout = 0xafc8; + + free_a_printer(&ntprinter, 2); + return True; +} + + /******************************************************************** Spoolss_enumprinters. ********************************************************************/ @@ -3333,6 +3376,72 @@ static WERROR getprinter_level_3(int snum, NEW_BUFFER *buffer, uint32 offered, u return WERR_OK; } +/**************************************************************************** +****************************************************************************/ +static WERROR getprinter_level_4(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +{ + PRINTER_INFO_4 *printer=NULL; + + if((printer=(PRINTER_INFO_4*)malloc(sizeof(PRINTER_INFO_4)))==NULL) + return WERR_NOMEM; + + if (!construct_printer_info_4(printer, snum)) + return WERR_NOMEM; + + /* check the required size. */ + *needed += spoolss_size_printer_info_4(printer); + + if (!alloc_buffer_size(buffer, *needed)) { + free_printer_info_4(printer); + return WERR_INSUFFICIENT_BUFFER; + } + + /* fill the buffer with the structures */ + smb_io_printer_info_4("", buffer, printer, 0); + + /* clear memory */ + free_printer_info_4(printer); + + if (*needed > offered) { + return WERR_INSUFFICIENT_BUFFER; + } + + return WERR_OK; +} + +/**************************************************************************** +****************************************************************************/ +static WERROR getprinter_level_5(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +{ + PRINTER_INFO_5 *printer=NULL; + + if((printer=(PRINTER_INFO_5*)malloc(sizeof(PRINTER_INFO_5)))==NULL) + return WERR_NOMEM; + + if (!construct_printer_info_5(printer, snum)) + return WERR_NOMEM; + + /* check the required size. */ + *needed += spoolss_size_printer_info_5(printer); + + if (!alloc_buffer_size(buffer, *needed)) { + free_printer_info_5(printer); + return WERR_INSUFFICIENT_BUFFER; + } + + /* fill the buffer with the structures */ + smb_io_printer_info_5("", buffer, printer, 0); + + /* clear memory */ + free_printer_info_5(printer); + + if (*needed > offered) { + return WERR_INSUFFICIENT_BUFFER; + } + + return WERR_OK; +} + /**************************************************************************** ****************************************************************************/ @@ -3364,6 +3473,10 @@ WERROR _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GET return getprinter_level_2(snum, buffer, offered, needed); case 3: return getprinter_level_3(snum, buffer, offered, needed); + case 4: + return getprinter_level_4(snum, buffer, offered, needed); + case 5: + return getprinter_level_5(snum, buffer, offered, needed); } return WERR_UNKNOWN_LEVEL; } -- cgit From 5fa0da0ba5e466eb5fe5f423393ae45dcd4d7237 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 15 Jan 2002 16:20:25 +0000 Subject: Missing assign fix from Bernt Nilsson bkn@ida.liu.se. Jeremy. (This used to be commit adf24a90e8b4d970d71fa8a6854edcf6deff9688) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 94444e0b13..2b41efcbf6 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -633,7 +633,7 @@ static void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size */ hl = NULL; - for ( p = get_first_pipe(); p; get_next_pipe(p)) { + for ( p = get_first_pipe(); p; p = get_next_pipe(p)) { if (strequal(p->name, "spoolss")) { hl = p->pipe_handles; break; -- cgit From bb6af711b8f9a525b74198abbe7f1c37014ca6f7 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sun, 20 Jan 2002 02:40:05 +0000 Subject: This is the current patch from Luke Leighton to add a degree of seperation betwen reading/writing the raw NamedPipe SMB packets and the matching operations inside smbd's RPC components. This patch is designed for no change in behaviour, and my tests hold that to be true. This patch does however allow for the future loadable modules interface to specify function pointers in replacement of the fixed state. The pipes_struct has been split into two peices, with smb_np_struct taking the information that should be generic to where the data ends up. Some other minor changes are made: we get another small helper function in util_sock.c and some of the original code has better failure debugs and variable use. (As per on-list comments). Andrew Bartlett (This used to be commit 8ef13cabdddf58b741886782297fb64b2fb7e489) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 2b41efcbf6..bdd2bbf31b 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -633,7 +633,7 @@ static void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size */ hl = NULL; - for ( p = get_first_pipe(); p; p = get_next_pipe(p)) { + for ( p = get_first_internal_pipe(); p; get_next_internal_pipe(p)) { if (strequal(p->name, "spoolss")) { hl = p->pipe_handles; break; -- cgit From 1182b7cd8cdfcb5065ed5ca65be4ebfd84f44b2a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 22 Jan 2002 19:45:17 +0000 Subject: Merge of fixes from 2.2. Jeremy. (This used to be commit 6406a42d012184f5289d4a2b1c07a55556635fe4) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index bdd2bbf31b..cffd88c3aa 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -316,7 +316,7 @@ static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) } return WERR_OK; -} +} /**************************************************************************** return the snum of a printer corresponding to an handle -- cgit From f0fe8ff18ad49ed9dee98a8a68cdb58275eb7beb Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 23 Jan 2002 11:47:19 +0000 Subject: Sync up startpageprinter with appliance. (This used to be commit 6025ab201aa34bbf4a7e897149ef6ba370a89703) --- source3/rpc_server/srv_spoolss_nt.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index cffd88c3aa..57521dc144 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4011,13 +4011,13 @@ WERROR _spoolss_startpageprinter(pipes_struct *p, SPOOL_Q_STARTPAGEPRINTER *q_u, Printer_entry *Printer = find_printer_index_by_hnd(p, handle); - if (Printer) { - Printer->page_started=True; - return WERR_OK; + if (!Printer) { + DEBUG(3,("Error in startpageprinter printer handle\n")); + return WERR_BADFID; } - DEBUG(3,("Error in startpageprinter printer handle\n")); - return WERR_BADFID; + Printer->page_started=True; + return WERR_OK; } /**************************************************************************** -- cgit From b3e5d34171b8e5e6320c28379cb0021bf857efa5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 25 Jan 2002 18:27:40 +0000 Subject: Make systemtime work for spooling on bigendian systems. Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au. Jeremy. (This used to be commit 5f4de275a3a63a95e76d077ffc94321a078833bf) --- source3/rpc_server/srv_spoolss_nt.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 57521dc144..8a13ebe19e 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2009,8 +2009,9 @@ static void spoolss_notify_job_size(int snum, } /******************************************************************* - * fill a notify_info_data with job position + Fill a notify_info_data with job position. ********************************************************************/ + static void spoolss_notify_job_position(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -2022,8 +2023,9 @@ static void spoolss_notify_job_position(int snum, } /******************************************************************* - * fill a notify_info_data with submitted time + Fill a notify_info_data with submitted time. ********************************************************************/ + static void spoolss_notify_submitted_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -2033,6 +2035,7 @@ static void spoolss_notify_submitted_time(int snum, struct tm *t; uint32 len; SYSTEMTIME st; + char *p; t=gmtime(&queue->time); @@ -2047,7 +2050,21 @@ static void spoolss_notify_submitted_time(int snum, } make_systemtime(&st, t); - memcpy(data->notify_data.data.string,&st,len); + + /* + * Systemtime must be linearized as a set of UINT16's. + * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au + */ + + p = (char *)data->notify_data.data.string; + SSVAL(p, 0, st.year); + SSVAL(p, 2, st.month); + SSVAL(p, 4, st.dayofweek); + SSVAL(p, 6, st.day); + SSVAL(p, 8, st.hour); + SSVAL(p, 10, st.minute); + SSVAL(p, 12, st.second); + SSVAL(p, 14, st.milliseconds); } #define END 65535 -- cgit From 5b0dca4998837231b931aa9a4a546079454d780e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 26 Jan 2002 01:20:38 +0000 Subject: Fixed ADDPRINTEREX to take a devmode and a security descriptor... Jeremy. (This used to be commit 27f65b3aad13ecd33bbb84048d70e3dde212f278) --- source3/rpc_server/srv_spoolss_nt.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 8a13ebe19e..c96612eef2 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -5843,7 +5843,7 @@ WERROR _spoolss_enumports( pipes_struct *p, SPOOL_Q_ENUMPORTS *q_u, SPOOL_R_ENUM ****************************************************************************/ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_srv_name, const SPOOL_PRINTER_INFO_LEVEL *info, - uint32 unk0, uint32 unk1, uint32 unk2, uint32 unk3, + DEVICEMODE *devmode, SEC_DESC_BUF *sec_desc_buf, uint32 user_switch, const SPOOL_USER_CTR *user, POLICY_HND *handle) { @@ -5939,10 +5939,8 @@ WERROR _spoolss_addprinterex( pipes_struct *p, SPOOL_Q_ADDPRINTEREX *q_u, SPOOL_ UNISTR2 *uni_srv_name = &q_u->server_name; uint32 level = q_u->level; SPOOL_PRINTER_INFO_LEVEL *info = &q_u->info; - uint32 unk0 = q_u->unk0; - uint32 unk1 = q_u->unk1; - uint32 unk2 = q_u->unk2; - uint32 unk3 = q_u->unk3; + DEVICEMODE *devmode = q_u->devmode_ctr.devmode; + SEC_DESC_BUF *sdb = q_u->secdesc_ctr; uint32 user_switch = q_u->user_switch; SPOOL_USER_CTR *user = &q_u->user_ctr; POLICY_HND *handle = &r_u->handle; @@ -5954,7 +5952,7 @@ WERROR _spoolss_addprinterex( pipes_struct *p, SPOOL_Q_ADDPRINTEREX *q_u, SPOOL_ return WERR_UNKNOWN_LEVEL; case 2: return spoolss_addprinterex_level_2(p, uni_srv_name, info, - unk0, unk1, unk2, unk3, + devmode, sdb, user_switch, user, handle); default: return WERR_UNKNOWN_LEVEL; -- cgit From 485b4ff5ecf40620a0a6fedc0929dacdb28876a2 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sat, 26 Jan 2002 22:27:12 +0000 Subject: merge from APPLIANCE_HEAD (This used to be commit e3b87ffc8c26f9fd4c3e8181897b8812b7dc4ab6) --- source3/rpc_server/srv_spoolss_nt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index c96612eef2..02f7085119 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4597,7 +4597,7 @@ static BOOL nt_printer_info_level_equal(NT_PRINTER_INFO_LEVEL *p1, PI_CHECK_INT(averageppm); /* Yuck - don't check the printername or servername as the - add_a_printer() code plays games with them. You can't + mod_a_printer() code plays games with them. You can't change the printername or the sharename through this interface in Samba. */ @@ -4735,7 +4735,7 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, } /* Update printer info */ - result = add_a_printer(*printer, 2); + result = mod_a_printer(*printer, 2); done: free_a_printer(&printer, 2); @@ -5911,7 +5911,7 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ set_driver_init(printer, 2); /* write the ASCII on disk */ - err = add_a_printer(*printer, 2); + err = mod_a_printer(*printer, 2); if (!W_ERROR_IS_OK(err)) { free_a_printer(&printer,2); return err; -- cgit From cd68afe31256ad60748b34f7318a180cfc2127cc Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 30 Jan 2002 06:08:46 +0000 Subject: Removed version number from file header. Changed "SMB/Netbios" to "SMB/CIFS" in file header. (This used to be commit 6a58c9bd06d0d7502a24bf5ce5a2faf0a146edfa) --- source3/rpc_server/srv_spoolss_nt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 02f7085119..bba7c54b81 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1,6 +1,5 @@ /* - * Unix SMB/Netbios implementation. - * Version 1.9. + * Unix SMB/CIFS implementation. * RPC Pipe client / server routines * Copyright (C) Andrew Tridgell 1992-2000, * Copyright (C) Luke Kenneth Casson Leighton 1996-2000, -- cgit From 8fff9a4b9e9104815ac83a768e0ab258e788cf5a Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 31 Jan 2002 11:44:00 +0000 Subject: Added administrator access check for server side add, delete and setform rpcs. The only one I have been able to verify is addform - can't get the client side routines working properly yet. )-: (This used to be commit 3cd97d65dea428382104ebde63eaf660aa3942fb) --- source3/rpc_server/srv_spoolss_nt.c | 44 ++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index bba7c54b81..69ecf5cc77 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6402,8 +6402,7 @@ WERROR _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM /* uint32 level = q_u->level; - notused. */ FORM *form = &q_u->form; nt_forms_struct tmpForm; - - int count=0; + int count=0, snum; nt_forms_struct *list=NULL; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); @@ -6414,14 +6413,19 @@ WERROR _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM return WERR_BADFID; } - /* - * FIXME!! Feels like there should be an access check here, but haven't - * had time to verify. --jerry - */ + /* Must be administrator to add a form */ + + if (!get_printer_snum(p, handle, &snum)) + return WERR_BADFID; + + if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { + DEBUG(0, ("_spoolss_addform: Access denied\n")); + return WERR_ACCESS_DENIED; + } /* can't add if builtin */ if (get_a_builtin_ntform(&form->name,&tmpForm)) { - return WERR_INVALID_PARAM; + return WERR_FILE_EXISTS; } count=get_ntforms(&list); @@ -6442,7 +6446,7 @@ WERROR _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE POLICY_HND *handle = &q_u->handle; UNISTR2 *form_name = &q_u->name; nt_forms_struct tmpForm; - int count=0; + int count=0, snum; WERROR ret = WERR_OK; nt_forms_struct *list=NULL; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); @@ -6454,6 +6458,16 @@ WERROR _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE return WERR_BADFID; } + /* Must be administrator to set a form */ + + if (!get_printer_snum(p, handle, &snum)) + return WERR_BADFID; + + if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { + DEBUG(0, ("_spoolss_addform: Access denied\n")); + return WERR_ACCESS_DENIED; + } + /* can't delete if builtin */ if (get_a_builtin_ntform(form_name,&tmpForm)) { return WERR_INVALID_PARAM; @@ -6478,8 +6492,7 @@ WERROR _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM * /* uint32 level = q_u->level; - notused. */ FORM *form = &q_u->form; nt_forms_struct tmpForm; - - int count=0; + int count=0, snum; nt_forms_struct *list=NULL; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); @@ -6489,6 +6502,17 @@ WERROR _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM * DEBUG(0,("_spoolss_setform: Invalid handle (%s).\n", OUR_HANDLE(handle))); return WERR_BADFID; } + + /* Must be administrator to set a form */ + + if (!get_printer_snum(p, handle, &snum)) + return WERR_BADFID; + + if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { + DEBUG(0, ("_spoolss_addform: Access denied\n")); + return WERR_ACCESS_DENIED; + } + /* can't set if builtin */ if (get_a_builtin_ntform(&form->name,&tmpForm)) { return WERR_INVALID_PARAM; -- cgit From 03cfb31ad931c65ca8c5b97c620f6e71bf5cac82 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 9 Feb 2002 04:10:24 +0000 Subject: Bring printing in HEAD inline with 2.2.x and app-head. Jeremy. (This used to be commit 771ef92fc6e43725b7cc351079998a8acb74abef) --- source3/rpc_server/srv_spoolss_nt.c | 491 +++++++++++++++++++++++------------- 1 file changed, 320 insertions(+), 171 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 69ecf5cc77..f76b78f116 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1,12 +1,12 @@ /* - * Unix SMB/CIFS implementation. + * Unix SMB/Netbios implementation. + * Version 1.9. * RPC Pipe client / server routines * Copyright (C) Andrew Tridgell 1992-2000, * Copyright (C) Luke Kenneth Casson Leighton 1996-2000, * Copyright (C) Jean François Micouleau 1998-2000. * Copyright (C) Jeremy Allison 2001. * Copyright (C) Gerald Carter 2000-2001. - * Copyright (C) Tim Potter 2001. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,6 +32,7 @@ #define MAX_OPEN_PRINTER_EXS 50 #endif +#define MAGIC_DISPLAY_FREQUENCY 0xfade2bad #define PHANTOM_DEVMODE_KEY "_p_f_a_n_t_0_m_" #define PRINTER_HANDLE_IS_PRINTER 0 #define PRINTER_HANDLE_IS_PRINTSERVER 1 @@ -48,9 +49,10 @@ struct table_node { /* and the notify info asked about */ /* that's the central struct */ typedef struct _Printer{ + struct _Printer *prev, *next; BOOL document_started; BOOL page_started; - int jobid; /* jobid in printing backend */ + int jobid; /* jobid in printing backend */ BOOL printer_type; union { fstring handlename; @@ -73,6 +75,8 @@ typedef struct _Printer{ } client; } Printer_entry; +static Printer_entry *printers_list; + typedef struct _counter_printer_0 { ubi_dlNode Next; ubi_dlNode Prev; @@ -86,7 +90,8 @@ static ubi_dlList counter_list; static struct cli_state cli; static uint32 smb_connections=0; -#define OUR_HANDLE(hnd) ((hnd==NULL)?"NULL":(IVAL(hnd->data5,4)==(uint32)sys_getpid()?"OURS":"OTHER")) +#define OUR_HANDLE(hnd) (((hnd)==NULL)?"NULL":(IVAL((hnd)->data5,4)==(uint32)sys_getpid()?"OURS":"OTHER")), \ +((unsigned int)IVAL((hnd)->data5,4)),((unsigned int)sys_getpid()) /* translate between internal status numbers and NT status numbers */ static int nt_printj_status(int v) @@ -193,6 +198,9 @@ static void free_printer_entry(void *ptr) Printer->notify.option=NULL; Printer->notify.client_connected=False; + /* Remove from the internal list. */ + DLIST_REMOVE(printers_list, Printer); + SAFE_FREE(Printer); } @@ -234,7 +242,7 @@ static Printer_entry *find_printer_index_by_hnd(pipes_struct *p, POLICY_HND *hnd Printer_entry *find_printer = NULL; if(!find_policy_by_hnd(p,hnd,(void **)&find_printer)) { - DEBUG(3,("find_printer_index_by_hnd: Printer handle not found: ")); + DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: ")); return NULL; } @@ -242,7 +250,7 @@ static Printer_entry *find_printer_index_by_hnd(pipes_struct *p, POLICY_HND *hnd } /**************************************************************************** - close printer index by handle + Close printer index by handle. ****************************************************************************/ static BOOL close_printer_handle(pipes_struct *p, POLICY_HND *hnd) @@ -250,7 +258,7 @@ static BOOL close_printer_handle(pipes_struct *p, POLICY_HND *hnd) Printer_entry *Printer = find_printer_index_by_hnd(p, hnd); if (!Printer) { - DEBUG(0,("close_printer_handle: Invalid handle (%s)\n", OUR_HANDLE(hnd))); + DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(hnd))); return False; } @@ -260,14 +268,15 @@ static BOOL close_printer_handle(pipes_struct *p, POLICY_HND *hnd) } /**************************************************************************** - delete a printer given a handle + Delete a printer given a handle. ****************************************************************************/ + static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) { Printer_entry *Printer = find_printer_index_by_hnd(p, hnd); if (!Printer) { - DEBUG(0,("delete_printer_handle: Invalid handle (%s)\n", OUR_HANDLE(hnd))); + DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(hnd))); return WERR_BADFID; } @@ -325,7 +334,7 @@ static BOOL get_printer_snum(pipes_struct *p, POLICY_HND *hnd, int *number) Printer_entry *Printer = find_printer_index_by_hnd(p, hnd); if (!Printer) { - DEBUG(0,("get_printer_snum: Invalid handle (%s)\n", OUR_HANDLE(hnd))); + DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(hnd))); return False; } @@ -349,7 +358,7 @@ static BOOL set_printer_hnd_accesstype(pipes_struct *p, POLICY_HND *hnd, uint32 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd); if (!Printer) { - DEBUG(0,("set_printer_hnd_accesstype: Invalid handle (%s)", OUR_HANDLE(hnd))); + DEBUG(2,("set_printer_hnd_accesstype: Invalid handle (%s:%u:%u)", OUR_HANDLE(hnd))); return False; } @@ -532,6 +541,9 @@ static BOOL open_printer_hnd(pipes_struct *p, POLICY_HND *hnd, char *name) new_printer->notify.option=NULL; + /* Add to the internal list. */ + DLIST_ADD(printers_list, new_printer); + if (!create_policy_hnd(p, hnd, free_printer_entry, new_printer)) { SAFE_FREE(new_printer); return False; @@ -553,7 +565,7 @@ static BOOL open_printer_hnd(pipes_struct *p, POLICY_HND *hnd, char *name) } /******************************************************************** - Return True is the handle is a print server. + Return True if the handle is a print server. ********************************************************************/ static BOOL handle_is_printserver(pipes_struct *p, POLICY_HND *handle) @@ -604,91 +616,62 @@ static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size) } /*************************************************************************** - receive the notify message + Receive the notify message. ****************************************************************************/ static void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size_t len) { - fstring printer; + Printer_entry *find_printer; WERROR status; - struct pipes_struct *p; - struct policy *pol; - struct handle_list *hl; - - *printer = '\0'; - fstrcpy(printer,buf); + char msg[8]; + uint32 low, high; - if (len == 0) { - DEBUG(0,("srv_spoolss_receive_message: got null message !\n")); + if (len != sizeof(msg)) { + DEBUG(2,("srv_spoolss_receive_message: got incorrect message size (%u)!\n", (unsigned int)len)); return; } - DEBUG(10,("srv_spoolss_receive_message: Got message about printer %s\n", printer )); - - /* - * We need to enumerate all printers. The handle list is shared - * across pipes of the same name, so just find the first open - * spoolss pipe. - */ - - hl = NULL; - for ( p = get_first_internal_pipe(); p; get_next_internal_pipe(p)) { - if (strequal(p->name, "spoolss")) { - hl = p->pipe_handles; - break; - } - } + memcpy(msg, buf, len); + low = IVAL(msg,0); + high = IVAL(msg,4); - if (!hl) { - DEBUG(0,("srv_spoolss_receive_message: no handle list on spoolss pipe !\n")); - return; - } + DEBUG(10,("srv_spoolss_receive_message: Got message printer change low=0x%x high=0x%x\n", (unsigned int)low, + (unsigned int)high )); - /* Iterate the printer list on this pipe. */ - for (pol = hl->Policy; pol; pol = pol->next ) { - Printer_entry *find_printer = (Printer_entry *)pol->data_ptr; + find_printer = printers_list; - if (!find_printer) - continue; + /* Iterate the printer list */ + for(; find_printer; find_printer = find_printer->next) { /* - * if the entry is the given printer or if it's a printerserver - * we send the message + * If the entry has a connected client we send the message. */ - if (find_printer->printer_type==PRINTER_HANDLE_IS_PRINTER) - if (strcmp(find_printer->dev.handlename, printer)) - continue; - if (find_printer->notify.client_connected==True) - cli_spoolss_reply_rrpcn(&cli, &find_printer->notify.client_hnd, PRINTER_CHANGE_ALL, 0x0, &status); + if (find_printer->notify.client_connected==True) { + DEBUG(10,("srv_spoolss_receive_message: printerserver [%s]\n", find_printer->dev.printerservername )); + if (cli_spoolss_reply_rrpcn(&cli, &find_printer->notify.client_hnd, low, high, &status)) + DEBUG(10,("srv_spoolss_receive_message: cli_spoolss_reply_rrpcn status = 0x%x\n", + (unsigned int)W_ERROR_V(status))); + else + DEBUG(10,("srv_spoolss_receive_message: cli_spoolss_reply_rrpcn failed\n")); + } } } /*************************************************************************** - send a notify event + Send a notify event. ****************************************************************************/ -static BOOL srv_spoolss_sendnotify(pipes_struct *p, POLICY_HND *handle) -{ - fstring printer; - - Printer_entry *Printer=find_printer_index_by_hnd(p, handle); - - if (!Printer) { - DEBUG(0,("srv_spoolss_sendnotify: Invalid handle (%s).\n", OUR_HANDLE(handle))); - return False; - } - if (Printer->printer_type==PRINTER_HANDLE_IS_PRINTER) - fstrcpy(printer, Printer->dev.handlename); - else - fstrcpy(printer, ""); - - /*srv_spoolss_receive_message(printer);*/ - DEBUG(10,("srv_spoolss_sendnotify: Sending message about printer %s\n", printer )); +static BOOL srv_spoolss_sendnotify(uint32 high, uint32 low) +{ + char msg[8]; - broadcast_printer_notify(printer); + SIVAL(msg,0,low); + SIVAL(msg,4,high); + DEBUG(10,("srv_spoolss_sendnotify: printer change low=0x%x high=0x%x\n", low, high)); + message_send_all(conn_tdb_ctx(), MSG_PRINTER_NOTIFY, msg, sizeof(msg), False, NULL); return True; } @@ -1021,7 +1004,7 @@ static WERROR _spoolss_enddocprinter_internal(pipes_struct *p, POLICY_HND *handl Printer_entry *Printer=find_printer_index_by_hnd(p, handle); if (!Printer) { - DEBUG(0,("_spoolss_enddocprinter_internal: Invalid handle (%s)\n", OUR_HANDLE(handle))); + DEBUG(2,("_spoolss_enddocprinter_internal: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle))); return WERR_BADFID; } @@ -1045,11 +1028,16 @@ WERROR _spoolss_closeprinter(pipes_struct *p, SPOOL_Q_CLOSEPRINTER *q_u, SPOOL_R if (Printer && Printer->document_started) _spoolss_enddocprinter_internal(p, handle); /* print job was not closed */ - memcpy(&r_u->handle, &q_u->handle, sizeof(r_u->handle)); - if (!close_printer_handle(p, handle)) return WERR_BADFID; + /* clear the returned printer handle. Observed behavior + from Win2k server. Don't think this really matters. + Previous code just copied the value of the closed + handle. --jerry */ + + memset(&r_u->handle, '\0', sizeof(r_u->handle)); + return WERR_OK; } @@ -1071,8 +1059,10 @@ WERROR _spoolss_deleteprinter(pipes_struct *p, SPOOL_Q_DELETEPRINTER *q_u, SPOOL result = delete_printer_handle(p, handle); + update_c_setprinter(FALSE); + if (W_ERROR_IS_OK(result)) { - srv_spoolss_sendnotify(p, handle); + srv_spoolss_sendnotify(0, PRINTER_CHANGE_DELETE_PRINTER); } return result; @@ -1160,6 +1150,14 @@ static BOOL getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint32 DEBUG(8,("getprinterdata_printer_server:%s\n", value)); + if (!strcmp(value, "W3SvcInstalled")) { + *type = 0x4; + if((*data = (uint8 *)talloc_zero(ctx, 4*sizeof(uint8) )) == NULL) + return False; + *needed = 0x4; + return True; + } + if (!strcmp(value, "BeepEnabled")) { *type = 0x4; if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) @@ -1245,7 +1243,7 @@ static BOOL getprinterdata_printer(pipes_struct *p, TALLOC_CTX *ctx, POLICY_HND DEBUG(5,("getprinterdata_printer\n")); if (!Printer) { - DEBUG(0,("getprinterdata_printer: Invalid handle (%s).\n", OUR_HANDLE(handle))); + DEBUG(2,("getprinterdata_printer: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); return False; } @@ -1321,7 +1319,7 @@ WERROR _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO if (!Printer) { if((*data=(uint8 *)talloc_zero(p->mem_ctx, 4*sizeof(uint8))) == NULL) return WERR_NOMEM; - DEBUG(0,("_spoolss_getprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); + DEBUG(2,("_spoolss_getprinterdata: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); return WERR_BADFID; } @@ -1407,7 +1405,7 @@ WERROR _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE Printer_entry *Printer=find_printer_index_by_hnd(p, handle); if (!Printer) { - DEBUG(0,("_spoolss_rffpcnex: Invalid handle (%s).\n", OUR_HANDLE(handle))); + DEBUG(2,("_spoolss_rffpcnex: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); return WERR_BADFID; } @@ -1448,7 +1446,7 @@ static void spoolss_notify_server_name(int snum, len = rpcstr_push(temp, temp_name, sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2; + data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1472,7 +1470,7 @@ static void spoolss_notify_printer_name(int snum, uint32 len; /* the notify name should not contain the \\server\ part */ - char *p = strrchr_m(printer->info_2->printername, '\\'); + char *p = strrchr(printer->info_2->printername, '\\'); if (!p) { p = printer->info_2->printername; @@ -1481,7 +1479,8 @@ static void spoolss_notify_printer_name(int snum, } len = rpcstr_push(temp, p, sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2; + + data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1506,7 +1505,7 @@ static void spoolss_notify_share_name(int snum, len = rpcstr_push(temp, lp_servicename(snum), sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2; + data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1533,7 +1532,7 @@ static void spoolss_notify_port_name(int snum, len = rpcstr_push(temp, printer->info_2->portname, sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2; + data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1559,7 +1558,7 @@ static void spoolss_notify_driver_name(int snum, uint32 len; len = rpcstr_push(temp, printer->info_2->drivername, sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2; + data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1584,11 +1583,10 @@ static void spoolss_notify_comment(int snum, if (*printer->info_2->comment == '\0') len = rpcstr_push(temp, lp_comment(snum), sizeof(temp)-2, STR_TERMINATE); - else len = rpcstr_push(temp, printer->info_2->comment, sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2; + data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1615,7 +1613,7 @@ static void spoolss_notify_location(int snum, len = rpcstr_push(temp, printer->info_2->location,sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2; + data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1654,7 +1652,7 @@ static void spoolss_notify_sepfile(int snum, len = rpcstr_push(temp, printer->info_2->sepfile, sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2; + data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1680,7 +1678,7 @@ static void spoolss_notify_print_processor(int snum, len = rpcstr_push(temp, printer->info_2->printprocessor, sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2; + data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1706,7 +1704,7 @@ static void spoolss_notify_parameters(int snum, len = rpcstr_push(temp, printer->info_2->parameters, sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2; + data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1732,7 +1730,7 @@ static void spoolss_notify_datatype(int snum, len = rpcstr_push(temp, printer->info_2->datatype, sizeof(pstring)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2; + data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1882,8 +1880,7 @@ static void spoolss_notify_username(int snum, len = rpcstr_push(temp, queue->user, sizeof(temp)-2, STR_TERMINATE); - - data->notify_data.data.length = len / 2; + data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1920,8 +1917,8 @@ static void spoolss_notify_job_name(int snum, uint32 len; len = rpcstr_push(temp, queue->file, sizeof(temp)-2, STR_TERMINATE); - - data->notify_data.data.length = len / 2; + + data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1970,7 +1967,7 @@ static void spoolss_notify_job_status_string(int snum, len = rpcstr_push(temp, p, sizeof(temp) - 2, STR_TERMINATE); - data->notify_data.data.length = len / 2; + data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -2248,7 +2245,7 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int continue; if((tid=(SPOOL_NOTIFY_INFO_DATA *)Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) { - DEBUG(0,("construct_notify_printer_info: failed to enlarge buffer info->data!\n")); + DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n")); return False; } else info->data = tid; @@ -2303,7 +2300,7 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, continue; if((tid=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) { - DEBUG(0,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n")); + DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n")); return False; } else info->data = tid; @@ -2363,6 +2360,9 @@ static WERROR printserver_notify_info(pipes_struct *p, POLICY_HND *hnd, DEBUG(4,("printserver_notify_info\n")); + if (!Printer) + return WERR_BADFID; + option=Printer->notify.option; id=1; info->version=2; @@ -2420,6 +2420,9 @@ static WERROR printer_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY DEBUG(4,("printer_notify_info\n")); + if (!Printer) + return WERR_BADFID; + option=Printer->notify.option; id=0xffffffff; info->version=2; @@ -2500,7 +2503,7 @@ WERROR _spoolss_rfnpcnex( pipes_struct *p, SPOOL_Q_RFNPCNEX *q_u, SPOOL_R_RFNPCN r_u->info_ptr=0x1; if (!Printer) { - DEBUG(0,("_spoolss_rfnpcnex: Invalid handle (%s).\n", + DEBUG(2,("_spoolss_rfnpcnex: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); goto done; } @@ -2624,7 +2627,7 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum) printer->unknown18 = 0x0; printer->status = nt_printq_status(status.status); printer->unknown20 = 0x0; - printer->c_setprinter = ntprinter->info_2->c_setprinter; /* how many times setprinter has been called */ + printer->c_setprinter = get_c_setprinter(); /* monotonically increasing sum of delta printer counts */ printer->unknown22 = 0x0; printer->unknown23 = 0x6; /* 6 ???*/ printer->unknown24 = 0; /* unknown 24 to 26 are always 0 */ @@ -2683,7 +2686,7 @@ static void free_dev_mode(DEVICEMODE *dev) if (dev == NULL) return; - SAFE_FREE(dev->private); + SAFE_FREE(dev->private); SAFE_FREE(dev); } @@ -2704,7 +2707,7 @@ static DEVICEMODE *construct_dev_mode(int snum) DEBUGADD(8,("getting printer characteristics\n")); if ((devmode = (DEVICEMODE *)malloc(sizeof(DEVICEMODE))) == NULL) { - DEBUG(0,("construct_dev_mode: malloc fail.\n")); + DEBUG(2,("construct_dev_mode: malloc fail.\n")); return NULL; } @@ -2849,7 +2852,7 @@ static BOOL construct_printer_info_3(PRINTER_INFO_3 **pp_printer, int snum) *pp_printer = NULL; if ((printer = (PRINTER_INFO_3 *)malloc(sizeof(PRINTER_INFO_3))) == NULL) { - DEBUG(0,("construct_printer_info_3: malloc fail.\n")); + DEBUG(2,("construct_printer_info_3: malloc fail.\n")); return False; } @@ -2951,7 +2954,7 @@ static WERROR enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 if (construct_printer_info_1(flags, ¤t_prt, snum)) { if((tp=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_1))) == NULL) { - DEBUG(0,("enum_all_printers_info_1: failed to enlarge printers buffer!\n")); + DEBUG(2,("enum_all_printers_info_1: failed to enlarge printers buffer!\n")); SAFE_FREE(printers); *returned=0; return WERR_NOMEM; @@ -3007,7 +3010,7 @@ static WERROR enum_all_printers_info_1_name(fstring name, NEW_BUFFER *buffer, ui if ((name[0] == '\\') && (name[1] == '\\')) s = name + 2; - + if (is_myname_or_ipaddr(s)) { return enum_all_printers_info_1(PRINTER_ENUM_ICON8, buffer, offered, needed, returned); } @@ -3100,7 +3103,7 @@ static WERROR enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint3 if (construct_printer_info_2(¤t_prt, snum)) { if((tp=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_2))) == NULL) { - DEBUG(0,("enum_all_printers_info_2: failed to enlarge printers buffer!\n")); + DEBUG(2,("enum_all_printers_info_2: failed to enlarge printers buffer!\n")); SAFE_FREE(printers); *returned = 0; return WERR_NOMEM; @@ -3613,10 +3616,10 @@ static void init_unistr_array(uint16 **uni_array, fstring *char_array, char *ser slprintf(line, sizeof(line)-1, "\\\\%s%s", servername, v); DEBUGADD(6,("%d:%s:%d\n", i, line, strlen(line))); if((tuary=Realloc(*uni_array, (j+strlen(line)+2)*sizeof(uint16))) == NULL) { - DEBUG(0,("init_unistr_array: Realloc error\n" )); + DEBUG(2,("init_unistr_array: Realloc error\n" )); return; - } - else *uni_array = tuary; + } else + *uni_array = tuary; j += (rpcstr_push((*uni_array+j), line, sizeof(uint16)*strlen(line)+2, 0)/ sizeof(uint16)); i++; } @@ -3692,10 +3695,38 @@ static WERROR construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fst status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version); DEBUG(8,("construct_printer_driver_info_3: status: %s\n", werror_str(status))); + +#if 0 /* JERRY */ + + /* + * I put this code in during testing. Helpful when commenting out the + * support for DRIVER_INFO_6 in regards to win2k. Not needed in general + * as win2k always queries the driver using an infor level of 6. + * I've left it in (but ifdef'd out) because I'll probably + * use it in experimentation again in the future. --jerry 22/01/2002 + */ + if (!W_ERROR_IS_OK(status)) { - free_a_printer(&printer,2); - return WERR_UNKNOWN_PRINTER_DRIVER; + /* + * Is this a W2k client ? + */ + if (version == 3) { + /* Yes - try again with a WinNT driver. */ + version = 2; + status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version); + DEBUG(8,("construct_printer_driver_info_3: status: %s\n", werror_str(status))); + } +#endif + + if (!W_ERROR_IS_OK(status)) { + free_a_printer(&printer,2); + return WERR_UNKNOWN_PRINTER_DRIVER; + } + +#if 0 /* JERRY */ } +#endif + fill_printer_driver_info_3(info, driver, servername); @@ -4046,7 +4077,7 @@ WERROR _spoolss_endpageprinter(pipes_struct *p, SPOOL_Q_ENDPAGEPRINTER *q_u, SPO Printer_entry *Printer = find_printer_index_by_hnd(p, handle); if (!Printer) { - DEBUG(0,("_spoolss_endpageprinter: Invalid handle (%s).\n",OUR_HANDLE(handle))); + DEBUG(2,("_spoolss_endpageprinter: Invalid handle (%s:%u:%u).\n",OUR_HANDLE(handle))); return WERR_BADFID; } @@ -4076,7 +4107,7 @@ WERROR _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, S struct current_user user; if (!Printer) { - DEBUG(0,("_spoolss_startdocprinter: Invalid handle (%s)\n", OUR_HANDLE(handle))); + DEBUG(2,("_spoolss_startdocprinter: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle))); return WERR_BADFID; } @@ -4150,7 +4181,7 @@ WERROR _spoolss_writeprinter(pipes_struct *p, SPOOL_Q_WRITEPRINTER *q_u, SPOOL_R Printer_entry *Printer = find_printer_index_by_hnd(p, handle); if (!Printer) { - DEBUG(0,("_spoolss_writeprinter: Invalid handle (%s)\n",OUR_HANDLE(handle))); + DEBUG(2,("_spoolss_writeprinter: Invalid handle (%s:%u:%u)\n",OUR_HANDLE(handle))); r_u->buffer_written = q_u->buffer_size2; return WERR_BADFID; } @@ -4179,7 +4210,7 @@ static WERROR control_printer(POLICY_HND *handle, uint32 command, get_current_user(&user, p); if (!Printer) { - DEBUG(0,("control_printer: Invalid handle (%s)\n", OUR_HANDLE(handle))); + DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle))); return WERR_BADFID; } @@ -4237,7 +4268,7 @@ static WERROR update_printer_sec(POLICY_HND *handle, uint32 level, Printer_entry *Printer = find_printer_index_by_hnd(p, handle); if (!Printer || !get_printer_snum(p, handle, &snum)) { - DEBUG(0,("update_printer_sec: Invalid handle (%s)\n", + DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle))); result = WERR_BADFID; @@ -4331,10 +4362,7 @@ static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s", get_called_name(), lp_servicename(snum)); fstrcpy(info->sharename, lp_servicename(snum)); - info->attributes = PRINTER_ATTRIBUTE_SHARED \ - | PRINTER_ATTRIBUTE_LOCAL \ - | PRINTER_ATTRIBUTE_RAW_ONLY \ - | PRINTER_ATTRIBUTE_QUEUED ; + info->attributes = PRINTER_ATTRIBUTE_SHARED | PRINTER_ATTRIBUTE_NETWORK; return True; } @@ -4350,6 +4378,7 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) int numlines; int ret; int fd; + fstring remote_machine = "%m"; /* build driver path... only 9X architecture is needed for legacy reasons */ slprintf(driverlocation, sizeof(driverlocation)-1, "\\\\%s\\print$\\WIN40\\0", @@ -4357,11 +4386,12 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) /* change \ to \\ for the shell */ all_string_sub(driverlocation,"\\","\\\\",sizeof(pstring)); - slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"", + slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"", cmd, printer->info_2->printername, printer->info_2->sharename, printer->info_2->portname, printer->info_2->drivername, - printer->info_2->location, driverlocation); + printer->info_2->location, driverlocation, remote_machine); + /* Convert script args to unix-codepage */ DEBUG(10,("Running [%s]\n", command)); ret = smbrun(command, &fd); DEBUGADD(10,("returned [%d]\n", ret)); @@ -4633,8 +4663,8 @@ static BOOL nt_printer_info_level_equal(NT_PRINTER_INFO_LEVEL *p1, } /******************************************************************** - * called by spoolss_api_setprinter - * when updating a printer description + * Called by spoolss_api_setprinter + * when updating a printer description. ********************************************************************/ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, @@ -4651,7 +4681,7 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, result = WERR_OK; if (level!=2) { - DEBUG(0,("Send a mail to samba@samba.org\n")); + DEBUG(0,("update_printer: Send a mail to samba@samba.org\n")); DEBUGADD(0,("with the following message: update_printer: level!=2\n")); result = WERR_UNKNOWN_LEVEL; goto done; @@ -4690,7 +4720,7 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, /* we have a valid devmode convert it and link it*/ - DEBUGADD(8,("Converting the devicemode struct\n")); + DEBUGADD(8,("update_printer: Converting the devicemode struct\n")); if (!convert_devicemode(printer->info_2->printername, devmode, &printer->info_2->devmode)) { result = WERR_NOMEM; @@ -4710,7 +4740,7 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, annoying permission denied dialog box. */ if (nt_printer_info_level_equal(printer, old_printer)) { - DEBUG(3, ("printer info has not changed\n")); + DEBUG(3, ("update_printer: printer info has not changed\n")); result = WERR_OK; goto done; } @@ -4718,8 +4748,7 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, /* Check calling user has permission to update printer description */ if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { - DEBUG(3, ("printer property change denied by security " - "descriptor\n")); + DEBUG(3, ("update_printer: printer property change denied by security descriptor\n")); result = WERR_ACCESS_DENIED; goto done; } @@ -4727,12 +4756,38 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, /* Call addprinter hook */ if (*lp_addprinter_cmd()) { - if (!add_printer_hook(printer)) { + if ( !add_printer_hook(printer) ) { result = WERR_ACCESS_DENIED; goto done; } } + /* + * Set the DRIVER_INIT info in the tdb; trigger on magic value for the + * DEVMODE.displayfrequency, which is not used for printer drivers. This + * requires Win32 client code (see other notes elsewhere in the code). + */ + if (printer->info_2->devmode && + printer->info_2->devmode->displayfrequency == MAGIC_DISPLAY_FREQUENCY) { + + DEBUG(10,("update_printer: Save printer driver init data\n")); + printer->info_2->devmode->displayfrequency = 0; + + if (update_driver_init(*printer, 2)!=0) { + DEBUG(10,("update_printer: error updating printer driver init DEVMODE\n")); + result = WERR_ACCESS_DENIED; + goto done; + } + } else { + /* + * When a *new* driver is bound to a printer, the drivername is used to + * lookup previously saved driver initialization info, which is then + * bound to the printer, simulating what happens in the Windows arch. + */ + if (strequal(printer->info_2->drivername, old_printer->info_2->drivername)) + set_driver_init(printer, 2); + } + /* Update printer info */ result = mod_a_printer(*printer, 2); @@ -4740,7 +4795,7 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, free_a_printer(&printer, 2); free_a_printer(&old_printer, 2); - srv_spoolss_sendnotify(p, handle); + srv_spoolss_sendnotify(0, PRINTER_CHANGE_SET_PRINTER); return result; } @@ -4760,7 +4815,7 @@ WERROR _spoolss_setprinter(pipes_struct *p, SPOOL_Q_SETPRINTER *q_u, SPOOL_R_SET Printer_entry *Printer = find_printer_index_by_hnd(p, handle); if (!Printer) { - DEBUG(0,("_spoolss_setprinter: Invalid handle (%s)\n", OUR_HANDLE(handle))); + DEBUG(2,("_spoolss_setprinter: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle))); return WERR_BADFID; } @@ -4788,7 +4843,7 @@ WERROR _spoolss_fcpn(pipes_struct *p, SPOOL_Q_FCPN *q_u, SPOOL_R_FCPN *r_u) Printer_entry *Printer= find_printer_index_by_hnd(p, handle); if (!Printer) { - DEBUG(0,("_spoolss_fcpn: Invalid handle (%s)\n", OUR_HANDLE(handle))); + DEBUG(2,("_spoolss_fcpn: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle))); return WERR_BADFID; } @@ -5902,11 +5957,24 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ return WERR_INVALID_PARAM; } - /* + /* * When a printer is created, the drivername bound to the printer is used * to lookup previously saved driver initialization info, which is then * bound to the new printer, simulating what happens in the Windows arch. */ + + if (!devmode) + set_driver_init(printer, 2); + else { + /* A valid devmode was included, convert and link it + */ + DEBUGADD(10, ("spoolss_addprinterex_level_2: devmode included, converting\n")); + + if (!convert_devicemode(printer->info_2->printername, devmode, + &printer->info_2->devmode)) + return WERR_NOMEM; + } + set_driver_init(printer, 2); /* write the ASCII on disk */ @@ -5925,7 +5993,9 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ free_a_printer(&printer,2); - srv_spoolss_sendnotify(p, handle); + update_c_setprinter(False); + + srv_spoolss_sendnotify(0, PRINTER_CHANGE_ADD_PRINTER); return WERR_OK; } @@ -6016,7 +6086,9 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen pstring long_archi; pstring short_archi; DRIVER_DIRECTORY_1 *info=NULL; - +#if 0 + fstring asc_name, servername; +#endif unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)-1); if (get_short_archi(short_archi, long_archi)==False) @@ -6025,6 +6097,20 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen if((info=(DRIVER_DIRECTORY_1 *)malloc(sizeof(DRIVER_DIRECTORY_1))) == NULL) return WERR_NOMEM; +#if 0 /* JERRY */ + /* use the name the client sent us */ + + unistr2_to_ascii(asc_name, name, sizeof(asc_name)-1); + if (asc_name[0] == '\\' && asc_name[1] == '\\') + fstrcpy(servername, asc_name); + else { + fstrcpy(servername, "\\\\"); + fstrcat(servername, asc_name); + } + + slprintf(path, sizeof(path)-1, "%s\\print$\\%s", servername, short_archi); +#endif + slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", get_called_name(), short_archi); DEBUG(4,("printer driver directory: [%s]\n", path)); @@ -6118,7 +6204,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S DEBUG(5,("spoolss_enumprinterdata\n")); if (!Printer) { - DEBUG(0,("_spoolss_enumprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); + DEBUG(2,("_spoolss_enumprinterdata: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); return WERR_BADFID; } @@ -6194,20 +6280,17 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S problems unmarshalling the response */ *out_max_value_len=(in_value_len/sizeof(uint16)); - if((*out_value=(uint16 *)malloc(in_value_len*sizeof(uint8))) == NULL) + if((*out_value=(uint16 *)talloc_zero(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL) return WERR_NOMEM; - ZERO_STRUCTP(*out_value); *out_value_len = rpcstr_push((char *)*out_value, "", in_value_len, 0); /* the data is counted in bytes */ *out_max_data_len = in_data_len; *out_data_len = in_data_len; - if((*data_out=(uint8 *)malloc(in_data_len*sizeof(uint8))) == NULL) + if((*data_out=(uint8 *)talloc_zero(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) return WERR_NOMEM; - memset(*data_out,'\0',in_data_len); - return WERR_NO_MORE_ITEMS; } @@ -6269,7 +6352,7 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP DEBUG(5,("spoolss_setprinterdata\n")); if (!Printer) { - DEBUG(0,("_spoolss_setprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); + DEBUG(2,("_spoolss_setprinterdata: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); return WERR_BADFID; } @@ -6305,6 +6388,8 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP convert_specific_param(¶m, value , type, data, real_len); #if 0 + /* JRA. W2K always changes changeid. */ + if (get_specific_param(*printer, 2, param->value, &old_param.data, &old_param.type, (uint32 *)&old_param.data_len)) { @@ -6344,6 +6429,11 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP free_nt_printer_param(¶m); SAFE_FREE(old_param.data); +#if 0 + /* Is this correct. JRA ? */ + srv_spoolss_sendnotify(0, PRINTER_CHANGE_SET_PRINTER); +#endif + return status; } @@ -6364,7 +6454,7 @@ WERROR _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_ DEBUG(5,("spoolss_deleteprinterdata\n")); if (!Printer) { - DEBUG(0,("_spoolss_deleteprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); + DEBUG(2,("_spoolss_deleteprinterdata: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); return WERR_BADFID; } @@ -6402,40 +6492,60 @@ WERROR _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM /* uint32 level = q_u->level; - notused. */ FORM *form = &q_u->form; nt_forms_struct tmpForm; - int count=0, snum; + int snum; + WERROR status = WERR_OK; + NT_PRINTER_INFO_LEVEL *printer = NULL; + + int count=0; nt_forms_struct *list=NULL; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); DEBUG(5,("spoolss_addform\n")); if (!Printer) { - DEBUG(0,("_spoolss_addform: Invalid handle (%s).\n", OUR_HANDLE(handle))); + DEBUG(2,("_spoolss_addform: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); return WERR_BADFID; } - /* Must be administrator to add a form */ - - if (!get_printer_snum(p, handle, &snum)) - return WERR_BADFID; + /* + * FIXME!! Feels like there should be an access check here, but haven't + * had time to verify. --jerry + */ - if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { - DEBUG(0, ("_spoolss_addform: Access denied\n")); - return WERR_ACCESS_DENIED; - } + if (!get_printer_snum(p,handle, &snum)) + return WERR_BADFID; + /* can't add if builtin */ if (get_a_builtin_ntform(&form->name,&tmpForm)) { - return WERR_FILE_EXISTS; + return WERR_ALREADY_EXISTS; } count=get_ntforms(&list); if(!add_a_form(&list, form, &count)) return WERR_NOMEM; write_ntforms(&list, count); + + /* + * ChangeID must always be set + */ + + if (!get_printer_snum(p,handle, &snum)) + return WERR_BADFID; + status = get_a_printer(&printer, 2, lp_servicename(snum)); + if (!W_ERROR_IS_OK(status)) + goto done; + + status = mod_a_printer(*printer, 2); + if (!W_ERROR_IS_OK(status)) + goto done; + +done: + free_a_printer(&printer, 2); SAFE_FREE(list); - return WERR_OK; + return status; } /**************************************************************************** @@ -6446,25 +6556,27 @@ WERROR _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE POLICY_HND *handle = &q_u->handle; UNISTR2 *form_name = &q_u->name; nt_forms_struct tmpForm; - int count=0, snum; + int count=0; WERROR ret = WERR_OK; nt_forms_struct *list=NULL; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); + int snum; + WERROR status = WERR_OK; + NT_PRINTER_INFO_LEVEL *printer = NULL; DEBUG(5,("spoolss_deleteform\n")); if (!Printer) { - DEBUG(0,("_spoolss_deleteform: Invalid handle (%s).\n", OUR_HANDLE(handle))); + DEBUG(2,("_spoolss_deleteform: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); return WERR_BADFID; } - /* Must be administrator to set a form */ - - if (!get_printer_snum(p, handle, &snum)) + if (!get_printer_snum(p, handle, &snum)) return WERR_BADFID; if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { - DEBUG(0, ("_spoolss_addform: Access denied\n")); + DEBUG(3, ("security descriptor change denied by existing " + "security descriptor\n")); return WERR_ACCESS_DENIED; } @@ -6477,6 +6589,23 @@ WERROR _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE if(!delete_a_form(&list, form_name, &count, &ret)) return WERR_INVALID_PARAM; + /* + * ChangeID must always be set + */ + + if (!get_printer_snum(p,handle, &snum)) + return WERR_BADFID; + + status = get_a_printer(&printer, 2, lp_servicename(snum)); + if (!W_ERROR_IS_OK(status)) + goto done; + + status = mod_a_printer(*printer, 2); + if (!W_ERROR_IS_OK(status)) + goto done; + +done: + free_a_printer(&printer, 2); SAFE_FREE(list); return ret; @@ -6492,24 +6621,27 @@ WERROR _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM * /* uint32 level = q_u->level; - notused. */ FORM *form = &q_u->form; nt_forms_struct tmpForm; - int count=0, snum; + int snum; + WERROR status = WERR_OK; + NT_PRINTER_INFO_LEVEL *printer = NULL; + + int count=0; nt_forms_struct *list=NULL; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); DEBUG(5,("spoolss_setform\n")); if (!Printer) { - DEBUG(0,("_spoolss_setform: Invalid handle (%s).\n", OUR_HANDLE(handle))); + DEBUG(2,("_spoolss_setform: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); return WERR_BADFID; } - /* Must be administrator to set a form */ - if (!get_printer_snum(p, handle, &snum)) return WERR_BADFID; if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { - DEBUG(0, ("_spoolss_addform: Access denied\n")); + DEBUG(3, ("security descriptor change denied by existing " + "security descriptor\n")); return WERR_ACCESS_DENIED; } @@ -6522,6 +6654,23 @@ WERROR _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM * update_a_form(&list, form, count); write_ntforms(&list, count); + /* + * ChangeID must always be set + */ + + if (!get_printer_snum(p,handle, &snum)) + return WERR_BADFID; + + status = get_a_printer(&printer, 2, lp_servicename(snum)); + if (!W_ERROR_IS_OK(status)) + goto done; + + status = mod_a_printer(*printer, 2); + if (!W_ERROR_IS_OK(status)) + goto done; + +done: + free_a_printer(&printer, 2); SAFE_FREE(list); return WERR_OK; @@ -6943,7 +7092,7 @@ WERROR _spoolss_getprinterdataex(pipes_struct *p, SPOOL_Q_GETPRINTERDATAEX *q_u, if (!Printer) { if((*data=(uint8 *)talloc_zero(p->mem_ctx, 4*sizeof(uint8))) == NULL) return WERR_NOMEM; - DEBUG(0,("_spoolss_getprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); + DEBUG(2,("_spoolss_getprinterdata: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); return WERR_BADFID; } @@ -7122,7 +7271,7 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ DEBUG(4,("_spoolss_enumprinterdataex\n")); if (!Printer) { - DEBUG(0,("_spoolss_enumprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle))); + DEBUG(2,("_spoolss_enumprinterdata: Invalid handle (%s:%u:%u1<).\n", OUR_HANDLE(handle))); return WERR_BADFID; } @@ -7259,7 +7408,7 @@ static WERROR getprintprocessordirectory_level_1(UNISTR2 *name, unistr2_to_ascii(long_archi, environment, sizeof(long_archi)-1); - if (get_short_archi(short_archi, long_archi)==False) + if (get_short_archi(short_archi, long_archi)==FALSE) return WERR_INVALID_ENVIRONMENT; if((info=(PRINTPROCESSOR_DIRECTORY_1 *)malloc(sizeof(PRINTPROCESSOR_DIRECTORY_1))) == NULL) -- cgit From 51e205c92acce4d9374cc6b9e5ae234219037626 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 12 Feb 2002 19:16:14 +0000 Subject: merge from 2.2 (This used to be commit 09fc979172327d6396642e824f6d482c6f986850) --- source3/rpc_server/srv_spoolss_nt.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index f76b78f116..1be11f6a18 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4422,6 +4422,8 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) return True; } +#if 0 /* JERRY */ + /* Return true if two devicemodes are equal */ #define DEVMODE_CHECK_INT(field) \ @@ -4431,6 +4433,10 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) return False; \ } +/************************************************************************ + Handy, but currently unused functions + ***********************************************************************/ + static BOOL nt_devicemode_equal(NT_DEVICEMODE *d1, NT_DEVICEMODE *d2) { if (!d1 && !d2) goto equal; /* if both are NULL they are equal */ @@ -4662,6 +4668,8 @@ static BOOL nt_printer_info_level_equal(NT_PRINTER_INFO_LEVEL *p1, return True; } +#endif + /******************************************************************** * Called by spoolss_api_setprinter * when updating a printer description. @@ -4735,9 +4743,13 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, goto done; } - /* NT likes to call this function even though nothing has actually - changed. Check this so the user doesn't end up with an - annoying permission denied dialog box. */ +#if 0 /* JERRY */ + + /* + * Another one of those historical misunderstandings... + * This is reminisent of a similar call we had in _spoolss_setprinterdata() + * I'm leaving it here as a reminder. --jerry + */ if (nt_printer_info_level_equal(printer, old_printer)) { DEBUG(3, ("update_printer: printer info has not changed\n")); @@ -4745,6 +4757,8 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, goto done; } +#endif + /* Check calling user has permission to update printer description */ if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { @@ -4784,7 +4798,7 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, * lookup previously saved driver initialization info, which is then * bound to the printer, simulating what happens in the Windows arch. */ - if (strequal(printer->info_2->drivername, old_printer->info_2->drivername)) + if (!strequal(printer->info_2->drivername, old_printer->info_2->drivername)) set_driver_init(printer, 2); } -- cgit From 1f6df6c9ce93cca5ee0d0ad13fb8f2ee4b782c63 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 12 Feb 2002 22:31:18 +0000 Subject: merge from 2.2 (This used to be commit e18a7c26476e05f95850ac2bbeb42c2588115741) --- source3/rpc_server/srv_spoolss_nt.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 1be11f6a18..088945fb79 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6521,14 +6521,15 @@ WERROR _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM return WERR_BADFID; } - /* - * FIXME!! Feels like there should be an access check here, but haven't - * had time to verify. --jerry - */ - - if (!get_printer_snum(p,handle, &snum)) return WERR_BADFID; + + if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { + DEBUG(3, ("security descriptor change denied by existing " + "security descriptor\n")); + status = WERR_ACCESS_DENIED; + goto done; + } /* can't add if builtin */ if (get_a_builtin_ntform(&form->name,&tmpForm)) { @@ -6544,9 +6545,6 @@ WERROR _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM * ChangeID must always be set */ - if (!get_printer_snum(p,handle, &snum)) - return WERR_BADFID; - status = get_a_printer(&printer, 2, lp_servicename(snum)); if (!W_ERROR_IS_OK(status)) goto done; @@ -6607,9 +6605,6 @@ WERROR _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE * ChangeID must always be set */ - if (!get_printer_snum(p,handle, &snum)) - return WERR_BADFID; - status = get_a_printer(&printer, 2, lp_servicename(snum)); if (!W_ERROR_IS_OK(status)) goto done; @@ -6672,9 +6667,6 @@ WERROR _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM * * ChangeID must always be set */ - if (!get_printer_snum(p,handle, &snum)) - return WERR_BADFID; - status = get_a_printer(&printer, 2, lp_servicename(snum)); if (!W_ERROR_IS_OK(status)) goto done; -- cgit From 83bc6cdd55b6be4001bff2ac758c7a3396740687 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 15 Feb 2002 18:59:34 +0000 Subject: merge from APPLIANCE_HEAD (This used to be commit 696d439515016e4c2bc5ad085e443abe43c95136) --- source3/rpc_server/srv_spoolss_nt.c | 93 +++++++------------------------------ 1 file changed, 18 insertions(+), 75 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 088945fb79..754390b7b6 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -401,10 +401,10 @@ static BOOL set_printer_hnd_printertype(Printer_entry *Printer, char *handlename static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) { - NT_PRINTER_INFO_LEVEL *printer = NULL; int snum; int n_services=lp_numservices(); char *aprinter; + fstring sname; BOOL found=False; DEBUG(4,("Setting printer name=%s (len=%d)\n", handlename, strlen(handlename))); @@ -429,97 +429,40 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) DEBUGADD(5,("searching for [%s] (len=%d)\n", aprinter, strlen(aprinter))); /* - * store the Samba share name in it - * in back we have the long printer name - * need to iterate all the snum and do a - * get_a_printer each time to find the printer - * faster to do it here than later. + * The original code allowed smbd to store a printer name that + * was different from the share name. This is not possible + * anymore, so I've simplified this loop greatly. Here + * we are just verifying that the printer name is a valid + * printer service defined in smb.conf + * --jerry [Fri Feb 15 11:17:46 CST 2002] */ - for (snum=0;snuminfo_2->printername+2, '\\'); - printername++; - - DEBUG(10,("set_printer_hnd_name: name [%s], aprinter [%s]\n", - printer->info_2->printername, aprinter )); + fstrcpy(sname, lp_servicename(snum)); - if ( strlen(printername) != strlen(aprinter) ) { - free_a_printer(&printer, 2); - continue; - } + DEBUGADD(5,("share:%s\n",sname)); - if ( strncasecmp(printername, aprinter, strlen(aprinter))) { - free_a_printer(&printer, 2); - continue; + if (! StrCaseCmp(sname, aprinter)) { + found = True; + break; } - - found=True; - } - - /* - * if we haven't found a printer with the given handlename - * then it can be a share name as you can open both \\server\printer and - * \\server\share - */ - - /* - * we still check if the printer description file exists as NT won't be happy - * if we reply OK in the openprinter call and can't reply in the subsequent RPC calls - */ - - if (found==False) { - DEBUGADD(5,("Printer not found, checking for share now\n")); - - for (snum=0;snuminfo_2->printername, aprinter )); - - if ( strlen(lp_servicename(snum)) != strlen(aprinter) ) { - free_a_printer(&printer, 2); - continue; - } - - if ( strncasecmp(lp_servicename(snum), aprinter, strlen(aprinter))) { - free_a_printer(&printer, 2); - continue; - } - - found=True; - } } + - if (found==False) { + if (!found) { DEBUGADD(4,("Printer not found\n")); return False; } - snum--; - DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s[%x]\n", - printer->info_2->printername, lp_servicename(snum),snum)); + DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname)); ZERO_STRUCT(Printer->dev.handlename); - strncpy(Printer->dev.handlename, lp_servicename(snum), strlen(lp_servicename(snum))); - - free_a_printer(&printer, 2); + fstrcpy(Printer->dev.handlename, sname); return True; } -- cgit From cef4f9215f752243d1c429e3b056344af3fe50f8 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 20 Feb 2002 23:36:23 +0000 Subject: merge from 2.2 (This used to be commit 25fb4a8d110bcdcbe7822a833cab9cfdec8a1fb2) --- source3/rpc_server/srv_spoolss_nt.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 754390b7b6..86efc2fb94 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1105,7 +1105,7 @@ static BOOL getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint32 *type = 0x4; if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) return False; - SIVAL(*data, 0, 0x01); + SIVAL(*data, 0, 0x00); *needed = 0x4; return True; } @@ -1114,7 +1114,8 @@ static BOOL getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint32 *type = 0x4; if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) return False; - SIVAL(*data, 0, 0x1B); + /* formally was 0x1b */ + SIVAL(*data, 0, 0x0); *needed = 0x4; return True; } @@ -1123,7 +1124,7 @@ static BOOL getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint32 *type = 0x4; if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) return False; - SIVAL(*data, 0, 0x01); + SIVAL(*data, 0, 0x00); *needed = 0x4; return True; } @@ -1137,8 +1138,10 @@ static BOOL getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint32 return True; } - if (!strcmp(value, "DefaultSpoolDirectory")) { - pstring string="You are using a Samba server"; + if (!strcmp(value, "DefaultSpoolDirectory")) { + fstring string; + + fstrcpy(string, string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH)); *type = 0x1; *needed = 2*(strlen(string)+1); if((*data = (uint8 *)talloc(ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL) -- cgit From 84b18178a99b4eeb081f09ce4bd09428ad57b5a2 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 21 Feb 2002 00:55:01 +0000 Subject: merge from 2.2 (This used to be commit 63ab947fd9dd17a4c370402e74b389458bbd3a60) --- source3/rpc_server/srv_spoolss_nt.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 86efc2fb94..b2de688b74 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -7280,6 +7280,10 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ enum_values[num_entries].value_len = (strlen(value)+1) * 2; enum_values[num_entries].type = type; +#if 0 /* JERRY - I think think was a bad assumption based on bad + offset values when I first implemented it. Commented out. + We should not be adding an extra NULL to the end of a string + just send what the client set in the first place. */ /* * NULL terminate REG_SZ * FIXME!!! We should not be correctly problems in the way @@ -7295,6 +7299,7 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ else add_len = data_len % 2; } +#endif if (!(enum_values[num_entries].data=talloc_zero(p->mem_ctx, data_len+add_len))) { DEBUG(0,("talloc_realloc failed to allocate more memory for data!\n")); -- cgit From 5dbe33e3ee3615260036b2dc89bfd164b62a6296 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 21 Feb 2002 17:30:58 +0000 Subject: merge from 2.2 (This used to be commit 505119f0a7c6f10fd7e580edfe1bd0fb6ec36428) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index b2de688b74..cdddb8b564 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -7113,7 +7113,7 @@ WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, unistr2_to_ascii(key, &q_u->key, sizeof(key) - 1); - if (strcmp(key, "PrinterDriverData") == 0) + if (strcmp(key, "PrinterDriverData") != 0) return WERR_INVALID_PARAM; ZERO_STRUCT(q_u_local); -- cgit From 2f8452fd49dd34da5cd07629dcba937861dd0731 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 25 Feb 2002 23:18:05 +0000 Subject: Merge of printing performance fixes from appliance. (This used to be commit c8dc59dfe877f63bea6976b7d7fd448e0c8722ba) --- source3/rpc_server/srv_spoolss_nt.c | 101 ++++++++++++++++++++++-------------- 1 file changed, 61 insertions(+), 40 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index cdddb8b564..6f46b4bc42 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4868,7 +4868,8 @@ static void fill_job_info_1(JOB_INFO_1 *job_info, print_queue_struct *queue, ****************************************************************************/ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, int position, int snum, - NT_PRINTER_INFO_LEVEL *ntprinter) + NT_PRINTER_INFO_LEVEL *ntprinter, + DEVICEMODE *devmode) { pstring temp_name; pstring chaine; @@ -4906,9 +4907,7 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, job_info->timeelapsed=0; job_info->pagesprinted=0; - if((job_info->devmode = construct_dev_mode(snum)) == NULL) { - return False; - } + job_info->devmode = devmode; return (True); } @@ -4967,24 +4966,33 @@ static WERROR enumjobs_level2(print_queue_struct *queue, int snum, uint32 *needed, uint32 *returned) { NT_PRINTER_INFO_LEVEL *ntprinter = NULL; - JOB_INFO_2 *info; + JOB_INFO_2 *info = NULL; int i; WERROR result; + DEVICEMODE *devmode = NULL; info=(JOB_INFO_2 *)malloc(*returned*sizeof(JOB_INFO_2)); if (info==NULL) { *returned=0; - return WERR_NOMEM; + result = WERR_NOMEM; + goto done; } result = get_a_printer(&ntprinter, 2, lp_servicename(snum)); if (!W_ERROR_IS_OK(result)) { *returned = 0; - return result; + goto done; } - + + if (!(devmode = construct_dev_mode(snum))) { + *returned = 0; + result = WERR_NOMEM; + goto done; + } + for (i=0; i<*returned; i++) - fill_job_info_2(&(info[i]), &queue[i], i, snum, ntprinter); + fill_job_info_2(&(info[i]), &queue[i], i, snum, ntprinter, + devmode); free_a_printer(&ntprinter, 2); SAFE_FREE(queue); @@ -4993,27 +5001,30 @@ static WERROR enumjobs_level2(print_queue_struct *queue, int snum, for (i=0; i<*returned; i++) (*needed) += spoolss_size_job_info_2(&info[i]); + if (*needed > offered) { + *returned=0; + result = WERR_INSUFFICIENT_BUFFER; + goto done; + } + if (!alloc_buffer_size(buffer, *needed)) { - SAFE_FREE(info); - return WERR_INSUFFICIENT_BUFFER; + result = WERR_INSUFFICIENT_BUFFER; + goto done; } /* fill the buffer with the structures */ for (i=0; i<*returned; i++) smb_io_job_info_2("", buffer, &info[i], 0); - /* clear memory */ - for (i = 0; i < *returned; i++) - free_job_info_2(&info[i]); + result = WERR_OK; + done: + free_a_printer(&ntprinter, 2); + free_devmode(devmode); + SAFE_FREE(queue); SAFE_FREE(info); - if (*needed > offered) { - *returned=0; - return WERR_INSUFFICIENT_BUFFER; - } - - return WERR_OK; + return result; } /**************************************************************************** @@ -6918,14 +6929,15 @@ static WERROR getjob_level_2(print_queue_struct *queue, int count, int snum, uin JOB_INFO_2 *info_2; NT_PRINTER_INFO_LEVEL *ntprinter = NULL; WERROR ret; + DEVICEMODE *devmode = NULL; info_2=(JOB_INFO_2 *)malloc(sizeof(JOB_INFO_2)); ZERO_STRUCTP(info_2); if (info_2 == NULL) { - SAFE_FREE(queue); - return WERR_NOMEM; + ret = WERR_NOMEM; + goto done; } for (i=0; i offered) { + ret = WERR_INSUFFICIENT_BUFFER; + goto done; + } - if (*needed > offered) - return WERR_INSUFFICIENT_BUFFER; + ret = WERR_OK; + + done: + /* Cleanup allocated memory */ - return WERR_OK; + SAFE_FREE(queue); + free_job_info_2(info_2); /* Also frees devmode */ + SAFE_FREE(info_2); + free_a_printer(&ntprinter, 2); + + return ret; } /**************************************************************************** -- cgit From 2ff93902451a234e78490a1b18c2fae43d997b01 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 26 Feb 2002 03:12:09 +0000 Subject: Fixup the sending of printer change messages from job changes. Jeremy. (This used to be commit 28d4e7a3e2bd8f15ef807b821e4300a72bbc6904) --- source3/rpc_server/srv_spoolss_nt.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 6f46b4bc42..c7b4df9d82 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -566,33 +566,39 @@ static void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size { Printer_entry *find_printer; WERROR status; + fstring printer_name; char msg[8]; + char *buf_ptr = (char *)buf; uint32 low, high; - if (len != sizeof(msg)) { + if (len < sizeof(msg) + 2) { DEBUG(2,("srv_spoolss_receive_message: got incorrect message size (%u)!\n", (unsigned int)len)); return; } - memcpy(msg, buf, len); + memcpy(msg, buf_ptr, sizeof(msg)); low = IVAL(msg,0); high = IVAL(msg,4); + fstrcpy(printer_name, buf_ptr + sizeof(msg)); - DEBUG(10,("srv_spoolss_receive_message: Got message printer change low=0x%x high=0x%x\n", (unsigned int)low, - (unsigned int)high )); - - find_printer = printers_list; + DEBUG(10,("srv_spoolss_receive_message: Got message printer change name [%s] low=0x%x high=0x%x\n", + printer_name, (unsigned int)low, (unsigned int)high )); /* Iterate the printer list */ - for(; find_printer; find_printer = find_printer->next) { + for(find_printer = printers_list; find_printer; find_printer = find_printer->next) { /* * If the entry has a connected client we send the message. */ - if (find_printer->notify.client_connected==True) { DEBUG(10,("srv_spoolss_receive_message: printerserver [%s]\n", find_printer->dev.printerservername )); + if (*printer_name && !strequal(printer_name, find_printer->dev.handlename)) { + DEBUG(10,("srv_spoolss_receive_message: ignoring message sent to %s [%s]\n", + printer_name, find_printer->dev.handlename )); + continue; + } + if (cli_spoolss_reply_rrpcn(&cli, &find_printer->notify.client_hnd, low, high, &status)) DEBUG(10,("srv_spoolss_receive_message: cli_spoolss_reply_rrpcn status = 0x%x\n", (unsigned int)W_ERROR_V(status))); @@ -608,8 +614,9 @@ static void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size static BOOL srv_spoolss_sendnotify(uint32 high, uint32 low) { - char msg[8]; + char msg[10]; + ZERO_STRUCT(msg); SIVAL(msg,0,low); SIVAL(msg,4,high); DEBUG(10,("srv_spoolss_sendnotify: printer change low=0x%x high=0x%x\n", low, high)); -- cgit From 43ca6e3ef80f89a0e188a6aa86c6979e01804af2 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 7 Mar 2002 01:02:48 +0000 Subject: Merge in the change to do per-handle access checks on setdata/setform etc. Should allow the buggy spoolss code on NT to work against us. Jeremy. (This used to be commit 2b3609a7dd55d96f5aafe137fff1ac2da0434867) --- source3/rpc_server/srv_spoolss_nt.c | 208 ++++++++++++++++++++++++------------ 1 file changed, 138 insertions(+), 70 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index c7b4df9d82..eb10de3253 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -59,7 +59,7 @@ typedef struct _Printer{ fstring printerservername; } dev; uint32 type; - uint32 access; + uint32 access_granted; struct { uint32 flags; uint32 options; @@ -327,8 +327,9 @@ static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) } /**************************************************************************** - return the snum of a printer corresponding to an handle + Return the snum of a printer corresponding to an handle. ****************************************************************************/ + static BOOL get_printer_snum(pipes_struct *p, POLICY_HND *hnd, int *number) { Printer_entry *Printer = find_printer_index_by_hnd(p, hnd); @@ -350,23 +351,6 @@ static BOOL get_printer_snum(pipes_struct *p, POLICY_HND *hnd, int *number) } } -/**************************************************************************** - set printer handle type. -****************************************************************************/ -static BOOL set_printer_hnd_accesstype(pipes_struct *p, POLICY_HND *hnd, uint32 access_required) -{ - Printer_entry *Printer = find_printer_index_by_hnd(p, hnd); - - if (!Printer) { - DEBUG(2,("set_printer_hnd_accesstype: Invalid handle (%s:%u:%u)", OUR_HANDLE(hnd))); - return False; - } - - DEBUG(4,("Setting printer access=%x\n", access_required)); - Printer->access = access_required; - return True; -} - /**************************************************************************** Set printer handle type. Check if it's \\server or \\server\printer @@ -468,10 +452,10 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) } /**************************************************************************** - find first available printer slot. creates a printer handle for you. + Find first available printer slot. creates a printer handle for you. ****************************************************************************/ -static BOOL open_printer_hnd(pipes_struct *p, POLICY_HND *hnd, char *name) +static BOOL open_printer_hnd(pipes_struct *p, POLICY_HND *hnd, char *name, uint32 access_granted) { Printer_entry *new_printer; @@ -502,31 +486,17 @@ static BOOL open_printer_hnd(pipes_struct *p, POLICY_HND *hnd, char *name) return False; } - DEBUG(5, ("%d printer handles active\n", (int)p->pipe_handles->count )); + new_printer->access_granted = access_granted; - return True; -} - -/******************************************************************** - Return True if the handle is a print server. - ********************************************************************/ - -static BOOL handle_is_printserver(pipes_struct *p, POLICY_HND *handle) -{ - Printer_entry *Printer=find_printer_index_by_hnd(p,handle); + DEBUG(5, ("%d printer handles active\n", (int)p->pipe_handles->count )); - if (!Printer) - return False; - - if (Printer->printer_type != PRINTER_HANDLE_IS_PRINTSERVER) - return False; - return True; } /**************************************************************************** - allocate more memory for a BUFFER. + Allocate more memory for a BUFFER. ****************************************************************************/ + static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size) { prs_struct *ps; @@ -646,6 +616,7 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, fstring name; int snum; struct current_user user; + Printer_entry *Printer=NULL; if (q_u->printername_ptr != 0) printername = &q_u->printername; @@ -659,9 +630,17 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, DEBUGADD(3,("checking name: %s\n",name)); - if (!open_printer_hnd(p, handle, name)) + if (!open_printer_hnd(p, handle, name, 0)) return WERR_INVALID_PRINTER_NAME; + Printer=find_printer_index_by_hnd(p, handle); + if (!Printer) { + DEBUG(0,(" _spoolss_open_printer_ex: logic error. \ +Can't find printer handle we created for priunter %s\n", name )); + close_printer_handle(p,handle); + return WERR_INVALID_PRINTER_NAME; + } + /* if (printer_default->datatype_ptr != NULL) { @@ -672,11 +651,6 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, set_printer_hnd_datatype(handle, ""); */ - if (!set_printer_hnd_accesstype(p, handle, printer_default->access_required)) { - close_printer_handle(p, handle); - return WERR_ACCESS_DENIED; - } - /* First case: the user is opening the print server: @@ -702,7 +676,7 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, get_current_user(&user, p); - if (handle_is_printserver(p, handle)) { + if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) { if (printer_default->access_required == 0) { return WERR_OK; } @@ -755,6 +729,21 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, return WERR_ACCESS_DENIED; } + /* + * An admin user always has access. + */ + + if (user.uid == 0 || user_in_list(uidtoname(user.uid), lp_printer_admin(snum))) + printer_default->access_required = PRINTER_ACCESS_ADMINISTER; + + if (printer_default->access_required & PRINTER_ACCESS_ADMINISTER) + printer_default->access_required = PRINTER_ACCESS_ADMINISTER; + else + printer_default->access_required = PRINTER_ACCESS_USE; + + DEBUG(4,("Setting printer access=%x\n", printer_default->access_required)); + Printer->access_granted = printer_default->access_required; + /* * If we have a default device pointer in the * printer_default struct, then we need to get @@ -836,6 +825,7 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, /**************************************************************************** ****************************************************************************/ + static BOOL convert_printer_info(const SPOOL_PRINTER_INFO_LEVEL *uni, NT_PRINTER_INFO_LEVEL *printer, uint32 level) { @@ -1022,6 +1012,7 @@ WERROR _spoolss_deleteprinter(pipes_struct *p, SPOOL_Q_DELETEPRINTER *q_u, SPOOL * static function to lookup the version id corresponding to an * long architecture string ******************************************************************/ + static int get_version_id (char * arch) { int i; @@ -1090,10 +1081,10 @@ WERROR _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER return delete_printer_driver(info.info_3); } - /******************************************************************** GetPrinterData on a printer server Handle. ********************************************************************/ + static BOOL getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint32 *type, uint8 **data, uint32 *needed, uint32 in_size) { int i; @@ -1183,6 +1174,7 @@ static BOOL getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint32 /******************************************************************** GetPrinterData on a printer Handle. ********************************************************************/ + static BOOL getprinterdata_printer(pipes_struct *p, TALLOC_CTX *ctx, POLICY_HND *handle, fstring value, uint32 *type, uint8 **data, uint32 *needed, uint32 in_size ) @@ -1303,8 +1295,9 @@ WERROR _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO } /*************************************************************************** - connect to the client + Connect to the client. ****************************************************************************/ + static BOOL srv_spoolss_replyopenprinter(char *printer, uint32 localprinter, uint32 type, POLICY_HND *handle) { WERROR status; @@ -1413,6 +1406,7 @@ static void spoolss_notify_server_name(int snum, /******************************************************************* * fill a notify_info_data with the printername (not including the servername). ********************************************************************/ + static void spoolss_notify_printer_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -1447,6 +1441,7 @@ static void spoolss_notify_printer_name(int snum, /******************************************************************* * fill a notify_info_data with the servicename ********************************************************************/ + static void spoolss_notify_share_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -1472,6 +1467,7 @@ static void spoolss_notify_share_name(int snum, /******************************************************************* * fill a notify_info_data with the port name ********************************************************************/ + static void spoolss_notify_port_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -1501,6 +1497,7 @@ static void spoolss_notify_port_name(int snum, * jfmxxxx: it's incorrect, should be lp_printerdrivername() * but it doesn't exist, have to see what to do ********************************************************************/ + static void spoolss_notify_driver_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -1525,6 +1522,7 @@ static void spoolss_notify_driver_name(int snum, /******************************************************************* * fill a notify_info_data with the comment ********************************************************************/ + static void spoolss_notify_comment(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -1555,6 +1553,7 @@ static void spoolss_notify_comment(int snum, * jfm:xxxx incorrect, have to create a new smb.conf option * location = "Room 1, floor 2, building 3" ********************************************************************/ + static void spoolss_notify_location(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -1581,6 +1580,7 @@ static void spoolss_notify_location(int snum, * fill a notify_info_data with the device mode * jfm:xxxx don't to it for know but that's a real problem !!! ********************************************************************/ + static void spoolss_notify_devmode(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -1594,6 +1594,7 @@ static void spoolss_notify_devmode(int snum, * jfm:xxxx just return no file could add an option to smb.conf * separator file = "separator.txt" ********************************************************************/ + static void spoolss_notify_sepfile(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -1620,6 +1621,7 @@ static void spoolss_notify_sepfile(int snum, * fill a notify_info_data with the print processor * jfm:xxxx return always winprint to indicate we don't do anything to it ********************************************************************/ + static void spoolss_notify_print_processor(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -1646,6 +1648,7 @@ static void spoolss_notify_print_processor(int snum, * fill a notify_info_data with the print processor options * jfm:xxxx send an empty string ********************************************************************/ + static void spoolss_notify_parameters(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -1672,6 +1675,7 @@ static void spoolss_notify_parameters(int snum, * fill a notify_info_data with the data type * jfm:xxxx always send RAW as data type ********************************************************************/ + static void spoolss_notify_datatype(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -1699,6 +1703,7 @@ static void spoolss_notify_datatype(int snum, * jfm:xxxx send an null pointer to say no security desc * have to implement security before ! ********************************************************************/ + static void spoolss_notify_security_desc(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -1713,6 +1718,7 @@ static void spoolss_notify_security_desc(int snum, * fill a notify_info_data with the attributes * jfm:xxxx a samba printer is always shared ********************************************************************/ + static void spoolss_notify_attributes(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -1726,6 +1732,7 @@ static void spoolss_notify_attributes(int snum, /******************************************************************* * fill a notify_info_data with the priority ********************************************************************/ + static void spoolss_notify_priority(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -1739,6 +1746,7 @@ static void spoolss_notify_priority(int snum, /******************************************************************* * fill a notify_info_data with the default priority ********************************************************************/ + static void spoolss_notify_default_priority(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -1752,6 +1760,7 @@ static void spoolss_notify_default_priority(int snum, /******************************************************************* * fill a notify_info_data with the start time ********************************************************************/ + static void spoolss_notify_start_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -1765,6 +1774,7 @@ static void spoolss_notify_start_time(int snum, /******************************************************************* * fill a notify_info_data with the until time ********************************************************************/ + static void spoolss_notify_until_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -1778,6 +1788,7 @@ static void spoolss_notify_until_time(int snum, /******************************************************************* * fill a notify_info_data with the status ********************************************************************/ + static void spoolss_notify_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -1794,6 +1805,7 @@ static void spoolss_notify_status(int snum, /******************************************************************* * fill a notify_info_data with the number of jobs queued ********************************************************************/ + static void spoolss_notify_cjobs(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -1807,6 +1819,7 @@ static void spoolss_notify_cjobs(int snum, /******************************************************************* * fill a notify_info_data with the average ppm ********************************************************************/ + static void spoolss_notify_average_ppm(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -1822,6 +1835,7 @@ static void spoolss_notify_average_ppm(int snum, /******************************************************************* * fill a notify_info_data with username ********************************************************************/ + static void spoolss_notify_username(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -1847,6 +1861,7 @@ static void spoolss_notify_username(int snum, /******************************************************************* * fill a notify_info_data with job status ********************************************************************/ + static void spoolss_notify_job_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -1860,6 +1875,7 @@ static void spoolss_notify_job_status(int snum, /******************************************************************* * fill a notify_info_data with job name ********************************************************************/ + static void spoolss_notify_job_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -1885,6 +1901,7 @@ static void spoolss_notify_job_name(int snum, /******************************************************************* * fill a notify_info_data with job status ********************************************************************/ + static void spoolss_notify_job_status_string(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -1934,6 +1951,7 @@ static void spoolss_notify_job_status_string(int snum, /******************************************************************* * fill a notify_info_data with job time ********************************************************************/ + static void spoolss_notify_job_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -1947,6 +1965,7 @@ static void spoolss_notify_job_time(int snum, /******************************************************************* * fill a notify_info_data with job size ********************************************************************/ + static void spoolss_notify_job_size(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -2085,8 +2104,9 @@ struct s_notify_info_data_table notify_info_data_table[] = }; /******************************************************************* -return the size of info_data structure + Return the size of info_data structure. ********************************************************************/ + static uint32 size_of_notify_info_data(uint16 type, uint16 field) { int i=0; @@ -2104,8 +2124,9 @@ static uint32 size_of_notify_info_data(uint16 type, uint16 field) } /******************************************************************* -return the type of notify_info_data + Return the type of notify_info_data. ********************************************************************/ + static BOOL type_of_notify_info_data(uint16 type, uint16 field) { int i=0; @@ -2131,6 +2152,7 @@ static BOOL type_of_notify_info_data(uint16 type, uint16 field) /**************************************************************************** ****************************************************************************/ + static int search_notify(uint16 type, uint16 field, int *value) { int j; @@ -2152,6 +2174,7 @@ static int search_notify(uint16 type, uint16 field, int *value) /**************************************************************************** ****************************************************************************/ + static void construct_info_data(SPOOL_NOTIFY_INFO_DATA *info_data, uint16 type, uint16 field, int id) { info_data->type = type; @@ -2168,6 +2191,7 @@ static void construct_info_data(SPOOL_NOTIFY_INFO_DATA *info_data, uint16 type, * fill a notify_info struct with info asked * ********************************************************************/ + static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPOOL_NOTIFY_OPTION_TYPE *option_type, uint32 id, @@ -2225,6 +2249,7 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int * fill a notify_info struct with info asked * ********************************************************************/ + static BOOL construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_INFO *info, NT_PRINTER_INFO_LEVEL *printer, @@ -2358,6 +2383,7 @@ static WERROR printserver_notify_info(pipes_struct *p, POLICY_HND *hnd, * fill a notify_info struct with info asked * ********************************************************************/ + static WERROR printer_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info, TALLOC_CTX *mem_ctx) { @@ -2494,6 +2520,7 @@ WERROR _spoolss_rfnpcnex( pipes_struct *p, SPOOL_Q_RFNPCNEX *q_u, SPOOL_R_RFNPCN * construct_printer_info_0 * fill a printer_info_0 struct ********************************************************************/ + static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum) { pstring chaine; @@ -2598,6 +2625,7 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum) * construct_printer_info_1 * fill a printer_info_1 struct ********************************************************************/ + static BOOL construct_printer_info_1(uint32 flags, PRINTER_INFO_1 *printer, int snum) { pstring chaine; @@ -2795,6 +2823,7 @@ static BOOL construct_printer_info_2(PRINTER_INFO_2 *printer, int snum) * construct_printer_info_3 * fill a printer_info_3 struct ********************************************************************/ + static BOOL construct_printer_info_3(PRINTER_INFO_3 **pp_printer, int snum) { NT_PRINTER_INFO_LEVEL *ntprinter = NULL; @@ -2887,10 +2916,10 @@ static BOOL construct_printer_info_5(PRINTER_INFO_5 *printer, int snum) return True; } - /******************************************************************** Spoolss_enumprinters. ********************************************************************/ + static WERROR enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int snum; @@ -2945,6 +2974,7 @@ static WERROR enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 /******************************************************************** enum_all_printers_info_1_local. *********************************************************************/ + static WERROR enum_all_printers_info_1_local(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { DEBUG(4,("enum_all_printers_info_1_local\n")); @@ -2955,6 +2985,7 @@ static WERROR enum_all_printers_info_1_local(NEW_BUFFER *buffer, uint32 offered, /******************************************************************** enum_all_printers_info_1_name. *********************************************************************/ + static WERROR enum_all_printers_info_1_name(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { char *s = name; @@ -2974,6 +3005,7 @@ static WERROR enum_all_printers_info_1_name(fstring name, NEW_BUFFER *buffer, ui /******************************************************************** enum_all_printers_info_1_remote. *********************************************************************/ + static WERROR enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PRINTER_INFO_1 *printer; @@ -3102,6 +3134,7 @@ static WERROR enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint3 /******************************************************************** * handle enumeration of printers at level 1 ********************************************************************/ + static WERROR enumprinters_level1( uint32 flags, fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) @@ -3126,6 +3159,7 @@ static WERROR enumprinters_level1( uint32 flags, fstring name, /******************************************************************** * handle enumeration of printers at level 2 ********************************************************************/ + static WERROR enumprinters_level2( uint32 flags, fstring servername, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) @@ -3154,6 +3188,7 @@ static WERROR enumprinters_level2( uint32 flags, fstring servername, /******************************************************************** * handle enumeration of printers at level 5 ********************************************************************/ + static WERROR enumprinters_level5( uint32 flags, fstring servername, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) @@ -3221,6 +3256,7 @@ WERROR _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOOL_ /**************************************************************************** ****************************************************************************/ + static WERROR getprinter_level_0(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_0 *printer=NULL; @@ -3253,6 +3289,7 @@ static WERROR getprinter_level_0(int snum, NEW_BUFFER *buffer, uint32 offered, u /**************************************************************************** ****************************************************************************/ + static WERROR getprinter_level_1(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_1 *printer=NULL; @@ -3285,6 +3322,7 @@ static WERROR getprinter_level_1(int snum, NEW_BUFFER *buffer, uint32 offered, u /**************************************************************************** ****************************************************************************/ + static WERROR getprinter_level_2(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_2 *printer=NULL; @@ -3320,6 +3358,7 @@ static WERROR getprinter_level_2(int snum, NEW_BUFFER *buffer, uint32 offered, u /**************************************************************************** ****************************************************************************/ + static WERROR getprinter_level_3(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_3 *printer=NULL; @@ -3350,6 +3389,7 @@ static WERROR getprinter_level_3(int snum, NEW_BUFFER *buffer, uint32 offered, u /**************************************************************************** ****************************************************************************/ + static WERROR getprinter_level_4(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_4 *printer=NULL; @@ -3383,6 +3423,7 @@ static WERROR getprinter_level_4(int snum, NEW_BUFFER *buffer, uint32 offered, u /**************************************************************************** ****************************************************************************/ + static WERROR getprinter_level_5(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_5 *printer=NULL; @@ -3456,6 +3497,7 @@ WERROR _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GET /******************************************************************** * fill a DRIVER_INFO_1 struct ********************************************************************/ + static void fill_printer_driver_info_1(DRIVER_INFO_1 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername, fstring architecture) { init_unistr( &info->name, driver.info_3->name); @@ -3464,6 +3506,7 @@ static void fill_printer_driver_info_1(DRIVER_INFO_1 *info, NT_PRINTER_DRIVER_IN /******************************************************************** * construct_printer_driver_info_1 ********************************************************************/ + static WERROR construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, fstring servername, fstring architecture, uint32 version) { NT_PRINTER_INFO_LEVEL *printer = NULL; @@ -3488,6 +3531,7 @@ static WERROR construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, fst * construct_printer_driver_info_2 * fill a printer_info_2 struct ********************************************************************/ + static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername) { pstring temp; @@ -3521,6 +3565,7 @@ static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, NT_PRINTER_DRIVER_IN * construct_printer_driver_info_2 * fill a printer_info_2 struct ********************************************************************/ + static WERROR construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fstring servername, fstring architecture, uint32 version) { NT_PRINTER_INFO_LEVEL *printer = NULL; @@ -3547,6 +3592,7 @@ static WERROR construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fst * * convert an array of ascii string to a UNICODE string ********************************************************************/ + static void init_unistr_array(uint16 **uni_array, fstring *char_array, char *servername) { int i=0; @@ -3588,6 +3634,7 @@ static void init_unistr_array(uint16 **uni_array, fstring *char_array, char *ser * construct_printer_info_3 * fill a printer_info_3 struct ********************************************************************/ + static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername) { pstring temp; @@ -3634,6 +3681,7 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_IN * construct_printer_info_3 * fill a printer_info_3 struct ********************************************************************/ + static WERROR construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fstring servername, fstring architecture, uint32 version) { NT_PRINTER_INFO_LEVEL *printer = NULL; @@ -3756,6 +3804,7 @@ static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_IN * construct_printer_info_6 * fill a printer_info_6 struct ********************************************************************/ + static WERROR construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, fstring servername, fstring architecture, uint32 version) { NT_PRINTER_INFO_LEVEL *printer = NULL; @@ -3816,6 +3865,7 @@ static void free_printer_driver_info_6(DRIVER_INFO_6 *info) /**************************************************************************** ****************************************************************************/ + static WERROR getprinterdriver2_level1(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_1 *info=NULL; @@ -3852,6 +3902,7 @@ static WERROR getprinterdriver2_level1(fstring servername, fstring architecture, /**************************************************************************** ****************************************************************************/ + static WERROR getprinterdriver2_level2(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_2 *info=NULL; @@ -3888,6 +3939,7 @@ static WERROR getprinterdriver2_level2(fstring servername, fstring architecture, /**************************************************************************** ****************************************************************************/ + static WERROR getprinterdriver2_level3(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_3 info; @@ -3921,6 +3973,7 @@ static WERROR getprinterdriver2_level3(fstring servername, fstring architecture, /**************************************************************************** ****************************************************************************/ + static WERROR getprinterdriver2_level6(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_6 info; @@ -4152,6 +4205,7 @@ WERROR _spoolss_writeprinter(pipes_struct *p, SPOOL_Q_WRITEPRINTER *q_u, SPOOL_R * called from the spoolss dispatcher * ********************************************************************/ + static WERROR control_printer(POLICY_HND *handle, uint32 command, pipes_struct *p) { @@ -4209,6 +4263,7 @@ WERROR _spoolss_abortprinter(pipes_struct *p, SPOOL_Q_ABORTPRINTER *q_u, SPOOL_R * called by spoolss_api_setprinter * when updating a printer description ********************************************************************/ + static WERROR update_printer_sec(POLICY_HND *handle, uint32 level, const SPOOL_PRINTER_INFO_LEVEL *info, pipes_struct *p, SEC_DESC_BUF *secdesc_ctr) @@ -4322,6 +4377,7 @@ static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) /**************************************************************************** ****************************************************************************/ + static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) { char *cmd = lp_addprinter_cmd(); @@ -4714,8 +4770,8 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, /* Check calling user has permission to update printer description */ - if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { - DEBUG(3, ("update_printer: printer property change denied by security descriptor\n")); + if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) { + DEBUG(3, ("update_printer: printer property change denied by handle\n")); result = WERR_ACCESS_DENIED; goto done; } @@ -4845,6 +4901,7 @@ WERROR _spoolss_addjob(pipes_struct *p, SPOOL_Q_ADDJOB *q_u, SPOOL_R_ADDJOB *r_u /**************************************************************************** ****************************************************************************/ + static void fill_job_info_1(JOB_INFO_1 *job_info, print_queue_struct *queue, int position, int snum) { @@ -4873,6 +4930,7 @@ static void fill_job_info_1(JOB_INFO_1 *job_info, print_queue_struct *queue, /**************************************************************************** ****************************************************************************/ + static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, int position, int snum, NT_PRINTER_INFO_LEVEL *ntprinter, @@ -4922,6 +4980,7 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, /**************************************************************************** Enumjobs at level 1. ****************************************************************************/ + static WERROR enumjobs_level1(print_queue_struct *queue, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) @@ -4968,6 +5027,7 @@ static WERROR enumjobs_level1(print_queue_struct *queue, int snum, /**************************************************************************** Enumjobs at level 2. ****************************************************************************/ + static WERROR enumjobs_level2(print_queue_struct *queue, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) @@ -5146,6 +5206,7 @@ WERROR _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u /**************************************************************************** Enumerates all printer drivers at level 1. ****************************************************************************/ + static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int i; @@ -5226,6 +5287,7 @@ static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture /**************************************************************************** Enumerates all printer drivers at level 2. ****************************************************************************/ + static WERROR enumprinterdrivers_level2(fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int i; @@ -5307,6 +5369,7 @@ static WERROR enumprinterdrivers_level2(fstring servername, fstring architecture /**************************************************************************** Enumerates all printer drivers at level 3. ****************************************************************************/ + static WERROR enumprinterdrivers_level3(fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int i; @@ -5635,6 +5698,7 @@ WERROR _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * /**************************************************************************** ****************************************************************************/ + static void fill_port_1(PORT_INFO_1 *port, char *name) { init_unistr(&port->port_name, name); @@ -5642,6 +5706,7 @@ static void fill_port_1(PORT_INFO_1 *port, char *name) /**************************************************************************** ****************************************************************************/ + static void fill_port_2(PORT_INFO_2 *port, char *name) { init_unistr(&port->port_name, name); @@ -5655,6 +5720,7 @@ static void fill_port_2(PORT_INFO_2 *port, char *name) /**************************************************************************** enumports level 1. ****************************************************************************/ + static WERROR enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PORT_INFO_1 *ports=NULL; @@ -5873,6 +5939,7 @@ WERROR _spoolss_enumports( pipes_struct *p, SPOOL_Q_ENUMPORTS *q_u, SPOOL_R_ENUM /**************************************************************************** ****************************************************************************/ + static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_srv_name, const SPOOL_PRINTER_INFO_LEVEL *info, DEVICEMODE *devmode, SEC_DESC_BUF *sec_desc_buf, @@ -5962,7 +6029,7 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ return err; } - if (!open_printer_hnd(p, handle, name)) { + if (!open_printer_hnd(p, handle, name, PRINTER_ACCESS_ADMINISTER)) { /* Handle open failed - remove addition. */ del_a_printer(printer->info_2->sharename); free_a_printer(&printer,2); @@ -6051,6 +6118,7 @@ WERROR _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u, /**************************************************************************** ****************************************************************************/ + static void fill_driverdir_1(DRIVER_DIRECTORY_1 *info, char *name) { init_unistr(&info->name, name); @@ -6058,6 +6126,7 @@ static void fill_driverdir_1(DRIVER_DIRECTORY_1 *info, char *name) /**************************************************************************** ****************************************************************************/ + static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environment, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { pstring path; @@ -6347,9 +6416,8 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP * when connecting to a printer --jerry */ - if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { - DEBUG(3, ("security descriptor change denied by existing " - "security descriptor\n")); + if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) { + DEBUG(3, ("_spoolss_setprinterdata: change denied by handle access permissions\n")); status = WERR_ACCESS_DENIED; goto done; } @@ -6439,9 +6507,8 @@ WERROR _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_ if (!get_printer_snum(p, handle, &snum)) return WERR_BADFID; - if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { - DEBUG(3, ("_spoolss_deleteprinterdata: printer properties " - "change denied by existing security descriptor\n")); + if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) { + DEBUG(3, ("_spoolss_deleteprinterdata: printer properties change denied by handle\n")); return WERR_ACCESS_DENIED; } @@ -6488,9 +6555,8 @@ WERROR _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM if (!get_printer_snum(p,handle, &snum)) return WERR_BADFID; - if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { - DEBUG(3, ("security descriptor change denied by existing " - "security descriptor\n")); + if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) { + DEBUG(2,("_spoolss_addform: denied by handle permissions.\n")); status = WERR_ACCESS_DENIED; goto done; } @@ -6550,9 +6616,8 @@ WERROR _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE if (!get_printer_snum(p, handle, &snum)) return WERR_BADFID; - if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { - DEBUG(3, ("security descriptor change denied by existing " - "security descriptor\n")); + if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) { + DEBUG(2,("_spoolss_deleteform: denied by handle permissions\n")); return WERR_ACCESS_DENIED; } @@ -6612,9 +6677,8 @@ WERROR _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM * if (!get_printer_snum(p, handle, &snum)) return WERR_BADFID; - if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { - DEBUG(3, ("security descriptor change denied by existing " - "security descriptor\n")); + if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) { + DEBUG(2,("_spoolss_setform: denied by handle permissions\n")); return WERR_ACCESS_DENIED; } @@ -6649,6 +6713,7 @@ done: /**************************************************************************** enumprintprocessors level 1. ****************************************************************************/ + static WERROR enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PRINTPROCESSOR_1 *info_1=NULL; @@ -6717,6 +6782,7 @@ WERROR _spoolss_enumprintprocessors(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCESSORS /**************************************************************************** enumprintprocdatatypes level 1. ****************************************************************************/ + static WERROR enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PRINTPROCDATATYPE_1 *info_1=NULL; @@ -6810,6 +6876,7 @@ static WERROR enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, uint /**************************************************************************** enumprintmonitors level 2. ****************************************************************************/ + static WERROR enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PRINTMONITOR_2 *info_2=NULL; @@ -6880,6 +6947,7 @@ WERROR _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS *q_ /**************************************************************************** ****************************************************************************/ + static WERROR getjob_level_1(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { int i=0; @@ -6926,9 +6994,9 @@ static WERROR getjob_level_1(print_queue_struct *queue, int count, int snum, uin return WERR_OK; } - /**************************************************************************** ****************************************************************************/ + static WERROR getjob_level_2(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { int i=0; -- cgit From 194e39b179efc040c3db65996edaf9e785ef6d78 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 8 Mar 2002 00:26:18 +0000 Subject: Turns out an Admin user shouldn't always have access on a handle. Jeremy. (This used to be commit d31d2dcd22e1be2c26ea315e1b0e8442822a9a0f) --- source3/rpc_server/srv_spoolss_nt.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index eb10de3253..7319356568 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -729,13 +729,6 @@ Can't find printer handle we created for priunter %s\n", name )); return WERR_ACCESS_DENIED; } - /* - * An admin user always has access. - */ - - if (user.uid == 0 || user_in_list(uidtoname(user.uid), lp_printer_admin(snum))) - printer_default->access_required = PRINTER_ACCESS_ADMINISTER; - if (printer_default->access_required & PRINTER_ACCESS_ADMINISTER) printer_default->access_required = PRINTER_ACCESS_ADMINISTER; else -- cgit From c3e813945c5c44a846efa522632e2b1e724d0bd9 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 8 Mar 2002 21:57:53 +0000 Subject: merge from 2.2 (This used to be commit 4960692e958c986ca7f71e091333300310b0e0b2) --- source3/rpc_server/srv_spoolss_nt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 7319356568..294d9d5535 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1282,7 +1282,7 @@ WERROR _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO } if (*needed > *out_size) - return WERR_STATUS_MORE_ENTRIES; + return WERR_MORE_DATA; else return WERR_OK; } @@ -7176,7 +7176,7 @@ WERROR _spoolss_getprinterdataex(pipes_struct *p, SPOOL_Q_GETPRINTERDATAEX *q_u, *data = NULL; } - return WERR_INVALID_PARAM; + return WERR_BADFILE; } if (*needed > *out_size) -- cgit From 8fa6b34e08e21546082892f27e3d70bae211c371 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 8 Mar 2002 22:07:18 +0000 Subject: merge from 2.2 (This used to be commit 66eb969ade0dfde355df3e308dccbc9522087eef) --- source3/rpc_server/srv_spoolss_nt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 294d9d5535..f489802f77 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1124,7 +1124,7 @@ static BOOL getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint32 *type = 0x4; if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) return False; - SIVAL(*data, 0, 0x02); + SIVAL(*data, 0, 0x03); *needed = 0x4; return True; } @@ -7157,7 +7157,7 @@ WERROR _spoolss_getprinterdataex(pipes_struct *p, SPOOL_Q_GETPRINTERDATAEX *q_u, */ if (strcmp(key, "PrinterDriverData") != 0) - return WERR_INVALID_PARAM; + return WERR_BADFILE; DEBUG(10, ("_spoolss_getprinterdataex: pass me to getprinterdata\n")); found = getprinterdata_printer(p, p->mem_ctx, handle, value, @@ -7176,7 +7176,7 @@ WERROR _spoolss_getprinterdataex(pipes_struct *p, SPOOL_Q_GETPRINTERDATAEX *q_u, *data = NULL; } - return WERR_BADFILE; + return WERR_INVALID_PARAM; } if (*needed > *out_size) -- cgit From 92e59edc410a1de09a3d1eaba09cd46f4db1367f Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 12 Mar 2002 00:16:03 +0000 Subject: Merge of enumprinters vs getprinter naming patch from 2.2 (This used to be commit dfd51bc8d0714473880bf50369f7994304c1d83f) --- source3/rpc_server/srv_spoolss_nt.c | 44 +++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 14 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index f489802f77..f0ea088dc3 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4,9 +4,10 @@ * RPC Pipe client / server routines * Copyright (C) Andrew Tridgell 1992-2000, * Copyright (C) Luke Kenneth Casson Leighton 1996-2000, - * Copyright (C) Jean François Micouleau 1998-2000. - * Copyright (C) Jeremy Allison 2001. - * Copyright (C) Gerald Carter 2000-2001. + * Copyright (C) Jean François Micouleau 1998-2000, + * Copyright (C) Jeremy Allison 2001, + * Copyright (C) Gerald Carter 2000-2001, + * Copyright (C) Tim Potter 2001-2002. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -2617,9 +2618,13 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum) /******************************************************************** * construct_printer_info_1 * fill a printer_info_1 struct + * + * The is_enum parameter says whether the PRINTER_INFO_1 returned is + * to be used in an enumprinters call. This affects whether the netbios + * name of the server is prefixed to the printer and server names. ********************************************************************/ - -static BOOL construct_printer_info_1(uint32 flags, PRINTER_INFO_1 *printer, int snum) +static BOOL construct_printer_info_1(uint32 flags, PRINTER_INFO_1 *printer, + int snum, BOOL is_enum) { pstring chaine; pstring chaine2; @@ -2632,13 +2637,23 @@ static BOOL construct_printer_info_1(uint32 flags, PRINTER_INFO_1 *printer, int if (*ntprinter->info_2->comment == '\0') { init_unistr(&printer->comment, lp_comment(snum)); - slprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",get_called_name(), ntprinter->info_2->printername, - ntprinter->info_2->drivername, lp_comment(snum)); - } - else { + if (is_enum) { + char *p; + + p = strchr(ntprinter->info_2->printername + 2, '\\'); + + if (p) + fstrcpy(ntprinter->info_2->printername, p + 1); + } + slprintf(chaine,sizeof(chaine)-1,"%s,%s,%s", + ntprinter->info_2->printername, + ntprinter->info_2->drivername, lp_comment(snum)); + } else { init_unistr(&printer->comment, ntprinter->info_2->comment); /* saved comment. */ - slprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",get_called_name(), ntprinter->info_2->printername, - ntprinter->info_2->drivername, ntprinter->info_2->comment); + slprintf(chaine,sizeof(chaine)-1,"%s,%s,%s", + ntprinter->info_2->printername, + ntprinter->info_2->drivername, + ntprinter->info_2->comment); } slprintf(chaine2,sizeof(chaine)-1,"%s", ntprinter->info_2->printername); @@ -2926,8 +2941,8 @@ static WERROR enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 for (snum=0; snum Date: Thu, 14 Mar 2002 01:48:59 +0000 Subject: Backed out enumprinters stuff - leave it for another day. (This used to be commit d7efc5dd3dd712e7138b5c79eea9756125757175) --- source3/rpc_server/srv_spoolss_nt.c | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index f0ea088dc3..3479e47f76 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2618,13 +2618,9 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum) /******************************************************************** * construct_printer_info_1 * fill a printer_info_1 struct - * - * The is_enum parameter says whether the PRINTER_INFO_1 returned is - * to be used in an enumprinters call. This affects whether the netbios - * name of the server is prefixed to the printer and server names. ********************************************************************/ -static BOOL construct_printer_info_1(uint32 flags, PRINTER_INFO_1 *printer, - int snum, BOOL is_enum) + +static BOOL construct_printer_info_1(uint32 flags, PRINTER_INFO_1 *printer, int snum) { pstring chaine; pstring chaine2; @@ -2637,23 +2633,13 @@ static BOOL construct_printer_info_1(uint32 flags, PRINTER_INFO_1 *printer, if (*ntprinter->info_2->comment == '\0') { init_unistr(&printer->comment, lp_comment(snum)); - if (is_enum) { - char *p; - - p = strchr(ntprinter->info_2->printername + 2, '\\'); - - if (p) - fstrcpy(ntprinter->info_2->printername, p + 1); - } - slprintf(chaine,sizeof(chaine)-1,"%s,%s,%s", - ntprinter->info_2->printername, - ntprinter->info_2->drivername, lp_comment(snum)); - } else { + slprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",get_called_name(), ntprinter->info_2->printername, + ntprinter->info_2->drivername, lp_comment(snum)); + } + else { init_unistr(&printer->comment, ntprinter->info_2->comment); /* saved comment. */ - slprintf(chaine,sizeof(chaine)-1,"%s,%s,%s", - ntprinter->info_2->printername, - ntprinter->info_2->drivername, - ntprinter->info_2->comment); + slprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",get_called_name(), ntprinter->info_2->printername, + ntprinter->info_2->drivername, ntprinter->info_2->comment); } slprintf(chaine2,sizeof(chaine)-1,"%s", ntprinter->info_2->printername); @@ -2942,7 +2928,7 @@ static WERROR enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) { DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum)); - if (construct_printer_info_1(flags, ¤t_prt, snum, True)) { + if (construct_printer_info_1(flags, ¤t_prt, snum)) { if((tp=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_1))) == NULL) { DEBUG(2,("enum_all_printers_info_1: failed to enlarge printers buffer!\n")); SAFE_FREE(printers); @@ -3306,7 +3292,7 @@ static WERROR getprinter_level_1(int snum, NEW_BUFFER *buffer, uint32 offered, u if((printer=(PRINTER_INFO_1*)malloc(sizeof(PRINTER_INFO_1))) == NULL) return WERR_NOMEM; - construct_printer_info_1(PRINTER_ENUM_ICON8, printer, snum, False); + construct_printer_info_1(PRINTER_ENUM_ICON8, printer, snum); /* check the required size. */ *needed += spoolss_size_printer_info_1(printer); -- cgit From 65c007b583e2107f5ad1ba6733d3e578a143863e Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 15 Mar 2002 08:14:10 +0000 Subject: syncing up printing code with SAMBA_2_2 (already done some merges in the reverse). * add in new printer change notify code from SAMBA_2_2 * add in se_map_standard() from 2.2 in _spoolss_open_printer_ex() * sync up the _print_queue_struct in smb.h (why did someone change the user/file names in fs_user/fs_file (or vice-versa) ? ) * sync up some cli_spoolss_XXX functions (This used to be commit 5760315c1de4033fdc22684c940f18010010924f) --- source3/rpc_server/srv_spoolss_nt.c | 432 ++++++++++++++++++++++++------------ 1 file changed, 290 insertions(+), 142 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 3479e47f76..a6c0f9368c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -91,6 +91,10 @@ static ubi_dlList counter_list; static struct cli_state cli; static uint32 smb_connections=0; + +/* in printing/nt_printing.c */ +extern STANDARD_MAPPING printer_std_mapping; + #define OUR_HANDLE(hnd) (((hnd)==NULL)?"NULL":(IVAL((hnd)->data5,4)==(uint32)sys_getpid()?"OURS":"OTHER")), \ ((unsigned int)IVAL((hnd)->data5,4)),((unsigned int)sys_getpid()) @@ -158,7 +162,7 @@ static void free_spool_notify_option(SPOOL_NOTIFY_OPTION **pp) static void srv_spoolss_replycloseprinter(POLICY_HND *handle) { - WERROR status; + NTSTATUS result; /* weird if the test succeds !!! */ if (smb_connections==0) { @@ -166,7 +170,9 @@ static void srv_spoolss_replycloseprinter(POLICY_HND *handle) return; } - if(!cli_spoolss_reply_close_printer(&cli, handle, &status)) + result = cli_spoolss_reply_close_printer(&cli, cli.mem_ctx, handle); + + if (!NT_STATUS_IS_OK(result)) DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed.\n")); /* if it's the last connection, deconnect the IPC$ share */ @@ -528,71 +534,233 @@ static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size) return True; } +/*************************************************************************** + Always give preference Printer_entry.notify.option over + Printer_entry.notify.flags. Return True if we should send notification + events using SPOOLSS_RRPCN. False means that we should use + SPOOLSS_ROUTERREPLYPRINTER. + **************************************************************************/ +static BOOL valid_notify_options(Printer_entry *printer) +{ + if (printer->notify.option == NULL) + return False; + + return True; +} /*************************************************************************** - Receive the notify message. -****************************************************************************/ + Simple check to see if the client motify handle is set to watch for events + represented by 'flags' + + FIXME!!!! only a stub right now --jerry + **************************************************************************/ + +static BOOL is_client_monitoring_event(Printer_entry *p, uint32 flags) +{ -static void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size_t len) + return True; +} + +/*************************************************************************** + Server wrapper for cli_spoolss_routerreplyprinter() since the client + function can only send a single change notification at a time. + + FIXME!!! only handles one change currently (PRINTER_CHANGE_SET_PRINTER_DRIVER) + --jerry + **************************************************************************/ + +static NTSTATUS srv_spoolss_routerreplyprinter (struct cli_state *cli, TALLOC_CTX *mem_ctx, + POLICY_HND *pol, PRINTER_MESSAGE_INFO *info, + NT_PRINTER_INFO_LEVEL *printer) { - Printer_entry *find_printer; - WERROR status; - fstring printer_name; - char msg[8]; - char *buf_ptr = (char *)buf; - uint32 low, high; + NTSTATUS result; + uint32 condition = 0x0; + + if (info->flags & PRINTER_MESSAGE_DRIVER) + condition = PRINTER_CHANGE_SET_PRINTER_DRIVER; + + result = cli_spoolss_routerreplyprinter(cli, mem_ctx, pol, condition, + printer->info_2->changeid); - if (len < sizeof(msg) + 2) { - DEBUG(2,("srv_spoolss_receive_message: got incorrect message size (%u)!\n", (unsigned int)len)); - return; + return result; +} + +/*********************************************************************** + Wrapper around the decision of which RPC use to in the change + notification + **********************************************************************/ + +static NTSTATUS srv_spoolss_send_event_to_client(Printer_entry* Printer, + struct cli_state *cli, PRINTER_MESSAGE_INFO *msg, + NT_PRINTER_INFO_LEVEL *info) +{ + NTSTATUS result; + + if (valid_notify_options(Printer)) { + /* This is a single call that can send information about multiple changes */ + if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) + msg->flags |= PRINTER_MESSAGE_ATTRIBUTES; + result = cli_spoolss_reply_rrpcn(cli, cli->mem_ctx, &Printer->notify.client_hnd, + msg, info); } + else { + /* This requires that the server send an individual event notification for each change */ + result = srv_spoolss_routerreplyprinter(cli, cli->mem_ctx, &Printer->notify.client_hnd, + msg, info); + } + + return result; +} - memcpy(msg, buf_ptr, sizeof(msg)); - low = IVAL(msg,0); - high = IVAL(msg,4); - fstrcpy(printer_name, buf_ptr + sizeof(msg)); - DEBUG(10,("srv_spoolss_receive_message: Got message printer change name [%s] low=0x%x high=0x%x\n", - printer_name, (unsigned int)low, (unsigned int)high )); +/*********************************************************************** + Send a change notication message on all handles which have a call + back registered + **********************************************************************/ + +static void send_spoolss_event_notification(PRINTER_MESSAGE_INFO *msg) +{ + Printer_entry *find_printer; + NTSTATUS result; + WERROR wresult; + NT_PRINTER_INFO_LEVEL *printer = NULL; + + if (!msg) { + DEBUG(0,("send_spoolss_event_notification: NULL msg pointer!\n")); + return; + } - /* Iterate the printer list */ for(find_printer = printers_list; find_printer; find_printer = find_printer->next) { /* - * If the entry has a connected client we send the message. + * If the entry has a connected client we send the message. There should + * only be one of these normally when dealing with the NT/2k spooler. + * However, iterate over all to make sure we deal with user applications + * in addition to spooler service. + * + * While we are only maintaining a single connection to the client, + * the FindFirstPrinterChangeNotification() call is made on a printer + * handle, so "client_connected" represents the whether or not the + * client asked for change notication on this handle. + * + * --jerry */ if (find_printer->notify.client_connected==True) { - DEBUG(10,("srv_spoolss_receive_message: printerserver [%s]\n", find_printer->dev.printerservername )); - if (*printer_name && !strequal(printer_name, find_printer->dev.handlename)) { - DEBUG(10,("srv_spoolss_receive_message: ignoring message sent to %s [%s]\n", - printer_name, find_printer->dev.handlename )); + + /* does the client care about what changed? */ + + if (msg->flags && !is_client_monitoring_event(find_printer, msg->flags)) { + DEBUG(10,("send_spoolss_event_notification: Client [%s] not monitoring these events\n", + find_printer->client.machine)); continue; } - if (cli_spoolss_reply_rrpcn(&cli, &find_printer->notify.client_hnd, low, high, &status)) - DEBUG(10,("srv_spoolss_receive_message: cli_spoolss_reply_rrpcn status = 0x%x\n", - (unsigned int)W_ERROR_V(status))); + if (find_printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) + DEBUG(10,("send_spoolss_event_notification: printserver [%s]\n", find_printer->dev.printerservername )); else - DEBUG(10,("srv_spoolss_receive_message: cli_spoolss_reply_rrpcn failed\n")); + DEBUG(10,("send_spoolss_event_notification: printer [%s]\n", find_printer->dev.handlename)); + + /* + * if handle is a printer, only send if the printer_name matches. + * ...else if handle is a printerserver, send to all + */ + + if (*msg->printer_name && (find_printer->printer_type==PRINTER_HANDLE_IS_PRINTER) + && !strequal(msg->printer_name, find_printer->dev.handlename)) + { + DEBUG(10,("send_spoolss_event_notification: ignoring message sent to %s [%s]\n", + msg->printer_name, find_printer->dev.handlename )); + continue; + } + + + /* lookup the printer if we have a name if we don't already have a + valid NT_PRINTER_INFO_LEVEL structure. And yes I'm assuming we + will always have a non-empty msg.printer_name */ + + if (!printer || !printer->info_2 || strcmp(msg->printer_name, printer->info_2->printername)) + { + + if (printer) { + free_a_printer(&printer, 2); + printer = NULL; + } + + wresult = get_a_printer(&printer, 2, msg->printer_name); + if (! W_ERROR_IS_OK(wresult)) + continue; + } + + /* issue the client call */ + + result = srv_spoolss_send_event_to_client(find_printer, &cli, msg, printer); + + if (!NT_STATUS_IS_OK(result)) { + DEBUG(10,("send_spoolss_event_notification: Event notification failed [%s]\n", + get_nt_error_msg(result))); } } } + return; +} +/*************************************************************************** + Receive the notify message and decode the message. Do not send + notification if we sent this originally as that would result in + duplicates. +****************************************************************************/ + +static void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size_t len) +{ + PRINTER_MESSAGE_INFO msg; + pid_t my_pid = sys_getpid(); + + if (len < sizeof(msg)) { + DEBUG(2,("srv_spoolss_receive_message: got incorrect message size (%u)!\n", (unsigned int)len)); + return; + } + + memcpy(&msg, buf, sizeof(PRINTER_MESSAGE_INFO)); + + if (my_pid == src) { + DEBUG(10,("srv_spoolss_receive_message: Skipping message to myself\n")); + return; + } + + DEBUG(10,("srv_spoolss_receive_message: Got message printer change [queue = %s] low=0x%x high=0x%x flags=0x%x\n", + msg.printer_name, (unsigned int)msg.low, (unsigned int)msg.high, msg.flags )); + + /* Iterate the printer list */ + + send_spoolss_event_notification(&msg); + +} + /*************************************************************************** Send a notify event. ****************************************************************************/ -static BOOL srv_spoolss_sendnotify(uint32 high, uint32 low) +static BOOL srv_spoolss_sendnotify(char* printer_name, uint32 high, uint32 low, uint32 flags) { - char msg[10]; + char msg[sizeof(PRINTER_MESSAGE_INFO)]; + PRINTER_MESSAGE_INFO info; + + ZERO_STRUCT(info); - ZERO_STRUCT(msg); - SIVAL(msg,0,low); - SIVAL(msg,4,high); - DEBUG(10,("srv_spoolss_sendnotify: printer change low=0x%x high=0x%x\n", low, high)); + info.low = low; + info.high = high; + info.flags = flags; + fstrcpy(info.printer_name, printer_name); + + memcpy(msg, &info, sizeof(PRINTER_MESSAGE_INFO)); + + DEBUG(10,("srv_spoolss_sendnotify: printer change low=0x%x high=0x%x [%s], flags=0x%x\n", + low, high, printer_name, flags)); + + message_send_all(conn_tdb_ctx(), MSG_PRINTER_NOTIFY, msg, sizeof(PRINTER_MESSAGE_INFO), + False, NULL); - message_send_all(conn_tdb_ctx(), MSG_PRINTER_NOTIFY, msg, sizeof(msg), False, NULL); return True; } @@ -707,6 +875,8 @@ Can't find printer handle we created for priunter %s\n", name )); if (!get_printer_snum(p, handle, &snum)) return WERR_BADFID; + se_map_standard(&printer_default->access_required, &printer_std_mapping); + /* map an empty access mask to the minimum access mask */ if (printer_default->access_required == 0x0) printer_default->access_required = PRINTER_ACCESS_USE; @@ -993,10 +1163,10 @@ WERROR _spoolss_deleteprinter(pipes_struct *p, SPOOL_Q_DELETEPRINTER *q_u, SPOOL result = delete_printer_handle(p, handle); - update_c_setprinter(FALSE); + update_c_setprinter(False); if (W_ERROR_IS_OK(result)) { - srv_spoolss_sendnotify(0, PRINTER_CHANGE_DELETE_PRINTER); + srv_spoolss_sendnotify(Printer->dev.handlename, 0, PRINTER_CHANGE_DELETE_PRINTER, 0x0); } return result; @@ -1294,7 +1464,7 @@ WERROR _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO static BOOL srv_spoolss_replyopenprinter(char *printer, uint32 localprinter, uint32 type, POLICY_HND *handle) { - WERROR status; + NTSTATUS result; /* * If it's the first connection, contact the client @@ -1313,10 +1483,10 @@ static BOOL srv_spoolss_replyopenprinter(char *printer, uint32 localprinter, uin smb_connections++; - if(!cli_spoolss_reply_open_printer(&cli, printer, localprinter, type, &status, handle)) - return False; + result = cli_spoolss_reply_open_printer(&cli, cli.mem_ctx, printer, localprinter, + type, handle); - return True; + return (NT_STATUS_IS_OK(result)); } /******************************************************************** @@ -1364,7 +1534,9 @@ WERROR _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE if(srv_spoolss_replyopenprinter(Printer->notify.localmachine, Printer->notify.printerlocal, 1, &Printer->notify.client_hnd)) + { Printer->notify.client_connected=True; + } return WERR_OK; } @@ -1373,7 +1545,7 @@ WERROR _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE * fill a notify_info_data with the servername ********************************************************************/ -static void spoolss_notify_server_name(int snum, +void spoolss_notify_server_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -1401,7 +1573,7 @@ static void spoolss_notify_server_name(int snum, * fill a notify_info_data with the printername (not including the servername). ********************************************************************/ -static void spoolss_notify_printer_name(int snum, +void spoolss_notify_printer_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -1436,7 +1608,7 @@ static void spoolss_notify_printer_name(int snum, * fill a notify_info_data with the servicename ********************************************************************/ -static void spoolss_notify_share_name(int snum, +void spoolss_notify_share_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -1462,7 +1634,7 @@ static void spoolss_notify_share_name(int snum, * fill a notify_info_data with the port name ********************************************************************/ -static void spoolss_notify_port_name(int snum, +void spoolss_notify_port_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -1488,11 +1660,10 @@ static void spoolss_notify_port_name(int snum, /******************************************************************* * fill a notify_info_data with the printername - * jfmxxxx: it's incorrect, should be lp_printerdrivername() * but it doesn't exist, have to see what to do ********************************************************************/ -static void spoolss_notify_driver_name(int snum, +void spoolss_notify_driver_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -1517,7 +1688,7 @@ static void spoolss_notify_driver_name(int snum, * fill a notify_info_data with the comment ********************************************************************/ -static void spoolss_notify_comment(int snum, +void spoolss_notify_comment(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -1544,11 +1715,10 @@ static void spoolss_notify_comment(int snum, /******************************************************************* * fill a notify_info_data with the comment - * jfm:xxxx incorrect, have to create a new smb.conf option * location = "Room 1, floor 2, building 3" ********************************************************************/ -static void spoolss_notify_location(int snum, +void spoolss_notify_location(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -1585,11 +1755,9 @@ static void spoolss_notify_devmode(int snum, /******************************************************************* * fill a notify_info_data with the separator file name - * jfm:xxxx just return no file could add an option to smb.conf - * separator file = "separator.txt" ********************************************************************/ -static void spoolss_notify_sepfile(int snum, +void spoolss_notify_sepfile(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -1616,7 +1784,7 @@ static void spoolss_notify_sepfile(int snum, * jfm:xxxx return always winprint to indicate we don't do anything to it ********************************************************************/ -static void spoolss_notify_print_processor(int snum, +void spoolss_notify_print_processor(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -1643,7 +1811,7 @@ static void spoolss_notify_print_processor(int snum, * jfm:xxxx send an empty string ********************************************************************/ -static void spoolss_notify_parameters(int snum, +void spoolss_notify_parameters(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -1670,7 +1838,7 @@ static void spoolss_notify_parameters(int snum, * jfm:xxxx always send RAW as data type ********************************************************************/ -static void spoolss_notify_datatype(int snum, +void spoolss_notify_datatype(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -1713,7 +1881,7 @@ static void spoolss_notify_security_desc(int snum, * jfm:xxxx a samba printer is always shared ********************************************************************/ -static void spoolss_notify_attributes(int snum, +void spoolss_notify_attributes(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -1800,7 +1968,7 @@ static void spoolss_notify_status(int snum, * fill a notify_info_data with the number of jobs queued ********************************************************************/ -static void spoolss_notify_cjobs(int snum, +void spoolss_notify_cjobs(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -1839,7 +2007,7 @@ static void spoolss_notify_username(int snum, pstring temp; uint32 len; - len = rpcstr_push(temp, queue->user, sizeof(temp)-2, STR_TERMINATE); + len = rpcstr_push(temp, queue->fs_user, sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); @@ -1879,7 +2047,7 @@ static void spoolss_notify_job_name(int snum, pstring temp; uint32 len; - len = rpcstr_push(temp, queue->file, sizeof(temp)-2, STR_TERMINATE); + len = rpcstr_push(temp, queue->fs_file, sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len / 2 - 1; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); @@ -2169,7 +2337,7 @@ static int search_notify(uint16 type, uint16 field, int *value) /**************************************************************************** ****************************************************************************/ -static void construct_info_data(SPOOL_NOTIFY_INFO_DATA *info_data, uint16 type, uint16 field, int id) +void construct_info_data(SPOOL_NOTIFY_INFO_DATA *info_data, uint16 type, uint16 field, int id) { info_data->type = type; info_data->field = field; @@ -2397,7 +2565,7 @@ static WERROR printer_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY return WERR_BADFID; option=Printer->notify.option; - id=0xffffffff; + id = 0x0; info->version=2; info->data=NULL; info->count=0; @@ -2585,8 +2753,13 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum) printer->global_counter = global_counter; printer->total_pages = 0; +#if 0 /* JERRY */ printer->major_version = 0x0004; /* NT 4 */ printer->build_version = 0x0565; /* build 1381 */ +#else + printer->major_version = 0x0005; /* NT 5 */ + printer->build_version = 0x0893; /* build 2195 */ +#endif printer->unknown7 = 0x1; printer->unknown8 = 0x0; printer->unknown9 = 0x0; @@ -4362,9 +4535,9 @@ static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) /* we force some elements to "correct" values */ slprintf(info->servername, sizeof(info->servername)-1, "\\\\%s", get_called_name()); - slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s", - get_called_name(), lp_servicename(snum)); fstrcpy(info->sharename, lp_servicename(snum)); + slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s", + get_called_name(), info->sharename); info->attributes = PRINTER_ATTRIBUTE_SHARED | PRINTER_ATTRIBUTE_NETWORK; return True; @@ -4686,10 +4859,13 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, int snum; NT_PRINTER_INFO_LEVEL *printer = NULL, *old_printer = NULL; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); + PRINTER_MESSAGE_INFO msg; WERROR result; DEBUG(8,("update_printer\n")); + ZERO_STRUCT(msg); + result = WERR_OK; if (level!=2) { @@ -4802,18 +4978,49 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, * lookup previously saved driver initialization info, which is then * bound to the printer, simulating what happens in the Windows arch. */ - if (!strequal(printer->info_2->drivername, old_printer->info_2->drivername)) + if (!strequal(printer->info_2->drivername, old_printer->info_2->drivername)){ set_driver_init(printer, 2); + msg.flags |= PRINTER_MESSAGE_DRIVER; + } } /* Update printer info */ result = mod_a_printer(*printer, 2); + /* flag which changes actually occured. This is a small subset of + all the possible changes */ + + if (!strequal(printer->info_2->comment, old_printer->info_2->comment)) + msg.flags |= PRINTER_MESSAGE_COMMENT; + + if (!strequal(printer->info_2->sharename, old_printer->info_2->sharename)) + msg.flags |= PRINTER_MESSAGE_SHARENAME; + + if (!strequal(printer->info_2->portname, old_printer->info_2->portname)) + msg.flags |= PRINTER_MESSAGE_PORT; + + if (!strequal(printer->info_2->location, old_printer->info_2->location)) + msg.flags |= PRINTER_MESSAGE_LOCATION; + + ZERO_STRUCT(msg); + + msg.low = PRINTER_CHANGE_ADD_PRINTER; + fstrcpy(msg.printer_name, printer->info_2->printername); + + /* only send a notify if something changed */ + if (msg.flags) + { + /* send to myself before replying to SetPrinter() */ + send_spoolss_event_notification(&msg); + + /* send to other smbd's */ + srv_spoolss_sendnotify(msg.printer_name, 0, PRINTER_CHANGE_ADD_PRINTER, msg.flags); + } + done: free_a_printer(&printer, 2); free_a_printer(&old_printer, 2); - srv_spoolss_sendnotify(0, PRINTER_CHANGE_SET_PRINTER); return result; } @@ -4910,8 +5117,8 @@ static void fill_job_info_1(JOB_INFO_1 *job_info, print_queue_struct *queue, job_info->jobid=queue->job; init_unistr(&job_info->printername, lp_servicename(snum)); init_unistr(&job_info->machinename, temp_name); - init_unistr(&job_info->username, queue->user); - init_unistr(&job_info->document, queue->file); + init_unistr(&job_info->username, queue->fs_user); + init_unistr(&job_info->document, queue->fs_file); init_unistr(&job_info->datatype, "RAW"); init_unistr(&job_info->text_status, ""); job_info->status=nt_printj_status(queue->status); @@ -4945,9 +5152,9 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, init_unistr(&job_info->printername, chaine); init_unistr(&job_info->machinename, temp_name); - init_unistr(&job_info->username, queue->user); - init_unistr(&job_info->document, queue->file); - init_unistr(&job_info->notifyname, queue->user); + init_unistr(&job_info->username, queue->fs_user); + init_unistr(&job_info->document, queue->fs_file); + init_unistr(&job_info->notifyname, queue->fs_user); init_unistr(&job_info->datatype, "RAW"); init_unistr(&job_info->printprocessor, "winprint"); init_unistr(&job_info->parameters, ""); @@ -5070,6 +5277,7 @@ static WERROR enumjobs_level2(print_queue_struct *queue, int snum, } if (!alloc_buffer_size(buffer, *needed)) { + SAFE_FREE(info); result = WERR_INSUFFICIENT_BUFFER; goto done; } @@ -6031,11 +6239,12 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ return WERR_ACCESS_DENIED; } + srv_spoolss_sendnotify(printer->info_2->printername, 0, PRINTER_CHANGE_ADD_PRINTER, 0x0); + free_a_printer(&printer,2); update_c_setprinter(False); - srv_spoolss_sendnotify(0, PRINTER_CHANGE_ADD_PRINTER); return WERR_OK; } @@ -6128,9 +6337,7 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen pstring long_archi; pstring short_archi; DRIVER_DIRECTORY_1 *info=NULL; -#if 0 - fstring asc_name, servername; -#endif + unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)-1); if (get_short_archi(short_archi, long_archi)==False) @@ -6139,20 +6346,6 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen if((info=(DRIVER_DIRECTORY_1 *)malloc(sizeof(DRIVER_DIRECTORY_1))) == NULL) return WERR_NOMEM; -#if 0 /* JERRY */ - /* use the name the client sent us */ - - unistr2_to_ascii(asc_name, name, sizeof(asc_name)-1); - if (asc_name[0] == '\\' && asc_name[1] == '\\') - fstrcpy(servername, asc_name); - else { - fstrcpy(servername, "\\\\"); - fstrcat(servername, asc_name); - } - - slprintf(path, sizeof(path)-1, "%s\\print$\\%s", servername, short_archi); -#endif - slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", get_called_name(), short_archi); DEBUG(4,("printer driver directory: [%s]\n", path)); @@ -6428,24 +6621,6 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP convert_specific_param(¶m, value , type, data, real_len); -#if 0 - /* JRA. W2K always changes changeid. */ - - if (get_specific_param(*printer, 2, param->value, &old_param.data, - &old_param.type, (uint32 *)&old_param.data_len)) { - - if (param->type == old_param.type && - param->data_len == old_param.data_len && - memcmp(param->data, old_param.data, - old_param.data_len) == 0) { - - DEBUG(3, ("setprinterdata hasn't changed\n")); - status = WERR_OK; - goto done; - } - } -#endif - unlink_specific_param_if_exist(printer->info_2, param); /* @@ -6470,17 +6645,18 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP free_nt_printer_param(¶m); SAFE_FREE(old_param.data); -#if 0 - /* Is this correct. JRA ? */ - srv_spoolss_sendnotify(0, PRINTER_CHANGE_SET_PRINTER); -#endif - return status; } /**************************************************************************** ****************************************************************************/ +WERROR _spoolss_resetprinter(pipes_struct *p, SPOOL_Q_RESETPRINTER *q_u, SPOOL_R_RESETPRINTER *r_u) +{ + return WERR_OK; +} + + WERROR _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_u, SPOOL_R_DELETEPRINTERDATA *r_u) { POLICY_HND *handle = &q_u->handle; @@ -7025,7 +7201,6 @@ static WERROR getjob_level_2(print_queue_struct *queue, int count, int snum, uin ret = get_a_printer(&ntprinter, 2, lp_servicename(snum)); if (!W_ERROR_IS_OK(ret)) goto done; - if (construct_dev_mode(snum) == NULL) { ret = WERR_NOMEM; goto done; @@ -7371,27 +7546,6 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ enum_values[num_entries].value_len = (strlen(value)+1) * 2; enum_values[num_entries].type = type; -#if 0 /* JERRY - I think think was a bad assumption based on bad - offset values when I first implemented it. Commented out. - We should not be adding an extra NULL to the end of a string - just send what the client set in the first place. */ - /* - * NULL terminate REG_SZ - * FIXME!!! We should not be correctly problems in the way - * we store PrinterData here. Need to investogate - * SetPrinterData[Ex] --jerry - */ - - if (type == REG_SZ) { - /* fix alignment if the string was stored - in a bizarre fashion */ - if ((data_len % 2) == 0) - add_len = 2; - else - add_len = data_len % 2; - } -#endif - if (!(enum_values[num_entries].data=talloc_zero(p->mem_ctx, data_len+add_len))) { DEBUG(0,("talloc_realloc failed to allocate more memory for data!\n")); result = WERR_NOMEM; @@ -7433,11 +7587,6 @@ done: /**************************************************************************** ****************************************************************************/ -/* Disabled because it doesn't fix the bug I am looking at but it would be - a shame to throw away the code. -tpot */ - -#if 0 - static void fill_printprocessordirectory_1(PRINTPROCESSOR_DIRECTORY_1 *info, char *name) { init_unistr(&info->name, name); @@ -7515,4 +7664,3 @@ WERROR _spoolss_getprintprocessordirectory(pipes_struct *p, SPOOL_Q_GETPRINTPROC return WERR_ACCESS_DENIED; } -#endif -- cgit From ab13654dc9ac23872e4d1384e1c54e336f113009 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 17 Mar 2002 04:36:35 +0000 Subject: Renamed get_nt_error_msg() to nt_errstr(). (This used to be commit 1f007d3ed41c1b71a89fa6be7d173e67e927c302) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a6c0f9368c..a861aa1905 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -698,7 +698,7 @@ static void send_spoolss_event_notification(PRINTER_MESSAGE_INFO *msg) if (!NT_STATUS_IS_OK(result)) { DEBUG(10,("send_spoolss_event_notification: Event notification failed [%s]\n", - get_nt_error_msg(result))); + nt_errstr(result))); } } } -- cgit From a4cce223d6873400b053872a6e3b2eb8621eea45 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 17 Mar 2002 06:04:15 +0000 Subject: Added dos_errstr() function. Not all errors in list yet. (This used to be commit ddb5753e36b8c5efb48ce5c82c16d970fb8e76b6) --- source3/rpc_server/srv_spoolss_nt.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a861aa1905..850d428165 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3858,12 +3858,12 @@ static WERROR construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fst ZERO_STRUCT(driver); status=get_a_printer(&printer, 2, lp_servicename(snum) ); - DEBUG(8,("construct_printer_driver_info_3: status: %s\n", werror_str(status))); + DEBUG(8,("construct_printer_driver_info_3: status: %s\n", dos_errstr(status))); if (!W_ERROR_IS_OK(status)) return WERR_INVALID_PRINTER_NAME; status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version); - DEBUG(8,("construct_printer_driver_info_3: status: %s\n", werror_str(status))); + DEBUG(8,("construct_printer_driver_info_3: status: %s\n", dos_errstr(status))); #if 0 /* JERRY */ @@ -3883,7 +3883,7 @@ static WERROR construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fst /* Yes - try again with a WinNT driver. */ version = 2; status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version); - DEBUG(8,("construct_printer_driver_info_3: status: %s\n", werror_str(status))); + DEBUG(8,("construct_printer_driver_info_3: status: %s\n", dos_errstr(status))); } #endif @@ -3981,12 +3981,12 @@ static WERROR construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, fst ZERO_STRUCT(driver); status=get_a_printer(&printer, 2, lp_servicename(snum) ); - DEBUG(8,("construct_printer_driver_info_6: status: %s\n", werror_str(status))); + DEBUG(8,("construct_printer_driver_info_6: status: %s\n", dos_errstr(status))); if (!W_ERROR_IS_OK(status)) return WERR_INVALID_PRINTER_NAME; status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version); - DEBUG(8,("construct_printer_driver_info_6: status: %s\n", werror_str(status))); + DEBUG(8,("construct_printer_driver_info_6: status: %s\n", dos_errstr(status))); if (!W_ERROR_IS_OK(status)) { /* * Is this a W2k client ? @@ -4000,7 +4000,7 @@ static WERROR construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, fst /* Yes - try again with a WinNT driver. */ version = 2; status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version); - DEBUG(8,("construct_printer_driver_info_6: status: %s\n", werror_str(status))); + DEBUG(8,("construct_printer_driver_info_6: status: %s\n", dos_errstr(status))); if (!W_ERROR_IS_OK(status)) { free_a_printer(&printer,2); return WERR_UNKNOWN_PRINTER_DRIVER; @@ -5957,7 +5957,7 @@ static WERROR enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need if(numlines) { if((ports=(PORT_INFO_1 *)malloc( numlines * sizeof(PORT_INFO_1) )) == NULL) { DEBUG(10,("Returning WERR_NOMEM [%s]\n", - werror_str(WERR_NOMEM))); + dos_errstr(WERR_NOMEM))); file_lines_free(qlines); return WERR_NOMEM; } -- cgit From 72eb7dbd40b4faf3438951c297fb1fbf6f9011ac Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 19 Mar 2002 02:35:12 +0000 Subject: Merge in JohnR's page count fixes. Jeremy. (This used to be commit 2e3133fbe5531b9bbc9bf46a04b27fa58e555f5a) --- source3/rpc_server/srv_spoolss_nt.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 850d428165..e351f125bf 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2138,6 +2138,32 @@ static void spoolss_notify_job_size(int snum, data->notify_data.value[1]=0; } +/******************************************************************* + * fill a notify_info_data with page info + ********************************************************************/ +static void spoolss_notify_total_pages(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) +{ + data->notify_data.value[0]=queue->page_count; + data->notify_data.value[1]=0; +} + +/******************************************************************* + * fill a notify_info_data with pages printed info. + ********************************************************************/ +static void spoolss_notify_pages_printed(int snum, + SPOOL_NOTIFY_INFO_DATA *data, + print_queue_struct *queue, + NT_PRINTER_INFO_LEVEL *printer, + TALLOC_CTX *mem_ctx) +{ + data->notify_data.value[0]=0; /* Add code when back-end tracks this */ + data->notify_data.value[1]=0; +} + /******************************************************************* Fill a notify_info_data with job position. ********************************************************************/ @@ -2258,8 +2284,8 @@ struct s_notify_info_data_table notify_info_data_table[] = { JOB_NOTIFY_TYPE, JOB_NOTIFY_START_TIME, "JOB_NOTIFY_START_TIME", ONE_VALUE, spoolss_notify_start_time }, { JOB_NOTIFY_TYPE, JOB_NOTIFY_UNTIL_TIME, "JOB_NOTIFY_UNTIL_TIME", ONE_VALUE, spoolss_notify_until_time }, { JOB_NOTIFY_TYPE, JOB_NOTIFY_TIME, "JOB_NOTIFY_TIME", ONE_VALUE, spoolss_notify_job_time }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_PAGES, "JOB_NOTIFY_TOTAL_PAGES", ONE_VALUE, NULL }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_PAGES_PRINTED, "JOB_NOTIFY_PAGES_PRINTED", ONE_VALUE, NULL }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_PAGES, "JOB_NOTIFY_TOTAL_PAGES", ONE_VALUE, spoolss_notify_total_pages }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_PAGES_PRINTED, "JOB_NOTIFY_PAGES_PRINTED", ONE_VALUE, spoolss_notify_pages_printed }, { JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_BYTES, "JOB_NOTIFY_TOTAL_BYTES", ONE_VALUE, spoolss_notify_job_size }, { JOB_NOTIFY_TYPE, JOB_NOTIFY_BYTES_PRINTED, "JOB_NOTIFY_BYTES_PRINTED", ONE_VALUE, NULL }, { END, END, "", END, NULL } @@ -4256,6 +4282,7 @@ WERROR _spoolss_endpageprinter(pipes_struct *p, SPOOL_Q_ENDPAGEPRINTER *q_u, SPO } Printer->page_started=False; + print_job_endpage(Printer->jobid); return WERR_OK; } @@ -5124,7 +5151,7 @@ static void fill_job_info_1(JOB_INFO_1 *job_info, print_queue_struct *queue, job_info->status=nt_printj_status(queue->status); job_info->priority=queue->priority; job_info->position=position; - job_info->totalpages=0; + job_info->totalpages=queue->page_count; job_info->pagesprinted=0; make_systemtime(&job_info->submitted, t); @@ -5168,7 +5195,7 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, job_info->position=position; job_info->starttime=0; job_info->untiltime=0; - job_info->totalpages=0; + job_info->totalpages=queue->page_count; job_info->size=queue->size; make_systemtime(&(job_info->submitted), t); job_info->timeelapsed=0; -- cgit From 0cd5dd67ce12f02d3d20568e901ef7666caa8472 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 20 Mar 2002 00:24:35 +0000 Subject: Merge from app-head: > Don't put two copies of the server name in construct_printer_info_1() (This used to be commit 47b1003bc5a069e84cb20df507022e5ff3e93832) --- source3/rpc_server/srv_spoolss_nt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index e351f125bf..c4a2334c16 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2832,12 +2832,12 @@ static BOOL construct_printer_info_1(uint32 flags, PRINTER_INFO_1 *printer, int if (*ntprinter->info_2->comment == '\0') { init_unistr(&printer->comment, lp_comment(snum)); - slprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",get_called_name(), ntprinter->info_2->printername, + slprintf(chaine,sizeof(chaine)-1,"%s,%s,%s", ntprinter->info_2->printername, ntprinter->info_2->drivername, lp_comment(snum)); } else { init_unistr(&printer->comment, ntprinter->info_2->comment); /* saved comment. */ - slprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",get_called_name(), ntprinter->info_2->printername, + slprintf(chaine,sizeof(chaine)-1,"%s,%s,%s", ntprinter->info_2->printername, ntprinter->info_2->drivername, ntprinter->info_2->comment); } -- cgit From 826f3fb86b954b29b4f152d8785860a227798975 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 20 Mar 2002 03:37:27 +0000 Subject: resetprinter merge from SAMBA_2_2 (This used to be commit 88d8897e21749f177952b264031aa386bbbeaaeb) --- source3/rpc_server/srv_spoolss_nt.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index c4a2334c16..b23cbaa9ae 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6680,6 +6680,28 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP WERROR _spoolss_resetprinter(pipes_struct *p, SPOOL_Q_RESETPRINTER *q_u, SPOOL_R_RESETPRINTER *r_u) { + POLICY_HND *handle = &q_u->handle; + Printer_entry *Printer=find_printer_index_by_hnd(p, handle); + int snum; + + DEBUG(5,("_spoolss_resetprinter\n")); + + /* + * All we do is to check to see if the handle and queue is valid. + * This call really doesn't mean anything to us because we only + * support RAW printing. --jerry + */ + + if (!Printer) { + DEBUG(2,("_spoolss_resetprinter: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); + return WERR_BADFID; + } + + if (!get_printer_snum(p,handle, &snum)) + return WERR_BADFID; + + + /* blindly return success */ return WERR_OK; } -- cgit From 9529a4827c203eb4e42a166e6d2c1281e73b4254 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 20 Mar 2002 23:09:34 +0000 Subject: merge from APPLIANCE_HEAD (This used to be commit 9282aa02d44ae7a7688e8399b397aae35f73ddd1) --- source3/rpc_server/srv_spoolss_nt.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index b23cbaa9ae..8e3ada5a8d 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -714,7 +714,6 @@ static void send_spoolss_event_notification(PRINTER_MESSAGE_INFO *msg) static void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size_t len) { PRINTER_MESSAGE_INFO msg; - pid_t my_pid = sys_getpid(); if (len < sizeof(msg)) { DEBUG(2,("srv_spoolss_receive_message: got incorrect message size (%u)!\n", (unsigned int)len)); @@ -723,11 +722,6 @@ static void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size memcpy(&msg, buf, sizeof(PRINTER_MESSAGE_INFO)); - if (my_pid == src) { - DEBUG(10,("srv_spoolss_receive_message: Skipping message to myself\n")); - return; - } - DEBUG(10,("srv_spoolss_receive_message: Got message printer change [queue = %s] low=0x%x high=0x%x flags=0x%x\n", msg.printer_name, (unsigned int)msg.low, (unsigned int)msg.high, msg.flags )); @@ -5035,12 +5029,7 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, fstrcpy(msg.printer_name, printer->info_2->printername); /* only send a notify if something changed */ - if (msg.flags) - { - /* send to myself before replying to SetPrinter() */ - send_spoolss_event_notification(&msg); - - /* send to other smbd's */ + if (msg.flags) { srv_spoolss_sendnotify(msg.printer_name, 0, PRINTER_CHANGE_ADD_PRINTER, msg.flags); } -- cgit From ce236d1dbf2673e2ff921683554cee41fca33249 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 22 Mar 2002 06:24:38 +0000 Subject: Stomped on some header file version numbers that have crept back in. (This used to be commit e66bdf1229ba84f64c19e817e2c4081dbbf0bee8) --- source3/rpc_server/srv_spoolss_nt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 8e3ada5a8d..717e51462b 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1,6 +1,5 @@ /* - * Unix SMB/Netbios implementation. - * Version 1.9. + * Unix SMB/CIFS implementation. * RPC Pipe client / server routines * Copyright (C) Andrew Tridgell 1992-2000, * Copyright (C) Luke Kenneth Casson Leighton 1996-2000, -- cgit From 737423f06ea08c38592b408faa12a55a95b9d696 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 26 Mar 2002 03:15:30 +0000 Subject: OpenPrinter() merge from 2.2 (This used to be commit 619397cc90549d4602ecddc25ee50eb247c913ee) --- source3/rpc_server/srv_spoolss_nt.c | 132 ++++++++++++++++++++++++++++++++++-- 1 file changed, 125 insertions(+), 7 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 717e51462b..e119825f31 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -757,18 +757,137 @@ static BOOL srv_spoolss_sendnotify(char* printer_name, uint32 high, uint32 low, return True; } +/******************************************************************** + Copy routines used by convert_to_openprinterex() + *******************************************************************/ + +static DEVICEMODE* dup_devicemode(TALLOC_CTX *ctx, DEVICEMODE *devmode) +{ + DEVICEMODE *d; + int len; + + if (!devmode) + return NULL; + + DEBUG (8,("dup_devmode\n")); + + /* bulk copy first */ + + d = talloc_memdup(ctx, devmode, sizeof(DEVICEMODE)); + if (!d) + return NULL; + + /* dup the pointer members separately */ + + len = unistrlen(devmode->devicename.buffer); + if (len != -1) { + d->devicename.buffer = talloc(ctx, len*2); + if (unistrcpy(d->devicename.buffer, devmode->devicename.buffer) != len) + return NULL; + } + + + len = unistrlen(devmode->formname.buffer); + if (len != -1) { + d->devicename.buffer = talloc(ctx, len*2); + if (unistrcpy(d->formname.buffer, devmode->formname.buffer) != len) + return NULL; + } + + d->private = talloc_memdup(ctx, devmode->private, devmode->driverextra); + + return d; +} + +static void copy_devmode_ctr(TALLOC_CTX *ctx, DEVMODE_CTR *new_ctr, DEVMODE_CTR *ctr) +{ + if (!new_ctr || !ctr) + return; + + DEBUG(8,("copy_devmode_ctr\n")); + + new_ctr->size = ctr->size; + new_ctr->devmode_ptr = ctr->devmode_ptr; + + if(ctr->devmode_ptr) + new_ctr->devmode = dup_devicemode(ctx, ctr->devmode); +} + +static void copy_printer_default(TALLOC_CTX *ctx, PRINTER_DEFAULT *new_def, PRINTER_DEFAULT *def) +{ + if (!new_def || !def) + return; + + DEBUG(8,("copy_printer_defaults\n")); + + new_def->datatype_ptr = def->datatype_ptr; + + if (def->datatype_ptr) + copy_unistr2(&new_def->datatype, &def->datatype); + + copy_devmode_ctr(ctx, &new_def->devmode_cont, &def->devmode_cont); + + new_def->access_required = def->access_required; +} + +/******************************************************************** + * Convert a SPOOL_Q_OPEN_PRINTER structure to a + * SPOOL_Q_OPEN_PRINTER_EX structure + ********************************************************************/ + +static void convert_to_openprinterex(TALLOC_CTX *ctx, SPOOL_Q_OPEN_PRINTER_EX *q_u_ex, SPOOL_Q_OPEN_PRINTER *q_u) +{ + if (!q_u_ex || !q_u) + return; + + DEBUG(8,("convert_to_openprinterex\n")); + + q_u_ex->printername_ptr = q_u->printername_ptr; + + if (q_u->printername_ptr) + copy_unistr2(&q_u_ex->printername, &q_u->printername); + + copy_printer_default(ctx, &q_u_ex->printer_default, &q_u->printer_default); +} + /******************************************************************** * spoolss_open_printer * * called from the spoolss dispatcher ********************************************************************/ -WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, SPOOL_R_OPEN_PRINTER_EX *r_u) +WERROR _spoolss_open_printer(pipes_struct *p, SPOOL_Q_OPEN_PRINTER *q_u, SPOOL_R_OPEN_PRINTER *r_u) { -#if 0 - WERROR result = WERR_OK; -#endif + SPOOL_Q_OPEN_PRINTER_EX q_u_ex; + SPOOL_R_OPEN_PRINTER_EX r_u_ex; + + if (!q_u || !r_u) + return WERR_NOMEM; + + ZERO_STRUCT(q_u_ex); + ZERO_STRUCT(r_u_ex); + + /* convert the OpenPrinter() call to OpenPrinterEx() */ + + convert_to_openprinterex(p->mem_ctx, &q_u_ex, q_u); + + r_u_ex.status = _spoolss_open_printer_ex(p, &q_u_ex, &r_u_ex); + + /* convert back to OpenPrinter() */ + + memcpy(r_u, &r_u_ex, sizeof(*r_u)); + + return r_u->status; +} + +/******************************************************************** + * spoolss_open_printer + * + * called from the spoolss dispatcher + ********************************************************************/ +WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, SPOOL_R_OPEN_PRINTER_EX *r_u) +{ UNISTR2 *printername = NULL; PRINTER_DEFAULT *printer_default = &q_u->printer_default; /* uint32 user_switch = q_u->user_switch; - notused */ @@ -6254,13 +6373,12 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ return WERR_ACCESS_DENIED; } + update_c_setprinter(False); + srv_spoolss_sendnotify(printer->info_2->printername, 0, PRINTER_CHANGE_ADD_PRINTER, 0x0); free_a_printer(&printer,2); - update_c_setprinter(False); - - return WERR_OK; } -- cgit From 16c3f6c7d0c925676bbc259fde79fff3a286c77d Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 28 Mar 2002 16:44:26 +0000 Subject: merge from SAMBA_2_2 (This used to be commit 606450f3cbe028a526ec6db9cea59d65324c3314) --- source3/rpc_server/srv_spoolss_nt.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index e119825f31..60c8fdfb7b 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1561,7 +1561,12 @@ WERROR _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO *data = NULL; } - return WERR_INVALID_PARAM; + /* error depends on handle type */ + + if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) + return WERR_INVALID_PARAM; + else + return WERR_BADFILE; } if (*needed > *out_size) -- cgit From ca43b0da79557818b0486d5047667a981fd3e3e6 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 5 Apr 2002 22:41:39 +0000 Subject: Fix Gerry bug - MajorVersion should be 2 not 3. Jeremy. (This used to be commit b8b88e863e3964231a85b4643a197d6d4d6b8f99) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 60c8fdfb7b..d1b92cf646 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1407,7 +1407,7 @@ static BOOL getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint32 *type = 0x4; if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) return False; - SIVAL(*data, 0, 0x03); + SIVAL(*data, 0, 2); *needed = 0x4; return True; } -- cgit From bcb842be57a0fe69f6c7374bae741c9e26ba1b45 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 9 Apr 2002 05:59:46 +0000 Subject: Fixed some compiler warnings. (This used to be commit be6f955107429f1431c49c8b45fd623406a9d641) --- source3/rpc_server/srv_spoolss_nt.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index d1b92cf646..2e96622118 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -568,7 +568,7 @@ static BOOL is_client_monitoring_event(Printer_entry *p, uint32 flags) --jerry **************************************************************************/ -static NTSTATUS srv_spoolss_routerreplyprinter (struct cli_state *cli, TALLOC_CTX *mem_ctx, +static NTSTATUS srv_spoolss_routerreplyprinter (struct cli_state *reply_cli, TALLOC_CTX *mem_ctx, POLICY_HND *pol, PRINTER_MESSAGE_INFO *info, NT_PRINTER_INFO_LEVEL *printer) { @@ -578,7 +578,7 @@ static NTSTATUS srv_spoolss_routerreplyprinter (struct cli_state *cli, TALLOC_CT if (info->flags & PRINTER_MESSAGE_DRIVER) condition = PRINTER_CHANGE_SET_PRINTER_DRIVER; - result = cli_spoolss_routerreplyprinter(cli, mem_ctx, pol, condition, + result = cli_spoolss_routerreplyprinter(reply_cli, mem_ctx, pol, condition, printer->info_2->changeid); return result; @@ -590,7 +590,7 @@ static NTSTATUS srv_spoolss_routerreplyprinter (struct cli_state *cli, TALLOC_CT **********************************************************************/ static NTSTATUS srv_spoolss_send_event_to_client(Printer_entry* Printer, - struct cli_state *cli, PRINTER_MESSAGE_INFO *msg, + struct cli_state *send_cli, PRINTER_MESSAGE_INFO *msg, NT_PRINTER_INFO_LEVEL *info) { NTSTATUS result; @@ -599,12 +599,12 @@ static NTSTATUS srv_spoolss_send_event_to_client(Printer_entry* Printer, /* This is a single call that can send information about multiple changes */ if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) msg->flags |= PRINTER_MESSAGE_ATTRIBUTES; - result = cli_spoolss_reply_rrpcn(cli, cli->mem_ctx, &Printer->notify.client_hnd, + result = cli_spoolss_reply_rrpcn(send_cli, send_cli->mem_ctx, &Printer->notify.client_hnd, msg, info); } else { /* This requires that the server send an individual event notification for each change */ - result = srv_spoolss_routerreplyprinter(cli, cli->mem_ctx, &Printer->notify.client_hnd, + result = srv_spoolss_routerreplyprinter(send_cli, send_cli->mem_ctx, &Printer->notify.client_hnd, msg, info); } -- cgit From d0d61ba689694a11165076b58c7ac0731333c0df Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 9 Apr 2002 06:19:42 +0000 Subject: Fixed typo in debug statement. (This used to be commit 49e429a97ff2b6b1889937c998f67d73d35829e1) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 2e96622118..3022b99afa 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -917,7 +917,7 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, Printer=find_printer_index_by_hnd(p, handle); if (!Printer) { DEBUG(0,(" _spoolss_open_printer_ex: logic error. \ -Can't find printer handle we created for priunter %s\n", name )); +Can't find printer handle we created for printer %s\n", name )); close_printer_handle(p,handle); return WERR_INVALID_PRINTER_NAME; } -- cgit From 83ece079956907e07c1018e5231dda1d0202f1a5 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 11 Apr 2002 01:50:18 +0000 Subject: WERROR merge from SAMBA_2_2 (This used to be commit 32dc5dbbfb16cb9fd6f953dbb8148f5228b453a4) --- source3/rpc_server/srv_spoolss_nt.c | 38 +++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 3022b99afa..dff1186e1e 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -161,7 +161,7 @@ static void free_spool_notify_option(SPOOL_NOTIFY_OPTION **pp) static void srv_spoolss_replycloseprinter(POLICY_HND *handle) { - NTSTATUS result; + WERROR result; /* weird if the test succeds !!! */ if (smb_connections==0) { @@ -171,8 +171,9 @@ static void srv_spoolss_replycloseprinter(POLICY_HND *handle) result = cli_spoolss_reply_close_printer(&cli, cli.mem_ctx, handle); - if (!NT_STATUS_IS_OK(result)) - DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed.\n")); + if (!W_ERROR_IS_OK(result)) + DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed [%s].\n", + werror_str(result))); /* if it's the last connection, deconnect the IPC$ share */ if (smb_connections==1) { @@ -568,11 +569,11 @@ static BOOL is_client_monitoring_event(Printer_entry *p, uint32 flags) --jerry **************************************************************************/ -static NTSTATUS srv_spoolss_routerreplyprinter (struct cli_state *reply_cli, TALLOC_CTX *mem_ctx, +static WERROR srv_spoolss_routerreplyprinter (struct cli_state *reply_cli, TALLOC_CTX *mem_ctx, POLICY_HND *pol, PRINTER_MESSAGE_INFO *info, NT_PRINTER_INFO_LEVEL *printer) { - NTSTATUS result; + WERROR result; uint32 condition = 0x0; if (info->flags & PRINTER_MESSAGE_DRIVER) @@ -589,16 +590,17 @@ static NTSTATUS srv_spoolss_routerreplyprinter (struct cli_state *reply_cli, TAL notification **********************************************************************/ -static NTSTATUS srv_spoolss_send_event_to_client(Printer_entry* Printer, +static WERROR srv_spoolss_send_event_to_client(Printer_entry* Printer, struct cli_state *send_cli, PRINTER_MESSAGE_INFO *msg, NT_PRINTER_INFO_LEVEL *info) { - NTSTATUS result; + WERROR result; if (valid_notify_options(Printer)) { /* This is a single call that can send information about multiple changes */ if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) msg->flags |= PRINTER_MESSAGE_ATTRIBUTES; + result = cli_spoolss_reply_rrpcn(send_cli, send_cli->mem_ctx, &Printer->notify.client_hnd, msg, info); } @@ -620,8 +622,7 @@ static NTSTATUS srv_spoolss_send_event_to_client(Printer_entry* Printer, static void send_spoolss_event_notification(PRINTER_MESSAGE_INFO *msg) { Printer_entry *find_printer; - NTSTATUS result; - WERROR wresult; + WERROR result; NT_PRINTER_INFO_LEVEL *printer = NULL; if (!msg) { @@ -686,8 +687,8 @@ static void send_spoolss_event_notification(PRINTER_MESSAGE_INFO *msg) printer = NULL; } - wresult = get_a_printer(&printer, 2, msg->printer_name); - if (! W_ERROR_IS_OK(wresult)) + result = get_a_printer(&printer, 2, msg->printer_name); + if (!W_ERROR_IS_OK(result)) continue; } @@ -695,9 +696,9 @@ static void send_spoolss_event_notification(PRINTER_MESSAGE_INFO *msg) result = srv_spoolss_send_event_to_client(find_printer, &cli, msg, printer); - if (!NT_STATUS_IS_OK(result)) { - DEBUG(10,("send_spoolss_event_notification: Event notification failed [%s]\n", - nt_errstr(result))); + if (!W_ERROR_IS_OK(result)) { + DEBUG(5,("send_spoolss_event_notification: Event notification failed [%s]\n", + werror_str(result))); } } } @@ -1581,7 +1582,7 @@ WERROR _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO static BOOL srv_spoolss_replyopenprinter(char *printer, uint32 localprinter, uint32 type, POLICY_HND *handle) { - NTSTATUS result; + WERROR result; /* * If it's the first connection, contact the client @@ -1594,6 +1595,7 @@ static BOOL srv_spoolss_replyopenprinter(char *printer, uint32 localprinter, uin if(!spoolss_connect_to_client(&cli, unix_printer)) return False; + message_register(MSG_PRINTER_NOTIFY, srv_spoolss_receive_message); } @@ -1603,7 +1605,11 @@ static BOOL srv_spoolss_replyopenprinter(char *printer, uint32 localprinter, uin result = cli_spoolss_reply_open_printer(&cli, cli.mem_ctx, printer, localprinter, type, handle); - return (NT_STATUS_IS_OK(result)); + if (!W_ERROR_IS_OK(result)) + DEBUG(5,("srv_spoolss_reply_open_printer: Client RPC returned [%s]\n", + werror_str(result))); + + return (W_ERROR_IS_OK(result)); } /******************************************************************** -- cgit From d3fa6d5de64f022eafd99b83d4853c86f8b2f46c Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 11 Apr 2002 02:13:56 +0000 Subject: s/werror_str/dos_errstr/g to fix compile (This used to be commit d7c9b00253499da047f30f71660dede3676d40ad) --- source3/rpc_server/srv_spoolss_nt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index dff1186e1e..23754602fb 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -173,7 +173,7 @@ static void srv_spoolss_replycloseprinter(POLICY_HND *handle) if (!W_ERROR_IS_OK(result)) DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed [%s].\n", - werror_str(result))); + dos_errstr(result))); /* if it's the last connection, deconnect the IPC$ share */ if (smb_connections==1) { @@ -698,7 +698,7 @@ static void send_spoolss_event_notification(PRINTER_MESSAGE_INFO *msg) if (!W_ERROR_IS_OK(result)) { DEBUG(5,("send_spoolss_event_notification: Event notification failed [%s]\n", - werror_str(result))); + dos_errstr(result))); } } } @@ -1607,7 +1607,7 @@ static BOOL srv_spoolss_replyopenprinter(char *printer, uint32 localprinter, uin if (!W_ERROR_IS_OK(result)) DEBUG(5,("srv_spoolss_reply_open_printer: Client RPC returned [%s]\n", - werror_str(result))); + dos_errstr(result))); return (W_ERROR_IS_OK(result)); } -- cgit From 8e2f3ec1d175ae530842b502c4f0431b50dd364e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 11 Apr 2002 02:59:31 +0000 Subject: Correctly emulate NT in printer handle opening access rights. Jeremy. (This used to be commit 42ae2334f21402c347aee560f08fd8e730481169) --- source3/rpc_server/srv_spoolss_nt.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 23754602fb..3bc91c2472 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -993,7 +993,6 @@ Can't find printer handle we created for printer %s\n", name )); /* map an empty access mask to the minimum access mask */ if (printer_default->access_required == 0x0) printer_default->access_required = PRINTER_ACCESS_USE; - /* * If we are not serving the printer driver for this printer, @@ -1013,6 +1012,12 @@ Can't find printer handle we created for printer %s\n", name )); return WERR_ACCESS_DENIED; } + if ((printer_default->access_required & SPECIFIC_RIGHTS_MASK)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) { + DEBUG(3, ("access DENIED for printer open - unknown bits\n")); + close_printer_handle(p, handle); + return WERR_ACCESS_DENIED; + } + if (printer_default->access_required & PRINTER_ACCESS_ADMINISTER) printer_default->access_required = PRINTER_ACCESS_ADMINISTER; else -- cgit From fea03cef2be825037b0c610964ca6e296ed6e33d Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 15 Apr 2002 03:49:53 +0000 Subject: Merge of print server permission handling fixes from HEAD. (This used to be commit 62ee1f8c3fbcf83641bed881143a1a8c70f836ba) --- source3/rpc_server/srv_spoolss_nt.c | 53 ++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 12 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 3bc91c2472..80bfd74b47 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -92,7 +92,8 @@ static uint32 smb_connections=0; /* in printing/nt_printing.c */ -extern STANDARD_MAPPING printer_std_mapping; + +extern STANDARD_MAPPING printer_std_mapping, printserver_std_mapping; #define OUR_HANDLE(hnd) (((hnd)==NULL)?"NULL":(IVAL((hnd)->data5,4)==(uint32)sys_getpid()?"OURS":"OTHER")), \ ((unsigned int)IVAL((hnd)->data5,4)),((unsigned int)sys_getpid()) @@ -959,26 +960,54 @@ Can't find printer handle we created for printer %s\n", name )); get_current_user(&user, p); if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) { - if (printer_default->access_required == 0) { - return WERR_OK; + + /* Printserver handles use global struct... */ + + snum = -1; + + /* Map standard access rights to object specific access + rights */ + + se_map_standard(&printer_default->access_required, + &printserver_std_mapping); + + /* Deny any object specific bits that don't apply to print + servers (i.e printer and job specific bits) */ + + printer_default->access_required &= SPECIFIC_RIGHTS_MASK; + + if (printer_default->access_required & + ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) { + DEBUG(3, ("access DENIED for non-printserver bits")); + close_printer_handle(p, handle); + return WERR_ACCESS_DENIED; } - else if ((printer_default->access_required & SERVER_ACCESS_ADMINISTER ) == SERVER_ACCESS_ADMINISTER) { - /* Printserver handles use global struct... */ - snum = -1; + /* Allow admin access */ + + if (printer_default->access_required & + SERVER_ACCESS_ADMINISTER) { if (!lp_ms_add_printer_wizard()) { close_printer_handle(p, handle); return WERR_ACCESS_DENIED; } - else if (user.uid == 0 || user_in_list(uidtoname(user.uid), lp_printer_admin(snum))) { + + if (user.uid == 0 || + user_in_list(uidtoname(user.uid), + lp_printer_admin(snum))) return WERR_OK; - } - else { - close_printer_handle(p, handle); - return WERR_ACCESS_DENIED; - } + + DEBUG(0, ("** denied 0x%08x to user %s\n", + printer_default->access_required, + uidtoname(user.uid))); + + close_printer_handle(p, handle); + return WERR_ACCESS_DENIED; } + + /* We fall through to return WERR_OK */ + } else { -- cgit From 59a04032c86a9304156946c6f71bb4b1375ab81b Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 15 Apr 2002 04:00:27 +0000 Subject: Whoops, removed debug 0 that snuck in. (This used to be commit dd1fb1b90b143c41238eb1f342d86d8fd406a4ef) --- source3/rpc_server/srv_spoolss_nt.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 80bfd74b47..6572e23fbb 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -998,10 +998,6 @@ Can't find printer handle we created for printer %s\n", name )); lp_printer_admin(snum))) return WERR_OK; - DEBUG(0, ("** denied 0x%08x to user %s\n", - printer_default->access_required, - uidtoname(user.uid))); - close_printer_handle(p, handle); return WERR_ACCESS_DENIED; } -- cgit From 2699f9b9df3f974a34e40761141361e997638b6c Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 22 Apr 2002 18:48:45 +0000 Subject: printing merge from HEAD (This used to be commit d3aed37dd87d425f51bcdc4e5151f0b0fe8f9c6b) --- source3/rpc_server/srv_spoolss_nt.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 6572e23fbb..322efa22b5 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -5084,7 +5084,7 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, goto done; } - if (info->info_2->devmode_ptr != 0) { + if (devmode) { /* we have a valid devmode convert it and link it*/ @@ -7807,13 +7807,7 @@ static WERROR getprintprocessordirectory_level_1(UNISTR2 *name, if((info=(PRINTPROCESSOR_DIRECTORY_1 *)malloc(sizeof(PRINTPROCESSOR_DIRECTORY_1))) == NULL) return WERR_NOMEM; - /* Not sure what to return here - are UNC names valid here?. - Windows returns the string: C:\WINNT\System32\spool\PRTPROCS\W32X86 - which is pretty bogus for a RPC. */ - - slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", get_called_name(), short_archi); - - DEBUG(4,("print processor directory: [%s]\n", path)); + pstrcpy(path, "C:\\WINNT\\System32\\spool\\PRTPROCS\\W32X86"); fill_printprocessordirectory_1(info, path); -- cgit From e90b65284812aaa5ff9e9935ce9bbad7791cbbcd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 15 Jul 2002 10:35:28 +0000 Subject: updated the 3.0 branch from the head branch - ready for alpha18 (This used to be commit 03ac082dcb375b6f3ca3d810a6a6367542bc23ce) --- source3/rpc_server/srv_spoolss_nt.c | 1384 ++++++++++++++++++++++++----------- 1 file changed, 943 insertions(+), 441 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 322efa22b5..68c792f8b0 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -5,7 +5,7 @@ * Copyright (C) Luke Kenneth Casson Leighton 1996-2000, * Copyright (C) Jean François Micouleau 1998-2000, * Copyright (C) Jeremy Allison 2001, - * Copyright (C) Gerald Carter 2000-2001, + * Copyright (C) Gerald Carter 2000-2002, * Copyright (C) Tim Potter 2001-2002. * * This program is free software; you can redistribute it and/or modify @@ -28,6 +28,10 @@ #include "includes.h" +#undef DBGC_CLASS +#define DBGC_CLASS DBGC_RPC_SRV +/* #define EMULATE_WIN2K_HACK 1 */ + #ifndef MAX_OPEN_PRINTER_EXS #define MAX_OPEN_PRINTER_EXS 50 #endif @@ -37,6 +41,15 @@ #define PRINTER_HANDLE_IS_PRINTER 0 #define PRINTER_HANDLE_IS_PRINTSERVER 1 +/* Table to map the driver version */ +/* to OS */ +char * drv_ver_to_os[] = { + "WIN9X", /* driver version/cversion 0 */ + "", /* unused ? */ + "WINNT", /* driver version/cversion 2 */ + "WIN2K", /* driver version/cversion 3 */ +}; + struct table_node { char *long_archi; char *short_archi; @@ -68,6 +81,7 @@ typedef struct _Printer{ SPOOL_NOTIFY_OPTION *option; POLICY_HND client_hnd; uint32 client_connected; + uint32 change; } notify; struct { fstring machine; @@ -178,10 +192,10 @@ static void srv_spoolss_replycloseprinter(POLICY_HND *handle) /* if it's the last connection, deconnect the IPC$ share */ if (smb_connections==1) { - if(!spoolss_disconnect_from_client(&cli)) - return; - - message_deregister(MSG_PRINTER_NOTIFY); + cli_nt_session_close(&cli); + cli_ulogoff(&cli); + cli_shutdown(&cli); + message_deregister(MSG_PRINTER_NOTIFY2); } smb_connections--; @@ -426,7 +440,7 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) * anymore, so I've simplified this loop greatly. Here * we are just verifying that the printer name is a valid * printer service defined in smb.conf - * --jerry [Fri Feb 15 11:17:46 CST 2002] + * --jerry [Fri Feb 15 11:17:46 CST 2002] */ for (snum=0; snumnotify.option == NULL) - return False; - return True; } -/*************************************************************************** - Simple check to see if the client motify handle is set to watch for events - represented by 'flags' - - FIXME!!!! only a stub right now --jerry - **************************************************************************/ - -static BOOL is_client_monitoring_event(Printer_entry *p, uint32 flags) +static BOOL is_monitoring_event(Printer_entry *p, uint16 notify_type, + uint16 notify_field) { + SPOOL_NOTIFY_OPTION *option = p->notify.option; + uint32 i, j; + + if (p->notify.flags) + return is_monitoring_event_flags( + p->notify.flags, notify_type, notify_field); - return True; -} + for (i = 0; i < option->count; i++) { + + /* Check match for notify_type */ + + if (option->ctr.type[i].type != notify_type) + continue; -/*************************************************************************** - Server wrapper for cli_spoolss_routerreplyprinter() since the client - function can only send a single change notification at a time. - - FIXME!!! only handles one change currently (PRINTER_CHANGE_SET_PRINTER_DRIVER) - --jerry - **************************************************************************/ - -static WERROR srv_spoolss_routerreplyprinter (struct cli_state *reply_cli, TALLOC_CTX *mem_ctx, - POLICY_HND *pol, PRINTER_MESSAGE_INFO *info, - NT_PRINTER_INFO_LEVEL *printer) -{ - WERROR result; - uint32 condition = 0x0; + /* Check match for field */ + + for (j = 0; j < option->ctr.type[i].count; j++) { + if (option->ctr.type[i].fields[j] == notify_field) { + return True; + } + } + } - if (info->flags & PRINTER_MESSAGE_DRIVER) - condition = PRINTER_CHANGE_SET_PRINTER_DRIVER; + DEBUG(10, ("%s is not monitoring 0x%02x/0x%02x\n", + (p->printer_type == PRINTER_HANDLE_IS_PRINTER) ? + p->dev.handlename : p->dev.printerservername, + notify_type, notify_field)); - result = cli_spoolss_routerreplyprinter(reply_cli, mem_ctx, pol, condition, - printer->info_2->changeid); + return False; +} - return result; +/* Convert a notification message to a SPOOL_NOTIFY_INFO_DATA struct */ + +static void notify_one_value(struct spoolss_notify_msg *msg, + SPOOL_NOTIFY_INFO_DATA *data, + TALLOC_CTX *mem_ctx) +{ + data->notify_data.value[0] = msg->notify.value[0]; + data->notify_data.value[1] = 0; } -/*********************************************************************** - Wrapper around the decision of which RPC use to in the change - notification - **********************************************************************/ - -static WERROR srv_spoolss_send_event_to_client(Printer_entry* Printer, - struct cli_state *send_cli, PRINTER_MESSAGE_INFO *msg, - NT_PRINTER_INFO_LEVEL *info) +static void notify_string(struct spoolss_notify_msg *msg, + SPOOL_NOTIFY_INFO_DATA *data, + TALLOC_CTX *mem_ctx) { - WERROR result; + UNISTR2 unistr; - if (valid_notify_options(Printer)) { - /* This is a single call that can send information about multiple changes */ - if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) - msg->flags |= PRINTER_MESSAGE_ATTRIBUTES; + /* The length of the message includes the trailing \0 */ - result = cli_spoolss_reply_rrpcn(send_cli, send_cli->mem_ctx, &Printer->notify.client_hnd, - msg, info); - } - else { - /* This requires that the server send an individual event notification for each change */ - result = srv_spoolss_routerreplyprinter(send_cli, send_cli->mem_ctx, &Printer->notify.client_hnd, - msg, info); + init_unistr2(&unistr, msg->notify.data, msg->len); + + data->notify_data.data.length = msg->len * 2; + data->notify_data.data.string = (uint16 *)talloc(mem_ctx, msg->len * 2); + + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; } - return result; + memcpy(data->notify_data.data.string, unistr.buffer, msg->len * 2); } +static void notify_system_time(struct spoolss_notify_msg *msg, + SPOOL_NOTIFY_INFO_DATA *data, + TALLOC_CTX *mem_ctx) +{ + SYSTEMTIME systime; + prs_struct ps; + + if (msg->len != sizeof(time_t)) { + DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n", + msg->len)); + return; + } + + if (!prs_init(&ps, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) { + DEBUG(5, ("notify_system_time: prs_init() failed\n")); + return; + } + + if (!make_systemtime(&systime, localtime((time_t *)msg->notify.data))) { + DEBUG(5, ("notify_system_time: unable to make systemtime\n")); + return; + } + + if (!spoolss_io_system_time("", &ps, 0, &systime)) + return; + + data->notify_data.data.length = prs_offset(&ps); + data->notify_data.data.string = + talloc(mem_ctx, prs_offset(&ps)); + + memcpy(data->notify_data.data.string, prs_data_p(&ps), prs_offset(&ps)); + + prs_mem_free(&ps); +} + +struct notify2_message_table { + char *name; + void (*fn)(struct spoolss_notify_msg *msg, + SPOOL_NOTIFY_INFO_DATA *data, TALLOC_CTX *mem_ctx); +}; + +static struct notify2_message_table printer_notify_table[] = { + /* 0x00 */ { "PRINTER_NOTIFY_SERVER_NAME", NULL }, + /* 0x01 */ { "PRINTER_NOTIFY_PRINTER_NAME", NULL }, + /* 0x02 */ { "PRINTER_NOTIFY_SHARE_NAME", NULL }, + /* 0x03 */ { "PRINTER_NOTIFY_PORT_NAME", NULL }, + /* 0x04 */ { "PRINTER_NOTIFY_DRIVER_NAME", NULL }, + /* 0x05 */ { "PRINTER_NOTIFY_COMMENT", NULL }, + /* 0x06 */ { "PRINTER_NOTIFY_LOCATION", NULL }, + /* 0x07 */ { "PRINTER_NOTIFY_DEVMODE", NULL }, + /* 0x08 */ { "PRINTER_NOTIFY_SEPFILE", NULL }, + /* 0x09 */ { "PRINTER_NOTIFY_PRINT_PROCESSOR", NULL }, + /* 0x0a */ { "PRINTER_NOTIFY_PARAMETERS", NULL }, + /* 0x0b */ { "PRINTER_NOTIFY_DATATYPE", NULL }, + /* 0x0c */ { "PRINTER_NOTIFY_SECURITY_DESCRIPTOR", NULL }, + /* 0x0d */ { "PRINTER_NOTIFY_ATTRIBUTES", NULL }, + /* 0x0e */ { "PRINTER_NOTIFY_PRIORITY", NULL }, + /* 0x0f */ { "PRINTER_NOTIFY_DEFAULT_PRIORITY", NULL }, + /* 0x10 */ { "PRINTER_NOTIFY_START_TIME", NULL }, + /* 0x11 */ { "PRINTER_NOTIFY_UNTIL_TIME", NULL }, + /* 0x12 */ { "PRINTER_NOTIFY_STATUS", notify_one_value }, +}; + +static struct notify2_message_table job_notify_table[] = { + /* 0x00 */ { "JOB_NOTIFY_PRINTER_NAME", NULL }, + /* 0x01 */ { "JOB_NOTIFY_MACHINE_NAME", NULL }, + /* 0x02 */ { "JOB_NOTIFY_PORT_NAME", NULL }, + /* 0x03 */ { "JOB_NOTIFY_USER_NAME", notify_string }, + /* 0x04 */ { "JOB_NOTIFY_NOTIFY_NAME", NULL }, + /* 0x05 */ { "JOB_NOTIFY_DATATYPE", NULL }, + /* 0x06 */ { "JOB_NOTIFY_PRINT_PROCESSOR", NULL }, + /* 0x07 */ { "JOB_NOTIFY_PARAMETERS", NULL }, + /* 0x08 */ { "JOB_NOTIFY_DRIVER_NAME", NULL }, + /* 0x09 */ { "JOB_NOTIFY_DEVMODE", NULL }, + /* 0x0a */ { "JOB_NOTIFY_STATUS", notify_one_value }, + /* 0x0b */ { "JOB_NOTIFY_STATUS_STRING", NULL }, + /* 0x0c */ { "JOB_NOTIFY_SECURITY_DESCRIPTOR", NULL }, + /* 0x0d */ { "JOB_NOTIFY_DOCUMENT", notify_string }, + /* 0x0e */ { "JOB_NOTIFY_PRIORITY", NULL }, + /* 0x0f */ { "JOB_NOTIFY_POSITION", NULL }, + /* 0x10 */ { "JOB_NOTIFY_SUBMITTED", notify_system_time }, + /* 0x11 */ { "JOB_NOTIFY_START_TIME", NULL }, + /* 0x12 */ { "JOB_NOTIFY_UNTIL_TIME", NULL }, + /* 0x13 */ { "JOB_NOTIFY_TIME", NULL }, + /* 0x14 */ { "JOB_NOTIFY_TOTAL_PAGES", notify_one_value }, + /* 0x15 */ { "JOB_NOTIFY_PAGES_PRINTED", NULL }, + /* 0x16 */ { "JOB_NOTIFY_TOTAL_BYTES", notify_one_value }, + /* 0x17 */ { "JOB_NOTIFY_BYTES_PRINTED", NULL }, +}; /*********************************************************************** Send a change notication message on all handles which have a call back registered **********************************************************************/ -static void send_spoolss_event_notification(PRINTER_MESSAGE_INFO *msg) +static void process_notify2_message(struct spoolss_notify_msg *msg, + TALLOC_CTX *mem_ctx) { - Printer_entry *find_printer; - WERROR result; - NT_PRINTER_INFO_LEVEL *printer = NULL; + Printer_entry *p; - if (!msg) { - DEBUG(0,("send_spoolss_event_notification: NULL msg pointer!\n")); - return; - } + for (p = printers_list; p; p = p->next) { + SPOOL_NOTIFY_INFO_DATA *data; + uint32 data_len = 1; + uint32 id; - for(find_printer = printers_list; find_printer; find_printer = find_printer->next) { + /* Is there notification on this handle? */ - /* - * If the entry has a connected client we send the message. There should - * only be one of these normally when dealing with the NT/2k spooler. - * However, iterate over all to make sure we deal with user applications - * in addition to spooler service. - * - * While we are only maintaining a single connection to the client, - * the FindFirstPrinterChangeNotification() call is made on a printer - * handle, so "client_connected" represents the whether or not the - * client asked for change notication on this handle. - * - * --jerry - */ + if (!p->notify.client_connected) + continue; - if (find_printer->notify.client_connected==True) { - - /* does the client care about what changed? */ + /* For this printer? Print servers always receive + notifications. */ - if (msg->flags && !is_client_monitoring_event(find_printer, msg->flags)) { - DEBUG(10,("send_spoolss_event_notification: Client [%s] not monitoring these events\n", - find_printer->client.machine)); - continue; - } + if (p->printer_type == PRINTER_HANDLE_IS_PRINTER && + !strequal(msg->printer, p->dev.handlename)) + continue; - if (find_printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) - DEBUG(10,("send_spoolss_event_notification: printserver [%s]\n", find_printer->dev.printerservername )); - else - DEBUG(10,("send_spoolss_event_notification: printer [%s]\n", find_printer->dev.handlename)); + /* Are we monitoring this event? */ + + if (!is_monitoring_event(p, msg->type, msg->field)) + continue; - /* - * if handle is a printer, only send if the printer_name matches. - * ...else if handle is a printerserver, send to all - */ + /* OK - send the event to the client */ - if (*msg->printer_name && (find_printer->printer_type==PRINTER_HANDLE_IS_PRINTER) - && !strequal(msg->printer_name, find_printer->dev.handlename)) - { - DEBUG(10,("send_spoolss_event_notification: ignoring message sent to %s [%s]\n", - msg->printer_name, find_printer->dev.handlename )); - continue; + data = talloc(mem_ctx, sizeof(SPOOL_NOTIFY_INFO_DATA)); + + ZERO_STRUCTP(data); + + /* Convert unix jobid to smb jobid */ + + id = msg->id; + + if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) { + + id = sysjob_to_jobid(msg->id); + + if (id == -1) { + DEBUG(3, ("no such unix jobid %d\n", msg->id)); + goto done; } + } + construct_info_data(data, msg->type, msg->field, id); - /* lookup the printer if we have a name if we don't already have a - valid NT_PRINTER_INFO_LEVEL structure. And yes I'm assuming we - will always have a non-empty msg.printer_name */ - - if (!printer || !printer->info_2 || strcmp(msg->printer_name, printer->info_2->printername)) - { - - if (printer) { - free_a_printer(&printer, 2); - printer = NULL; - } - - result = get_a_printer(&printer, 2, msg->printer_name); - if (!W_ERROR_IS_OK(result)) - continue; + switch(msg->type) { + case PRINTER_NOTIFY_TYPE: + if (printer_notify_table[msg->field].fn) + printer_notify_table[msg->field].fn( + msg, data, mem_ctx); + else + goto done; + break; + case JOB_NOTIFY_TYPE: + if (job_notify_table[msg->field].fn) + job_notify_table[msg->field].fn( + msg, data, mem_ctx); + else + goto done; + break; + default: + DEBUG(5, ("Unknown notification type %d\n", + msg->type)); + goto done; + } + + if (!p->notify.flags) + cli_spoolss_rrpcn( + &cli, mem_ctx, &p->notify.client_hnd, + data_len, data, p->notify.change, 0); + else { + NT_PRINTER_INFO_LEVEL *printer = NULL; + + get_a_printer(&printer, 2, msg->printer); + + if (!printer) { + DEBUG(5, ("unable to load info2 for %s\n", + msg->printer)); + goto done; } - /* issue the client call */ + /* XXX: This needs to be updated for + PRINTER_CHANGE_SET_PRINTER_DRIVER. */ - result = srv_spoolss_send_event_to_client(find_printer, &cli, msg, printer); - - if (!W_ERROR_IS_OK(result)) { - DEBUG(5,("send_spoolss_event_notification: Event notification failed [%s]\n", - dos_errstr(result))); + cli_spoolss_routerreplyprinter( + &cli, mem_ctx, &p->notify.client_hnd, + 0, printer->info_2->changeid); + + free_a_printer(&printer, 2); } } -} - +done: return; } -/*************************************************************************** - Receive the notify message and decode the message. Do not send - notification if we sent this originally as that would result in - duplicates. -****************************************************************************/ -static void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size_t len) +/* Receive a notify2 message */ + +static void receive_notify2_message(int msg_type, pid_t src, void *buf, + size_t len) { - PRINTER_MESSAGE_INFO msg; - - if (len < sizeof(msg)) { - DEBUG(2,("srv_spoolss_receive_message: got incorrect message size (%u)!\n", (unsigned int)len)); - return; - } + struct spoolss_notify_msg msg; + int offset = 0; + TALLOC_CTX *mem_ctx = talloc_init(); - memcpy(&msg, buf, sizeof(PRINTER_MESSAGE_INFO)); - - DEBUG(10,("srv_spoolss_receive_message: Got message printer change [queue = %s] low=0x%x high=0x%x flags=0x%x\n", - msg.printer_name, (unsigned int)msg.low, (unsigned int)msg.high, msg.flags )); + /* Unpack message */ - /* Iterate the printer list */ - - send_spoolss_event_notification(&msg); + ZERO_STRUCT(msg); + + offset += tdb_unpack((char *)buf + offset, len - offset, "f", + msg.printer); + offset += tdb_unpack((char *)buf + offset, len - offset, "ddddd", + &msg.type, &msg.field, &msg.id, &msg.len, &msg.flags); + + if (msg.len == 0) + tdb_unpack((char *)buf + offset, len - offset, "dd", + &msg.notify.value[0], &msg.notify.value[1]); + else + tdb_unpack((char *)buf + offset, len - offset, "B", + &msg.len, &msg.notify.data); + + DEBUG(3, ("got NOTIFY2 message, type %d, field 0x%02x, flags 0x%04x\n", + msg.type, msg.field, msg.flags)); + + if (msg.len == 0) + DEBUG(3, ("value1 = %d, value2 = %d\n", msg.notify.value[0], + msg.notify.value[1])); + else + dump_data(3, msg.notify.data, msg.len); + + /* Process message */ + + process_notify2_message(&msg, mem_ctx); + + /* Free message */ + + if (msg.len > 0) + free(msg.notify.data); + + talloc_destroy(mem_ctx); } /*************************************************************************** - Send a notify event. -****************************************************************************/ - -static BOOL srv_spoolss_sendnotify(char* printer_name, uint32 high, uint32 low, uint32 flags) + Server wrapper for cli_spoolss_routerreplyprinter() since the client + function can only send a single change notification at a time. + + FIXME!!! only handles one change currently (PRINTER_CHANGE_SET_PRINTER_DRIVER) + --jerry + **************************************************************************/ + +static WERROR srv_spoolss_routerreplyprinter (struct cli_state *reply_cli, TALLOC_CTX *mem_ctx, + POLICY_HND *pol, PRINTER_MESSAGE_INFO *info, + NT_PRINTER_INFO_LEVEL *printer) { - char msg[sizeof(PRINTER_MESSAGE_INFO)]; - PRINTER_MESSAGE_INFO info; + WERROR result; + uint32 condition = 0x0; - ZERO_STRUCT(info); + if (info->flags & PRINTER_MESSAGE_DRIVER) + condition = PRINTER_CHANGE_SET_PRINTER_DRIVER; + + result = cli_spoolss_routerreplyprinter(reply_cli, mem_ctx, pol, condition, + printer->info_2->changeid); - info.low = low; - info.high = high; - info.flags = flags; - fstrcpy(info.printer_name, printer_name); + return result; +} + +/******************************************************************** + Send a message to ourself about new driver being installed + so we can upgrade the information for each printer bound to this + driver + ********************************************************************/ + +static BOOL srv_spoolss_drv_upgrade_printer(char* drivername) +{ + int len = strlen(drivername); - memcpy(msg, &info, sizeof(PRINTER_MESSAGE_INFO)); + if (!len) + return False; - DEBUG(10,("srv_spoolss_sendnotify: printer change low=0x%x high=0x%x [%s], flags=0x%x\n", - low, high, printer_name, flags)); + DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n", + drivername)); - message_send_all(conn_tdb_ctx(), MSG_PRINTER_NOTIFY, msg, sizeof(PRINTER_MESSAGE_INFO), - False, NULL); + message_send_pid(sys_getpid(), MSG_PRINTER_DRVUPGRADE, drivername, len+1, False); return True; -} +} + +/********************************************************************** + callback to receive a MSG_PRINTER_DRVUPGRADE message and interate + over all printers, upgrading ones as neessary + **********************************************************************/ + +void do_drv_upgrade_printer(int msg_type, pid_t src, void *buf, size_t len) +{ + fstring drivername; + int snum; + int n_services = lp_numservices(); + + len = MIN(len,sizeof(drivername)-1); + strncpy(drivername, buf, len); + + DEBUG(10,("do_drv_upgrade_printer: Got message for new driver [%s]\n", drivername )); + + /* Iterate the printer list */ + + for (snum=0; snuminfo_2 && !strcmp(drivername, printer->info_2->drivername)) + { + DEBUG(6,("Updating printer [%s]\n", printer->info_2->printername)); + + /* all we care about currently is the change_id */ + + result = mod_a_printer(*printer, 2); + if (!W_ERROR_IS_OK(result)) { + DEBUG(3,("do_drv_upgrade_printer: mod_a_printer() failed with status [%s]\n", + dos_errstr(result))); + } + } + + free_a_printer(&printer, 2); + } + } + + /* all done */ +} /******************************************************************** Copy routines used by convert_to_openprinterex() @@ -924,16 +1126,6 @@ Can't find printer handle we created for printer %s\n", name )); return WERR_INVALID_PRINTER_NAME; } -/* - if (printer_default->datatype_ptr != NULL) - { - unistr2_to_ascii(datatype, printer_default->datatype, sizeof(datatype)-1); - set_printer_hnd_datatype(handle, datatype); - } - else - set_printer_hnd_datatype(handle, ""); -*/ - /* First case: the user is opening the print server: @@ -997,7 +1189,7 @@ Can't find printer handle we created for printer %s\n", name )); user_in_list(uidtoname(user.uid), lp_printer_admin(snum))) return WERR_OK; - + close_printer_handle(p, handle); return WERR_ACCESS_DENIED; } @@ -1031,7 +1223,9 @@ Can't find printer handle we created for printer %s\n", name )); printer_default->access_required = PRINTER_ACCESS_USE; } - if (!print_access_check(&user, snum, printer_default->access_required)) { + /* check smb.conf parameters and the the sec_desc */ + + if (!user_ok(uidtoname(user.uid), snum) || !print_access_check(&user, snum, printer_default->access_required)) { DEBUG(3, ("access DENIED for printer open\n")); close_printer_handle(p, handle); return WERR_ACCESS_DENIED; @@ -1308,10 +1502,6 @@ WERROR _spoolss_deleteprinter(pipes_struct *p, SPOOL_Q_DELETEPRINTER *q_u, SPOOL update_c_setprinter(False); - if (W_ERROR_IS_OK(result)) { - srv_spoolss_sendnotify(Printer->dev.handlename, 0, PRINTER_CHANGE_DELETE_PRINTER, 0x0); - } - return result; } @@ -1344,26 +1534,17 @@ static int get_version_id (char * arch) /******************************************************************** * _spoolss_deleteprinterdriver - * - * We currently delete the driver for the architecture only. - * This can leave the driver for other archtectures. However, - * since every printer associates a "Windows NT x86" driver name - * and we cannot delete that one while it is in use, **and** since - * it is impossible to assign a driver to a Samba printer without - * having the "Windows NT x86" driver installed,... - * - * ....we should not get into trouble here. - * - * --jerry ********************************************************************/ -WERROR _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER *q_u, - SPOOL_R_DELETEPRINTERDRIVER *r_u) +WERROR _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER *q_u, SPOOL_R_DELETEPRINTERDRIVER *r_u) { fstring driver; fstring arch; NT_PRINTER_DRIVER_INFO_LEVEL info; int version; + struct current_user user; + + get_current_user(&user, p); unistr2_to_ascii(driver, &q_u->driver, sizeof(driver)-1 ); unistr2_to_ascii(arch, &q_u->arch, sizeof(arch)-1 ); @@ -1373,21 +1554,89 @@ WERROR _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER /* this is what NT returns */ return WERR_INVALID_ENVIRONMENT; } + + /* if they said "Windows NT x86", then try for version 2 & 3 */ + + if ( version == 2 ) + version = DRIVER_ANY_VERSION; ZERO_STRUCT(info); - if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, driver, arch, version))) { + + if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, driver, arch, version))) return WERR_UNKNOWN_PRINTER_DRIVER; - } + if (printer_driver_in_use(info.info_3)) + return WERR_PRINTER_DRIVER_IN_USE; - if (printer_driver_in_use(arch, driver)) - { + return delete_printer_driver(info.info_3, &user, DRIVER_ANY_VERSION, False); +} + +/******************************************************************** + * spoolss_deleteprinterdriverex + ********************************************************************/ + +WERROR _spoolss_deleteprinterdriverex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVEREX *q_u, SPOOL_R_DELETEPRINTERDRIVEREX *r_u) +{ + fstring driver; + fstring arch; + NT_PRINTER_DRIVER_INFO_LEVEL info; + int version; + uint32 flags = q_u->delete_flags; + BOOL delete_files; + struct current_user user; + + get_current_user(&user, p); + + unistr2_to_ascii(driver, &q_u->driver, sizeof(driver)-1 ); + unistr2_to_ascii(arch, &q_u->arch, sizeof(arch)-1 ); + + /* check that we have a valid driver name first */ + if ((version=get_version_id(arch)) == -1) { + /* this is what NT returns */ + return WERR_INVALID_ENVIRONMENT; + } + + if ( flags & DPD_DELETE_SPECIFIC_VERSION ) + version = q_u->version; + else if ( version == 2 ) + /* if they said "Windows NT x86", then try for version 2 & 3 */ + version = DRIVER_ANY_VERSION; + + ZERO_STRUCT(info); + + if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, driver, arch, version))) + return WERR_UNKNOWN_PRINTER_DRIVER; + + if ( printer_driver_in_use(info.info_3) ) return WERR_PRINTER_DRIVER_IN_USE; + + /* + * we have a couple of cases to consider. + * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set, + * then the delete should fail if **any** files overlap with + * other drivers + * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all + * non-overlapping files + * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES + * is set, the do not delete any files + * Refer to MSDN docs on DeletePrinterDriverEx() for details. + */ + + delete_files = flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES); + + if ( delete_files ) + { + /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */ + + if ( printer_driver_files_in_use(info.info_3) & (flags&DPD_DELETE_ALL_FILES) ) + /* no idea of the correct error here */ + return WERR_ACCESS_DENIED; } - return delete_printer_driver(info.info_3); + return delete_printer_driver(info.info_3, &user, version, delete_files); } + /******************************************************************** GetPrinterData on a printer server Handle. ********************************************************************/ @@ -1438,7 +1687,11 @@ static BOOL getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint32 *type = 0x4; if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) return False; +#ifndef EMULATE_WIN2K_HACK /* JERRY */ SIVAL(*data, 0, 2); +#else + SIVAL(*data, 0, 3); +#endif *needed = 0x4; return True; } @@ -1574,36 +1827,126 @@ WERROR _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO DEBUG(2,("_spoolss_getprinterdata: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); return WERR_BADFID; } - - unistr2_to_ascii(value, valuename, sizeof(value)-1); - - if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) - found=getprinterdata_printer_server(p->mem_ctx, value, type, data, needed, *out_size); - else - found= getprinterdata_printer(p, p->mem_ctx, handle, value, type, data, needed, *out_size); + + unistr2_to_ascii(value, valuename, sizeof(value)-1); + + if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) + found=getprinterdata_printer_server(p->mem_ctx, value, type, data, needed, *out_size); + else + found= getprinterdata_printer(p, p->mem_ctx, handle, value, type, data, needed, *out_size); + + if (found==False) { + DEBUG(5, ("value not found, allocating %d\n", *out_size)); + /* reply this param doesn't exist */ + if (*out_size) { + if((*data=(uint8 *)talloc_zero(p->mem_ctx, *out_size*sizeof(uint8))) == NULL) + return WERR_NOMEM; + } else { + *data = NULL; + } + + /* error depends on handle type */ + + if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) + return WERR_INVALID_PARAM; + else + return WERR_BADFILE; + } + + if (*needed > *out_size) + return WERR_MORE_DATA; + else + return WERR_OK; +} + +/********************************************************* + Connect to the client machine. +**********************************************************/ + +static BOOL spoolss_connect_to_client(struct cli_state *the_cli, char *remote_machine) +{ + extern pstring global_myname; + + ZERO_STRUCTP(the_cli); + if(cli_initialise(the_cli) == NULL) { + DEBUG(0,("connect_to_client: unable to initialize client connection.\n")); + return False; + } + + if(!resolve_name( remote_machine, &the_cli->dest_ip, 0x20)) { + DEBUG(0,("connect_to_client: Can't resolve address for %s\n", remote_machine)); + cli_shutdown(the_cli); + return False; + } + + if (ismyip(the_cli->dest_ip)) { + DEBUG(0,("connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n", remote_machine)); + cli_shutdown(the_cli); + return False; + } + + if (!cli_connect(the_cli, remote_machine, &the_cli->dest_ip)) { + DEBUG(0,("connect_to_client: unable to connect to SMB server on machine %s. Error was : %s.\n", remote_machine, cli_errstr(the_cli) )); + cli_shutdown(the_cli); + return False; + } + + if (!attempt_netbios_session_request(the_cli, global_myname, remote_machine, &the_cli->dest_ip)) { + DEBUG(0,("connect_to_client: machine %s rejected the NetBIOS session request.\n", + remote_machine)); + return False; + } + + the_cli->protocol = PROTOCOL_NT1; + + if (!cli_negprot(the_cli)) { + DEBUG(0,("connect_to_client: machine %s rejected the negotiate protocol. Error was : %s.\n", remote_machine, cli_errstr(the_cli) )); + cli_shutdown(the_cli); + return False; + } + + if (the_cli->protocol != PROTOCOL_NT1) { + DEBUG(0,("connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine)); + cli_shutdown(the_cli); + return False; + } + + /* + * Do an anonymous session setup. + */ + + if (!cli_session_setup(the_cli, "", "", 0, "", 0, "")) { + DEBUG(0,("connect_to_client: machine %s rejected the session setup. Error was : %s.\n", remote_machine, cli_errstr(the_cli) )); + cli_shutdown(the_cli); + return False; + } + + if (!(the_cli->sec_mode & 1)) { + DEBUG(0,("connect_to_client: machine %s isn't in user level security mode\n", remote_machine)); + cli_shutdown(the_cli); + return False; + } + + if (!cli_send_tconX(the_cli, "IPC$", "IPC", "", 1)) { + DEBUG(0,("connect_to_client: machine %s rejected the tconX on the IPC$ share. Error was : %s.\n", remote_machine, cli_errstr(the_cli) )); + cli_shutdown(the_cli); + return False; + } - if (found==False) { - DEBUG(5, ("value not found, allocating %d\n", *out_size)); - /* reply this param doesn't exist */ - if (*out_size) { - if((*data=(uint8 *)talloc_zero(p->mem_ctx, *out_size*sizeof(uint8))) == NULL) - return WERR_NOMEM; - } else { - *data = NULL; - } + /* + * Ok - we have an anonymous connection to the IPC$ share. + * Now start the NT Domain stuff :-). + */ - /* error depends on handle type */ + if(cli_nt_session_open(the_cli, PIPE_SPOOLSS) == False) { + DEBUG(0,("connect_to_client: unable to open the domain client session to machine %s. Error was : %s.\n", remote_machine, cli_errstr(the_cli))); + cli_nt_session_close(the_cli); + cli_ulogoff(the_cli); + cli_shutdown(the_cli); + return False; + } - if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) - return WERR_INVALID_PARAM; - else - return WERR_BADFILE; - } - - if (*needed > *out_size) - return WERR_MORE_DATA; - else - return WERR_OK; + return True; } /*************************************************************************** @@ -1626,15 +1969,14 @@ static BOOL srv_spoolss_replyopenprinter(char *printer, uint32 localprinter, uin if(!spoolss_connect_to_client(&cli, unix_printer)) return False; - message_register(MSG_PRINTER_NOTIFY, srv_spoolss_receive_message); - + message_register(MSG_PRINTER_NOTIFY2, receive_notify2_message); } smb_connections++; result = cli_spoolss_reply_open_printer(&cli, cli.mem_ctx, printer, localprinter, type, handle); - + if (!W_ERROR_IS_OK(result)) DEBUG(5,("srv_spoolss_reply_open_printer: Client RPC returned [%s]\n", dos_errstr(result))); @@ -1646,9 +1988,8 @@ static BOOL srv_spoolss_replyopenprinter(char *printer, uint32 localprinter, uin * _spoolss_rffpcnex * ReplyFindFirstPrinterChangeNotifyEx * - * jfmxxxx: before replying OK: status=0 - * should do a rpc call to the workstation asking ReplyOpenPrinter - * have to code it, later. + * before replying OK: status=0 a rpc call is made to the workstation + * asking ReplyOpenPrinter * * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe * called from api_spoolss_rffpcnex @@ -1681,15 +2022,17 @@ WERROR _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE Printer->notify.option=dup_spool_notify_option(option); - unistr2_to_ascii(Printer->notify.localmachine, localmachine, sizeof(Printer->notify.localmachine)-1); + unistr2_to_ascii(Printer->notify.localmachine, localmachine, + sizeof(Printer->notify.localmachine)-1); + + /* Connect to the client machine and send a ReplyOpenPrinter */ - /* connect to the client machine and send a ReplyOpenPrinter */ - if(srv_spoolss_replyopenprinter(Printer->notify.localmachine, + if(!srv_spoolss_replyopenprinter(Printer->notify.localmachine, Printer->notify.printerlocal, 1, &Printer->notify.client_hnd)) - { - Printer->notify.client_connected=True; - } + return WERR_SERVER_UNAVAILABLE; + + Printer->notify.client_connected=True; return WERR_OK; } @@ -1711,7 +2054,7 @@ void spoolss_notify_server_name(int snum, len = rpcstr_push(temp, temp_name, sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.length = len; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1746,7 +2089,7 @@ void spoolss_notify_printer_name(int snum, len = rpcstr_push(temp, p, sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.length = len; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1772,7 +2115,7 @@ void spoolss_notify_share_name(int snum, len = rpcstr_push(temp, lp_servicename(snum), sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.length = len; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1800,7 +2143,7 @@ void spoolss_notify_port_name(int snum, len = rpcstr_push(temp, printer->info_2->portname, sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.length = len; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1826,7 +2169,8 @@ void spoolss_notify_driver_name(int snum, uint32 len; len = rpcstr_push(temp, printer->info_2->drivername, sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2 - 1; + + data->notify_data.data.length = len; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1855,7 +2199,7 @@ void spoolss_notify_comment(int snum, else len = rpcstr_push(temp, printer->info_2->comment, sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.length = len; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1882,7 +2226,7 @@ void spoolss_notify_location(int snum, len = rpcstr_push(temp, printer->info_2->location,sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.length = len; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1921,7 +2265,7 @@ void spoolss_notify_sepfile(int snum, len = rpcstr_push(temp, printer->info_2->sepfile, sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.length = len; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1948,7 +2292,7 @@ void spoolss_notify_print_processor(int snum, len = rpcstr_push(temp, printer->info_2->printprocessor, sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.length = len; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -1975,7 +2319,7 @@ void spoolss_notify_parameters(int snum, len = rpcstr_push(temp, printer->info_2->parameters, sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.length = len; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -2002,7 +2346,7 @@ void spoolss_notify_datatype(int snum, len = rpcstr_push(temp, printer->info_2->datatype, sizeof(pstring)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.length = len; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -2162,7 +2506,7 @@ static void spoolss_notify_username(int snum, len = rpcstr_push(temp, queue->fs_user, sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.length = len; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -2202,7 +2546,7 @@ static void spoolss_notify_job_name(int snum, len = rpcstr_push(temp, queue->fs_file, sizeof(temp)-2, STR_TERMINATE); - data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.length = len; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -2252,7 +2596,7 @@ static void spoolss_notify_job_status_string(int snum, len = rpcstr_push(temp, p, sizeof(temp) - 2, STR_TERMINATE); - data->notify_data.data.length = len / 2 - 1; + data->notify_data.data.length = len; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); if (!data->notify_data.data.string) { @@ -2376,8 +2720,6 @@ static void spoolss_notify_submitted_time(int snum, SSVAL(p, 14, st.milliseconds); } -#define END 65535 - struct s_notify_info_data_table { uint16 type; @@ -2389,59 +2731,61 @@ struct s_notify_info_data_table NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx); }; +/* A table describing the various print notification constants and + whether the notification data is a pointer to a variable sized + buffer, a one value uint32 or a two value uint32. */ + struct s_notify_info_data_table notify_info_data_table[] = { -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SERVER_NAME, "PRINTER_NOTIFY_SERVER_NAME", POINTER, spoolss_notify_server_name }, -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINTER_NAME, "PRINTER_NOTIFY_PRINTER_NAME", POINTER, spoolss_notify_printer_name }, -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SHARE_NAME, "PRINTER_NOTIFY_SHARE_NAME", POINTER, spoolss_notify_share_name }, -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PORT_NAME, "PRINTER_NOTIFY_PORT_NAME", POINTER, spoolss_notify_port_name }, -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DRIVER_NAME, "PRINTER_NOTIFY_DRIVER_NAME", POINTER, spoolss_notify_driver_name }, -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_COMMENT, "PRINTER_NOTIFY_COMMENT", POINTER, spoolss_notify_comment }, -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_LOCATION, "PRINTER_NOTIFY_LOCATION", POINTER, spoolss_notify_location }, -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DEVMODE, "PRINTER_NOTIFY_DEVMODE", POINTER, spoolss_notify_devmode }, -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SEPFILE, "PRINTER_NOTIFY_SEPFILE", POINTER, spoolss_notify_sepfile }, -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINT_PROCESSOR, "PRINTER_NOTIFY_PRINT_PROCESSOR", POINTER, spoolss_notify_print_processor }, -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PARAMETERS, "PRINTER_NOTIFY_PARAMETERS", POINTER, spoolss_notify_parameters }, -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DATATYPE, "PRINTER_NOTIFY_DATATYPE", POINTER, spoolss_notify_datatype }, -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_SECURITY_DESCRIPTOR", POINTER, spoolss_notify_security_desc }, -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_ATTRIBUTES, "PRINTER_NOTIFY_ATTRIBUTES", ONE_VALUE, spoolss_notify_attributes }, -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRIORITY, "PRINTER_NOTIFY_PRIORITY", ONE_VALUE, spoolss_notify_priority }, -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DEFAULT_PRIORITY, "PRINTER_NOTIFY_DEFAULT_PRIORITY", ONE_VALUE, spoolss_notify_default_priority }, -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_START_TIME, "PRINTER_NOTIFY_START_TIME", ONE_VALUE, spoolss_notify_start_time }, -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_UNTIL_TIME, "PRINTER_NOTIFY_UNTIL_TIME", ONE_VALUE, spoolss_notify_until_time }, -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_STATUS, "PRINTER_NOTIFY_STATUS", ONE_VALUE, spoolss_notify_status }, -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_STATUS_STRING, "PRINTER_NOTIFY_STATUS_STRING", POINTER, NULL }, -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_CJOBS, "PRINTER_NOTIFY_CJOBS", ONE_VALUE, spoolss_notify_cjobs }, -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_AVERAGE_PPM, "PRINTER_NOTIFY_AVERAGE_PPM", ONE_VALUE, spoolss_notify_average_ppm }, -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_PAGES, "PRINTER_NOTIFY_TOTAL_PAGES", POINTER, NULL }, -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PAGES_PRINTED, "PRINTER_NOTIFY_PAGES_PRINTED", POINTER, NULL }, -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_BYTES, "PRINTER_NOTIFY_TOTAL_BYTES", POINTER, NULL }, -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_BYTES_PRINTED, "PRINTER_NOTIFY_BYTES_PRINTED", POINTER, NULL }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINTER_NAME, "JOB_NOTIFY_PRINTER_NAME", POINTER, spoolss_notify_printer_name }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_MACHINE_NAME, "JOB_NOTIFY_MACHINE_NAME", POINTER, spoolss_notify_server_name }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_PORT_NAME, "JOB_NOTIFY_PORT_NAME", POINTER, spoolss_notify_port_name }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_USER_NAME, "JOB_NOTIFY_USER_NAME", POINTER, spoolss_notify_username }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_NOTIFY_NAME, "JOB_NOTIFY_NOTIFY_NAME", POINTER, spoolss_notify_username }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_DATATYPE, "JOB_NOTIFY_DATATYPE", POINTER, spoolss_notify_datatype }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINT_PROCESSOR, "JOB_NOTIFY_PRINT_PROCESSOR", POINTER, spoolss_notify_print_processor }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_PARAMETERS, "JOB_NOTIFY_PARAMETERS", POINTER, spoolss_notify_parameters }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_DRIVER_NAME, "JOB_NOTIFY_DRIVER_NAME", POINTER, spoolss_notify_driver_name }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_DEVMODE, "JOB_NOTIFY_DEVMODE", POINTER, spoolss_notify_devmode }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_STATUS, "JOB_NOTIFY_STATUS", ONE_VALUE, spoolss_notify_job_status }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_STATUS_STRING, "JOB_NOTIFY_STATUS_STRING", POINTER, spoolss_notify_job_status_string }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_SECURITY_DESCRIPTOR, "JOB_NOTIFY_SECURITY_DESCRIPTOR", POINTER, NULL }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_DOCUMENT, "JOB_NOTIFY_DOCUMENT", POINTER, spoolss_notify_job_name }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_PRIORITY, "JOB_NOTIFY_PRIORITY", ONE_VALUE, spoolss_notify_priority }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_POSITION, "JOB_NOTIFY_POSITION", ONE_VALUE, spoolss_notify_job_position }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_SUBMITTED, "JOB_NOTIFY_SUBMITTED", POINTER, spoolss_notify_submitted_time }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_START_TIME, "JOB_NOTIFY_START_TIME", ONE_VALUE, spoolss_notify_start_time }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_UNTIL_TIME, "JOB_NOTIFY_UNTIL_TIME", ONE_VALUE, spoolss_notify_until_time }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_TIME, "JOB_NOTIFY_TIME", ONE_VALUE, spoolss_notify_job_time }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_PAGES, "JOB_NOTIFY_TOTAL_PAGES", ONE_VALUE, spoolss_notify_total_pages }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_PAGES_PRINTED, "JOB_NOTIFY_PAGES_PRINTED", ONE_VALUE, spoolss_notify_pages_printed }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_BYTES, "JOB_NOTIFY_TOTAL_BYTES", ONE_VALUE, spoolss_notify_job_size }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_BYTES_PRINTED, "JOB_NOTIFY_BYTES_PRINTED", ONE_VALUE, NULL }, -{ END, END, "", END, NULL } +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SERVER_NAME, "PRINTER_NOTIFY_SERVER_NAME", NOTIFY_STRING, spoolss_notify_server_name }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINTER_NAME, "PRINTER_NOTIFY_PRINTER_NAME", NOTIFY_STRING, spoolss_notify_printer_name }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SHARE_NAME, "PRINTER_NOTIFY_SHARE_NAME", NOTIFY_STRING, spoolss_notify_share_name }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PORT_NAME, "PRINTER_NOTIFY_PORT_NAME", NOTIFY_STRING, spoolss_notify_port_name }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DRIVER_NAME, "PRINTER_NOTIFY_DRIVER_NAME", NOTIFY_STRING, spoolss_notify_driver_name }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_COMMENT, "PRINTER_NOTIFY_COMMENT", NOTIFY_STRING, spoolss_notify_comment }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_LOCATION, "PRINTER_NOTIFY_LOCATION", NOTIFY_STRING, spoolss_notify_location }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DEVMODE, "PRINTER_NOTIFY_DEVMODE", NOTIFY_POINTER, spoolss_notify_devmode }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SEPFILE, "PRINTER_NOTIFY_SEPFILE", NOTIFY_STRING, spoolss_notify_sepfile }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINT_PROCESSOR, "PRINTER_NOTIFY_PRINT_PROCESSOR", NOTIFY_STRING, spoolss_notify_print_processor }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PARAMETERS, "PRINTER_NOTIFY_PARAMETERS", NOTIFY_STRING, spoolss_notify_parameters }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DATATYPE, "PRINTER_NOTIFY_DATATYPE", NOTIFY_STRING, spoolss_notify_datatype }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_SECURITY_DESCRIPTOR", NOTIFY_POINTER, spoolss_notify_security_desc }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_ATTRIBUTES, "PRINTER_NOTIFY_ATTRIBUTES", NOTIFY_ONE_VALUE, spoolss_notify_attributes }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRIORITY, "PRINTER_NOTIFY_PRIORITY", NOTIFY_ONE_VALUE, spoolss_notify_priority }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DEFAULT_PRIORITY, "PRINTER_NOTIFY_DEFAULT_PRIORITY", NOTIFY_ONE_VALUE, spoolss_notify_default_priority }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_START_TIME, "PRINTER_NOTIFY_START_TIME", NOTIFY_ONE_VALUE, spoolss_notify_start_time }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_UNTIL_TIME, "PRINTER_NOTIFY_UNTIL_TIME", NOTIFY_ONE_VALUE, spoolss_notify_until_time }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_STATUS, "PRINTER_NOTIFY_STATUS", NOTIFY_ONE_VALUE, spoolss_notify_status }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_STATUS_STRING, "PRINTER_NOTIFY_STATUS_STRING", NOTIFY_POINTER, NULL }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_CJOBS, "PRINTER_NOTIFY_CJOBS", NOTIFY_ONE_VALUE, spoolss_notify_cjobs }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_AVERAGE_PPM, "PRINTER_NOTIFY_AVERAGE_PPM", NOTIFY_ONE_VALUE, spoolss_notify_average_ppm }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_PAGES, "PRINTER_NOTIFY_TOTAL_PAGES", NOTIFY_POINTER, NULL }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PAGES_PRINTED, "PRINTER_NOTIFY_PAGES_PRINTED", NOTIFY_POINTER, NULL }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_BYTES, "PRINTER_NOTIFY_TOTAL_BYTES", NOTIFY_POINTER, NULL }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_BYTES_PRINTED, "PRINTER_NOTIFY_BYTES_PRINTED", NOTIFY_POINTER, NULL }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINTER_NAME, "JOB_NOTIFY_PRINTER_NAME", NOTIFY_STRING, spoolss_notify_printer_name }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_MACHINE_NAME, "JOB_NOTIFY_MACHINE_NAME", NOTIFY_STRING, spoolss_notify_server_name }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_PORT_NAME, "JOB_NOTIFY_PORT_NAME", NOTIFY_STRING, spoolss_notify_port_name }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_USER_NAME, "JOB_NOTIFY_USER_NAME", NOTIFY_STRING, spoolss_notify_username }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_NOTIFY_NAME, "JOB_NOTIFY_NOTIFY_NAME", NOTIFY_STRING, spoolss_notify_username }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_DATATYPE, "JOB_NOTIFY_DATATYPE", NOTIFY_STRING, spoolss_notify_datatype }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINT_PROCESSOR, "JOB_NOTIFY_PRINT_PROCESSOR", NOTIFY_STRING, spoolss_notify_print_processor }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_PARAMETERS, "JOB_NOTIFY_PARAMETERS", NOTIFY_STRING, spoolss_notify_parameters }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_DRIVER_NAME, "JOB_NOTIFY_DRIVER_NAME", NOTIFY_STRING, spoolss_notify_driver_name }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_DEVMODE, "JOB_NOTIFY_DEVMODE", NOTIFY_POINTER, spoolss_notify_devmode }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_STATUS, "JOB_NOTIFY_STATUS", NOTIFY_ONE_VALUE, spoolss_notify_job_status }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_STATUS_STRING, "JOB_NOTIFY_STATUS_STRING", NOTIFY_STRING, spoolss_notify_job_status_string }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_SECURITY_DESCRIPTOR, "JOB_NOTIFY_SECURITY_DESCRIPTOR", NOTIFY_POINTER, NULL }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_DOCUMENT, "JOB_NOTIFY_DOCUMENT", NOTIFY_STRING, spoolss_notify_job_name }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_PRIORITY, "JOB_NOTIFY_PRIORITY", NOTIFY_ONE_VALUE, spoolss_notify_priority }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_POSITION, "JOB_NOTIFY_POSITION", NOTIFY_ONE_VALUE, spoolss_notify_job_position }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_SUBMITTED, "JOB_NOTIFY_SUBMITTED", NOTIFY_POINTER, spoolss_notify_submitted_time }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_START_TIME, "JOB_NOTIFY_START_TIME", NOTIFY_ONE_VALUE, spoolss_notify_start_time }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_UNTIL_TIME, "JOB_NOTIFY_UNTIL_TIME", NOTIFY_ONE_VALUE, spoolss_notify_until_time }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_TIME, "JOB_NOTIFY_TIME", NOTIFY_ONE_VALUE, spoolss_notify_job_time }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_PAGES, "JOB_NOTIFY_TOTAL_PAGES", NOTIFY_ONE_VALUE, spoolss_notify_total_pages }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_PAGES_PRINTED, "JOB_NOTIFY_PAGES_PRINTED", NOTIFY_ONE_VALUE, spoolss_notify_pages_printed }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_BYTES, "JOB_NOTIFY_TOTAL_BYTES", NOTIFY_ONE_VALUE, spoolss_notify_job_size }, }; /******************************************************************* @@ -2452,43 +2796,46 @@ static uint32 size_of_notify_info_data(uint16 type, uint16 field) { int i=0; - while (notify_info_data_table[i].type != END) - { - if ( (notify_info_data_table[i].type == type ) && - (notify_info_data_table[i].field == field ) ) - { - return (notify_info_data_table[i].size); + for (i = 0; i < sizeof(notify_info_data_table); i++) { + if (notify_info_data_table[i].type == type && + notify_info_data_table[i].field == field) { + switch(notify_info_data_table[i].size) { + case NOTIFY_ONE_VALUE: + case NOTIFY_TWO_VALUE: + return 1; + case NOTIFY_STRING: + return 2; + + /* The only pointer notify data I have seen on + the wire is the submitted time and this has + the notify size set to 4. -tpot */ + + case NOTIFY_POINTER: + return 4; + } } - i++; } - return (65535); + + DEBUG(5, ("invalid notify data type %d/%d\n", type, field)); + + return 0; } /******************************************************************* Return the type of notify_info_data. ********************************************************************/ -static BOOL type_of_notify_info_data(uint16 type, uint16 field) +static int type_of_notify_info_data(uint16 type, uint16 field) { int i=0; - while (notify_info_data_table[i].type != END) - { - if ( (notify_info_data_table[i].type == type ) && - (notify_info_data_table[i].field == field ) ) - { - if (notify_info_data_table[i].size == POINTER) - { - return (False); - } - else - { - return (True); - } - } - i++; + for (i = 0; i < sizeof(notify_info_data_table); i++) { + if (notify_info_data_table[i].type == type && + notify_info_data_table[i].field == field) + return notify_info_data_table[i].size; } - return (False); + + return False; } /**************************************************************************** @@ -2496,21 +2843,18 @@ static BOOL type_of_notify_info_data(uint16 type, uint16 field) static int search_notify(uint16 type, uint16 field, int *value) { - int j; - BOOL found; + int i; - for (j=0, found=False; found==False && notify_info_data_table[j].type != END ; j++) - { - if ( (notify_info_data_table[j].type == type ) && - (notify_info_data_table[j].field == field ) ) - found=True; + for (i = 0; i < sizeof(notify_info_data_table); i++) { + if (notify_info_data_table[i].type == type && + notify_info_data_table[i].field == field && + notify_info_data_table[i].fn != NULL) { + *value = i; + return True; + } } - *value=--j; - - if ( found && (notify_info_data_table[j].fn != NULL) ) - return True; - else - return False; + + return False; } /**************************************************************************** @@ -2521,7 +2865,12 @@ void construct_info_data(SPOOL_NOTIFY_INFO_DATA *info_data, uint16 type, uint16 info_data->type = type; info_data->field = field; info_data->reserved = 0; - info_data->id = id; + + if (type == JOB_NOTIFY_TYPE) + info_data->id = id; + else + info_data->id = 0; + info_data->size = size_of_notify_info_data(type, field); info_data->enc_type = type_of_notify_info_data(type, field); } @@ -2570,7 +2919,7 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int current_data=&info->data[info->count]; - construct_info_data(current_data, type, field, id); + construct_info_data(current_data, type, field, id); DEBUG(10,("construct_notify_printer_info: calling [%s] snum=%d printername=[%s])\n", notify_info_data_table[j].name, snum, printer->info_2->printername )); @@ -2812,7 +3161,6 @@ static WERROR printer_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY WERROR _spoolss_rfnpcnex( pipes_struct *p, SPOOL_Q_RFNPCNEX *q_u, SPOOL_R_RFNPCNEX *r_u) { POLICY_HND *handle = &q_u->handle; -/* uint32 change = q_u->change; - notused. */ /* SPOOL_NOTIFY_OPTION *option = q_u->option; - notused. */ SPOOL_NOTIFY_INFO *info = &r_u->info; @@ -2830,17 +3178,19 @@ WERROR _spoolss_rfnpcnex( pipes_struct *p, SPOOL_Q_RFNPCNEX *q_u, SPOOL_R_RFNPCN DEBUG(4,("Printer type %x\n",Printer->printer_type)); - /* jfm: the change value isn't used right now. - * we will honour it when - * a) we'll be able to send notification to the client - * b) we'll have a way to communicate between the spoolss process. - * - * same thing for option->flags + /* + * We are now using the change value, and * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as * I don't have a global notification system, I'm sending back all the * informations even when _NOTHING_ has changed. */ + /* We need to keep track of the change value to send back in + RRPCN replies otherwise our updates are ignored. */ + + if (Printer->notify.client_connected) + Printer->notify.change = q_u->change; + /* just ignore the SPOOL_NOTIFY_OPTION */ switch (Printer->printer_type) { @@ -2932,7 +3282,7 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum) printer->global_counter = global_counter; printer->total_pages = 0; -#if 0 /* JERRY */ +#ifndef EMULATE_WIN2K_HACK /* JERRY */ printer->major_version = 0x0004; /* NT 4 */ printer->build_version = 0x0565; /* build 1381 */ #else @@ -2971,7 +3321,6 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum) * construct_printer_info_1 * fill a printer_info_1 struct ********************************************************************/ - static BOOL construct_printer_info_1(uint32 flags, PRINTER_INFO_1 *printer, int snum) { pstring chaine; @@ -3046,8 +3395,10 @@ static DEVICEMODE *construct_dev_mode(int snum) if (printer->info_2->devmode) ntdevmode = dup_nt_devicemode(printer->info_2->devmode); - if (ntdevmode == NULL) + if (ntdevmode == NULL) { + DEBUG(5, ("BONG! There was no device mode!\n")); goto fail; + } DEBUGADD(8,("loading DEVICEMODE\n")); @@ -3408,10 +3759,26 @@ static WERROR enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, enum_all_printers_info_1_network. *********************************************************************/ -static WERROR enum_all_printers_info_1_network(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enum_all_printers_info_1_network(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { + char *s = name; + DEBUG(4,("enum_all_printers_info_1_network\n")); + /* If we respond to a enum_printers level 1 on our name with flags + set to PRINTER_ENUM_REMOTE with a list of printers then these + printers incorrectly appear in the APW browse list. + Specifically the printers for the server appear at the workgroup + level where all the other servers in the domain are + listed. Windows responds to this call with a + WERR_CAN_NOT_COMPLETE so we should do the same. */ + + if (name[0] == '\\' && name[1] == '\\') + s = name + 2; + + if (is_myname_or_ipaddr(s)) + return WERR_CAN_NOT_COMPLETE; + return enum_all_printers_info_1(PRINTER_ENUM_UNKNOWN_8, buffer, offered, needed, returned); } @@ -3449,9 +3816,9 @@ static WERROR enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint3 } /* check the required size. */ - for (i=0; i<*returned; i++) + for (i=0; i<*returned; i++) (*needed) += spoolss_size_printer_info_2(&printers[i]); - + if (!alloc_buffer_size(buffer, *needed)) { for (i=0; i<*returned; i++) { free_devmode(printers[i].devmode); @@ -3498,7 +3865,7 @@ static WERROR enumprinters_level1( uint32 flags, fstring name, return enum_all_printers_info_1_remote(name, buffer, offered, needed, returned); if (flags & PRINTER_ENUM_NETWORK) - return enum_all_printers_info_1_network(buffer, offered, needed, returned); + return enum_all_printers_info_1_network(name, buffer, offered, needed, returned); return WERR_OK; /* NT4sp5 does that */ } @@ -3681,7 +4048,7 @@ static WERROR getprinter_level_2(int snum, NEW_BUFFER *buffer, uint32 offered, u /* check the required size. */ *needed += spoolss_size_printer_info_2(printer); - + if (!alloc_buffer_size(buffer, *needed)) { free_printer_info_2(printer); return WERR_INSUFFICIENT_BUFFER; @@ -4728,6 +5095,7 @@ static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) { + extern userdom_struct current_user_info; char *cmd = lp_addprinter_cmd(); char **qlines; pstring command; @@ -4742,13 +5110,13 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) get_called_name()); /* change \ to \\ for the shell */ all_string_sub(driverlocation,"\\","\\\\",sizeof(pstring)); - + standard_sub_basic(current_user_info.smb_name, remote_machine,sizeof(remote_machine)); + slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"", cmd, printer->info_2->printername, printer->info_2->sharename, printer->info_2->portname, printer->info_2->drivername, printer->info_2->location, driverlocation, remote_machine); - /* Convert script args to unix-codepage */ DEBUG(10,("Running [%s]\n", command)); ret = smbrun(command, &fd); DEBUGADD(10,("returned [%d]\n", ret)); @@ -5039,13 +5407,10 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, int snum; NT_PRINTER_INFO_LEVEL *printer = NULL, *old_printer = NULL; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); - PRINTER_MESSAGE_INFO msg; WERROR result; DEBUG(8,("update_printer\n")); - - ZERO_STRUCT(msg); - + result = WERR_OK; if (level!=2) { @@ -5159,8 +5524,11 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, * bound to the printer, simulating what happens in the Windows arch. */ if (!strequal(printer->info_2->drivername, old_printer->info_2->drivername)){ - set_driver_init(printer, 2); - msg.flags |= PRINTER_MESSAGE_DRIVER; + if (!set_driver_init(printer, 2)) { + DEBUG(5,("update_printer: Error restoring driver initialization data for driver [%s]!\n", + printer->info_2->drivername)); + } + notify_printer_driver(snum, printer->info_2->drivername); } } @@ -5171,28 +5539,18 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, all the possible changes */ if (!strequal(printer->info_2->comment, old_printer->info_2->comment)) - msg.flags |= PRINTER_MESSAGE_COMMENT; + notify_printer_comment(snum, printer->info_2->comment); if (!strequal(printer->info_2->sharename, old_printer->info_2->sharename)) - msg.flags |= PRINTER_MESSAGE_SHARENAME; + notify_printer_sharename(snum, printer->info_2->sharename); if (!strequal(printer->info_2->portname, old_printer->info_2->portname)) - msg.flags |= PRINTER_MESSAGE_PORT; + notify_printer_port(snum, printer->info_2->portname); if (!strequal(printer->info_2->location, old_printer->info_2->location)) - msg.flags |= PRINTER_MESSAGE_LOCATION; - - ZERO_STRUCT(msg); - - msg.low = PRINTER_CHANGE_ADD_PRINTER; - fstrcpy(msg.printer_name, printer->info_2->printername); - - /* only send a notify if something changed */ - if (msg.flags) { - srv_spoolss_sendnotify(msg.printer_name, 0, PRINTER_CHANGE_ADD_PRINTER, msg.flags); - } + notify_printer_location(snum, printer->info_2->location); - done: +done: free_a_printer(&printer, 2); free_a_printer(&old_printer, 2); @@ -5310,7 +5668,7 @@ static void fill_job_info_1(JOB_INFO_1 *job_info, print_queue_struct *queue, static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, int position, int snum, - NT_PRINTER_INFO_LEVEL *ntprinter, + NT_PRINTER_INFO_LEVEL *ntprinter, DEVICEMODE *devmode) { pstring temp_name; @@ -5427,7 +5785,7 @@ static WERROR enumjobs_level2(print_queue_struct *queue, int snum, *returned = 0; goto done; } - + if (!(devmode = construct_dev_mode(snum))) { *returned = 0; result = WERR_NOMEM; @@ -5470,6 +5828,7 @@ static WERROR enumjobs_level2(print_queue_struct *queue, int snum, SAFE_FREE(info); return result; + } /**************************************************************************** @@ -5538,8 +5897,6 @@ WERROR _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u { POLICY_HND *handle = &q_u->handle; uint32 jobid = q_u->jobid; -/* uint32 level = q_u->level; - notused. */ -/* JOB_INFO *ctr = &q_u->ctr; - notused. */ uint32 command = q_u->command; struct current_user user; @@ -5597,9 +5954,7 @@ static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture *returned=0; -#define MAX_VERSION 4 - - for (version=0; versioninfo_2->printername, 0, PRINTER_CHANGE_ADD_PRINTER, 0x0); - free_a_printer(&printer,2); return WERR_OK; @@ -6462,10 +6810,12 @@ WERROR _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u, WERROR err = WERR_OK; NT_PRINTER_DRIVER_INFO_LEVEL driver; struct current_user user; - + fstring driver_name; + uint32 version; + ZERO_STRUCT(driver); - get_current_user(&user, p); + get_current_user(&user, p); if (!convert_printer_driver_info(info, &driver, level)) { err = WERR_NOMEM; @@ -6489,11 +6839,131 @@ WERROR _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u, goto done; } - done: + /* BEGIN_ADMIN_LOG */ + switch(level) { + case 3: + sys_adminlog(LOG_INFO,"Added printer driver. Print driver name: %s. Print driver OS: %s. Administrator name: %s.", + driver.info_3->name,drv_ver_to_os[driver.info_3->cversion],uidtoname(user.uid)); + fstrcpy(driver_name, driver.info_3->name); + break; + case 6: + sys_adminlog(LOG_INFO,"Added printer driver. Print driver name: %s. Print driver OS: %s. Administrator name: %s.", + driver.info_6->name,drv_ver_to_os[driver.info_6->version],uidtoname(user.uid)); + fstrcpy(driver_name, driver.info_6->name); + break; + } + /* END_ADMIN_LOG */ + + /* + * I think this is where he DrvUpgradePrinter() hook would be + * be called in a driver's interface DLL on a Windows NT 4.0/2k + * server. Right now, we just need to send ourselves a message + * to update each printer bound to this driver. --jerry + */ + + if (!srv_spoolss_drv_upgrade_printer(driver_name)) { + DEBUG(0,("_spoolss_addprinterdriver: Failed to send message about upgrading driver [%s]!\n", + driver_name)); + } + + /* + * Based on the version (e.g. driver destination dir: 0=9x,2=Nt/2k,3=2k/Xp), + * decide if the driver init data should be deleted. The rules are: + * 1) never delete init data if it is a 9x driver, they don't use it anyway + * 2) delete init data only if there is no 2k/Xp driver + * 3) always delete init data + * The generalized rule is always use init data from the highest order driver. + * It is necessary to follow the driver install by an initialization step to + * finish off this process. + */ + if (level == 3) + version = driver.info_3->cversion; + else if (level == 6) + version = driver.info_6->version; + else + version = -1; + switch (version) { + /* + * 9x printer driver - never delete init data + */ + case 0: + DEBUG(10,("_spoolss_addprinterdriver: init data not deleted for 9x driver [%s]\n", + driver_name)); + break; + + /* + * Nt or 2k (compatiblity mode) printer driver - only delete init data if + * there is no 2k/Xp driver init data for this driver name. + */ + case 2: + { + NT_PRINTER_DRIVER_INFO_LEVEL driver1; + + if (!W_ERROR_IS_OK(get_a_printer_driver(&driver1, 3, driver_name, "Windows NT x86", 3))) { + /* + * No 2k/Xp driver found, delete init data (if any) for the new Nt driver. + */ + if (!del_driver_init(driver_name)) + DEBUG(6,("_spoolss_addprinterdriver: del_driver_init(%s) Nt failed!\n", driver_name)); + } else { + /* + * a 2k/Xp driver was found, don't delete init data because Nt driver will use it. + */ + free_a_printer_driver(driver1,3); + DEBUG(10,("_spoolss_addprinterdriver: init data not deleted for Nt driver [%s]\n", + driver_name)); + } + } + break; + + /* + * 2k or Xp printer driver - always delete init data + */ + case 3: + if (!del_driver_init(driver_name)) + DEBUG(6,("_spoolss_addprinterdriver: del_driver_init(%s) 2k/Xp failed!\n", driver_name)); + break; + + default: + DEBUG(0,("_spoolss_addprinterdriver: invalid level=%d\n", level)); + break; + } + + +done: free_a_printer_driver(driver, level); return err; } +/******************************************************************** + * spoolss_addprinterdriverex + ********************************************************************/ + +WERROR _spoolss_addprinterdriverex(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVEREX *q_u, SPOOL_R_ADDPRINTERDRIVEREX *r_u) +{ + SPOOL_Q_ADDPRINTERDRIVER q_u_local; + SPOOL_R_ADDPRINTERDRIVER r_u_local; + + /* + * we only support the semantics of AddPrinterDriver() + * i.e. only copy files that are newer than existing ones + */ + + if ( q_u->copy_flags != APD_COPY_NEW_FILES ) + return WERR_ACCESS_DENIED; + + /* just pass the information off to _spoolss_addprinterdriver() */ + ZERO_STRUCT(q_u_local); + ZERO_STRUCT(r_u_local); + + q_u_local.server_name_ptr = q_u->server_name_ptr; + copy_unistr2(&q_u_local.server_name, &q_u->server_name); + q_u_local.level = q_u->level; + memcpy( &q_u_local.info, &q_u->info, sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL) ); + + return _spoolss_addprinterdriver( p, &q_u_local, &r_u_local ); +} + /**************************************************************************** ****************************************************************************/ @@ -6632,23 +7102,6 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S if ( (in_value_len==0) && (in_data_len==0) ) { DEBUGADD(6,("Activating NT mega-hack to find sizes\n")); -#if 0 - /* - * NT can ask for a specific parameter size - we need to return NO_MORE_ITEMS - * if this parameter size doesn't exist. - * Ok - my opinion here is that the client is not asking for the greatest - * possible size of all the parameters, but is asking specifically for the size needed - * for this specific parameter. In that case we can remove the loop below and - * simplify this lookup code considerably. JF - comments welcome. JRA. - */ - - if (!get_specific_param_by_index(*printer, 2, idx, value, &data, &type, &data_len)) { - SAFE_FREE(data); - free_a_printer(&printer, 2); - return WERR_NO_MORE_ITEMS; - } -#endif - SAFE_FREE(data); param_index=0; @@ -6692,7 +7145,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S if((*out_value=(uint16 *)talloc_zero(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL) return WERR_NOMEM; - *out_value_len = rpcstr_push((char *)*out_value, "", in_value_len, 0); + *out_value_len = (uint32)rpcstr_push((char *)*out_value, "", in_value_len, 0); /* the data is counted in bytes */ *out_max_data_len = in_data_len; @@ -6720,7 +7173,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S return WERR_NOMEM; } - *out_value_len = rpcstr_push((char *)*out_value,value, in_value_len, 0); + *out_value_len = (uint32)rpcstr_push((char *)*out_value,value, in_value_len, 0); *out_type=type; @@ -6747,10 +7200,8 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP POLICY_HND *handle = &q_u->handle; UNISTR2 *value = &q_u->value; uint32 type = q_u->type; -/* uint32 max_len = q_u->max_len; - notused. */ uint8 *data = q_u->data; uint32 real_len = q_u->real_len; -/* uint32 numeric_data = q_u->numeric_data; - notused. */ NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_PARAM *param = NULL, old_param; @@ -7022,8 +7473,6 @@ done: WERROR _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM *r_u) { POLICY_HND *handle = &q_u->handle; -/* UNISTR2 *uni_name = &q_u->name; - notused. */ -/* uint32 level = q_u->level; - notused. */ FORM *form = &q_u->form; nt_forms_struct tmpForm; int snum; @@ -7114,12 +7563,10 @@ static WERROR enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, ui WERROR _spoolss_enumprintprocessors(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCESSORS *q_u, SPOOL_R_ENUMPRINTPROCESSORS *r_u) { -/* UNISTR2 *name = &q_u->name; - notused. */ -/* UNISTR2 *environment = &q_u->environment; - notused. */ uint32 level = q_u->level; - NEW_BUFFER *buffer = NULL; + NEW_BUFFER *buffer = NULL; uint32 offered = q_u->offered; - uint32 *needed = &r_u->needed; + uint32 *needed = &r_u->needed; uint32 *returned = &r_u->returned; /* that's an [in out] buffer */ @@ -7183,8 +7630,6 @@ static WERROR enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered, WERROR _spoolss_enumprintprocdatatypes(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCDATATYPES *q_u, SPOOL_R_ENUMPRINTPROCDATATYPES *r_u) { -/* UNISTR2 *name = &q_u->name; - notused. */ -/* UNISTR2 *processor = &q_u->processor; - notused. */ uint32 level = q_u->level; NEW_BUFFER *buffer = NULL; uint32 offered = q_u->offered; @@ -7279,11 +7724,10 @@ static WERROR enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint WERROR _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS *q_u, SPOOL_R_ENUMPRINTMONITORS *r_u) { -/* UNISTR2 *name = &q_u->name; - notused. */ uint32 level = q_u->level; - NEW_BUFFER *buffer = NULL; + NEW_BUFFER *buffer = NULL; uint32 offered = q_u->offered; - uint32 *needed = &r_u->needed; + uint32 *needed = &r_u->needed; uint32 *returned = &r_u->returned; /* that's an [in out] buffer */ @@ -7427,7 +7871,7 @@ static WERROR getjob_level_2(print_queue_struct *queue, int count, int snum, uin free_job_info_2(info_2); /* Also frees devmode */ SAFE_FREE(info_2); free_a_printer(&ntprinter, 2); - + return ret; } @@ -7594,6 +8038,34 @@ WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, return _spoolss_setprinterdata(p, &q_u_local, &r_u_local); } + +/******************************************************************** + * spoolss_deleteprinterdataex + ********************************************************************/ + +WERROR _spoolss_deleteprinterdataex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATAEX *q_u, SPOOL_R_DELETEPRINTERDATAEX *r_u) +{ + SPOOL_Q_DELETEPRINTERDATA q_u_local; + SPOOL_R_DELETEPRINTERDATA r_u_local; + fstring key; + + /* From MSDN documentation of SetPrinterDataEx: pass request to + SetPrinterData if key is "PrinterDriverData" */ + + unistr2_to_ascii(key, &q_u->keyname, sizeof(key) - 1); + + if (strcmp(key, "PrinterDriverData") != 0) + return WERR_INVALID_PARAM; + + memcpy(&q_u_local.handle, &q_u->handle, sizeof(POLICY_HND)); + copy_unistr2(&q_u_local.valuename, &q_u->valuename); + + return _spoolss_deleteprinterdata( p, &q_u_local, &r_u_local ); +} + + + + /******************************************************************** * spoolss_enumprinterkey ********************************************************************/ @@ -7660,6 +8132,34 @@ WERROR _spoolss_enumprinterkey(pipes_struct *p, SPOOL_Q_ENUMPRINTERKEY *q_u, SPO return WERR_BADFILE; } +/******************************************************************** + * spoolss_deleteprinterkey + ********************************************************************/ + +WERROR _spoolss_deleteprinterkey(pipes_struct *p, SPOOL_Q_DELETEPRINTERKEY *q_u, SPOOL_R_DELETEPRINTERKEY *r_u) +{ + Printer_entry *Printer = find_printer_index_by_hnd(p, &q_u->handle); + fstring key; + + if (!Printer) { + DEBUG(2,("_spoolss_deleteprinterkey: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(&q_u->handle))); + return WERR_BADFID; + } + + unistr2_to_ascii(key, &q_u->keyname, sizeof(key) - 1); + + if (strcmp(key, "PrinterDriverData") != 0) + return WERR_INVALID_PARAM; + + /* + * this is what 2k returns when you try to delete the "PrinterDriverData" + * key + */ + + return WERR_ACCESS_DENIED; +} + + /******************************************************************** * spoolss_enumprinterdataex ********************************************************************/ @@ -7801,7 +8301,7 @@ static WERROR getprintprocessordirectory_level_1(UNISTR2 *name, unistr2_to_ascii(long_archi, environment, sizeof(long_archi)-1); - if (get_short_archi(short_archi, long_archi)==FALSE) + if (get_short_archi(short_archi, long_archi)==False) return WERR_INVALID_ENVIRONMENT; if((info=(PRINTPROCESSOR_DIRECTORY_1 *)malloc(sizeof(PRINTPROCESSOR_DIRECTORY_1))) == NULL) @@ -7834,6 +8334,7 @@ WERROR _spoolss_getprintprocessordirectory(pipes_struct *p, SPOOL_Q_GETPRINTPROC NEW_BUFFER *buffer = NULL; uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; + WERROR result; /* that's an [in out] buffer */ spoolss_move_buffer(q_u->buffer, &r_u->buffer); @@ -7845,12 +8346,13 @@ WERROR _spoolss_getprintprocessordirectory(pipes_struct *p, SPOOL_Q_GETPRINTPROC switch(level) { case 1: - return getprintprocessordirectory_level_1 + result = getprintprocessordirectory_level_1 (&q_u->name, &q_u->environment, buffer, offered, needed); default: - return WERR_UNKNOWN_LEVEL; + result = WERR_UNKNOWN_LEVEL; } - return WERR_ACCESS_DENIED; + return result; } + -- cgit From 8c53b214da14e7fbfeee3ccf28bddedb55592ab8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 17 Aug 2002 15:34:15 +0000 Subject: Sync 3.0 branch with HEAD (This used to be commit e01596853e3eea533baa08c33f26ded75f33fdd4) --- source3/rpc_server/srv_spoolss_nt.c | 1159 ++++++++++++++++------------------- 1 file changed, 534 insertions(+), 625 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 68c792f8b0..7aceaa548f 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -65,7 +65,7 @@ typedef struct _Printer{ struct _Printer *prev, *next; BOOL document_started; BOOL page_started; - int jobid; /* jobid in printing backend */ + uint32 jobid; /* jobid in printing backend */ BOOL printer_type; union { fstring handlename; @@ -101,7 +101,7 @@ typedef struct _counter_printer_0 { static ubi_dlList counter_list; -static struct cli_state cli; +static struct cli_state notify_cli; /* print notify back-channel */ static uint32 smb_connections=0; @@ -184,7 +184,7 @@ static void srv_spoolss_replycloseprinter(POLICY_HND *handle) return; } - result = cli_spoolss_reply_close_printer(&cli, cli.mem_ctx, handle); + result = cli_spoolss_reply_close_printer(¬ify_cli, notify_cli.mem_ctx, handle); if (!W_ERROR_IS_OK(result)) DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed [%s].\n", @@ -192,9 +192,9 @@ static void srv_spoolss_replycloseprinter(POLICY_HND *handle) /* if it's the last connection, deconnect the IPC$ share */ if (smb_connections==1) { - cli_nt_session_close(&cli); - cli_ulogoff(&cli); - cli_shutdown(&cli); + cli_nt_session_close(¬ify_cli); + cli_ulogoff(¬ify_cli); + cli_shutdown(¬ify_cli); message_deregister(MSG_PRINTER_NOTIFY2); } @@ -668,21 +668,21 @@ struct notify2_message_table { }; static struct notify2_message_table printer_notify_table[] = { - /* 0x00 */ { "PRINTER_NOTIFY_SERVER_NAME", NULL }, - /* 0x01 */ { "PRINTER_NOTIFY_PRINTER_NAME", NULL }, - /* 0x02 */ { "PRINTER_NOTIFY_SHARE_NAME", NULL }, - /* 0x03 */ { "PRINTER_NOTIFY_PORT_NAME", NULL }, - /* 0x04 */ { "PRINTER_NOTIFY_DRIVER_NAME", NULL }, - /* 0x05 */ { "PRINTER_NOTIFY_COMMENT", NULL }, - /* 0x06 */ { "PRINTER_NOTIFY_LOCATION", NULL }, + /* 0x00 */ { "PRINTER_NOTIFY_SERVER_NAME", notify_string }, + /* 0x01 */ { "PRINTER_NOTIFY_PRINTER_NAME", notify_string }, + /* 0x02 */ { "PRINTER_NOTIFY_SHARE_NAME", notify_string }, + /* 0x03 */ { "PRINTER_NOTIFY_PORT_NAME", notify_string }, + /* 0x04 */ { "PRINTER_NOTIFY_DRIVER_NAME", notify_string }, + /* 0x05 */ { "PRINTER_NOTIFY_COMMENT", notify_string }, + /* 0x06 */ { "PRINTER_NOTIFY_LOCATION", notify_string }, /* 0x07 */ { "PRINTER_NOTIFY_DEVMODE", NULL }, - /* 0x08 */ { "PRINTER_NOTIFY_SEPFILE", NULL }, - /* 0x09 */ { "PRINTER_NOTIFY_PRINT_PROCESSOR", NULL }, + /* 0x08 */ { "PRINTER_NOTIFY_SEPFILE", notify_string }, + /* 0x09 */ { "PRINTER_NOTIFY_PRINT_PROCESSOR", notify_string }, /* 0x0a */ { "PRINTER_NOTIFY_PARAMETERS", NULL }, - /* 0x0b */ { "PRINTER_NOTIFY_DATATYPE", NULL }, + /* 0x0b */ { "PRINTER_NOTIFY_DATATYPE", notify_string }, /* 0x0c */ { "PRINTER_NOTIFY_SECURITY_DESCRIPTOR", NULL }, - /* 0x0d */ { "PRINTER_NOTIFY_ATTRIBUTES", NULL }, - /* 0x0e */ { "PRINTER_NOTIFY_PRIORITY", NULL }, + /* 0x0d */ { "PRINTER_NOTIFY_ATTRIBUTES", notify_one_value }, + /* 0x0e */ { "PRINTER_NOTIFY_PRIORITY", notify_one_value }, /* 0x0f */ { "PRINTER_NOTIFY_DEFAULT_PRIORITY", NULL }, /* 0x10 */ { "PRINTER_NOTIFY_START_TIME", NULL }, /* 0x11 */ { "PRINTER_NOTIFY_UNTIL_TIME", NULL }, @@ -726,6 +726,8 @@ static void process_notify2_message(struct spoolss_notify_msg *msg, { Printer_entry *p; + DEBUG(8,("process_notify2_message: Enter...[%s]\n", msg->printer)); + for (p = printers_list; p; p = p->next) { SPOOL_NOTIFY_INFO_DATA *data; uint32 data_len = 1; @@ -736,28 +738,52 @@ static void process_notify2_message(struct spoolss_notify_msg *msg, if (!p->notify.client_connected) continue; + DEBUG(10,("Client connected! [%s]\n", p->dev.handlename)); + /* For this printer? Print servers always receive notifications. */ - if (p->printer_type == PRINTER_HANDLE_IS_PRINTER && - !strequal(msg->printer, p->dev.handlename)) + if ( ( p->printer_type == PRINTER_HANDLE_IS_PRINTER ) && + ( !strequal(msg->printer, p->dev.handlename) ) ) continue; + DEBUG(10,("Our printer\n")); + /* Are we monitoring this event? */ if (!is_monitoring_event(p, msg->type, msg->field)) continue; + DEBUG(10,("process_notify2_message: Sending message type [%x] field [%x] for printer [%s]\n", + msg->type, msg->field, p->dev.handlename)); + /* OK - send the event to the client */ data = talloc(mem_ctx, sizeof(SPOOL_NOTIFY_INFO_DATA)); ZERO_STRUCTP(data); - /* Convert unix jobid to smb jobid */ + /* + * if the is a printer notification handle and not a job notification + * type, then set the id to 0. Other wise just use what was specified + * in the message. + * + * When registering change notification on a print server handle + * we always need to send back the id (snum) matching the printer + * for which the change took place. For change notify registered + * on a printer handle, this does not matter and the id should be 0. + * + * --jerry + */ + if ( ( p->printer_type == PRINTER_HANDLE_IS_PRINTER ) && ( msg->type == PRINTER_NOTIFY_TYPE ) ) + id = 0; + else id = msg->id; + + /* Convert unix jobid to smb jobid */ + if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) { id = sysjob_to_jobid(msg->id); @@ -772,51 +798,31 @@ static void process_notify2_message(struct spoolss_notify_msg *msg, switch(msg->type) { case PRINTER_NOTIFY_TYPE: - if (printer_notify_table[msg->field].fn) - printer_notify_table[msg->field].fn( - msg, data, mem_ctx); - else + if ( !printer_notify_table[msg->field].fn ) goto done; + + printer_notify_table[msg->field].fn(msg, data, mem_ctx); + break; + case JOB_NOTIFY_TYPE: - if (job_notify_table[msg->field].fn) - job_notify_table[msg->field].fn( - msg, data, mem_ctx); - else + if ( !job_notify_table[msg->field].fn ) goto done; - break; - default: - DEBUG(5, ("Unknown notification type %d\n", - msg->type)); - goto done; - } - if (!p->notify.flags) - cli_spoolss_rrpcn( - &cli, mem_ctx, &p->notify.client_hnd, - data_len, data, p->notify.change, 0); - else { - NT_PRINTER_INFO_LEVEL *printer = NULL; + job_notify_table[msg->field].fn(msg, data, mem_ctx); - get_a_printer(&printer, 2, msg->printer); + break; - if (!printer) { - DEBUG(5, ("unable to load info2 for %s\n", - msg->printer)); + default: + DEBUG(5, ("Unknown notification type %d\n", msg->type)); goto done; } - /* XXX: This needs to be updated for - PRINTER_CHANGE_SET_PRINTER_DRIVER. */ - - cli_spoolss_routerreplyprinter( - &cli, mem_ctx, &p->notify.client_hnd, - 0, printer->info_2->changeid); - - free_a_printer(&printer, 2); - } + cli_spoolss_rrpcn( ¬ify_cli, mem_ctx, &p->notify.client_hnd, + data_len, data, p->notify.change, 0 ); } done: + DEBUG(8,("process_notify2_message: Exit...\n")); return; } @@ -867,30 +873,6 @@ static void receive_notify2_message(int msg_type, pid_t src, void *buf, talloc_destroy(mem_ctx); } -/*************************************************************************** - Server wrapper for cli_spoolss_routerreplyprinter() since the client - function can only send a single change notification at a time. - - FIXME!!! only handles one change currently (PRINTER_CHANGE_SET_PRINTER_DRIVER) - --jerry - **************************************************************************/ - -static WERROR srv_spoolss_routerreplyprinter (struct cli_state *reply_cli, TALLOC_CTX *mem_ctx, - POLICY_HND *pol, PRINTER_MESSAGE_INFO *info, - NT_PRINTER_INFO_LEVEL *printer) -{ - WERROR result; - uint32 condition = 0x0; - - if (info->flags & PRINTER_MESSAGE_DRIVER) - condition = PRINTER_CHANGE_SET_PRINTER_DRIVER; - - result = cli_spoolss_routerreplyprinter(reply_cli, mem_ctx, pol, condition, - printer->info_2->changeid); - - return result; -} - /******************************************************************** Send a message to ourself about new driver being installed so we can upgrade the information for each printer bound to this @@ -961,6 +943,80 @@ void do_drv_upgrade_printer(int msg_type, pid_t src, void *buf, size_t len) /* all done */ } +/******************************************************************** + Send a message to ourself about new driver being installed + so we can upgrade the information for each printer bound to this + driver + ********************************************************************/ + +static BOOL srv_spoolss_reset_printerdata(char* drivername) +{ + int len = strlen(drivername); + + if (!len) + return False; + + DEBUG(10,("srv_spoolss_reset_printerdata: Sending message about resetting printerdata [%s]\n", + drivername)); + + message_send_pid(sys_getpid(), MSG_PRINTERDATA_INIT_RESET, drivername, len+1, False); + + return True; +} + +/********************************************************************** + callback to receive a MSG_PRINTERDATA_INIT_RESET message and interate + over all printers, resetting printer data as neessary + **********************************************************************/ + +void reset_all_printerdata(int msg_type, pid_t src, void *buf, size_t len) +{ + fstring drivername; + int snum; + int n_services = lp_numservices(); + + len = MIN( len, sizeof(drivername)-1 ); + strncpy( drivername, buf, len ); + + DEBUG(10,("reset_all_printerdata: Got message for new driver [%s]\n", drivername )); + + /* Iterate the printer list */ + + for ( snum=0; snuminfo_2 && !strcmp(drivername, printer->info_2->drivername) ) + { + DEBUG(6,("reset_all_printerdata: Updating printer [%s]\n", printer->info_2->printername)); + + if ( !set_driver_init(printer, 2) ) { + DEBUG(5,("reset_all_printerdata: Error resetting printer data for printer [%s], driver [%s]!\n", + printer->info_2->printername, printer->info_2->drivername)); + } + } + + free_a_printer( &printer, 2 ); + } + } + + /* all done */ + + return; +} + /******************************************************************** Copy routines used by convert_to_openprinterex() *******************************************************************/ @@ -1094,8 +1150,6 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, { UNISTR2 *printername = NULL; PRINTER_DEFAULT *printer_default = &q_u->printer_default; -/* uint32 user_switch = q_u->user_switch; - notused */ -/* SPOOL_USER_CTR user_ctr = q_u->user_ctr; - notused */ POLICY_HND *handle = &r_u->handle; fstring name; @@ -1443,14 +1497,18 @@ BOOL convert_devicemode(char *printername, const DEVICEMODE *devmode, static WERROR _spoolss_enddocprinter_internal(pipes_struct *p, POLICY_HND *handle) { Printer_entry *Printer=find_printer_index_by_hnd(p, handle); - + int snum; + if (!Printer) { DEBUG(2,("_spoolss_enddocprinter_internal: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle))); return WERR_BADFID; } + if (!get_printer_snum(p, handle, &snum)) + return WERR_BADFID; + Printer->document_started=False; - print_job_end(Printer->jobid,True); + print_job_end(snum, Printer->jobid,True); /* error codes unhandled so far ... */ return WERR_OK; @@ -1740,51 +1798,56 @@ static BOOL getprinterdata_printer(pipes_struct *p, TALLOC_CTX *ctx, POLICY_HND uint8 **data, uint32 *needed, uint32 in_size ) { NT_PRINTER_INFO_LEVEL *printer = NULL; - int snum=0; - uint8 *idata=NULL; - uint32 len; - Printer_entry *Printer = find_printer_index_by_hnd(p, handle); + int snum=0; + Printer_entry *Printer = find_printer_index_by_hnd(p, handle); + REGISTRY_VALUE *val; + int size = 0; DEBUG(5,("getprinterdata_printer\n")); - if (!Printer) { + if ( !Printer ) { DEBUG(2,("getprinterdata_printer: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); return False; } - if(!get_printer_snum(p, handle, &snum)) + if ( !get_printer_snum(p, handle, &snum) ) return False; - if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, lp_servicename(snum)))) + if ( !W_ERROR_IS_OK(get_a_printer(&printer, 2, lp_servicename(snum))) ) return False; - if (!get_specific_param(*printer, 2, value, &idata, type, &len)) { + if ( !(val = get_printer_data( printer->info_2, SPOOL_PRINTERDATA_KEY, value)) ) + { free_a_printer(&printer, 2); return False; } + + *type = regval_type( val ); - free_a_printer(&printer, 2); DEBUG(5,("getprinterdata_printer:allocating %d\n", in_size)); - if (in_size) { - if((*data = (uint8 *)talloc(ctx, in_size *sizeof(uint8) )) == NULL) { + if (in_size) + { + if ( (*data = (uint8 *)talloc(ctx, in_size * sizeof(uint8))) == NULL ) return False; - } - memset(*data, 0, in_size *sizeof(uint8)); + memset( *data, 0, in_size *sizeof(uint8) ); + /* copy the min(in_size, len) */ - memcpy(*data, idata, (len>in_size)?in_size:len *sizeof(uint8)); - } else { - *data = NULL; + + size = regval_size( val ); + memcpy( *data, regval_data_p(val), (size > in_size) ? in_size : size*sizeof(uint8) ); } + else + *data = NULL; - *needed = len; + *needed = size; DEBUG(5,("getprinterdata_printer:copy done\n")); - SAFE_FREE(idata); + free_a_printer(&printer, 2); return True; } @@ -1813,11 +1876,12 @@ WERROR _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO * JFM, 4/19/1999 */ - *out_size=in_size; + *out_size = in_size; /* in case of problem, return some default values */ - *needed=0; - *type=0; + + *needed = 0; + *type = 0; DEBUG(4,("_spoolss_getprinterdata\n")); @@ -1831,13 +1895,16 @@ WERROR _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO unistr2_to_ascii(value, valuename, sizeof(value)-1); if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) - found=getprinterdata_printer_server(p->mem_ctx, value, type, data, needed, *out_size); + found = getprinterdata_printer_server(p->mem_ctx, value, type, data, needed, *out_size); else - found= getprinterdata_printer(p, p->mem_ctx, handle, value, type, data, needed, *out_size); + found = getprinterdata_printer(p, p->mem_ctx, handle, value, type, data, needed, *out_size); - if (found==False) { + if ( !found ) + { DEBUG(5, ("value not found, allocating %d\n", *out_size)); + /* reply this param doesn't exist */ + if (*out_size) { if((*data=(uint8 *)talloc_zero(p->mem_ctx, *out_size*sizeof(uint8))) == NULL) return WERR_NOMEM; @@ -1966,7 +2033,7 @@ static BOOL srv_spoolss_replyopenprinter(char *printer, uint32 localprinter, uin fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */ - if(!spoolss_connect_to_client(&cli, unix_printer)) + if(!spoolss_connect_to_client(¬ify_cli, unix_printer)) return False; message_register(MSG_PRINTER_NOTIFY2, receive_notify2_message); @@ -1974,7 +2041,7 @@ static BOOL srv_spoolss_replyopenprinter(char *printer, uint32 localprinter, uin smb_connections++; - result = cli_spoolss_reply_open_printer(&cli, cli.mem_ctx, printer, localprinter, + result = cli_spoolss_reply_open_printer(¬ify_cli, notify_cli.mem_ctx, printer, localprinter, type, handle); if (!W_ERROR_IS_OK(result)) @@ -2749,7 +2816,7 @@ struct s_notify_info_data_table notify_info_data_table[] = { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINT_PROCESSOR, "PRINTER_NOTIFY_PRINT_PROCESSOR", NOTIFY_STRING, spoolss_notify_print_processor }, { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PARAMETERS, "PRINTER_NOTIFY_PARAMETERS", NOTIFY_STRING, spoolss_notify_parameters }, { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DATATYPE, "PRINTER_NOTIFY_DATATYPE", NOTIFY_STRING, spoolss_notify_datatype }, -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_SECURITY_DESCRIPTOR", NOTIFY_POINTER, spoolss_notify_security_desc }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_SECURITY_DESCRIPTOR", NOTIFY_SECDESC, spoolss_notify_security_desc }, { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_ATTRIBUTES, "PRINTER_NOTIFY_ATTRIBUTES", NOTIFY_ONE_VALUE, spoolss_notify_attributes }, { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRIORITY, "PRINTER_NOTIFY_PRIORITY", NOTIFY_ONE_VALUE, spoolss_notify_priority }, { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DEFAULT_PRIORITY, "PRINTER_NOTIFY_DEFAULT_PRIORITY", NOTIFY_ONE_VALUE, spoolss_notify_default_priority }, @@ -2796,10 +2863,13 @@ static uint32 size_of_notify_info_data(uint16 type, uint16 field) { int i=0; - for (i = 0; i < sizeof(notify_info_data_table); i++) { - if (notify_info_data_table[i].type == type && - notify_info_data_table[i].field == field) { - switch(notify_info_data_table[i].size) { + for (i = 0; i < sizeof(notify_info_data_table); i++) + { + if ( (notify_info_data_table[i].type == type) + && (notify_info_data_table[i].field == field) ) + { + switch(notify_info_data_table[i].size) + { case NOTIFY_ONE_VALUE: case NOTIFY_TWO_VALUE: return 1; @@ -2812,6 +2882,9 @@ static uint32 size_of_notify_info_data(uint16 type, uint16 field) case NOTIFY_POINTER: return 4; + + case NOTIFY_SECDESC: + return 5; } } } @@ -2866,13 +2939,11 @@ void construct_info_data(SPOOL_NOTIFY_INFO_DATA *info_data, uint16 type, uint16 info_data->field = field; info_data->reserved = 0; - if (type == JOB_NOTIFY_TYPE) - info_data->id = id; - else - info_data->id = 0; - info_data->size = size_of_notify_info_data(type, field); info_data->enc_type = type_of_notify_info_data(type, field); + + info_data->id = id; + } @@ -2904,20 +2975,24 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, lp_servicename(snum)))) return False; - for(field_num=0; field_numcount; field_num++) { + for(field_num=0; field_numcount; field_num++) + { field = option_type->fields[field_num]; + DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field)); if (!search_notify(type, field, &j) ) continue; - if((tid=(SPOOL_NOTIFY_INFO_DATA *)Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) { + if((tid=(SPOOL_NOTIFY_INFO_DATA *)Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) + { DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n")); return False; } - else info->data = tid; + else + info->data = tid; - current_data=&info->data[info->count]; + current_data = &info->data[info->count]; construct_info_data(current_data, type, field, id); @@ -3044,16 +3119,17 @@ static WERROR printserver_notify_info(pipes_struct *p, POLICY_HND *hnd, continue; for (snum=0; snumversion:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count)); DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n")); @@ -3063,7 +3139,7 @@ static WERROR printserver_notify_info(pipes_struct *p, POLICY_HND *hnd, i, info->data[i].type, info->data[i].field, info->data[i].reserved, info->data[i].id, info->data[i].size, info->data[i].enc_type)); } - */ +#endif return WERR_OK; } @@ -3161,7 +3237,6 @@ static WERROR printer_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY WERROR _spoolss_rfnpcnex( pipes_struct *p, SPOOL_Q_RFNPCNEX *q_u, SPOOL_R_RFNPCNEX *r_u) { POLICY_HND *handle = &q_u->handle; -/* SPOOL_NOTIFY_OPTION *option = q_u->option; - notused. */ SPOOL_NOTIFY_INFO *info = &r_u->info; Printer_entry *Printer=find_printer_index_by_hnd(p, handle); @@ -3188,8 +3263,10 @@ WERROR _spoolss_rfnpcnex( pipes_struct *p, SPOOL_Q_RFNPCNEX *q_u, SPOOL_R_RFNPCN /* We need to keep track of the change value to send back in RRPCN replies otherwise our updates are ignored. */ - if (Printer->notify.client_connected) + if (Printer->notify.client_connected) { + DEBUG(10,("_spoolss_rfnpcnex: Saving change value in request [%x]\n", q_u->change)); Printer->notify.change = q_u->change; + } /* just ignore the SPOOL_NOTIFY_OPTION */ @@ -3370,7 +3447,7 @@ static void free_dev_mode(DEVICEMODE *dev) Create a DEVMODE struct. Returns malloced memory. ****************************************************************************/ -static DEVICEMODE *construct_dev_mode(int snum) +DEVICEMODE *construct_dev_mode(int snum) { char adevice[32]; char aform[32]; @@ -4318,22 +4395,29 @@ static void init_unistr_array(uint16 **uni_array, fstring *char_array, char *ser DEBUG(6,("init_unistr_array\n")); *uni_array=NULL; - while (1) { + while (True) + { if (char_array == NULL) v = ""; else { v = char_array[i]; if (!v) v = ""; /* hack to handle null lists */ } - if (strlen(v) == 0) break; + + if ( !strlen(v) ) + break; + slprintf(line, sizeof(line)-1, "\\\\%s%s", servername, v); + DEBUGADD(6,("%d:%s:%d\n", i, line, strlen(line))); + if((tuary=Realloc(*uni_array, (j+strlen(line)+2)*sizeof(uint16))) == NULL) { DEBUG(2,("init_unistr_array: Realloc error\n" )); return; } else *uni_array = tuary; - j += (rpcstr_push((*uni_array+j), line, sizeof(uint16)*strlen(line)+2, 0)/ sizeof(uint16)); + + j += (rpcstr_push((*uni_array+j), line, sizeof(uint16)*strlen(line)+2, STR_TERMINATE) / sizeof(uint16)); i++; } @@ -4495,8 +4579,8 @@ static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_IN init_unistr( &info->monitorname, driver.info_3->monitorname ); init_unistr( &info->defaultdatatype, driver.info_3->defaultdatatype ); - info->dependentfiles=NULL; - init_unistr_array(&info->dependentfiles, driver.info_3->dependentfiles, servername); + info->dependentfiles = NULL; + init_unistr_array( &info->dependentfiles, driver.info_3->dependentfiles, servername ); info->previousdrivernames=NULL; init_unistr_array(&info->previousdrivernames, &nullstr, servername); @@ -4519,21 +4603,28 @@ static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_IN * fill a printer_info_6 struct ********************************************************************/ -static WERROR construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, fstring servername, fstring architecture, uint32 version) +static WERROR construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, + fstring servername, fstring architecture, uint32 version) { - NT_PRINTER_INFO_LEVEL *printer = NULL; - NT_PRINTER_DRIVER_INFO_LEVEL driver; - WERROR status; + NT_PRINTER_INFO_LEVEL *printer = NULL; + NT_PRINTER_DRIVER_INFO_LEVEL driver; + WERROR status; + ZERO_STRUCT(driver); status=get_a_printer(&printer, 2, lp_servicename(snum) ); + DEBUG(8,("construct_printer_driver_info_6: status: %s\n", dos_errstr(status))); + if (!W_ERROR_IS_OK(status)) return WERR_INVALID_PRINTER_NAME; - status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version); + status = get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version); + DEBUG(8,("construct_printer_driver_info_6: status: %s\n", dos_errstr(status))); - if (!W_ERROR_IS_OK(status)) { + + if (!W_ERROR_IS_OK(status)) + { /* * Is this a W2k client ? */ @@ -4728,7 +4819,6 @@ WERROR _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_ UNISTR2 *uni_arch = &q_u->architecture; uint32 level = q_u->level; uint32 clientmajorversion = q_u->clientmajorversion; -/* uint32 clientminorversion = q_u->clientminorversion; - notused. */ NEW_BUFFER *buffer = NULL; uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; @@ -4745,9 +4835,9 @@ WERROR _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_ DEBUG(4,("_spoolss_getprinterdriver2\n")); - *needed=0; - *servermajorversion=0; - *serverminorversion=0; + *needed = 0; + *servermajorversion = 0; + *serverminorversion = 0; pstrcpy(servername, get_called_name()); unistr2_to_ascii(architecture, uni_arch, sizeof(architecture)-1); @@ -4793,6 +4883,7 @@ WERROR _spoolss_startpageprinter(pipes_struct *p, SPOOL_Q_STARTPAGEPRINTER *q_u, WERROR _spoolss_endpageprinter(pipes_struct *p, SPOOL_Q_ENDPAGEPRINTER *q_u, SPOOL_R_ENDPAGEPRINTER *r_u) { POLICY_HND *handle = &q_u->handle; + int snum; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); @@ -4801,8 +4892,11 @@ WERROR _spoolss_endpageprinter(pipes_struct *p, SPOOL_Q_ENDPAGEPRINTER *q_u, SPO return WERR_BADFID; } + if (!get_printer_snum(p, handle, &snum)) + return WERR_BADFID; + Printer->page_started=False; - print_job_endpage(Printer->jobid); + print_job_endpage(snum, Printer->jobid); return WERR_OK; } @@ -4816,7 +4910,6 @@ WERROR _spoolss_endpageprinter(pipes_struct *p, SPOOL_Q_ENDPAGEPRINTER *q_u, SPO WERROR _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, SPOOL_R_STARTDOCPRINTER *r_u) { POLICY_HND *handle = &q_u->handle; -/* uint32 level = q_u->doc_info_container.level; - notused. */ DOC_INFO *docinfo = &q_u->doc_info_container.docinfo; uint32 *jobid = &r_u->jobid; @@ -4898,7 +4991,7 @@ WERROR _spoolss_writeprinter(pipes_struct *p, SPOOL_Q_WRITEPRINTER *q_u, SPOOL_R uint32 buffer_size = q_u->buffer_size; uint8 *buffer = q_u->buffer; uint32 *buffer_written = &q_u->buffer_size2; - + int snum; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); if (!Printer) { @@ -4907,8 +5000,10 @@ WERROR _spoolss_writeprinter(pipes_struct *p, SPOOL_Q_WRITEPRINTER *q_u, SPOOL_R return WERR_BADFID; } - (*buffer_written) = print_job_write(Printer->jobid, (char *)buffer, buffer_size); + if (!get_printer_snum(p, handle, &snum)) + return WERR_BADFID; + (*buffer_written) = print_job_write(snum, Printer->jobid, (char *)buffer, buffer_size); r_u->buffer_written = q_u->buffer_size2; @@ -5147,254 +5242,6 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) return True; } -#if 0 /* JERRY */ - -/* Return true if two devicemodes are equal */ - -#define DEVMODE_CHECK_INT(field) \ - if (d1->field != d2->field) { \ - DEBUG(10, ("nt_devicemode_equal(): " #field " not equal (%d != %d)\n", \ - d1->field, d2->field)); \ - return False; \ - } - -/************************************************************************ - Handy, but currently unused functions - ***********************************************************************/ - -static BOOL nt_devicemode_equal(NT_DEVICEMODE *d1, NT_DEVICEMODE *d2) -{ - if (!d1 && !d2) goto equal; /* if both are NULL they are equal */ - - if (!d1 ^ !d2) { - DEBUG(10, ("nt_devicemode_equal(): pointers not equal\n")); - return False; /* if either is exclusively NULL are not equal */ - } - - if (!strequal(d1->devicename, d2->devicename)) { - DEBUG(10, ("nt_devicemode_equal(): device not equal (%s != %s)\n", d1->devicename, d2->devicename)); - return False; - } - - if (!strequal(d1->formname, d2->formname)) { - DEBUG(10, ("nt_devicemode_equal(): formname not equal (%s != %s)\n", d1->formname, d2->formname)); - return False; - } - - DEVMODE_CHECK_INT(specversion); - DEVMODE_CHECK_INT(driverversion); - DEVMODE_CHECK_INT(driverextra); - DEVMODE_CHECK_INT(orientation); - DEVMODE_CHECK_INT(papersize); - DEVMODE_CHECK_INT(paperlength); - DEVMODE_CHECK_INT(paperwidth); - DEVMODE_CHECK_INT(scale); - DEVMODE_CHECK_INT(copies); - DEVMODE_CHECK_INT(defaultsource); - DEVMODE_CHECK_INT(printquality); - DEVMODE_CHECK_INT(color); - DEVMODE_CHECK_INT(duplex); - DEVMODE_CHECK_INT(yresolution); - DEVMODE_CHECK_INT(ttoption); - DEVMODE_CHECK_INT(collate); - DEVMODE_CHECK_INT(logpixels); - - DEVMODE_CHECK_INT(fields); - DEVMODE_CHECK_INT(bitsperpel); - DEVMODE_CHECK_INT(pelswidth); - DEVMODE_CHECK_INT(pelsheight); - DEVMODE_CHECK_INT(displayflags); - DEVMODE_CHECK_INT(displayfrequency); - DEVMODE_CHECK_INT(icmmethod); - DEVMODE_CHECK_INT(icmintent); - DEVMODE_CHECK_INT(mediatype); - DEVMODE_CHECK_INT(dithertype); - DEVMODE_CHECK_INT(reserved1); - DEVMODE_CHECK_INT(reserved2); - DEVMODE_CHECK_INT(panningwidth); - DEVMODE_CHECK_INT(panningheight); - - /* compare the private data if it exists */ - if (!d1->driverextra && !d2->driverextra) goto equal; - - - DEVMODE_CHECK_INT(driverextra); - - if (memcmp(d1->private, d2->private, d1->driverextra)) { - DEBUG(10, ("nt_devicemode_equal(): private data not equal\n")); - return False; - } - - equal: - DEBUG(10, ("nt_devicemode_equal(): devicemodes identical\n")); - return True; -} - -/* Return true if two NT_PRINTER_PARAM structures are equal */ - -static BOOL nt_printer_param_equal(NT_PRINTER_PARAM *p1, - NT_PRINTER_PARAM *p2) -{ - if (!p1 && !p2) goto equal; - - if ((!p1 && p2) || (p1 && !p2)) { - DEBUG(10, ("nt_printer_param_equal(): pointers differ\n")); - return False; - } - - /* Compare lists of printer parameters */ - - while (p1) { - BOOL found = False; - NT_PRINTER_PARAM *q = p1; - - /* Find the parameter in the second structure */ - - while(q) { - - if (strequal(p1->value, q->value)) { - - if (p1->type != q->type) { - DEBUG(10, ("nt_printer_param_equal():" - "types for %s differ (%d != %d)\n", - p1->value, p1->type, - q->type)); - break; - } - - if (p1->data_len != q->data_len) { - DEBUG(10, ("nt_printer_param_equal():" - "len for %s differs (%d != %d)\n", - p1->value, p1->data_len, - q->data_len)); - break; - } - - if (memcmp(p1->data, q->data, p1->data_len) == 0) { - found = True; - } else { - DEBUG(10, ("nt_printer_param_equal():" - "data for %s differs\n", p1->value)); - } - - break; - } - - q = q->next; - } - - if (!found) { - DEBUG(10, ("nt_printer_param_equal(): param %s " - "does not exist\n", p1->value)); - return False; - } - - p1 = p1->next; - } - - equal: - - DEBUG(10, ("nt_printer_param_equal(): printer params identical\n")); - return True; -} - -/******************************************************************** - * Called by update_printer when trying to work out whether to - * actually update printer info. - ********************************************************************/ - -#define PI_CHECK_INT(field) \ - if (pi1->field != pi2->field) { \ - DEBUG(10, ("nt_printer_info_level_equal(): " #field " not equal (%d != %d)\n", \ - pi1->field, pi2->field)); \ - return False; \ - } - -#define PI_CHECK_STR(field) \ - if (!strequal(pi1->field, pi2->field)) { \ - DEBUG(10, ("nt_printer_info_level_equal(): " #field " not equal (%s != %s)\n", \ - pi1->field, pi2->field)); \ - return False; \ - } - -static BOOL nt_printer_info_level_equal(NT_PRINTER_INFO_LEVEL *p1, - NT_PRINTER_INFO_LEVEL *p2) -{ - NT_PRINTER_INFO_LEVEL_2 *pi1, *pi2; - - /* Trivial conditions */ - - if ((!p1 && !p2) || (!p1->info_2 && !p2->info_2)) { - goto equal; - } - - if ((!p1 && p2) || (p1 && !p2) || - (!p1->info_2 && p2->info_2) || - (p1->info_2 && !p2->info_2)) { - DEBUG(10, ("nt_printer_info_level_equal(): info levels " - "differ\n")); - return False; - } - - /* Compare two nt_printer_info_level structures. Don't compare - status or cjobs as they seem to have something to do with the - printer queue. */ - - pi1 = p1->info_2; - pi2 = p2->info_2; - - /* Don't check the attributes as we stomp on the value in - check_printer_ok() anyway. */ - -#if 0 - PI_CHECK_INT(attributes); -#endif - - PI_CHECK_INT(priority); - PI_CHECK_INT(default_priority); - PI_CHECK_INT(starttime); - PI_CHECK_INT(untiltime); - PI_CHECK_INT(averageppm); - - /* Yuck - don't check the printername or servername as the - mod_a_printer() code plays games with them. You can't - change the printername or the sharename through this interface - in Samba. */ - - PI_CHECK_STR(sharename); - PI_CHECK_STR(portname); - PI_CHECK_STR(drivername); - PI_CHECK_STR(comment); - PI_CHECK_STR(location); - - if (!nt_devicemode_equal(pi1->devmode, pi2->devmode)) { - return False; - } - - PI_CHECK_STR(sepfile); - PI_CHECK_STR(printprocessor); - PI_CHECK_STR(datatype); - PI_CHECK_STR(parameters); - - if (!nt_printer_param_equal(pi1->specific, pi2->specific)) { - return False; - } - - if (!sec_desc_equal(pi1->secdesc_buf->sec, pi2->secdesc_buf->sec)) { - return False; - } - - PI_CHECK_INT(changeid); - PI_CHECK_INT(c_setprinter); - PI_CHECK_INT(setuptime); - - equal: - DEBUG(10, ("nt_printer_info_level_equal(): infos are identical\n")); - return True; -} - -#endif - /******************************************************************** * Called by spoolss_api_setprinter * when updating a printer description. @@ -5507,7 +5354,8 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, * requires Win32 client code (see other notes elsewhere in the code). */ if (printer->info_2->devmode && - printer->info_2->devmode->displayfrequency == MAGIC_DISPLAY_FREQUENCY) { + printer->info_2->devmode->displayfrequency == MAGIC_DISPLAY_FREQUENCY) + { DEBUG(10,("update_printer: Save printer driver init data\n")); printer->info_2->devmode->displayfrequency = 0; @@ -5517,17 +5365,31 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, result = WERR_ACCESS_DENIED; goto done; } - } else { + + /* we need to reset all driver init data for all printers + bound to this driver */ + + srv_spoolss_reset_printerdata( printer->info_2->drivername ); + + } + else + { /* * When a *new* driver is bound to a printer, the drivername is used to * lookup previously saved driver initialization info, which is then * bound to the printer, simulating what happens in the Windows arch. */ - if (!strequal(printer->info_2->drivername, old_printer->info_2->drivername)){ - if (!set_driver_init(printer, 2)) { + if (!strequal(printer->info_2->drivername, old_printer->info_2->drivername)) + { + if (!set_driver_init(printer, 2)) + { DEBUG(5,("update_printer: Error restoring driver initialization data for driver [%s]!\n", printer->info_2->drivername)); } + + DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n", + printer->info_2->drivername)); + notify_printer_driver(snum, printer->info_2->drivername); } } @@ -5838,8 +5700,6 @@ static WERROR enumjobs_level2(print_queue_struct *queue, int snum, WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJOBS *r_u) { POLICY_HND *handle = &q_u->handle; -/* uint32 firstjob = q_u->firstjob; - notused. */ -/* uint32 numofjobs = q_u->numofjobs; - notused. */ uint32 level = q_u->level; NEW_BUFFER *buffer = NULL; uint32 offered = q_u->offered; @@ -5907,7 +5767,7 @@ WERROR _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u return WERR_BADFID; } - if (!print_job_exists(jobid)) { + if (!print_job_exists(snum, jobid)) { return WERR_INVALID_PRINTER_NAME; } @@ -5916,18 +5776,18 @@ WERROR _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u switch (command) { case JOB_CONTROL_CANCEL: case JOB_CONTROL_DELETE: - if (print_job_delete(&user, jobid, &errcode)) { + if (print_job_delete(&user, snum, jobid, &errcode)) { errcode = WERR_OK; } break; case JOB_CONTROL_PAUSE: - if (print_job_pause(&user, jobid, &errcode)) { + if (print_job_pause(&user, snum, jobid, &errcode)) { errcode = WERR_OK; } break; case JOB_CONTROL_RESTART: case JOB_CONTROL_RESUME: - if (print_job_resume(&user, jobid, &errcode)) { + if (print_job_resume(&user, snum, jobid, &errcode)) { errcode = WERR_OK; } break; @@ -6186,7 +6046,6 @@ static WERROR enumprinterdrivers_level3(fstring servername, fstring architecture WERROR _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS *q_u, SPOOL_R_ENUMPRINTERDRIVERS *r_u) { -/* UNISTR2 *name = &q_u->name; - notused. */ UNISTR2 *environment = &q_u->environment; uint32 level = q_u->level; NEW_BUFFER *buffer = NULL; @@ -6243,7 +6102,6 @@ static void fill_form_1(FORM_1 *form, nt_forms_struct *list) WERROR _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMFORMS *r_u) { -/* POLICY_HND *handle = &q_u->handle; - notused. */ uint32 level = q_u->level; NEW_BUFFER *buffer = NULL; uint32 offered = q_u->offered; @@ -6344,7 +6202,6 @@ WERROR _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMF WERROR _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM *r_u) { -/* POLICY_HND *handle = &q_u->handle; - notused. */ uint32 level = q_u->level; UNISTR2 *uni_formname = &q_u->formname; NEW_BUFFER *buffer = NULL; @@ -6640,7 +6497,6 @@ static WERROR enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need WERROR _spoolss_enumports( pipes_struct *p, SPOOL_Q_ENUMPORTS *q_u, SPOOL_R_ENUMPORTS *r_u) { -/* UNISTR2 *name = &q_u->name; - notused. */ uint32 level = q_u->level; NEW_BUFFER *buffer = NULL; uint32 offered = q_u->offered; @@ -6804,7 +6660,6 @@ WERROR _spoolss_addprinterex( pipes_struct *p, SPOOL_Q_ADDPRINTEREX *q_u, SPOOL_ WERROR _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u, SPOOL_R_ADDPRINTERDRIVER *r_u) { -/* UNISTR2 *server_name = &q_u->server_name; - notused. */ uint32 level = q_u->level; SPOOL_PRINTER_DRIVER_INFO_LEVEL *info = &q_u->info; WERROR err = WERR_OK; @@ -6952,10 +6807,10 @@ WERROR _spoolss_addprinterdriverex(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVEREX * if ( q_u->copy_flags != APD_COPY_NEW_FILES ) return WERR_ACCESS_DENIED; - /* just pass the information off to _spoolss_addprinterdriver() */ ZERO_STRUCT(q_u_local); ZERO_STRUCT(r_u_local); + /* just pass the information off to _spoolss_addprinterdriver() */ q_u_local.server_name_ptr = q_u->server_name_ptr; copy_unistr2(&q_u_local.server_name, &q_u->server_name); q_u_local.level = q_u->level; @@ -7047,38 +6902,38 @@ WERROR _spoolss_getprinterdriverdirectory(pipes_struct *p, SPOOL_Q_GETPRINTERDRI WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, SPOOL_R_ENUMPRINTERDATA *r_u) { POLICY_HND *handle = &q_u->handle; - uint32 idx = q_u->index; - uint32 in_value_len = q_u->valuesize; - uint32 in_data_len = q_u->datasize; - uint32 *out_max_value_len = &r_u->valuesize; - uint16 **out_value = &r_u->value; - uint32 *out_value_len = &r_u->realvaluesize; - uint32 *out_type = &r_u->type; + uint32 idx = q_u->index; + uint32 in_value_len = q_u->valuesize; + uint32 in_data_len = q_u->datasize; + uint32 *out_max_value_len= &r_u->valuesize; + uint16 **out_value = &r_u->value; + uint32 *out_value_len = &r_u->realvaluesize; + uint32 *out_type = &r_u->type; uint32 *out_max_data_len = &r_u->datasize; - uint8 **data_out = &r_u->data; - uint32 *out_data_len = &r_u->realdatasize; + uint8 **data_out = &r_u->data; + uint32 *out_data_len = &r_u->realdatasize; NT_PRINTER_INFO_LEVEL *printer = NULL; - fstring value; + uint32 param_index; + uint32 biggest_valuesize; + uint32 biggest_datasize; + uint32 data_len; + Printer_entry *Printer = find_printer_index_by_hnd(p, handle); + int snum; + WERROR result; + REGISTRY_VALUE *val; + NT_PRINTER_DATA *p_data; + int i, key_index, num_values; + int name_length; - uint32 param_index; - uint32 biggest_valuesize; - uint32 biggest_datasize; - uint32 data_len; - Printer_entry *Printer = find_printer_index_by_hnd(p, handle); - int snum; - uint8 *data=NULL; - uint32 type; - WERROR result; - - ZERO_STRUCT(printer); + ZERO_STRUCT( printer ); - *out_type=0; + *out_type = 0; - *out_max_data_len=0; - *data_out=NULL; - *out_data_len=0; + *out_max_data_len = 0; + *data_out = NULL; + *out_data_len = 0; DEBUG(5,("spoolss_enumprinterdata\n")); @@ -7093,103 +6948,133 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S result = get_a_printer(&printer, 2, lp_servicename(snum)); if (!W_ERROR_IS_OK(result)) return result; + + p_data = &printer->info_2->data; + key_index = lookup_printerkey( p_data, SPOOL_PRINTERDATA_KEY ); + + result = WERR_OK; /* * The NT machine wants to know the biggest size of value and data * * cf: MSDN EnumPrinterData remark section */ - if ( (in_value_len==0) && (in_data_len==0) ) { + + if ( !in_value_len && !in_data_len ) + { DEBUGADD(6,("Activating NT mega-hack to find sizes\n")); - SAFE_FREE(data); - - param_index=0; - biggest_valuesize=0; - biggest_datasize=0; + param_index = 0; + biggest_valuesize = 0; + biggest_datasize = 0; + + num_values = regval_ctr_numvals( &p_data->keys[key_index].values ); - while (get_specific_param_by_index(*printer, 2, param_index, value, &data, &type, &data_len)) { - if (strlen(value) > biggest_valuesize) biggest_valuesize=strlen(value); - if (data_len > biggest_datasize) biggest_datasize=data_len; - - DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize, biggest_datasize)); - - SAFE_FREE(data); - param_index++; + for ( i=0; ikeys[key_index].values, i ); + + name_length = strlen(val->valuename); + if ( strlen(val->valuename) > biggest_valuesize ) + biggest_valuesize = name_length; + + if ( val->size > biggest_datasize ) + biggest_datasize = val->size; + + DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize, + biggest_datasize)); } - /* the value is an UNICODE string but realvaluesize is the length in bytes including the leading 0 */ - *out_value_len=2*(1+biggest_valuesize); - *out_data_len=biggest_datasize; + /* the value is an UNICODE string but real_value_size is the length + in bytes including the trailing 0 */ + + *out_value_len = 2 * (1+biggest_valuesize); + *out_data_len = biggest_datasize; DEBUG(6,("final values: [%d], [%d]\n", *out_value_len, *out_data_len)); - free_a_printer(&printer, 2); - return WERR_OK; + goto done; } /* * the value len is wrong in NT sp3 * that's the number of bytes not the number of unicode chars */ + + val = regval_ctr_specific_value( &p_data->keys[key_index].values, idx ); - if (!get_specific_param_by_index(*printer, 2, idx, value, &data, &type, &data_len)) { - - SAFE_FREE(data); - free_a_printer(&printer, 2); + if ( !val ) + { /* out_value should default to "" or else NT4 has problems unmarshalling the response */ - *out_max_value_len=(in_value_len/sizeof(uint16)); - if((*out_value=(uint16 *)talloc_zero(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL) - return WERR_NOMEM; + *out_max_value_len = (in_value_len/sizeof(uint16)); + + if ( (*out_value=(uint16 *)talloc_zero(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL ) + { + result = WERR_NOMEM; + goto done; + } *out_value_len = (uint32)rpcstr_push((char *)*out_value, "", in_value_len, 0); /* the data is counted in bytes */ + *out_max_data_len = in_data_len; - *out_data_len = in_data_len; - if((*data_out=(uint8 *)talloc_zero(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) - return WERR_NOMEM; + *out_data_len = in_data_len; + + /* only allocate when given a non-zero data_len */ + + if ( in_data_len && ((*data_out=(uint8 *)talloc_zero(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) ) + { + result = WERR_NOMEM; + goto done; + } - return WERR_NO_MORE_ITEMS; + result = WERR_NO_MORE_ITEMS; } - - free_a_printer(&printer, 2); - - /* - * the value is: - * - counted in bytes in the request - * - counted in UNICODE chars in the max reply - * - counted in bytes in the real size - * - * take a pause *before* coding not *during* coding - */ + else + { + /* + * the value is: + * - counted in bytes in the request + * - counted in UNICODE chars in the max reply + * - counted in bytes in the real size + * + * take a pause *before* coding not *during* coding + */ - *out_max_value_len=(in_value_len/sizeof(uint16)); - if((*out_value=(uint16 *)talloc_zero(p->mem_ctx,in_value_len*sizeof(uint8))) == NULL) { - SAFE_FREE(data); - return WERR_NOMEM; - } + /* name */ + *out_max_value_len = ( in_value_len / sizeof(uint16) ); + if ( (*out_value = (uint16 *)talloc_zero(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL ) + { + result = WERR_NOMEM; + goto done; + } - *out_value_len = (uint32)rpcstr_push((char *)*out_value,value, in_value_len, 0); + *out_value_len = (uint32)rpcstr_push((char *)*out_value, regval_name(val), in_value_len, 0); - *out_type=type; + /* type */ + + *out_type = regval_type( val ); - /* the data is counted in bytes */ - *out_max_data_len=in_data_len; - if((*data_out=(uint8 *)talloc_zero(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) { - SAFE_FREE(data); - return WERR_NOMEM; + /* data - counted in bytes */ + + *out_max_data_len = in_data_len; + if ( (*data_out = (uint8 *)talloc_zero(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) + { + result = WERR_NOMEM; + goto done; + } + data_len = (size_t)regval_size(val); + memcpy( *data_out, regval_data_p(val), data_len ); + *out_data_len = data_len; } - - memcpy(*data_out, data, (size_t)data_len); - *out_data_len=data_len; - SAFE_FREE(data); - - return WERR_OK; +done: + free_a_printer(&printer, 2); + return result; } /**************************************************************************** @@ -7197,17 +7082,17 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SPOOL_R_SETPRINTERDATA *r_u) { - POLICY_HND *handle = &q_u->handle; - UNISTR2 *value = &q_u->value; - uint32 type = q_u->type; - uint8 *data = q_u->data; - uint32 real_len = q_u->real_len; + POLICY_HND *handle = &q_u->handle; + UNISTR2 *value = &q_u->value; + uint32 type = q_u->type; + uint8 *data = q_u->data; + uint32 real_len = q_u->real_len; - NT_PRINTER_INFO_LEVEL *printer = NULL; - NT_PRINTER_PARAM *param = NULL, old_param; - int snum=0; - WERROR status = WERR_OK; - Printer_entry *Printer=find_printer_index_by_hnd(p, handle); + NT_PRINTER_INFO_LEVEL *printer = NULL; + int snum=0; + WERROR status = WERR_OK; + Printer_entry *Printer=find_printer_index_by_hnd(p, handle); + fstring valuename; DEBUG(5,("spoolss_setprinterdata\n")); @@ -7219,8 +7104,6 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP if (!get_printer_snum(p,handle, &snum)) return WERR_BADFID; - ZERO_STRUCT(old_param); - /* * Access check : NT returns "access denied" if you make a * SetPrinterData call without the necessary privildge. @@ -7235,40 +7118,22 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP goto done; } - /* Check if we are making any changes or not. Return true if - nothing is actually changing. This is not needed anymore but - has been left in as an optimization to keep from from - writing to disk as often --jerry */ - status = get_a_printer(&printer, 2, lp_servicename(snum)); if (!W_ERROR_IS_OK(status)) return status; - convert_specific_param(¶m, value , type, data, real_len); + /* save the registry data */ + + unistr2_to_ascii( valuename, value, sizeof(valuename)-1 ); + delete_printer_data( printer->info_2, SPOOL_PRINTERDATA_KEY, valuename ); + add_printer_data( printer->info_2, SPOOL_PRINTERDATA_KEY, valuename, type, data, real_len ); - unlink_specific_param_if_exist(printer->info_2, param); + /* write the **entire** printer out to disk.... :-( */ - /* - * When client side code sets a magic printer data key, detect it and save - * the current printer data and the magic key's data (its the DEVMODE) for - * future printer/driver initializations. - */ - if (param->type==3 && !strcmp( param->value, PHANTOM_DEVMODE_KEY)) { - /* - * Set devmode and printer initialization info - */ - status = save_driver_init(printer, 2, param); - } - else { - add_a_specific_param(printer->info_2, ¶m); - status = mod_a_printer(*printer, 2); - } + status = mod_a_printer(*printer, 2); - done: +done: free_a_printer(&printer, 2); - if (param) - free_nt_printer_param(¶m); - SAFE_FREE(old_param.data); return status; } @@ -7278,9 +7143,9 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP WERROR _spoolss_resetprinter(pipes_struct *p, SPOOL_Q_RESETPRINTER *q_u, SPOOL_R_RESETPRINTER *r_u) { - POLICY_HND *handle = &q_u->handle; - Printer_entry *Printer=find_printer_index_by_hnd(p, handle); - int snum; + POLICY_HND *handle = &q_u->handle; + Printer_entry *Printer=find_printer_index_by_hnd(p, handle); + int snum; DEBUG(5,("_spoolss_resetprinter\n")); @@ -7304,16 +7169,19 @@ WERROR _spoolss_resetprinter(pipes_struct *p, SPOOL_Q_RESETPRINTER *q_u, SPOOL_R } +/**************************************************************************** +****************************************************************************/ + WERROR _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_u, SPOOL_R_DELETEPRINTERDATA *r_u) { - POLICY_HND *handle = &q_u->handle; - UNISTR2 *value = &q_u->valuename; + POLICY_HND *handle = &q_u->handle; + UNISTR2 *value = &q_u->valuename; - NT_PRINTER_INFO_LEVEL *printer = NULL; - NT_PRINTER_PARAM param; - int snum=0; - WERROR status = WERR_OK; - Printer_entry *Printer=find_printer_index_by_hnd(p, handle); + NT_PRINTER_INFO_LEVEL *printer = NULL; + int snum=0; + WERROR status = WERR_OK; + Printer_entry *Printer=find_printer_index_by_hnd(p, handle); + pstring valuename; DEBUG(5,("spoolss_deleteprinterdata\n")); @@ -7334,15 +7202,14 @@ WERROR _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_ if (!W_ERROR_IS_OK(status)) return status; - ZERO_STRUCTP(¶m); - unistr2_to_ascii(param.value, value, sizeof(param.value)-1); + unistr2_to_ascii( valuename, value, sizeof(valuename)-1 ); - if(!unlink_specific_param_if_exist(printer->info_2, ¶m)) - status = WERR_INVALID_PARAM; - else + status = delete_printer_data( printer->info_2, SPOOL_PRINTERDATA_KEY, valuename ); + if ( NT_STATUS_IS_OK(status) ) status = mod_a_printer(*printer, 2); free_a_printer(&printer, 2); + return status; } @@ -7352,7 +7219,6 @@ WERROR _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_ WERROR _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM *r_u) { POLICY_HND *handle = &q_u->handle; -/* uint32 level = q_u->level; - notused. */ FORM *form = &q_u->form; nt_forms_struct tmpForm; int snum; @@ -7971,9 +7837,10 @@ WERROR _spoolss_getprinterdataex(pipes_struct *p, SPOOL_Q_GETPRINTERDATAEX *q_u, * (a) DsDriver * (b) DsSpooler * (c) PnPData + * (d) DsUser */ - if (strcmp(key, "PrinterDriverData") != 0) + if (strcmp(key, SPOOL_PRINTERDATA_KEY) != 0) return WERR_BADFILE; DEBUG(10, ("_spoolss_getprinterdataex: pass me to getprinterdata\n")); @@ -8019,7 +7886,7 @@ WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, unistr2_to_ascii(key, &q_u->key, sizeof(key) - 1); - if (strcmp(key, "PrinterDriverData") != 0) + if (strcmp(key, SPOOL_PRINTERDATA_KEY) != 0) return WERR_INVALID_PARAM; ZERO_STRUCT(q_u_local); @@ -8054,7 +7921,7 @@ WERROR _spoolss_deleteprinterdataex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATAEX unistr2_to_ascii(key, &q_u->keyname, sizeof(key) - 1); - if (strcmp(key, "PrinterDriverData") != 0) + if (strcmp(key, SPOOL_PRINTERDATA_KEY) != 0) return WERR_INVALID_PARAM; memcpy(&q_u_local.handle, &q_u->handle, sizeof(POLICY_HND)); @@ -8070,57 +7937,66 @@ WERROR _spoolss_deleteprinterdataex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATAEX * spoolss_enumprinterkey ********************************************************************/ -/* constants for EnumPrinterKey() */ -#define ENUMERATED_KEY_SIZE 19 WERROR _spoolss_enumprinterkey(pipes_struct *p, SPOOL_Q_ENUMPRINTERKEY *q_u, SPOOL_R_ENUMPRINTERKEY *r_u) { fstring key; - uint16 enumkeys[ENUMERATED_KEY_SIZE+1]; + uint16 *enumkeys = NULL; char* ptr = NULL; int i; - char *PrinterKey = "PrinterDriverData"; + int printerkey_len = strlen(SPOOL_PRINTERDATA_KEY)+1; DEBUG(4,("_spoolss_enumprinterkey\n")); - unistr2_to_ascii(key, &q_u->key, sizeof(key) - 1); + unistr2_to_ascii( key, &q_u->key, sizeof(key)-1 ); /* * we only support enumating all keys (key == "") * Of course, the only key we support is the "PrinterDriverData" * key - */ - if (strlen(key) == 0) + */ + + if ( !strlen( key ) ) { - r_u->needed = ENUMERATED_KEY_SIZE *2; - if (q_u->size < r_u->needed) + r_u->needed = printerkey_len*2; + + if ( q_u->size < r_u->needed ) return WERR_MORE_DATA; - ptr = PrinterKey; - for (i=0; imem_ctx, printerkey_len*2 )) ) { + DEBUG(0,("_spoolss_enumprinterkey: talloc() failed for [%d] bytes!\n", + printerkey_len)); + return WERR_NOMEM; + } + + ptr = SPOOL_PRINTERDATA_KEY; + for ( i=0; i<(printerkey_len-1); i++ ) { enumkeys[i] = (uint16)(*ptr); ptr++; } - /* tag of with 2 '\0's */ - enumkeys[i++] = '\0'; - enumkeys[i] = '\0'; + /* tag of '\0's */ + + enumkeys[i] = 0x0; - if (!make_spoolss_buffer5(p->mem_ctx, &r_u->keys, ENUMERATED_KEY_SIZE, enumkeys)) + if (!make_spoolss_buffer5(p->mem_ctx, &r_u->keys, printerkey_len, enumkeys)) return WERR_BADFILE; return WERR_OK; } /* The "PrinterDriverData" key should have no subkeys */ - if (strcmp(key, PrinterKey) == 0) + if ( strcmp(key, SPOOL_PRINTERDATA_KEY) == 0 ) { - r_u-> needed = 2; + uint16 dummy_key = 0; + + r_u->needed = 2; + if (q_u->size < r_u->needed) return WERR_MORE_DATA; - enumkeys[0] = 0x0; - if (!make_spoolss_buffer5(p->mem_ctx, &r_u->keys, 1, enumkeys)) + + if ( !make_spoolss_buffer5(p->mem_ctx, &r_u->keys, 1, &dummy_key ) ) return WERR_BADFILE; return WERR_OK; @@ -8129,6 +8005,7 @@ WERROR _spoolss_enumprinterkey(pipes_struct *p, SPOOL_Q_ENUMPRINTERKEY *q_u, SPO /* The return value for an unknown key is documented in MSDN EnumPrinterKey description */ + return WERR_BADFILE; } @@ -8148,7 +8025,7 @@ WERROR _spoolss_deleteprinterkey(pipes_struct *p, SPOOL_Q_DELETEPRINTERKEY *q_u, unistr2_to_ascii(key, &q_u->keyname, sizeof(key) - 1); - if (strcmp(key, "PrinterDriverData") != 0) + if (strcmp(key, SPOOL_PRINTERDATA_KEY) != 0) return WERR_INVALID_PARAM; /* @@ -8172,14 +8049,16 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ needed; NT_PRINTER_INFO_LEVEL *printer = NULL; PRINTER_ENUM_VALUES *enum_values = NULL; - fstring key, value; + NT_PRINTER_DATA *p_data; + fstring key; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); int snum; - uint32 param_index, - data_len, - type; WERROR result; - uint8 *data=NULL; + int key_index; + int i; + REGISTRY_VALUE *val; + char *value_name; + int data_len; DEBUG(4,("_spoolss_enumprinterdataex\n")); @@ -8190,20 +8069,8 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ } - /* - * The only key we support is "PrinterDriverData". This should return - > an array of all the key/value pairs returned by EnumPrinterDataSee - * _spoolss_getprinterdataex() for details --jerry - */ - - unistr2_to_ascii(key, &q_u->key, sizeof(key) - 1); - if (strcmp(key, "PrinterDriverData") != 0) - { - DEBUG(10,("_spoolss_enumprinterdataex: Unknown keyname [%s]\n", key)); - return WERR_INVALID_PARAM; - } - - + /* first get the printer off of disk */ + if (!get_printer_snum(p,handle, &snum)) return WERR_BADFID; @@ -8211,55 +8078,78 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ result = get_a_printer(&printer, 2, lp_servicename(snum)); if (!W_ERROR_IS_OK(result)) return result; - - /* - * loop through all params and build the array to pass - * back to the client - */ + /* now look for a match on the key name */ + + p_data = &printer->info_2->data; + + unistr2_to_ascii(key, &q_u->key, sizeof(key) - 1); + if ( (key_index = lookup_printerkey( p_data, key)) == -1 ) + { + DEBUG(10,("_spoolss_enumprinterdataex: Unknown keyname [%s]\n", key)); + result = WERR_INVALID_PARAM; + goto done; + } + result = WERR_OK; - param_index = 0; - needed = 0; - num_entries = 0; + needed = 0; - while (get_specific_param_by_index(*printer, 2, param_index, value, &data, &type, &data_len)) + /* allocate the memory for the array of pointers -- if necessary */ + + num_entries = regval_ctr_numvals( &p_data->keys[key_index].values ); + if ( num_entries ) { - PRINTER_ENUM_VALUES *ptr; - uint32 add_len = 0; - - DEBUG(10,("retrieved value number [%d] [%s]\n", num_entries, value)); - - if ((ptr=talloc_realloc(p->mem_ctx, enum_values, (num_entries+1) * sizeof(PRINTER_ENUM_VALUES))) == NULL) + if ( (enum_values=talloc(p->mem_ctx, num_entries*sizeof(PRINTER_ENUM_VALUES))) == NULL ) { - DEBUG(0,("talloc_realloc failed to allocate more memory!\n")); + DEBUG(0,("_spoolss_enumprinterdataex: talloc() failed to allocate memory for [%d] bytes!\n", + num_entries*sizeof(PRINTER_ENUM_VALUES))); result = WERR_NOMEM; goto done; } - enum_values = ptr; + + memset( enum_values, 0x0, num_entries*sizeof(PRINTER_ENUM_VALUES) ); + } + + /* + * loop through all params and build the array to pass + * back to the client + */ + + for ( i=0; ikeys[key_index].values, i ); + DEBUG(10,("retrieved value number [%d] [%s]\n", i, regval_name(val) )); /* copy the data */ - init_unistr(&enum_values[num_entries].valuename, value); - enum_values[num_entries].value_len = (strlen(value)+1) * 2; - enum_values[num_entries].type = type; - if (!(enum_values[num_entries].data=talloc_zero(p->mem_ctx, data_len+add_len))) { - DEBUG(0,("talloc_realloc failed to allocate more memory for data!\n")); - result = WERR_NOMEM; - goto done; + value_name = regval_name( val ); + init_unistr( &enum_values[i].valuename, value_name ); + enum_values[i].value_len = (strlen(value_name)+1) * 2; + enum_values[i].type = regval_type( val ); + + data_len = regval_size( val ); + if ( data_len ) { + if ( !(enum_values[i].data = talloc_memdup(p->mem_ctx, regval_data_p(val), data_len)) ) + { + DEBUG(0,("talloc_memdup failed to allocate memory [data_len=%d] for data!\n", + data_len )); + result = WERR_NOMEM; + goto done; + } } - memcpy(enum_values[num_entries].data, data, data_len); - enum_values[num_entries].data_len = data_len + add_len; + enum_values[i].data_len = data_len; /* keep track of the size of the array in bytes */ - needed += spoolss_size_printer_enum_values(&enum_values[num_entries]); - - num_entries++; - param_index++; + needed += spoolss_size_printer_enum_values(&enum_values[i]); } - r_u->needed = needed; - r_u->returned = num_entries; + /* housekeeping information in the reply */ + + r_u->needed = needed; + r_u->returned = num_entries; if (needed > in_size) { result = WERR_MORE_DATA; @@ -8355,4 +8245,23 @@ WERROR _spoolss_getprintprocessordirectory(pipes_struct *p, SPOOL_Q_GETPRINTPROC return result; } +#if 0 + +WERROR _spoolss_replyopenprinter(pipes_struct *p, SPOOL_Q_REPLYOPENPRINTER *q_u, + SPOOL_R_REPLYOPENPRINTER *r_u) +{ + DEBUG(5,("_spoolss_replyopenprinter\n")); + + DEBUG(10, ("replyopenprinter for localprinter %d\n", q_u->printer)); + + return WERR_OK; +} + +WERROR _spoolss_replycloseprinter(pipes_struct *p, SPOOL_Q_REPLYCLOSEPRINTER *q_u, + SPOOL_R_REPLYCLOSEPRINTER *r_u) +{ + DEBUG(5,("_spoolss_replycloseprinter\n")); + return WERR_OK; +} +#endif -- cgit From a834a73e341059be154426390304a42e4a011f72 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 25 Sep 2002 15:19:00 +0000 Subject: sync'ing up for 3.0alpha20 release (This used to be commit 65e7b5273bb58802bf0c389b77f7fcae0a1f6139) --- source3/rpc_server/srv_spoolss_nt.c | 1898 ++++++++++++++++++++++------------- 1 file changed, 1211 insertions(+), 687 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 7aceaa548f..2190215107 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4,7 +4,7 @@ * Copyright (C) Andrew Tridgell 1992-2000, * Copyright (C) Luke Kenneth Casson Leighton 1996-2000, * Copyright (C) Jean François Micouleau 1998-2000, - * Copyright (C) Jeremy Allison 2001, + * Copyright (C) Jeremy Allison 2001-2002, * Copyright (C) Gerald Carter 2000-2002, * Copyright (C) Tim Potter 2001-2002. * @@ -87,6 +87,10 @@ typedef struct _Printer{ fstring machine; fstring user; } client; + + /* devmode sent in the OpenPrinter() call */ + NT_DEVICEMODE *nt_devmode; + } Printer_entry; static Printer_entry *printers_list; @@ -196,6 +200,11 @@ static void srv_spoolss_replycloseprinter(POLICY_HND *handle) cli_ulogoff(¬ify_cli); cli_shutdown(¬ify_cli); message_deregister(MSG_PRINTER_NOTIFY2); + + /* Tell the connections db we're no longer interested in + * printer notify messages. */ + + register_message_flags( False, FLAG_MSG_PRINTING ); } smb_connections--; @@ -219,6 +228,8 @@ static void free_printer_entry(void *ptr) free_spool_notify_option(&Printer->notify.option); Printer->notify.option=NULL; Printer->notify.client_connected=False; + + free_nt_devicemode( &Printer->nt_devmode ); /* Remove from the internal list. */ DLIST_REMOVE(printers_list, Printer); @@ -566,7 +577,14 @@ static BOOL is_monitoring_event(Printer_entry *p, uint16 notify_type, { SPOOL_NOTIFY_OPTION *option = p->notify.option; uint32 i, j; - + + /* + * Flags should always be zero when the change notify + * is registered by the cliebnt's spooler. A user Win32 app + * might use the flags though instead of the NOTIFY_OPTION_INFO + * --jerry + */ + if (p->notify.flags) return is_monitoring_event_flags( p->notify.flags, notify_type, notify_field); @@ -716,26 +734,177 @@ static struct notify2_message_table job_notify_table[] = { /* 0x17 */ { "JOB_NOTIFY_BYTES_PRINTED", NULL }, }; + +/*********************************************************************** + Allocate talloc context for container object + **********************************************************************/ + +static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr ) +{ + if ( !ctr ) + return; + + ctr->ctx = talloc_init(); + + return; +} + +/*********************************************************************** + release all allocated memory and zero out structure + **********************************************************************/ + +static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr ) +{ + if ( !ctr ) + return; + + if ( ctr->ctx ) + talloc_destroy(ctr->ctx); + + ZERO_STRUCTP(ctr); + + return; +} + +/*********************************************************************** + **********************************************************************/ + +static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr ) +{ + if ( !ctr ) + return NULL; + + return ctr->ctx; +} + +/*********************************************************************** + **********************************************************************/ + +static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) +{ + if ( !ctr || !ctr->msg_groups ) + return NULL; + + if ( idx >= ctr->num_groups ) + return NULL; + + return &ctr->msg_groups[idx]; + +} + +/*********************************************************************** + How many groups of change messages do we have ? + **********************************************************************/ + +static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr ) +{ + if ( !ctr ) + return 0; + + return ctr->num_groups; +} + +/*********************************************************************** + Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group + **********************************************************************/ + +static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg ) +{ + SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL; + SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL; + SPOOLSS_NOTIFY_MSG *msg_list = NULL; + int i, new_slot; + + if ( !ctr || !msg ) + return 0; + + /* loop over all groups looking for a matching printer name */ + + for ( i=0; inum_groups; i++ ) { + if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 ) + break; + } + + /* add a new group? */ + + if ( i == ctr->num_groups ) + { + ctr->num_groups++; + + if ( !(groups = talloc_realloc( ctr->ctx, ctr->msg_groups, sizeof(SPOOLSS_NOTIFY_MSG_GROUP)*ctr->num_groups)) ) { + DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n")); + return 0; + } + ctr->msg_groups = groups; + + /* clear the new entry and set the printer name */ + + ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] ); + fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer ); + } + + /* add the change messages; 'i' is the correct index now regardless */ + + msg_grp = &ctr->msg_groups[i]; + + msg_grp->num_msgs++; + + if ( !(msg_list = talloc_realloc( ctr->ctx, msg_grp->msgs, sizeof(SPOOLSS_NOTIFY_MSG)*msg_grp->num_msgs )) ) { + DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs)); + return 0; + } + msg_grp->msgs = msg_list; + + new_slot = msg_grp->num_msgs-1; + memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) ); + + /* need to allocate own copy of data */ + + if ( msg->len != 0 ) + msg_grp->msgs[new_slot].notify.data = talloc_memdup( ctr->ctx, msg->notify.data, msg->len ); + + return ctr->num_groups; +} + /*********************************************************************** Send a change notication message on all handles which have a call back registered **********************************************************************/ -static void process_notify2_message(struct spoolss_notify_msg *msg, - TALLOC_CTX *mem_ctx) +static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) { - Printer_entry *p; - - DEBUG(8,("process_notify2_message: Enter...[%s]\n", msg->printer)); + Printer_entry *p; + TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr ); + SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx ); + SPOOLSS_NOTIFY_MSG *messages; + + + if ( !msg_group ) { + DEBUG(5,("send_notify2_changes() called with no msg group!\n")); + return; + } + + messages = msg_group->msgs; - for (p = printers_list; p; p = p->next) { + if ( !messages ) { + DEBUG(5,("send_notify2_changes() called with no messages!\n")); + return; + } + + DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername)); + + /* loop over all printers */ + + for (p = printers_list; p; p = p->next) + { SPOOL_NOTIFY_INFO_DATA *data; - uint32 data_len = 1; - uint32 id; + uint32 data_len = 0; + uint32 id; + int i; /* Is there notification on this handle? */ - if (!p->notify.client_connected) + if ( !p->notify.client_connected ) continue; DEBUG(10,("Client connected! [%s]\n", p->dev.handlename)); @@ -744,25 +913,31 @@ static void process_notify2_message(struct spoolss_notify_msg *msg, notifications. */ if ( ( p->printer_type == PRINTER_HANDLE_IS_PRINTER ) && - ( !strequal(msg->printer, p->dev.handlename) ) ) + ( !strequal(msg_group->printername, p->dev.handlename) ) ) continue; DEBUG(10,("Our printer\n")); + /* allocate the max entries possible */ + + data = talloc( mem_ctx, msg_group->num_msgs*sizeof(SPOOL_NOTIFY_INFO_DATA) ); + ZERO_STRUCTP(data); + + /* build the array of change notifications */ + + for ( i=0; inum_msgs; i++ ) + { + SPOOLSS_NOTIFY_MSG *msg = &messages[i]; + /* Are we monitoring this event? */ if (!is_monitoring_event(p, msg->type, msg->field)) continue; + DEBUG(10,("process_notify2_message: Sending message type [%x] field [%x] for printer [%s]\n", msg->type, msg->field, p->dev.handlename)); - /* OK - send the event to the client */ - - data = talloc(mem_ctx, sizeof(SPOOL_NOTIFY_INFO_DATA)); - - ZERO_STRUCTP(data); - /* * if the is a printer notification handle and not a job notification * type, then set the id to 0. Other wise just use what was specified @@ -784,8 +959,8 @@ static void process_notify2_message(struct spoolss_notify_msg *msg, /* Convert unix jobid to smb jobid */ - if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) { - + if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) + { id = sysjob_to_jobid(msg->id); if (id == -1) { @@ -794,22 +969,20 @@ static void process_notify2_message(struct spoolss_notify_msg *msg, } } - construct_info_data(data, msg->type, msg->field, id); + construct_info_data( &data[data_len], msg->type, msg->field, id ); switch(msg->type) { case PRINTER_NOTIFY_TYPE: if ( !printer_notify_table[msg->field].fn ) goto done; - - printer_notify_table[msg->field].fn(msg, data, mem_ctx); + printer_notify_table[msg->field].fn(msg, &data[data_len], mem_ctx); break; case JOB_NOTIFY_TYPE: if ( !job_notify_table[msg->field].fn ) goto done; - - job_notify_table[msg->field].fn(msg, data, mem_ctx); + job_notify_table[msg->field].fn(msg, &data[data_len], mem_ctx); break; @@ -818,59 +991,139 @@ static void process_notify2_message(struct spoolss_notify_msg *msg, goto done; } + data_len++; + } + cli_spoolss_rrpcn( ¬ify_cli, mem_ctx, &p->notify.client_hnd, data_len, data, p->notify.change, 0 ); } + done: - DEBUG(8,("process_notify2_message: Exit...\n")); + DEBUG(8,("send_notify2_changes: Exit...\n")); return; } -/* Receive a notify2 message */ +/*********************************************************************** + **********************************************************************/ -static void receive_notify2_message(int msg_type, pid_t src, void *buf, - size_t len) +static BOOL notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, void *buf, size_t len ) { - struct spoolss_notify_msg msg; + int offset = 0; - TALLOC_CTX *mem_ctx = talloc_init(); /* Unpack message */ - ZERO_STRUCT(msg); - offset += tdb_unpack((char *)buf + offset, len - offset, "f", - msg.printer); + msg->printer); offset += tdb_unpack((char *)buf + offset, len - offset, "ddddd", - &msg.type, &msg.field, &msg.id, &msg.len, &msg.flags); + &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags); - if (msg.len == 0) + if (msg->len == 0) tdb_unpack((char *)buf + offset, len - offset, "dd", - &msg.notify.value[0], &msg.notify.value[1]); + &msg->notify.value[0], &msg->notify.value[1]); else tdb_unpack((char *)buf + offset, len - offset, "B", - &msg.len, &msg.notify.data); + &msg->len, &msg->notify.data); - DEBUG(3, ("got NOTIFY2 message, type %d, field 0x%02x, flags 0x%04x\n", - msg.type, msg.field, msg.flags)); + DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message, type %d, field 0x%02x, flags 0x%04x\n", + msg->type, msg->field, msg->flags)); - if (msg.len == 0) - DEBUG(3, ("value1 = %d, value2 = %d\n", msg.notify.value[0], - msg.notify.value[1])); + if (msg->len == 0) + DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0], + msg->notify.value[1])); else - dump_data(3, msg.notify.data, msg.len); + dump_data(3, msg->notify.data, msg->len); + + return True; +} + +/******************************************************************** + Receive a notify2 message list + ********************************************************************/ + +static void receive_notify2_message_list(int msg_type, pid_t src, void *msg, size_t len) +{ + size_t msg_count, i; + char *buf = (char *)msg; + char *msg_ptr; + size_t msg_len; + SPOOLSS_NOTIFY_MSG notify; + SPOOLSS_NOTIFY_MSG_CTR messages; + int num_groups; + + if (len < 4) { + DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n")); + return; + } + + msg_count = IVAL(buf, 0); + msg_ptr = buf + 4; - /* Process message */ + DEBUG(5, ("receive_notify2_message_list: got %d messages in list\n", msg_count)); - process_notify2_message(&msg, mem_ctx); + if (msg_count == 0) { + DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n")); + return; + } - /* Free message */ + /* initialize the container */ + + ZERO_STRUCT( messages ); + notify_msg_ctr_init( &messages ); + + /* + * build message groups for each printer identified + * in a change_notify msg. Remember that a PCN message + * includes the handle returned for the srv_spoolss_replyopenprinter() + * call. Therefore messages are grouped according to printer handle. + */ + + for ( i=0; i len) { + DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n")); + return; + } - if (msg.len > 0) - free(msg.notify.data); + msg_len = IVAL(msg_ptr,0); + msg_ptr += 4; - talloc_destroy(mem_ctx); + if (msg_ptr + msg_len - buf > len) { + DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n")); + return; + } + + /* unpack messages */ + + ZERO_STRUCT( notify ); + notify2_unpack_msg( ¬ify, msg_ptr, msg_len ); + msg_ptr += msg_len; + + /* add to correct list in container */ + + notify_msg_ctr_addmsg( &messages, ¬ify ); + + /* free memory that might have been allocated by notify2_unpack_msg() */ + + if ( notify.len != 0 ) + SAFE_FREE( notify.notify.data ); + } + + /* process each group of messages */ + + num_groups = notify_msg_ctr_numgroups( &messages ); + for ( i=0; iprinter_default; - POLICY_HND *handle = &r_u->handle; + UNISTR2 *printername = NULL; + PRINTER_DEFAULT *printer_default = &q_u->printer_default; + POLICY_HND *handle = &r_u->handle; fstring name; int snum; @@ -1180,39 +1484,36 @@ Can't find printer handle we created for printer %s\n", name )); return WERR_INVALID_PRINTER_NAME; } - /* - First case: the user is opening the print server: - - Disallow MS AddPrinterWizard if parameter disables it. A Win2k - client 1st tries an OpenPrinterEx with access==0, MUST be allowed. - - Then both Win2k and WinNT clients try an OpenPrinterEx with - SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0) - or if the user is listed in the smb.conf printer admin parameter. - - Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the - client view printer folder, but does not show the MSAPW. - - Note: this test needs code to check access rights here too. Jeremy - could you look at this? - - - Second case: the user is opening a printer: - NT doesn't let us connect to a printer if the connecting user - doesn't have print permission. - - */ - get_current_user(&user, p); - if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) { + /* + * First case: the user is opening the print server: + * + * Disallow MS AddPrinterWizard if parameter disables it. A Win2k + * client 1st tries an OpenPrinterEx with access==0, MUST be allowed. + * + * Then both Win2k and WinNT clients try an OpenPrinterEx with + * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0) + * or if the user is listed in the smb.conf printer admin parameter. + * + * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the + * client view printer folder, but does not show the MSAPW. + * + * Note: this test needs code to check access rights here too. Jeremy + * could you look at this? + * + * Second case: the user is opening a printer: + * NT doesn't let us connect to a printer if the connecting user + * doesn't have print permission. + */ + if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) + { /* Printserver handles use global struct... */ snum = -1; - /* Map standard access rights to object specific access - rights */ + /* Map standard access rights to object specific access rights */ se_map_standard(&printer_default->access_required, &printserver_std_mapping); @@ -1231,23 +1532,32 @@ Can't find printer handle we created for printer %s\n", name )); /* Allow admin access */ - if (printer_default->access_required & - SERVER_ACCESS_ADMINISTER) { - + if ( printer_default->access_required & SERVER_ACCESS_ADMINISTER ) + { if (!lp_ms_add_printer_wizard()) { close_printer_handle(p, handle); return WERR_ACCESS_DENIED; } - if (user.uid == 0 || - user_in_list(uidtoname(user.uid), - lp_printer_admin(snum))) - return WERR_OK; + /* if the user is not root and not a printer admin, then fail */ - close_printer_handle(p, handle); - return WERR_ACCESS_DENIED; + if ( user.uid != 0 + && !user_in_list(uidtoname(user.uid), lp_printer_admin(snum)) ) + { + close_printer_handle(p, handle); + return WERR_ACCESS_DENIED; + } + + printer_default->access_required = SERVER_ACCESS_ADMINISTER; + } + else + { + printer_default->access_required = SERVER_ACCESS_ENUMERATE; } + DEBUG(4,("Setting print server access = %s\n", (printer_default->access_required == SERVER_ACCESS_ADMINISTER) + ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" )); + /* We fall through to return WERR_OK */ } @@ -1296,84 +1606,24 @@ Can't find printer handle we created for printer %s\n", name )); else printer_default->access_required = PRINTER_ACCESS_USE; - DEBUG(4,("Setting printer access=%x\n", printer_default->access_required)); - Printer->access_granted = printer_default->access_required; - - /* - * If we have a default device pointer in the - * printer_default struct, then we need to get - * the printer info from the tdb and if there is - * no default devicemode there then we do a *SET* - * here ! This is insanity.... JRA. - */ - - /* - * If the openprinterex rpc call contains a devmode, - * it's a per-user one. This per-user devmode is derivated - * from the global devmode. Openprinterex() contains a per-user - * devmode for when you do EMF printing and spooling. - * In the EMF case, the NT workstation is only doing half the job - * of rendering the page. The other half is done by running the printer - * driver on the server. - * The EMF file doesn't contain the page description (paper size, orientation, ...). - * The EMF file only contains what is to be printed on the page. - * So in order for the server to know how to print, the NT client sends - * a devicemode attached to the openprinterex call. - * But this devicemode is short lived, it's only valid for the current print job. - * - * If Samba would have supported EMF spooling, this devicemode would - * have been attached to the handle, to sent it to the driver to correctly - * rasterize the EMF file. - * - * As Samba only supports RAW spooling, we only receive a ready-to-print file, - * we just act as a pass-thru between windows and the printer. - * - * In order to know that Samba supports only RAW spooling, NT has to call - * getprinter() at level 2 (attribute field) or NT has to call startdoc() - * and until NT sends a RAW job, we refuse it. - * - * But to call getprinter() or startdoc(), you first need a valid handle, - * and to get an handle you have to call openprintex(). Hence why you have - * a devicemode in the openprinterex() call. - * - * - * Differences between NT4 and NT 2000. - * NT4: - * --- - * On NT4, you only have a global devicemode. This global devicemode can be changed - * by the administrator (or by a user with enough privs). Everytime a user - * wants to print, the devicemode is resetted to the default. In Word, everytime - * you print, the printer's characteristics are always reset to the global devicemode. - * - * NT 2000: - * ------- - * In W2K, there is the notion of per-user devicemode. The first time you use - * a printer, a per-user devicemode is build from the global devicemode. - * If you change your per-user devicemode, it is saved in the registry, under the - * H_KEY_CURRENT_KEY sub_tree. So that everytime you print, you have your default - * printer preferences available. - * - * To change the per-user devicemode: it's the "Printing Preferences ..." button - * on the General Tab of the printer properties windows. - * - * To change the global devicemode: it's the "Printing Defaults..." button - * on the Advanced Tab of the printer properties window. - * - * JFM. - */ + DEBUG(4,("Setting printer access = %s\n", (printer_default->access_required == PRINTER_ACCESS_ADMINISTER) + ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" )); - - -#if 0 - if (printer_default->devmode_cont.devmode != NULL) { - result = printer_write_default_dev( snum, printer_default); - if (result != 0) { - close_printer_handle(p, handle); - return result; - } - } -#endif } + + Printer->access_granted = printer_default->access_required; + + /* + * If the client sent a devmode in the OpenPrinter() call, then + * save it here in case we get a job submission on this handle + */ + + if ( (Printer->printer_type != PRINTER_HANDLE_IS_PRINTSERVER) + && q_u->printer_default.devmode_cont.devmode_ptr ) + { + convert_devicemode( Printer->dev.handlename, q_u->printer_default.devmode_cont.devmode, + &Printer->nt_devmode ); + } return WERR_OK; } @@ -1599,8 +1849,11 @@ WERROR _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER fstring driver; fstring arch; NT_PRINTER_DRIVER_INFO_LEVEL info; + NT_PRINTER_DRIVER_INFO_LEVEL info_win2k; int version; struct current_user user; + WERROR status; + WERROR status_win2k = WERR_ACCESS_DENIED; get_current_user(&user, p); @@ -1608,25 +1861,58 @@ WERROR _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER unistr2_to_ascii(arch, &q_u->arch, sizeof(arch)-1 ); /* check that we have a valid driver name first */ - if ((version=get_version_id(arch)) == -1) { - /* this is what NT returns */ + + if ((version=get_version_id(arch)) == -1) return WERR_INVALID_ENVIRONMENT; + + ZERO_STRUCT(info); + ZERO_STRUCT(info_win2k); + + if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, driver, arch, version))) + { + /* try for Win2k driver if "Windows NT x86" */ + + if ( version == 2 ) { + version = 3; + if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, driver, arch, version))) { + status = WERR_UNKNOWN_PRINTER_DRIVER; + goto done; + } + } } - /* if they said "Windows NT x86", then try for version 2 & 3 */ + if (printer_driver_in_use(info.info_3)) { + status = WERR_PRINTER_DRIVER_IN_USE; + goto done; + } if ( version == 2 ) - version = DRIVER_ANY_VERSION; + { + if (W_ERROR_IS_OK(get_a_printer_driver(&info_win2k, 3, driver, arch, 3))) + { + /* if we get to here, we now have 2 driver info structures to remove */ + /* remove the Win2k driver first*/ - ZERO_STRUCT(info); + status_win2k = delete_printer_driver(info_win2k.info_3, &user, 3, False ); + free_a_printer_driver( info_win2k, 3 ); + + /* this should not have failed---if it did, report to client */ + if ( !W_ERROR_IS_OK(status_win2k) ) + goto done; + } + } - if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, driver, arch, version))) - return WERR_UNKNOWN_PRINTER_DRIVER; + status = delete_printer_driver(info.info_3, &user, version, False); + + /* if at least one of the deletes succeeded return OK */ - if (printer_driver_in_use(info.info_3)) - return WERR_PRINTER_DRIVER_IN_USE; + if ( W_ERROR_IS_OK(status) || W_ERROR_IS_OK(status_win2k) ) + status = WERR_OK; + +done: + free_a_printer_driver( info, 3 ); - return delete_printer_driver(info.info_3, &user, DRIVER_ANY_VERSION, False); + return status; } /******************************************************************** @@ -1638,10 +1924,13 @@ WERROR _spoolss_deleteprinterdriverex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIV fstring driver; fstring arch; NT_PRINTER_DRIVER_INFO_LEVEL info; + NT_PRINTER_DRIVER_INFO_LEVEL info_win2k; int version; uint32 flags = q_u->delete_flags; BOOL delete_files; struct current_user user; + WERROR status; + WERROR status_win2k = WERR_ACCESS_DENIED; get_current_user(&user, p); @@ -1656,17 +1945,36 @@ WERROR _spoolss_deleteprinterdriverex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIV if ( flags & DPD_DELETE_SPECIFIC_VERSION ) version = q_u->version; - else if ( version == 2 ) - /* if they said "Windows NT x86", then try for version 2 & 3 */ - version = DRIVER_ANY_VERSION; ZERO_STRUCT(info); + ZERO_STRUCT(info_win2k); + + status = get_a_printer_driver(&info, 3, driver, arch, version); - if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, driver, arch, version))) - return WERR_UNKNOWN_PRINTER_DRIVER; + if ( !W_ERROR_IS_OK(status) ) + { + /* + * if the client asked for a specific version, + * or this is something other than Windows NT x86, + * then we've failed + */ + + if ( (flags&DPD_DELETE_SPECIFIC_VERSION) || (version !=2) ) + goto done; + + /* try for Win2k driver if "Windows NT x86" */ + + version = 3; + if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, driver, arch, version))) { + status = WERR_UNKNOWN_PRINTER_DRIVER; + goto done; + } + } - if ( printer_driver_in_use(info.info_3) ) - return WERR_PRINTER_DRIVER_IN_USE; + if ( printer_driver_in_use(info.info_3) ) { + status = WERR_PRINTER_DRIVER_IN_USE; + goto done; + } /* * we have a couple of cases to consider. @@ -1682,24 +1990,119 @@ WERROR _spoolss_deleteprinterdriverex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIV delete_files = flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES); - if ( delete_files ) - { - /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */ + /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */ + + if ( delete_files && printer_driver_files_in_use(info.info_3) & (flags&DPD_DELETE_ALL_FILES) ) { + /* no idea of the correct error here */ + status = WERR_ACCESS_DENIED; + goto done; + } + + + /* also check for W32X86/3 if necessary; maybe we already have? */ + + if ( (version == 2) && ((flags&DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) { + if (W_ERROR_IS_OK(get_a_printer_driver(&info_win2k, 3, driver, arch, 3))) + { + + if ( delete_files && printer_driver_files_in_use(info_win2k.info_3) & (flags&DPD_DELETE_ALL_FILES) ) { + /* no idea of the correct error here */ + free_a_printer_driver( info_win2k, 3 ); + status = WERR_ACCESS_DENIED; + goto done; + } + + /* if we get to here, we now have 2 driver info structures to remove */ + /* remove the Win2k driver first*/ - if ( printer_driver_files_in_use(info.info_3) & (flags&DPD_DELETE_ALL_FILES) ) - /* no idea of the correct error here */ - return WERR_ACCESS_DENIED; + status_win2k = delete_printer_driver(info_win2k.info_3, &user, 3, delete_files); + free_a_printer_driver( info_win2k, 3 ); + + /* this should not have failed---if it did, report to client */ + + if ( !W_ERROR_IS_OK(status_win2k) ) + goto done; + } } - return delete_printer_driver(info.info_3, &user, version, delete_files); + status = delete_printer_driver(info.info_3, &user, version, delete_files); + + if ( W_ERROR_IS_OK(status) || W_ERROR_IS_OK(status_win2k) ) + status = WERR_OK; +done: + free_a_printer_driver( info, 3 ); + + return status; +} + + +/**************************************************************************** + Internal routine for retreiving printerdata + ***************************************************************************/ + +static WERROR get_printer_dataex( TALLOC_CTX *ctx, NT_PRINTER_INFO_LEVEL *printer, + char *key, char *value, uint32 *type, uint8 **data, + uint32 *needed, uint32 in_size ) +{ + REGISTRY_VALUE *val; + int size, data_len; + + if ( !(val = get_printer_data( printer->info_2, key, value)) ) + return WERR_BADFILE; + + *type = regval_type( val ); + + DEBUG(5,("get_printer_dataex: allocating %d\n", in_size)); + + size = regval_size( val ); + + /* copy the min(in_size, len) */ + + if ( in_size ) { + data_len = (size > in_size) ? in_size : size*sizeof(uint8); + if ( (*data = (uint8 *)talloc_memdup(ctx, regval_data_p(val), data_len)) == NULL ) + return WERR_NOMEM; + } + else + *data = NULL; + + *needed = size; + + DEBUG(5,("get_printer_dataex: copy done\n")); + + return WERR_OK; +} + +/**************************************************************************** + Internal routine for removing printerdata + ***************************************************************************/ + +static WERROR delete_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, char *key, char *value ) +{ + delete_printer_data( printer->info_2, key, value ); + + return mod_a_printer(*printer, 2); } +/**************************************************************************** + Internal routine for storing printerdata + ***************************************************************************/ + +static WERROR set_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, char *key, char *value, + uint32 type, uint8 *data, int real_len ) +{ + delete_printer_data( printer->info_2, key, value ); + + add_printer_data( printer->info_2, key, value, type, data, real_len ); + + return mod_a_printer(*printer, 2); +} /******************************************************************** GetPrinterData on a printer server Handle. ********************************************************************/ -static BOOL getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint32 *type, uint8 **data, uint32 *needed, uint32 in_size) +static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint32 *type, uint8 **data, uint32 *needed, uint32 in_size) { int i; @@ -1708,50 +2111,50 @@ static BOOL getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint32 if (!strcmp(value, "W3SvcInstalled")) { *type = 0x4; if((*data = (uint8 *)talloc_zero(ctx, 4*sizeof(uint8) )) == NULL) - return False; - *needed = 0x4; - return True; + return WERR_NOMEM; + *needed = 0x4; + return WERR_OK; } if (!strcmp(value, "BeepEnabled")) { *type = 0x4; if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) - return False; + return WERR_NOMEM; SIVAL(*data, 0, 0x00); *needed = 0x4; - return True; + return WERR_OK; } if (!strcmp(value, "EventLog")) { *type = 0x4; if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) - return False; + return WERR_NOMEM; /* formally was 0x1b */ SIVAL(*data, 0, 0x0); *needed = 0x4; - return True; + return WERR_OK; } if (!strcmp(value, "NetPopup")) { *type = 0x4; if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) - return False; + return WERR_NOMEM; SIVAL(*data, 0, 0x00); *needed = 0x4; - return True; + return WERR_OK; } if (!strcmp(value, "MajorVersion")) { *type = 0x4; if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) - return False; + return WERR_NOMEM; #ifndef EMULATE_WIN2K_HACK /* JERRY */ SIVAL(*data, 0, 2); #else SIVAL(*data, 0, 3); #endif *needed = 0x4; - return True; + return WERR_OK; } if (!strcmp(value, "DefaultSpoolDirectory")) { @@ -1761,7 +2164,7 @@ static BOOL getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint32 *type = 0x1; *needed = 2*(strlen(string)+1); if((*data = (uint8 *)talloc(ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL) - return False; + return WERR_NOMEM; memset(*data, 0, (*needed > in_size) ? *needed:in_size); /* it's done by hand ready to go on the wire */ @@ -1769,7 +2172,7 @@ static BOOL getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint32 (*data)[2*i]=string[i]; (*data)[2*i+1]='\0'; } - return True; + return WERR_OK; } if (!strcmp(value, "Architecture")) { @@ -1777,97 +2180,36 @@ static BOOL getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint32 *type = 0x1; *needed = 2*(strlen(string)+1); if((*data = (uint8 *)talloc(ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL) - return False; + return WERR_NOMEM; memset(*data, 0, (*needed > in_size) ? *needed:in_size); for (i=0; iinfo_2, SPOOL_PRINTERDATA_KEY, value)) ) - { - free_a_printer(&printer, 2); - return False; - } - - *type = regval_type( val ); - - - DEBUG(5,("getprinterdata_printer:allocating %d\n", in_size)); - - if (in_size) - { - if ( (*data = (uint8 *)talloc(ctx, in_size * sizeof(uint8))) == NULL ) - return False; - - memset( *data, 0, in_size *sizeof(uint8) ); - - /* copy the min(in_size, len) */ - - size = regval_size( val ); - memcpy( *data, regval_data_p(val), (size > in_size) ? in_size : size*sizeof(uint8) ); - } - else - *data = NULL; - - *needed = size; - - DEBUG(5,("getprinterdata_printer:copy done\n")); - - - free_a_printer(&printer, 2); - return True; -} - /******************************************************************** * spoolss_getprinterdata ********************************************************************/ WERROR _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPOOL_R_GETPRINTERDATA *r_u) { - POLICY_HND *handle = &q_u->handle; - UNISTR2 *valuename = &q_u->valuename; - uint32 in_size = q_u->size; - uint32 *type = &r_u->type; - uint32 *out_size = &r_u->size; - uint8 **data = &r_u->data; - uint32 *needed = &r_u->needed; - - fstring value; - BOOL found=False; - Printer_entry *Printer = find_printer_index_by_hnd(p, handle); + POLICY_HND *handle = &q_u->handle; + UNISTR2 *valuename = &q_u->valuename; + uint32 in_size = q_u->size; + uint32 *type = &r_u->type; + uint32 *out_size = &r_u->size; + uint8 **data = &r_u->data; + uint32 *needed = &r_u->needed; + WERROR status; + fstring value; + Printer_entry *Printer = find_printer_index_by_hnd(p, handle); + NT_PRINTER_INFO_LEVEL *printer = NULL; + int snum = 0; /* * Reminder: when it's a string, the length is in BYTES @@ -1885,45 +2227,58 @@ WERROR _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO DEBUG(4,("_spoolss_getprinterdata\n")); - if (!Printer) { - if((*data=(uint8 *)talloc_zero(p->mem_ctx, 4*sizeof(uint8))) == NULL) - return WERR_NOMEM; + if ( !Printer ) { DEBUG(2,("_spoolss_getprinterdata: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); - return WERR_BADFID; + status = WERR_BADFID; + goto done; } unistr2_to_ascii(value, valuename, sizeof(value)-1); - if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) - found = getprinterdata_printer_server(p->mem_ctx, value, type, data, needed, *out_size); + if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER ) + status = getprinterdata_printer_server( p->mem_ctx, value, type, data, needed, *out_size ); else - found = getprinterdata_printer(p, p->mem_ctx, handle, value, type, data, needed, *out_size); + { + if ( !get_printer_snum(p,handle, &snum) ) { + status = WERR_BADFID; + goto done; + } - if ( !found ) + status = get_a_printer(&printer, 2, lp_servicename(snum)); + if ( !W_ERROR_IS_OK(status) ) + goto done; + + status = get_printer_dataex( p->mem_ctx, printer, SPOOL_PRINTERDATA_KEY, value, type, data, needed, *out_size ); + } + + if (*needed > *out_size) + status = WERR_MORE_DATA; + +done: + if ( !W_ERROR_IS_OK(status) ) { - DEBUG(5, ("value not found, allocating %d\n", *out_size)); + DEBUG(5, ("error: allocating %d\n", *out_size)); /* reply this param doesn't exist */ - if (*out_size) { - if((*data=(uint8 *)talloc_zero(p->mem_ctx, *out_size*sizeof(uint8))) == NULL) + if ( *out_size ) { + if((*data=(uint8 *)talloc_zero(p->mem_ctx, *out_size*sizeof(uint8))) == NULL) { + if ( printer ) + free_a_printer( &printer, 2 ); return WERR_NOMEM; - } else { + } + } + else { *data = NULL; } - - /* error depends on handle type */ - - if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) - return WERR_INVALID_PARAM; - else - return WERR_BADFILE; } - if (*needed > *out_size) - return WERR_MORE_DATA; - else - return WERR_OK; + /* cleanup & exit */ + + if ( printer ) + free_a_printer( &printer, 2 ); + + return status; } /********************************************************* @@ -1961,6 +2316,7 @@ static BOOL spoolss_connect_to_client(struct cli_state *the_cli, char *remote_ma if (!attempt_netbios_session_request(the_cli, global_myname, remote_machine, &the_cli->dest_ip)) { DEBUG(0,("connect_to_client: machine %s rejected the NetBIOS session request.\n", remote_machine)); + cli_shutdown(the_cli); return False; } @@ -2036,7 +2392,10 @@ static BOOL srv_spoolss_replyopenprinter(char *printer, uint32 localprinter, uin if(!spoolss_connect_to_client(¬ify_cli, unix_printer)) return False; - message_register(MSG_PRINTER_NOTIFY2, receive_notify2_message); + message_register(MSG_PRINTER_NOTIFY2, receive_notify2_message_list); + /* Tell the connections db we're now interested in printer + * notify messages. */ + register_message_flags( True, FLAG_MSG_PRINTING ); } smb_connections++; @@ -2436,8 +2795,8 @@ static void spoolss_notify_security_desc(int snum, NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) { - data->notify_data.data.length=0; - data->notify_data.data.string = NULL; + data->notify_data.sd.size = printer->info_2->secdesc_buf->len; + data->notify_data.sd.desc = dup_sec_desc( mem_ctx, printer->info_2->secdesc_buf->sec ) ; } /******************************************************************* @@ -3443,47 +3802,20 @@ static void free_dev_mode(DEVICEMODE *dev) SAFE_FREE(dev); } + /**************************************************************************** - Create a DEVMODE struct. Returns malloced memory. + Convert an NT_DEVICEMODE to a DEVICEMODE structure. Both pointers + should be valid upon entry ****************************************************************************/ -DEVICEMODE *construct_dev_mode(int snum) +static BOOL convert_nt_devicemode( DEVICEMODE *devmode, NT_DEVICEMODE *ntdevmode ) { - char adevice[32]; - char aform[32]; - NT_PRINTER_INFO_LEVEL *printer = NULL; - NT_DEVICEMODE *ntdevmode = NULL; - DEVICEMODE *devmode = NULL; - - DEBUG(7,("construct_dev_mode\n")); - - DEBUGADD(8,("getting printer characteristics\n")); - - if ((devmode = (DEVICEMODE *)malloc(sizeof(DEVICEMODE))) == NULL) { - DEBUG(2,("construct_dev_mode: malloc fail.\n")); - return NULL; - } - - ZERO_STRUCTP(devmode); - - if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, lp_servicename(snum)))) - goto fail; - - if (printer->info_2->devmode) - ntdevmode = dup_nt_devicemode(printer->info_2->devmode); - - if (ntdevmode == NULL) { - DEBUG(5, ("BONG! There was no device mode!\n")); - goto fail; - } - - DEBUGADD(8,("loading DEVICEMODE\n")); - - slprintf(adevice, sizeof(adevice)-1, printer->info_2->printername); - init_unistr(&devmode->devicename, adevice); + if ( !devmode || !ntdevmode ) + return False; + + init_unistr(&devmode->devicename, ntdevmode->devicename); - slprintf(aform, sizeof(aform)-1, ntdevmode->formname); - init_unistr(&devmode->formname, aform); + init_unistr(&devmode->formname, ntdevmode->formname); devmode->specversion = ntdevmode->specversion; devmode->driverversion = ntdevmode->driverversion; @@ -3511,23 +3843,51 @@ DEVICEMODE *construct_dev_mode(int snum) if (ntdevmode->private != NULL) { if ((devmode->private=(uint8 *)memdup(ntdevmode->private, ntdevmode->driverextra)) == NULL) - goto fail; + return False; } + + return True; +} - free_nt_devicemode(&ntdevmode); - free_a_printer(&printer,2); +/**************************************************************************** + Create a DEVMODE struct. Returns malloced memory. +****************************************************************************/ - return devmode; +DEVICEMODE *construct_dev_mode(int snum) +{ + NT_PRINTER_INFO_LEVEL *printer = NULL; + DEVICEMODE *devmode = NULL; + + DEBUG(7,("construct_dev_mode\n")); + + DEBUGADD(8,("getting printer characteristics\n")); - fail: + if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, lp_servicename(snum)))) + return NULL; - if (ntdevmode) - free_nt_devicemode(&ntdevmode); - if (printer) - free_a_printer(&printer,2); - free_dev_mode(devmode); + if ( !printer->info_2->devmode ) { + DEBUG(5, ("BONG! There was no device mode!\n")); + goto done; + } + + if ((devmode = (DEVICEMODE *)malloc(sizeof(DEVICEMODE))) == NULL) { + DEBUG(2,("construct_dev_mode: malloc fail.\n")); + goto done; + } + + ZERO_STRUCTP(devmode); + + DEBUGADD(8,("loading DEVICEMODE\n")); + + if ( !convert_nt_devicemode( devmode, printer->info_2->devmode ) ) { + free_dev_mode( devmode ); + devmode = NULL; + } - return NULL; +done: + free_a_printer(&printer,2); + + return devmode; } /******************************************************************** @@ -4384,7 +4744,7 @@ static WERROR construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fst * convert an array of ascii string to a UNICODE string ********************************************************************/ -static void init_unistr_array(uint16 **uni_array, fstring *char_array, char *servername) +static uint32 init_unistr_array(uint16 **uni_array, fstring *char_array, char *servername) { int i=0; int j=0; @@ -4397,26 +4757,34 @@ static void init_unistr_array(uint16 **uni_array, fstring *char_array, char *ser while (True) { - if (char_array == NULL) + if ( !char_array ) v = ""; - else { + else + { v = char_array[i]; - if (!v) v = ""; /* hack to handle null lists */ + if (!v) + v = ""; /* hack to handle null lists */ } - if ( !strlen(v) ) - break; + /* hack to allow this to be used in places other than when generating + the list of dependent files */ + + if ( servername ) + slprintf( line, sizeof(line)-1, "\\\\%s%s", servername, v ); + else + pstrcpy( line, v ); - slprintf(line, sizeof(line)-1, "\\\\%s%s", servername, v); - DEBUGADD(6,("%d:%s:%d\n", i, line, strlen(line))); - if((tuary=Realloc(*uni_array, (j+strlen(line)+2)*sizeof(uint16))) == NULL) { + if ( (tuary=Realloc(*uni_array, (j+strlen(line)+2)*sizeof(uint16))) == NULL ) { DEBUG(2,("init_unistr_array: Realloc error\n" )); - return; + return 0; } else *uni_array = tuary; + if ( !strlen(v) ) + break; + j += (rpcstr_push((*uni_array+j), line, sizeof(uint16)*strlen(line)+2, STR_TERMINATE) / sizeof(uint16)); i++; } @@ -4426,6 +4794,10 @@ static void init_unistr_array(uint16 **uni_array, fstring *char_array, char *ser } DEBUGADD(6,("last one:done\n")); + + /* return size of array in uint16's */ + + return j+1; } /******************************************************************** @@ -4444,29 +4816,29 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_IN init_unistr( &info->name, driver.info_3->name ); init_unistr( &info->architecture, driver.info_3->environment ); - if (strlen(driver.info_3->driverpath)) { - slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->driverpath); - init_unistr( &info->driverpath, temp ); - } else - init_unistr( &info->driverpath, "" ); + if (strlen(driver.info_3->driverpath)) { + slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->driverpath); + init_unistr( &info->driverpath, temp ); + } else + init_unistr( &info->driverpath, "" ); - if (strlen(driver.info_3->datafile)) { - slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->datafile); - init_unistr( &info->datafile, temp ); - } else - init_unistr( &info->datafile, "" ); + if (strlen(driver.info_3->datafile)) { + slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->datafile); + init_unistr( &info->datafile, temp ); + } else + init_unistr( &info->datafile, "" ); - if (strlen(driver.info_3->configfile)) { - slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->configfile); - init_unistr( &info->configfile, temp ); - } else - init_unistr( &info->configfile, "" ); + if (strlen(driver.info_3->configfile)) { + slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->configfile); + init_unistr( &info->configfile, temp ); + } else + init_unistr( &info->configfile, "" ); - if (strlen(driver.info_3->helpfile)) { - slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->helpfile); - init_unistr( &info->helpfile, temp ); - } else - init_unistr( &info->helpfile, "" ); + if (strlen(driver.info_3->helpfile)) { + slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->helpfile); + init_unistr( &info->helpfile, temp ); + } else + init_unistr( &info->helpfile, "" ); init_unistr( &info->monitorname, driver.info_3->monitorname ); init_unistr( &info->defaultdatatype, driver.info_3->defaultdatatype ); @@ -4933,10 +5305,6 @@ WERROR _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, S * in EMF format. * * So I add checks like in NT Server ... - * - * lkclXXXX jean-francois, i love this kind of thing. oh, well, - * there's a bug in NT client-side code, so we'll fix it in the - * server-side code. *nnnnnggggh!* */ if (info_1->p_datatype != 0) { @@ -4954,7 +5322,7 @@ WERROR _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, S unistr2_to_ascii(jobname, &info_1->docname, sizeof(jobname)); - Printer->jobid = print_job_start(&user, snum, jobname); + Printer->jobid = print_job_start(&user, snum, jobname, Printer->nt_devmode); /* An error occured in print_job_start() so return an appropriate NT error code. */ @@ -5004,6 +5372,13 @@ WERROR _spoolss_writeprinter(pipes_struct *p, SPOOL_Q_WRITEPRINTER *q_u, SPOOL_R return WERR_BADFID; (*buffer_written) = print_job_write(snum, Printer->jobid, (char *)buffer, buffer_size); + if (*buffer_written == -1) { + r_u->buffer_written = 0; + if (errno == ENOSPC) + return WERR_NO_SPOOL_SPACE; + else + return WERR_ACCESS_DENIED; + } r_u->buffer_written = q_u->buffer_size2; @@ -5046,11 +5421,13 @@ static WERROR control_printer(POLICY_HND *handle, uint32 command, errcode = WERR_OK; } break; +#if 0 /* JERRY - Never called */ case PRINTER_CONTROL_PURGE: if (print_queue_purge(&user, snum, &errcode)) { errcode = WERR_OK; } break; +#endif default: return WERR_UNKNOWN_LEVEL; } @@ -5060,13 +5437,31 @@ static WERROR control_printer(POLICY_HND *handle, uint32 command, /******************************************************************** * api_spoolss_abortprinter + * From MSDN: "Deletes printer's spool file if printer is configured + * for spooling" ********************************************************************/ WERROR _spoolss_abortprinter(pipes_struct *p, SPOOL_Q_ABORTPRINTER *q_u, SPOOL_R_ABORTPRINTER *r_u) { - POLICY_HND *handle = &q_u->handle; - - return control_printer(handle, PRINTER_CONTROL_PURGE, p); + POLICY_HND *handle = &q_u->handle; + Printer_entry *Printer = find_printer_index_by_hnd(p, handle); + int snum; + struct current_user user; + WERROR errcode = WERR_OK; + + if (!Printer) { + DEBUG(2,("_spoolss_abortprinter: Invalid handle (%s:%u:%u)\n",OUR_HANDLE(handle))); + return WERR_BADFID; + } + + if (!get_printer_snum(p, handle, &snum)) + return WERR_BADFID; + + get_current_user( &user, p ); + + print_job_delete( &user, snum, Printer->jobid, &errcode ); + + return errcode; } /******************************************************************** @@ -5315,22 +5710,6 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, goto done; } -#if 0 /* JERRY */ - - /* - * Another one of those historical misunderstandings... - * This is reminisent of a similar call we had in _spoolss_setprinterdata() - * I'm leaving it here as a reminder. --jerry - */ - - if (nt_printer_info_level_equal(printer, old_printer)) { - DEBUG(3, ("update_printer: printer info has not changed\n")); - result = WERR_OK; - goto done; - } - -#endif - /* Check calling user has permission to update printer description */ if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) { @@ -5349,49 +5728,22 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, } /* - * Set the DRIVER_INIT info in the tdb; trigger on magic value for the - * DEVMODE.displayfrequency, which is not used for printer drivers. This - * requires Win32 client code (see other notes elsewhere in the code). + * When a *new* driver is bound to a printer, the drivername is used to + * lookup previously saved driver initialization info, which is then + * bound to the printer, simulating what happens in the Windows arch. */ - if (printer->info_2->devmode && - printer->info_2->devmode->displayfrequency == MAGIC_DISPLAY_FREQUENCY) + if (!strequal(printer->info_2->drivername, old_printer->info_2->drivername)) { - - DEBUG(10,("update_printer: Save printer driver init data\n")); - printer->info_2->devmode->displayfrequency = 0; - - if (update_driver_init(*printer, 2)!=0) { - DEBUG(10,("update_printer: error updating printer driver init DEVMODE\n")); - result = WERR_ACCESS_DENIED; - goto done; - } - - /* we need to reset all driver init data for all printers - bound to this driver */ - - srv_spoolss_reset_printerdata( printer->info_2->drivername ); - - } - else - { - /* - * When a *new* driver is bound to a printer, the drivername is used to - * lookup previously saved driver initialization info, which is then - * bound to the printer, simulating what happens in the Windows arch. - */ - if (!strequal(printer->info_2->drivername, old_printer->info_2->drivername)) + if (!set_driver_init(printer, 2)) { - if (!set_driver_init(printer, 2)) - { - DEBUG(5,("update_printer: Error restoring driver initialization data for driver [%s]!\n", - printer->info_2->drivername)); - } - - DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n", + DEBUG(5,("update_printer: Error restoring driver initialization data for driver [%s]!\n", printer->info_2->drivername)); - - notify_printer_driver(snum, printer->info_2->drivername); } + + DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n", + printer->info_2->drivername)); + + notify_printer_driver(snum, printer->info_2->drivername); } /* Update printer info */ @@ -6594,8 +6946,11 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ */ if (!devmode) + { set_driver_init(printer, 2); - else { + } + else + { /* A valid devmode was included, convert and link it */ DEBUGADD(10, ("spoolss_addprinterex_level_2: devmode included, converting\n")); @@ -6605,8 +6960,6 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ return WERR_NOMEM; } - set_driver_init(printer, 2); - /* write the ASCII on disk */ err = mod_a_printer(*printer, 2); if (!W_ERROR_IS_OK(err)) { @@ -6905,7 +7258,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S uint32 idx = q_u->index; uint32 in_value_len = q_u->valuesize; uint32 in_data_len = q_u->datasize; - uint32 *out_max_value_len= &r_u->valuesize; + uint32 *out_max_value_len = &r_u->valuesize; uint16 **out_value = &r_u->value; uint32 *out_value_len = &r_u->realvaluesize; uint32 *out_type = &r_u->type; @@ -7112,7 +7465,8 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP * when connecting to a printer --jerry */ - if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) { + if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) + { DEBUG(3, ("_spoolss_setprinterdata: change denied by handle access permissions\n")); status = WERR_ACCESS_DENIED; goto done; @@ -7122,15 +7476,27 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP if (!W_ERROR_IS_OK(status)) return status; - /* save the registry data */ - unistr2_to_ascii( valuename, value, sizeof(valuename)-1 ); - delete_printer_data( printer->info_2, SPOOL_PRINTERDATA_KEY, valuename ); - add_printer_data( printer->info_2, SPOOL_PRINTERDATA_KEY, valuename, type, data, real_len ); - - /* write the **entire** printer out to disk.... :-( */ - status = mod_a_printer(*printer, 2); + /* + * When client side code sets a magic printer data key, detect it and save + * the current printer data and the magic key's data (its the DEVMODE) for + * future printer/driver initializations. + */ + if ( (type == REG_BINARY) && strequal( valuename, PHANTOM_DEVMODE_KEY)) + { + /* Set devmode and printer initialization info */ + status = save_driver_init( printer, 2, data, real_len ); + + srv_spoolss_reset_printerdata( printer->info_2->drivername ); + } + else + { + status = set_printer_dataex( printer, SPOOL_PRINTERDATA_KEY, valuename, + type, data, real_len ); + if ( W_ERROR_IS_OK(status) ) + status = mod_a_printer(*printer, 2); + } done: free_a_printer(&printer, 2); @@ -7204,9 +7570,7 @@ WERROR _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_ unistr2_to_ascii( valuename, value, sizeof(valuename)-1 ); - status = delete_printer_data( printer->info_2, SPOOL_PRINTERDATA_KEY, valuename ); - if ( NT_STATUS_IS_OK(status) ) - status = mod_a_printer(*printer, 2); + status = delete_printer_dataex( printer, SPOOL_PRINTERDATA_KEY, valuename ); free_a_printer(&printer, 2); @@ -7235,40 +7599,52 @@ WERROR _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM DEBUG(2,("_spoolss_addform: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); return WERR_BADFID; } + + + /* forms can be added on printer of on the print server handle */ + + if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTER ) + { + if (!get_printer_snum(p,handle, &snum)) + return WERR_BADFID; + + status = get_a_printer(&printer, 2, lp_servicename(snum)); + if (!W_ERROR_IS_OK(status)) + goto done; + } - if (!get_printer_snum(p,handle, &snum)) - return WERR_BADFID; - - if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) { + if ( !(Printer->access_granted & (PRINTER_ACCESS_ADMINISTER|SERVER_ACCESS_ADMINISTER)) ) { DEBUG(2,("_spoolss_addform: denied by handle permissions.\n")); status = WERR_ACCESS_DENIED; goto done; } - + /* can't add if builtin */ + if (get_a_builtin_ntform(&form->name,&tmpForm)) { - return WERR_ALREADY_EXISTS; + status = WERR_ALREADY_EXISTS; + goto done; } - count=get_ntforms(&list); - if(!add_a_form(&list, form, &count)) - return WERR_NOMEM; + count = get_ntforms(&list); + + if(!add_a_form(&list, form, &count)) { + status = WERR_NOMEM; + goto done; + } + write_ntforms(&list, count); /* - * ChangeID must always be set + * ChangeID must always be set if this is a printer */ - status = get_a_printer(&printer, 2, lp_servicename(snum)); - if (!W_ERROR_IS_OK(status)) - goto done; - - status = mod_a_printer(*printer, 2); - if (!W_ERROR_IS_OK(status)) - goto done; + if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTER ) + status = mod_a_printer(*printer, 2); done: - free_a_printer(&printer, 2); + if ( printer ) + free_a_printer(&printer, 2); SAFE_FREE(list); return status; @@ -7283,7 +7659,6 @@ WERROR _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE UNISTR2 *form_name = &q_u->name; nt_forms_struct tmpForm; int count=0; - WERROR ret = WERR_OK; nt_forms_struct *list=NULL; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); int snum; @@ -7297,40 +7672,49 @@ WERROR _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE return WERR_BADFID; } - if (!get_printer_snum(p, handle, &snum)) - return WERR_BADFID; + /* forms can be deleted on printer of on the print server handle */ + + if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTER ) + { + if (!get_printer_snum(p,handle, &snum)) + return WERR_BADFID; + + status = get_a_printer(&printer, 2, lp_servicename(snum)); + if (!W_ERROR_IS_OK(status)) + goto done; + } - if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) { - DEBUG(2,("_spoolss_deleteform: denied by handle permissions\n")); - return WERR_ACCESS_DENIED; + if ( !(Printer->access_granted & (PRINTER_ACCESS_ADMINISTER|SERVER_ACCESS_ADMINISTER)) ) { + DEBUG(2,("_spoolss_deleteform: denied by handle permissions.\n")); + status = WERR_ACCESS_DENIED; + goto done; } /* can't delete if builtin */ + if (get_a_builtin_ntform(form_name,&tmpForm)) { - return WERR_INVALID_PARAM; + status = WERR_INVALID_PARAM; + goto done; } count = get_ntforms(&list); - if(!delete_a_form(&list, form_name, &count, &ret)) - return WERR_INVALID_PARAM; + + if ( !delete_a_form(&list, form_name, &count, &status )) + goto done; /* - * ChangeID must always be set + * ChangeID must always be set if this is a printer */ - status = get_a_printer(&printer, 2, lp_servicename(snum)); - if (!W_ERROR_IS_OK(status)) - goto done; - - status = mod_a_printer(*printer, 2); - if (!W_ERROR_IS_OK(status)) - goto done; + if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTER ) + status = mod_a_printer(*printer, 2); done: - free_a_printer(&printer, 2); + if ( printer ) + free_a_printer(&printer, 2); SAFE_FREE(list); - return ret; + return status; } /**************************************************************************** @@ -7356,40 +7740,48 @@ WERROR _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM * return WERR_BADFID; } - if (!get_printer_snum(p, handle, &snum)) - return WERR_BADFID; + /* forms can be modified on printer of on the print server handle */ + + if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTER ) + { + if (!get_printer_snum(p,handle, &snum)) + return WERR_BADFID; + + status = get_a_printer(&printer, 2, lp_servicename(snum)); + if (!W_ERROR_IS_OK(status)) + goto done; + } - if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) { + if ( !(Printer->access_granted & (PRINTER_ACCESS_ADMINISTER|SERVER_ACCESS_ADMINISTER)) ) { DEBUG(2,("_spoolss_setform: denied by handle permissions\n")); - return WERR_ACCESS_DENIED; + status = WERR_ACCESS_DENIED; + goto done; } /* can't set if builtin */ if (get_a_builtin_ntform(&form->name,&tmpForm)) { - return WERR_INVALID_PARAM; + status = WERR_INVALID_PARAM; + goto done; } - count=get_ntforms(&list); + count = get_ntforms(&list); update_a_form(&list, form, count); write_ntforms(&list, count); /* - * ChangeID must always be set + * ChangeID must always be set if this is a printer */ - status = get_a_printer(&printer, 2, lp_servicename(snum)); - if (!W_ERROR_IS_OK(status)) - goto done; + if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTER ) + status = mod_a_printer(*printer, 2); - status = mod_a_printer(*printer, 2); - if (!W_ERROR_IS_OK(status)) - goto done; done: - free_a_printer(&printer, 2); + if ( printer ) + free_a_printer(&printer, 2); SAFE_FREE(list); - return WERR_OK; + return status; } /**************************************************************************** @@ -7638,7 +8030,7 @@ static WERROR getjob_level_1(print_queue_struct *queue, int count, int snum, uin return WERR_NOMEM; } - for (i=0; ioffered; uint32 *needed = &r_u->needed; + WERROR wstatus = WERR_OK; int snum; int count; - print_queue_struct *queue=NULL; + print_queue_struct *queue = NULL; print_status_struct prt_status; /* that's an [in out] buffer */ @@ -7764,7 +8172,7 @@ WERROR _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_ DEBUG(5,("spoolss_getjob\n")); - *needed=0; + *needed = 0; if (!get_printer_snum(p, handle, &snum)) return WERR_BADFID; @@ -7774,19 +8182,29 @@ WERROR _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_ DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n", count, prt_status.status, prt_status.message)); - switch (level) { + switch ( level ) { case 1: - return getjob_level_1(queue, count, snum, jobid, buffer, offered, needed); + wstatus = getjob_level_1(queue, count, snum, jobid, + buffer, offered, needed); + break; case 2: - return getjob_level_2(queue, count, snum, jobid, buffer, offered, needed); + wstatus = getjob_level_2(queue, count, snum, jobid, + buffer, offered, needed); + break; default: - SAFE_FREE(queue); - return WERR_UNKNOWN_LEVEL; + wstatus = WERR_UNKNOWN_LEVEL; + break; } + + SAFE_FREE(queue); + return wstatus; } /******************************************************************** - * spoolss_getprinterdataex + spoolss_getprinterdataex + + From MSDN documentation of GetPrinterDataEx: pass request + to GetPrinterData if key is "PrinterDriverData". ********************************************************************/ WERROR _spoolss_getprinterdataex(pipes_struct *p, SPOOL_Q_GETPRINTERDATAEX *q_u, SPOOL_R_GETPRINTERDATAEX *r_u) @@ -7797,112 +8215,181 @@ WERROR _spoolss_getprinterdataex(pipes_struct *p, SPOOL_Q_GETPRINTERDATAEX *q_u, uint32 *out_size = &r_u->size; uint8 **data = &r_u->data; uint32 *needed = &r_u->needed; - - fstring key, value; + fstring keyname, valuename; + Printer_entry *Printer = find_printer_index_by_hnd(p, handle); - BOOL found = False; + + NT_PRINTER_INFO_LEVEL *printer = NULL; + int snum = 0; + WERROR status = WERR_OK; DEBUG(4,("_spoolss_getprinterdataex\n")); - unistr2_to_ascii(key, &q_u->keyname, sizeof(key) - 1); - unistr2_to_ascii(value, &q_u->valuename, sizeof(value) - 1); + unistr2_to_ascii(keyname, &q_u->keyname, sizeof(keyname) - 1); + unistr2_to_ascii(valuename, &q_u->valuename, sizeof(valuename) - 1); + + DEBUG(10, ("_spoolss_getprinterdataex: key => [%s], value => [%s]\n", + keyname, valuename)); /* in case of problem, return some default values */ - *needed=0; - *type=0; - *out_size=0; + + *needed = 0; + *type = 0; + *out_size = in_size; - if (!Printer) { - if((*data=(uint8 *)talloc_zero(p->mem_ctx, 4*sizeof(uint8))) == NULL) - return WERR_NOMEM; - DEBUG(2,("_spoolss_getprinterdata: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); - return WERR_BADFID; + DEBUG(2,("_spoolss_getprinterdataex: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); + status = WERR_BADFID; + goto done; } - /* Is the handle to a printer or to the server? */ - if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) - { + if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) { DEBUG(10,("_spoolss_getprinterdatex: Not implemented for server handles yet\n")); - return WERR_INVALID_PARAM; + status = WERR_INVALID_PARAM; + goto done; } - else - { - /* - * From MSDN documentation of GetPrinterDataEx: pass request - * to GetPrinterData if key is "PrinterDriverData". This is - * the only key we really support. Other keys to implement: - * (a) DsDriver - * (b) DsSpooler - * (c) PnPData - * (d) DsUser - */ - - if (strcmp(key, SPOOL_PRINTERDATA_KEY) != 0) - return WERR_BADFILE; + + if ( !get_printer_snum(p,handle, &snum) ) + return WERR_BADFID; - DEBUG(10, ("_spoolss_getprinterdataex: pass me to getprinterdata\n")); - found = getprinterdata_printer(p, p->mem_ctx, handle, value, - type, data, needed, in_size); - + status = get_a_printer(&printer, 2, lp_servicename(snum)); + if ( !W_ERROR_IS_OK(status) ) + goto done; + + /* check to see if the keyname is valid */ + if ( !strlen(keyname) ) { + status = WERR_INVALID_PARAM; + goto done; } - - if (!found) { - DEBUG(5, ("value not found, allocating %d\n", *out_size)); + + if ( lookup_printerkey( &printer->info_2->data, keyname ) == -1 ) { + DEBUG(4,("_spoolss_getprinterdataex: Invalid keyname [%s]\n", keyname )); + free_a_printer( &printer, 2 ); + status = WERR_BADFILE; + goto done; + } + + /* When given a new keyname, we should just create it */ + + status = get_printer_dataex( p->mem_ctx, printer, keyname, valuename, type, data, needed, in_size ); + + if (*needed > *out_size) + status = WERR_MORE_DATA; + +done: + if ( !W_ERROR_IS_OK(status) ) + { + DEBUG(5, ("error: allocating %d\n", *out_size)); /* reply this param doesn't exist */ - if (*out_size) { - if((*data=(uint8 *)talloc_zero(p->mem_ctx, *out_size*sizeof(uint8))) == NULL) - return WERR_NOMEM; - } else { + + if ( *out_size ) + { + if( (*data=(uint8 *)talloc_zero(p->mem_ctx, *out_size*sizeof(uint8))) == NULL ) { + status = WERR_NOMEM; + goto done; + } + } + else { *data = NULL; - } - - return WERR_INVALID_PARAM; + } } - if (*needed > *out_size) - return WERR_MORE_DATA; - else - return WERR_OK; + if ( printer ) + free_a_printer( &printer, 2 ); + + return status; } /******************************************************************** - * spoolss_setprinterdata + * spoolss_setprinterdataex ********************************************************************/ WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, SPOOL_R_SETPRINTERDATAEX *r_u) { - SPOOL_Q_SETPRINTERDATA q_u_local; - SPOOL_R_SETPRINTERDATA r_u_local; - fstring key; + POLICY_HND *handle = &q_u->handle; + uint32 type = q_u->type; + uint8 *data = q_u->data; + uint32 real_len = q_u->real_len; + NT_PRINTER_INFO_LEVEL *printer = NULL; + int snum = 0; + WERROR status = WERR_OK; + Printer_entry *Printer = find_printer_index_by_hnd(p, handle); + fstring valuename; + fstring keyname; + char *oid_string; + DEBUG(4,("_spoolss_setprinterdataex\n")); /* From MSDN documentation of SetPrinterDataEx: pass request to SetPrinterData if key is "PrinterDriverData" */ - unistr2_to_ascii(key, &q_u->key, sizeof(key) - 1); + if (!Printer) { + DEBUG(2,("_spoolss_setprinterdata: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); + return WERR_BADFID; + } - if (strcmp(key, SPOOL_PRINTERDATA_KEY) != 0) - return WERR_INVALID_PARAM; - - ZERO_STRUCT(q_u_local); - ZERO_STRUCT(r_u_local); - - /* make a copy to call _spoolss_setprinterdata() */ - - memcpy(&q_u_local.handle, &q_u->handle, sizeof(POLICY_HND)); - copy_unistr2(&q_u_local.value, &q_u->value); - q_u_local.type = q_u->type; - q_u_local.max_len = q_u->max_len; - q_u_local.data = q_u->data; - q_u_local.real_len = q_u->real_len; - q_u_local.numeric_data = q_u->numeric_data; + if ( !get_printer_snum(p,handle, &snum) ) + return WERR_BADFID; + + /* + * Access check : NT returns "access denied" if you make a + * SetPrinterData call without the necessary privildge. + * we were originally returning OK if nothing changed + * which made Win2k issue **a lot** of SetPrinterData + * when connecting to a printer --jerry + */ + + if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) + { + DEBUG(3, ("_spoolss_setprinterdataex: change denied by handle access permissions\n")); + return WERR_ACCESS_DENIED; + } + + status = get_a_printer(&printer, 2, lp_servicename(snum)); + if (!W_ERROR_IS_OK(status)) + return status; + + unistr2_to_ascii( valuename, &q_u->value, sizeof(valuename) - 1); + unistr2_to_ascii( keyname, &q_u->key, sizeof(keyname) - 1); + + /* check for OID in valuename */ + + if ( (oid_string = strchr( valuename, ',' )) != NULL ) + { + *oid_string = '\0'; + oid_string++; + } + + /* save the registry data */ + + status = set_printer_dataex( printer, keyname, valuename, type, data, real_len ); + + /* save the OID if one was specified and the previous set call succeeded */ + + if ( W_ERROR_IS_OK(status) && oid_string ) + { + + fstrcat( keyname, "\\" ); + fstrcat( keyname, SPOOL_OID_KEY ); - return _spoolss_setprinterdata(p, &q_u_local, &r_u_local); + /* + * I'm not checking the status here on purpose. Don't know + * if this is right, but I'm returning the status from the + * previous set_printer_dataex() call. I have no idea if + * this is right. --jerry + */ + + set_printer_dataex( printer, keyname, valuename, + REG_SZ, (void*)oid_string, strlen(oid_string)+1 ); + } + + free_a_printer(&printer, 2); + + return status; } @@ -7912,26 +8399,44 @@ WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, WERROR _spoolss_deleteprinterdataex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATAEX *q_u, SPOOL_R_DELETEPRINTERDATAEX *r_u) { - SPOOL_Q_DELETEPRINTERDATA q_u_local; - SPOOL_R_DELETEPRINTERDATA r_u_local; - fstring key; - - /* From MSDN documentation of SetPrinterDataEx: pass request to - SetPrinterData if key is "PrinterDriverData" */ - - unistr2_to_ascii(key, &q_u->keyname, sizeof(key) - 1); + POLICY_HND *handle = &q_u->handle; + UNISTR2 *value = &q_u->valuename; + UNISTR2 *key = &q_u->keyname; - if (strcmp(key, SPOOL_PRINTERDATA_KEY) != 0) - return WERR_INVALID_PARAM; + NT_PRINTER_INFO_LEVEL *printer = NULL; + int snum=0; + WERROR status = WERR_OK; + Printer_entry *Printer=find_printer_index_by_hnd(p, handle); + pstring valuename, keyname; - memcpy(&q_u_local.handle, &q_u->handle, sizeof(POLICY_HND)); - copy_unistr2(&q_u_local.valuename, &q_u->valuename); + DEBUG(5,("spoolss_deleteprinterdataex\n")); - return _spoolss_deleteprinterdata( p, &q_u_local, &r_u_local ); -} + if (!Printer) { + DEBUG(2,("_spoolss_deleteprinterdata: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); + return WERR_BADFID; + } + + if (!get_printer_snum(p, handle, &snum)) + return WERR_BADFID; + + if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) { + DEBUG(3, ("_spoolss_deleteprinterdataex: printer properties change denied by handle\n")); + return WERR_ACCESS_DENIED; + } + + status = get_a_printer(&printer, 2, lp_servicename(snum)); + if (!W_ERROR_IS_OK(status)) + return status; + + unistr2_to_ascii( valuename, value, sizeof(valuename)-1 ); + unistr2_to_ascii( keyname, key, sizeof(keyname)-1 ); + status = delete_printer_dataex( printer, keyname, valuename ); + free_a_printer(&printer, 2); + return status; +} /******************************************************************** * spoolss_enumprinterkey @@ -7940,73 +8445,69 @@ WERROR _spoolss_deleteprinterdataex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATAEX WERROR _spoolss_enumprinterkey(pipes_struct *p, SPOOL_Q_ENUMPRINTERKEY *q_u, SPOOL_R_ENUMPRINTERKEY *r_u) { - fstring key; - uint16 *enumkeys = NULL; - char* ptr = NULL; - int i; - int printerkey_len = strlen(SPOOL_PRINTERDATA_KEY)+1; - + fstring key; + fstring *keynames = NULL; + uint16 *enumkeys = NULL; + int num_keys; + int printerkey_len; + POLICY_HND *handle = &q_u->handle; + Printer_entry *Printer = find_printer_index_by_hnd(p, handle); + NT_PRINTER_DATA *data; + NT_PRINTER_INFO_LEVEL *printer = NULL; + int snum = 0; + WERROR status = WERR_BADFILE; + + DEBUG(4,("_spoolss_enumprinterkey\n")); - unistr2_to_ascii( key, &q_u->key, sizeof(key)-1 ); + if (!Printer) { + DEBUG(2,("_spoolss_enumprinterkey: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); + return WERR_BADFID; + } - /* - * we only support enumating all keys (key == "") - * Of course, the only key we support is the "PrinterDriverData" - * key - */ + if ( !get_printer_snum(p,handle, &snum) ) + return WERR_BADFID; - if ( !strlen( key ) ) - { - r_u->needed = printerkey_len*2; + status = get_a_printer(&printer, 2, lp_servicename(snum)); + if (!W_ERROR_IS_OK(status)) + return status; - if ( q_u->size < r_u->needed ) - return WERR_MORE_DATA; + /* get the list of subkey names */ - if ( !(enumkeys = talloc( p->mem_ctx, printerkey_len*2 )) ) { - DEBUG(0,("_spoolss_enumprinterkey: talloc() failed for [%d] bytes!\n", - printerkey_len)); - return WERR_NOMEM; - } - - ptr = SPOOL_PRINTERDATA_KEY; - for ( i=0; i<(printerkey_len-1); i++ ) - { - enumkeys[i] = (uint16)(*ptr); - ptr++; - } + unistr2_to_ascii( key, &q_u->key, sizeof(key)-1 ); + data = &printer->info_2->data; - /* tag of '\0's */ - - enumkeys[i] = 0x0; - - if (!make_spoolss_buffer5(p->mem_ctx, &r_u->keys, printerkey_len, enumkeys)) - return WERR_BADFILE; - - return WERR_OK; + num_keys = get_printer_subkeys( data, key, &keynames ); + + if ( num_keys == -1 ) { + status = WERR_BADFILE; + goto done; } - - /* The "PrinterDriverData" key should have no subkeys */ - if ( strcmp(key, SPOOL_PRINTERDATA_KEY) == 0 ) - { - uint16 dummy_key = 0; - - r_u->needed = 2; - - if (q_u->size < r_u->needed) - return WERR_MORE_DATA; - - if ( !make_spoolss_buffer5(p->mem_ctx, &r_u->keys, 1, &dummy_key ) ) - return WERR_BADFILE; - - return WERR_OK; + + printerkey_len = init_unistr_array( &enumkeys, keynames, NULL ); + + r_u->needed = printerkey_len*2; + + if ( q_u->size < r_u->needed ) { + status = WERR_MORE_DATA; + goto done; } - - /* The return value for an unknown key is documented in MSDN - EnumPrinterKey description */ - - return WERR_BADFILE; + if (!make_spoolss_buffer5(p->mem_ctx, &r_u->keys, printerkey_len, enumkeys)) { + status = WERR_NOMEM; + goto done; + } + + status = WERR_OK; + + if ( q_u->size < r_u->needed ) + status = WERR_MORE_DATA; + +done: + free_a_printer( &printer, 2 ); + SAFE_FREE( keynames ); + + return status; } /******************************************************************** @@ -8015,25 +8516,49 @@ WERROR _spoolss_enumprinterkey(pipes_struct *p, SPOOL_Q_ENUMPRINTERKEY *q_u, SPO WERROR _spoolss_deleteprinterkey(pipes_struct *p, SPOOL_Q_DELETEPRINTERKEY *q_u, SPOOL_R_DELETEPRINTERKEY *r_u) { - Printer_entry *Printer = find_printer_index_by_hnd(p, &q_u->handle); - fstring key; + POLICY_HND *handle = &q_u->handle; + Printer_entry *Printer = find_printer_index_by_hnd(p, &q_u->handle); + fstring key; + NT_PRINTER_INFO_LEVEL *printer = NULL; + int snum=0; + WERROR status; + + DEBUG(5,("spoolss_deleteprinterkey\n")); if (!Printer) { - DEBUG(2,("_spoolss_deleteprinterkey: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(&q_u->handle))); + DEBUG(2,("_spoolss_deleteprinterkey: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); return WERR_BADFID; } + + /* if keyname == NULL, return error */ + + if ( !q_u->keyname.buffer ) + return WERR_INVALID_PARAM; + + if (!get_printer_snum(p, handle, &snum)) + return WERR_BADFID; + + if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) { + DEBUG(3, ("_spoolss_deleteprinterkey: printer properties change denied by handle\n")); + return WERR_ACCESS_DENIED; + } + + status = get_a_printer(&printer, 2, lp_servicename(snum)); + if (!W_ERROR_IS_OK(status)) + return status; + + /* delete the key and all subneys */ unistr2_to_ascii(key, &q_u->keyname, sizeof(key) - 1); + + status = delete_all_printer_data( printer->info_2, key ); - if (strcmp(key, SPOOL_PRINTERDATA_KEY) != 0) - return WERR_INVALID_PARAM; - - /* - * this is what 2k returns when you try to delete the "PrinterDriverData" - * key - */ - - return WERR_ACCESS_DENIED; + if ( W_ERROR_IS_OK(status) ) + status = mod_a_printer(*printer, 2); + + free_a_printer( &printer, 2 ); + + return status; } @@ -8068,7 +8593,6 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ return WERR_BADFID; } - /* first get the printer off of disk */ if (!get_printer_snum(p,handle, &snum)) -- cgit From c56213607cd1e9d8a4d98b3aa1e9c36b4d3b275a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 27 Sep 2002 22:51:44 +0000 Subject: It turns out that Windows allows delete printer on a handle opened by an admin user, then used on a pipe handle created by an anonymous user..... but they're working on security.... riiight ! Jeremy. (This used to be commit e96e6a60b82b71714120ce7636fa8402007d4b03) --- source3/rpc_server/srv_spoolss_nt.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 2190215107..e60a1d2063 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -318,6 +318,19 @@ static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) return WERR_BADFID; } + /* + * It turns out that Windows allows delete printer on a handle + * opened by an admin user, then used on a pipe handle created + * by an anonymous user..... but they're working on security.... riiight ! + * JRA. + */ + + if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) { + DEBUG(3, ("delete_printer_handle: denied by handle\n")); + return WERR_ACCESS_DENIED; + } + +#if 0 /* Check calling user has permission to delete printer. Note that since we set the snum parameter to -1 only administrators can delete the printer. This stops people with the Full Control @@ -327,6 +340,7 @@ static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) DEBUG(3, ("printer delete denied by security descriptor\n")); return WERR_ACCESS_DENIED; } +#endif if (*lp_deleteprinter_cmd()) { -- cgit From f2d1f19a66ebaf9b88d23c0faa2412536cc74cda Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 1 Oct 2002 18:26:00 +0000 Subject: syncing up with HEAD. Seems to be a lot of differences creeping in (i ignored the new SAMBA stuff, but the rest of this looks like it should have been merged already). (This used to be commit 3de09e5cf1f667e410ee8b9516a956860ce7290f) --- source3/rpc_server/srv_spoolss_nt.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index e60a1d2063..f942a685a1 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -313,11 +313,6 @@ static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) return WERR_BADFID; } - if (del_a_printer(Printer->dev.handlename) != 0) { - DEBUG(3,("Error deleting printer %s\n", Printer->dev.handlename)); - return WERR_BADFID; - } - /* * It turns out that Windows allows delete printer on a handle * opened by an admin user, then used on a pipe handle created @@ -342,6 +337,11 @@ static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) } #endif + if (del_a_printer(Printer->dev.handlename) != 0) { + DEBUG(3,("Error deleting printer %s\n", Printer->dev.handlename)); + return WERR_BADFID; + } + if (*lp_deleteprinter_cmd()) { char *cmd = lp_deleteprinter_cmd(); -- cgit From c4596dcf32902b9c7375d84c8a079d30677054fc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 2 Oct 2002 22:55:28 +0000 Subject: Missing break meant getprintprocessordirectory always returned UNKNOWN_LEVEL. Jeremy. (This used to be commit a9a959b85d110c4a6b9ac8988d35aee9a4d6b9f1) --- source3/rpc_server/srv_spoolss_nt.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index f942a685a1..12d6639348 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -8776,6 +8776,7 @@ WERROR _spoolss_getprintprocessordirectory(pipes_struct *p, SPOOL_Q_GETPRINTPROC case 1: result = getprintprocessordirectory_level_1 (&q_u->name, &q_u->environment, buffer, offered, needed); + break; default: result = WERR_UNKNOWN_LEVEL; } -- cgit From 36ef82a52953384acedbd51f54ded9357fa8ca3e Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 4 Oct 2002 04:10:23 +0000 Subject: merge of new client side support the Win2k LSARPC UUID in rpcbind from APP_HEAD (This used to be commit 1cfd2ee433305e91e87804dd55d10e025d30a69e) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 12d6639348..41ef599a3c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2375,7 +2375,7 @@ static BOOL spoolss_connect_to_client(struct cli_state *the_cli, char *remote_ma * Now start the NT Domain stuff :-). */ - if(cli_nt_session_open(the_cli, PIPE_SPOOLSS) == False) { + if(cli_nt_session_open(the_cli, PI_SPOOLSS) == False) { DEBUG(0,("connect_to_client: unable to open the domain client session to machine %s. Error was : %s.\n", remote_machine, cli_errstr(the_cli))); cli_nt_session_close(the_cli); cli_ulogoff(the_cli); -- cgit From bfa93735abe52fe07fde1b10ece0c31f5cf73ef8 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 8 Oct 2002 18:32:42 +0000 Subject: merge from APP_HEAD of winbindd's domain local group fix (This used to be commit 09c6f6329d6ae9327b7ef06de0ea78d24d805456) --- source3/rpc_server/srv_spoolss_nt.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 41ef599a3c..2851ed79c6 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -5603,23 +5603,17 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) char *cmd = lp_addprinter_cmd(); char **qlines; pstring command; - pstring driverlocation; int numlines; int ret; int fd; fstring remote_machine = "%m"; - /* build driver path... only 9X architecture is needed for legacy reasons */ - slprintf(driverlocation, sizeof(driverlocation)-1, "\\\\%s\\print$\\WIN40\\0", - get_called_name()); - /* change \ to \\ for the shell */ - all_string_sub(driverlocation,"\\","\\\\",sizeof(pstring)); standard_sub_basic(current_user_info.smb_name, remote_machine,sizeof(remote_machine)); slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"", cmd, printer->info_2->printername, printer->info_2->sharename, printer->info_2->portname, printer->info_2->drivername, - printer->info_2->location, driverlocation, remote_machine); + printer->info_2->location, printer->info_2->comment, remote_machine); DEBUG(10,("Running [%s]\n", command)); ret = smbrun(command, &fd); -- cgit From b57d0e060df0a83b0e74439974563c46796064a1 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 9 Oct 2002 16:59:45 +0000 Subject: add_printer_hook() fix from APP_HEAD (This used to be commit b381ed3a9eba24c11796a9ca5cb4d226c131d867) --- source3/rpc_server/srv_spoolss_nt.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 2851ed79c6..a1eb99cb32 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -363,10 +363,10 @@ static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) /* Send SIGHUP to process group... is there a better way? */ kill(0, SIGHUP); - if ( ( i = lp_servicenumber( Printer->dev.handlename ) ) >= 0 ) { - lp_killservice( i ); - return WERR_OK; - } else + /* go ahead and re-read the services immediately */ + reload_services( False ); + + if ( ( i = lp_servicenumber( Printer->dev.handlename ) ) < 0 ) return WERR_ACCESS_DENIED; } @@ -5638,7 +5638,9 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) /* Send SIGHUP to process group... is there a better way? */ kill(0, SIGHUP); - add_all_printers(); + + /* reload our services immediately */ + reload_services( False ); } file_lines_free(qlines); @@ -5709,6 +5711,13 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, result = WERR_NOMEM; goto done; } + + /* + * make sure we actually reload the services after + * this as smb.conf could have a new section in it + * .... shouldn't .... but could + */ + reload_services(False); } /* Do sanity check on the requested changes for Samba */ @@ -6918,15 +6927,17 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ return WERR_PRINTER_ALREADY_EXISTS; } - if (*lp_addprinter_cmd() ) + if (*lp_addprinter_cmd() ) { if ( !add_printer_hook(printer) ) { free_a_printer(&printer,2); return WERR_ACCESS_DENIED; } + } slprintf(name, sizeof(name)-1, "\\\\%s\\%s", get_called_name(), printer->info_2->sharename); + if ((snum = print_queue_snum(printer->info_2->sharename)) == -1) { free_a_printer(&printer,2); return WERR_ACCESS_DENIED; -- cgit From 9c25d8907088ef35eef396df5a13074f445adacd Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 9 Oct 2002 18:55:35 +0000 Subject: print job properties fix from APP_HEAD. a null devmode is not a failure. (This used to be commit 8f95773e0ab0c5e0854d9e442170e25280279bfb) --- source3/rpc_server/srv_spoolss_nt.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a1eb99cb32..c5d46abe57 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6017,11 +6017,9 @@ static WERROR enumjobs_level2(print_queue_struct *queue, int snum, goto done; } - if (!(devmode = construct_dev_mode(snum))) { - *returned = 0; - result = WERR_NOMEM; - goto done; - } + /* this should not be a failure condition if the devmode is NULL */ + + devmode = construct_dev_mode(snum); for (i=0; i<*returned; i++) fill_job_info_2(&(info[i]), &queue[i], i, snum, ntprinter, @@ -8122,7 +8120,8 @@ static WERROR getjob_level_2(print_queue_struct *queue, int count, int snum, uin /* * if the print job does not have a DEVMODE associated with it, - * just use the one for the printer + * just use the one for the printer. A NULL devicemode is not + * a failure condition */ if ( !(nt_devmode=print_job_devmode( snum, jobid )) ) @@ -8134,11 +8133,6 @@ static WERROR getjob_level_2(print_queue_struct *queue, int count, int snum, uin } } - if ( !devmode ) { - ret = WERR_NOMEM; - goto done; - } - fill_job_info_2(info_2, &(queue[i-1]), i, snum, ntprinter, devmode); *needed += spoolss_size_job_info_2(info_2); -- cgit From 4bdfae3df718e1d4945a02f1a317029c54bae883 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 15 Oct 2002 00:35:12 +0000 Subject: merge from APP_HEAD to use GMT in job submission notification (This used to be commit 2ec53858d9ee01ed500f99a67e9a94e33576486d) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index c5d46abe57..a4dcfdcec9 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -676,7 +676,7 @@ static void notify_system_time(struct spoolss_notify_msg *msg, return; } - if (!make_systemtime(&systime, localtime((time_t *)msg->notify.data))) { + if (!make_systemtime(&systime, gmtime((time_t *)msg->notify.data))) { DEBUG(5, ("notify_system_time: unable to make systemtime\n")); return; } -- cgit From 378fd95ce872912bd2e21c87dd7369f5056203b8 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 16 Oct 2002 18:23:15 +0000 Subject: merge from app_head to commit re-init'd printer to disk (This used to be commit 92fd939c3439208660ac3821c458f8cd34a59555) --- source3/rpc_server/srv_spoolss_nt.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a4dcfdcec9..3e6d5d6594 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1273,6 +1273,12 @@ void reset_all_printerdata(int msg_type, pid_t src, void *buf, size_t len) DEBUG(5,("reset_all_printerdata: Error resetting printer data for printer [%s], driver [%s]!\n", printer->info_2->printername, printer->info_2->drivername)); } + + result = mod_a_printer( *printer, 2 ); + if ( !W_ERROR_IS_OK(result) ) { + DEBUG(3,("reset_all_printerdata: mod_a_printer() failed! (%s)\n", + get_dos_error_msg(result))); + } } free_a_printer( &printer, 2 ); -- cgit From 35357e85891f24636bb563ae23569ac83517cbae Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 25 Oct 2002 22:16:00 +0000 Subject: merge PURGE_PRINTER fix from APP_HEAD (This used to be commit 4d32e6bdb6500f442ff3cda7d43bdf506a08eacf) --- source3/rpc_server/srv_spoolss_nt.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 3e6d5d6594..a5e464f73b 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -5441,13 +5441,11 @@ static WERROR control_printer(POLICY_HND *handle, uint32 command, errcode = WERR_OK; } break; -#if 0 /* JERRY - Never called */ case PRINTER_CONTROL_PURGE: if (print_queue_purge(&user, snum, &errcode)) { errcode = WERR_OK; } break; -#endif default: return WERR_UNKNOWN_LEVEL; } -- cgit From 93042487882d8b2407541ad21d2e9bc2b59142e5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 7 Nov 2002 02:15:35 +0000 Subject: Merge of scalable printing code fix... Needs testing. Jeremy. (This used to be commit d030df76439c72825d68410211e62090438cef54) --- source3/rpc_server/srv_spoolss_nt.c | 38 ++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a5e464f73b..245df2003f 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -178,10 +178,18 @@ static void free_spool_notify_option(SPOOL_NOTIFY_OPTION **pp) Disconnect from the client ****************************************************************************/ -static void srv_spoolss_replycloseprinter(POLICY_HND *handle) +static void srv_spoolss_replycloseprinter(int snum, POLICY_HND *handle) { WERROR result; + /* + * Tell the specific printing tdb we no longer want messages for this printer + * by deregistering our PID. + */ + + if (!print_notify_deregister_pid(snum)) + DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", lp_const_servicename(snum) )); + /* weird if the test succeds !!! */ if (smb_connections==0) { DEBUG(0,("srv_spoolss_replycloseprinter:Trying to close non-existant notify backchannel !\n")); @@ -219,7 +227,8 @@ static void free_printer_entry(void *ptr) Printer_entry *Printer = (Printer_entry *)ptr; if (Printer->notify.client_connected==True) - srv_spoolss_replycloseprinter(&Printer->notify.client_hnd); + srv_spoolss_replycloseprinter(print_queue_snum(Printer->dev.handlename), + &Printer->notify.client_hnd); Printer->notify.flags=0; Printer->notify.options=0; @@ -2305,7 +2314,7 @@ done: Connect to the client machine. **********************************************************/ -static BOOL spoolss_connect_to_client(struct cli_state *the_cli, char *remote_machine) +static BOOL spoolss_connect_to_client(struct cli_state *the_cli, const char *remote_machine) { extern pstring global_myname; @@ -2396,7 +2405,7 @@ static BOOL spoolss_connect_to_client(struct cli_state *the_cli, char *remote_ma Connect to the client. ****************************************************************************/ -static BOOL srv_spoolss_replyopenprinter(char *printer, uint32 localprinter, uint32 type, POLICY_HND *handle) +static BOOL srv_spoolss_replyopenprinter(int snum, const char *printer, uint32 localprinter, uint32 type, POLICY_HND *handle) { WERROR result; @@ -2418,6 +2427,14 @@ static BOOL srv_spoolss_replyopenprinter(char *printer, uint32 localprinter, uin register_message_flags( True, FLAG_MSG_PRINTING ); } + /* + * Tell the specific printing tdb we want messages for this printer + * by registering our PID. + */ + + if (!print_notify_register_pid(snum)) + DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", printer )); + smb_connections++; result = cli_spoolss_reply_open_printer(¬ify_cli, notify_cli.mem_ctx, printer, localprinter, @@ -2448,6 +2465,7 @@ WERROR _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE uint32 options = q_u->options; UNISTR2 *localmachine = &q_u->localmachine; uint32 printerlocal = q_u->printerlocal; + int snum; SPOOL_NOTIFY_OPTION *option = q_u->option; /* store the notify value in the printer struct */ @@ -2459,6 +2477,9 @@ WERROR _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE return WERR_BADFID; } + if (!get_printer_snum(p, handle, &snum)) + return WERR_BADFID; + Printer->notify.flags=flags; Printer->notify.options=options; Printer->notify.printerlocal=printerlocal; @@ -2473,7 +2494,7 @@ WERROR _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE /* Connect to the client machine and send a ReplyOpenPrinter */ - if(!srv_spoolss_replyopenprinter(Printer->notify.localmachine, + if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine, Printer->notify.printerlocal, 1, &Printer->notify.client_hnd)) return WERR_SERVER_UNAVAILABLE; @@ -5832,7 +5853,7 @@ WERROR _spoolss_setprinter(pipes_struct *p, SPOOL_Q_SETPRINTER *q_u, SPOOL_R_SET WERROR _spoolss_fcpn(pipes_struct *p, SPOOL_Q_FCPN *q_u, SPOOL_R_FCPN *r_u) { POLICY_HND *handle = &q_u->handle; - + int snum; Printer_entry *Printer= find_printer_index_by_hnd(p, handle); if (!Printer) { @@ -5840,8 +5861,11 @@ WERROR _spoolss_fcpn(pipes_struct *p, SPOOL_Q_FCPN *q_u, SPOOL_R_FCPN *r_u) return WERR_BADFID; } + if (!get_printer_snum(p, handle, &snum)) + return WERR_BADFID; + if (Printer->notify.client_connected==True) - srv_spoolss_replycloseprinter(&Printer->notify.client_hnd); + srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd); Printer->notify.flags=0; Printer->notify.options=0; -- cgit From 2d08c914d782087ab0360aed9387ec1524d273d6 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sat, 9 Nov 2002 05:42:37 +0000 Subject: re-enable ffpcn on print server handle (This used to be commit 47a0c68fa9e98ab761e609d889894db1de9520db) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 245df2003f..5ebefc5ea0 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2477,7 +2477,7 @@ WERROR _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE return WERR_BADFID; } - if (!get_printer_snum(p, handle, &snum)) + if ( (Printer->printer_type == PRINTER_HANDLE_IS_PRINTER) && !get_printer_snum(p, handle, &snum) ) return WERR_BADFID; Printer->notify.flags=flags; -- cgit From cda79e5d36711317f055f3724c354fec000be86a Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sat, 9 Nov 2002 14:49:26 +0000 Subject: deldriver fix (This used to be commit 78ff2cc34aedaf82d965a71e0c9dfdeb86a90fdd) --- source3/rpc_server/srv_spoolss_nt.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 5ebefc5ea0..f8262110ce 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1908,6 +1908,12 @@ WERROR _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER goto done; } } + /* otherwise it was a failure */ + else { + status = WERR_UNKNOWN_PRINTER_DRIVER; + goto done; + } + } if (printer_driver_in_use(info.info_3)) { -- cgit From fc2dc328e157d625d6fb4baa5d46cab2bd2a8a4f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 10 Nov 2002 22:24:00 +0000 Subject: First cut of fix for changenotify on a print server handle. Use the connections tdb with an snum of -1 and a special printername. Jeremy. (This used to be commit 06b04380078ad840768a2c5a803f02669f54bc82) --- source3/rpc_server/srv_spoolss_nt.c | 40 +++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 11 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index f8262110ce..2227d39f44 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -226,9 +226,19 @@ static void free_printer_entry(void *ptr) { Printer_entry *Printer = (Printer_entry *)ptr; - if (Printer->notify.client_connected==True) - srv_spoolss_replycloseprinter(print_queue_snum(Printer->dev.handlename), - &Printer->notify.client_hnd); + if (Printer->notify.client_connected==True) { + int snum = -1; + + if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) { + snum = -1; + srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd); + } else if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTER) { + snum = print_queue_snum(Printer->dev.handlename); + if (snum != -1) + srv_spoolss_replycloseprinter(snum, + &Printer->notify.client_hnd); + } + } Printer->notify.flags=0; Printer->notify.options=0; @@ -2471,7 +2481,7 @@ WERROR _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE uint32 options = q_u->options; UNISTR2 *localmachine = &q_u->localmachine; uint32 printerlocal = q_u->printerlocal; - int snum; + int snum = -1; SPOOL_NOTIFY_OPTION *option = q_u->option; /* store the notify value in the printer struct */ @@ -2483,9 +2493,6 @@ WERROR _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE return WERR_BADFID; } - if ( (Printer->printer_type == PRINTER_HANDLE_IS_PRINTER) && !get_printer_snum(p, handle, &snum) ) - return WERR_BADFID; - Printer->notify.flags=flags; Printer->notify.options=options; Printer->notify.printerlocal=printerlocal; @@ -2500,6 +2507,12 @@ WERROR _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE /* Connect to the client machine and send a ReplyOpenPrinter */ + if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) + snum = -1; + else if ( (Printer->printer_type == PRINTER_HANDLE_IS_PRINTER) && + !get_printer_snum(p, handle, &snum) ) + return WERR_BADFID; + if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine, Printer->notify.printerlocal, 1, &Printer->notify.client_hnd)) @@ -5859,7 +5872,6 @@ WERROR _spoolss_setprinter(pipes_struct *p, SPOOL_Q_SETPRINTER *q_u, SPOOL_R_SET WERROR _spoolss_fcpn(pipes_struct *p, SPOOL_Q_FCPN *q_u, SPOOL_R_FCPN *r_u) { POLICY_HND *handle = &q_u->handle; - int snum; Printer_entry *Printer= find_printer_index_by_hnd(p, handle); if (!Printer) { @@ -5867,11 +5879,17 @@ WERROR _spoolss_fcpn(pipes_struct *p, SPOOL_Q_FCPN *q_u, SPOOL_R_FCPN *r_u) return WERR_BADFID; } - if (!get_printer_snum(p, handle, &snum)) - return WERR_BADFID; + if (Printer->notify.client_connected==True) { + int snum = -1; + + if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) + snum = -1; + else if ( (Printer->printer_type == PRINTER_HANDLE_IS_PRINTER) && + !get_printer_snum(p, handle, &snum) ) + return WERR_BADFID; - if (Printer->notify.client_connected==True) srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd); + } Printer->notify.flags=0; Printer->notify.options=0; -- cgit From 9b62172031ed16221821ad7a975e48c140e4ff26 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 11 Nov 2002 22:05:32 +0000 Subject: fix for CR 601. Only call addprinter command when the port, driver, comment, or location field changed (This used to be commit 62a19247d31b1e5b81767880182b40ba396b261a) --- source3/rpc_server/srv_spoolss_nt.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 2227d39f44..871aac8e68 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -5780,8 +5780,14 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, } /* Call addprinter hook */ - - if (*lp_addprinter_cmd()) { + /* Check changes to see if this is really needed */ + + if ( *lp_addprinter_cmd() + && (!strequal(printer->info_2->drivername, old_printer->info_2->drivername) + || !strequal(printer->info_2->comment, old_printer->info_2->comment) + || !strequal(printer->info_2->portname, old_printer->info_2->portname) + || !strequal(printer->info_2->location, old_printer->info_2->location)) ) + { if ( !add_printer_hook(printer) ) { result = WERR_ACCESS_DENIED; goto done; -- cgit From 2f194322d419350f35a48dff750066894d68eccf Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 12 Nov 2002 23:20:50 +0000 Subject: Removed global_myworkgroup, global_myname, global_myscope. Added liberal dashes of const. This is a rather large check-in, some things may break. It does compile though :-). Jeremy. (This used to be commit f755711df8f74f9b8e8c1a2b0d07d02a931eeb89) --- source3/rpc_server/srv_spoolss_nt.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 871aac8e68..ad55ea6a49 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2332,8 +2332,6 @@ done: static BOOL spoolss_connect_to_client(struct cli_state *the_cli, const char *remote_machine) { - extern pstring global_myname; - ZERO_STRUCTP(the_cli); if(cli_initialise(the_cli) == NULL) { DEBUG(0,("connect_to_client: unable to initialize client connection.\n")); @@ -2358,7 +2356,7 @@ static BOOL spoolss_connect_to_client(struct cli_state *the_cli, const char *rem return False; } - if (!attempt_netbios_session_request(the_cli, global_myname, remote_machine, &the_cli->dest_ip)) { + if (!attempt_netbios_session_request(the_cli, global_myname(), remote_machine, &the_cli->dest_ip)) { DEBUG(0,("connect_to_client: machine %s rejected the NetBIOS session request.\n", remote_machine)); cli_shutdown(the_cli); -- cgit From a850e90080cd12fa3c8b92028c8984164494f508 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 4 Dec 2002 01:15:50 +0000 Subject: [merge from app_head] XP sends GetPrinterData("ChangeId"). So we now respond accordingly. Possible fix for CR 1147. (This used to be commit 9424a3b1d1bf11bf38e2bdfd20f1537cf97400ca) --- source3/rpc_server/srv_spoolss_nt.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index ad55ea6a49..9e4b31813f 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2292,8 +2292,21 @@ WERROR _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO status = get_a_printer(&printer, 2, lp_servicename(snum)); if ( !W_ERROR_IS_OK(status) ) goto done; - - status = get_printer_dataex( p->mem_ctx, printer, SPOOL_PRINTERDATA_KEY, value, type, data, needed, *out_size ); + + /* XP sends this and wants to change id value from the PRINTER_INFO_0 */ + + if ( strequal(value, "ChangeId") ) { + *type = REG_DWORD; + *needed = sizeof(uint32); + if ( (*data = (uint8*)talloc(p->mem_ctx, sizeof(uint32))) == NULL) { + status = WERR_NOMEM; + goto done; + } + **data = printer->info_2->changeid; + status = WERR_OK; + } + else + status = get_printer_dataex( p->mem_ctx, printer, SPOOL_PRINTERDATA_KEY, value, type, data, needed, *out_size ); } if (*needed > *out_size) -- cgit From dae62a3d2ed67998a77ec0ffe4f1540bdcc4fe40 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Wed, 4 Dec 2002 17:40:50 +0000 Subject: Automatic printer publishing when using APW or choosing 'list in the directory' in printer settings. Currently very little is published, and you cannot unpublish because of a bug in win2k clients. (This used to be commit ca6360e8db30fc9be3fe3718c8b49c92dba5ecac) --- source3/rpc_server/srv_spoolss_nt.c | 207 +++++++++++++++++++++++++++--------- 1 file changed, 154 insertions(+), 53 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 9e4b31813f..fd22330449 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -30,7 +30,6 @@ #undef DBGC_CLASS #define DBGC_CLASS DBGC_RPC_SRV -/* #define EMULATE_WIN2K_HACK 1 */ #ifndef MAX_OPEN_PRINTER_EXS #define MAX_OPEN_PRINTER_EXS 50 @@ -962,60 +961,60 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) { SPOOLSS_NOTIFY_MSG *msg = &messages[i]; - /* Are we monitoring this event? */ + /* Are we monitoring this event? */ - if (!is_monitoring_event(p, msg->type, msg->field)) - continue; + if (!is_monitoring_event(p, msg->type, msg->field)) + continue; - DEBUG(10,("process_notify2_message: Sending message type [%x] field [%x] for printer [%s]\n", - msg->type, msg->field, p->dev.handlename)); + DEBUG(10,("process_notify2_message: Sending message type [%x] field [%x] for printer [%s]\n", + msg->type, msg->field, p->dev.handlename)); - /* - * if the is a printer notification handle and not a job notification - * type, then set the id to 0. Other wise just use what was specified - * in the message. - * - * When registering change notification on a print server handle - * we always need to send back the id (snum) matching the printer - * for which the change took place. For change notify registered - * on a printer handle, this does not matter and the id should be 0. - * - * --jerry - */ + /* + * if the is a printer notification handle and not a job notification + * type, then set the id to 0. Other wise just use what was specified + * in the message. + * + * When registering change notification on a print server handle + * we always need to send back the id (snum) matching the printer + * for which the change took place. For change notify registered + * on a printer handle, this does not matter and the id should be 0. + * + * --jerry + */ - if ( ( p->printer_type == PRINTER_HANDLE_IS_PRINTER ) && ( msg->type == PRINTER_NOTIFY_TYPE ) ) - id = 0; - else - id = msg->id; + if ( ( p->printer_type == PRINTER_HANDLE_IS_PRINTER ) && ( msg->type == PRINTER_NOTIFY_TYPE ) ) + id = 0; + else + id = msg->id; - /* Convert unix jobid to smb jobid */ + /* Convert unix jobid to smb jobid */ if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) { - id = sysjob_to_jobid(msg->id); + id = sysjob_to_jobid(msg->id); - if (id == -1) { - DEBUG(3, ("no such unix jobid %d\n", msg->id)); - goto done; + if (id == -1) { + DEBUG(3, ("no such unix jobid %d\n", msg->id)); + goto done; + } } - } construct_info_data( &data[data_len], msg->type, msg->field, id ); - switch(msg->type) { - case PRINTER_NOTIFY_TYPE: + switch(msg->type) { + case PRINTER_NOTIFY_TYPE: if ( !printer_notify_table[msg->field].fn ) - goto done; - printer_notify_table[msg->field].fn(msg, &data[data_len], mem_ctx); + goto done; + printer_notify_table[msg->field].fn(msg, &data[data_len], mem_ctx); - break; + break; - case JOB_NOTIFY_TYPE: + case JOB_NOTIFY_TYPE: if ( !job_notify_table[msg->field].fn ) - goto done; - job_notify_table[msg->field].fn(msg, &data[data_len], mem_ctx); + goto done; + job_notify_table[msg->field].fn(msg, &data[data_len], mem_ctx); break; @@ -2153,7 +2152,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint DEBUG(8,("getprinterdata_printer_server:%s\n", value)); - if (!strcmp(value, "W3SvcInstalled")) { + if (!StrCaseCmp(value, "W3SvcInstalled")) { *type = 0x4; if((*data = (uint8 *)talloc_zero(ctx, 4*sizeof(uint8) )) == NULL) return WERR_NOMEM; @@ -2161,7 +2160,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint return WERR_OK; } - if (!strcmp(value, "BeepEnabled")) { + if (!StrCaseCmp(value, "BeepEnabled")) { *type = 0x4; if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) return WERR_NOMEM; @@ -2170,7 +2169,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint return WERR_OK; } - if (!strcmp(value, "EventLog")) { + if (!StrCaseCmp(value, "EventLog")) { *type = 0x4; if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) return WERR_NOMEM; @@ -2180,7 +2179,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint return WERR_OK; } - if (!strcmp(value, "NetPopup")) { + if (!StrCaseCmp(value, "NetPopup")) { *type = 0x4; if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) return WERR_NOMEM; @@ -2189,20 +2188,20 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint return WERR_OK; } - if (!strcmp(value, "MajorVersion")) { + if (!StrCaseCmp(value, "MajorVersion")) { *type = 0x4; if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) return WERR_NOMEM; -#ifndef EMULATE_WIN2K_HACK /* JERRY */ - SIVAL(*data, 0, 2); -#else +#ifdef HAVE_ADS SIVAL(*data, 0, 3); +#else + SIVAL(*data, 0, 2); #endif *needed = 0x4; return WERR_OK; } - if (!strcmp(value, "DefaultSpoolDirectory")) { + if (!StrCaseCmp(value, "DefaultSpoolDirectory")) { fstring string; fstrcpy(string, string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH)); @@ -2220,7 +2219,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint return WERR_OK; } - if (!strcmp(value, "Architecture")) { + if (!StrCaseCmp(value, "Architecture")) { pstring string="Windows NT x86"; *type = 0x1; *needed = 2*(strlen(string)+1); @@ -2233,8 +2232,35 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint } return WERR_OK; } - - return WERR_INVALID_PARAM; + + if (!StrCaseCmp(value, "DsPresent")) { + *type = 0x4; + if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) + return WERR_NOMEM; + SIVAL(*data, 0, 0x01); + *needed = 0x4; + return WERR_OK; + } + + if (!StrCaseCmp(value, "DNSMachineName")) { + pstring hostname; + + if (!get_myfullname(hostname)) + return WERR_BADFILE; + *type = 0x1; + *needed = 2*(strlen(hostname)+1); + if((*data = (uint8 *)talloc(ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL) + return WERR_NOMEM; + memset(*data, 0, (*needed > in_size) ? *needed:in_size); + for (i=0; iglobal_counter = global_counter; printer->total_pages = 0; -#ifndef EMULATE_WIN2K_HACK /* JERRY */ - printer->major_version = 0x0004; /* NT 4 */ - printer->build_version = 0x0565; /* build 1381 */ -#else +#ifdef HAVE_ADS printer->major_version = 0x0005; /* NT 5 */ printer->build_version = 0x0893; /* build 2195 */ +#else + printer->major_version = 0x0004; /* NT 4 */ + printer->build_version = 0x0565; /* build 1381 */ #endif printer->unknown7 = 0x1; printer->unknown8 = 0x0; @@ -4121,6 +4147,18 @@ static BOOL construct_printer_info_5(PRINTER_INFO_5 *printer, int snum) return True; } +/******************************************************************** + * construct_printer_info_5 + * fill a printer_info_5 struct + ********************************************************************/ + +static BOOL construct_printer_info_7(PRINTER_INFO_7 *printer) +{ + init_unistr(&printer->guid, ""); + printer->action = 0; + return True; +} + /******************************************************************** Spoolss_enumprinters. ********************************************************************/ @@ -4677,6 +4715,37 @@ static WERROR getprinter_level_5(int snum, NEW_BUFFER *buffer, uint32 offered, u return WERR_OK; } +static WERROR getprinter_level_7(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +{ + PRINTER_INFO_7 *printer=NULL; + + if((printer=(PRINTER_INFO_7*)malloc(sizeof(PRINTER_INFO_7)))==NULL) + return WERR_NOMEM; + + if (!construct_printer_info_7(printer)) + return WERR_NOMEM; + + /* check the required size. */ + *needed += spoolss_size_printer_info_7(printer); + + if (!alloc_buffer_size(buffer, *needed)) { + free_printer_info_7(printer); + return WERR_INSUFFICIENT_BUFFER; + } + + /* fill the buffer with the structures */ + smb_io_printer_info_7("", buffer, printer, 0); + + /* clear memory */ + free_printer_info_7(printer); + + if (*needed > offered) { + return WERR_INSUFFICIENT_BUFFER; + } + + return WERR_OK; +} + /**************************************************************************** ****************************************************************************/ @@ -4712,6 +4781,8 @@ WERROR _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GET return getprinter_level_4(snum, buffer, offered, needed); case 5: return getprinter_level_5(snum, buffer, offered, needed); + case 7: + return getprinter_level_7(snum, buffer, offered, needed); } return WERR_UNKNOWN_LEVEL; } @@ -5850,6 +5921,34 @@ done: return result; } +/**************************************************************************** +****************************************************************************/ +static WERROR publish_or_unpublish_printer(pipes_struct *p, POLICY_HND *handle, + const SPOOL_PRINTER_INFO_LEVEL *info) +{ +#ifdef HAVE_ADS + SPOOL_PRINTER_INFO_LEVEL_7 *info7 = info->info_7; + int snum; + Printer_entry *Printer = find_printer_index_by_hnd(p, handle); + WERROR result; + + DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action)); + + result = WERR_OK; + + if (!Printer) + return WERR_BADFID; + + if (!get_printer_snum(p, handle, &snum)) + return WERR_BADFID; + + nt_printer_publish(snum, info7->action); + + return WERR_OK; +#else + return WERR_UNKNOWN_LEVEL; +#endif +} /**************************************************************************** ****************************************************************************/ @@ -5878,6 +5977,8 @@ WERROR _spoolss_setprinter(pipes_struct *p, SPOOL_Q_SETPRINTER *q_u, SPOOL_R_SET case 3: return update_printer_sec(handle, level, info, p, secdesc_ctr); + case 7: + return publish_or_unpublish_printer(p, handle, info); default: return WERR_UNKNOWN_LEVEL; } -- cgit From 81a2a307392a12e5ec464e524d2948611e23b943 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Fri, 13 Dec 2002 19:01:27 +0000 Subject: More printer publishing code. - Add published attribute to info2, needed for win clients to work properly - Return proper info on getprinter 7 This means you can now look at the sharing tab of a printer and get correct info about whether it is published or not, and change it. (This used to be commit d57bddc9b22e809c79294c7eacbd5d0f115fe990) --- source3/rpc_server/srv_spoolss_nt.c | 46 +++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 5 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index fd22330449..0e3d69924b 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4148,14 +4148,50 @@ static BOOL construct_printer_info_5(PRINTER_INFO_5 *printer, int snum) } /******************************************************************** - * construct_printer_info_5 - * fill a printer_info_5 struct + * construct_printer_info_7 + * fill a printer_info_7 struct ********************************************************************/ -static BOOL construct_printer_info_7(PRINTER_INFO_7 *printer) +static BOOL construct_printer_info_7(PRINTER_INFO_7 *printer, int snum) { +#ifdef HAVE_ADS + char *guid_str = NULL; + GUID guid; + ADS_STRUCT *ads; + ADS_STATUS ads_rc; + void *res = NULL; + char *prt_dn; + const char *attrs[] = {"objectGUID", NULL}; + + printer->action = SPOOL_DS_UNPUBLISH; + + ads = ads_init(NULL, NULL, lp_ads_server()); + ads_rc = ads_connect(ads); + ads_rc = ads_find_printer_on_server(ads, &res, lp_servicename(snum), + global_myname()); + if (ADS_ERR_OK(ads_rc) && ads_count_replies(ads, res)) { + prt_dn = ads_get_dn(ads, res); + ads_msgfree(ads, res); + if (prt_dn && + ADS_ERR_OK(ads_search_dn(ads, &res, prt_dn, attrs))) { + ads_rc = ads_search_dn(ads, &res, prt_dn, attrs); + ads_memfree(ads, prt_dn); + ads_pull_guid(ads, res, &guid); + printer->action = SPOOL_DS_PUBLISH; + } + } + + ads_msgfree(ads, res); + + asprintf(&guid_str, "{%s}", uuid_string_static(guid)); + strupper(guid_str); + init_unistr(&printer->guid, guid_str); + +#else + printer->action = SPOOL_DS_UNPUBLISH; init_unistr(&printer->guid, ""); - printer->action = 0; +#endif + return True; } @@ -4722,7 +4758,7 @@ static WERROR getprinter_level_7(int snum, NEW_BUFFER *buffer, uint32 offered, u if((printer=(PRINTER_INFO_7*)malloc(sizeof(PRINTER_INFO_7)))==NULL) return WERR_NOMEM; - if (!construct_printer_info_7(printer)) + if (!construct_printer_info_7(printer, snum)) return WERR_NOMEM; /* check the required size. */ -- cgit From f201af19250895b278568df91aad58cea247e543 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Fri, 13 Dec 2002 21:56:34 +0000 Subject: Store printer guid in the dsspooler registry key so we don't have to query the directory server every time someone asks (This used to be commit dd81003bddc17522041e1cd2f0484e1760493e4a) --- source3/rpc_server/srv_spoolss_nt.c | 43 ++++++++----------------------------- 1 file changed, 9 insertions(+), 34 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 0e3d69924b..6dd4352cbc 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4154,43 +4154,18 @@ static BOOL construct_printer_info_5(PRINTER_INFO_5 *printer, int snum) static BOOL construct_printer_info_7(PRINTER_INFO_7 *printer, int snum) { -#ifdef HAVE_ADS char *guid_str = NULL; GUID guid; - ADS_STRUCT *ads; - ADS_STATUS ads_rc; - void *res = NULL; - char *prt_dn; - const char *attrs[] = {"objectGUID", NULL}; - - printer->action = SPOOL_DS_UNPUBLISH; - - ads = ads_init(NULL, NULL, lp_ads_server()); - ads_rc = ads_connect(ads); - ads_rc = ads_find_printer_on_server(ads, &res, lp_servicename(snum), - global_myname()); - if (ADS_ERR_OK(ads_rc) && ads_count_replies(ads, res)) { - prt_dn = ads_get_dn(ads, res); - ads_msgfree(ads, res); - if (prt_dn && - ADS_ERR_OK(ads_search_dn(ads, &res, prt_dn, attrs))) { - ads_rc = ads_search_dn(ads, &res, prt_dn, attrs); - ads_memfree(ads, prt_dn); - ads_pull_guid(ads, res, &guid); - printer->action = SPOOL_DS_PUBLISH; - } - } - - ads_msgfree(ads, res); - asprintf(&guid_str, "{%s}", uuid_string_static(guid)); - strupper(guid_str); - init_unistr(&printer->guid, guid_str); - -#else - printer->action = SPOOL_DS_UNPUBLISH; - init_unistr(&printer->guid, ""); -#endif + if (is_printer_published(snum, &guid)) { + asprintf(&guid_str, "{%s}", uuid_string_static(guid)); + strupper(guid_str); + init_unistr(&printer->guid, guid_str); + printer->action = SPOOL_DS_PUBLISH; + } else { + init_unistr(&printer->guid, ""); + printer->action = SPOOL_DS_UNPUBLISH; + } return True; } -- cgit From 1c318819cc043b472596186b255d75b12f8abbf8 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 17 Dec 2002 21:36:31 +0000 Subject: * fix memory leak when constructing an driver_level_6 structure and no dependent files (working on smbd memory leak). No CR# yet. (This used to be commit 416fd947da4463f5d4dc336dfddf5ce35f50fae9) --- source3/rpc_server/srv_spoolss_nt.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 6dd4352cbc..751ff00a04 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4929,7 +4929,9 @@ static uint32 init_unistr_array(uint16 **uni_array, fstring *char_array, char *s DEBUGADD(6,("%d:%s:%d\n", i, line, strlen(line))); - if ( (tuary=Realloc(*uni_array, (j+strlen(line)+2)*sizeof(uint16))) == NULL ) { + /* add one extra unit16 for the second terminating NULL */ + + if ( (tuary=Realloc(*uni_array, (j+1+strlen(line)+2)*sizeof(uint16))) == NULL ) { DEBUG(2,("init_unistr_array: Realloc error\n" )); return 0; } else @@ -4943,6 +4945,9 @@ static uint32 init_unistr_array(uint16 **uni_array, fstring *char_array, char *s } if (*uni_array) { + /* special case for ""; we need to add both NULL's here */ + if (!j) + (*uni_array)[j++]=0x0000; (*uni_array)[j]=0x0000; } @@ -5172,6 +5177,7 @@ static WERROR construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, fill_printer_driver_info_6(info, driver, servername); free_a_printer(&printer,2); + free_a_printer_driver(driver, 3); return WERR_OK; } -- cgit From 4ae77aa17ce192eff17f91c2712b97cbbe15671a Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 20 Dec 2002 01:29:08 +0000 Subject: Whitespace syncup. (This used to be commit 7a4a2cb8e86ae8ed0bd877f0cfa324e23b96593a) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 751ff00a04..b5c5749f3c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4928,7 +4928,7 @@ static uint32 init_unistr_array(uint16 **uni_array, fstring *char_array, char *s pstrcpy( line, v ); DEBUGADD(6,("%d:%s:%d\n", i, line, strlen(line))); - + /* add one extra unit16 for the second terminating NULL */ if ( (tuary=Realloc(*uni_array, (j+1+strlen(line)+2)*sizeof(uint16))) == NULL ) { -- cgit From ef8bd7c4f7ae8192ea05db070962ecf0ff3615f3 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 20 Dec 2002 20:21:31 +0000 Subject: Forward port the change to talloc_init() to make all talloc contexts named. Ensure we can query them. Jeremy. (This used to be commit 09a218a9f6fb0bd922940467bf8500eb4f1bcf84) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index b5c5749f3c..68a2dcb83d 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -776,7 +776,7 @@ static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr ) if ( !ctr ) return; - ctr->ctx = talloc_init(); + ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr); return; } -- cgit From 634c54310c92c48dd4eceec602e230a021bdcfc5 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 3 Jan 2003 08:28:12 +0000 Subject: Merge from HEAD - make Samba compile with -Wwrite-strings without additional warnings. (Adds a lot of const). Andrew Bartlett (This used to be commit 3a7458f9472432ef12c43008414925fd1ce8ea0c) --- source3/rpc_server/srv_spoolss_nt.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 68a2dcb83d..291ed50ddd 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -42,7 +42,7 @@ /* Table to map the driver version */ /* to OS */ -char * drv_ver_to_os[] = { +static const char * drv_ver_to_os[] = { "WIN9X", /* driver version/cversion 0 */ "", /* unused ? */ "WINNT", /* driver version/cversion 2 */ @@ -50,8 +50,8 @@ char * drv_ver_to_os[] = { }; struct table_node { - char *long_archi; - char *short_archi; + const char *long_archi; + const char *short_archi; int version; }; @@ -712,7 +712,7 @@ static void notify_system_time(struct spoolss_notify_msg *msg, } struct notify2_message_table { - char *name; + const char *name; void (*fn)(struct spoolss_notify_msg *msg, SPOOL_NOTIFY_INFO_DATA *data, TALLOC_CTX *mem_ctx); }; @@ -1708,7 +1708,7 @@ static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL *u return result; } -BOOL convert_devicemode(char *printername, const DEVICEMODE *devmode, +BOOL convert_devicemode(const char *printername, const DEVICEMODE *devmode, NT_DEVICEMODE **pp_nt_devmode) { NT_DEVICEMODE *nt_devmode = *pp_nt_devmode; @@ -2085,7 +2085,7 @@ done: ***************************************************************************/ static WERROR get_printer_dataex( TALLOC_CTX *ctx, NT_PRINTER_INFO_LEVEL *printer, - char *key, char *value, uint32 *type, uint8 **data, + const char *key, const char *value, uint32 *type, uint8 **data, uint32 *needed, uint32 in_size ) { REGISTRY_VALUE *val; @@ -2121,7 +2121,7 @@ static WERROR get_printer_dataex( TALLOC_CTX *ctx, NT_PRINTER_INFO_LEVEL *printe Internal routine for removing printerdata ***************************************************************************/ -static WERROR delete_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, char *key, char *value ) +static WERROR delete_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char *key, const char *value ) { delete_printer_data( printer->info_2, key, value ); @@ -2132,7 +2132,7 @@ static WERROR delete_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, char *key, Internal routine for storing printerdata ***************************************************************************/ -static WERROR set_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, char *key, char *value, +static WERROR set_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char *key, const char *value, uint32 type, uint8 *data, int real_len ) { delete_printer_data( printer->info_2, key, value ); @@ -3094,7 +3094,7 @@ static void spoolss_notify_job_status_string(int snum, * Now we're returning job status codes we just return a "" here. JRA. */ - char *p = ""; + const char *p = ""; pstring temp; uint32 len; @@ -3247,7 +3247,7 @@ struct s_notify_info_data_table { uint16 type; uint16 field; - char *name; + const char *name; uint32 size; void (*fn) (int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, @@ -3258,7 +3258,7 @@ struct s_notify_info_data_table whether the notification data is a pointer to a variable sized buffer, a one value uint32 or a two value uint32. */ -struct s_notify_info_data_table notify_info_data_table[] = +static const struct s_notify_info_data_table notify_info_data_table[] = { { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SERVER_NAME, "PRINTER_NOTIFY_SERVER_NAME", NOTIFY_STRING, spoolss_notify_server_name }, { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINTER_NAME, "PRINTER_NOTIFY_PRINTER_NAME", NOTIFY_STRING, spoolss_notify_printer_name }, @@ -4897,11 +4897,11 @@ static WERROR construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fst * convert an array of ascii string to a UNICODE string ********************************************************************/ -static uint32 init_unistr_array(uint16 **uni_array, fstring *char_array, char *servername) +static uint32 init_unistr_array(uint16 **uni_array, fstring *char_array, const char *servername) { int i=0; int j=0; - char *v; + const char *v; pstring line; uint16 *tuary; @@ -6839,7 +6839,7 @@ WERROR _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * /**************************************************************************** ****************************************************************************/ -static void fill_port_1(PORT_INFO_1 *port, char *name) +static void fill_port_1(PORT_INFO_1 *port, const char *name) { init_unistr(&port->port_name, name); } @@ -6847,7 +6847,7 @@ static void fill_port_1(PORT_INFO_1 *port, char *name) /**************************************************************************** ****************************************************************************/ -static void fill_port_2(PORT_INFO_2 *port, char *name) +static void fill_port_2(PORT_INFO_2 *port, const char *name) { init_unistr(&port->port_name, name); init_unistr(&port->monitor_name, "Local Monitor"); -- cgit From d221b11bc6d62663544d0580321d088152332ec4 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 9 Jan 2003 19:49:14 +0000 Subject: a 0 length printer data value is not a memory allocation error; fix CR601 (This used to be commit 47c1709425e0c8c1e57d95dd4441b1424a5b914c) --- source3/rpc_server/srv_spoolss_nt.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 291ed50ddd..279bbb86ff 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2104,8 +2104,16 @@ static WERROR get_printer_dataex( TALLOC_CTX *ctx, NT_PRINTER_INFO_LEVEL *printe if ( in_size ) { data_len = (size > in_size) ? in_size : size*sizeof(uint8); - if ( (*data = (uint8 *)talloc_memdup(ctx, regval_data_p(val), data_len)) == NULL ) - return WERR_NOMEM; + + /* special case for 0 length values */ + if ( data_len ) { + if ( (*data = (uint8 *)talloc_memdup(ctx, regval_data_p(val), data_len)) == NULL ) + return WERR_NOMEM; + } + else { + if ( (*data = (uint8 *)talloc_zero(ctx, in_size)) == NULL ) + return WERR_NOMEM; + } } else *data = NULL; -- cgit From 071af8f007efc20c23959d140a87cc09363aae83 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sat, 11 Jan 2003 02:38:36 +0000 Subject: [merge] make sure to update print queue cache during timeout_processing() to send notify events; CR 1491 (This used to be commit f8a915b14d63e4fdb99235053eeb896ef9492068) --- source3/rpc_server/srv_spoolss_nt.c | 49 ++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 9 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 279bbb86ff..a289de78de 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -79,8 +79,10 @@ typedef struct _Printer{ uint32 printerlocal; SPOOL_NOTIFY_OPTION *option; POLICY_HND client_hnd; - uint32 client_connected; + BOOL client_connected; uint32 change; + /* are we in a FindNextPrinterChangeNotify() call? */ + BOOL fnpcn; } notify; struct { fstring machine; @@ -90,6 +92,7 @@ typedef struct _Printer{ /* devmode sent in the OpenPrinter() call */ NT_DEVICEMODE *nt_devmode; + } Printer_entry; static Printer_entry *printers_list; @@ -932,7 +935,7 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) SPOOL_NOTIFY_INFO_DATA *data; uint32 data_len = 0; uint32 id; - int i; + int i, event_index; /* Is there notification on this handle? */ @@ -955,6 +958,8 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) data = talloc( mem_ctx, msg_group->num_msgs*sizeof(SPOOL_NOTIFY_INFO_DATA) ); ZERO_STRUCTP(data); + event_index = 0; + /* build the array of change notifications */ for ( i=0; inum_msgs; i++ ) @@ -1005,17 +1010,13 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) switch(msg->type) { case PRINTER_NOTIFY_TYPE: - if ( !printer_notify_table[msg->field].fn ) - goto done; + if ( printer_notify_table[msg->field].fn ) printer_notify_table[msg->field].fn(msg, &data[data_len], mem_ctx); - break; case JOB_NOTIFY_TYPE: - if ( !job_notify_table[msg->field].fn ) - goto done; + if ( job_notify_table[msg->field].fn ) job_notify_table[msg->field].fn(msg, &data[data_len], mem_ctx); - break; default: @@ -1228,6 +1229,32 @@ void do_drv_upgrade_printer(int msg_type, pid_t src, void *buf, size_t len) /* all done */ } +/******************************************************************** + Update the cahce for all printq's with a registered client + connection + ********************************************************************/ + +void update_monitored_printq_cache( void ) +{ + Printer_entry *printer = printers_list; + int snum; + + /* loop through all printers and update the cache where + client_connected == True */ + while ( printer ) + { + if ( (printer->printer_type == PRINTER_HANDLE_IS_PRINTER) + && printer->notify.client_connected ) + { + snum = print_queue_snum(printer->dev.handlename); + print_queue_status( snum, NULL, NULL ); + } + + printer = printer->next; + } + + return; +} /******************************************************************** Send a message to ourself about new driver being installed so we can upgrade the information for each printer bound to this @@ -3727,6 +3754,8 @@ WERROR _spoolss_rfnpcnex( pipes_struct *p, SPOOL_Q_RFNPCNEX *q_u, SPOOL_R_RFNPCN /* We need to keep track of the change value to send back in RRPCN replies otherwise our updates are ignored. */ + Printer->notify.fnpcn = True; + if (Printer->notify.client_connected) { DEBUG(10,("_spoolss_rfnpcnex: Saving change value in request [%x]\n", q_u->change)); Printer->notify.change = q_u->change; @@ -3744,7 +3773,9 @@ WERROR _spoolss_rfnpcnex( pipes_struct *p, SPOOL_Q_RFNPCNEX *q_u, SPOOL_R_RFNPCN break; } - done: + Printer->notify.fnpcn = False; + +done: return result; } -- cgit From 27b7e51a3cc619f879655a3230611457ac43b9e7 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 14 Jan 2003 08:53:59 +0000 Subject: Merge from HEAD: - fstring/pstring mixups - the detection code that found them (disabled) - a bit of whitespace - a static Andrew Bartlett (This used to be commit 9b70fa868e7d9481f584c83fc4046174e1dedfd9) --- source3/rpc_server/srv_spoolss_nt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a289de78de..b44910883c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -262,7 +262,7 @@ static void free_printer_entry(void *ptr) Functions to duplicate a SPOOL_NOTIFY_OPTION struct stored in Printer_entry. ****************************************************************************/ -SPOOL_NOTIFY_OPTION *dup_spool_notify_option(SPOOL_NOTIFY_OPTION *sp) +static SPOOL_NOTIFY_OPTION *dup_spool_notify_option(SPOOL_NOTIFY_OPTION *sp) { SPOOL_NOTIFY_OPTION *new_sp = NULL; @@ -1011,12 +1011,12 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) switch(msg->type) { case PRINTER_NOTIFY_TYPE: if ( printer_notify_table[msg->field].fn ) - printer_notify_table[msg->field].fn(msg, &data[data_len], mem_ctx); + printer_notify_table[msg->field].fn(msg, &data[data_len], mem_ctx); break; case JOB_NOTIFY_TYPE: if ( job_notify_table[msg->field].fn ) - job_notify_table[msg->field].fn(msg, &data[data_len], mem_ctx); + job_notify_table[msg->field].fn(msg, &data[data_len], mem_ctx); break; default: @@ -5409,7 +5409,7 @@ WERROR _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_ *servermajorversion = 0; *serverminorversion = 0; - pstrcpy(servername, get_called_name()); + fstrcpy(servername, get_called_name()); unistr2_to_ascii(architecture, uni_arch, sizeof(architecture)-1); if (!get_printer_snum(p, handle, &snum)) -- cgit From 7d854ebcc67a3c71d3a070dbfc283249787ac4fc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 5 Feb 2003 22:09:06 +0000 Subject: Fixed type. Jeremy. (This used to be commit 76c3ccf6ed258b43d7cf1222524d8e5d2bdc8c82) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index b44910883c..e316fc9acb 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1042,7 +1042,7 @@ done: static BOOL notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, void *buf, size_t len ) { - int offset = 0; + size_t offset = 0; /* Unpack message */ -- cgit From 0ab1705cbc177f8d31285222ba64618f2c1314ae Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 13 Feb 2003 06:51:51 +0000 Subject: Merge JohnR's patch. Removed extra copy of server name in the printername field (it was mangling the the name to be \\server\\\server\printer ... yes, there were 3 backslashes) reported by get & enum jobs level 2. Jeremy. (This used to be commit 2d63f3a13d2cea794eb413023b83c4a1071eaea0) --- source3/rpc_server/srv_spoolss_nt.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index e316fc9acb..6a8333eeea 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6137,9 +6137,7 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, job_info->jobid=queue->job; - slprintf(chaine, sizeof(chaine)-1, "\\\\%s\\%s", get_called_name(), ntprinter->info_2->printername); - - init_unistr(&job_info->printername, chaine); + init_unistr(&job_info->printername, ntprinter->info_2->printername); init_unistr(&job_info->machinename, temp_name); init_unistr(&job_info->username, queue->fs_user); -- cgit From 02da4c79444152a074d79e3b5b8b293a0b61ea1b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 13 Feb 2003 19:49:28 +0000 Subject: Removed unused variable. Jeremy. (This used to be commit a29f1aa85f23fa82795a06ad81b26895b025954b) --- source3/rpc_server/srv_spoolss_nt.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 6a8333eeea..594c749c9c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6129,7 +6129,6 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, DEVICEMODE *devmode) { pstring temp_name; - pstring chaine; struct tm *t; t=gmtime(&queue->time); -- cgit From 8fc1f1aead6db996a6d96efdc5f81779afc9c8d2 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 14 Feb 2003 22:55:46 +0000 Subject: Ensure that only parse_prs.c access internal members of the prs_struct. Needed to move to disk based i/o later. Jeremy. (This used to be commit a823fee5b41a5b6cd4ef05aa1f85f7725bd272a5) --- source3/rpc_server/srv_spoolss_nt.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 594c749c9c..8304b14a1c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -706,10 +706,9 @@ static void notify_system_time(struct spoolss_notify_msg *msg, return; data->notify_data.data.length = prs_offset(&ps); - data->notify_data.data.string = - talloc(mem_ctx, prs_offset(&ps)); + data->notify_data.data.string = talloc(mem_ctx, prs_offset(&ps)); - memcpy(data->notify_data.data.string, prs_data_p(&ps), prs_offset(&ps)); + prs_copy_all_data_out((char *)data->notify_data.data.string, &ps); prs_mem_free(&ps); } -- cgit From 940fcdf09575788781e0b92b9080fff527363fd4 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sat, 15 Feb 2003 23:33:30 +0000 Subject: * set PRINTER_ATTRIBUTE_RAW_ONLY; CR 1736 * never save a pointer to an automatic variable (they go away) implement a deep copy for SPOOLSS_NOTIFY_MSG to correct messages being sent that have junk for strings; fix in response to changes for CR 1504 (This used to be commit ffda9e2480414c7ed6156958f516e0d1f3c61350) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 8304b14a1c..0bcc3c5a30 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -5770,7 +5770,7 @@ static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) fstrcpy(info->sharename, lp_servicename(snum)); slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s", get_called_name(), info->sharename); - info->attributes = PRINTER_ATTRIBUTE_SHARED | PRINTER_ATTRIBUTE_NETWORK; + info->attributes = PRINTER_ATTRIBUTE_SAMBA; return True; } -- cgit From ac30e445ba0291c67a5dec338f5c148298961e61 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 18 Feb 2003 03:42:34 +0000 Subject: set the various DsSpooler keys that are linked to PRINTER_INFO_2 fields; CR 985 (This used to be commit 9efaef4a96a14bd1ffabf12326ff6f6903f663b2) --- source3/rpc_server/srv_spoolss_nt.c | 67 +++++++++++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 10 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 0bcc3c5a30..4306f5185c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4175,13 +4175,17 @@ static BOOL construct_printer_info_5(PRINTER_INFO_5 *printer, int snum) if (!W_ERROR_IS_OK(get_a_printer(&ntprinter, 2, lp_servicename(snum)))) return False; - init_unistr(&printer->printername, ntprinter->info_2->printername); /* printername*/ - init_unistr(&printer->portname, ntprinter->info_2->portname); /* portname */ + init_unistr(&printer->printername, ntprinter->info_2->printername); + init_unistr(&printer->portname, ntprinter->info_2->portname); printer->attributes = ntprinter->info_2->attributes; - printer->device_not_selected_timeout = 0x3a98; - printer->transmission_retry_timeout = 0xafc8; + + /* these two are not used by NT+ according to MSDN */ + + printer->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */ + printer->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */ free_a_printer(&ntprinter, 2); + return True; } @@ -5772,6 +5776,7 @@ static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) get_called_name(), info->sharename); info->attributes = PRINTER_ATTRIBUTE_SAMBA; + return True; } @@ -5841,6 +5846,8 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, NT_PRINTER_INFO_LEVEL *printer = NULL, *old_printer = NULL; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); WERROR result; + UNISTR2 buffer; + fstring asc_buffer; DEBUG(8,("update_printer\n")); @@ -5953,20 +5960,60 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, /* Update printer info */ result = mod_a_printer(*printer, 2); - /* flag which changes actually occured. This is a small subset of - all the possible changes */ + /* + * flag which changes actually occured. This is a small subset of + * all the possible changes. We also have to update things in the + * DsSpooler key. + */ + + if (!strequal(printer->info_2->comment, old_printer->info_2->comment)) { + init_unistr2( &buffer, printer->info_2->comment, strlen(printer->info_2->comment)+1 ); + set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "description", + REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 ); - if (!strequal(printer->info_2->comment, old_printer->info_2->comment)) notify_printer_comment(snum, printer->info_2->comment); + } + + if (!strequal(printer->info_2->sharename, old_printer->info_2->sharename)) { + init_unistr2( &buffer, printer->info_2->sharename, strlen(printer->info_2->sharename)+1 ); + set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "printerName", + REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 ); + set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "shareName", + REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 ); - if (!strequal(printer->info_2->sharename, old_printer->info_2->sharename)) notify_printer_sharename(snum, printer->info_2->sharename); + } + + if (!strequal(printer->info_2->portname, old_printer->info_2->portname)) { + init_unistr2( &buffer, printer->info_2->portname, strlen(printer->info_2->portname)+1 ); + set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "portName", + REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 ); - if (!strequal(printer->info_2->portname, old_printer->info_2->portname)) notify_printer_port(snum, printer->info_2->portname); + } + + if (!strequal(printer->info_2->location, old_printer->info_2->location)) { + init_unistr2( &buffer, printer->info_2->location, strlen(printer->info_2->location)+1 ); + set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "location", + REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 ); - if (!strequal(printer->info_2->location, old_printer->info_2->location)) notify_printer_location(snum, printer->info_2->location); + } + + /* here we need to update some more DsSpooler keys */ + /* uNCName, serverName, shortServerName */ + + init_unistr2( &buffer, global_myname(), strlen(global_myname())+1 ); + set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "serverName", + REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 ); + set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "shortServerName", + REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 ); + + slprintf( asc_buffer, sizeof(asc_buffer)-1, "\\\\%s\\%s", + global_myname(), printer->info_2->sharename ); + init_unistr2( &buffer, asc_buffer, strlen(asc_buffer)+1 ); + set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "uNCName", + REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 ); done: free_a_printer(&printer, 2); -- cgit From 380635538b442ee4de4d7e1242125acd5eb815fd Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 21 Feb 2003 17:04:01 +0000 Subject: couple of merges from APP_HEAD * performance optimization in enumprinterdataex() when keyname is empty * fix a few typos in comments * reload services after addprinter_command() dump registry data in ascii when the key is REG_SZ or REG_MULTI_SZ (This used to be commit 3fc90ea1d9b11186f26484516a4dd8502b6d7323) --- source3/rpc_server/srv_spoolss_nt.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 4306f5185c..64dfef2f9e 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -615,7 +615,7 @@ static BOOL is_monitoring_event(Printer_entry *p, uint16 notify_type, /* * Flags should always be zero when the change notify - * is registered by the cliebnt's spooler. A user Win32 app + * is registered by the client's spooler. A user Win32 app * might use the flags though instead of the NOTIFY_OPTION_INFO * --jerry */ @@ -5936,6 +5936,13 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, result = WERR_ACCESS_DENIED; goto done; } + + /* + * make sure we actually reload the services after + * this as smb.conf could have a new section in it + * .... shouldn't .... but could + */ + reload_services(False); } /* @@ -8871,11 +8878,24 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ DEBUG(4,("_spoolss_enumprinterdataex\n")); if (!Printer) { - DEBUG(2,("_spoolss_enumprinterdata: Invalid handle (%s:%u:%u1<).\n", OUR_HANDLE(handle))); + DEBUG(2,("_spoolss_enumprinterdataex: Invalid handle (%s:%u:%u1<).\n", OUR_HANDLE(handle))); return WERR_BADFID; } - /* first get the printer off of disk */ + /* + * first check for a keyname of NULL or "". Win2k seems to send + * this a lot and we should send back WERR_INVALID_PARAM + * no need to spend time looking up the printer in this case. + * --jerry + */ + + unistr2_to_dos(key, &q_u->key, sizeof(key) - 1); + if ( !strlen(key) ) { + result = WERR_INVALID_PARAM; + goto done; + } + + /* get the printer off of disk */ if (!get_printer_snum(p,handle, &snum)) return WERR_BADFID; @@ -8971,7 +8991,8 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ done: - free_a_printer(&printer, 2); + if ( printer ) + free_a_printer(&printer, 2); return result; } -- cgit From 01490bc0d254380f9bf3ab1f8dc3d98b8c0e723e Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 21 Feb 2003 19:02:07 +0000 Subject: s/unistr2_to_dos/unistr2_to_ascii/ to fix compile (This used to be commit de6a2d154e0e863a7628f18cca8fdcaa49d9c0ff) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 64dfef2f9e..3605c1a24d 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -8889,7 +8889,7 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ * --jerry */ - unistr2_to_dos(key, &q_u->key, sizeof(key) - 1); + unistr2_to_ascii(key, &q_u->key, sizeof(key) - 1); if ( !strlen(key) ) { result = WERR_INVALID_PARAM; goto done; -- cgit From e72ecdc862804339912325fe848401e8ec57cde7 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 24 Feb 2003 02:35:54 +0000 Subject: Merge of server-side authentication changes to 3.0: - user_ok() and user_in_group() now take a list of groups, instead of looking for the user in the members of all groups. - The 'server_info' returned from the authentication is now kept around - in future we won't copy the sesion key, username etc, we will just referece them directly. - rhosts upgraded to use the SAM if possible, otherwise fake up based on getpwnam(). - auth_util code to deal with groups upgraded to deal with non-winbind domain members again. Andrew Bartlett (This used to be commit 74b5436c75114170ce7c780c19226103d0df9060) --- source3/rpc_server/srv_spoolss_nt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 3605c1a24d..93566c2bb7 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1606,7 +1606,7 @@ Can't find printer handle we created for printer %s\n", name )); /* if the user is not root and not a printer admin, then fail */ if ( user.uid != 0 - && !user_in_list(uidtoname(user.uid), lp_printer_admin(snum)) ) + && !user_in_list(uidtoname(user.uid), lp_printer_admin(snum), user.groups, user.ngroups) ) { close_printer_handle(p, handle); return WERR_ACCESS_DENIED; @@ -1653,7 +1653,7 @@ Can't find printer handle we created for printer %s\n", name )); /* check smb.conf parameters and the the sec_desc */ - if (!user_ok(uidtoname(user.uid), snum) || !print_access_check(&user, snum, printer_default->access_required)) { + if (!user_ok(uidtoname(user.uid), snum, user.groups, user.ngroups) || !print_access_check(&user, snum, printer_default->access_required)) { DEBUG(3, ("access DENIED for printer open\n")); close_printer_handle(p, handle); return WERR_ACCESS_DENIED; @@ -8992,7 +8992,7 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ done: if ( printer ) - free_a_printer(&printer, 2); + free_a_printer(&printer, 2); return result; } -- cgit From 23b3b29eec61860155404333f6e70ebd24b50940 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 25 Feb 2003 20:53:53 +0000 Subject: Progress on CR 601 cache the printer_info_2 with the open printer handle. cache is invalidated on a mod_a_printer() call **on that smbd**. Yes, this means that the window for admins to step on each other from different clients just got larger, but since handles a generally short lived this is probably ok. (This used to be commit 31272d3b6bb9ec62fd666301c7adfa0c1720a99b) --- source3/rpc_server/srv_spoolss_nt.c | 277 ++++++++++++++++-------------------- 1 file changed, 122 insertions(+), 155 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 93566c2bb7..fa9b8eaeff 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -5,7 +5,7 @@ * Copyright (C) Luke Kenneth Casson Leighton 1996-2000, * Copyright (C) Jean François Micouleau 1998-2000, * Copyright (C) Jeremy Allison 2001-2002, - * Copyright (C) Gerald Carter 2000-2002, + * Copyright (C) Gerald Carter 2000-2003, * Copyright (C) Tim Potter 2001-2002. * * This program is free software; you can redistribute it and/or modify @@ -37,8 +37,7 @@ #define MAGIC_DISPLAY_FREQUENCY 0xfade2bad #define PHANTOM_DEVMODE_KEY "_p_f_a_n_t_0_m_" -#define PRINTER_HANDLE_IS_PRINTER 0 -#define PRINTER_HANDLE_IS_PRINTSERVER 1 + /* Table to map the driver version */ /* to OS */ @@ -55,46 +54,6 @@ struct table_node { int version; }; - -/* structure to store the printer handles */ -/* and a reference to what it's pointing to */ -/* and the notify info asked about */ -/* that's the central struct */ -typedef struct _Printer{ - struct _Printer *prev, *next; - BOOL document_started; - BOOL page_started; - uint32 jobid; /* jobid in printing backend */ - BOOL printer_type; - union { - fstring handlename; - fstring printerservername; - } dev; - uint32 type; - uint32 access_granted; - struct { - uint32 flags; - uint32 options; - fstring localmachine; - uint32 printerlocal; - SPOOL_NOTIFY_OPTION *option; - POLICY_HND client_hnd; - BOOL client_connected; - uint32 change; - /* are we in a FindNextPrinterChangeNotify() call? */ - BOOL fnpcn; - } notify; - struct { - fstring machine; - fstring user; - } client; - - /* devmode sent in the OpenPrinter() call */ - NT_DEVICEMODE *nt_devmode; - - -} Printer_entry; - static Printer_entry *printers_list; typedef struct _counter_printer_0 { @@ -251,6 +210,9 @@ static void free_printer_entry(void *ptr) Printer->notify.client_connected=False; free_nt_devicemode( &Printer->nt_devmode ); + free_a_printer( &Printer->printer_info, 2 ); + + talloc_destroy( Printer->ctx ); /* Remove from the internal list. */ DLIST_REMOVE(printers_list, Printer); @@ -303,6 +265,29 @@ static Printer_entry *find_printer_index_by_hnd(pipes_struct *p, POLICY_HND *hnd return find_printer; } +/**************************************************************************** + find printer index by handle +****************************************************************************/ + +void invalidate_printer_hnd_cache( char *printername ) +{ + Printer_entry *p; + + DEBUG(10,("invalidate_printer_hnd_cache: printer [%s]\n", printername)); + + for ( p=printers_list; p; p=p->next ) + { + if ( p->printer_type==PRINTER_HANDLE_IS_PRINTER + && StrCaseCmp(p->dev.handlename, printername)==0) + { + DEBUG(10,("invalidating printer_info cache for handl:\n")); + free_a_printer( &p->printer_info, 2 ); + p->printer_info = NULL; + } + } + + return; +} /**************************************************************************** Close printer index by handle. ****************************************************************************/ @@ -534,6 +519,11 @@ static BOOL open_printer_hnd(pipes_struct *p, POLICY_HND *hnd, char *name, uint3 ZERO_STRUCTP(new_printer); + if ( !(new_printer->ctx = talloc_init("Printer Entry [0x%x]", (uint32)hnd)) ) { + DEBUG(0,("open_printer_hnd: talloc_init() failed!\n")); + return False; + } + new_printer->notify.option=NULL; /* Add to the internal list. */ @@ -861,8 +851,7 @@ static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MS /* add a new group? */ - if ( i == ctr->num_groups ) - { + if ( i == ctr->num_groups ) { ctr->num_groups++; if ( !(groups = talloc_realloc( ctr->ctx, ctr->msg_groups, sizeof(SPOOLSS_NOTIFY_MSG_GROUP)*ctr->num_groups)) ) { @@ -929,8 +918,7 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) /* loop over all printers */ - for (p = printers_list; p; p = p->next) - { + for (p = printers_list; p; p = p->next) { SPOOL_NOTIFY_INFO_DATA *data; uint32 data_len = 0; uint32 id; @@ -961,8 +949,7 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) /* build the array of change notifications */ - for ( i=0; inum_msgs; i++ ) - { + for ( i=0; inum_msgs; i++ ) { SPOOLSS_NOTIFY_MSG *msg = &messages[i]; /* Are we monitoring this event? */ @@ -995,8 +982,7 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) /* Convert unix jobid to smb jobid */ - if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) - { + if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) { id = sysjob_to_jobid(msg->id); if (id == -1) { @@ -1204,7 +1190,7 @@ void do_drv_upgrade_printer(int msg_type, pid_t src, void *buf, size_t len) WERROR result; NT_PRINTER_INFO_LEVEL *printer = NULL; - result = get_a_printer(&printer, 2, lp_servicename(snum)); + result = get_a_printer(NULL, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(result)) continue; @@ -1300,7 +1286,7 @@ void reset_all_printerdata(int msg_type, pid_t src, void *buf, size_t len) WERROR result; NT_PRINTER_INFO_LEVEL *printer = NULL; - result = get_a_printer( &printer, 2, lp_servicename(snum) ); + result = get_a_printer( NULL, &printer, 2, lp_const_servicename(snum) ); if ( !W_ERROR_IS_OK(result) ) continue; @@ -2157,9 +2143,7 @@ static WERROR get_printer_dataex( TALLOC_CTX *ctx, NT_PRINTER_INFO_LEVEL *printe static WERROR delete_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char *key, const char *value ) { - delete_printer_data( printer->info_2, key, value ); - - return mod_a_printer(*printer, 2); + return delete_printer_data( printer->info_2, key, value ); } /**************************************************************************** @@ -2171,9 +2155,7 @@ static WERROR set_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char *ke { delete_printer_data( printer->info_2, key, value ); - add_printer_data( printer->info_2, key, value, type, data, real_len ); - - return mod_a_printer(*printer, 2); + return add_printer_data( printer->info_2, key, value, type, data, real_len ); } /******************************************************************** @@ -2349,7 +2331,7 @@ WERROR _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO goto done; } - status = get_a_printer(&printer, 2, lp_servicename(snum)); + status = get_a_printer(Printer, &printer, 2, lp_servicename(snum)); if ( !W_ERROR_IS_OK(status) ) goto done; @@ -3443,7 +3425,7 @@ void construct_info_data(SPOOL_NOTIFY_INFO_DATA *info_data, uint16 type, uint16 * ********************************************************************/ -static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int +static BOOL construct_notify_printer_info(Printer_entry *print_hnd, SPOOL_NOTIFY_INFO *info, int snum, SPOOL_NOTIFY_OPTION_TYPE *option_type, uint32 id, TALLOC_CTX *mem_ctx) @@ -3462,11 +3444,10 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int (option_type->type==PRINTER_NOTIFY_TYPE?"PRINTER_NOTIFY_TYPE":"JOB_NOTIFY_TYPE"), option_type->count, lp_servicename(snum))); - if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, lp_servicename(snum)))) + if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &printer, 2, lp_const_servicename(snum)))) return False; - for(field_num=0; field_numcount; field_num++) - { + for(field_num=0; field_numcount; field_num++) { field = option_type->fields[field_num]; DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field)); @@ -3474,12 +3455,10 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int if (!search_notify(type, field, &j) ) continue; - if((tid=(SPOOL_NOTIFY_INFO_DATA *)Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) - { + if((tid=(SPOOL_NOTIFY_INFO_DATA *)Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) { DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n")); return False; - } - else + } else info->data = tid; current_data = &info->data[info->count]; @@ -3611,7 +3590,7 @@ static WERROR printserver_notify_info(pipes_struct *p, POLICY_HND *hnd, for (snum=0; snumtype ) { case PRINTER_NOTIFY_TYPE: - if(construct_notify_printer_info(info, snum, + if(construct_notify_printer_info(Printer, info, snum, option_type, id, mem_ctx)) id--; @@ -3682,8 +3661,7 @@ static WERROR printer_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY count = print_queue_status(snum, &queue, &status); - if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, - lp_servicename(snum)))) + if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)))) goto done; for (j=0; jflags=flags; @@ -3997,7 +3975,7 @@ DEVICEMODE *construct_dev_mode(int snum) DEBUGADD(8,("getting printer characteristics\n")); - if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, lp_servicename(snum)))) + if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, lp_const_servicename(snum)))) return NULL; if ( !printer->info_2->devmode ) { @@ -4030,14 +4008,14 @@ done: * fill a printer_info_2 struct ********************************************************************/ -static BOOL construct_printer_info_2(PRINTER_INFO_2 *printer, int snum) +static BOOL construct_printer_info_2(Printer_entry *print_hnd, PRINTER_INFO_2 *printer, int snum) { int count; NT_PRINTER_INFO_LEVEL *ntprinter = NULL; print_status_struct status; - if (!W_ERROR_IS_OK(get_a_printer(&ntprinter, 2, lp_servicename(snum)))) + if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum)))) return False; count = print_queue_length(snum, &status); @@ -4093,12 +4071,12 @@ static BOOL construct_printer_info_2(PRINTER_INFO_2 *printer, int snum) * fill a printer_info_3 struct ********************************************************************/ -static BOOL construct_printer_info_3(PRINTER_INFO_3 **pp_printer, int snum) +static BOOL construct_printer_info_3(Printer_entry *print_hnd, PRINTER_INFO_3 **pp_printer, int snum) { NT_PRINTER_INFO_LEVEL *ntprinter = NULL; PRINTER_INFO_3 *printer = NULL; - if (!W_ERROR_IS_OK(get_a_printer(&ntprinter, 2, lp_servicename(snum)))) + if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum)))) return False; *pp_printer = NULL; @@ -4148,11 +4126,11 @@ static BOOL construct_printer_info_3(PRINTER_INFO_3 **pp_printer, int snum) * fill a printer_info_4 struct ********************************************************************/ -static BOOL construct_printer_info_4(PRINTER_INFO_4 *printer, int snum) +static BOOL construct_printer_info_4(Printer_entry *print_hnd, PRINTER_INFO_4 *printer, int snum) { NT_PRINTER_INFO_LEVEL *ntprinter = NULL; - if (!W_ERROR_IS_OK(get_a_printer(&ntprinter, 2, lp_servicename(snum)))) + if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum)))) return False; init_unistr(&printer->printername, ntprinter->info_2->printername); /* printername*/ @@ -4168,11 +4146,11 @@ static BOOL construct_printer_info_4(PRINTER_INFO_4 *printer, int snum) * fill a printer_info_5 struct ********************************************************************/ -static BOOL construct_printer_info_5(PRINTER_INFO_5 *printer, int snum) +static BOOL construct_printer_info_5(Printer_entry *print_hnd, PRINTER_INFO_5 *printer, int snum) { NT_PRINTER_INFO_LEVEL *ntprinter = NULL; - if (!W_ERROR_IS_OK(get_a_printer(&ntprinter, 2, lp_servicename(snum)))) + if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum)))) return False; init_unistr(&printer->printername, ntprinter->info_2->printername); @@ -4194,12 +4172,12 @@ static BOOL construct_printer_info_5(PRINTER_INFO_5 *printer, int snum) * fill a printer_info_7 struct ********************************************************************/ -static BOOL construct_printer_info_7(PRINTER_INFO_7 *printer, int snum) +static BOOL construct_printer_info_7(Printer_entry *print_hnd, PRINTER_INFO_7 *printer, int snum) { char *guid_str = NULL; GUID guid; - if (is_printer_published(snum, &guid)) { + if (is_printer_published(print_hnd, snum, &guid)) { asprintf(&guid_str, "{%s}", uuid_string_static(guid)); strupper(guid_str); init_unistr(&printer->guid, guid_str); @@ -4230,7 +4208,7 @@ static WERROR enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) { DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum)); - if (construct_printer_info_1(flags, ¤t_prt, snum)) { + if (construct_printer_info_1(NULL, flags, ¤t_prt, snum)) { if((tp=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_1))) == NULL) { DEBUG(2,("enum_all_printers_info_1: failed to enlarge printers buffer!\n")); SAFE_FREE(printers); @@ -4399,7 +4377,7 @@ static WERROR enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint3 if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) { DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum)); - if (construct_printer_info_2(¤t_prt, snum)) { + if (construct_printer_info_2(NULL, ¤t_prt, snum)) { if((tp=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_2))) == NULL) { DEBUG(2,("enum_all_printers_info_2: failed to enlarge printers buffer!\n")); SAFE_FREE(printers); @@ -4570,14 +4548,14 @@ WERROR _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOOL_ /**************************************************************************** ****************************************************************************/ -static WERROR getprinter_level_0(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinter_level_0(Printer_entry *print_hnd, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_0 *printer=NULL; if((printer=(PRINTER_INFO_0*)malloc(sizeof(PRINTER_INFO_0))) == NULL) return WERR_NOMEM; - construct_printer_info_0(printer, snum); + construct_printer_info_0(print_hnd, printer, snum); /* check the required size. */ *needed += spoolss_size_printer_info_0(printer); @@ -4603,14 +4581,14 @@ static WERROR getprinter_level_0(int snum, NEW_BUFFER *buffer, uint32 offered, u /**************************************************************************** ****************************************************************************/ -static WERROR getprinter_level_1(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinter_level_1(Printer_entry *print_hnd, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_1 *printer=NULL; if((printer=(PRINTER_INFO_1*)malloc(sizeof(PRINTER_INFO_1))) == NULL) return WERR_NOMEM; - construct_printer_info_1(PRINTER_ENUM_ICON8, printer, snum); + construct_printer_info_1(print_hnd, PRINTER_ENUM_ICON8, printer, snum); /* check the required size. */ *needed += spoolss_size_printer_info_1(printer); @@ -4636,14 +4614,14 @@ static WERROR getprinter_level_1(int snum, NEW_BUFFER *buffer, uint32 offered, u /**************************************************************************** ****************************************************************************/ -static WERROR getprinter_level_2(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinter_level_2(Printer_entry *print_hnd, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_2 *printer=NULL; if((printer=(PRINTER_INFO_2*)malloc(sizeof(PRINTER_INFO_2)))==NULL) return WERR_NOMEM; - construct_printer_info_2(printer, snum); + construct_printer_info_2(print_hnd, printer, snum); /* check the required size. */ *needed += spoolss_size_printer_info_2(printer); @@ -4672,11 +4650,11 @@ static WERROR getprinter_level_2(int snum, NEW_BUFFER *buffer, uint32 offered, u /**************************************************************************** ****************************************************************************/ -static WERROR getprinter_level_3(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinter_level_3(Printer_entry *print_hnd, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_3 *printer=NULL; - if (!construct_printer_info_3(&printer, snum)) + if (!construct_printer_info_3(print_hnd, &printer, snum)) return WERR_NOMEM; /* check the required size. */ @@ -4703,14 +4681,14 @@ static WERROR getprinter_level_3(int snum, NEW_BUFFER *buffer, uint32 offered, u /**************************************************************************** ****************************************************************************/ -static WERROR getprinter_level_4(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinter_level_4(Printer_entry *print_hnd, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_4 *printer=NULL; if((printer=(PRINTER_INFO_4*)malloc(sizeof(PRINTER_INFO_4)))==NULL) return WERR_NOMEM; - if (!construct_printer_info_4(printer, snum)) + if (!construct_printer_info_4(print_hnd, printer, snum)) return WERR_NOMEM; /* check the required size. */ @@ -4737,14 +4715,14 @@ static WERROR getprinter_level_4(int snum, NEW_BUFFER *buffer, uint32 offered, u /**************************************************************************** ****************************************************************************/ -static WERROR getprinter_level_5(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinter_level_5(Printer_entry *print_hnd, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_5 *printer=NULL; if((printer=(PRINTER_INFO_5*)malloc(sizeof(PRINTER_INFO_5)))==NULL) return WERR_NOMEM; - if (!construct_printer_info_5(printer, snum)) + if (!construct_printer_info_5(print_hnd, printer, snum)) return WERR_NOMEM; /* check the required size. */ @@ -4768,14 +4746,14 @@ static WERROR getprinter_level_5(int snum, NEW_BUFFER *buffer, uint32 offered, u return WERR_OK; } -static WERROR getprinter_level_7(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinter_level_7(Printer_entry *print_hnd, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_7 *printer=NULL; if((printer=(PRINTER_INFO_7*)malloc(sizeof(PRINTER_INFO_7)))==NULL) return WERR_NOMEM; - if (!construct_printer_info_7(printer, snum)) + if (!construct_printer_info_7(print_hnd, printer, snum)) return WERR_NOMEM; /* check the required size. */ @@ -4809,6 +4787,7 @@ WERROR _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GET NEW_BUFFER *buffer = NULL; uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; + Printer_entry *Printer=find_printer_index_by_hnd(p, handle); int snum; @@ -4823,19 +4802,19 @@ WERROR _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GET switch (level) { case 0: - return getprinter_level_0(snum, buffer, offered, needed); + return getprinter_level_0(Printer, snum, buffer, offered, needed); case 1: - return getprinter_level_1(snum, buffer, offered, needed); + return getprinter_level_1(Printer, snum, buffer, offered, needed); case 2: - return getprinter_level_2(snum, buffer, offered, needed); + return getprinter_level_2(Printer, snum, buffer, offered, needed); case 3: - return getprinter_level_3(snum, buffer, offered, needed); + return getprinter_level_3(Printer, snum, buffer, offered, needed); case 4: - return getprinter_level_4(snum, buffer, offered, needed); + return getprinter_level_4(Printer, snum, buffer, offered, needed); case 5: - return getprinter_level_5(snum, buffer, offered, needed); + return getprinter_level_5(Printer, snum, buffer, offered, needed); case 7: - return getprinter_level_7(snum, buffer, offered, needed); + return getprinter_level_7(Printer, snum, buffer, offered, needed); } return WERR_UNKNOWN_LEVEL; } @@ -4860,7 +4839,7 @@ static WERROR construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, fst ZERO_STRUCT(driver); - if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, lp_servicename(snum)))) + if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, lp_const_servicename(snum)))) return WERR_INVALID_PRINTER_NAME; if (!W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version))) @@ -4920,7 +4899,7 @@ static WERROR construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fst ZERO_STRUCT(printer); ZERO_STRUCT(driver); - if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, lp_servicename(snum)))) + if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, lp_const_servicename(snum)))) return WERR_INVALID_PRINTER_NAME; if (!W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version))) @@ -5059,7 +5038,7 @@ static WERROR construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fst WERROR status; ZERO_STRUCT(driver); - status=get_a_printer(&printer, 2, lp_servicename(snum) ); + status=get_a_printer(NULL, &printer, 2, lp_const_servicename(snum) ); DEBUG(8,("construct_printer_driver_info_3: status: %s\n", dos_errstr(status))); if (!W_ERROR_IS_OK(status)) return WERR_INVALID_PRINTER_NAME; @@ -5184,7 +5163,7 @@ static WERROR construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, ZERO_STRUCT(driver); - status=get_a_printer(&printer, 2, lp_servicename(snum) ); + status=get_a_printer(NULL, &printer, 2, lp_const_servicename(snum) ); DEBUG(8,("construct_printer_driver_info_6: status: %s\n", dos_errstr(status))); @@ -5853,13 +5832,6 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, result = WERR_OK; - if (level!=2) { - DEBUG(0,("update_printer: Send a mail to samba@samba.org\n")); - DEBUGADD(0,("with the following message: update_printer: level!=2\n")); - result = WERR_UNKNOWN_LEVEL; - goto done; - } - if (!Printer) { result = WERR_BADFID; goto done; @@ -5870,8 +5842,8 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, goto done; } - if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, lp_servicename(snum))) || - (!W_ERROR_IS_OK(get_a_printer(&old_printer, 2, lp_servicename(snum))))) { + if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum))) || + (!W_ERROR_IS_OK(get_a_printer(Printer, &old_printer, 2, lp_const_servicename(snum))))) { result = WERR_BADFID; goto done; } @@ -5899,13 +5871,6 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, result = WERR_NOMEM; goto done; } - - /* - * make sure we actually reload the services after - * this as smb.conf could have a new section in it - * .... shouldn't .... but could - */ - reload_services(False); } /* Do sanity check on the requested changes for Samba */ @@ -5964,9 +5929,6 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, notify_printer_driver(snum, printer->info_2->drivername); } - /* Update printer info */ - result = mod_a_printer(*printer, 2); - /* * flag which changes actually occured. This is a small subset of * all the possible changes. We also have to update things in the @@ -6022,6 +5984,9 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "uNCName", REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 ); + /* Update printer info */ + result = mod_a_printer(*printer, 2); + done: free_a_printer(&printer, 2); free_a_printer(&old_printer, 2); @@ -6051,7 +6016,7 @@ static WERROR publish_or_unpublish_printer(pipes_struct *p, POLICY_HND *handle, if (!get_printer_snum(p, handle, &snum)) return WERR_BADFID; - nt_printer_publish(snum, info7->action); + nt_printer_publish(Printer, snum, info7->action); return WERR_OK; #else @@ -6287,7 +6252,7 @@ static WERROR enumjobs_level2(print_queue_struct *queue, int snum, goto done; } - result = get_a_printer(&ntprinter, 2, lp_servicename(snum)); + result = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum)); if (!W_ERROR_IS_OK(result)) { *returned = 0; goto done; @@ -7591,7 +7556,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S if (!get_printer_snum(p,handle, &snum)) return WERR_BADFID; - result = get_a_printer(&printer, 2, lp_servicename(snum)); + result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(result)) return result; @@ -7655,9 +7620,9 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S /* out_value should default to "" or else NT4 has problems unmarshalling the response */ - *out_max_value_len = (in_value_len/sizeof(uint16)); + *out_max_value_len=(in_value_len/sizeof(uint16)); - if ( (*out_value=(uint16 *)talloc_zero(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL ) + if((*out_value=(uint16 *)talloc_zero(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL) { result = WERR_NOMEM; goto done; @@ -7692,7 +7657,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S */ /* name */ - *out_max_value_len = ( in_value_len / sizeof(uint16) ); + *out_max_value_len=(in_value_len/sizeof(uint16)); if ( (*out_value = (uint16 *)talloc_zero(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL ) { result = WERR_NOMEM; @@ -7765,7 +7730,7 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP goto done; } - status = get_a_printer(&printer, 2, lp_servicename(snum)); + status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(status)) return status; @@ -7857,7 +7822,7 @@ WERROR _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_ return WERR_ACCESS_DENIED; } - status = get_a_printer(&printer, 2, lp_servicename(snum)); + status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(status)) return status; @@ -7901,7 +7866,7 @@ WERROR _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM if (!get_printer_snum(p,handle, &snum)) return WERR_BADFID; - status = get_a_printer(&printer, 2, lp_servicename(snum)); + status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(status)) goto done; } @@ -7972,7 +7937,7 @@ WERROR _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE if (!get_printer_snum(p,handle, &snum)) return WERR_BADFID; - status = get_a_printer(&printer, 2, lp_servicename(snum)); + status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(status)) goto done; } @@ -8040,7 +8005,7 @@ WERROR _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM * if (!get_printer_snum(p,handle, &snum)) return WERR_BADFID; - status = get_a_printer(&printer, 2, lp_servicename(snum)); + status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(status)) goto done; } @@ -8390,7 +8355,7 @@ static WERROR getjob_level_2(print_queue_struct *queue, int count, int snum, uin goto done; } - ret = get_a_printer(&ntprinter, 2, lp_servicename(snum)); + ret = get_a_printer(NULL, &ntprinter, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(ret)) goto done; @@ -8543,7 +8508,7 @@ WERROR _spoolss_getprinterdataex(pipes_struct *p, SPOOL_Q_GETPRINTERDATAEX *q_u, if ( !get_printer_snum(p,handle, &snum) ) return WERR_BADFID; - status = get_a_printer(&printer, 2, lp_servicename(snum)); + status = get_a_printer(Printer, &printer, 2, lp_servicename(snum)); if ( !W_ERROR_IS_OK(status) ) goto done; @@ -8638,7 +8603,7 @@ WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, return WERR_ACCESS_DENIED; } - status = get_a_printer(&printer, 2, lp_servicename(snum)); + status = get_a_printer(Printer, &printer, 2, lp_servicename(snum)); if (!W_ERROR_IS_OK(status)) return status; @@ -8657,11 +8622,10 @@ WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, status = set_printer_dataex( printer, keyname, valuename, type, data, real_len ); - /* save the OID if one was specified and the previous set call succeeded */ - - if ( W_ERROR_IS_OK(status) && oid_string ) + if ( W_ERROR_IS_OK(status) ) { - + /* save the OID if one was specified */ + if ( oid_string ) { fstrcat( keyname, "\\" ); fstrcat( keyname, SPOOL_OID_KEY ); @@ -8676,6 +8640,9 @@ WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, REG_SZ, (void*)oid_string, strlen(oid_string)+1 ); } + status = mod_a_printer(*printer, 2); + } + free_a_printer(&printer, 2); return status; @@ -8713,7 +8680,7 @@ WERROR _spoolss_deleteprinterdataex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATAEX return WERR_ACCESS_DENIED; } - status = get_a_printer(&printer, 2, lp_servicename(snum)); + status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(status)) return status; @@ -8757,7 +8724,7 @@ WERROR _spoolss_enumprinterkey(pipes_struct *p, SPOOL_Q_ENUMPRINTERKEY *q_u, SPO if ( !get_printer_snum(p,handle, &snum) ) return WERR_BADFID; - status = get_a_printer(&printer, 2, lp_servicename(snum)); + status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(status)) return status; @@ -8832,7 +8799,7 @@ WERROR _spoolss_deleteprinterkey(pipes_struct *p, SPOOL_Q_DELETEPRINTERKEY *q_u, return WERR_ACCESS_DENIED; } - status = get_a_printer(&printer, 2, lp_servicename(snum)); + status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(status)) return status; @@ -8901,7 +8868,7 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ return WERR_BADFID; ZERO_STRUCT(printer); - result = get_a_printer(&printer, 2, lp_servicename(snum)); + result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(result)) return result; -- cgit From 0d30cdf66c4e186e20a09e1e8b39d501e662ae50 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 27 Feb 2003 21:22:36 +0000 Subject: additional fix for CR 601 * distinguish WinXP from Win2k * add a 1/3 of a second delay in OpenPrinter in order to trigger a LAN/WAN optimization in 2k clients. (This used to be commit c7712fa054d21b4884a78b7ea6c0fb8b3d637c6b) --- source3/rpc_server/srv_spoolss_nt.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index fa9b8eaeff..4006d0c08e 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1675,6 +1675,12 @@ Can't find printer handle we created for printer %s\n", name )); &Printer->nt_devmode ); } + /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN + optimization in Windows 2000 clients --jerry */ + + if ( RA_WIN2K == get_remote_arch() ) + usleep( 384000 ); + return WERR_OK; } -- cgit From ba3ccc2928f0178034b48e27383e57a8cf1a4f21 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 1 Mar 2003 02:39:12 +0000 Subject: Added limit to number of jobs enumerated. Set to 0 (means no limit). Yes I will add the docs.... Jeremy. (This used to be commit e1b0001c8df9e9823b42a372ca675188570b252a) --- source3/rpc_server/srv_spoolss_nt.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 4006d0c08e..b321832930 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6323,6 +6323,7 @@ WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO int snum; print_status_struct prt_status; print_queue_struct *queue=NULL; + int max_rep_jobs; /* that's an [in out] buffer */ spoolss_move_buffer(q_u->buffer, &r_u->buffer); @@ -6336,6 +6337,8 @@ WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO if (!get_printer_snum(p, handle, &snum)) return WERR_BADFID; + max_rep_jobs = lp_max_reported_jobs(snum); + *returned = print_queue_status(snum, &queue, &prt_status); DEBUGADD(4,("count:[%d], status:[%d], [%s]\n", *returned, prt_status.status, prt_status.message)); @@ -6344,6 +6347,9 @@ WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO return WERR_OK; } + if (max_rep_jobs && (*returned > max_rep_jobs)) + *returned = max_rep_jobs; + switch (level) { case 1: return enumjobs_level1(queue, snum, buffer, offered, needed, returned); -- cgit From d95f1e4260e66b0ab37b69105e7cc252e23bee16 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 3 Mar 2003 16:32:03 +0000 Subject: * CR1868: only send a change notify message if we have something that changed that the client is monitoring. * couple of comments abnout how we need to validate driver names on SetPrinter() and AddPrinter() * up the debug level on some overly verbose dev mode parsing messages (This used to be commit e8939165b77c9e2ea8b3cef2e85885b9812c7184) --- source3/rpc_server/srv_spoolss_nt.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index b321832930..a966326d3a 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -900,7 +900,7 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr ); SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx ); SPOOLSS_NOTIFY_MSG *messages; - + int sending_msg_count; if ( !msg_group ) { DEBUG(5,("send_notify2_changes() called with no msg group!\n")); @@ -949,6 +949,8 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) /* build the array of change notifications */ + sending_msg_count = 0; + for ( i=0; inum_msgs; i++ ) { SPOOLSS_NOTIFY_MSG *msg = &messages[i]; @@ -957,6 +959,8 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) if (!is_monitoring_event(p, msg->type, msg->field)) continue; + sending_msg_count++; + DEBUG(10,("process_notify2_message: Sending message type [%x] field [%x] for printer [%s]\n", msg->type, msg->field, p->dev.handlename)); @@ -1012,8 +1016,10 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) data_len++; } - cli_spoolss_rrpcn( ¬ify_cli, mem_ctx, &p->notify.client_hnd, - data_len, data, p->notify.change, 0 ); + if ( sending_msg_count ) { + cli_spoolss_rrpcn( ¬ify_cli, mem_ctx, &p->notify.client_hnd, + data_len, data, p->notify.change, 0 ); + } } done: @@ -5886,6 +5892,9 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, goto done; } + /* FIXME!!! If the driver has changed we really should verify that + it is installed before doing much else --jerry */ + /* Check calling user has permission to update printer description */ if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) { @@ -7177,6 +7186,9 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ free_a_printer(&printer, 2); return WERR_PRINTER_ALREADY_EXISTS; } + + /* FIXME!!! smbd should check to see if the driver is installed before + trying to add a printer like this --jerry */ if (*lp_addprinter_cmd() ) { if ( !add_printer_hook(printer) ) { -- cgit From cc7f40f4b7c090e73f7cd54e89e3927c8bff0004 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 3 Mar 2003 17:32:55 +0000 Subject: * always report ourselves as a Windows 2000 print server (even without ADS support) * add "MinorVersion" print server data key and comment on "OSVersion" (This used to be commit e1383368169faa50b9e612c9f71f92f790698b48) --- source3/rpc_server/srv_spoolss_nt.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a966326d3a..5d63f27d23 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2220,14 +2220,37 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint *type = 0x4; if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) return WERR_NOMEM; -#ifdef HAVE_ADS SIVAL(*data, 0, 3); -#else + *needed = 0x4; + return WERR_OK; + } + + if (!StrCaseCmp(value, "MinorVersion")) { + *type = 0x4; + if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) + return WERR_NOMEM; + SIVAL(*data, 0, 0); + *needed = 0x4; + return WERR_OK; + } + +#if 0 /* JERRY */ + /* REG_BINARY + * uint32 size = 0x114 + * uint32 major = 5 + * uint32 minor = [0|1] + * uint32 build = [2195|2600] + * extra unicode string = e.g. "Service Pack 3" + */ + if (!StrCaseCmp(value, "OSVersion")) { + *type = 0x4; + if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) + return WERR_NOMEM; SIVAL(*data, 0, 2); -#endif *needed = 0x4; return WERR_OK; } +#endif if (!StrCaseCmp(value, "DefaultSpoolDirectory")) { fstring string; @@ -3843,13 +3866,11 @@ static BOOL construct_printer_info_0(Printer_entry *print_hnd, PRINTER_INFO_0 *p printer->global_counter = global_counter; printer->total_pages = 0; -#ifdef HAVE_ADS + + /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */ printer->major_version = 0x0005; /* NT 5 */ printer->build_version = 0x0893; /* build 2195 */ -#else - printer->major_version = 0x0004; /* NT 4 */ - printer->build_version = 0x0565; /* build 1381 */ -#endif + printer->unknown7 = 0x1; printer->unknown8 = 0x0; printer->unknown9 = 0x0; -- cgit From 3be18a1fba5b008e55a4497470165de62aa15054 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 20 Mar 2003 00:52:37 +0000 Subject: lib/messages.c: Check return from chainlock before modifying message queue. Apply the job returned limit across all requests for job queues. Jeremy. (This used to be commit bf795b684e608f82db822e0759e7b69afd451b65) --- source3/rpc_server/srv_spoolss_nt.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 5d63f27d23..a7b73b5ac9 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6353,7 +6353,6 @@ WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO int snum; print_status_struct prt_status; print_queue_struct *queue=NULL; - int max_rep_jobs; /* that's an [in out] buffer */ spoolss_move_buffer(q_u->buffer, &r_u->buffer); @@ -6367,8 +6366,6 @@ WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO if (!get_printer_snum(p, handle, &snum)) return WERR_BADFID; - max_rep_jobs = lp_max_reported_jobs(snum); - *returned = print_queue_status(snum, &queue, &prt_status); DEBUGADD(4,("count:[%d], status:[%d], [%s]\n", *returned, prt_status.status, prt_status.message)); @@ -6377,9 +6374,6 @@ WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO return WERR_OK; } - if (max_rep_jobs && (*returned > max_rep_jobs)) - *returned = max_rep_jobs; - switch (level) { case 1: return enumjobs_level1(queue, snum, buffer, offered, needed, returned); -- cgit From a97a1d5fed2af91ba4d2c5cf2c82140aef98989d Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 31 Mar 2003 00:59:58 +0000 Subject: add a few error checks in EnumPrinterData() (This used to be commit 6cd74dea086aa6e0936719f6e2829494c4688ea6) --- source3/rpc_server/srv_spoolss_nt.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a7b73b5ac9..0e81fa38d5 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -7572,7 +7572,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S Printer_entry *Printer = find_printer_index_by_hnd(p, handle); int snum; WERROR result; - REGISTRY_VALUE *val; + REGISTRY_VALUE *val = NULL; NT_PRINTER_DATA *p_data; int i, key_index, num_values; int name_length; @@ -7610,7 +7610,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S * cf: MSDN EnumPrinterData remark section */ - if ( !in_value_len && !in_data_len ) + if ( !in_value_len && !in_data_len && (key_index != -1) ) { DEBUGADD(6,("Activating NT mega-hack to find sizes\n")); @@ -7650,8 +7650,9 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S * the value len is wrong in NT sp3 * that's the number of bytes not the number of unicode chars */ - - val = regval_ctr_specific_value( &p_data->keys[key_index].values, idx ); + + if ( key_index != -1 ) + val = regval_ctr_specific_value( &p_data->keys[key_index].values, idx ); if ( !val ) { -- cgit From 4660928c61dd4d61f24fb447e1c71c828a7710b3 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 31 Mar 2003 17:43:45 +0000 Subject: fix potential smbd crash when we fail to alloacte a policy handle for a printer open; CR 2102 (reviewed by jreilly) (This used to be commit 26478158bc03fdf019589ce68062100a39149b52) --- source3/rpc_server/srv_spoolss_nt.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 0e81fa38d5..4dd4456b2c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -519,18 +519,19 @@ static BOOL open_printer_hnd(pipes_struct *p, POLICY_HND *hnd, char *name, uint3 ZERO_STRUCTP(new_printer); - if ( !(new_printer->ctx = talloc_init("Printer Entry [0x%x]", (uint32)hnd)) ) { - DEBUG(0,("open_printer_hnd: talloc_init() failed!\n")); + if (!create_policy_hnd(p, hnd, free_printer_entry, new_printer)) { + SAFE_FREE(new_printer); return False; } - new_printer->notify.option=NULL; - /* Add to the internal list. */ DLIST_ADD(printers_list, new_printer); - if (!create_policy_hnd(p, hnd, free_printer_entry, new_printer)) { - SAFE_FREE(new_printer); + new_printer->notify.option=NULL; + + if ( !(new_printer->ctx = talloc_init("Printer Entry [0x%x]", (uint32)hnd)) ) { + DEBUG(0,("open_printer_hnd: talloc_init() failed!\n")); + close_printer_handle(p, hnd); return False; } -- cgit From 45c7b76da3f738095910ebfe04d2f173000c59e7 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 1 Apr 2003 14:57:59 +0000 Subject: fix potential handle leak in _spoolss_open_printer_ex(); final fix for CR2102; reviewed by jra (This used to be commit 50c25e54ff05bfb01a93e84afd2ad92e90d5a5c2) --- source3/rpc_server/srv_spoolss_nt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 4dd4456b2c..3c309d6e16 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1623,8 +1623,10 @@ Can't find printer handle we created for printer %s\n", name )); /* NT doesn't let us connect to a printer if the connecting user doesn't have print permission. */ - if (!get_printer_snum(p, handle, &snum)) + if (!get_printer_snum(p, handle, &snum)) { + close_printer_handle(p, handle); return WERR_BADFID; + } se_map_standard(&printer_default->access_required, &printer_std_mapping); -- cgit From a9b39993fa366a6f0ab26deafac61947a9e8e1cc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 2 Apr 2003 02:31:51 +0000 Subject: Subtle changes to message handling after ENUMJOBS. Jeremy. (This used to be commit e5e83544dc0acf812bfa5ea17960b5a6be954ca1) --- source3/rpc_server/srv_spoolss_nt.c | 103 +++++++++++++++++++++++++++++++++--- 1 file changed, 95 insertions(+), 8 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 3c309d6e16..1c203733b5 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1031,9 +1031,10 @@ done: /*********************************************************************** **********************************************************************/ -static BOOL notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, void *buf, size_t len ) +static BOOL notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len ) { + uint32 tv_sec, tv_usec; size_t offset = 0; /* Unpack message */ @@ -1041,8 +1042,9 @@ static BOOL notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, void *buf, size_t len ) offset += tdb_unpack((char *)buf + offset, len - offset, "f", msg->printer); - offset += tdb_unpack((char *)buf + offset, len - offset, "ddddd", - &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags); + offset += tdb_unpack((char *)buf + offset, len - offset, "ddddddd", + &tv_sec, &tv_usec, + &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags); if (msg->len == 0) tdb_unpack((char *)buf + offset, len - offset, "dd", @@ -1054,6 +1056,9 @@ static BOOL notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, void *buf, size_t len ) DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message, type %d, field 0x%02x, flags 0x%04x\n", msg->type, msg->field, msg->flags)); + tv->tv_sec = tv_sec; + tv->tv_usec = tv_usec; + if (msg->len == 0) DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0], msg->notify.value[1])); @@ -1063,6 +1068,58 @@ static BOOL notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, void *buf, size_t len ) return True; } +/* ENUMJOB last timestamp list. */ +struct ejts_list { + struct ejts_list *next, *prev; + char *printer_name; + struct timeval tv; +}; + +static struct ejts_list *ejts_head; + +static struct ejts_list *find_enumjobs_timestamp(const char *printer_name) +{ + struct ejts_list *ejtsl; + + for( ejtsl = ejts_head; ejtsl; ejtsl = ejtsl->next) + if (strequal(ejtsl->printer_name, printer_name)) + return ejtsl; + return NULL; +} + +static void set_enumjobs_timestamp(int snum) +{ + const char *printer_name = lp_const_servicename(snum); + struct ejts_list *ejtsl = find_enumjobs_timestamp(printer_name); + + if (!ejtsl) { + ejtsl = (struct ejts_list *)malloc(sizeof(struct ejts_list)); + if (!ejtsl) + return; + ejtsl->printer_name = strdup(printer_name); + if (!ejtsl->printer_name) { + SAFE_FREE(ejtsl); + return; + } + DLIST_ADD(ejts_head, ejtsl); + } + + gettimeofday(&ejtsl->tv, NULL); +} + +static int timeval_diff(struct timeval *tv1, struct timeval *tv2) +{ + if (tv1->tv_sec > tv2->tv_sec) + return 1; + if (tv1->tv_sec < tv2->tv_sec) + return -1; + if (tv1->tv_usec > tv2->tv_usec) + return 1; + if (tv1->tv_usec < tv2->tv_usec) + return -1; + return 0; +} + /******************************************************************** Receive a notify2 message list ********************************************************************/ @@ -1104,8 +1161,9 @@ static void receive_notify2_message_list(int msg_type, pid_t src, void *msg, siz * call. Therefore messages are grouped according to printer handle. */ - for ( i=0; i len) { DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n")); return; @@ -1122,9 +1180,32 @@ static void receive_notify2_message_list(int msg_type, pid_t src, void *msg, siz /* unpack messages */ ZERO_STRUCT( notify ); - notify2_unpack_msg( ¬ify, msg_ptr, msg_len ); + notify2_unpack_msg( ¬ify, &msg_tv, msg_ptr, msg_len ); msg_ptr += msg_len; + /* See if it is still relevent. */ + if (notify.type == JOB_NOTIFY_TYPE) { + BOOL status_is_deleting = False; + + if (notify.field == JOB_NOTIFY_STATUS && (notify.notify.value[0] & (JOB_STATUS_DELETING|JOB_STATUS_DELETED))) + status_is_deleting = True; + + if (!status_is_deleting) { + struct ejts_list *ejtsl = find_enumjobs_timestamp(notify.printer); + + if (ejtsl && (timeval_diff(&ejtsl->tv, &msg_tv) > 0)) { + + DEBUG(10, ("receive_notify2_message_list: enumjobs ts = %u, %u, msg ts = %u, %u discarding\n", + (unsigned int)ejtsl->tv.tv_sec, (unsigned int)ejtsl->tv.tv_usec, + (unsigned int)msg_tv.tv_sec, (unsigned int)msg_tv.tv_usec )); + + /* Message no longer relevent. Ignore it. */ + if ( notify.len != 0 ) + SAFE_FREE( notify.notify.data ); + continue; + } + } + } /* add to correct list in container */ notify_msg_ctr_addmsg( &messages, ¬ify ); @@ -6352,6 +6433,7 @@ WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; uint32 *returned = &r_u->returned; + WERROR wret; int snum; print_status_struct prt_status; @@ -6373,15 +6455,20 @@ WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO DEBUGADD(4,("count:[%d], status:[%d], [%s]\n", *returned, prt_status.status, prt_status.message)); if (*returned == 0) { + set_enumjobs_timestamp(snum); SAFE_FREE(queue); return WERR_OK; } switch (level) { case 1: - return enumjobs_level1(queue, snum, buffer, offered, needed, returned); + wret = enumjobs_level1(queue, snum, buffer, offered, needed, returned); + set_enumjobs_timestamp(snum); + return wret; case 2: - return enumjobs_level2(queue, snum, buffer, offered, needed, returned); + wret = enumjobs_level2(queue, snum, buffer, offered, needed, returned); + set_enumjobs_timestamp(snum); + return wret; default: SAFE_FREE(queue); *returned=0; -- cgit From b4f1061cca33d66a0e473cb6631b1373bca338ac Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 8 Apr 2003 14:06:27 +0000 Subject: fixup extra SAFE_FREE()'s noticed by abartlet (This used to be commit 51d330dcf3bd74367fc18f4229a9cfa0392f0b36) --- source3/rpc_server/srv_spoolss_nt.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 1c203733b5..fd837cd9fb 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -8414,7 +8414,6 @@ static WERROR getjob_level_1(print_queue_struct *queue, int count, int snum, uin info_1=(JOB_INFO_1 *)malloc(sizeof(JOB_INFO_1)); if (info_1 == NULL) { - SAFE_FREE(queue); return WERR_NOMEM; } @@ -8424,7 +8423,6 @@ static WERROR getjob_level_1(print_queue_struct *queue, int count, int snum, uin } if (found==False) { - SAFE_FREE(queue); SAFE_FREE(info_1); /* NT treats not found as bad param... yet another bad choice */ return WERR_INVALID_PARAM; -- cgit From c618a8dae43cc45cf8686dd4235435c30b689dcd Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 9 Apr 2003 05:30:48 +0000 Subject: another forgotten merge sitting on my laptop from app_head; only stall open_printer when 2k client opens with admin privs & fix reply for ChangeId printer data reply (This used to be commit 12eb3e993788eb8bc0e9eb62e60a8b55079df5ad) --- source3/rpc_server/srv_spoolss_nt.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index fd837cd9fb..3d2b73d571 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1768,8 +1768,11 @@ Can't find printer handle we created for printer %s\n", name )); /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN optimization in Windows 2000 clients --jerry */ - if ( RA_WIN2K == get_remote_arch() ) - usleep( 384000 ); + if ( (printer_default->access_required == PRINTER_ACCESS_ADMINISTER) + && (RA_WIN2K == get_remote_arch()) ) + { + usleep( 500000 ); + } return WERR_OK; } @@ -2463,7 +2466,7 @@ WERROR _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO status = WERR_NOMEM; goto done; } - **data = printer->info_2->changeid; + SIVAL( *data, 0, printer->info_2->changeid ); status = WERR_OK; } else -- cgit From 7c735eabc9c8277a13fd47bdb18b264e225672d1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 10 Apr 2003 18:43:13 +0000 Subject: Ensure we're not filtering our essential delete messages. Added jobid debug when unpacking message. Jeremy. (This used to be commit 8a6f3313e69c6d47e20838f42ebc9f8a2ce9ddc4) --- source3/rpc_server/srv_spoolss_nt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 3d2b73d571..62884fbdf4 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1053,8 +1053,8 @@ static BOOL notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, voi tdb_unpack((char *)buf + offset, len - offset, "B", &msg->len, &msg->notify.data); - DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message, type %d, field 0x%02x, flags 0x%04x\n", - msg->type, msg->field, msg->flags)); + DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n", + msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags)); tv->tv_sec = tv_sec; tv->tv_usec = tv_usec; -- cgit From 84b4b3caf1a59d9206e351fef0aa42fcaba1e346 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 11 Apr 2003 20:29:36 +0000 Subject: simple fix to hopefully speed up srv_spoolss_replyopenprinter(). Use the client address from the pipe->conn->client_address instead of trying to resolve the name in the _spoolss_rffpcn() request. Should make us more robust as well when the clients are not registered in DNS or WINS. (This used to be commit 23f0fcf6421b1e8dd6ed6ab14af14ea7eb380c1c) --- source3/rpc_server/srv_spoolss_nt.c | 58 +++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 22 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 62884fbdf4..90090efde8 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2507,34 +2507,43 @@ done: Connect to the client machine. **********************************************************/ -static BOOL spoolss_connect_to_client(struct cli_state *the_cli, const char *remote_machine) +static BOOL spoolss_connect_to_client(struct cli_state *the_cli, + struct in_addr *client_ip, const char *remote_machine) { ZERO_STRUCTP(the_cli); + if(cli_initialise(the_cli) == NULL) { - DEBUG(0,("connect_to_client: unable to initialize client connection.\n")); + DEBUG(0,("spoolss_connect_to_client: unable to initialize client connection.\n")); return False; } + + if ( is_zero_ip(*client_ip) ) { + if(!resolve_name( remote_machine, &the_cli->dest_ip, 0x20)) { + DEBUG(0,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine)); + cli_shutdown(the_cli); + return False; + } - if(!resolve_name( remote_machine, &the_cli->dest_ip, 0x20)) { - DEBUG(0,("connect_to_client: Can't resolve address for %s\n", remote_machine)); - cli_shutdown(the_cli); - return False; + if (ismyip(the_cli->dest_ip)) { + DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n", remote_machine)); + cli_shutdown(the_cli); + return False; + } } - - if (ismyip(the_cli->dest_ip)) { - DEBUG(0,("connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n", remote_machine)); - cli_shutdown(the_cli); - return False; + else { + the_cli->dest_ip.s_addr = client_ip->s_addr; + DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n", + inet_ntoa(*client_ip) )); } if (!cli_connect(the_cli, remote_machine, &the_cli->dest_ip)) { - DEBUG(0,("connect_to_client: unable to connect to SMB server on machine %s. Error was : %s.\n", remote_machine, cli_errstr(the_cli) )); + DEBUG(0,("spoolss_connect_to_client: unable to connect to SMB server on machine %s. Error was : %s.\n", remote_machine, cli_errstr(the_cli) )); cli_shutdown(the_cli); return False; } if (!attempt_netbios_session_request(the_cli, global_myname(), remote_machine, &the_cli->dest_ip)) { - DEBUG(0,("connect_to_client: machine %s rejected the NetBIOS session request.\n", + DEBUG(0,("spoolss_connect_to_client: machine %s rejected the NetBIOS session request.\n", remote_machine)); cli_shutdown(the_cli); return False; @@ -2543,13 +2552,13 @@ static BOOL spoolss_connect_to_client(struct cli_state *the_cli, const char *rem the_cli->protocol = PROTOCOL_NT1; if (!cli_negprot(the_cli)) { - DEBUG(0,("connect_to_client: machine %s rejected the negotiate protocol. Error was : %s.\n", remote_machine, cli_errstr(the_cli) )); + DEBUG(0,("spoolss_connect_to_client: machine %s rejected the negotiate protocol. Error was : %s.\n", remote_machine, cli_errstr(the_cli) )); cli_shutdown(the_cli); return False; } if (the_cli->protocol != PROTOCOL_NT1) { - DEBUG(0,("connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine)); + DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine)); cli_shutdown(the_cli); return False; } @@ -2559,19 +2568,19 @@ static BOOL spoolss_connect_to_client(struct cli_state *the_cli, const char *rem */ if (!cli_session_setup(the_cli, "", "", 0, "", 0, "")) { - DEBUG(0,("connect_to_client: machine %s rejected the session setup. Error was : %s.\n", remote_machine, cli_errstr(the_cli) )); + DEBUG(0,("spoolss_connect_to_client: machine %s rejected the session setup. Error was : %s.\n", remote_machine, cli_errstr(the_cli) )); cli_shutdown(the_cli); return False; } if (!(the_cli->sec_mode & 1)) { - DEBUG(0,("connect_to_client: machine %s isn't in user level security mode\n", remote_machine)); + DEBUG(0,("spoolss_connect_to_client: machine %s isn't in user level security mode\n", remote_machine)); cli_shutdown(the_cli); return False; } if (!cli_send_tconX(the_cli, "IPC$", "IPC", "", 1)) { - DEBUG(0,("connect_to_client: machine %s rejected the tconX on the IPC$ share. Error was : %s.\n", remote_machine, cli_errstr(the_cli) )); + DEBUG(0,("spoolss_connect_to_client: machine %s rejected the tconX on the IPC$ share. Error was : %s.\n", remote_machine, cli_errstr(the_cli) )); cli_shutdown(the_cli); return False; } @@ -2582,7 +2591,7 @@ static BOOL spoolss_connect_to_client(struct cli_state *the_cli, const char *rem */ if(cli_nt_session_open(the_cli, PI_SPOOLSS) == False) { - DEBUG(0,("connect_to_client: unable to open the domain client session to machine %s. Error was : %s.\n", remote_machine, cli_errstr(the_cli))); + DEBUG(0,("spoolss_connect_to_client: unable to open the domain client session to machine %s. Error was : %s.\n", remote_machine, cli_errstr(the_cli))); cli_nt_session_close(the_cli); cli_ulogoff(the_cli); cli_shutdown(the_cli); @@ -2596,7 +2605,9 @@ static BOOL spoolss_connect_to_client(struct cli_state *the_cli, const char *rem Connect to the client. ****************************************************************************/ -static BOOL srv_spoolss_replyopenprinter(int snum, const char *printer, uint32 localprinter, uint32 type, POLICY_HND *handle) +static BOOL srv_spoolss_replyopenprinter(int snum, const char *printer, + uint32 localprinter, uint32 type, + POLICY_HND *handle, struct in_addr *client_ip) { WERROR result; @@ -2609,7 +2620,7 @@ static BOOL srv_spoolss_replyopenprinter(int snum, const char *printer, uint32 l fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */ - if(!spoolss_connect_to_client(¬ify_cli, unix_printer)) + if(!spoolss_connect_to_client(¬ify_cli, client_ip, unix_printer)) return False; message_register(MSG_PRINTER_NOTIFY2, receive_notify2_message_list); @@ -2658,6 +2669,7 @@ WERROR _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE uint32 printerlocal = q_u->printerlocal; int snum = -1; SPOOL_NOTIFY_OPTION *option = q_u->option; + struct in_addr client_ip; /* store the notify value in the printer struct */ @@ -2687,10 +2699,12 @@ WERROR _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE else if ( (Printer->printer_type == PRINTER_HANDLE_IS_PRINTER) && !get_printer_snum(p, handle, &snum) ) return WERR_BADFID; + + client_ip.s_addr = inet_addr(p->conn->client_address); if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine, Printer->notify.printerlocal, 1, - &Printer->notify.client_hnd)) + &Printer->notify.client_hnd, &client_ip)) return WERR_SERVER_UNAVAILABLE; Printer->notify.client_connected=True; -- cgit From e1ea87ff03f7029f309a119e6be726a11000ab34 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 11 Apr 2003 23:48:24 +0000 Subject: * We must return 0x2 as the majorversion for nt4 to upload drivers * fix bug found by clobber_region() (This used to be commit b2e29c7bd45f8f33d9ed58fe75bbf5ffc78350f5) --- source3/rpc_server/srv_spoolss_nt.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 90090efde8..b0529fea81 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2307,7 +2307,17 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint *type = 0x4; if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) return WERR_NOMEM; - SIVAL(*data, 0, 3); + + /* Windows NT 4.0 seems to not allow uploading of drivers + to a server that reports 0x3 as the MajorVersion. + need to investigate more how Win2k gets around this . + -- jerry */ + + if ( RA_WINNT == get_remote_arch() ) + SIVAL(*data, 0, 2); + else + SIVAL(*data, 0, 3); + *needed = 0x4; return WERR_OK; } -- cgit From ce31379577d5e713ab7214e46631bd260e653ea6 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Apr 2003 20:42:26 +0000 Subject: Fix typos (This used to be commit 21166e87bfeeaa5079dfbcac3df9232d73986532) --- source3/rpc_server/srv_spoolss_nt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index b0529fea81..dfc045877d 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1255,7 +1255,7 @@ static BOOL srv_spoolss_drv_upgrade_printer(char* drivername) /********************************************************************** callback to receive a MSG_PRINTER_DRVUPGRADE message and interate - over all printers, upgrading ones as neessary + over all printers, upgrading ones as necessary **********************************************************************/ void do_drv_upgrade_printer(int msg_type, pid_t src, void *buf, size_t len) @@ -1303,7 +1303,7 @@ void do_drv_upgrade_printer(int msg_type, pid_t src, void *buf, size_t len) } /******************************************************************** - Update the cahce for all printq's with a registered client + Update the cache for all printq's with a registered client connection ********************************************************************/ -- cgit From dfe1dd1455199b561a4fc0600a9e23d5f949197a Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 15 Apr 2003 06:56:43 +0000 Subject: Merge of comment typo. Whitespace syncup. (This used to be commit c69237edf2bfdb426447d808fbd1dc6eb5cffabe) --- source3/rpc_server/srv_spoolss_nt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index dfc045877d..f9788fc7f0 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -526,7 +526,7 @@ static BOOL open_printer_hnd(pipes_struct *p, POLICY_HND *hnd, char *name, uint3 /* Add to the internal list. */ DLIST_ADD(printers_list, new_printer); - + new_printer->notify.option=NULL; if ( !(new_printer->ctx = talloc_init("Printer Entry [0x%x]", (uint32)hnd)) ) { @@ -534,7 +534,7 @@ static BOOL open_printer_hnd(pipes_struct *p, POLICY_HND *hnd, char *name, uint3 close_printer_handle(p, hnd); return False; } - + if (!set_printer_hnd_printertype(new_printer, name)) { close_printer_handle(p, hnd); return False; @@ -2623,7 +2623,7 @@ static BOOL srv_spoolss_replyopenprinter(int snum, const char *printer, /* * If it's the first connection, contact the client - * and connect to the IPC$ share anonumously + * and connect to the IPC$ share anonymously */ if (smb_connections==0) { fstring unix_printer; -- cgit From 2a3a9f0bf43c3bf99a71f7296bb5ff6199893fea Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 23 Apr 2003 13:27:35 +0000 Subject: Merge the 'safe' parts of my StrnCpy patch - many of the users really wanted a pstrcpy/fstrcpy or at most a safe_strcpy(). These have the advantage of being compiler-verifiable. Get these out of the way, along with a rewrite of 'get_short_archi' in the spoolss client and server. (This pushes around const string pointers, rather than copied strings). Andrew Bartlett (This used to be commit 32fb801ddc035e8971e9911ed4b6e51892e9d1cc) --- source3/rpc_server/srv_spoolss_nt.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index f9788fc7f0..e6129f4ace 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -7601,12 +7601,12 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen { pstring path; pstring long_archi; - pstring short_archi; + const char *short_archi; DRIVER_DIRECTORY_1 *info=NULL; unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)-1); - if (get_short_archi(short_archi, long_archi)==False) + if (!(short_archi = get_short_archi(long_archi))) return WERR_INVALID_ENVIRONMENT; if((info=(DRIVER_DIRECTORY_1 *)malloc(sizeof(DRIVER_DIRECTORY_1))) == NULL) @@ -8432,7 +8432,7 @@ WERROR _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS *q_ /**************************************************************************** ****************************************************************************/ -static WERROR getjob_level_1(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getjob_level_1(print_queue_struct **queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { int i=0; BOOL found=False; @@ -8445,7 +8445,7 @@ static WERROR getjob_level_1(print_queue_struct *queue, int count, int snum, uin } for (i=0; i Date: Thu, 15 May 2003 17:21:32 +0000 Subject: Ensure sys_adminlog code won't coredump with incorrect client params. Jeremy. (This used to be commit b754089a2660975c593a6651e5e72b7360a0aba1) --- source3/rpc_server/srv_spoolss_nt.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index e6129f4ace..95237e979f 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -48,6 +48,13 @@ static const char * drv_ver_to_os[] = { "WIN2K", /* driver version/cversion 3 */ }; +static const char *get_drv_ver_to_os(int ver) +{ + if (ver < 0 || ver > 3) + return ""; + return drv_ver_to_os[ver]; +} + struct table_node { const char *long_archi; const char *short_archi; @@ -7464,14 +7471,14 @@ WERROR _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u, /* BEGIN_ADMIN_LOG */ switch(level) { case 3: + fstrcpy(driver_name, driver.info_3->name ? driver.info_3->name : ""); sys_adminlog(LOG_INFO,"Added printer driver. Print driver name: %s. Print driver OS: %s. Administrator name: %s.", - driver.info_3->name,drv_ver_to_os[driver.info_3->cversion],uidtoname(user.uid)); - fstrcpy(driver_name, driver.info_3->name); + driver_name, get_drv_ver_to_os(driver.info_3->cversion),uidtoname(user.uid)); break; case 6: + fstrcpy(driver_name, driver.info_6->name ? driver.info_6->name : ""); sys_adminlog(LOG_INFO,"Added printer driver. Print driver name: %s. Print driver OS: %s. Administrator name: %s.", - driver.info_6->name,drv_ver_to_os[driver.info_6->version],uidtoname(user.uid)); - fstrcpy(driver_name, driver.info_6->name); + driver_name, get_drv_ver_to_os(driver.info_6->version),uidtoname(user.uid)); break; } /* END_ADMIN_LOG */ -- cgit From cd22a6ac90f1dfdd30894219afe579fc1869ce45 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 3 Jun 2003 07:18:18 +0000 Subject: Merge DEBUG message on usleep on open. Jeremy. (This used to be commit 063a210448d57e08db6d47a584c591f20645c80a) --- source3/rpc_server/srv_spoolss_nt.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 95237e979f..92b1481ab8 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1778,6 +1778,7 @@ Can't find printer handle we created for printer %s\n", name )); if ( (printer_default->access_required == PRINTER_ACCESS_ADMINISTER) && (RA_WIN2K == get_remote_arch()) ) { + DEBUG(10,("_spoolss_open_printer_ex: Enabling LAN/WAN hack for Win2k clients.\n")); usleep( 500000 ); } -- cgit From 0a9396dcca1e30fa32fbcde3ee2dce86f586ba4b Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 13 Jun 2003 04:35:53 +0000 Subject: Rename some uuid functions so as not to conflict with system versions. Fixes bug #154. (This used to be commit 986eae40f7669d15dc75aed340e628aa7efafddc) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 92b1481ab8..217d2cbaea 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4330,7 +4330,7 @@ static BOOL construct_printer_info_7(Printer_entry *print_hnd, PRINTER_INFO_7 *p GUID guid; if (is_printer_published(print_hnd, snum, &guid)) { - asprintf(&guid_str, "{%s}", uuid_string_static(guid)); + asprintf(&guid_str, "{%s}", smb_uuid_string_static(guid)); strupper(guid_str); init_unistr(&printer->guid, guid_str); printer->action = SPOOL_DS_PUBLISH; -- cgit From 6b31240391949fb6afa83853aa3df30b354d508a Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 3 Jul 2003 17:18:07 +0000 Subject: Fix for bug #199 (xp driver uploads). Needed to support the "OSVersion" print server data value. (This used to be commit 02bc7be1ac6b75bf6559ea684bbc89ab3e19402e) --- source3/rpc_server/srv_spoolss_nt.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 217d2cbaea..deca2ad8bb 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2339,7 +2339,6 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint return WERR_OK; } -#if 0 /* JERRY */ /* REG_BINARY * uint32 size = 0x114 * uint32 major = 5 @@ -2348,14 +2347,23 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint * extra unicode string = e.g. "Service Pack 3" */ if (!StrCaseCmp(value, "OSVersion")) { - *type = 0x4; - if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) + *type = 0x3; + *needed = 0x114; + + if((*data = (uint8 *)talloc(ctx, (*needed)*sizeof(uint8) )) == NULL) return WERR_NOMEM; - SIVAL(*data, 0, 2); - *needed = 0x4; + ZERO_STRUCTP( *data ); + + SIVAL(*data, 0, *needed); /* size */ + SIVAL(*data, 4, 5); /* Windows 2000 == 5.0 */ + SIVAL(*data, 8, 0); + SIVAL(*data, 12, 2195); /* build */ + + /* leave extra string empty */ + return WERR_OK; } -#endif + if (!StrCaseCmp(value, "DefaultSpoolDirectory")) { fstring string; -- cgit From ce72beb2b558d86fb49063c6b1fa00e07952ce56 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 3 Jul 2003 19:11:31 +0000 Subject: Removed strupper/strlower macros that automatically map to strupper_m/strlower_m. I really want people to think about when they're using multibyte strings. Jeremy. (This used to be commit ff222716a08af65d26ad842ce4c2841cc6540959) --- source3/rpc_server/srv_spoolss_nt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index deca2ad8bb..2b68e34b2d 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4339,7 +4339,7 @@ static BOOL construct_printer_info_7(Printer_entry *print_hnd, PRINTER_INFO_7 *p if (is_printer_published(print_hnd, snum, &guid)) { asprintf(&guid_str, "{%s}", smb_uuid_string_static(guid)); - strupper(guid_str); + strupper_m(guid_str); init_unistr(&printer->guid, guid_str); printer->action = SPOOL_DS_PUBLISH; } else { @@ -4689,7 +4689,7 @@ WERROR _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOOL_ */ unistr2_to_ascii(name, servername, sizeof(name)-1); - strupper(name); + strupper_m(name); switch (level) { case 1: -- cgit From eb2b68302205e6dc217a4abdef494c45e9fc3cc0 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 14 Jul 2003 19:51:34 +0000 Subject: fix cache coherency bug in print handle print_info_2 cache. Needs to be rewritten to use a reference counter, but this will work for now. also the memory allocation in the printing code needs to be cleaned up to use talloc exclusively. (This used to be commit 3d293027563b36411b7f84ed9d8f47f926271c6f) --- source3/rpc_server/srv_spoolss_nt.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 2b68e34b2d..2d316051af 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -273,7 +273,34 @@ static Printer_entry *find_printer_index_by_hnd(pipes_struct *p, POLICY_HND *hnd } /**************************************************************************** - find printer index by handle + look for a printer object cached on an open printer handle +****************************************************************************/ + +WERROR find_printer_in_print_hnd_cache( TALLOC_CTX *ctx, NT_PRINTER_INFO_LEVEL_2 **info2, + const char *printername ) +{ + Printer_entry *p; + + DEBUG(10,("find_printer_in_print_hnd_cache: printer [%s]\n", printername)); + + for ( p=printers_list; p; p=p->next ) + { + if ( p->printer_type==PRINTER_HANDLE_IS_PRINTER + && p->printer_info + && StrCaseCmp(p->dev.handlename, printername) == 0 ) + { + DEBUG(10,("Found printer\n")); + *info2 = dup_printer_2( ctx, p->printer_info->info_2 ); + if ( *info2 ) + return WERR_OK; + } + } + + return WERR_INVALID_PRINTER_NAME; +} + +/**************************************************************************** + destroy any cached printer_info_2 structures on open handles ****************************************************************************/ void invalidate_printer_hnd_cache( char *printername ) -- cgit From 06345b81164d575bc1faf537e3c48a5dfe8e2442 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 22 Jul 2003 01:18:24 +0000 Subject: Use %p for a pointer type in a printf-style format string. Also casting a pointer to a uint32 value is incorrect on a 64-bit architecture. (This used to be commit afed2cbbcc07de9e453156972250f5f9d22e8e83) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 2d316051af..c7fab32957 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -563,7 +563,7 @@ static BOOL open_printer_hnd(pipes_struct *p, POLICY_HND *hnd, char *name, uint3 new_printer->notify.option=NULL; - if ( !(new_printer->ctx = talloc_init("Printer Entry [0x%x]", (uint32)hnd)) ) { + if ( !(new_printer->ctx = talloc_init("Printer Entry [%p]", hnd)) ) { DEBUG(0,("open_printer_hnd: talloc_init() failed!\n")); close_printer_handle(p, hnd); return False; -- cgit From 77373f1f8e3b2f61e9bbcd9fadfb83257d390cf2 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 24 Jul 2003 23:46:27 +0000 Subject: More printf fixes - size_t is long on some architectures. (This used to be commit ba4d334b822248d8ab929c9568533431603d967e) --- source3/rpc_server/srv_spoolss_nt.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index c7fab32957..a33179d054 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -478,7 +478,7 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) fstring sname; BOOL found=False; - DEBUG(4,("Setting printer name=%s (len=%d)\n", handlename, strlen(handlename))); + DEBUG(4,("Setting printer name=%s (len=%l)\n", handlename, strlen(handlename))); if (Printer->printer_type==PRINTER_HANDLE_IS_PRINTSERVER) { ZERO_STRUCT(Printer->dev.printerservername); @@ -497,7 +497,7 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) aprinter=handlename; } - DEBUGADD(5,("searching for [%s] (len=%d)\n", aprinter, strlen(aprinter))); + DEBUGADD(5,("searching for [%s] (len=%l)\n", aprinter, strlen(aprinter))); /* * The original code allowed smbd to store a printer name that @@ -1176,7 +1176,7 @@ static void receive_notify2_message_list(int msg_type, pid_t src, void *msg, siz msg_count = IVAL(buf, 0); msg_ptr = buf + 4; - DEBUG(5, ("receive_notify2_message_list: got %d messages in list\n", msg_count)); + DEBUG(5, ("receive_notify2_message_list: got %l messages in list\n", msg_count)); if (msg_count == 0) { DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n")); @@ -5135,7 +5135,7 @@ static uint32 init_unistr_array(uint16 **uni_array, fstring *char_array, const c else pstrcpy( line, v ); - DEBUGADD(6,("%d:%s:%d\n", i, line, strlen(line))); + DEBUGADD(6,("%d:%s:%l\n", i, line, strlen(line))); /* add one extra unit16 for the second terminating NULL */ @@ -9092,7 +9092,7 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ { if ( (enum_values=talloc(p->mem_ctx, num_entries*sizeof(PRINTER_ENUM_VALUES))) == NULL ) { - DEBUG(0,("_spoolss_enumprinterdataex: talloc() failed to allocate memory for [%d] bytes!\n", + DEBUG(0,("_spoolss_enumprinterdataex: talloc() failed to allocate memory for [%l] bytes!\n", num_entries*sizeof(PRINTER_ENUM_VALUES))); result = WERR_NOMEM; goto done; -- cgit From 7d833de662b83f026b54a236588da27dd8899630 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 25 Jul 2003 04:24:40 +0000 Subject: More printf portability fixes. Got caught out by some gcc'isms last time. )-: (This used to be commit 59dae1da66a5eb7e128263bd578f167d8746e9f0) --- source3/rpc_server/srv_spoolss_nt.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a33179d054..0f984019e9 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -478,7 +478,7 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) fstring sname; BOOL found=False; - DEBUG(4,("Setting printer name=%s (len=%l)\n", handlename, strlen(handlename))); + DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename, (unsigned long)strlen(handlename))); if (Printer->printer_type==PRINTER_HANDLE_IS_PRINTSERVER) { ZERO_STRUCT(Printer->dev.printerservername); @@ -497,7 +497,7 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) aprinter=handlename; } - DEBUGADD(5,("searching for [%s] (len=%l)\n", aprinter, strlen(aprinter))); + DEBUGADD(5,("searching for [%s] (len=%lu)\n", aprinter, (unsigned long)strlen(aprinter))); /* * The original code allowed smbd to store a printer name that @@ -1176,7 +1176,7 @@ static void receive_notify2_message_list(int msg_type, pid_t src, void *msg, siz msg_count = IVAL(buf, 0); msg_ptr = buf + 4; - DEBUG(5, ("receive_notify2_message_list: got %l messages in list\n", msg_count)); + DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count)); if (msg_count == 0) { DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n")); @@ -5135,7 +5135,7 @@ static uint32 init_unistr_array(uint16 **uni_array, fstring *char_array, const c else pstrcpy( line, v ); - DEBUGADD(6,("%d:%s:%l\n", i, line, strlen(line))); + DEBUGADD(6,("%d:%s:%lu\n", i, line, (unsigned long)strlen(line))); /* add one extra unit16 for the second terminating NULL */ @@ -9092,8 +9092,8 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ { if ( (enum_values=talloc(p->mem_ctx, num_entries*sizeof(PRINTER_ENUM_VALUES))) == NULL ) { - DEBUG(0,("_spoolss_enumprinterdataex: talloc() failed to allocate memory for [%l] bytes!\n", - num_entries*sizeof(PRINTER_ENUM_VALUES))); + DEBUG(0,("_spoolss_enumprinterdataex: talloc() failed to allocate memory for [%lu] bytes!\n", + (unsigned long)num_entries*sizeof(PRINTER_ENUM_VALUES))); result = WERR_NOMEM; goto done; } -- cgit From 6bf70229ae11147496ac7318a3c980c3b985ce8b Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 25 Jul 2003 14:35:17 +0000 Subject: fix some error returns and strings; patch from metze (This used to be commit 948b1b138cf1fce18c93645fbdf948e589b19dc5) --- source3/rpc_server/srv_spoolss_nt.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 0f984019e9..8237298ebb 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2393,9 +2393,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint if (!StrCaseCmp(value, "DefaultSpoolDirectory")) { - fstring string; - - fstrcpy(string, string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH)); + const char *string="C:\\PRINTERS"; *type = 0x1; *needed = 2*(strlen(string)+1); if((*data = (uint8 *)talloc(ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL) @@ -2411,7 +2409,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint } if (!StrCaseCmp(value, "Architecture")) { - pstring string="Windows NT x86"; + const char *string="Windows NT x86"; *type = 0x1; *needed = 2*(strlen(string)+1); if((*data = (uint8 *)talloc(ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL) @@ -7912,6 +7910,11 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP return WERR_BADFID; } + if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER ) { + DEBUG(10,("_spoolss_setprinterdata: Not implemented for server handles yet\n")); + return WERR_INVALID_PARAM; + } + if (!get_printer_snum(p,handle, &snum)) return WERR_BADFID; @@ -8698,7 +8701,7 @@ WERROR _spoolss_getprinterdataex(pipes_struct *p, SPOOL_Q_GETPRINTERDATAEX *q_u, /* Is the handle to a printer or to the server? */ if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) { - DEBUG(10,("_spoolss_getprinterdatex: Not implemented for server handles yet\n")); + DEBUG(10,("_spoolss_getprinterdataex: Not implemented for server handles yet\n")); status = WERR_INVALID_PARAM; goto done; } @@ -8780,10 +8783,15 @@ WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, SetPrinterData if key is "PrinterDriverData" */ if (!Printer) { - DEBUG(2,("_spoolss_setprinterdata: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); + DEBUG(2,("_spoolss_setprinterdataex: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); return WERR_BADFID; } + if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER ) { + DEBUG(10,("_spoolss_setprinterdataex: Not implemented for server handles yet\n")); + return WERR_INVALID_PARAM; + } + if ( !get_printer_snum(p,handle, &snum) ) return WERR_BADFID; -- cgit From 38b3ee6467230955ec94c820f3740eab89534d8c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 8 Aug 2003 17:08:35 +0000 Subject: RPC fix from Ronan Waide . Tested with rpcecho. Jeremy. (This used to be commit 68590b9e2266cf76b46a68cca0acaa47733811fe) --- source3/rpc_server/srv_spoolss_nt.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 8237298ebb..edbd1562bc 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -7100,7 +7100,6 @@ static void fill_port_2(PORT_INFO_2 *port, const char *name) init_unistr(&port->port_name, name); init_unistr(&port->monitor_name, "Local Monitor"); init_unistr(&port->description, "Local Port"); -#define PORT_TYPE_WRITE 1 port->port_type=PORT_TYPE_WRITE; port->reserved=0x0; } -- cgit From 062f89bc2833bf49f873a7fd5c2624babd702db0 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Fri, 15 Aug 2003 01:42:30 +0000 Subject: get rid of some sompiler warnings on IRIX (This used to be commit a6a39c61e8228c8b3b7552ab3c61ec3a6a639143) --- source3/rpc_server/srv_spoolss_nt.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index edbd1562bc..725672da69 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -387,7 +387,6 @@ static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) char *cmd = lp_deleteprinter_cmd(); pstring command; int ret; - int i; /* Printer->dev.handlename equals portname equals sharename */ slprintf(command, sizeof(command)-1, "%s \"%s\"", cmd, @@ -406,7 +405,7 @@ static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) /* go ahead and re-read the services immediately */ reload_services( False ); - if ( ( i = lp_servicenumber( Printer->dev.handlename ) ) < 0 ) + if ( lp_servicenumber( Printer->dev.handlename ) < 0 ) return WERR_ACCESS_DENIED; } @@ -957,7 +956,7 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) SPOOL_NOTIFY_INFO_DATA *data; uint32 data_len = 0; uint32 id; - int i, event_index; + int i; /* Is there notification on this handle? */ @@ -980,8 +979,6 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) data = talloc( mem_ctx, msg_group->num_msgs*sizeof(SPOOL_NOTIFY_INFO_DATA) ); ZERO_STRUCTP(data); - event_index = 0; - /* build the array of change notifications */ sending_msg_count = 0; @@ -3753,7 +3750,6 @@ static WERROR printserver_notify_info(pipes_struct *p, POLICY_HND *hnd, Printer_entry *Printer=find_printer_index_by_hnd(p, hnd); int n_services=lp_numservices(); int i; - uint32 id; SPOOL_NOTIFY_OPTION *option; SPOOL_NOTIFY_OPTION_TYPE *option_type; @@ -3763,7 +3759,6 @@ static WERROR printserver_notify_info(pipes_struct *p, POLICY_HND *hnd, return WERR_BADFID; option=Printer->notify.option; - id=1; info->version=2; info->data=NULL; info->count=0; @@ -6192,12 +6187,9 @@ static WERROR publish_or_unpublish_printer(pipes_struct *p, POLICY_HND *handle, SPOOL_PRINTER_INFO_LEVEL_7 *info7 = info->info_7; int snum; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); - WERROR result; DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action)); - result = WERR_OK; - if (!Printer) return WERR_BADFID; @@ -7722,7 +7714,6 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S NT_PRINTER_INFO_LEVEL *printer = NULL; - uint32 param_index; uint32 biggest_valuesize; uint32 biggest_datasize; uint32 data_len; @@ -7771,7 +7762,6 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S { DEBUGADD(6,("Activating NT mega-hack to find sizes\n")); - param_index = 0; biggest_valuesize = 0; biggest_datasize = 0; @@ -9185,12 +9175,11 @@ static WERROR getprintprocessordirectory_level_1(UNISTR2 *name, { pstring path; pstring long_archi; - const char *short_archi; PRINTPROCESSOR_DIRECTORY_1 *info=NULL; unistr2_to_ascii(long_archi, environment, sizeof(long_archi)-1); - if (!(short_archi = get_short_archi(long_archi))) + if (!get_short_archi(long_archi)) return WERR_INVALID_ENVIRONMENT; if((info=(PRINTPROCESSOR_DIRECTORY_1 *)malloc(sizeof(PRINTPROCESSOR_DIRECTORY_1))) == NULL) -- cgit From 4e88fd330e0306188e5a95d8b3d3665e4e3d56bb Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 15 Aug 2003 20:12:40 +0000 Subject: possible fix for bug 288 to repcent using an uninitialized cli_state struct (This used to be commit d09dc91c024d718a8ddb6b7f08c7fe84716beda4) --- source3/rpc_server/srv_spoolss_nt.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 725672da69..646aac347c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2668,6 +2668,8 @@ static BOOL srv_spoolss_replyopenprinter(int snum, const char *printer, fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */ + ZERO_STRUCT(notify_cli); + if(!spoolss_connect_to_client(¬ify_cli, client_ip, unix_printer)) return False; -- cgit From 983b4e7011174961748eb5d3011ec59b25d0917e Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sat, 23 Aug 2003 03:34:24 +0000 Subject: it never amazes me when some new things crawls out of the windows spooler. :-( When installing the Adobe PS driver onto a Samba printer via cupsaddsmb, I noticed a WIN2k client sending DeletePrinterData("DependentFiles") pver and over. I also noticed that we never checked to see if the value was valid. No now we do and return WERR_BADFILE which I think is correct. Next, I noticed that we never wrote the updated printer out to disk after a succesfully DeletePrinterData[Ex](). Finally, I found a driver (Canon BJC 1000 using the Adobe PS drivers and foomatic PPD file) that was destroying the device name string in the devmode. So now get_a_printer_2() always writes out the device name in \\server\share form. I think these changes might fix bug 294. (This used to be commit deb25780874b66e68ac597db24fbc50e7f7458b5) --- source3/rpc_server/srv_spoolss_nt.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 646aac347c..7159527a7d 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -8023,6 +8023,9 @@ WERROR _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_ unistr2_to_ascii( valuename, value, sizeof(valuename)-1 ); status = delete_printer_dataex( printer, SPOOL_PRINTERDATA_KEY, valuename ); + + if ( W_ERROR_IS_OK(status) ) + mod_a_printer( *printer, 2 ); free_a_printer(&printer, 2); @@ -8886,6 +8889,9 @@ WERROR _spoolss_deleteprinterdataex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATAEX status = delete_printer_dataex( printer, keyname, valuename ); + if ( W_ERROR_IS_OK(status) ) + mod_a_printer( *printer, 2 ); + free_a_printer(&printer, 2); return status; -- cgit From d3b9384308e4b5130c9455b853edc4702d7af303 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 25 Sep 2003 21:26:16 +0000 Subject: Fix for #480. Change the interface for init_unistr2 to not take a length but a flags field. We were assuming that 2*strlen(mb_string) == length of ucs2-le string. This is not the case. Count it after conversion. Jeremy. (This used to be commit f82c273a42f930c7152cfab84394781744815e0e) --- source3/rpc_server/srv_spoolss_nt.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 7159527a7d..493f58f8a8 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -690,7 +690,7 @@ static void notify_string(struct spoolss_notify_msg *msg, /* The length of the message includes the trailing \0 */ - init_unistr2(&unistr, msg->notify.data, msg->len); + init_unistr2(&unistr, msg->notify.data, UNI_STR_TERMINATE); data->notify_data.data.length = msg->len * 2; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, msg->len * 2); @@ -6121,7 +6121,7 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, */ if (!strequal(printer->info_2->comment, old_printer->info_2->comment)) { - init_unistr2( &buffer, printer->info_2->comment, strlen(printer->info_2->comment)+1 ); + init_unistr2( &buffer, printer->info_2->comment, UNI_STR_TERMINATE); set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "description", REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 ); @@ -6129,7 +6129,7 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, } if (!strequal(printer->info_2->sharename, old_printer->info_2->sharename)) { - init_unistr2( &buffer, printer->info_2->sharename, strlen(printer->info_2->sharename)+1 ); + init_unistr2( &buffer, printer->info_2->sharename, UNI_STR_TERMINATE); set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "printerName", REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 ); set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "shareName", @@ -6139,7 +6139,7 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, } if (!strequal(printer->info_2->portname, old_printer->info_2->portname)) { - init_unistr2( &buffer, printer->info_2->portname, strlen(printer->info_2->portname)+1 ); + init_unistr2( &buffer, printer->info_2->portname, UNI_STR_TERMINATE); set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "portName", REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 ); @@ -6147,7 +6147,7 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, } if (!strequal(printer->info_2->location, old_printer->info_2->location)) { - init_unistr2( &buffer, printer->info_2->location, strlen(printer->info_2->location)+1 ); + init_unistr2( &buffer, printer->info_2->location, UNI_STR_TERMINATE); set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "location", REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 ); @@ -6157,7 +6157,7 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, /* here we need to update some more DsSpooler keys */ /* uNCName, serverName, shortServerName */ - init_unistr2( &buffer, global_myname(), strlen(global_myname())+1 ); + init_unistr2( &buffer, global_myname(), UNI_STR_TERMINATE); set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "serverName", REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 ); set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "shortServerName", @@ -6165,7 +6165,7 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, slprintf( asc_buffer, sizeof(asc_buffer)-1, "\\\\%s\\%s", global_myname(), printer->info_2->sharename ); - init_unistr2( &buffer, asc_buffer, strlen(asc_buffer)+1 ); + init_unistr2( &buffer, asc_buffer, UNI_STR_TERMINATE); set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "uNCName", REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 ); -- cgit From 3092718ab127bcf83138552a0518cea070451d14 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 2 Oct 2003 17:36:47 +0000 Subject: Portability fix from schmitz@hp.com (Joachim Schmitz) for bug #548. Jeremy. (This used to be commit 6677eba28a1f2de11c36e3edc5b7d2854452bd04) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 493f58f8a8..f2fb02176b 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1803,7 +1803,7 @@ Can't find printer handle we created for printer %s\n", name )); && (RA_WIN2K == get_remote_arch()) ) { DEBUG(10,("_spoolss_open_printer_ex: Enabling LAN/WAN hack for Win2k clients.\n")); - usleep( 500000 ); + sys_usleep( 500000 ); } return WERR_OK; -- cgit From f589164ed94d79161d0798296c325b81c5eadbc7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 21 Oct 2003 21:19:00 +0000 Subject: Patch from Stefan Metzmacher to fix signing problems when reverse connecting back to a client for printer notify. Jeremy. (This used to be commit 06aa434c3fdb139e3f3143d19413556945cbcd4f) --- source3/rpc_server/srv_spoolss_nt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index f2fb02176b..15578f6148 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2598,7 +2598,8 @@ static BOOL spoolss_connect_to_client(struct cli_state *the_cli, } the_cli->protocol = PROTOCOL_NT1; - + cli_setup_signing_state(the_cli, lp_client_signing()); + if (!cli_negprot(the_cli)) { DEBUG(0,("spoolss_connect_to_client: machine %s rejected the negotiate protocol. Error was : %s.\n", remote_machine, cli_errstr(the_cli) )); cli_shutdown(the_cli); -- cgit From 2f2e5b01919fe4daf60f97430959ebc98e31ce92 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 30 Jan 2004 18:38:48 +0000 Subject: Fix up name canonicalization (needed for krb5 keytab support later). Remove source_env handler (no longer used in any codepath). Jeremy. (This used to be commit 3a3e33603084048e647af86a9badaaf49433c789) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 15578f6148..61c908e474 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2431,7 +2431,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint if (!StrCaseCmp(value, "DNSMachineName")) { pstring hostname; - if (!get_myfullname(hostname)) + if (!get_mydnsfullname(hostname)) return WERR_BADFILE; *type = 0x1; *needed = 2*(strlen(hostname)+1); -- cgit From dbb38cc6b5829d9ac45e3dea40878039edd26f8d Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 16 Mar 2004 17:06:11 +0000 Subject: merging print change notify fix from HP appliance. Also might address some one the issues in BUG 1007 (This used to be commit 17ecea4152fb0883acde675b01f19d3e19ff1d64) --- source3/rpc_server/srv_spoolss_nt.c | 78 ------------------------------------- 1 file changed, 78 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 61c908e474..c971ff3631 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1099,58 +1099,6 @@ static BOOL notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, voi return True; } -/* ENUMJOB last timestamp list. */ -struct ejts_list { - struct ejts_list *next, *prev; - char *printer_name; - struct timeval tv; -}; - -static struct ejts_list *ejts_head; - -static struct ejts_list *find_enumjobs_timestamp(const char *printer_name) -{ - struct ejts_list *ejtsl; - - for( ejtsl = ejts_head; ejtsl; ejtsl = ejtsl->next) - if (strequal(ejtsl->printer_name, printer_name)) - return ejtsl; - return NULL; -} - -static void set_enumjobs_timestamp(int snum) -{ - const char *printer_name = lp_const_servicename(snum); - struct ejts_list *ejtsl = find_enumjobs_timestamp(printer_name); - - if (!ejtsl) { - ejtsl = (struct ejts_list *)malloc(sizeof(struct ejts_list)); - if (!ejtsl) - return; - ejtsl->printer_name = strdup(printer_name); - if (!ejtsl->printer_name) { - SAFE_FREE(ejtsl); - return; - } - DLIST_ADD(ejts_head, ejtsl); - } - - gettimeofday(&ejtsl->tv, NULL); -} - -static int timeval_diff(struct timeval *tv1, struct timeval *tv2) -{ - if (tv1->tv_sec > tv2->tv_sec) - return 1; - if (tv1->tv_sec < tv2->tv_sec) - return -1; - if (tv1->tv_usec > tv2->tv_usec) - return 1; - if (tv1->tv_usec < tv2->tv_usec) - return -1; - return 0; -} - /******************************************************************** Receive a notify2 message list ********************************************************************/ @@ -1214,29 +1162,6 @@ static void receive_notify2_message_list(int msg_type, pid_t src, void *msg, siz notify2_unpack_msg( ¬ify, &msg_tv, msg_ptr, msg_len ); msg_ptr += msg_len; - /* See if it is still relevent. */ - if (notify.type == JOB_NOTIFY_TYPE) { - BOOL status_is_deleting = False; - - if (notify.field == JOB_NOTIFY_STATUS && (notify.notify.value[0] & (JOB_STATUS_DELETING|JOB_STATUS_DELETED))) - status_is_deleting = True; - - if (!status_is_deleting) { - struct ejts_list *ejtsl = find_enumjobs_timestamp(notify.printer); - - if (ejtsl && (timeval_diff(&ejtsl->tv, &msg_tv) > 0)) { - - DEBUG(10, ("receive_notify2_message_list: enumjobs ts = %u, %u, msg ts = %u, %u discarding\n", - (unsigned int)ejtsl->tv.tv_sec, (unsigned int)ejtsl->tv.tv_usec, - (unsigned int)msg_tv.tv_sec, (unsigned int)msg_tv.tv_usec )); - - /* Message no longer relevent. Ignore it. */ - if ( notify.len != 0 ) - SAFE_FREE( notify.notify.data ); - continue; - } - } - } /* add to correct list in container */ notify_msg_ctr_addmsg( &messages, ¬ify ); @@ -6518,7 +6443,6 @@ WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO DEBUGADD(4,("count:[%d], status:[%d], [%s]\n", *returned, prt_status.status, prt_status.message)); if (*returned == 0) { - set_enumjobs_timestamp(snum); SAFE_FREE(queue); return WERR_OK; } @@ -6526,11 +6450,9 @@ WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO switch (level) { case 1: wret = enumjobs_level1(queue, snum, buffer, offered, needed, returned); - set_enumjobs_timestamp(snum); return wret; case 2: wret = enumjobs_level2(queue, snum, buffer, offered, needed, returned); - set_enumjobs_timestamp(snum); return wret; default: SAFE_FREE(queue); -- cgit From 8ad3d8c9b065f3a2040beff801bdc9dceac868a8 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 13 Apr 2004 14:39:48 +0000 Subject: r196: merging struct uuid from trunk (This used to be commit 911a28361b9d8dd50597627f245ebfb57c6294fb) --- source3/rpc_server/srv_spoolss_nt.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index c971ff3631..3b1bb5ede5 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3,7 +3,7 @@ * RPC Pipe client / server routines * Copyright (C) Andrew Tridgell 1992-2000, * Copyright (C) Luke Kenneth Casson Leighton 1996-2000, - * Copyright (C) Jean François Micouleau 1998-2000, + * Copyright (C) Jean François Micouleau 1998-2000, * Copyright (C) Jeremy Allison 2001-2002, * Copyright (C) Gerald Carter 2000-2003, * Copyright (C) Tim Potter 2001-2002. @@ -4283,10 +4283,11 @@ static BOOL construct_printer_info_5(Printer_entry *print_hnd, PRINTER_INFO_5 *p static BOOL construct_printer_info_7(Printer_entry *print_hnd, PRINTER_INFO_7 *printer, int snum) { char *guid_str = NULL; - GUID guid; + UUID_FLAT guid; if (is_printer_published(print_hnd, snum, &guid)) { - asprintf(&guid_str, "{%s}", smb_uuid_string_static(guid)); + asprintf(&guid_str, "{%s}", + smb_uuid_string_static(smb_uuid_unpack_static(guid))); strupper_m(guid_str); init_unistr(&printer->guid, guid_str); printer->action = SPOOL_DS_PUBLISH; -- cgit From 7959cba656133840c37d293ffab6831f3097016f Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 27 May 2004 15:38:54 +0000 Subject: r925: add changes frpm trunk (r841 and r842) -- enable background queue update process and allow printers to have different sharenames from printernames (This used to be commit 066b9c4276a968788a03709a00d4f672ac032df7) --- source3/rpc_server/srv_spoolss_nt.c | 107 +++++++++++++++++++++++++++--------- 1 file changed, 81 insertions(+), 26 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 3b1bb5ede5..a6d47a46c3 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -473,9 +473,11 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) { int snum; int n_services=lp_numservices(); - char *aprinter; + char *aprinter, *printername; fstring sname; BOOL found=False; + NT_PRINTER_INFO_LEVEL *printer; + WERROR result; DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename, (unsigned long)strlen(handlename))); @@ -496,31 +498,56 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) aprinter=handlename; } - DEBUGADD(5,("searching for [%s] (len=%lu)\n", aprinter, (unsigned long)strlen(aprinter))); + DEBUGADD(5, ("searching for [%s] (len=%lu)\n", aprinter, (unsigned long)strlen(aprinter))); - /* - * The original code allowed smbd to store a printer name that - * was different from the share name. This is not possible - * anymore, so I've simplified this loop greatly. Here - * we are just verifying that the printer name is a valid - * printer service defined in smb.conf - * --jerry [Fri Feb 15 11:17:46 CST 2002] - */ + /* have to search on sharename and PRINTER_INFO2->printername */ for (snum=0; 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++; + + if ( strequal(printername, aprinter) ) { + found = True; + } + + DEBUGADD(10, ("printername: %s\n", printername)); + + free_a_printer( &printer, 2); + + if ( found ) + break; } @@ -5854,14 +5881,28 @@ static WERROR update_printer_sec(POLICY_HND *handle, uint32 level, static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) { + fstring printername; + const char *p; + DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s portname=%s drivername=%s comment=%s location=%s\n", info->servername, info->printername, info->sharename, info->portname, info->drivername, info->comment, info->location)); /* we force some elements to "correct" values */ slprintf(info->servername, sizeof(info->servername)-1, "\\\\%s", get_called_name()); fstrcpy(info->sharename, lp_servicename(snum)); + + /* make sure printername is in \\server\printername format */ + + fstrcpy( printername, info->printername ); + p = printername; + if ( printername[0] == '\\' && printername[1] == '\\' ) { + if ( (p = strchr_m( &printername[2], '\\' )) != NULL ) + p++; + } + slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s", - get_called_name(), info->sharename); + get_called_name(), p ); + info->attributes = PRINTER_ATTRIBUTE_SAMBA; @@ -6057,14 +6098,28 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, if (!strequal(printer->info_2->sharename, old_printer->info_2->sharename)) { init_unistr2( &buffer, printer->info_2->sharename, UNI_STR_TERMINATE); - set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "printerName", - REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 ); set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "shareName", REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 ); notify_printer_sharename(snum, printer->info_2->sharename); } + if (!strequal(printer->info_2->printername, old_printer->info_2->printername)) { + char *pname; + + if ( (pname = strchr_m( printer->info_2->printername+2, '\\' )) != NULL ) + pname++; + else + pname = printer->info_2->printername; + + + init_unistr2( &buffer, pname, UNI_STR_TERMINATE); + set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "printerName", + REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 ); + + notify_printer_printername( snum, pname ); + } + if (!strequal(printer->info_2->portname, old_printer->info_2->portname)) { init_unistr2( &buffer, printer->info_2->portname, UNI_STR_TERMINATE); set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "portName", @@ -8750,19 +8805,19 @@ WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, { /* save the OID if one was specified */ if ( oid_string ) { - fstrcat( keyname, "\\" ); - fstrcat( keyname, SPOOL_OID_KEY ); + fstrcat( keyname, "\\" ); + fstrcat( keyname, SPOOL_OID_KEY ); - /* - * I'm not checking the status here on purpose. Don't know - * if this is right, but I'm returning the status from the - * previous set_printer_dataex() call. I have no idea if - * this is right. --jerry - */ + /* + * I'm not checking the status here on purpose. Don't know + * if this is right, but I'm returning the status from the + * previous set_printer_dataex() call. I have no idea if + * this is right. --jerry + */ - set_printer_dataex( printer, keyname, valuename, - REG_SZ, (void*)oid_string, strlen(oid_string)+1 ); - } + set_printer_dataex( printer, keyname, valuename, + REG_SZ, (void*)oid_string, strlen(oid_string)+1 ); + } status = mod_a_printer(*printer, 2); } -- cgit From 087868c49916e96cf860577144bc19b799fd720e Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 23 Jun 2004 15:46:01 +0000 Subject: r1230: (merges from HP PSA) fixing a couple of caching bugs in the printing code. (a) make sure to clear jobs_changed list when deleting a job and, (b) invalidate the printer handle cache when we get a notification that something has changed on that printer (This used to be commit e3d4fea7808abc77bfdb1a540ab18afe04af5030) --- source3/rpc_server/srv_spoolss_nt.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a6d47a46c3..d8c6b5350c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -5,7 +5,7 @@ * Copyright (C) Luke Kenneth Casson Leighton 1996-2000, * Copyright (C) Jean François Micouleau 1998-2000, * Copyright (C) Jeremy Allison 2001-2002, - * Copyright (C) Gerald Carter 2000-2003, + * Copyright (C) Gerald Carter 2000-2004, * Copyright (C) Tim Potter 2001-2002. * * This program is free software; you can redistribute it and/or modify @@ -312,6 +312,7 @@ void invalidate_printer_hnd_cache( char *printername ) for ( p=printers_list; p; p=p->next ) { if ( p->printer_type==PRINTER_HANDLE_IS_PRINTER + && p->printer_info && StrCaseCmp(p->dev.handlename, printername)==0) { DEBUG(10,("invalidating printer_info cache for handl:\n")); @@ -1188,6 +1189,12 @@ static void receive_notify2_message_list(int msg_type, pid_t src, void *msg, siz ZERO_STRUCT( notify ); notify2_unpack_msg( ¬ify, &msg_tv, msg_ptr, msg_len ); msg_ptr += msg_len; + + /* we don't know if the change was from us or not so kill + any cached printer objects */ + + if ( notify.type == PRINTER_NOTIFY_TYPE ) + invalidate_printer_hnd_cache( notify.printer ); /* add to correct list in container */ -- cgit From cf1c4ae9a63b2cc76d40dd5db721520743a26153 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 24 Jun 2004 19:32:50 +0000 Subject: r1241: Fix incorrect type in printer publishing (struct uuid, not UUID_FLAT). Jeremy. (This used to be commit a535a059754730d0a5c2fe64ef14708da2ca6b5c) --- source3/rpc_server/srv_spoolss_nt.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index d8c6b5350c..06ba543597 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4317,11 +4317,10 @@ static BOOL construct_printer_info_5(Printer_entry *print_hnd, PRINTER_INFO_5 *p static BOOL construct_printer_info_7(Printer_entry *print_hnd, PRINTER_INFO_7 *printer, int snum) { char *guid_str = NULL; - UUID_FLAT guid; + struct uuid guid; if (is_printer_published(print_hnd, snum, &guid)) { - asprintf(&guid_str, "{%s}", - smb_uuid_string_static(smb_uuid_unpack_static(guid))); + asprintf(&guid_str, "{%s}", smb_uuid_string_static(guid)); strupper_m(guid_str); init_unistr(&printer->guid, guid_str); printer->action = SPOOL_DS_PUBLISH; -- cgit From aca738698904fe7c8c19202e3b4a080e7939864d Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 13 Jul 2004 19:20:37 +0000 Subject: r1484: BUG 1520: work around bug in xp sp2 rc2 where the client sends a fnpcn() request without previously sending a ffpcn(). Return what win2k sp4 does (This used to be commit 3f73d19807cbcbae8e5cfd96fd5c9b4de8c388a3) --- source3/rpc_server/srv_spoolss_nt.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 06ba543597..08553bfe65 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3725,6 +3725,12 @@ static WERROR printserver_notify_info(pipes_struct *p, POLICY_HND *hnd, info->data=NULL; info->count=0; + /* a bug in xp sp2 rc2 causes it to send a fnpcn request without + sending a ffpcn() request first */ + + if ( !option ) + return WERR_BADFID; + for (i=0; icount; i++) { option_type=&(option->ctr.type[i]); @@ -3787,6 +3793,12 @@ static WERROR printer_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY info->data=NULL; info->count=0; + /* a bug in xp sp2 rc2 causes it to send a fnpcn request without + sending a ffpcn() request first */ + + if ( !option ) + return WERR_BADFID; + get_printer_snum(p, hnd, &snum); for (i=0; icount; i++) { -- cgit From de22eab16dad4372a12c2e95f5fdb5fe9a8d162b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 14 Jul 2004 18:29:12 +0000 Subject: r1501: One more check for option != 0. Jeremy. (This used to be commit a6d0452a2d71201309a5abbe3ebc161ae75b17b8) --- source3/rpc_server/srv_spoolss_nt.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 08553bfe65..e3c9ff08d9 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -671,7 +671,11 @@ static BOOL is_monitoring_event(Printer_entry *p, uint16 notify_type, * might use the flags though instead of the NOTIFY_OPTION_INFO * --jerry */ - + + if (!option) { + return False; + } + if (p->notify.flags) return is_monitoring_event_flags( p->notify.flags, notify_type, notify_field); -- cgit From 60727acc3b33cb90309a43c10813fadcb94142eb Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 10 Aug 2004 14:27:17 +0000 Subject: r1692: first commit :) * add IA64 to the architecture table of printer-drivers * add new "net"-subcommands: net rpc printer migrate {drivers|printers|forms|security|settings|all} [printer] net rpc share migrate {shares|files|all} [share] this is the first part of the migration suite. this will will (once feature-complete) allow to do 1:1 server-cloning in the best possible way by making heavy use of samba's rpc_client-functions. all migration-steps are implemented as rpc/smb-client-calls; net communicates via rpc/smb with two servers at the same time (a remote, source server and a destination server that currently defaults to the local smbd). this allows e. g. printer-driver migration including driverfiles, recursive mirroring of file-shares including file-acls, etc. almost any migration step can be called with a migrate-subcommand to provide more flexibility during a migration process (at the cost of quite some redundancy :) ). "net rpc printer migrate settings" is still in a bad condition (many open questions that hopefully can be adressed soon). "net rpc share migrate security" as an isolated call to just migrate share-ACLs will be added later. Before playing with it, make sure to use a test-server. Migration is a serious business and this tool-set can perfectly overwrite your existing file/print-shares. * along with the migration functions had to make I the following changes: - implement setprinter level 3 client-side - implement net_add_share level 502 client-side - allow security descriptor to be set in setprinterdata level 2 serverside guenther (This used to be commit 8f1716a29b7e85baf738bc14df7dabf03762f723) --- source3/rpc_server/srv_spoolss_nt.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index e3c9ff08d9..ccff65688a 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1972,6 +1972,7 @@ static int get_version_id (char * arch) {"Windows NT R4000", "W32MIPS", 2 }, {"Windows NT Alpha_AXP", "W32ALPHA", 2 }, {"Windows NT PowerPC", "W32PPC", 2 }, + {"Windows IA64", "IA64", 3 }, {NULL, "", -1 } }; @@ -6220,6 +6221,7 @@ WERROR _spoolss_setprinter(pipes_struct *p, SPOOL_Q_SETPRINTER *q_u, SPOOL_R_SET DEVMODE_CTR devmode_ctr = q_u->devmode_ctr; SEC_DESC_BUF *secdesc_ctr = q_u->secdesc_ctr; uint32 command = q_u->command; + WERROR result; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); @@ -6233,7 +6235,12 @@ WERROR _spoolss_setprinter(pipes_struct *p, SPOOL_Q_SETPRINTER *q_u, SPOOL_R_SET case 0: return control_printer(handle, command, p); case 2: - return update_printer(p, handle, level, info, devmode_ctr.devmode); + result = update_printer(p, handle, level, info, devmode_ctr.devmode); + if (!W_ERROR_IS_OK(result)) + return result; + if (secdesc_ctr) + result = update_printer_sec(handle, level, info, p, secdesc_ctr); + return result; case 3: return update_printer_sec(handle, level, info, p, secdesc_ctr); -- cgit From 1842fde7d10a6faccae1a24ebc67f8452a5a828e Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 18 Aug 2004 13:55:58 +0000 Subject: r1885: tighten the cache consistency with the ntprinters.tdb entry an the in memory cache associated with open printer handles; also make sure that register_messages_flags() doesn't overwrite the originally registers flags (This used to be commit 540daf71d8ad189af5dd6d45aa1ce2b3d67da752) --- source3/rpc_server/srv_spoolss_nt.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index ccff65688a..5775b3ab49 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -180,7 +180,7 @@ static void srv_spoolss_replycloseprinter(int snum, POLICY_HND *handle) /* Tell the connections db we're no longer interested in * printer notify messages. */ - register_message_flags( False, FLAG_MSG_PRINTING ); + register_message_flags( False, FLAG_MSG_PRINT_NOTIFY ); } smb_connections--; @@ -1194,12 +1194,6 @@ static void receive_notify2_message_list(int msg_type, pid_t src, void *msg, siz notify2_unpack_msg( ¬ify, &msg_tv, msg_ptr, msg_len ); msg_ptr += msg_len; - /* we don't know if the change was from us or not so kill - any cached printer objects */ - - if ( notify.type == PRINTER_NOTIFY_TYPE ) - invalidate_printer_hnd_cache( notify.printer ); - /* add to correct list in container */ notify_msg_ctr_addmsg( &messages, ¬ify ); @@ -1226,6 +1220,22 @@ static void receive_notify2_message_list(int msg_type, pid_t src, void *msg, siz return; } +/******************************************************************** + callback to MSG_PRINTER_CHANGED. When a printer is changed by + one smbd, all of processes must clear their printer cache immediately. + ********************************************************************/ + +void receive_printer_mod_msg(int msg_type, pid_t src, void *buf, size_t len) +{ + fstring printername; + + fstrcpy( printername, buf ); + + DEBUG(10,("receive_printer_mod_msg: Printer change [%s]\n", printername )); + + invalidate_printer_hnd_cache( printername ); +} + /******************************************************************** Send a message to ourself about new driver being installed so we can upgrade the information for each printer bound to this @@ -2641,7 +2651,7 @@ static BOOL srv_spoolss_replyopenprinter(int snum, const char *printer, message_register(MSG_PRINTER_NOTIFY2, receive_notify2_message_list); /* Tell the connections db we're now interested in printer * notify messages. */ - register_message_flags( True, FLAG_MSG_PRINTING ); + register_message_flags( True, FLAG_MSG_PRINT_NOTIFY ); } /* -- cgit From b894c95f8d5c300d3a609cec5a211fc8bd956d1c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 20 Aug 2004 22:50:48 +0000 Subject: r1974: Just use a simple linked list for this. Jeremy. (This used to be commit 77bddd40b0a3cb9d2a95b61c098468d3d98e41b0) --- source3/rpc_server/srv_spoolss_nt.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 5775b3ab49..3a5bb8452f 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -64,14 +64,14 @@ struct table_node { static Printer_entry *printers_list; typedef struct _counter_printer_0 { - ubi_dlNode Next; - ubi_dlNode Prev; + struct _counter_printer_0 *next; + struct _counter_printer_0 *prev; int snum; uint32 counter; } counter_printer_0; -static ubi_dlList counter_list; +static counter_printer_0 *counter_list; static struct cli_state notify_cli; /* print notify back-channel */ static uint32 smb_connections=0; @@ -3949,9 +3949,7 @@ static BOOL construct_printer_info_0(Printer_entry *print_hnd, PRINTER_INFO_0 *p count = print_queue_length(snum, &status); /* check if we already have a counter for this printer */ - session_counter = (counter_printer_0 *)ubi_dlFirst(&counter_list); - - for(; session_counter; session_counter = (counter_printer_0 *)ubi_dlNext(session_counter)) { + for(session_counter = counter_list; session_counter; session_counter = session_counter->next) { if (session_counter->snum == snum) break; } @@ -3965,7 +3963,7 @@ static BOOL construct_printer_info_0(Printer_entry *print_hnd, PRINTER_INFO_0 *p ZERO_STRUCTP(session_counter); session_counter->snum=snum; session_counter->counter=0; - ubi_dlAddHead( &counter_list, (ubi_dlNode *)session_counter); + DLIST_ADD(counter_list, session_counter); } /* increment it */ -- cgit From 278f9467f2079044497e3fd4c5358c280f179e41 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 31 Aug 2004 15:11:41 +0000 Subject: r2133: Several fixes: * BUG 1627: fix for NIS compiles on HPUX 11.00, AIX 4.3 and 5.1 patch from Olaf Flebbe . Will need to watch this one in the build farm. * Fix bug found by rwf@loonybin.net where the PRINT_ATTRIBUTE_PUBLISHED was getting reset by attempts to sanitize the defined attributes (PRINTER_ATTRIBUTE_SAMBA) * Resolve name conflict on DEC OSF-5.1 (inspired by patch from Adharsh Praveen ) * Work around parsing error in the print change notify code (not that the alignment bug is still there but reording the entries in the array works around it). * remove duplicate declaration of getprintprocdir from rpcclient. (This used to be commit 7474c6a446037f3ca2546cb6984d800bfc524029) --- source3/rpc_server/srv_spoolss_nt.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 3a5bb8452f..d50237905a 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1026,7 +1026,7 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) sending_msg_count++; - DEBUG(10,("process_notify2_message: Sending message type [%x] field [%x] for printer [%s]\n", + DEBUG(10,("process_notify2_message: Sending message type [0x%x] field [0x%2x] for printer [%s]\n", msg->type, msg->field, p->dev.handlename)); /* @@ -5573,6 +5573,12 @@ WERROR _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_ return getprinterdriver2_level3(servername, architecture, clientmajorversion, snum, buffer, offered, needed); case 6: return getprinterdriver2_level6(servername, architecture, clientmajorversion, snum, buffer, offered, needed); +#if 0 /* JERRY */ + case 101: + /* apparently this call is the equivalent of + EnumPrinterDataEx() for the DsDriver key */ + break; +#endif } return WERR_UNKNOWN_LEVEL; @@ -5934,7 +5940,9 @@ static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s", get_called_name(), p ); - info->attributes = PRINTER_ATTRIBUTE_SAMBA; + info->attributes |= PRINTER_ATTRIBUTE_SAMBA; + info->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA; + return True; -- cgit From 5a8effaaae3c3037ae0f96a942734298950169c6 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 23 Sep 2004 19:24:02 +0000 Subject: r2569: Patch from Rob Foehl : - fix typo in libads/ldap_printer.c:39, ads_find_printer_on_server() (originally libads-typo.patch) - fix leak in printing/nt_printing.c, is_printer_published() (originally is_printer_published-leak.patch) - fix double print_backend_init() calls, now only called from main() - restructuring in printing/nt_printing.c - replaced (un)publish_it() with ads-specific functions - moved common code to nt_printer_publish() - improved error handling in several places - added check_published_printers() in printing/nt_printing.c, to verify that each published printer is actually in the directory at startup - changed calling semantics of mod_a_printer, dump_a_printer, and update_driver_init to be more consistent with the rest of the api and reduce some copying (This used to be commit 50a5a3dbd02acb0d09133b6e42cc37d091ea901d) --- source3/rpc_server/srv_spoolss_nt.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index d50237905a..e7b1fdb1d0 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1292,7 +1292,7 @@ void do_drv_upgrade_printer(int msg_type, pid_t src, void *buf, size_t len) /* all we care about currently is the change_id */ - result = mod_a_printer(*printer, 2); + result = mod_a_printer(printer, 2); if (!W_ERROR_IS_OK(result)) { DEBUG(3,("do_drv_upgrade_printer: mod_a_printer() failed with status [%s]\n", dos_errstr(result))); @@ -1396,7 +1396,7 @@ void reset_all_printerdata(int msg_type, pid_t src, void *buf, size_t len) printer->info_2->printername, printer->info_2->drivername)); } - result = mod_a_printer( *printer, 2 ); + result = mod_a_printer( printer, 2 ); if ( !W_ERROR_IS_OK(result) ) { DEBUG(3,("reset_all_printerdata: mod_a_printer() failed! (%s)\n", get_dos_error_msg(result))); @@ -6191,7 +6191,7 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 ); /* Update printer info */ - result = mod_a_printer(*printer, 2); + result = mod_a_printer(printer, 2); done: free_a_printer(&printer, 2); @@ -7433,7 +7433,7 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ } /* write the ASCII on disk */ - err = mod_a_printer(*printer, 2); + err = mod_a_printer(printer, 2); if (!W_ERROR_IS_OK(err)) { free_a_printer(&printer,2); return err; @@ -7971,7 +7971,7 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP status = set_printer_dataex( printer, SPOOL_PRINTERDATA_KEY, valuename, type, data, real_len ); if ( W_ERROR_IS_OK(status) ) - status = mod_a_printer(*printer, 2); + status = mod_a_printer(printer, 2); } done: @@ -8049,7 +8049,7 @@ WERROR _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_ status = delete_printer_dataex( printer, SPOOL_PRINTERDATA_KEY, valuename ); if ( W_ERROR_IS_OK(status) ) - mod_a_printer( *printer, 2 ); + mod_a_printer( printer, 2 ); free_a_printer(&printer, 2); @@ -8119,7 +8119,7 @@ WERROR _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM */ if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTER ) - status = mod_a_printer(*printer, 2); + status = mod_a_printer(printer, 2); done: if ( printer ) @@ -8186,7 +8186,7 @@ WERROR _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE */ if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTER ) - status = mod_a_printer(*printer, 2); + status = mod_a_printer(printer, 2); done: if ( printer ) @@ -8252,7 +8252,7 @@ WERROR _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM * */ if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTER ) - status = mod_a_printer(*printer, 2); + status = mod_a_printer(printer, 2); done: @@ -8864,7 +8864,7 @@ WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, REG_SZ, (void*)oid_string, strlen(oid_string)+1 ); } - status = mod_a_printer(*printer, 2); + status = mod_a_printer(printer, 2); } free_a_printer(&printer, 2); @@ -8914,7 +8914,7 @@ WERROR _spoolss_deleteprinterdataex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATAEX status = delete_printer_dataex( printer, keyname, valuename ); if ( W_ERROR_IS_OK(status) ) - mod_a_printer( *printer, 2 ); + mod_a_printer( printer, 2 ); free_a_printer(&printer, 2); @@ -9037,7 +9037,7 @@ WERROR _spoolss_deleteprinterkey(pipes_struct *p, SPOOL_Q_DELETEPRINTERKEY *q_u, status = delete_all_printer_data( printer->info_2, key ); if ( W_ERROR_IS_OK(status) ) - status = mod_a_printer(*printer, 2); + status = mod_a_printer(printer, 2); free_a_printer( &printer, 2 ); -- cgit From 31441aaa137145511a2c09dd540d46876df56701 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 1 Oct 2004 20:34:12 +0000 Subject: r2768: BUG 1519: save the hostname used in the open_printer_ex() for later reuse when filling in the spolss replies (also gets rid of get_called_name() (This used to be commit 57db8ca91f52329c7f8985c04463b6b69015b0c4) --- source3/rpc_server/srv_spoolss_nt.c | 277 +++++++++++++++++++++--------------- 1 file changed, 164 insertions(+), 113 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index e7b1fdb1d0..5c8a6235b6 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -201,7 +201,7 @@ static void free_printer_entry(void *ptr) snum = -1; srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd); } else if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTER) { - snum = print_queue_snum(Printer->dev.handlename); + snum = print_queue_snum(Printer->sharename); if (snum != -1) srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd); @@ -277,17 +277,19 @@ static Printer_entry *find_printer_index_by_hnd(pipes_struct *p, POLICY_HND *hnd ****************************************************************************/ WERROR find_printer_in_print_hnd_cache( TALLOC_CTX *ctx, NT_PRINTER_INFO_LEVEL_2 **info2, - const char *printername ) + const char *servername, const char *printername ) { Printer_entry *p; - DEBUG(10,("find_printer_in_print_hnd_cache: printer [%s]\n", printername)); + DEBUG(10,("find_printer_in_print_hnd_cache: printer [\\\\%s\\%s]\n", + servername, printername)); for ( p=printers_list; p; p=p->next ) { if ( p->printer_type==PRINTER_HANDLE_IS_PRINTER && p->printer_info - && StrCaseCmp(p->dev.handlename, printername) == 0 ) + && strequal( p->sharename, printername ) + && strequal( p->servername, servername ) ) { DEBUG(10,("Found printer\n")); *info2 = dup_printer_2( ctx, p->printer_info->info_2 ); @@ -313,7 +315,7 @@ void invalidate_printer_hnd_cache( char *printername ) { if ( p->printer_type==PRINTER_HANDLE_IS_PRINTER && p->printer_info - && StrCaseCmp(p->dev.handlename, printername)==0) + && StrCaseCmp(p->sharename, printername)==0) { DEBUG(10,("invalidating printer_info cache for handl:\n")); free_a_printer( &p->printer_info, 2 ); @@ -378,8 +380,8 @@ static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) } #endif - if (del_a_printer(Printer->dev.handlename) != 0) { - DEBUG(3,("Error deleting printer %s\n", Printer->dev.handlename)); + if (del_a_printer( Printer->sharename ) != 0) { + DEBUG(3,("Error deleting printer %s\n", Printer->sharename)); return WERR_BADFID; } @@ -389,9 +391,7 @@ static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) pstring command; int ret; - /* Printer->dev.handlename equals portname equals sharename */ - slprintf(command, sizeof(command)-1, "%s \"%s\"", cmd, - Printer->dev.handlename); + pstr_sprintf(command, "%s \"%s\"", cmd, Printer->sharename); DEBUG(10,("Running [%s]\n", command)); ret = smbrun(command, NULL); @@ -406,7 +406,7 @@ static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) /* go ahead and re-read the services immediately */ reload_services( False ); - if ( lp_servicenumber( Printer->dev.handlename ) < 0 ) + if ( lp_servicenumber( Printer->sharename ) < 0 ) return WERR_ACCESS_DENIED; } @@ -427,14 +427,14 @@ static BOOL get_printer_snum(pipes_struct *p, POLICY_HND *hnd, int *number) } switch (Printer->printer_type) { - case PRINTER_HANDLE_IS_PRINTER: - DEBUG(4,("short name:%s\n", Printer->dev.handlename)); - *number = print_queue_snum(Printer->dev.handlename); - return (*number != -1); - case PRINTER_HANDLE_IS_PRINTSERVER: - return False; - default: - return False; + case PRINTER_HANDLE_IS_PRINTER: + DEBUG(4,("short name:%s\n", Printer->sharename)); + *number = print_queue_snum(Printer->sharename); + return (*number != -1); + case PRINTER_HANDLE_IS_PRINTSERVER: + return False; + default: + return False; } } @@ -475,6 +475,7 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) int snum; int n_services=lp_numservices(); char *aprinter, *printername; + const char *servername; fstring sname; BOOL found=False; NT_PRINTER_INFO_LEVEL *printer; @@ -482,28 +483,37 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename, (unsigned long)strlen(handlename))); - if (Printer->printer_type==PRINTER_HANDLE_IS_PRINTSERVER) { - ZERO_STRUCT(Printer->dev.printerservername); - strncpy(Printer->dev.printerservername, handlename, strlen(handlename)); - return True; - } - - if (Printer->printer_type!=PRINTER_HANDLE_IS_PRINTER) - return False; - - if (*handlename=='\\') { - aprinter=strchr_m(handlename+2, '\\'); - aprinter++; + aprinter = handlename; + if ( *handlename == '\\' ) { + servername = handlename + 2; + if ( (aprinter = strchr_m( handlename+2, '\\' )) != NULL ) { + *aprinter = '\0'; + aprinter++; + } } else { - aprinter=handlename; + servername = ""; } + + /* save the servername to fill in replies on this handle */ + + if ( !is_myname_or_ipaddr( servername ) ) + return False; + + fstrcpy( Printer->servername, servername ); + + if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER ) + return True; - DEBUGADD(5, ("searching for [%s] (len=%lu)\n", aprinter, (unsigned long)strlen(aprinter))); + if ( Printer->printer_type != PRINTER_HANDLE_IS_PRINTER ) + return False; - /* have to search on sharename and PRINTER_INFO2->printername */ + DEBUGADD(5, ("searching for [%s]\n", aprinter )); - for (snum=0; snum %s\n", aprinter, sname)); - ZERO_STRUCT(Printer->dev.handlename); - fstrcpy(Printer->dev.handlename, sname); + fstrcpy(Printer->sharename, sname); return True; } @@ -696,10 +708,8 @@ static BOOL is_monitoring_event(Printer_entry *p, uint16 notify_type, } } - DEBUG(10, ("%s is not monitoring 0x%02x/0x%02x\n", - (p->printer_type == PRINTER_HANDLE_IS_PRINTER) ? - p->dev.handlename : p->dev.printerservername, - notify_type, notify_field)); + DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n", + p->servername, p->sharename, notify_type, notify_field)); return False; } @@ -995,13 +1005,13 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) if ( !p->notify.client_connected ) continue; - DEBUG(10,("Client connected! [%s]\n", p->dev.handlename)); + DEBUG(10,("Client connected! [\\\\%s\\%s]\n", p->servername, p->sharename)); /* For this printer? Print servers always receive notifications. */ if ( ( p->printer_type == PRINTER_HANDLE_IS_PRINTER ) && - ( !strequal(msg_group->printername, p->dev.handlename) ) ) + ( !strequal(msg_group->printername, p->sharename) ) ) continue; DEBUG(10,("Our printer\n")); @@ -1027,7 +1037,7 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) DEBUG(10,("process_notify2_message: Sending message type [0x%x] field [0x%2x] for printer [%s]\n", - msg->type, msg->field, p->dev.handlename)); + msg->type, msg->field, p->sharename)); /* * if the is a printer notification handle and not a job notification @@ -1323,7 +1333,7 @@ void update_monitored_printq_cache( void ) if ( (printer->printer_type == PRINTER_HANDLE_IS_PRINTER) && printer->notify.client_connected ) { - snum = print_queue_snum(printer->dev.handlename); + snum = print_queue_snum(printer->sharename); print_queue_status( snum, NULL, NULL ); } @@ -1619,9 +1629,9 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, return WERR_INVALID_PRINTER_NAME; Printer=find_printer_index_by_hnd(p, handle); - if (!Printer) { - DEBUG(0,(" _spoolss_open_printer_ex: logic error. \ -Can't find printer handle we created for printer %s\n", name )); + if ( !Printer ) { + DEBUG(0,(" _spoolss_open_printer_ex: logic error. Can't find printer " + "handle we created for printer %s\n", name )); close_printer_handle(p,handle); return WERR_INVALID_PRINTER_NAME; } @@ -1765,10 +1775,11 @@ Can't find printer handle we created for printer %s\n", name )); if ( (Printer->printer_type != PRINTER_HANDLE_IS_PRINTSERVER) && q_u->printer_default.devmode_cont.devmode_ptr ) { - convert_devicemode( Printer->dev.handlename, q_u->printer_default.devmode_cont.devmode, + convert_devicemode( Printer->sharename, q_u->printer_default.devmode_cont.devmode, &Printer->nt_devmode ); } +#if 0 /* JERRY -- I'm doubtful this is really effective */ /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN optimization in Windows 2000 clients --jerry */ @@ -1778,6 +1789,7 @@ Can't find printer handle we created for printer %s\n", name )); DEBUG(10,("_spoolss_open_printer_ex: Enabling LAN/WAN hack for Win2k clients.\n")); sys_usleep( 500000 ); } +#endif return WERR_OK; } @@ -2737,6 +2749,8 @@ WERROR _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE return WERR_OK; } +#if 0 /* JERRY -- disabled; not used for now */ + /******************************************************************* * fill a notify_info_data with the servername ********************************************************************/ @@ -2750,7 +2764,9 @@ void spoolss_notify_server_name(int snum, pstring temp_name, temp; uint32 len; - slprintf(temp_name, sizeof(temp_name)-1, "\\\\%s", get_called_name()); + fstrcpy( temp_name, "\\\\%L" ); + standard_sub_basic( NULL, temp_name, sizeof(temp_name)-1 ); + len = rpcstr_push(temp, temp_name, sizeof(temp)-2, STR_TERMINATE); @@ -2765,6 +2781,9 @@ void spoolss_notify_server_name(int snum, memcpy(data->notify_data.data.string, temp, len); } +#endif + + /******************************************************************* * fill a notify_info_data with the printername (not including the servername). ********************************************************************/ @@ -3437,7 +3456,7 @@ struct s_notify_info_data_table static const struct s_notify_info_data_table notify_info_data_table[] = { -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SERVER_NAME, "PRINTER_NOTIFY_SERVER_NAME", NOTIFY_STRING, spoolss_notify_server_name }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SERVER_NAME, "PRINTER_NOTIFY_SERVER_NAME", NOTIFY_STRING, NULL}, { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINTER_NAME, "PRINTER_NOTIFY_PRINTER_NAME", NOTIFY_STRING, spoolss_notify_printer_name }, { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SHARE_NAME, "PRINTER_NOTIFY_SHARE_NAME", NOTIFY_STRING, spoolss_notify_share_name }, { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PORT_NAME, "PRINTER_NOTIFY_PORT_NAME", NOTIFY_STRING, spoolss_notify_port_name }, @@ -3464,7 +3483,7 @@ static const struct s_notify_info_data_table notify_info_data_table[] = { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_BYTES, "PRINTER_NOTIFY_TOTAL_BYTES", NOTIFY_POINTER, NULL }, { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_BYTES_PRINTED, "PRINTER_NOTIFY_BYTES_PRINTED", NOTIFY_POINTER, NULL }, { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINTER_NAME, "JOB_NOTIFY_PRINTER_NAME", NOTIFY_STRING, spoolss_notify_printer_name }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_MACHINE_NAME, "JOB_NOTIFY_MACHINE_NAME", NOTIFY_STRING, spoolss_notify_server_name }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_MACHINE_NAME, "JOB_NOTIFY_MACHINE_NAME", NOTIFY_STRING, NULL}, { JOB_NOTIFY_TYPE, JOB_NOTIFY_PORT_NAME, "JOB_NOTIFY_PORT_NAME", NOTIFY_STRING, spoolss_notify_port_name }, { JOB_NOTIFY_TYPE, JOB_NOTIFY_USER_NAME, "JOB_NOTIFY_USER_NAME", NOTIFY_STRING, spoolss_notify_username }, { JOB_NOTIFY_TYPE, JOB_NOTIFY_NOTIFY_NAME, "JOB_NOTIFY_NOTIFY_NAME", NOTIFY_STRING, spoolss_notify_username }, @@ -3979,7 +3998,7 @@ static BOOL construct_printer_info_0(Printer_entry *print_hnd, PRINTER_INFO_0 *p init_unistr(&printer->printername, chaine); - slprintf(chaine,sizeof(chaine)-1,"\\\\%s", get_called_name()); + slprintf(chaine,sizeof(chaine)-1,"\\\\%s", get_server_name(print_hnd)); init_unistr(&printer->servername, chaine); printer->cjobs = count; @@ -4444,6 +4463,7 @@ static WERROR enum_all_printers_info_1_name(fstring name, NEW_BUFFER *buffer, ui return WERR_INVALID_NAME; } +#if 0 /* JERRY -- disabled for now. Don't think this is used, tested, or correct */ /******************************************************************** enum_all_printers_info_1_remote. *********************************************************************/ @@ -4458,9 +4478,10 @@ static WERROR enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, /* JFM: currently it's more a place holder than anything else. * In the spooler world there is a notion of server registration. - * the print servers are registring (sp ?) on the PDC (in the same domain) + * the print servers are registered on the PDC (in the same domain) * - * We should have a TDB here. The registration is done thru an undocumented RPC call. + * We should have a TDB here. The registration is done thru an + * undocumented RPC call. */ if((printer=(PRINTER_INFO_1 *)malloc(sizeof(PRINTER_INFO_1))) == NULL) @@ -4468,8 +4489,8 @@ static WERROR enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, *returned=1; - slprintf(printername, sizeof(printername)-1,"Windows NT Remote Printers!!\\\\%s", get_called_name()); - slprintf(desc, sizeof(desc)-1,"%s", get_called_name()); + slprintf(printername, sizeof(printername)-1,"Windows NT Remote Printers!!\\\\%s", name); + slprintf(desc, sizeof(desc)-1,"%s", name); slprintf(comment, sizeof(comment)-1, "Logged on Domain"); init_unistr(&printer->description, desc); @@ -4499,6 +4520,8 @@ static WERROR enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, return WERR_OK; } +#endif + /******************************************************************** enum_all_printers_info_1_network. *********************************************************************/ @@ -4605,8 +4628,10 @@ static WERROR enumprinters_level1( uint32 flags, fstring name, if (flags & PRINTER_ENUM_NAME) return enum_all_printers_info_1_name(name, buffer, offered, needed, returned); +#if 0 /* JERRY - disabled for now */ if (flags & PRINTER_ENUM_REMOTE) return enum_all_printers_info_1_remote(name, buffer, offered, needed, returned); +#endif if (flags & PRINTER_ENUM_NETWORK) return enum_all_printers_info_1_network(name, buffer, offered, needed, returned); @@ -5543,6 +5568,7 @@ WERROR _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_ uint32 *needed = &r_u->needed; uint32 *servermajorversion = &r_u->servermajorversion; uint32 *serverminorversion = &r_u->serverminorversion; + Printer_entry *printer; fstring servername; fstring architecture; @@ -5554,11 +5580,16 @@ WERROR _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_ DEBUG(4,("_spoolss_getprinterdriver2\n")); + if ( !(printer = find_printer_index_by_hnd( p, handle )) ) { + DEBUG(0,("_spoolss_getprinterdriver2: invalid printer handle!\n")); + return WERR_INVALID_PRINTER_NAME; + } + *needed = 0; *servermajorversion = 0; *serverminorversion = 0; - fstrcpy(servername, get_called_name()); + fstrcpy(servername, get_server_name( printer )); unistr2_to_ascii(architecture, uni_arch, sizeof(architecture)-1); if (!get_printer_snum(p, handle, &snum)) @@ -5840,11 +5871,9 @@ static WERROR update_printer_sec(POLICY_HND *handle, uint32 level, } /* NT seems to like setting the security descriptor even though - nothing may have actually changed. This causes annoying - dialog boxes when the user doesn't have permission to change - the security descriptor. */ + nothing may have actually changed. */ - nt_printing_getsec(p->mem_ctx, Printer->dev.handlename, &old_secdesc_ctr); + nt_printing_getsec(p->mem_ctx, Printer->sharename, &old_secdesc_ctr); if (DEBUGLEVEL >= 10) { SEC_ACL *the_acl; @@ -5903,7 +5932,7 @@ static WERROR update_printer_sec(POLICY_HND *handle, uint32 level, goto done; } - result = nt_printing_setsec(Printer->dev.handlename, new_secdesc_ctr); + result = nt_printing_setsec(Printer->sharename, new_secdesc_ctr); done: @@ -5911,9 +5940,12 @@ static WERROR update_printer_sec(POLICY_HND *handle, uint32 level, } /******************************************************************** - Do Samba sanity checks on a printer info struct. - this has changed purpose: it now "canonicalises" printer - info from a client rather than just checking it is correct + Canonicalize printer info from a client + + ATTN: It does not matter what we set the servername to hear + since we do the necessary work in get_a_printer() to set it to + the correct value based on what the client sent in the + _spoolss_open_printer_ex(). ********************************************************************/ static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) @@ -5921,11 +5953,13 @@ static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) fstring printername; const char *p; - DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s portname=%s drivername=%s comment=%s location=%s\n", - info->servername, info->printername, info->sharename, info->portname, info->drivername, info->comment, info->location)); + DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s " + "portname=%s drivername=%s comment=%s location=%s\n", + info->servername, info->printername, info->sharename, + info->portname, info->drivername, info->comment, info->location)); /* we force some elements to "correct" values */ - slprintf(info->servername, sizeof(info->servername)-1, "\\\\%s", get_called_name()); + slprintf(info->servername, sizeof(info->servername)-1, "\\\\%s", global_myname()); fstrcpy(info->sharename, lp_servicename(snum)); /* make sure printername is in \\server\printername format */ @@ -5938,7 +5972,7 @@ static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) } slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s", - get_called_name(), p ); + global_myname(), p ); info->attributes |= PRINTER_ATTRIBUTE_SAMBA; info->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA; @@ -6322,18 +6356,16 @@ WERROR _spoolss_addjob(pipes_struct *p, SPOOL_Q_ADDJOB *q_u, SPOOL_R_ADDJOB *r_u ****************************************************************************/ static void fill_job_info_1(JOB_INFO_1 *job_info, print_queue_struct *queue, - int position, int snum) + int position, int snum, + NT_PRINTER_INFO_LEVEL *ntprinter) { - pstring temp_name; - struct tm *t; t=gmtime(&queue->time); - slprintf(temp_name, sizeof(temp_name)-1, "\\\\%s", get_called_name()); job_info->jobid=queue->job; init_unistr(&job_info->printername, lp_servicename(snum)); - init_unistr(&job_info->machinename, temp_name); + init_unistr(&job_info->machinename, ntprinter->info_2->servername); init_unistr(&job_info->username, queue->fs_user); init_unistr(&job_info->document, queue->fs_file); init_unistr(&job_info->datatype, "RAW"); @@ -6355,17 +6387,15 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *ntprinter, DEVICEMODE *devmode) { - pstring temp_name; struct tm *t; t=gmtime(&queue->time); - slprintf(temp_name, sizeof(temp_name)-1, "\\\\%s", get_called_name()); job_info->jobid=queue->job; init_unistr(&job_info->printername, ntprinter->info_2->printername); - init_unistr(&job_info->machinename, temp_name); + init_unistr(&job_info->machinename, ntprinter->info_2->servername); init_unistr(&job_info->username, queue->fs_user); init_unistr(&job_info->document, queue->fs_file); init_unistr(&job_info->notifyname, queue->fs_user); @@ -6398,6 +6428,7 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, ****************************************************************************/ static WERROR enumjobs_level1(print_queue_struct *queue, int snum, + NT_PRINTER_INFO_LEVEL *ntprinter, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { @@ -6412,7 +6443,7 @@ static WERROR enumjobs_level1(print_queue_struct *queue, int snum, } for (i=0; i<*returned; i++) - fill_job_info_1(&info[i], &queue[i], i, snum); + fill_job_info_1( &info[i], &queue[i], i, snum, ntprinter ); SAFE_FREE(queue); @@ -6445,10 +6476,10 @@ static WERROR enumjobs_level1(print_queue_struct *queue, int snum, ****************************************************************************/ static WERROR enumjobs_level2(print_queue_struct *queue, int snum, + NT_PRINTER_INFO_LEVEL *ntprinter, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { - NT_PRINTER_INFO_LEVEL *ntprinter = NULL; JOB_INFO_2 *info = NULL; int i; WERROR result; @@ -6460,12 +6491,6 @@ static WERROR enumjobs_level2(print_queue_struct *queue, int snum, result = WERR_NOMEM; goto done; } - - result = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum)); - if (!W_ERROR_IS_OK(result)) { - *returned = 0; - goto done; - } /* this should not be a failure condition if the devmode is NULL */ @@ -6523,7 +6548,7 @@ WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO uint32 *needed = &r_u->needed; uint32 *returned = &r_u->returned; WERROR wret; - + NT_PRINTER_INFO_LEVEL *ntprinter = NULL; int snum; print_status_struct prt_status; print_queue_struct *queue=NULL; @@ -6537,9 +6562,15 @@ WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO *needed=0; *returned=0; + /* lookup the printer snum and tdb entry */ + if (!get_printer_snum(p, handle, &snum)) return WERR_BADFID; + wret = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum)); + if ( !W_ERROR_IS_OK(wret) ) + return wret; + *returned = print_queue_status(snum, &queue, &prt_status); DEBUGADD(4,("count:[%d], status:[%d], [%s]\n", *returned, prt_status.status, prt_status.message)); @@ -6550,16 +6581,19 @@ WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO switch (level) { case 1: - wret = enumjobs_level1(queue, snum, buffer, offered, needed, returned); + wret = enumjobs_level1(queue, snum, ntprinter, buffer, offered, needed, returned); return wret; case 2: - wret = enumjobs_level2(queue, snum, buffer, offered, needed, returned); + wret = enumjobs_level2(queue, snum, ntprinter, buffer, offered, needed, returned); return wret; default: SAFE_FREE(queue); *returned=0; - return WERR_UNKNOWN_LEVEL; + wret = WERR_UNKNOWN_LEVEL; } + + free_a_printer( &ntprinter, 2 ); + return wret; } /**************************************************************************** @@ -6866,7 +6900,6 @@ static WERROR enumprinterdrivers_level3(fstring servername, fstring architecture WERROR _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS *q_u, SPOOL_R_ENUMPRINTERDRIVERS *r_u) { - UNISTR2 *environment = &q_u->environment; uint32 level = q_u->level; NEW_BUFFER *buffer = NULL; uint32 offered = q_u->offered; @@ -6882,11 +6915,14 @@ WERROR _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS buffer = r_u->buffer; DEBUG(4,("_spoolss_enumprinterdrivers\n")); - fstrcpy(servername, get_called_name()); *needed=0; *returned=0; - unistr2_to_ascii(architecture, environment, sizeof(architecture)-1); + unistr2_to_ascii(architecture, &q_u->environment, sizeof(architecture)-1); + unistr2_to_ascii(servername, &q_u->name, sizeof(servername)-1); + + if ( !is_myname_or_ipaddr( servername ) ) + return WERR_UNKNOWN_PRINTER_DRIVER; switch (level) { case 1: @@ -7387,7 +7423,10 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ } } - slprintf(name, sizeof(name)-1, "\\\\%s\\%s", get_called_name(), + /* use our primary netbios name since get_a_printer() will convert + it to what the client expects on a case by case basis */ + + slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname(), printer->info_2->sharename); @@ -7659,10 +7698,15 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen { pstring path; pstring long_archi; + fstring servername; const char *short_archi; DRIVER_DIRECTORY_1 *info=NULL; + unistr2_to_ascii(servername, name, sizeof(servername)-1); unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)-1); + + if ( !is_myname_or_ipaddr( servername ) ) + return WERR_INVALID_PARAM; if (!(short_archi = get_short_archi(long_archi))) return WERR_INVALID_ENVIRONMENT; @@ -7670,7 +7714,7 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen if((info=(DRIVER_DIRECTORY_1 *)malloc(sizeof(DRIVER_DIRECTORY_1))) == NULL) return WERR_NOMEM; - slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", get_called_name(), short_archi); + slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", servername, short_archi); DEBUG(4,("printer driver directory: [%s]\n", path)); @@ -8496,7 +8540,10 @@ WERROR _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS *q_ /**************************************************************************** ****************************************************************************/ -static WERROR getjob_level_1(print_queue_struct **queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getjob_level_1(print_queue_struct **queue, int count, int snum, + NT_PRINTER_INFO_LEVEL *ntprinter, + uint32 jobid, NEW_BUFFER *buffer, uint32 offered, + uint32 *needed) { int i=0; BOOL found=False; @@ -8519,7 +8566,7 @@ static WERROR getjob_level_1(print_queue_struct **queue, int count, int snum, ui return WERR_INVALID_PARAM; } - fill_job_info_1(info_1, &((*queue)[i-1]), i, snum); + fill_job_info_1( info_1, &((*queue)[i-1]), i, snum, ntprinter ); *needed += spoolss_size_job_info_1(info_1); @@ -8541,12 +8588,14 @@ static WERROR getjob_level_1(print_queue_struct **queue, int count, int snum, ui /**************************************************************************** ****************************************************************************/ -static WERROR getjob_level_2(print_queue_struct **queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getjob_level_2(print_queue_struct **queue, int count, int snum, + NT_PRINTER_INFO_LEVEL *ntprinter, + uint32 jobid, NEW_BUFFER *buffer, uint32 offered, + uint32 *needed) { int i = 0; BOOL found = False; JOB_INFO_2 *info_2; - NT_PRINTER_INFO_LEVEL *ntprinter = NULL; WERROR ret; DEVICEMODE *devmode = NULL; NT_DEVICEMODE *nt_devmode = NULL; @@ -8574,10 +8623,6 @@ static WERROR getjob_level_2(print_queue_struct **queue, int count, int snum, ui goto done; } - ret = get_a_printer(NULL, &ntprinter, 2, lp_const_servicename(snum)); - if (!W_ERROR_IS_OK(ret)) - goto done; - /* * if the print job does not have a DEVMODE associated with it, * just use the one for the printer. A NULL devicemode is not @@ -8633,7 +8678,7 @@ WERROR _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_ uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; WERROR wstatus = WERR_OK; - + NT_PRINTER_INFO_LEVEL *ntprinter = NULL; int snum; int count; print_queue_struct *queue = NULL; @@ -8650,6 +8695,10 @@ WERROR _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_ if (!get_printer_snum(p, handle, &snum)) return WERR_BADFID; + wstatus = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum)); + if ( !W_ERROR_IS_OK(wstatus) ) + return wstatus; + count = print_queue_status(snum, &queue, &prt_status); DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n", @@ -8657,11 +8706,11 @@ WERROR _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_ switch ( level ) { case 1: - wstatus = getjob_level_1(&queue, count, snum, jobid, + wstatus = getjob_level_1(&queue, count, snum, ntprinter, jobid, buffer, offered, needed); break; case 2: - wstatus = getjob_level_2(&queue, count, snum, jobid, + wstatus = getjob_level_2(&queue, count, snum, ntprinter, jobid, buffer, offered, needed); break; default: @@ -8670,6 +8719,8 @@ WERROR _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_ } SAFE_FREE(queue); + free_a_printer( &ntprinter, 2 ); + return wstatus; } -- cgit From 2d016a67b87b5fee71fbdd33ea6b6fa78b0c8828 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 4 Oct 2004 22:13:57 +0000 Subject: r2821: Adding "Windows x64" as architecture string and driverdir "x64" for the 64bit AMD platform. (This used to be "Windows AMD64" and "AMD64" in one of the release candidates of SP2 for Windows XP. AMD64 is obviously still supported but not documented.) Guenther (This used to be commit cc5892f0411b8eb5daebe746164a2cf21d3d4c68) --- source3/rpc_server/srv_spoolss_nt.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 5c8a6235b6..fb498e73ad 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1995,6 +1995,7 @@ static int get_version_id (char * arch) {"Windows NT Alpha_AXP", "W32ALPHA", 2 }, {"Windows NT PowerPC", "W32PPC", 2 }, {"Windows IA64", "IA64", 3 }, + {"Windows x64", "x64", 3 }, {NULL, "", -1 } }; -- cgit From a169b950c778f066b189de770d0690dcc2fdbe91 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 11 Oct 2004 20:01:01 +0000 Subject: r2918: BUG 1907: fix getprinterdriverdir_1(). have to make sure we don't add unnecessary double slashes to the servername (This used to be commit 859599dbcaa9e39a7902cc959955fcea2dad334b) --- source3/rpc_server/srv_spoolss_nt.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index fb498e73ad..a1db4c3854 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -7700,13 +7700,22 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen pstring path; pstring long_archi; fstring servername; + char *pservername; const char *short_archi; DRIVER_DIRECTORY_1 *info=NULL; unistr2_to_ascii(servername, name, sizeof(servername)-1); unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)-1); + + /* check for beginning double '\'s and that the server + long enough */ + + pservername = servername; + if ( *pservername == '\\' && strlen(servername)>2 ) { + pservername += 2; + } - if ( !is_myname_or_ipaddr( servername ) ) + if ( !is_myname_or_ipaddr( pservername ) ) return WERR_INVALID_PARAM; if (!(short_archi = get_short_archi(long_archi))) @@ -7715,7 +7724,7 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen if((info=(DRIVER_DIRECTORY_1 *)malloc(sizeof(DRIVER_DIRECTORY_1))) == NULL) return WERR_NOMEM; - slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", servername, short_archi); + slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", pservername, short_archi); DEBUG(4,("printer driver directory: [%s]\n", path)); -- cgit From 7df1ed060be1fe730f78eb4665cdb5f1a3fef0c9 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 13 Oct 2004 19:40:22 +0000 Subject: r2955: fixing a segfault uncovered by the changes for BUG 1519 (This used to be commit 1664395257eb2425246e200ebde4384aa54484a4) --- source3/rpc_server/srv_spoolss_nt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a1db4c3854..c882cea59b 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3506,6 +3506,7 @@ static const struct s_notify_info_data_table notify_info_data_table[] = { JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_PAGES, "JOB_NOTIFY_TOTAL_PAGES", NOTIFY_ONE_VALUE, spoolss_notify_total_pages }, { JOB_NOTIFY_TYPE, JOB_NOTIFY_PAGES_PRINTED, "JOB_NOTIFY_PAGES_PRINTED", NOTIFY_ONE_VALUE, spoolss_notify_pages_printed }, { JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_BYTES, "JOB_NOTIFY_TOTAL_BYTES", NOTIFY_ONE_VALUE, spoolss_notify_job_size }, +{ PRINT_TABLE_END, 0x0, NULL, 0x0, NULL }, }; /******************************************************************* @@ -3571,7 +3572,7 @@ static int search_notify(uint16 type, uint16 field, int *value) { int i; - for (i = 0; i < sizeof(notify_info_data_table); i++) { + for (i = 0; notify_info_data_table[i].type != PRINT_TABLE_END; i++) { if (notify_info_data_table[i].type == type && notify_info_data_table[i].field == field && notify_info_data_table[i].fn != NULL) { -- cgit From c53e6401eb3de7fa4abc85c25f8672b624cf2c66 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 18 Oct 2004 19:57:03 +0000 Subject: r3049: fixing some calls in the printing code to stanard_sub_basic(); fix standard_sub_snum() to use the current user's gid; add some (snum == -1) checks to standard_sub_advanced() (This used to be commit 8c3fd1908d201e9891878ff4c3259ed9690dff97) --- source3/rpc_server/srv_spoolss_nt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index c882cea59b..2bdcfeff4d 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2766,7 +2766,7 @@ void spoolss_notify_server_name(int snum, uint32 len; fstrcpy( temp_name, "\\\\%L" ); - standard_sub_basic( NULL, temp_name, sizeof(temp_name)-1 ); + standard_sub_basic( "", temp_name, sizeof(temp_name)-1 ); len = rpcstr_push(temp, temp_name, sizeof(temp)-2, STR_TERMINATE); @@ -6623,7 +6623,7 @@ WERROR _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u return WERR_BADFID; } - if (!print_job_exists(snum, jobid)) { + if (!print_job_exists(lp_const_servicename(snum), jobid)) { return WERR_INVALID_PRINTER_NAME; } @@ -8640,7 +8640,7 @@ static WERROR getjob_level_2(print_queue_struct **queue, int count, int snum, * a failure condition */ - if ( !(nt_devmode=print_job_devmode( snum, jobid )) ) + if ( !(nt_devmode=print_job_devmode( lp_const_servicename(snum), jobid )) ) devmode = construct_dev_mode(snum); else { if ((devmode = (DEVICEMODE *)malloc(sizeof(DEVICEMODE))) != NULL) { -- cgit From 0af8284de1ce411289ec71d5b840a6171b66dc3b Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 19 Oct 2004 14:45:48 +0000 Subject: r3065: BUG 1519 (more): apparently the server_name notify request is used to fill in the title bar of the port monitor window and unless we get it right, you cannot open the printer properties from the port monitor window (This used to be commit fc691572c9ba5ae85c63db5202b7777efdbf7260) --- source3/rpc_server/srv_spoolss_nt.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 2bdcfeff4d..d096ed4021 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2750,8 +2750,6 @@ WERROR _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE return WERR_OK; } -#if 0 /* JERRY -- disabled; not used for now */ - /******************************************************************* * fill a notify_info_data with the servername ********************************************************************/ @@ -2762,14 +2760,10 @@ void spoolss_notify_server_name(int snum, NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) { - pstring temp_name, temp; + pstring temp; uint32 len; - fstrcpy( temp_name, "\\\\%L" ); - standard_sub_basic( "", temp_name, sizeof(temp_name)-1 ); - - - len = rpcstr_push(temp, temp_name, sizeof(temp)-2, STR_TERMINATE); + len = rpcstr_push(temp, printer->info_2->servername, sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); @@ -2782,9 +2776,6 @@ void spoolss_notify_server_name(int snum, memcpy(data->notify_data.data.string, temp, len); } -#endif - - /******************************************************************* * fill a notify_info_data with the printername (not including the servername). ********************************************************************/ @@ -3457,7 +3448,7 @@ struct s_notify_info_data_table static const struct s_notify_info_data_table notify_info_data_table[] = { -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SERVER_NAME, "PRINTER_NOTIFY_SERVER_NAME", NOTIFY_STRING, NULL}, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SERVER_NAME, "PRINTER_NOTIFY_SERVER_NAME", NOTIFY_STRING, spoolss_notify_server_name }, { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINTER_NAME, "PRINTER_NOTIFY_PRINTER_NAME", NOTIFY_STRING, spoolss_notify_printer_name }, { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SHARE_NAME, "PRINTER_NOTIFY_SHARE_NAME", NOTIFY_STRING, spoolss_notify_share_name }, { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PORT_NAME, "PRINTER_NOTIFY_PORT_NAME", NOTIFY_STRING, spoolss_notify_port_name }, @@ -3484,7 +3475,7 @@ static const struct s_notify_info_data_table notify_info_data_table[] = { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_BYTES, "PRINTER_NOTIFY_TOTAL_BYTES", NOTIFY_POINTER, NULL }, { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_BYTES_PRINTED, "PRINTER_NOTIFY_BYTES_PRINTED", NOTIFY_POINTER, NULL }, { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINTER_NAME, "JOB_NOTIFY_PRINTER_NAME", NOTIFY_STRING, spoolss_notify_printer_name }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_MACHINE_NAME, "JOB_NOTIFY_MACHINE_NAME", NOTIFY_STRING, NULL}, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_MACHINE_NAME, "JOB_NOTIFY_MACHINE_NAME", NOTIFY_STRING, spoolss_notify_server_name }, { JOB_NOTIFY_TYPE, JOB_NOTIFY_PORT_NAME, "JOB_NOTIFY_PORT_NAME", NOTIFY_STRING, spoolss_notify_port_name }, { JOB_NOTIFY_TYPE, JOB_NOTIFY_USER_NAME, "JOB_NOTIFY_USER_NAME", NOTIFY_STRING, spoolss_notify_username }, { JOB_NOTIFY_TYPE, JOB_NOTIFY_NOTIFY_NAME, "JOB_NOTIFY_NOTIFY_NAME", NOTIFY_STRING, spoolss_notify_username }, -- cgit From f2aca08c653a61dc4d6e99263dda7b649ef648b0 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 19 Oct 2004 16:17:23 +0000 Subject: r3066: BUG 1519: fix segfault caused by double free of a printer (This used to be commit 3760464193c540e82f0ba4e61d1d3b96a9803aca) --- source3/rpc_server/srv_spoolss_nt.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index d096ed4021..2d230b07bb 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -8663,7 +8663,6 @@ static WERROR getjob_level_2(print_queue_struct **queue, int count, int snum, free_job_info_2(info_2); /* Also frees devmode */ SAFE_FREE(info_2); - free_a_printer(&ntprinter, 2); return ret; } -- cgit From 4e18fa46d54b65a2145da769cb5e26b63eee1b1d Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 19 Oct 2004 22:13:08 +0000 Subject: r3069: add 'force printername' service parameter for people that want to enforce printername == sharename for spoolss printing (This used to be commit d47b8a0b4f348171df35b3b0028ce7d99fab8af3) --- source3/rpc_server/srv_spoolss_nt.c | 44 +++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 14 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 2d230b07bb..fad5555cea 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -529,12 +529,20 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) } } + /* do another loop to look for printernames */ for (snum=0; !found && snumservername, sizeof(info->servername)-1, "\\\\%s", global_myname()); fstrcpy(info->sharename, lp_servicename(snum)); - /* make sure printername is in \\server\printername format */ + /* check to see if we allow printername != sharename */ + + if ( lp_force_printername(snum) ) { + slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s", + global_myname(), info->sharename ); + } else { + + /* make sure printername is in \\server\printername format */ - fstrcpy( printername, info->printername ); - p = printername; - if ( printername[0] == '\\' && printername[1] == '\\' ) { - if ( (p = strchr_m( &printername[2], '\\' )) != NULL ) - p++; + fstrcpy( printername, info->printername ); + p = printername; + if ( printername[0] == '\\' && printername[1] == '\\' ) { + if ( (p = strchr_m( &printername[2], '\\' )) != NULL ) + p++; + } + + slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s", + global_myname(), p ); } - - slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s", - global_myname(), p ); - + info->attributes |= PRINTER_ATTRIBUTE_SAMBA; info->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA; -- cgit From 3bd3be97dc8a581c0502410453091c195e322766 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 6 Dec 2004 19:25:25 +0000 Subject: r4083: consolidate printer searches to use find_service rather than for loops (This used to be commit 12440744ba36445186042c8c254785766cce5385) --- source3/rpc_server/srv_spoolss_nt.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index fad5555cea..aba7e6c22f 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -512,24 +512,14 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) /* Search all sharenames first as this is easier than pulling the printer_info_2 off of disk */ - - for (snum=0; !found && snum Date: Tue, 7 Dec 2004 18:25:53 +0000 Subject: r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation functions so we can funnel through some well known functions. Should help greatly with malloc checking. HEAD patch to follow. Jeremy. (This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a) --- source3/rpc_server/srv_spoolss_nt.c | 174 ++++++++++++++++++------------------ 1 file changed, 87 insertions(+), 87 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index aba7e6c22f..78b5fb61fa 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -238,7 +238,7 @@ static SPOOL_NOTIFY_OPTION *dup_spool_notify_option(SPOOL_NOTIFY_OPTION *sp) if (!sp) return NULL; - new_sp = (SPOOL_NOTIFY_OPTION *)malloc(sizeof(SPOOL_NOTIFY_OPTION)); + new_sp = SMB_MALLOC_P(SPOOL_NOTIFY_OPTION); if (!new_sp) return NULL; @@ -585,7 +585,7 @@ static BOOL open_printer_hnd(pipes_struct *p, POLICY_HND *hnd, char *name, uint3 DEBUG(10,("open_printer_hnd: name [%s]\n", name)); - if((new_printer=(Printer_entry *)malloc(sizeof(Printer_entry))) == NULL) + if((new_printer=SMB_MALLOC_P(Printer_entry)) == NULL) return False; ZERO_STRUCTP(new_printer); @@ -733,7 +733,7 @@ static void notify_string(struct spoolss_notify_msg *msg, init_unistr2(&unistr, msg->notify.data, UNI_STR_TERMINATE); data->notify_data.data.length = msg->len * 2; - data->notify_data.data.string = (uint16 *)talloc(mem_ctx, msg->len * 2); + data->notify_data.data.string = TALLOC_ARRAY(mem_ctx, uint16, msg->len); if (!data->notify_data.data.string) { data->notify_data.data.length = 0; @@ -770,7 +770,7 @@ static void notify_system_time(struct spoolss_notify_msg *msg, return; data->notify_data.data.length = prs_offset(&ps); - data->notify_data.data.string = talloc(mem_ctx, prs_offset(&ps)); + data->notify_data.data.string = TALLOC(mem_ctx, prs_offset(&ps)); prs_copy_all_data_out((char *)data->notify_data.data.string, &ps); @@ -928,7 +928,7 @@ static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MS if ( i == ctr->num_groups ) { ctr->num_groups++; - if ( !(groups = talloc_realloc( ctr->ctx, ctr->msg_groups, sizeof(SPOOLSS_NOTIFY_MSG_GROUP)*ctr->num_groups)) ) { + if ( !(groups = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) { DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n")); return 0; } @@ -946,7 +946,7 @@ static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MS msg_grp->num_msgs++; - if ( !(msg_list = talloc_realloc( ctr->ctx, msg_grp->msgs, sizeof(SPOOLSS_NOTIFY_MSG)*msg_grp->num_msgs )) ) { + if ( !(msg_list = TALLOC_REALLOC_ARRAY( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) { DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs)); return 0; } @@ -958,7 +958,7 @@ static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MS /* need to allocate own copy of data */ if ( msg->len != 0 ) - msg_grp->msgs[new_slot].notify.data = talloc_memdup( ctr->ctx, msg->notify.data, msg->len ); + msg_grp->msgs[new_slot].notify.data = TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len ); return ctr->num_groups; } @@ -1016,7 +1016,7 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) /* allocate the max entries possible */ - data = talloc( mem_ctx, msg_group->num_msgs*sizeof(SPOOL_NOTIFY_INFO_DATA) ); + data = TALLOC_ARRAY( mem_ctx, SPOOL_NOTIFY_INFO_DATA, msg_group->num_msgs); ZERO_STRUCTP(data); /* build the array of change notifications */ @@ -1436,7 +1436,7 @@ static DEVICEMODE* dup_devicemode(TALLOC_CTX *ctx, DEVICEMODE *devmode) /* bulk copy first */ - d = talloc_memdup(ctx, devmode, sizeof(DEVICEMODE)); + d = TALLOC_MEMDUP(ctx, devmode, sizeof(DEVICEMODE)); if (!d) return NULL; @@ -1444,7 +1444,7 @@ static DEVICEMODE* dup_devicemode(TALLOC_CTX *ctx, DEVICEMODE *devmode) len = unistrlen(devmode->devicename.buffer); if (len != -1) { - d->devicename.buffer = talloc(ctx, len*2); + d->devicename.buffer = TALLOC_ARRAY(ctx, uint16, len); if (unistrcpy(d->devicename.buffer, devmode->devicename.buffer) != len) return NULL; } @@ -1452,12 +1452,12 @@ static DEVICEMODE* dup_devicemode(TALLOC_CTX *ctx, DEVICEMODE *devmode) len = unistrlen(devmode->formname.buffer); if (len != -1) { - d->devicename.buffer = talloc(ctx, len*2); + d->devicename.buffer = TALLOC_ARRAY(ctx, uint16, len); if (unistrcpy(d->formname.buffer, devmode->formname.buffer) != len) return NULL; } - d->private = talloc_memdup(ctx, devmode->private, devmode->driverextra); + d->private = TALLOC_MEMDUP(ctx, devmode->private, devmode->driverextra); return d; } @@ -1894,7 +1894,7 @@ BOOL convert_devicemode(const char *printername, const DEVICEMODE *devmode, if ((devmode->driverextra != 0) && (devmode->private != NULL)) { SAFE_FREE(nt_devmode->private); nt_devmode->driverextra=devmode->driverextra; - if((nt_devmode->private=(uint8 *)malloc(nt_devmode->driverextra * sizeof(uint8))) == NULL) + if((nt_devmode->private=SMB_MALLOC_ARRAY(uint8, nt_devmode->driverextra)) == NULL) return False; memcpy(nt_devmode->private, devmode->private, nt_devmode->driverextra); } @@ -2235,11 +2235,11 @@ static WERROR get_printer_dataex( TALLOC_CTX *ctx, NT_PRINTER_INFO_LEVEL *printe /* special case for 0 length values */ if ( data_len ) { - if ( (*data = (uint8 *)talloc_memdup(ctx, regval_data_p(val), data_len)) == NULL ) + if ( (*data = (uint8 *)TALLOC_MEMDUP(ctx, regval_data_p(val), data_len)) == NULL ) return WERR_NOMEM; } else { - if ( (*data = (uint8 *)talloc_zero(ctx, in_size)) == NULL ) + if ( (*data = (uint8 *)TALLOC_ZERO(ctx, in_size)) == NULL ) return WERR_NOMEM; } } @@ -2286,7 +2286,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint if (!StrCaseCmp(value, "W3SvcInstalled")) { *type = 0x4; - if((*data = (uint8 *)talloc_zero(ctx, 4*sizeof(uint8) )) == NULL) + if((*data = (uint8 *)TALLOC_ZERO(ctx, 4*sizeof(uint8) )) == NULL) return WERR_NOMEM; *needed = 0x4; return WERR_OK; @@ -2294,7 +2294,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint if (!StrCaseCmp(value, "BeepEnabled")) { *type = 0x4; - if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) + if((*data = (uint8 *)TALLOC(ctx, 4*sizeof(uint8) )) == NULL) return WERR_NOMEM; SIVAL(*data, 0, 0x00); *needed = 0x4; @@ -2303,7 +2303,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint if (!StrCaseCmp(value, "EventLog")) { *type = 0x4; - if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) + if((*data = (uint8 *)TALLOC(ctx, 4 )) == NULL) return WERR_NOMEM; /* formally was 0x1b */ SIVAL(*data, 0, 0x0); @@ -2313,7 +2313,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint if (!StrCaseCmp(value, "NetPopup")) { *type = 0x4; - if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) + if((*data = (uint8 *)TALLOC(ctx, 4 )) == NULL) return WERR_NOMEM; SIVAL(*data, 0, 0x00); *needed = 0x4; @@ -2322,7 +2322,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint if (!StrCaseCmp(value, "MajorVersion")) { *type = 0x4; - if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) + if((*data = (uint8 *)TALLOC(ctx, 4 )) == NULL) return WERR_NOMEM; /* Windows NT 4.0 seems to not allow uploading of drivers @@ -2341,7 +2341,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint if (!StrCaseCmp(value, "MinorVersion")) { *type = 0x4; - if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL) + if((*data = (uint8 *)TALLOC(ctx, 4 )) == NULL) return WERR_NOMEM; SIVAL(*data, 0, 0); *needed = 0x4; @@ -2359,7 +2359,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint *type = 0x3; *needed = 0x114; - if((*data = (uint8 *)talloc(ctx, (*needed)*sizeof(uint8) )) == NULL) + if((*data = (uint8 *)TALLOC(ctx, *needed)) == NULL) return WERR_NOMEM; ZERO_STRUCTP( *data ); @@ -2378,7 +2378,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint const char *string="C:\\PRINTERS"; *type = 0x1; *needed = 2*(strlen(string)+1); - if((*data = (uint8 *)talloc(ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL) + if((*data = (uint8 *)TALLOC(ctx, (*needed > in_size) ? *needed:in_size )) == NULL) return WERR_NOMEM; memset(*data, 0, (*needed > in_size) ? *needed:in_size); @@ -2394,7 +2394,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint const char *string="Windows NT x86"; *type = 0x1; *needed = 2*(strlen(string)+1); - if((*data = (uint8 *)talloc(ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL) + if((*data = (uint8 *)TALLOC(ctx, (*needed > in_size) ? *needed:in_size )) == NULL) return WERR_NOMEM; memset(*data, 0, (*needed > in_size) ? *needed:in_size); for (i=0; i in_size) ? *needed:in_size) *sizeof(uint8))) == NULL) + if((*data = (uint8 *)TALLOC(ctx, (*needed > in_size) ? *needed:in_size )) == NULL) return WERR_NOMEM; memset(*data, 0, (*needed > in_size) ? *needed:in_size); for (i=0; imem_ctx, sizeof(uint32))) == NULL) { + if ( (*data = (uint8*)TALLOC(p->mem_ctx, sizeof(uint32))) == NULL) { status = WERR_NOMEM; goto done; } @@ -2517,7 +2517,7 @@ done: /* reply this param doesn't exist */ if ( *out_size ) { - if((*data=(uint8 *)talloc_zero(p->mem_ctx, *out_size*sizeof(uint8))) == NULL) { + if((*data=(uint8 *)TALLOC_ZERO_ARRAY(p->mem_ctx, uint8, *out_size)) == NULL) { if ( printer ) free_a_printer( &printer, 2 ); return WERR_NOMEM; @@ -2764,7 +2764,7 @@ void spoolss_notify_server_name(int snum, len = rpcstr_push(temp, printer->info_2->servername, sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); if (!data->notify_data.data.string) { data->notify_data.data.length = 0; @@ -2799,7 +2799,7 @@ void spoolss_notify_printer_name(int snum, len = rpcstr_push(temp, p, sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); if (!data->notify_data.data.string) { data->notify_data.data.length = 0; @@ -2825,7 +2825,7 @@ void spoolss_notify_share_name(int snum, len = rpcstr_push(temp, lp_servicename(snum), sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); if (!data->notify_data.data.string) { data->notify_data.data.length = 0; @@ -2853,7 +2853,7 @@ void spoolss_notify_port_name(int snum, len = rpcstr_push(temp, printer->info_2->portname, sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); if (!data->notify_data.data.string) { data->notify_data.data.length = 0; @@ -2880,7 +2880,7 @@ void spoolss_notify_driver_name(int snum, len = rpcstr_push(temp, printer->info_2->drivername, sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); if (!data->notify_data.data.string) { data->notify_data.data.length = 0; @@ -2909,7 +2909,7 @@ void spoolss_notify_comment(int snum, len = rpcstr_push(temp, printer->info_2->comment, sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); if (!data->notify_data.data.string) { data->notify_data.data.length = 0; @@ -2936,7 +2936,7 @@ void spoolss_notify_location(int snum, len = rpcstr_push(temp, printer->info_2->location,sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); if (!data->notify_data.data.string) { data->notify_data.data.length = 0; @@ -2975,7 +2975,7 @@ void spoolss_notify_sepfile(int snum, len = rpcstr_push(temp, printer->info_2->sepfile, sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); if (!data->notify_data.data.string) { data->notify_data.data.length = 0; @@ -3002,7 +3002,7 @@ void spoolss_notify_print_processor(int snum, len = rpcstr_push(temp, printer->info_2->printprocessor, sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); if (!data->notify_data.data.string) { data->notify_data.data.length = 0; @@ -3029,7 +3029,7 @@ void spoolss_notify_parameters(int snum, len = rpcstr_push(temp, printer->info_2->parameters, sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); if (!data->notify_data.data.string) { data->notify_data.data.length = 0; @@ -3056,7 +3056,7 @@ void spoolss_notify_datatype(int snum, len = rpcstr_push(temp, printer->info_2->datatype, sizeof(pstring)-2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); if (!data->notify_data.data.string) { data->notify_data.data.length = 0; @@ -3216,7 +3216,7 @@ static void spoolss_notify_username(int snum, len = rpcstr_push(temp, queue->fs_user, sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); if (!data->notify_data.data.string) { data->notify_data.data.length = 0; @@ -3256,7 +3256,7 @@ static void spoolss_notify_job_name(int snum, len = rpcstr_push(temp, queue->fs_file, sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); if (!data->notify_data.data.string) { data->notify_data.data.length = 0; @@ -3306,7 +3306,7 @@ static void spoolss_notify_job_status_string(int snum, len = rpcstr_push(temp, p, sizeof(temp) - 2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); if (!data->notify_data.data.string) { data->notify_data.data.length = 0; @@ -3404,7 +3404,7 @@ static void spoolss_notify_submitted_time(int snum, len = sizeof(SYSTEMTIME); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); if (!data->notify_data.data.string) { data->notify_data.data.length = 0; @@ -3626,7 +3626,7 @@ static BOOL construct_notify_printer_info(Printer_entry *print_hnd, SPOOL_NOTIFY if (!search_notify(type, field, &j) ) continue; - if((tid=(SPOOL_NOTIFY_INFO_DATA *)Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) { + if((tid=SMB_REALLOC_ARRAY(info->data, SPOOL_NOTIFY_INFO_DATA, info->count+1)) == NULL) { DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n")); return False; } else @@ -3682,7 +3682,7 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, if (!search_notify(type, field, &j) ) continue; - if((tid=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) { + if((tid=SMB_REALLOC_ARRAY(info->data, SPOOL_NOTIFY_INFO_DATA, info->count+1)) == NULL) { DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n")); return False; } @@ -3966,7 +3966,7 @@ static BOOL construct_printer_info_0(Printer_entry *print_hnd, PRINTER_INFO_0 *p /* it's the first time, add it to the list */ if (session_counter==NULL) { - if((session_counter=(counter_printer_0 *)malloc(sizeof(counter_printer_0))) == NULL) { + if((session_counter=SMB_MALLOC_P(counter_printer_0)) == NULL) { free_a_printer(&ntprinter, 2); return False; } @@ -4160,7 +4160,7 @@ DEVICEMODE *construct_dev_mode(int snum) goto done; } - if ((devmode = (DEVICEMODE *)malloc(sizeof(DEVICEMODE))) == NULL) { + if ((devmode = SMB_MALLOC_P(DEVICEMODE)) == NULL) { DEBUG(2,("construct_dev_mode: malloc fail.\n")); goto done; } @@ -4257,7 +4257,7 @@ static BOOL construct_printer_info_3(Printer_entry *print_hnd, PRINTER_INFO_3 ** return False; *pp_printer = NULL; - if ((printer = (PRINTER_INFO_3 *)malloc(sizeof(PRINTER_INFO_3))) == NULL) { + if ((printer = SMB_MALLOC_P(PRINTER_INFO_3)) == NULL) { DEBUG(2,("construct_printer_info_3: malloc fail.\n")); return False; } @@ -4386,7 +4386,7 @@ static WERROR enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum)); if (construct_printer_info_1(NULL, flags, ¤t_prt, snum)) { - if((tp=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_1))) == NULL) { + if((tp=SMB_REALLOC_ARRAY(printers, PRINTER_INFO_1, *returned +1)) == NULL) { DEBUG(2,("enum_all_printers_info_1: failed to enlarge printers buffer!\n")); SAFE_FREE(printers); *returned=0; @@ -4475,7 +4475,7 @@ static WERROR enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, * undocumented RPC call. */ - if((printer=(PRINTER_INFO_1 *)malloc(sizeof(PRINTER_INFO_1))) == NULL) + if((printer=SMB_MALLOC_P(PRINTER_INFO_1)) == NULL) return WERR_NOMEM; *returned=1; @@ -4559,7 +4559,7 @@ static WERROR enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint3 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum)); if (construct_printer_info_2(NULL, ¤t_prt, snum)) { - if((tp=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_2))) == NULL) { + if((tp=SMB_REALLOC_ARRAY(printers, PRINTER_INFO_2, *returned +1)) == NULL) { DEBUG(2,("enum_all_printers_info_2: failed to enlarge printers buffer!\n")); SAFE_FREE(printers); *returned = 0; @@ -4735,7 +4735,7 @@ static WERROR getprinter_level_0(Printer_entry *print_hnd, int snum, NEW_BUFFER { PRINTER_INFO_0 *printer=NULL; - if((printer=(PRINTER_INFO_0*)malloc(sizeof(PRINTER_INFO_0))) == NULL) + if((printer=SMB_MALLOC_P(PRINTER_INFO_0)) == NULL) return WERR_NOMEM; construct_printer_info_0(print_hnd, printer, snum); @@ -4768,7 +4768,7 @@ static WERROR getprinter_level_1(Printer_entry *print_hnd, int snum, NEW_BUFFER { PRINTER_INFO_1 *printer=NULL; - if((printer=(PRINTER_INFO_1*)malloc(sizeof(PRINTER_INFO_1))) == NULL) + if((printer=SMB_MALLOC_P(PRINTER_INFO_1)) == NULL) return WERR_NOMEM; construct_printer_info_1(print_hnd, PRINTER_ENUM_ICON8, printer, snum); @@ -4801,7 +4801,7 @@ static WERROR getprinter_level_2(Printer_entry *print_hnd, int snum, NEW_BUFFER { PRINTER_INFO_2 *printer=NULL; - if((printer=(PRINTER_INFO_2*)malloc(sizeof(PRINTER_INFO_2)))==NULL) + if((printer=SMB_MALLOC_P(PRINTER_INFO_2))==NULL) return WERR_NOMEM; construct_printer_info_2(print_hnd, printer, snum); @@ -4868,7 +4868,7 @@ static WERROR getprinter_level_4(Printer_entry *print_hnd, int snum, NEW_BUFFER { PRINTER_INFO_4 *printer=NULL; - if((printer=(PRINTER_INFO_4*)malloc(sizeof(PRINTER_INFO_4)))==NULL) + if((printer=SMB_MALLOC_P(PRINTER_INFO_4))==NULL) return WERR_NOMEM; if (!construct_printer_info_4(print_hnd, printer, snum)) @@ -4902,7 +4902,7 @@ static WERROR getprinter_level_5(Printer_entry *print_hnd, int snum, NEW_BUFFER { PRINTER_INFO_5 *printer=NULL; - if((printer=(PRINTER_INFO_5*)malloc(sizeof(PRINTER_INFO_5)))==NULL) + if((printer=SMB_MALLOC_P(PRINTER_INFO_5))==NULL) return WERR_NOMEM; if (!construct_printer_info_5(print_hnd, printer, snum)) @@ -4933,7 +4933,7 @@ static WERROR getprinter_level_7(Printer_entry *print_hnd, int snum, NEW_BUFFER { PRINTER_INFO_7 *printer=NULL; - if((printer=(PRINTER_INFO_7*)malloc(sizeof(PRINTER_INFO_7)))==NULL) + if((printer=SMB_MALLOC_P(PRINTER_INFO_7))==NULL) return WERR_NOMEM; if (!construct_printer_info_7(print_hnd, printer, snum)) @@ -5135,7 +5135,7 @@ static uint32 init_unistr_array(uint16 **uni_array, fstring *char_array, const c /* add one extra unit16 for the second terminating NULL */ - if ( (tuary=Realloc(*uni_array, (j+1+strlen(line)+2)*sizeof(uint16))) == NULL ) { + if ( (tuary=SMB_REALLOC_ARRAY(*uni_array, uint16, j+1+strlen(line)+2)) == NULL ) { DEBUG(2,("init_unistr_array: Realloc error\n" )); return 0; } else @@ -5411,7 +5411,7 @@ static WERROR getprinterdriver2_level1(fstring servername, fstring architecture, DRIVER_INFO_1 *info=NULL; WERROR status; - if((info=(DRIVER_INFO_1 *)malloc(sizeof(DRIVER_INFO_1))) == NULL) + if((info=SMB_MALLOC_P(DRIVER_INFO_1)) == NULL) return WERR_NOMEM; status=construct_printer_driver_info_1(info, snum, servername, architecture, version); @@ -5448,7 +5448,7 @@ static WERROR getprinterdriver2_level2(fstring servername, fstring architecture, DRIVER_INFO_2 *info=NULL; WERROR status; - if((info=(DRIVER_INFO_2 *)malloc(sizeof(DRIVER_INFO_2))) == NULL) + if((info=SMB_MALLOC_P(DRIVER_INFO_2)) == NULL) return WERR_NOMEM; status=construct_printer_driver_info_2(info, snum, servername, architecture, version); @@ -6434,7 +6434,7 @@ static WERROR enumjobs_level1(print_queue_struct *queue, int snum, JOB_INFO_1 *info; int i; - info=(JOB_INFO_1 *)malloc(*returned*sizeof(JOB_INFO_1)); + info=SMB_MALLOC_ARRAY(JOB_INFO_1,*returned); if (info==NULL) { SAFE_FREE(queue); *returned=0; @@ -6484,7 +6484,7 @@ static WERROR enumjobs_level2(print_queue_struct *queue, int snum, WERROR result; DEVICEMODE *devmode = NULL; - info=(JOB_INFO_2 *)malloc(*returned*sizeof(JOB_INFO_2)); + info=SMB_MALLOC_ARRAY(JOB_INFO_2,*returned); if (info==NULL) { *returned=0; result = WERR_NOMEM; @@ -6676,7 +6676,7 @@ static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture return WERR_NOMEM; if(ndrivers != 0) { - if((tdi1=(DRIVER_INFO_1 *)Realloc(driver_info_1, (*returned+ndrivers) * sizeof(DRIVER_INFO_1))) == NULL) { + if((tdi1=SMB_REALLOC_ARRAY(driver_info_1, DRIVER_INFO_1, *returned+ndrivers )) == NULL) { DEBUG(0,("enumprinterdrivers_level1: failed to enlarge driver info buffer!\n")); SAFE_FREE(driver_info_1); SAFE_FREE(list); @@ -6755,7 +6755,7 @@ static WERROR enumprinterdrivers_level2(fstring servername, fstring architecture return WERR_NOMEM; if(ndrivers != 0) { - if((tdi2=(DRIVER_INFO_2 *)Realloc(driver_info_2, (*returned+ndrivers) * sizeof(DRIVER_INFO_2))) == NULL) { + if((tdi2=SMB_REALLOC_ARRAY(driver_info_2, DRIVER_INFO_2, *returned+ndrivers )) == NULL) { DEBUG(0,("enumprinterdrivers_level2: failed to enlarge driver info buffer!\n")); SAFE_FREE(driver_info_2); SAFE_FREE(list); @@ -6835,7 +6835,7 @@ static WERROR enumprinterdrivers_level3(fstring servername, fstring architecture return WERR_NOMEM; if(ndrivers != 0) { - if((tdi3=(DRIVER_INFO_3 *)Realloc(driver_info_3, (*returned+ndrivers) * sizeof(DRIVER_INFO_3))) == NULL) { + if((tdi3=SMB_REALLOC_ARRAY(driver_info_3, DRIVER_INFO_3, *returned+ndrivers )) == NULL) { DEBUG(0,("enumprinterdrivers_level3: failed to enlarge driver info buffer!\n")); SAFE_FREE(driver_info_3); SAFE_FREE(list); @@ -6988,7 +6988,7 @@ WERROR _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMF switch (level) { case 1: - if ((forms_1=(FORM_1 *)malloc(*numofforms * sizeof(FORM_1))) == NULL) { + if ((forms_1=SMB_MALLOC_ARRAY(FORM_1, *numofforms)) == NULL) { *numofforms=0; return WERR_NOMEM; } @@ -7192,7 +7192,7 @@ static WERROR enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need close(fd); if(numlines) { - if((ports=(PORT_INFO_1 *)malloc( numlines * sizeof(PORT_INFO_1) )) == NULL) { + if((ports=SMB_MALLOC_ARRAY( PORT_INFO_1, numlines )) == NULL) { DEBUG(10,("Returning WERR_NOMEM [%s]\n", dos_errstr(WERR_NOMEM))); file_lines_free(qlines); @@ -7212,7 +7212,7 @@ static WERROR enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need } else { *returned = 1; /* Sole Samba port returned. */ - if((ports=(PORT_INFO_1 *)malloc( sizeof(PORT_INFO_1) )) == NULL) + if((ports=SMB_MALLOC_P(PORT_INFO_1)) == NULL) return WERR_NOMEM; DEBUG(10,("enumports_level_1: port name %s\n", SAMBA_PRINTER_PORT_NAME)); @@ -7291,7 +7291,7 @@ static WERROR enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need close(fd); if(numlines) { - if((ports=(PORT_INFO_2 *)malloc( numlines * sizeof(PORT_INFO_2) )) == NULL) { + if((ports=SMB_MALLOC_ARRAY( PORT_INFO_2, numlines)) == NULL) { file_lines_free(qlines); return WERR_NOMEM; } @@ -7310,7 +7310,7 @@ static WERROR enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need *returned = 1; - if((ports=(PORT_INFO_2 *)malloc( sizeof(PORT_INFO_2) )) == NULL) + if((ports=SMB_MALLOC_P(PORT_INFO_2)) == NULL) return WERR_NOMEM; DEBUG(10,("enumports_level_2: port name %s\n", SAMBA_PRINTER_PORT_NAME)); @@ -7390,7 +7390,7 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ int snum; WERROR err = WERR_OK; - if ((printer = (NT_PRINTER_INFO_LEVEL *)malloc(sizeof(NT_PRINTER_INFO_LEVEL))) == NULL) { + if ((printer = SMB_MALLOC_P(NT_PRINTER_INFO_LEVEL)) == NULL) { DEBUG(0,("spoolss_addprinterex_level_2: malloc fail.\n")); return WERR_NOMEM; } @@ -7719,7 +7719,7 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen if (!(short_archi = get_short_archi(long_archi))) return WERR_INVALID_ENVIRONMENT; - if((info=(DRIVER_DIRECTORY_1 *)malloc(sizeof(DRIVER_DIRECTORY_1))) == NULL) + if((info=SMB_MALLOC_P(DRIVER_DIRECTORY_1)) == NULL) return WERR_NOMEM; slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", pservername, short_archi); @@ -7887,7 +7887,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S *out_max_value_len=(in_value_len/sizeof(uint16)); - if((*out_value=(uint16 *)talloc_zero(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL) + if((*out_value=(uint16 *)TALLOC_ZERO(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL) { result = WERR_NOMEM; goto done; @@ -7902,7 +7902,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S /* only allocate when given a non-zero data_len */ - if ( in_data_len && ((*data_out=(uint8 *)talloc_zero(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) ) + if ( in_data_len && ((*data_out=(uint8 *)TALLOC_ZERO(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) ) { result = WERR_NOMEM; goto done; @@ -7923,7 +7923,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S /* name */ *out_max_value_len=(in_value_len/sizeof(uint16)); - if ( (*out_value = (uint16 *)talloc_zero(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL ) + if ( (*out_value = (uint16 *)TALLOC_ZERO(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL ) { result = WERR_NOMEM; goto done; @@ -7938,7 +7938,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S /* data - counted in bytes */ *out_max_data_len = in_data_len; - if ( (*data_out = (uint8 *)talloc_zero(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) + if ( (*data_out = (uint8 *)TALLOC_ZERO(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) { result = WERR_NOMEM; goto done; @@ -8323,7 +8323,7 @@ static WERROR enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, ui { PRINTPROCESSOR_1 *info_1=NULL; - if((info_1 = (PRINTPROCESSOR_1 *)malloc(sizeof(PRINTPROCESSOR_1))) == NULL) + if((info_1 = SMB_MALLOC_P(PRINTPROCESSOR_1)) == NULL) return WERR_NOMEM; (*returned) = 0x1; @@ -8390,7 +8390,7 @@ static WERROR enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered, { PRINTPROCDATATYPE_1 *info_1=NULL; - if((info_1 = (PRINTPROCDATATYPE_1 *)malloc(sizeof(PRINTPROCDATATYPE_1))) == NULL) + if((info_1 = SMB_MALLOC_P(PRINTPROCDATATYPE_1)) == NULL) return WERR_NOMEM; (*returned) = 0x1; @@ -8450,7 +8450,7 @@ static WERROR enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, uint { PRINTMONITOR_1 *info_1=NULL; - if((info_1 = (PRINTMONITOR_1 *)malloc(sizeof(PRINTMONITOR_1))) == NULL) + if((info_1 = SMB_MALLOC_P(PRINTMONITOR_1)) == NULL) return WERR_NOMEM; (*returned) = 0x1; @@ -8482,7 +8482,7 @@ static WERROR enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint { PRINTMONITOR_2 *info_2=NULL; - if((info_2 = (PRINTMONITOR_2 *)malloc(sizeof(PRINTMONITOR_2))) == NULL) + if((info_2 = SMB_MALLOC_P(PRINTMONITOR_2)) == NULL) return WERR_NOMEM; (*returned) = 0x1; @@ -8557,7 +8557,7 @@ static WERROR getjob_level_1(print_queue_struct **queue, int count, int snum, BOOL found=False; JOB_INFO_1 *info_1=NULL; - info_1=(JOB_INFO_1 *)malloc(sizeof(JOB_INFO_1)); + info_1=SMB_MALLOC_P(JOB_INFO_1); if (info_1 == NULL) { return WERR_NOMEM; @@ -8608,7 +8608,7 @@ static WERROR getjob_level_2(print_queue_struct **queue, int count, int snum, DEVICEMODE *devmode = NULL; NT_DEVICEMODE *nt_devmode = NULL; - info_2=(JOB_INFO_2 *)malloc(sizeof(JOB_INFO_2)); + info_2=SMB_MALLOC_P(JOB_INFO_2); ZERO_STRUCTP(info_2); @@ -8640,7 +8640,7 @@ static WERROR getjob_level_2(print_queue_struct **queue, int count, int snum, if ( !(nt_devmode=print_job_devmode( lp_const_servicename(snum), jobid )) ) devmode = construct_dev_mode(snum); else { - if ((devmode = (DEVICEMODE *)malloc(sizeof(DEVICEMODE))) != NULL) { + if ((devmode = SMB_MALLOC_P(DEVICEMODE)) != NULL) { ZERO_STRUCTP( devmode ); convert_nt_devicemode( devmode, nt_devmode ); } @@ -8818,7 +8818,7 @@ done: if ( *out_size ) { - if( (*data=(uint8 *)talloc_zero(p->mem_ctx, *out_size*sizeof(uint8))) == NULL ) { + if( (*data=(uint8 *)TALLOC_ZERO(p->mem_ctx, *out_size*sizeof(uint8))) == NULL ) { status = WERR_NOMEM; goto done; } @@ -9177,7 +9177,7 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ num_entries = regval_ctr_numvals( &p_data->keys[key_index].values ); if ( num_entries ) { - if ( (enum_values=talloc(p->mem_ctx, num_entries*sizeof(PRINTER_ENUM_VALUES))) == NULL ) + if ( (enum_values=TALLOC_ARRAY(p->mem_ctx, PRINTER_ENUM_VALUES, num_entries)) == NULL ) { DEBUG(0,("_spoolss_enumprinterdataex: talloc() failed to allocate memory for [%lu] bytes!\n", (unsigned long)num_entries*sizeof(PRINTER_ENUM_VALUES))); @@ -9209,7 +9209,7 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ data_len = regval_size( val ); if ( data_len ) { - if ( !(enum_values[i].data = talloc_memdup(p->mem_ctx, regval_data_p(val), data_len)) ) + if ( !(enum_values[i].data = TALLOC_MEMDUP(p->mem_ctx, regval_data_p(val), data_len)) ) { DEBUG(0,("talloc_memdup failed to allocate memory [data_len=%d] for data!\n", data_len )); @@ -9272,7 +9272,7 @@ static WERROR getprintprocessordirectory_level_1(UNISTR2 *name, if (!get_short_archi(long_archi)) return WERR_INVALID_ENVIRONMENT; - if((info=(PRINTPROCESSOR_DIRECTORY_1 *)malloc(sizeof(PRINTPROCESSOR_DIRECTORY_1))) == NULL) + if((info=SMB_MALLOC_P(PRINTPROCESSOR_DIRECTORY_1)) == NULL) return WERR_NOMEM; pstrcpy(path, "C:\\WINNT\\System32\\spool\\PRTPROCS\\W32X86"); -- cgit From 3c45a093c435a106e08746aa3f3db824192340f1 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 10 Dec 2004 21:08:34 +0000 Subject: r4134: check the setprinter(3) based on the access permissions on the handle and avoid the call to print_access_chaeck() (This used to be commit 426634df9c221fbe4f48b4ff9d1b4b8426a581f7) --- source3/rpc_server/srv_spoolss_nt.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 78b5fb61fa..9aa46d1a5a 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -5860,6 +5860,17 @@ static WERROR update_printer_sec(POLICY_HND *handle, uint32 level, result = WERR_BADFID; goto done; } + + /* Check the user has permissions to change the security + descriptor. By experimentation with two NT machines, the user + requires Full Access to the printer to change security + information. */ + + if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) { + DEBUG(4,("update_printer_sec: updated denied by printer permissions\n")); + result = WERR_ACCESS_DENIED; + goto done; + } /* NT seems to like setting the security descriptor even though nothing may have actually changed. */ @@ -5909,20 +5920,6 @@ static WERROR update_printer_sec(POLICY_HND *handle, uint32 level, goto done; } - /* Work out which user is performing the operation */ - - get_current_user(&user, p); - - /* Check the user has permissions to change the security - descriptor. By experimentation with two NT machines, the user - requires Full Access to the printer to change security - information. */ - - if (!print_access_check(&user, snum, PRINTER_ACCESS_ADMINISTER)) { - result = WERR_ACCESS_DENIED; - goto done; - } - result = nt_printing_setsec(Printer->sharename, new_secdesc_ctr); done: -- cgit From 00eede9a6b7e258faa6abe4de0d39a16bbcebd14 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 14 Dec 2004 00:20:55 +0000 Subject: r4184: Removed unused extern. Jeremy. (This used to be commit 72e39041e9fbb7f252292182d56b1927a8133be0) --- source3/rpc_server/srv_spoolss_nt.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 9aa46d1a5a..a3424fe73b 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -5847,7 +5847,6 @@ static WERROR update_printer_sec(POLICY_HND *handle, uint32 level, pipes_struct *p, SEC_DESC_BUF *secdesc_ctr) { SEC_DESC_BUF *new_secdesc_ctr = NULL, *old_secdesc_ctr = NULL; - struct current_user user; WERROR result; int snum; -- cgit From 2c33c41b0c98ee36f5c9b6a368deb1192360fd5b Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 14 Jan 2005 21:24:15 +0000 Subject: r4740: allow SE_PRINT_OPERATORS to have printer admin access (This used to be commit 85731706c9d794e8bd3f26ce9b1f881c1ee6a3ba) --- source3/rpc_server/srv_spoolss_nt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a3424fe73b..ba3ee4706c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1689,10 +1689,12 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, return WERR_ACCESS_DENIED; } - /* if the user is not root and not a printer admin, then fail */ + /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege, + and not a printer admin, then fail */ if ( user.uid != 0 - && !user_in_list(uidtoname(user.uid), lp_printer_admin(snum), user.groups, user.ngroups) ) + && !user_has_privilege( user.nt_user_token, SE_PRINT_OPERATOR ) + && !user_in_list(uidtoname(user.uid), lp_printer_admin(snum), user.groups, user.ngroups) ) { close_printer_handle(p, handle); return WERR_ACCESS_DENIED; -- cgit From 46e5effea948931509283cb84b27007d34b521c8 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 17 Jan 2005 15:23:11 +0000 Subject: r4805: Last planned change to the privileges infrastructure: * rewrote the tdb layout of privilege records in account_pol.tdb (allow for 128 bits instead of 32 bit flags) * migrated to using SE_PRIV structure instead of the PRIVILEGE_SET structure. The latter is now used for parsing routines mainly. Still need to incorporate some client support into 'net' so for setting privileges. And make use of the SeAddUserPrivilege right. (This used to be commit 41dc7f7573c6d637e19a01e7ed0e716ac0f1fb15) --- source3/rpc_server/srv_spoolss_nt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index ba3ee4706c..12611c4ee5 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1684,6 +1684,8 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, if ( printer_default->access_required & SERVER_ACCESS_ADMINISTER ) { + SE_PRIV se_printop = SE_PRINT_OPERATOR; + if (!lp_ms_add_printer_wizard()) { close_printer_handle(p, handle); return WERR_ACCESS_DENIED; @@ -1693,7 +1695,7 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, and not a printer admin, then fail */ if ( user.uid != 0 - && !user_has_privilege( user.nt_user_token, SE_PRINT_OPERATOR ) + && !user_has_privileges( user.nt_user_token, &se_printop ) && !user_in_list(uidtoname(user.uid), lp_printer_admin(snum), user.groups, user.ngroups) ) { close_printer_handle(p, handle); -- cgit From 10861a6160fb1ead19e23ff58f3590813600fc7b Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 18 Jan 2005 19:51:36 +0000 Subject: r4825: Printing changes ---------------- * bracket the add/delete/set printer scripts with checks for se_print_op * slight change to the add/set printer script semantics. smbd no longer relies on output from the script (on stdout) to re-read smb.conf * remove SIGHUP from set/add/delete printin script code and now just use MSG_SMB_CONF_UPDATED * bracket the add/delete/set share scripts with checks for se_print_op (this includes setting share ACLs) (This used to be commit 8ab8113d2e1bec6a1dbf464882ad724c7c591be4) --- source3/rpc_server/srv_spoolss_nt.c | 74 ++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 17 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 12611c4ee5..31e1e4a3bf 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -379,29 +379,50 @@ static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) return WERR_ACCESS_DENIED; } #endif - + + /* this does not need a become root since the access check has been + done on the handle already */ + if (del_a_printer( Printer->sharename ) != 0) { DEBUG(3,("Error deleting printer %s\n", Printer->sharename)); return WERR_BADFID; } + /* the delete printer script shoudl be run as root if the user has perms */ + if (*lp_deleteprinter_cmd()) { char *cmd = lp_deleteprinter_cmd(); pstring command; int ret; - + SE_PRIV se_printop = SE_PRINT_OPERATOR; + BOOL is_print_op; + pstr_sprintf(command, "%s \"%s\"", cmd, Printer->sharename); + is_print_op = user_has_privileges( p->pipe_user.nt_user_token, &se_printop ); + DEBUG(10,("Running [%s]\n", command)); + + /********** BEGIN SePrintOperatorPrivlege BLOCK **********/ + + if ( is_print_op ) + become_root(); + ret = smbrun(command, NULL); - if (ret != 0) { - return WERR_BADFID; /* What to return here? */ - } + + if ( is_print_op ) + unbecome_root(); + + /********** BEGIN SePrintOperatorPrivlege BLOCK **********/ + DEBUGADD(10,("returned [%d]\n", ret)); - /* Send SIGHUP to process group... is there a better way? */ - kill(0, SIGHUP); + if (ret != 0) + return WERR_BADFID; /* What to return here? */ + + /* Tell everyone we updated smb.conf. */ + message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL); /* go ahead and re-read the services immediately */ reload_services( False ); @@ -5984,7 +6005,7 @@ static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) /**************************************************************************** ****************************************************************************/ -static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) +static BOOL add_printer_hook(NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer) { extern userdom_struct current_user_info; char *cmd = lp_addprinter_cmd(); @@ -5994,6 +6015,8 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) int ret; int fd; fstring remote_machine = "%m"; + SE_PRIV se_printop = SE_PRINT_OPERATOR; + BOOL is_print_op; standard_sub_basic(current_user_info.smb_name, remote_machine,sizeof(remote_machine)); @@ -6002,8 +6025,22 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) printer->info_2->portname, printer->info_2->drivername, printer->info_2->location, printer->info_2->comment, remote_machine); + is_print_op = user_has_privileges( token, &se_printop ); + DEBUG(10,("Running [%s]\n", command)); + + /********* BEGIN SePrintOperatorPrivilege **********/ + + if ( is_print_op ) + become_root(); + ret = smbrun(command, &fd); + + if ( is_print_op ) + unbecome_root(); + + /********* END SePrintOperatorPrivilege **********/ + DEBUGADD(10,("returned [%d]\n", ret)); if ( ret != 0 ) { @@ -6012,22 +6049,25 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer) return False; } + /* Tell everyone we updated smb.conf. */ + message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL); + + /* reload our services immediately */ + reload_services( False ); + numlines = 0; /* Get lines and convert them back to dos-codepage */ qlines = fd_lines_load(fd, &numlines); DEBUGADD(10,("Lines returned = [%d]\n", numlines)); close(fd); - if(numlines) { + /* Set the portname to what the script says the portname should be. */ + /* but don't require anything to be return from the script exit a good error code */ + + 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)); DEBUGADD(6,("Line[0] = [%s]\n", qlines[0])); - - /* Send SIGHUP to process group... is there a better way? */ - kill(0, SIGHUP); - - /* reload our services immediately */ - reload_services( False ); } file_lines_free(qlines); @@ -6122,7 +6162,7 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, || !strequal(printer->info_2->portname, old_printer->info_2->portname) || !strequal(printer->info_2->location, old_printer->info_2->location)) ) { - if ( !add_printer_hook(printer) ) { + if ( !add_printer_hook(p->pipe_user.nt_user_token, printer) ) { result = WERR_ACCESS_DENIED; goto done; } @@ -7416,7 +7456,7 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ trying to add a printer like this --jerry */ if (*lp_addprinter_cmd() ) { - if ( !add_printer_hook(printer) ) { + if ( !add_printer_hook(p->pipe_user.nt_user_token, printer) ) { free_a_printer(&printer,2); return WERR_ACCESS_DENIED; } -- cgit From 372440f207d88e058af76cf7ce4c5901ba7a7547 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 19 Jan 2005 21:10:56 +0000 Subject: r4856: after testing a simple add printer script, i realized that you still have to be root to send the message to all smbds that the config file has been updated (This used to be commit 6409de1a1ef34bb41c3efeebfabdf13be5e08613) --- source3/rpc_server/srv_spoolss_nt.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 31e1e4a3bf..ed7a544d72 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -409,21 +409,21 @@ static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) if ( is_print_op ) become_root(); - ret = smbrun(command, NULL); + if ( (ret = smbrun(command, NULL)) == 0 ) { + /* Tell everyone we updated smb.conf. */ + message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL); + } if ( is_print_op ) unbecome_root(); - /********** BEGIN SePrintOperatorPrivlege BLOCK **********/ + /********** END SePrintOperatorPrivlege BLOCK **********/ DEBUGADD(10,("returned [%d]\n", ret)); if (ret != 0) return WERR_BADFID; /* What to return here? */ - /* Tell everyone we updated smb.conf. */ - message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL); - /* go ahead and re-read the services immediately */ reload_services( False ); @@ -6034,7 +6034,10 @@ static BOOL add_printer_hook(NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printe if ( is_print_op ) become_root(); - ret = smbrun(command, &fd); + if ( (ret = smbrun(command, &fd)) == 0 ) { + /* Tell everyone we updated smb.conf. */ + message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL); + } if ( is_print_op ) unbecome_root(); @@ -6049,9 +6052,6 @@ static BOOL add_printer_hook(NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printe return False; } - /* Tell everyone we updated smb.conf. */ - message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL); - /* reload our services immediately */ reload_services( False ); -- cgit From 5ba59da467eef5cbc6506d45b0a6abb1777f2346 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 1 Mar 2005 17:28:25 +0000 Subject: r5605: only display the publish check box on printer if we are a member of an AD domain clean up some hardcoded constands with the REG_XXX constant. (This used to be commit a1d0be740d9ea8c9ea8c04950da826dd84bbc51b) --- source3/rpc_server/srv_spoolss_nt.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index ed7a544d72..ffeeb0af9a 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2310,7 +2310,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint DEBUG(8,("getprinterdata_printer_server:%s\n", value)); if (!StrCaseCmp(value, "W3SvcInstalled")) { - *type = 0x4; + *type = REG_DWORD; if((*data = (uint8 *)TALLOC_ZERO(ctx, 4*sizeof(uint8) )) == NULL) return WERR_NOMEM; *needed = 0x4; @@ -2318,7 +2318,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint } if (!StrCaseCmp(value, "BeepEnabled")) { - *type = 0x4; + *type = REG_DWORD; if((*data = (uint8 *)TALLOC(ctx, 4*sizeof(uint8) )) == NULL) return WERR_NOMEM; SIVAL(*data, 0, 0x00); @@ -2327,7 +2327,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint } if (!StrCaseCmp(value, "EventLog")) { - *type = 0x4; + *type = REG_DWORD; if((*data = (uint8 *)TALLOC(ctx, 4 )) == NULL) return WERR_NOMEM; /* formally was 0x1b */ @@ -2337,7 +2337,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint } if (!StrCaseCmp(value, "NetPopup")) { - *type = 0x4; + *type = REG_DWORD; if((*data = (uint8 *)TALLOC(ctx, 4 )) == NULL) return WERR_NOMEM; SIVAL(*data, 0, 0x00); @@ -2346,7 +2346,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint } if (!StrCaseCmp(value, "MajorVersion")) { - *type = 0x4; + *type = REG_DWORD; if((*data = (uint8 *)TALLOC(ctx, 4 )) == NULL) return WERR_NOMEM; @@ -2365,7 +2365,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint } if (!StrCaseCmp(value, "MinorVersion")) { - *type = 0x4; + *type = REG_DWORD; if((*data = (uint8 *)TALLOC(ctx, 4 )) == NULL) return WERR_NOMEM; SIVAL(*data, 0, 0); @@ -2381,7 +2381,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint * extra unicode string = e.g. "Service Pack 3" */ if (!StrCaseCmp(value, "OSVersion")) { - *type = 0x3; + *type = REG_BINARY; *needed = 0x114; if((*data = (uint8 *)TALLOC(ctx, *needed)) == NULL) @@ -2401,7 +2401,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint if (!StrCaseCmp(value, "DefaultSpoolDirectory")) { const char *string="C:\\PRINTERS"; - *type = 0x1; + *type = REG_SZ; *needed = 2*(strlen(string)+1); if((*data = (uint8 *)TALLOC(ctx, (*needed > in_size) ? *needed:in_size )) == NULL) return WERR_NOMEM; @@ -2417,7 +2417,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint if (!StrCaseCmp(value, "Architecture")) { const char *string="Windows NT x86"; - *type = 0x1; + *type = REG_SZ; *needed = 2*(strlen(string)+1); if((*data = (uint8 *)TALLOC(ctx, (*needed > in_size) ? *needed:in_size )) == NULL) return WERR_NOMEM; @@ -2430,10 +2430,18 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint } if (!StrCaseCmp(value, "DsPresent")) { - *type = 0x4; + *type = REG_DWORD; if((*data = (uint8 *)TALLOC(ctx, 4 )) == NULL) return WERR_NOMEM; - SIVAL(*data, 0, 0x01); + + /* only show the publish check box if we are a + memeber of a AD domain */ + + if ( lp_security() == SEC_ADS ) + SIVAL(*data, 0, 0x01); + else + SIVAL(*data, 0, 0x00); + *needed = 0x4; return WERR_OK; } @@ -2443,7 +2451,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint if (!get_mydnsfullname(hostname)) return WERR_BADFILE; - *type = 0x1; + *type = REG_SZ; *needed = 2*(strlen(hostname)+1); if((*data = (uint8 *)TALLOC(ctx, (*needed > in_size) ? *needed:in_size )) == NULL) return WERR_NOMEM; -- cgit From 61dfab9f705cb38e552dcec1822974433997543c Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 15 Mar 2005 19:43:44 +0000 Subject: r5805: merging spoolss parsing changes from trunk and cleaning up resulting segvs (This used to be commit 25121547caaaed0d60f4db7458570c14e7d21b2a) --- source3/rpc_server/srv_spoolss_nt.c | 908 ++++++++++++++++++++---------------- 1 file changed, 509 insertions(+), 399 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index ffeeb0af9a..053290f80f 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -644,41 +644,6 @@ static BOOL open_printer_hnd(pipes_struct *p, POLICY_HND *hnd, char *name, uint3 return True; } -/**************************************************************************** - Allocate more memory for a BUFFER. -****************************************************************************/ - -static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size) -{ - prs_struct *ps; - uint32 extra_space; - uint32 old_offset; - - ps= &buffer->prs; - - /* damn, I'm doing the reverse operation of prs_grow() :) */ - if (buffer_size < prs_data_size(ps)) - extra_space=0; - else - extra_space = buffer_size - prs_data_size(ps); - - /* - * save the offset and move to the end of the buffer - * prs_grow() checks the extra_space against the offset - */ - old_offset=prs_offset(ps); - prs_set_offset(ps, prs_data_size(ps)); - - if (!prs_grow(ps, extra_space)) - return False; - - prs_set_offset(ps, old_offset); - - buffer->string_at_end=prs_data_size(ps); - - return True; -} - /*************************************************************************** check to see if the client motify handle is monitoring the notification given by (notify_type, notify_field). @@ -4121,7 +4086,7 @@ static void free_dev_mode(DEVICEMODE *dev) if (dev == NULL) return; - SAFE_FREE(dev->private); + SAFE_FREE(dev->private); SAFE_FREE(dev); } @@ -4404,13 +4369,14 @@ static BOOL construct_printer_info_7(Printer_entry *print_hnd, PRINTER_INFO_7 *p Spoolss_enumprinters. ********************************************************************/ -static WERROR enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enum_all_printers_info_1(uint32 flags, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int snum; int i; int n_services=lp_numservices(); PRINTER_INFO_1 *tp, *printers=NULL; PRINTER_INFO_1 current_prt; + WERROR result = WERR_OK; DEBUG(4,("enum_all_printers_info_1\n")); @@ -4438,29 +4404,36 @@ static WERROR enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 for (i=0; i<*returned; i++) (*needed) += spoolss_size_printer_info_1(&printers[i]); - if (!alloc_buffer_size(buffer, *needed)) - return WERR_INSUFFICIENT_BUFFER; + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; + } + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; + } /* fill the buffer with the structures */ for (i=0; i<*returned; i++) smb_io_printer_info_1("", buffer, &printers[i], 0); +out: /* clear memory */ + SAFE_FREE(printers); - if (*needed > offered) { - *returned=0; - return WERR_INSUFFICIENT_BUFFER; - } - else - return WERR_OK; + if ( !W_ERROR_IS_OK(result) ) + *returned = 0; + + return result; } /******************************************************************** enum_all_printers_info_1_local. *********************************************************************/ -static WERROR enum_all_printers_info_1_local(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enum_all_printers_info_1_local(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { DEBUG(4,("enum_all_printers_info_1_local\n")); @@ -4471,7 +4444,7 @@ static WERROR enum_all_printers_info_1_local(NEW_BUFFER *buffer, uint32 offered, enum_all_printers_info_1_name. *********************************************************************/ -static WERROR enum_all_printers_info_1_name(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enum_all_printers_info_1_name(fstring name, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { char *s = name; @@ -4492,13 +4465,14 @@ static WERROR enum_all_printers_info_1_name(fstring name, NEW_BUFFER *buffer, ui enum_all_printers_info_1_remote. *********************************************************************/ -static WERROR enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enum_all_printers_info_1_remote(fstring name, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PRINTER_INFO_1 *printer; fstring printername; fstring desc; fstring comment; DEBUG(4,("enum_all_printers_info_1_remote\n")); + WERROR result = WERR_OK; /* JFM: currently it's more a place holder than anything else. * In the spooler world there is a notion of server registration. @@ -4525,23 +4499,27 @@ static WERROR enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, /* check the required size. */ *needed += spoolss_size_printer_info_1(printer); - if (!alloc_buffer_size(buffer, *needed)) { - SAFE_FREE(printer); - return WERR_INSUFFICIENT_BUFFER; + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; + } + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; } /* fill the buffer with the structures */ smb_io_printer_info_1("", buffer, printer, 0); +out: /* clear memory */ SAFE_FREE(printer); - if (*needed > offered) { - *returned=0; - return WERR_INSUFFICIENT_BUFFER; - } - else - return WERR_OK; + if ( !W_ERROR_IS_OK(result) ) + *returned = 0; + + return result; } #endif @@ -4550,7 +4528,7 @@ static WERROR enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, enum_all_printers_info_1_network. *********************************************************************/ -static WERROR enum_all_printers_info_1_network(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enum_all_printers_info_1_network(fstring name, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { char *s = name; @@ -4579,13 +4557,14 @@ static WERROR enum_all_printers_info_1_network(fstring name, NEW_BUFFER *buffer, * called from api_spoolss_enumprinters (see this to understand) ********************************************************************/ -static WERROR enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enum_all_printers_info_2(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int snum; int i; int n_services=lp_numservices(); PRINTER_INFO_2 *tp, *printers=NULL; PRINTER_INFO_2 current_prt; + WERROR result = WERR_OK; for (snum=0; snum offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; + } + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; } /* fill the buffer with the structures */ for (i=0; i<*returned; i++) smb_io_printer_info_2("", buffer, &(printers[i]), 0); +out: /* clear memory */ for (i=0; i<*returned; i++) { free_devmode(printers[i].devmode); } SAFE_FREE(printers); - if (*needed > offered) { - *returned=0; - return WERR_INSUFFICIENT_BUFFER; - } - else - return WERR_OK; + if ( !W_ERROR_IS_OK(result) ) + *returned = 0; + + return result; } /******************************************************************** @@ -4641,7 +4621,7 @@ static WERROR enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint3 ********************************************************************/ static WERROR enumprinters_level1( uint32 flags, fstring name, - NEW_BUFFER *buffer, uint32 offered, + RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { /* Not all the flags are equals */ @@ -4668,7 +4648,7 @@ static WERROR enumprinters_level1( uint32 flags, fstring name, ********************************************************************/ static WERROR enumprinters_level2( uint32 flags, fstring servername, - NEW_BUFFER *buffer, uint32 offered, + RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { char *s = servername; @@ -4697,7 +4677,7 @@ static WERROR enumprinters_level2( uint32 flags, fstring servername, ********************************************************************/ static WERROR enumprinters_level5( uint32 flags, fstring servername, - NEW_BUFFER *buffer, uint32 offered, + RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { /* return enum_all_printers_info_5(buffer, offered, needed, returned);*/ @@ -4715,7 +4695,7 @@ WERROR _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOOL_ uint32 flags = q_u->flags; UNISTR2 *servername = &q_u->servername; uint32 level = q_u->level; - NEW_BUFFER *buffer = NULL; + RPC_BUFFER *buffer = NULL; uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; uint32 *returned = &r_u->returned; @@ -4723,8 +4703,11 @@ WERROR _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOOL_ fstring name; /* that's an [in out] buffer */ - spoolss_move_buffer(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + + if ( q_u->buffer ) { + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + } DEBUG(4,("_spoolss_enumprinters\n")); @@ -4764,9 +4747,10 @@ WERROR _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOOL_ /**************************************************************************** ****************************************************************************/ -static WERROR getprinter_level_0(Printer_entry *print_hnd, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinter_level_0(Printer_entry *print_hnd, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_0 *printer=NULL; + WERROR result = WERR_OK; if((printer=SMB_MALLOC_P(PRINTER_INFO_0)) == NULL) return WERR_NOMEM; @@ -4776,30 +4760,34 @@ static WERROR getprinter_level_0(Printer_entry *print_hnd, int snum, NEW_BUFFER /* check the required size. */ *needed += spoolss_size_printer_info_0(printer); - if (!alloc_buffer_size(buffer, *needed)) { - SAFE_FREE(printer); - return WERR_INSUFFICIENT_BUFFER; + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; + } + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; } /* fill the buffer with the structures */ smb_io_printer_info_0("", buffer, printer, 0); +out: /* clear memory */ - SAFE_FREE(printer); - if (*needed > offered) { - return WERR_INSUFFICIENT_BUFFER; - } + SAFE_FREE(printer); - return WERR_OK; + return result; } /**************************************************************************** ****************************************************************************/ -static WERROR getprinter_level_1(Printer_entry *print_hnd, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinter_level_1(Printer_entry *print_hnd, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_1 *printer=NULL; + WERROR result = WERR_OK; if((printer=SMB_MALLOC_P(PRINTER_INFO_1)) == NULL) return WERR_NOMEM; @@ -4809,30 +4797,33 @@ static WERROR getprinter_level_1(Printer_entry *print_hnd, int snum, NEW_BUFFER /* check the required size. */ *needed += spoolss_size_printer_info_1(printer); - if (!alloc_buffer_size(buffer, *needed)) { - SAFE_FREE(printer); - return WERR_INSUFFICIENT_BUFFER; + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; + } + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; } /* fill the buffer with the structures */ smb_io_printer_info_1("", buffer, printer, 0); +out: /* clear memory */ SAFE_FREE(printer); - if (*needed > offered) { - return WERR_INSUFFICIENT_BUFFER; - } - - return WERR_OK; + return result; } /**************************************************************************** ****************************************************************************/ -static WERROR getprinter_level_2(Printer_entry *print_hnd, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinter_level_2(Printer_entry *print_hnd, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_2 *printer=NULL; + WERROR result = WERR_OK; if((printer=SMB_MALLOC_P(PRINTER_INFO_2))==NULL) return WERR_NOMEM; @@ -4842,33 +4833,34 @@ static WERROR getprinter_level_2(Printer_entry *print_hnd, int snum, NEW_BUFFER /* check the required size. */ *needed += spoolss_size_printer_info_2(printer); - if (!alloc_buffer_size(buffer, *needed)) { - free_printer_info_2(printer); - return WERR_INSUFFICIENT_BUFFER; + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; } - /* fill the buffer with the structures */ - if (!smb_io_printer_info_2("", buffer, printer, 0)) { - free_printer_info_2(printer); - return WERR_NOMEM; + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; } + + /* fill the buffer with the structures */ + if (!smb_io_printer_info_2("", buffer, printer, 0)) + result = WERR_NOMEM; +out: /* clear memory */ free_printer_info_2(printer); - if (*needed > offered) { - return WERR_INSUFFICIENT_BUFFER; - } - - return WERR_OK; + return result; } /**************************************************************************** ****************************************************************************/ -static WERROR getprinter_level_3(Printer_entry *print_hnd, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinter_level_3(Printer_entry *print_hnd, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_3 *printer=NULL; + WERROR result = WERR_OK; if (!construct_printer_info_3(print_hnd, &printer, snum)) return WERR_NOMEM; @@ -4876,30 +4868,33 @@ static WERROR getprinter_level_3(Printer_entry *print_hnd, int snum, NEW_BUFFER /* check the required size. */ *needed += spoolss_size_printer_info_3(printer); - if (!alloc_buffer_size(buffer, *needed)) { - free_printer_info_3(printer); - return WERR_INSUFFICIENT_BUFFER; + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; + } + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; } /* fill the buffer with the structures */ smb_io_printer_info_3("", buffer, printer, 0); +out: /* clear memory */ free_printer_info_3(printer); - if (*needed > offered) { - return WERR_INSUFFICIENT_BUFFER; - } - - return WERR_OK; + return result; } /**************************************************************************** ****************************************************************************/ -static WERROR getprinter_level_4(Printer_entry *print_hnd, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinter_level_4(Printer_entry *print_hnd, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_4 *printer=NULL; + WERROR result = WERR_OK; if((printer=SMB_MALLOC_P(PRINTER_INFO_4))==NULL) return WERR_NOMEM; @@ -4910,30 +4905,33 @@ static WERROR getprinter_level_4(Printer_entry *print_hnd, int snum, NEW_BUFFER /* check the required size. */ *needed += spoolss_size_printer_info_4(printer); - if (!alloc_buffer_size(buffer, *needed)) { - free_printer_info_4(printer); - return WERR_INSUFFICIENT_BUFFER; + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; + } + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; } /* fill the buffer with the structures */ smb_io_printer_info_4("", buffer, printer, 0); +out: /* clear memory */ free_printer_info_4(printer); - if (*needed > offered) { - return WERR_INSUFFICIENT_BUFFER; - } - - return WERR_OK; + return result; } /**************************************************************************** ****************************************************************************/ -static WERROR getprinter_level_5(Printer_entry *print_hnd, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinter_level_5(Printer_entry *print_hnd, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_5 *printer=NULL; + WERROR result = WERR_OK; if((printer=SMB_MALLOC_P(PRINTER_INFO_5))==NULL) return WERR_NOMEM; @@ -4944,27 +4942,30 @@ static WERROR getprinter_level_5(Printer_entry *print_hnd, int snum, NEW_BUFFER /* check the required size. */ *needed += spoolss_size_printer_info_5(printer); - if (!alloc_buffer_size(buffer, *needed)) { - free_printer_info_5(printer); - return WERR_INSUFFICIENT_BUFFER; + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; + } + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; } /* fill the buffer with the structures */ smb_io_printer_info_5("", buffer, printer, 0); +out: /* clear memory */ free_printer_info_5(printer); - if (*needed > offered) { - return WERR_INSUFFICIENT_BUFFER; - } - - return WERR_OK; + return result; } -static WERROR getprinter_level_7(Printer_entry *print_hnd, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinter_level_7(Printer_entry *print_hnd, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_7 *printer=NULL; + WERROR result = WERR_OK; if((printer=SMB_MALLOC_P(PRINTER_INFO_7))==NULL) return WERR_NOMEM; @@ -4975,22 +4976,25 @@ static WERROR getprinter_level_7(Printer_entry *print_hnd, int snum, NEW_BUFFER /* check the required size. */ *needed += spoolss_size_printer_info_7(printer); - if (!alloc_buffer_size(buffer, *needed)) { - free_printer_info_7(printer); - return WERR_INSUFFICIENT_BUFFER; + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; + } + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; + } /* fill the buffer with the structures */ smb_io_printer_info_7("", buffer, printer, 0); +out: /* clear memory */ free_printer_info_7(printer); - if (*needed > offered) { - return WERR_INSUFFICIENT_BUFFER; - } - - return WERR_OK; + return result; } /**************************************************************************** @@ -5000,7 +5004,7 @@ WERROR _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GET { POLICY_HND *handle = &q_u->handle; uint32 level = q_u->level; - NEW_BUFFER *buffer = NULL; + RPC_BUFFER *buffer = NULL; uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; Printer_entry *Printer=find_printer_index_by_hnd(p, handle); @@ -5008,8 +5012,11 @@ WERROR _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GET int snum; /* that's an [in out] buffer */ - spoolss_move_buffer(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + + if ( q_u->buffer ) { + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + } *needed=0; @@ -5433,149 +5440,154 @@ static void free_printer_driver_info_3(DRIVER_INFO_3 *info) static void free_printer_driver_info_6(DRIVER_INFO_6 *info) { SAFE_FREE(info->dependentfiles); - } /**************************************************************************** ****************************************************************************/ -static WERROR getprinterdriver2_level1(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinterdriver2_level1(fstring servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_1 *info=NULL; - WERROR status; + WERROR result; if((info=SMB_MALLOC_P(DRIVER_INFO_1)) == NULL) return WERR_NOMEM; - status=construct_printer_driver_info_1(info, snum, servername, architecture, version); - if (!W_ERROR_IS_OK(status)) { - SAFE_FREE(info); - return status; - } + result = construct_printer_driver_info_1(info, snum, servername, architecture, version); + if (!W_ERROR_IS_OK(result)) + goto out; /* check the required size. */ *needed += spoolss_size_printer_driver_info_1(info); - if (!alloc_buffer_size(buffer, *needed)) { - SAFE_FREE(info); - return WERR_INSUFFICIENT_BUFFER; + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; + } + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; } /* fill the buffer with the structures */ smb_io_printer_driver_info_1("", buffer, info, 0); +out: /* clear memory */ SAFE_FREE(info); - if (*needed > offered) - return WERR_INSUFFICIENT_BUFFER; - - return WERR_OK; + return result; } /**************************************************************************** ****************************************************************************/ -static WERROR getprinterdriver2_level2(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinterdriver2_level2(fstring servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_2 *info=NULL; - WERROR status; + WERROR result; if((info=SMB_MALLOC_P(DRIVER_INFO_2)) == NULL) return WERR_NOMEM; - status=construct_printer_driver_info_2(info, snum, servername, architecture, version); - if (!W_ERROR_IS_OK(status)) { - SAFE_FREE(info); - return status; - } + result = construct_printer_driver_info_2(info, snum, servername, architecture, version); + if (!W_ERROR_IS_OK(result)) + goto out; /* check the required size. */ *needed += spoolss_size_printer_driver_info_2(info); - if (!alloc_buffer_size(buffer, *needed)) { - SAFE_FREE(info); - return WERR_INSUFFICIENT_BUFFER; + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; + } + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; } /* fill the buffer with the structures */ smb_io_printer_driver_info_2("", buffer, info, 0); +out: /* clear memory */ SAFE_FREE(info); - if (*needed > offered) - return WERR_INSUFFICIENT_BUFFER; - - return WERR_OK; + return result; } /**************************************************************************** ****************************************************************************/ -static WERROR getprinterdriver2_level3(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinterdriver2_level3(fstring servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_3 info; - WERROR status; + WERROR result; ZERO_STRUCT(info); - status=construct_printer_driver_info_3(&info, snum, servername, architecture, version); - if (!W_ERROR_IS_OK(status)) { - return status; - } + result = construct_printer_driver_info_3(&info, snum, servername, architecture, version); + if (!W_ERROR_IS_OK(result)) + goto out; /* check the required size. */ *needed += spoolss_size_printer_driver_info_3(&info); - if (!alloc_buffer_size(buffer, *needed)) { - free_printer_driver_info_3(&info); - return WERR_INSUFFICIENT_BUFFER; + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; + } + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; } /* fill the buffer with the structures */ smb_io_printer_driver_info_3("", buffer, &info, 0); +out: free_printer_driver_info_3(&info); - if (*needed > offered) - return WERR_INSUFFICIENT_BUFFER; - - return WERR_OK; + return result; } /**************************************************************************** ****************************************************************************/ -static WERROR getprinterdriver2_level6(fstring servername, fstring architecture, uint32 version, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinterdriver2_level6(fstring servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_6 info; - WERROR status; + WERROR result; ZERO_STRUCT(info); - status=construct_printer_driver_info_6(&info, snum, servername, architecture, version); - if (!W_ERROR_IS_OK(status)) { - return status; - } + result = construct_printer_driver_info_6(&info, snum, servername, architecture, version); + if (!W_ERROR_IS_OK(result)) + goto out; /* check the required size. */ *needed += spoolss_size_printer_driver_info_6(&info); - if (!alloc_buffer_size(buffer, *needed)) { - free_printer_driver_info_6(&info); - return WERR_INSUFFICIENT_BUFFER; + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; + } + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; } /* fill the buffer with the structures */ smb_io_printer_driver_info_6("", buffer, &info, 0); +out: free_printer_driver_info_6(&info); - if (*needed > offered) - return WERR_INSUFFICIENT_BUFFER; - - return WERR_OK; + return result; } /**************************************************************************** @@ -5587,7 +5599,7 @@ WERROR _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_ UNISTR2 *uni_arch = &q_u->architecture; uint32 level = q_u->level; uint32 clientmajorversion = q_u->clientmajorversion; - NEW_BUFFER *buffer = NULL; + RPC_BUFFER *buffer = NULL; uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; uint32 *servermajorversion = &r_u->servermajorversion; @@ -5599,8 +5611,11 @@ WERROR _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_ int snum; /* that's an [in out] buffer */ - spoolss_move_buffer(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + + if ( q_u->buffer ) { + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + } DEBUG(4,("_spoolss_getprinterdriver2\n")); @@ -6389,8 +6404,10 @@ WERROR _spoolss_fcpn(pipes_struct *p, SPOOL_Q_FCPN *q_u, SPOOL_R_FCPN *r_u) WERROR _spoolss_addjob(pipes_struct *p, SPOOL_Q_ADDJOB *q_u, SPOOL_R_ADDJOB *r_u) { - /* that's an [in out] buffer (despite appearences to the contrary) */ - spoolss_move_buffer(q_u->buffer, &r_u->buffer); + /* that's an [in out] buffer */ + + if ( q_u->buffer ) + rpcbuf_move(q_u->buffer, &r_u->buffer); r_u->needed = 0; return WERR_INVALID_PARAM; /* this is what a NT server @@ -6476,11 +6493,12 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, static WERROR enumjobs_level1(print_queue_struct *queue, int snum, NT_PRINTER_INFO_LEVEL *ntprinter, - NEW_BUFFER *buffer, uint32 offered, + RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { JOB_INFO_1 *info; int i; + WERROR result = WERR_OK; info=SMB_MALLOC_ARRAY(JOB_INFO_1,*returned); if (info==NULL) { @@ -6498,24 +6516,28 @@ static WERROR enumjobs_level1(print_queue_struct *queue, int snum, for (i=0; i<*returned; i++) (*needed) += spoolss_size_job_info_1(&info[i]); - if (!alloc_buffer_size(buffer, *needed)) { - SAFE_FREE(info); - return WERR_INSUFFICIENT_BUFFER; + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; + } + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; } /* fill the buffer with the structures */ for (i=0; i<*returned; i++) smb_io_job_info_1("", buffer, &info[i], 0); +out: /* clear memory */ SAFE_FREE(info); - if (*needed > offered) { - *returned=0; - return WERR_INSUFFICIENT_BUFFER; - } + if ( !W_ERROR_IS_OK(result) ) + *returned = 0; - return WERR_OK; + return result; } /**************************************************************************** @@ -6524,19 +6546,17 @@ static WERROR enumjobs_level1(print_queue_struct *queue, int snum, static WERROR enumjobs_level2(print_queue_struct *queue, int snum, NT_PRINTER_INFO_LEVEL *ntprinter, - NEW_BUFFER *buffer, uint32 offered, + RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { JOB_INFO_2 *info = NULL; int i; - WERROR result; + WERROR result = WERR_OK; DEVICEMODE *devmode = NULL; - info=SMB_MALLOC_ARRAY(JOB_INFO_2,*returned); - if (info==NULL) { + if ( !(info = SMB_MALLOC_ARRAY(JOB_INFO_2,*returned)) ) { *returned=0; - result = WERR_NOMEM; - goto done; + return WERR_NOMEM; } /* this should not be a failure condition if the devmode is NULL */ @@ -6544,8 +6564,7 @@ static WERROR enumjobs_level2(print_queue_struct *queue, int snum, devmode = construct_dev_mode(snum); for (i=0; i<*returned; i++) - fill_job_info_2(&(info[i]), &queue[i], i, snum, ntprinter, - devmode); + fill_job_info_2(&(info[i]), &queue[i], i, snum, ntprinter, devmode); free_a_printer(&ntprinter, 2); SAFE_FREE(queue); @@ -6555,29 +6574,26 @@ static WERROR enumjobs_level2(print_queue_struct *queue, int snum, (*needed) += spoolss_size_job_info_2(&info[i]); if (*needed > offered) { - *returned=0; result = WERR_INSUFFICIENT_BUFFER; - goto done; + goto out; } - if (!alloc_buffer_size(buffer, *needed)) { - SAFE_FREE(info); - result = WERR_INSUFFICIENT_BUFFER; - goto done; + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; } /* fill the buffer with the structures */ for (i=0; i<*returned; i++) smb_io_job_info_2("", buffer, &info[i], 0); - result = WERR_OK; - - done: - free_a_printer(&ntprinter, 2); +out: free_devmode(devmode); - SAFE_FREE(queue); SAFE_FREE(info); + if ( !W_ERROR_IS_OK(result) ) + *returned = 0; + return result; } @@ -6590,7 +6606,7 @@ WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO { POLICY_HND *handle = &q_u->handle; uint32 level = q_u->level; - NEW_BUFFER *buffer = NULL; + RPC_BUFFER *buffer = NULL; uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; uint32 *returned = &r_u->returned; @@ -6601,8 +6617,11 @@ WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO print_queue_struct *queue=NULL; /* that's an [in out] buffer */ - spoolss_move_buffer(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + + if ( q_u->buffer ) { + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + } DEBUG(4,("_spoolss_enumjobs\n")); @@ -6703,15 +6722,15 @@ WERROR _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u Enumerates all printer drivers at level 1. ****************************************************************************/ -static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int i; int ndrivers; uint32 version; fstring *list = NULL; - NT_PRINTER_DRIVER_INFO_LEVEL driver; DRIVER_INFO_1 *tdi1, *driver_info_1=NULL; + WERROR result = WERR_OK; *returned=0; @@ -6757,9 +6776,14 @@ static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture *needed += spoolss_size_printer_driver_info_1(&driver_info_1[i]); } - if (!alloc_buffer_size(buffer, *needed)) { - SAFE_FREE(driver_info_1); - return WERR_INSUFFICIENT_BUFFER; + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; + } + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; } /* fill the buffer with the driver structures */ @@ -6768,29 +6792,28 @@ static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture smb_io_printer_driver_info_1("", buffer, &driver_info_1[i], 0); } +out: SAFE_FREE(driver_info_1); - if (*needed > offered) { - *returned=0; - return WERR_INSUFFICIENT_BUFFER; - } + if ( !W_ERROR_IS_OK(result) ) + *returned = 0; - return WERR_OK; + return result; } /**************************************************************************** Enumerates all printer drivers at level 2. ****************************************************************************/ -static WERROR enumprinterdrivers_level2(fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enumprinterdrivers_level2(fstring servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int i; int ndrivers; uint32 version; fstring *list = NULL; - NT_PRINTER_DRIVER_INFO_LEVEL driver; DRIVER_INFO_2 *tdi2, *driver_info_2=NULL; + WERROR result = WERR_OK; *returned=0; @@ -6837,9 +6860,14 @@ static WERROR enumprinterdrivers_level2(fstring servername, fstring architecture *needed += spoolss_size_printer_driver_info_2(&(driver_info_2[i])); } - if (!alloc_buffer_size(buffer, *needed)) { - SAFE_FREE(driver_info_2); - return WERR_INSUFFICIENT_BUFFER; + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; + } + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; } /* fill the buffer with the form structures */ @@ -6848,29 +6876,28 @@ static WERROR enumprinterdrivers_level2(fstring servername, fstring architecture smb_io_printer_driver_info_2("", buffer, &(driver_info_2[i]), 0); } +out: SAFE_FREE(driver_info_2); - if (*needed > offered) { - *returned=0; - return WERR_INSUFFICIENT_BUFFER; - } + if ( !W_ERROR_IS_OK(result) ) + *returned = 0; - return WERR_OK; + return result; } /**************************************************************************** Enumerates all printer drivers at level 3. ****************************************************************************/ -static WERROR enumprinterdrivers_level3(fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enumprinterdrivers_level3(fstring servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int i; int ndrivers; uint32 version; fstring *list = NULL; - NT_PRINTER_DRIVER_INFO_LEVEL driver; DRIVER_INFO_3 *tdi3, *driver_info_3=NULL; + WERROR result = WERR_OK; *returned=0; @@ -6917,28 +6944,32 @@ static WERROR enumprinterdrivers_level3(fstring servername, fstring architecture *needed += spoolss_size_printer_driver_info_3(&driver_info_3[i]); } - if (!alloc_buffer_size(buffer, *needed)) { - SAFE_FREE(driver_info_3); - return WERR_INSUFFICIENT_BUFFER; + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; } - + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; + } + /* fill the buffer with the driver structures */ for (i=0; i<*returned; i++) { DEBUGADD(6,("adding driver [%d] to buffer\n",i)); smb_io_printer_driver_info_3("", buffer, &driver_info_3[i], 0); } +out: for (i=0; i<*returned; i++) SAFE_FREE(driver_info_3[i].dependentfiles); - + SAFE_FREE(driver_info_3); - if (*needed > offered) { - *returned=0; - return WERR_INSUFFICIENT_BUFFER; - } + if ( !W_ERROR_IS_OK(result) ) + *returned = 0; - return WERR_OK; + return result; } /**************************************************************************** @@ -6948,22 +6979,25 @@ static WERROR enumprinterdrivers_level3(fstring servername, fstring architecture WERROR _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS *q_u, SPOOL_R_ENUMPRINTERDRIVERS *r_u) { uint32 level = q_u->level; - NEW_BUFFER *buffer = NULL; + RPC_BUFFER *buffer = NULL; uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; uint32 *returned = &r_u->returned; - fstring *list = NULL; fstring servername; fstring architecture; /* that's an [in out] buffer */ - spoolss_move_buffer(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + + if ( q_u->buffer ) { + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + } DEBUG(4,("_spoolss_enumprinterdrivers\n")); - *needed=0; - *returned=0; + + *needed = 0; + *returned = 0; unistr2_to_ascii(architecture, &q_u->environment, sizeof(architecture)-1); unistr2_to_ascii(servername, &q_u->name, sizeof(servername)-1); @@ -6979,8 +7013,6 @@ WERROR _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS case 3: return enumprinterdrivers_level3(servername, architecture, buffer, offered, needed, returned); default: - *returned=0; - SAFE_FREE(list); return WERR_UNKNOWN_LEVEL; } } @@ -7006,7 +7038,7 @@ static void fill_form_1(FORM_1 *form, nt_forms_struct *list) WERROR _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMFORMS *r_u) { uint32 level = q_u->level; - NEW_BUFFER *buffer = NULL; + RPC_BUFFER *buffer = NULL; uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; uint32 *numofforms = &r_u->numofforms; @@ -7019,8 +7051,11 @@ WERROR _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMF int i; /* that's an [in out] buffer */ - spoolss_move_buffer(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + + if ( q_u->buffer ) { + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + } DEBUG(4,("_spoolss_enumforms\n")); DEBUGADD(5,("Offered buffer size [%d]\n", offered)); @@ -7032,7 +7067,8 @@ WERROR _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMF DEBUGADD(5,("Number of user forms [%d]\n", *numofforms)); *numofforms += numbuiltinforms; - if (*numofforms == 0) return WERR_NO_MORE_ITEMS; + if (*numofforms == 0) + return WERR_NO_MORE_ITEMS; switch (level) { case 1: @@ -7068,10 +7104,17 @@ WERROR _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMF *needed=buffer_size; - if (!alloc_buffer_size(buffer, buffer_size)){ + if (*needed > offered) { SAFE_FREE(forms_1); + *numofforms=0; return WERR_INSUFFICIENT_BUFFER; } + + if (!rpcbuf_alloc_size(buffer, buffer_size)){ + SAFE_FREE(forms_1); + *numofforms=0; + return WERR_NOMEM; + } /* fill the buffer with the form structures */ for (i=0; i offered) { - *numofforms=0; - return WERR_INSUFFICIENT_BUFFER; - } - else - return WERR_OK; + return WERR_OK; default: SAFE_FREE(list); @@ -7107,7 +7145,7 @@ WERROR _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * { uint32 level = q_u->level; UNISTR2 *uni_formname = &q_u->formname; - NEW_BUFFER *buffer = NULL; + RPC_BUFFER *buffer = NULL; uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; @@ -7120,8 +7158,11 @@ WERROR _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * int numofforms=0, i=0; /* that's an [in out] buffer */ - spoolss_move_buffer(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + + if ( q_u->buffer ) { + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + } unistr2_to_ascii(form_name, uni_formname, sizeof(form_name)-1); @@ -7165,13 +7206,11 @@ WERROR _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * *needed=spoolss_size_form_1(&form_1); - if (!alloc_buffer_size(buffer, buffer_size)){ + if (*needed > offered) return WERR_INSUFFICIENT_BUFFER; - } - if (*needed > offered) { - return WERR_INSUFFICIENT_BUFFER; - } + if (!rpcbuf_alloc_size(buffer, buffer_size)) + return WERR_NOMEM; /* fill the buffer with the form structures */ DEBUGADD(6,("adding form %s [%d] to buffer\n", form_name, i)); @@ -7209,10 +7248,11 @@ static void fill_port_2(PORT_INFO_2 *port, const char *name) enumports level 1. ****************************************************************************/ -static WERROR enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enumports_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PORT_INFO_1 *ports=NULL; int i=0; + WERROR result = WERR_OK; if (*lp_enumports_cmd()) { char *cmd = lp_enumports_cmd(); @@ -7274,9 +7314,14 @@ static WERROR enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need *needed += spoolss_size_port_info_1(&ports[i]); } - if (!alloc_buffer_size(buffer, *needed)) { - SAFE_FREE(ports); - return WERR_INSUFFICIENT_BUFFER; + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; + } + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; } /* fill the buffer with the ports structures */ @@ -7285,24 +7330,24 @@ static WERROR enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need smb_io_port_1("", buffer, &ports[i], 0); } +out: SAFE_FREE(ports); - if (*needed > offered) { - *returned=0; - return WERR_INSUFFICIENT_BUFFER; - } + if ( !W_ERROR_IS_OK(result) ) + *returned = 0; - return WERR_OK; + return result; } /**************************************************************************** enumports level 2. ****************************************************************************/ -static WERROR enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enumports_level_2(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PORT_INFO_2 *ports=NULL; int i=0; + WERROR result = WERR_OK; if (*lp_enumports_cmd()) { char *cmd = lp_enumports_cmd(); @@ -7372,9 +7417,14 @@ static WERROR enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need *needed += spoolss_size_port_info_2(&ports[i]); } - if (!alloc_buffer_size(buffer, *needed)) { - SAFE_FREE(ports); - return WERR_INSUFFICIENT_BUFFER; + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; + } + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; } /* fill the buffer with the ports structures */ @@ -7383,14 +7433,13 @@ static WERROR enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need smb_io_port_2("", buffer, &ports[i], 0); } +out: SAFE_FREE(ports); - if (*needed > offered) { - *returned=0; - return WERR_INSUFFICIENT_BUFFER; - } + if ( !W_ERROR_IS_OK(result) ) + *returned = 0; - return WERR_OK; + return result; } /**************************************************************************** @@ -7400,14 +7449,17 @@ static WERROR enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need WERROR _spoolss_enumports( pipes_struct *p, SPOOL_Q_ENUMPORTS *q_u, SPOOL_R_ENUMPORTS *r_u) { uint32 level = q_u->level; - NEW_BUFFER *buffer = NULL; + RPC_BUFFER *buffer = NULL; uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; uint32 *returned = &r_u->returned; /* that's an [in out] buffer */ - spoolss_move_buffer(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + + if ( q_u->buffer ) { + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + } DEBUG(4,("_spoolss_enumports\n")); @@ -7741,7 +7793,7 @@ static void fill_driverdir_1(DRIVER_DIRECTORY_1 *info, char *name) /**************************************************************************** ****************************************************************************/ -static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environment, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environment, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { pstring path; pstring long_archi; @@ -7749,6 +7801,7 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen char *pservername; const char *short_archi; DRIVER_DIRECTORY_1 *info=NULL; + WERROR result = WERR_OK; unistr2_to_ascii(servername, name, sizeof(servername)-1); unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)-1); @@ -7778,19 +7831,22 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen *needed += spoolss_size_driverdir_info_1(info); - if (!alloc_buffer_size(buffer, *needed)) { - SAFE_FREE(info); - return WERR_INSUFFICIENT_BUFFER; + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; + } + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; } smb_io_driverdir_1("", buffer, info, 0); +out: SAFE_FREE(info); - if (*needed > offered) - return WERR_INSUFFICIENT_BUFFER; - - return WERR_OK; + return result; } /**************************************************************************** @@ -7801,13 +7857,16 @@ WERROR _spoolss_getprinterdriverdirectory(pipes_struct *p, SPOOL_Q_GETPRINTERDRI UNISTR2 *name = &q_u->name; UNISTR2 *uni_environment = &q_u->environment; uint32 level = q_u->level; - NEW_BUFFER *buffer = NULL; + RPC_BUFFER *buffer = NULL; uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; /* that's an [in out] buffer */ - spoolss_move_buffer(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + + if ( q_u->buffer ) { + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + } DEBUG(4,("_spoolss_getprinterdriverdirectory\n")); @@ -8367,9 +8426,10 @@ done: enumprintprocessors level 1. ****************************************************************************/ -static WERROR enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enumprintprocessors_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PRINTPROCESSOR_1 *info_1=NULL; + WERROR result = WERR_OK; if((info_1 = SMB_MALLOC_P(PRINTPROCESSOR_1)) == NULL) return WERR_NOMEM; @@ -8380,19 +8440,25 @@ static WERROR enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, ui *needed += spoolss_size_printprocessor_info_1(info_1); - if (!alloc_buffer_size(buffer, *needed)) - return WERR_INSUFFICIENT_BUFFER; + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; + } + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; + } smb_io_printprocessor_info_1("", buffer, info_1, 0); +out: SAFE_FREE(info_1); - if (*needed > offered) { - *returned=0; - return WERR_INSUFFICIENT_BUFFER; - } + if ( !W_ERROR_IS_OK(result) ) + *returned = 0; - return WERR_OK; + return result; } /**************************************************************************** @@ -8401,14 +8467,17 @@ static WERROR enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, ui WERROR _spoolss_enumprintprocessors(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCESSORS *q_u, SPOOL_R_ENUMPRINTPROCESSORS *r_u) { uint32 level = q_u->level; - NEW_BUFFER *buffer = NULL; + RPC_BUFFER *buffer = NULL; uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; uint32 *returned = &r_u->returned; /* that's an [in out] buffer */ - spoolss_move_buffer(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + + if ( q_u->buffer ) { + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + } DEBUG(5,("spoolss_enumprintprocessors\n")); @@ -8434,9 +8503,10 @@ WERROR _spoolss_enumprintprocessors(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCESSORS enumprintprocdatatypes level 1. ****************************************************************************/ -static WERROR enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enumprintprocdatatypes_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PRINTPROCDATATYPE_1 *info_1=NULL; + WERROR result = WERR_NOMEM; if((info_1 = SMB_MALLOC_P(PRINTPROCDATATYPE_1)) == NULL) return WERR_NOMEM; @@ -8447,19 +8517,25 @@ static WERROR enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered, *needed += spoolss_size_printprocdatatype_info_1(info_1); - if (!alloc_buffer_size(buffer, *needed)) - return WERR_INSUFFICIENT_BUFFER; + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; + } + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; + } smb_io_printprocdatatype_info_1("", buffer, info_1, 0); +out: SAFE_FREE(info_1); - if (*needed > offered) { - *returned=0; - return WERR_INSUFFICIENT_BUFFER; - } + if ( !W_ERROR_IS_OK(result) ) + *returned = 0; - return WERR_OK; + return result; } /**************************************************************************** @@ -8468,14 +8544,17 @@ static WERROR enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered, WERROR _spoolss_enumprintprocdatatypes(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCDATATYPES *q_u, SPOOL_R_ENUMPRINTPROCDATATYPES *r_u) { uint32 level = q_u->level; - NEW_BUFFER *buffer = NULL; + RPC_BUFFER *buffer = NULL; uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; uint32 *returned = &r_u->returned; /* that's an [in out] buffer */ - spoolss_move_buffer(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + + if ( q_u->buffer ) { + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + } DEBUG(5,("_spoolss_enumprintprocdatatypes\n")); @@ -8494,9 +8573,10 @@ WERROR _spoolss_enumprintprocdatatypes(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCDAT enumprintmonitors level 1. ****************************************************************************/ -static WERROR enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enumprintmonitors_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PRINTMONITOR_1 *info_1=NULL; + WERROR result = WERR_OK; if((info_1 = SMB_MALLOC_P(PRINTMONITOR_1)) == NULL) return WERR_NOMEM; @@ -8507,28 +8587,35 @@ static WERROR enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, uint *needed += spoolss_size_printmonitor_info_1(info_1); - if (!alloc_buffer_size(buffer, *needed)) - return WERR_INSUFFICIENT_BUFFER; + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; + } + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; + } smb_io_printmonitor_info_1("", buffer, info_1, 0); +out: SAFE_FREE(info_1); - if (*needed > offered) { - *returned=0; - return WERR_INSUFFICIENT_BUFFER; - } + if ( !W_ERROR_IS_OK(result) ) + *returned = 0; - return WERR_OK; + return result; } /**************************************************************************** enumprintmonitors level 2. ****************************************************************************/ -static WERROR enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enumprintmonitors_level_2(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PRINTMONITOR_2 *info_2=NULL; + WERROR result = WERR_OK; if((info_2 = SMB_MALLOC_P(PRINTMONITOR_2)) == NULL) return WERR_NOMEM; @@ -8541,19 +8628,25 @@ static WERROR enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint *needed += spoolss_size_printmonitor_info_2(info_2); - if (!alloc_buffer_size(buffer, *needed)) - return WERR_INSUFFICIENT_BUFFER; + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; + } + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; + } smb_io_printmonitor_info_2("", buffer, info_2, 0); +out: SAFE_FREE(info_2); - if (*needed > offered) { - *returned=0; - return WERR_INSUFFICIENT_BUFFER; - } - - return WERR_OK; + if ( !W_ERROR_IS_OK(result) ) + *returned = 0; + + return result; } /**************************************************************************** @@ -8562,14 +8655,17 @@ static WERROR enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint WERROR _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS *q_u, SPOOL_R_ENUMPRINTMONITORS *r_u) { uint32 level = q_u->level; - NEW_BUFFER *buffer = NULL; + RPC_BUFFER *buffer = NULL; uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; uint32 *returned = &r_u->returned; /* that's an [in out] buffer */ - spoolss_move_buffer(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + + if ( q_u->buffer ) { + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + } DEBUG(5,("spoolss_enumprintmonitors\n")); @@ -8598,12 +8694,13 @@ WERROR _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS *q_ static WERROR getjob_level_1(print_queue_struct **queue, int count, int snum, NT_PRINTER_INFO_LEVEL *ntprinter, - uint32 jobid, NEW_BUFFER *buffer, uint32 offered, + uint32 jobid, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { int i=0; BOOL found=False; JOB_INFO_1 *info_1=NULL; + WERROR result = WERR_OK; info_1=SMB_MALLOC_P(JOB_INFO_1); @@ -8626,19 +8723,22 @@ static WERROR getjob_level_1(print_queue_struct **queue, int count, int snum, *needed += spoolss_size_job_info_1(info_1); - if (!alloc_buffer_size(buffer, *needed)) { - SAFE_FREE(info_1); - return WERR_INSUFFICIENT_BUFFER; + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; + } + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; } smb_io_job_info_1("", buffer, info_1, 0); +out: SAFE_FREE(info_1); - if (*needed > offered) - return WERR_INSUFFICIENT_BUFFER; - - return WERR_OK; + return result; } /**************************************************************************** @@ -8646,7 +8746,7 @@ static WERROR getjob_level_1(print_queue_struct **queue, int count, int snum, static WERROR getjob_level_2(print_queue_struct **queue, int count, int snum, NT_PRINTER_INFO_LEVEL *ntprinter, - uint32 jobid, NEW_BUFFER *buffer, uint32 offered, + uint32 jobid, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { int i = 0; @@ -8698,18 +8798,18 @@ static WERROR getjob_level_2(print_queue_struct **queue, int count, int snum, *needed += spoolss_size_job_info_2(info_2); - if (!alloc_buffer_size(buffer, *needed)) { + if (*needed > offered) { ret = WERR_INSUFFICIENT_BUFFER; goto done; } - smb_io_job_info_2("", buffer, info_2, 0); - - if (*needed > offered) { + if (!rpcbuf_alloc_size(buffer, *needed)) { ret = WERR_INSUFFICIENT_BUFFER; goto done; } + smb_io_job_info_2("", buffer, info_2, 0); + ret = WERR_OK; done: @@ -8729,7 +8829,7 @@ WERROR _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_ POLICY_HND *handle = &q_u->handle; uint32 jobid = q_u->jobid; uint32 level = q_u->level; - NEW_BUFFER *buffer = NULL; + RPC_BUFFER *buffer = NULL; uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; WERROR wstatus = WERR_OK; @@ -8740,8 +8840,11 @@ WERROR _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_ print_status_struct prt_status; /* that's an [in out] buffer */ - spoolss_move_buffer(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + + if ( q_u->buffer ) { + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + } DEBUG(5,("spoolss_getjob\n")); @@ -9307,13 +9410,14 @@ static void fill_printprocessordirectory_1(PRINTPROCESSOR_DIRECTORY_1 *info, cha static WERROR getprintprocessordirectory_level_1(UNISTR2 *name, UNISTR2 *environment, - NEW_BUFFER *buffer, + RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { pstring path; pstring long_archi; PRINTPROCESSOR_DIRECTORY_1 *info=NULL; + WERROR result = WERR_OK; unistr2_to_ascii(long_archi, environment, sizeof(long_archi)-1); @@ -9329,32 +9433,38 @@ static WERROR getprintprocessordirectory_level_1(UNISTR2 *name, *needed += spoolss_size_printprocessordirectory_info_1(info); - if (!alloc_buffer_size(buffer, *needed)) { - safe_free(info); - return WERR_INSUFFICIENT_BUFFER; + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; + } + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; } smb_io_printprocessordirectory_1("", buffer, info, 0); - safe_free(info); +out: + SAFE_FREE(info); - if (*needed > offered) - return WERR_INSUFFICIENT_BUFFER; - else - return WERR_OK; + return result; } WERROR _spoolss_getprintprocessordirectory(pipes_struct *p, SPOOL_Q_GETPRINTPROCESSORDIRECTORY *q_u, SPOOL_R_GETPRINTPROCESSORDIRECTORY *r_u) { uint32 level = q_u->level; - NEW_BUFFER *buffer = NULL; + RPC_BUFFER *buffer = NULL; uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; WERROR result; /* that's an [in out] buffer */ - spoolss_move_buffer(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + + if ( q_u->buffer ) { + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + } DEBUG(5,("_spoolss_getprintprocessordirectory\n")); -- cgit From d177f1bc8f0cb5ad91c9146871ba2e93eb2988d2 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 15 Mar 2005 20:12:51 +0000 Subject: r5806: * fix a couple more segvs in spoolss * comment out unused variable after jra's change to revert the 56bit des smb signing changes (This used to be commit 13ed08cd2a1097021cc44f4109859ba89db7df81) --- source3/rpc_server/srv_spoolss_nt.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 053290f80f..3c611be9ac 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -8752,30 +8752,25 @@ static WERROR getjob_level_2(print_queue_struct **queue, int count, int snum, int i = 0; BOOL found = False; JOB_INFO_2 *info_2; - WERROR ret; + WERROR result; DEVICEMODE *devmode = NULL; NT_DEVICEMODE *nt_devmode = NULL; - info_2=SMB_MALLOC_P(JOB_INFO_2); + if ( !(info_2=SMB_MALLOC_P(JOB_INFO_2)) ) + return WERR_NOMEM; ZERO_STRUCTP(info_2); - if (info_2 == NULL) { - ret = WERR_NOMEM; - goto done; - } - for ( i=0; i offered) { - ret = WERR_INSUFFICIENT_BUFFER; + result = WERR_INSUFFICIENT_BUFFER; goto done; } if (!rpcbuf_alloc_size(buffer, *needed)) { - ret = WERR_INSUFFICIENT_BUFFER; + result = WERR_NOMEM; goto done; } smb_io_job_info_2("", buffer, info_2, 0); - ret = WERR_OK; + result = WERR_OK; done: /* Cleanup allocated memory */ @@ -8818,7 +8813,7 @@ static WERROR getjob_level_2(print_queue_struct **queue, int count, int snum, free_job_info_2(info_2); /* Also frees devmode */ SAFE_FREE(info_2); - return ret; + return result; } /**************************************************************************** -- cgit From 5d1cb8e79edea9e8581d3c2c9dd297310cd9a98c Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 23 Mar 2005 23:26:33 +0000 Subject: r6014: rather large change set.... pulling back all recent rpc changes from trunk into 3.0. I've tested a compile and so don't think I've missed any files. But if so, just mail me and I'll clean backup in a couple of hours. Changes include \winreg, \eventlog, \svcctl, and general parse_misc.c updates. I am planning on bracketing the event code with an #ifdef ENABLE_EVENTLOG until I finish merging Marcin's changes (very soon). (This used to be commit 4e0ac63c36527cd8c52ef720cae17e84f67e7221) --- source3/rpc_server/srv_spoolss_nt.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 3c611be9ac..2e84a7b909 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1491,10 +1491,10 @@ static void convert_to_openprinterex(TALLOC_CTX *ctx, SPOOL_Q_OPEN_PRINTER_EX *q DEBUG(8,("convert_to_openprinterex\n")); - q_u_ex->printername_ptr = q_u->printername_ptr; - - if (q_u->printername_ptr) - copy_unistr2(&q_u_ex->printername, &q_u->printername); + if ( q_u->printername ) { + q_u_ex->printername = TALLOC_P( ctx, UNISTR2 ); + copy_unistr2(q_u_ex->printername, q_u->printername); + } copy_printer_default(ctx, &q_u_ex->printer_default, &q_u->printer_default); } @@ -1588,7 +1588,6 @@ WERROR _spoolss_open_printer(pipes_struct *p, SPOOL_Q_OPEN_PRINTER *q_u, SPOOL_R WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, SPOOL_R_OPEN_PRINTER_EX *r_u) { - UNISTR2 *printername = NULL; PRINTER_DEFAULT *printer_default = &q_u->printer_default; POLICY_HND *handle = &r_u->handle; @@ -1597,15 +1596,13 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, struct current_user user; Printer_entry *Printer=NULL; - if (q_u->printername_ptr != 0) - printername = &q_u->printername; - - if (printername == NULL) + if ( !q_u->printername ) return WERR_INVALID_PRINTER_NAME; /* some sanity check because you can open a printer or a print server */ /* aka: \\server\printer or \\server */ - unistr2_to_ascii(name, printername, sizeof(name)-1); + + unistr2_to_ascii(name, q_u->printername, sizeof(name)-1); DEBUGADD(3,("checking name: %s\n",name)); @@ -7595,7 +7592,7 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ WERROR _spoolss_addprinterex( pipes_struct *p, SPOOL_Q_ADDPRINTEREX *q_u, SPOOL_R_ADDPRINTEREX *r_u) { - UNISTR2 *uni_srv_name = &q_u->server_name; + UNISTR2 *uni_srv_name = q_u->server_name; uint32 level = q_u->level; SPOOL_PRINTER_INFO_LEVEL *info = &q_u->info; DEVICEMODE *devmode = q_u->devmode_ctr.devmode; -- cgit From 978ca8486031e43754a3c23757f361bf3a85f335 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Wed, 6 Apr 2005 16:28:04 +0000 Subject: r6225: get rid of warnings from my compiler about nested externs (This used to be commit efea76ac71412f8622cd233912309e91b9ea52da) --- source3/rpc_server/srv_spoolss_nt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 2e84a7b909..0f33fd7dec 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -28,6 +28,8 @@ #include "includes.h" +extern userdom_struct current_user_info; + #undef DBGC_CLASS #define DBGC_CLASS DBGC_RPC_SRV @@ -6027,7 +6029,6 @@ static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) static BOOL add_printer_hook(NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer) { - extern userdom_struct current_user_info; char *cmd = lp_addprinter_cmd(); char **qlines; pstring command; -- cgit From 4f3c2d4424823df26e56c8ecbfea54d743469304 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 9 May 2005 12:52:57 +0000 Subject: r6679: BUG 2684: abartlett's patch for check the per service hosts allow/deny on printers when connecting via MS-RPC (This used to be commit 80da9ca3869380541728cb38df93d012eb20c307) --- source3/rpc_server/srv_spoolss_nt.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 0f33fd7dec..7daf1630fe 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1730,6 +1730,11 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, /* check smb.conf parameters and the the sec_desc */ + if ( !check_access(smbd_server_fd(), lp_hostsallow(snum), lp_hostsdeny(snum)) ) { + DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n")); + return WERR_ACCESS_DENIED; + } + if (!user_ok(uidtoname(user.uid), snum, user.groups, user.ngroups) || !print_access_check(&user, snum, printer_default->access_required)) { DEBUG(3, ("access DENIED for printer open\n")); close_printer_handle(p, handle); -- cgit From fe0ce8dd8e18de6110404661f26db7a66ebac5ad Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 18 May 2005 18:02:15 +0000 Subject: r6890: Refactor printing interface to take offset into job. Fixes bug where large print jobs can have out-of-order offsets. Bug found by Arcady Chernyak Jeremy. (This used to be commit 482f7e0e3706098b71aa0b31a134994acb1e9fcf) --- source3/rpc_server/srv_spoolss_nt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 7daf1630fe..b7091b2ade 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -5798,8 +5798,9 @@ WERROR _spoolss_writeprinter(pipes_struct *p, SPOOL_Q_WRITEPRINTER *q_u, SPOOL_R if (!get_printer_snum(p, handle, &snum)) return WERR_BADFID; - (*buffer_written) = print_job_write(snum, Printer->jobid, (char *)buffer, buffer_size); - if (*buffer_written == -1) { + (*buffer_written) = (uint32)print_job_write(snum, Printer->jobid, (const char *)buffer, + (SMB_OFF_T)-1, (size_t)buffer_size); + if (*buffer_written == (uint32)-1) { r_u->buffer_written = 0; if (errno == ENOSPC) return WERR_NO_SPOOL_SPACE; -- cgit From f0c650a38286c07b9f3e83139c15bfbadc70ad5f Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 23 May 2005 16:25:31 +0000 Subject: r6942: * merging the registry changes back to the 3.0 tree * removing the testprns tool (This used to be commit 81ffb0dbbbd244623507880c323a3c37e2b8dc4d) --- source3/rpc_server/srv_spoolss_nt.c | 103 ++++++++++++++---------------------- 1 file changed, 40 insertions(+), 63 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index b7091b2ade..2fee1972ab 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2353,9 +2353,8 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint *type = REG_BINARY; *needed = 0x114; - if((*data = (uint8 *)TALLOC(ctx, *needed)) == NULL) + if ( !(*data = TALLOC_ZERO_ARRAY(ctx, uint8, *needed)) ) return WERR_NOMEM; - ZERO_STRUCTP( *data ); SIVAL(*data, 0, *needed); /* size */ SIVAL(*data, 4, 5); /* Windows 2000 == 5.0 */ @@ -7249,16 +7248,11 @@ static void fill_port_2(PORT_INFO_2 *port, const char *name) } /**************************************************************************** - enumports level 1. + wrapper around the enumer ports command ****************************************************************************/ -static WERROR enumports_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +WERROR enumports_hook( int *count, char ***lines ) { - PORT_INFO_1 *ports=NULL; - int i=0; - WERROR result = WERR_OK; - - if (*lp_enumports_cmd()) { char *cmd = lp_enumports_cmd(); char **qlines; pstring command; @@ -7266,6 +7260,18 @@ static WERROR enumports_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *need int ret; int fd; + + /* if no hook then just fill in the default port */ + + if ( !*cmd ) { + qlines = SMB_MALLOC_ARRAY( char*, 2 ); + qlines[0] = SMB_STRDUP( SAMBA_PRINTER_PORT_NAME ); + qlines[1] = NULL; + numlines = 1; + } + else { + /* we have a valid enumport command */ + slprintf(command, sizeof(command)-1, "%s \"%d\"", cmd, 1); DEBUG(10,("Running [%s]\n", command)); @@ -7274,7 +7280,7 @@ static WERROR enumports_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *need if (ret != 0) { if (fd != -1) close(fd); - /* Is this the best error to return here? */ + return WERR_ACCESS_DENIED; } @@ -7282,6 +7288,28 @@ static WERROR enumports_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *need qlines = fd_lines_load(fd, &numlines); DEBUGADD(10,("Lines returned = [%d]\n", numlines)); close(fd); + } + + *count = numlines; + *lines = qlines; + + return WERR_OK; +} + +/**************************************************************************** + enumports level 1. +****************************************************************************/ + +static WERROR enumports_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +{ + PORT_INFO_1 *ports=NULL; + int i=0; + WERROR result = WERR_OK; + char **qlines; + int numlines; + + if ( !W_ERROR_IS_OK(result = enumports_hook( &numlines, &qlines )) ) + return result; if(numlines) { if((ports=SMB_MALLOC_ARRAY( PORT_INFO_1, numlines )) == NULL) { @@ -7301,17 +7329,6 @@ static WERROR enumports_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *need *returned = numlines; - } else { - *returned = 1; /* Sole Samba port returned. */ - - if((ports=SMB_MALLOC_P(PORT_INFO_1)) == NULL) - return WERR_NOMEM; - - DEBUG(10,("enumports_level_1: port name %s\n", SAMBA_PRINTER_PORT_NAME)); - - fill_port_1(&ports[0], SAMBA_PRINTER_PORT_NAME); - } - /* check the required size. */ for (i=0; i<*returned; i++) { DEBUGADD(6,("adding port [%d]'s size\n", i)); @@ -7352,40 +7369,12 @@ static WERROR enumports_level_2(RPC_BUFFER *buffer, uint32 offered, uint32 *need PORT_INFO_2 *ports=NULL; int i=0; WERROR result = WERR_OK; - - if (*lp_enumports_cmd()) { - char *cmd = lp_enumports_cmd(); - char *path; char **qlines; - pstring tmp_file; - pstring command; int numlines; - int ret; - int fd; - - if (*lp_pathname(lp_servicenumber(PRINTERS_NAME))) - path = lp_pathname(lp_servicenumber(PRINTERS_NAME)); - else - path = lp_lockdir(); - - slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%u.", path, (unsigned int)sys_getpid()); - slprintf(command, sizeof(command)-1, "%s \"%d\"", cmd, 2); - unlink(tmp_file); - DEBUG(10,("Running [%s > %s]\n", command,tmp_file)); - ret = smbrun(command, &fd); - DEBUGADD(10,("returned [%d]\n", ret)); - if (ret != 0) { - if (fd != -1) - close(fd); - /* Is this the best error to return here? */ - return WERR_ACCESS_DENIED; - } + if ( !W_ERROR_IS_OK(result = enumports_hook( &numlines, &qlines )) ) + return result; - numlines = 0; - qlines = fd_lines_load(fd, &numlines); - DEBUGADD(10,("Lines returned = [%d]\n", numlines)); - close(fd); if(numlines) { if((ports=SMB_MALLOC_ARRAY( PORT_INFO_2, numlines)) == NULL) { @@ -7403,18 +7392,6 @@ static WERROR enumports_level_2(RPC_BUFFER *buffer, uint32 offered, uint32 *need *returned = numlines; - } else { - - *returned = 1; - - if((ports=SMB_MALLOC_P(PORT_INFO_2)) == NULL) - return WERR_NOMEM; - - DEBUG(10,("enumports_level_2: port name %s\n", SAMBA_PRINTER_PORT_NAME)); - - fill_port_2(&ports[0], SAMBA_PRINTER_PORT_NAME); - } - /* check the required size. */ for (i=0; i<*returned; i++) { DEBUGADD(6,("adding port [%d]'s size\n", i)); -- cgit From f24d88cf9da46680d52b42b92bd484e7b09ce99b Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 31 May 2005 13:46:45 +0000 Subject: r7139: trying to reduce the number of diffs between trunk and 3.0; changing version to 3.0.20pre1 (This used to be commit 9727d05241574042dd3aa8844ae5c701d22e2da1) --- source3/rpc_server/srv_spoolss_nt.c | 77 +++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 38 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 2fee1972ab..39c294fa45 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2355,7 +2355,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint if ( !(*data = TALLOC_ZERO_ARRAY(ctx, uint8, *needed)) ) return WERR_NOMEM; - + SIVAL(*data, 0, *needed); /* size */ SIVAL(*data, 4, 5); /* Windows 2000 == 5.0 */ SIVAL(*data, 8, 0); @@ -7247,18 +7247,19 @@ static void fill_port_2(PORT_INFO_2 *port, const char *name) port->reserved=0x0; } + /**************************************************************************** wrapper around the enumer ports command ****************************************************************************/ WERROR enumports_hook( int *count, char ***lines ) { - char *cmd = lp_enumports_cmd(); - char **qlines; - pstring command; - int numlines; - int ret; - int fd; + char *cmd = lp_enumports_cmd(); + char **qlines; + pstring command; + int numlines; + int ret; + int fd; /* if no hook then just fill in the default port */ @@ -7310,24 +7311,24 @@ static WERROR enumports_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *need if ( !W_ERROR_IS_OK(result = enumports_hook( &numlines, &qlines )) ) return result; - - if(numlines) { - if((ports=SMB_MALLOC_ARRAY( PORT_INFO_1, numlines )) == NULL) { - DEBUG(10,("Returning WERR_NOMEM [%s]\n", - dos_errstr(WERR_NOMEM))); - file_lines_free(qlines); - return WERR_NOMEM; - } - - for (i=0; i Date: Wed, 15 Jun 2005 17:03:34 +0000 Subject: r7614: convert move_driver_to_download_area() to return WERROR in order to provide better error messages to clients when a AddPrinterDriver[Ex]() call fails (This used to be commit c98e17446afffc4b12f1a31f6e5cce517fc0a95b) --- source3/rpc_server/srv_spoolss_nt.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 39c294fa45..972f6e9730 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -7628,9 +7628,7 @@ WERROR _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u, goto done; DEBUG(5,("Moving driver to final destination\n")); - if(!move_driver_to_download_area(driver, level, &user, &err)) { - if (W_ERROR_IS_OK(err)) - err = WERR_ACCESS_DENIED; + if( !W_ERROR_IS_OK(err = move_driver_to_download_area(driver, level, &user, &err)) ) { goto done; } -- cgit From 19ca97a70f6b7b41d251eaa76e4d3c980c6eedff Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 24 Jun 2005 20:25:18 +0000 Subject: r7882: Looks like a large patch - but what it actually does is make Samba safe for using our headers and linking with C++ modules. Stops us from using C++ reserved keywords in our code. Jeremy (This used to be commit 9506b8e145982b1160a2f0aee5c9b7a54980940a) --- source3/rpc_server/srv_spoolss_nt.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 972f6e9730..e05bfa1eaa 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1445,7 +1445,7 @@ static DEVICEMODE* dup_devicemode(TALLOC_CTX *ctx, DEVICEMODE *devmode) return NULL; } - d->private = TALLOC_MEMDUP(ctx, devmode->private, devmode->driverextra); + d->dev_private = TALLOC_MEMDUP(ctx, devmode->dev_private, devmode->driverextra); return d; } @@ -1885,12 +1885,12 @@ BOOL convert_devicemode(const char *printername, const DEVICEMODE *devmode, * has a new one. JRA. */ - if ((devmode->driverextra != 0) && (devmode->private != NULL)) { - SAFE_FREE(nt_devmode->private); + if ((devmode->driverextra != 0) && (devmode->dev_private != NULL)) { + SAFE_FREE(nt_devmode->nt_dev_private); nt_devmode->driverextra=devmode->driverextra; - if((nt_devmode->private=SMB_MALLOC_ARRAY(uint8, nt_devmode->driverextra)) == NULL) + if((nt_devmode->nt_dev_private=SMB_MALLOC_ARRAY(uint8, nt_devmode->driverextra)) == NULL) return False; - memcpy(nt_devmode->private, devmode->private, nt_devmode->driverextra); + memcpy(nt_devmode->nt_dev_private, devmode->dev_private, nt_devmode->driverextra); } *pp_nt_devmode = nt_devmode; @@ -4089,7 +4089,7 @@ static void free_dev_mode(DEVICEMODE *dev) if (dev == NULL) return; - SAFE_FREE(dev->private); + SAFE_FREE(dev->dev_private); SAFE_FREE(dev); } @@ -4132,8 +4132,8 @@ static BOOL convert_nt_devicemode( DEVICEMODE *devmode, NT_DEVICEMODE *ntdevmode devmode->mediatype = ntdevmode->mediatype; devmode->dithertype = ntdevmode->dithertype; - if (ntdevmode->private != NULL) { - if ((devmode->private=(uint8 *)memdup(ntdevmode->private, ntdevmode->driverextra)) == NULL) + if (ntdevmode->nt_dev_private != NULL) { + if ((devmode->dev_private=(uint8 *)memdup(ntdevmode->nt_dev_private, ntdevmode->driverextra)) == NULL) return False; } -- cgit From 270b90e25f2ec5fcb1283588a9e605b7228e0e41 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 29 Jun 2005 16:35:32 +0000 Subject: r7995: * privileges are local except when they're *not* printmig.exe assumes that the LUID of the SeBackupPrivlege on the target server matches the LUID of the privilege on the local client. Even though an LUID is never guaranteed to be the same across reboots. How *awful*! My cat could write better code! (more on my cat later....) * Set the privelege LUID in the global PRIVS[] array * Rename RegCreateKey() to RegCreateKeyEx() to better match MSDN * Rename the unknown field in RegCreateKeyEx() to disposition (guess according to MSDN) * Add the capability to define REG_TDB_ONLY for using the reg_db.c functions and stress the RegXXX() rpc functions. (This used to be commit 0d6352da4800aabc04dfd7c65a6afe6af7cd2d4b) --- source3/rpc_server/srv_spoolss_nt.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index e05bfa1eaa..12e8e2bd41 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2211,7 +2211,8 @@ static WERROR get_printer_dataex( TALLOC_CTX *ctx, NT_PRINTER_INFO_LEVEL *printe uint32 *needed, uint32 in_size ) { REGISTRY_VALUE *val; - int size, data_len; + uint32 size; + int data_len; if ( !(val = get_printer_data( printer->info_2, key, value)) ) return WERR_BADFILE; @@ -8030,7 +8031,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S result = WERR_NOMEM; goto done; } - data_len = (size_t)regval_size(val); + data_len = regval_size(val); memcpy( *data_out, regval_data_p(val), data_len ); *out_data_len = data_len; } @@ -9250,7 +9251,7 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ int i; REGISTRY_VALUE *val; char *value_name; - int data_len; + uint32 data_len; DEBUG(4,("_spoolss_enumprinterdataex\n")); -- cgit From c296f858ef61acd6c749db768670453f436f78f2 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sat, 2 Jul 2005 01:23:21 +0000 Subject: r8066: * had to modify the printer data storage slightly in ntprinters.tdb when packing values. It is a compatible change though and will not require a tdb version upgrade * Can successfully create new printer subkeys via winreg that are immediately available via spoolss calls. Still cannot delete keys yet though. That comes next. (This used to be commit 00bce2b3bb78a44842a258b1737076281297d247) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 12e8e2bd41..19ef3700e6 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -583,7 +583,7 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) DEBUGADD(10, ("printername: %s\n", printername)); - free_a_printer( &printer, 2); + free_a_printer( &printer, 2); } if ( !found ) { -- cgit From 18609ce1af72802accd1e5e85689db69e8b0c914 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 11 Jul 2005 16:55:10 +0000 Subject: r8322: * get RegSetValue() working for printer subkey values (not immediate values below the key yet. (This used to be commit a872ea5f0e29f7b585574a56b52a5eb44cb92278) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 19ef3700e6..0329471d49 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2261,7 +2261,7 @@ static WERROR delete_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char Internal routine for storing printerdata ***************************************************************************/ -static WERROR set_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char *key, const char *value, +WERROR set_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char *key, const char *value, uint32 type, uint8 *data, int real_len ) { delete_printer_data( printer->info_2, key, value ); -- cgit From e574081ad93ec5f5eb121436a889f64294fa290d Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 11 Jul 2005 18:27:22 +0000 Subject: r8324: * initial cut at creating printers via the registry API Need to add delete_key support (This used to be commit 9a27f7181adca10f60c47d342a51dec34321e12b) --- source3/rpc_server/srv_spoolss_nt.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 0329471d49..b5dd459462 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6033,7 +6033,7 @@ static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) /**************************************************************************** ****************************************************************************/ -static BOOL add_printer_hook(NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer) +BOOL add_printer_hook(NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer) { char *cmd = lp_addprinter_cmd(); char **qlines; @@ -6043,7 +6043,7 @@ static BOOL add_printer_hook(NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printe int fd; fstring remote_machine = "%m"; SE_PRIV se_printop = SE_PRINT_OPERATOR; - BOOL is_print_op; + BOOL is_print_op = False; standard_sub_basic(current_user_info.smb_name, remote_machine,sizeof(remote_machine)); @@ -6052,7 +6052,8 @@ static BOOL add_printer_hook(NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printe printer->info_2->portname, printer->info_2->drivername, printer->info_2->location, printer->info_2->comment, remote_machine); - is_print_op = user_has_privileges( token, &se_printop ); + if ( token ) + is_print_op = user_has_privileges( token, &se_printop ); DEBUG(10,("Running [%s]\n", command)); -- cgit From f2ff8bed26cc8b0f2fffbc41a605a8f95163a382 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 11 Jul 2005 18:59:54 +0000 Subject: r8326: factor out the delete printer code to a delete_printer_hook() for reuse (This used to be commit 0689851a90fbd91ff30f6e2afc05d141f6ce082d) --- source3/rpc_server/srv_spoolss_nt.c | 109 ++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 56 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index b5dd459462..5fbb6d91b0 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -345,6 +345,58 @@ static BOOL close_printer_handle(pipes_struct *p, POLICY_HND *hnd) return True; } +/**************************************************************************** + Delete a printer given a handle. +****************************************************************************/ +WERROR delete_printer_hook( NT_USER_TOKEN *token, const char *sharename ) +{ + char *cmd = lp_deleteprinter_cmd(); + pstring command; + int ret; + SE_PRIV se_printop = SE_PRINT_OPERATOR; + BOOL is_print_op = False; + + /* can't fail if we don't try */ + + if ( !*cmd ) + return WERR_OK; + + pstr_sprintf(command, "%s \"%s\"", cmd, sharename); + + if ( token ) + is_print_op = user_has_privileges( token, &se_printop ); + + DEBUG(10,("Running [%s]\n", command)); + + /********** BEGIN SePrintOperatorPrivlege BLOCK **********/ + + if ( is_print_op ) + become_root(); + + if ( (ret = smbrun(command, NULL)) == 0 ) { + /* Tell everyone we updated smb.conf. */ + message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL); + } + + if ( is_print_op ) + unbecome_root(); + + /********** END SePrintOperatorPrivlege BLOCK **********/ + + DEBUGADD(10,("returned [%d]\n", ret)); + + if (ret != 0) + return WERR_BADFID; /* What to return here? */ + + /* go ahead and re-read the services immediately */ + reload_services( False ); + + if ( lp_servicenumber( sharename ) < 0 ) + return WERR_ACCESS_DENIED; + + return WERR_OK; +} + /**************************************************************************** Delete a printer given a handle. ****************************************************************************/ @@ -369,18 +421,6 @@ static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) DEBUG(3, ("delete_printer_handle: denied by handle\n")); return WERR_ACCESS_DENIED; } - -#if 0 - /* Check calling user has permission to delete printer. Note that - since we set the snum parameter to -1 only administrators can - delete the printer. This stops people with the Full Control - permission from deleting the printer. */ - - if (!print_access_check(NULL, -1, PRINTER_ACCESS_ADMINISTER)) { - DEBUG(3, ("printer delete denied by security descriptor\n")); - return WERR_ACCESS_DENIED; - } -#endif /* this does not need a become root since the access check has been done on the handle already */ @@ -390,50 +430,7 @@ static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) return WERR_BADFID; } - /* the delete printer script shoudl be run as root if the user has perms */ - - if (*lp_deleteprinter_cmd()) { - - char *cmd = lp_deleteprinter_cmd(); - pstring command; - int ret; - SE_PRIV se_printop = SE_PRINT_OPERATOR; - BOOL is_print_op; - - pstr_sprintf(command, "%s \"%s\"", cmd, Printer->sharename); - - is_print_op = user_has_privileges( p->pipe_user.nt_user_token, &se_printop ); - - DEBUG(10,("Running [%s]\n", command)); - - /********** BEGIN SePrintOperatorPrivlege BLOCK **********/ - - if ( is_print_op ) - become_root(); - - if ( (ret = smbrun(command, NULL)) == 0 ) { - /* Tell everyone we updated smb.conf. */ - message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL); - } - - if ( is_print_op ) - unbecome_root(); - - /********** END SePrintOperatorPrivlege BLOCK **********/ - - DEBUGADD(10,("returned [%d]\n", ret)); - - if (ret != 0) - return WERR_BADFID; /* What to return here? */ - - /* go ahead and re-read the services immediately */ - reload_services( False ); - - if ( lp_servicenumber( Printer->sharename ) < 0 ) - return WERR_ACCESS_DENIED; - } - - return WERR_OK; + return delete_printer_hook( p->pipe_user.nt_user_token, Printer->sharename ); } /**************************************************************************** -- cgit From 6fe54515435e351ba958886cb9a7175c436ef88d Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 15 Jul 2005 14:26:11 +0000 Subject: r8501: * disable printer handle object cache (was mostly used for NT4 clients enumerating printer data on slow CPUs) * fix pinter and secdesc record upgrade to normalize the key (rev'd printer tdb version) * fixed problem that was normalizing the printername name field in general, this should fix the issues upgrading print servers from 3.0.14a to 3.0.20 (This used to be commit d07179de2f2a6eb1d13d0e25ac10de1a21475559) --- source3/rpc_server/srv_spoolss_nt.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 5fbb6d91b0..66804028e1 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -274,6 +274,7 @@ static Printer_entry *find_printer_index_by_hnd(pipes_struct *p, POLICY_HND *hnd return find_printer; } +#ifdef ENABLE_PRINT_HND_OBJECT_CACHE /**************************************************************************** look for a printer object cached on an open printer handle ****************************************************************************/ @@ -327,6 +328,8 @@ void invalidate_printer_hnd_cache( char *printername ) return; } +#endif + /**************************************************************************** Close printer index by handle. ****************************************************************************/ @@ -1213,6 +1216,7 @@ static void receive_notify2_message_list(int msg_type, pid_t src, void *msg, siz return; } +#ifdef ENABLE_PRINT_HND_OBJECT_CACHE /******************************************************************** callback to MSG_PRINTER_CHANGED. When a printer is changed by one smbd, all of processes must clear their printer cache immediately. @@ -1228,6 +1232,7 @@ void receive_printer_mod_msg(int msg_type, pid_t src, void *buf, size_t len) invalidate_printer_hnd_cache( printername ); } +#endif /******************************************************************** Send a message to ourself about new driver being installed -- cgit From ae64b2f2aad54833fb29911c50406f784bd2d8b6 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 19 Jul 2005 21:41:41 +0000 Subject: r8617: Be very explicit if addprinterex is called that the "addprinter command" must be defined in smb.conf. Jeremy. (This used to be commit 86f8368c997f0eece20724a0a7158832c66da9f7) --- source3/rpc_server/srv_spoolss_nt.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 66804028e1..7498a449c3 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -7492,7 +7492,7 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ /* check to see if the printer already exists */ if ((snum = print_queue_snum(printer->info_2->sharename)) != -1) { - DEBUG(5, ("_spoolss_addprinterex: Attempted to add a printer named [%s] when one already existed!\n", + DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n", printer->info_2->sharename)); free_a_printer(&printer, 2); return WERR_PRINTER_ALREADY_EXISTS; @@ -7505,7 +7505,12 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ if ( !add_printer_hook(p->pipe_user.nt_user_token, printer) ) { free_a_printer(&printer,2); return WERR_ACCESS_DENIED; - } + } + } else { + DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no" + "smb.conf parameter \"addprinter command\" is defined. This" + "parameter must exist for this call to succeed\n", + printer->info_2->sharename )); } /* use our primary netbios name since get_a_printer() will convert -- cgit From 57939971b42b8f0a993e08e92480223b4f412907 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 2 Aug 2005 07:26:29 +0000 Subject: r8916: should fix the valgrind invalid read of size 1 onthe GetPrinterData("OSVersion") abartlet saw when browsing from Vista client. (This used to be commit b527b86ae80ebc0b6e7318ed31d44be985aa9af0) --- source3/rpc_server/srv_spoolss_nt.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 7498a449c3..bec67daa3e 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2283,7 +2283,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint if (!StrCaseCmp(value, "W3SvcInstalled")) { *type = REG_DWORD; - if((*data = (uint8 *)TALLOC_ZERO(ctx, 4*sizeof(uint8) )) == NULL) + if ( !(*data = TALLOC_ARRAY(ctx, uint8, sizeof(uint32) )) ) return WERR_NOMEM; *needed = 0x4; return WERR_OK; @@ -2291,7 +2291,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint if (!StrCaseCmp(value, "BeepEnabled")) { *type = REG_DWORD; - if((*data = (uint8 *)TALLOC(ctx, 4*sizeof(uint8) )) == NULL) + if ( !(*data = TALLOC_ARRAY(ctx, uint8, sizeof(uint32) )) ) return WERR_NOMEM; SIVAL(*data, 0, 0x00); *needed = 0x4; @@ -2300,7 +2300,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint if (!StrCaseCmp(value, "EventLog")) { *type = REG_DWORD; - if((*data = (uint8 *)TALLOC(ctx, 4 )) == NULL) + if ( !(*data = TALLOC_ARRAY(ctx, uint8, sizeof(uint32) )) ) return WERR_NOMEM; /* formally was 0x1b */ SIVAL(*data, 0, 0x0); @@ -2310,7 +2310,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint if (!StrCaseCmp(value, "NetPopup")) { *type = REG_DWORD; - if((*data = (uint8 *)TALLOC(ctx, 4 )) == NULL) + if ( !(*data = TALLOC_ARRAY(ctx, uint8, sizeof(uint32) )) ) return WERR_NOMEM; SIVAL(*data, 0, 0x00); *needed = 0x4; @@ -2319,7 +2319,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint if (!StrCaseCmp(value, "MajorVersion")) { *type = REG_DWORD; - if((*data = (uint8 *)TALLOC(ctx, 4 )) == NULL) + if ( !(*data = TALLOC_ARRAY(ctx, uint8, sizeof(uint32) )) ) return WERR_NOMEM; /* Windows NT 4.0 seems to not allow uploading of drivers @@ -2338,7 +2338,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint if (!StrCaseCmp(value, "MinorVersion")) { *type = REG_DWORD; - if((*data = (uint8 *)TALLOC(ctx, 4 )) == NULL) + if ( !(*data = TALLOC_ARRAY(ctx, uint8, sizeof(uint32) )) ) return WERR_NOMEM; SIVAL(*data, 0, 0); *needed = 0x4; @@ -2356,7 +2356,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint *type = REG_BINARY; *needed = 0x114; - if ( !(*data = TALLOC_ZERO_ARRAY(ctx, uint8, *needed)) ) + if ( !(*data = TALLOC_ZERO_ARRAY(ctx, uint8, (*needed > in_size) ? *needed:in_size )) ) return WERR_NOMEM; SIVAL(*data, 0, *needed); /* size */ @@ -2402,7 +2402,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint if (!StrCaseCmp(value, "DsPresent")) { *type = REG_DWORD; - if((*data = (uint8 *)TALLOC(ctx, 4 )) == NULL) + if ( !(*data = TALLOC_ARRAY(ctx, uint8, sizeof(uint32) )) ) return WERR_NOMEM; /* only show the publish check box if we are a -- cgit From fdc2ab72f7a524b43c7fe03e17cf4817fc3730a2 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 3 Aug 2005 22:07:57 +0000 Subject: r9021: Fix smbd-crash bug in openprinter (found by samba4 smbtorture RPC-SPOOLSS). Guenther (This used to be commit 06bfe789d54a12dfa3c46e9777f96ff7e162a9db) --- source3/rpc_server/srv_spoolss_nt.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index bec67daa3e..692dacf159 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1488,19 +1488,23 @@ static void copy_printer_default(TALLOC_CTX *ctx, PRINTER_DEFAULT *new_def, PRIN * SPOOL_Q_OPEN_PRINTER_EX structure ********************************************************************/ -static void convert_to_openprinterex(TALLOC_CTX *ctx, SPOOL_Q_OPEN_PRINTER_EX *q_u_ex, SPOOL_Q_OPEN_PRINTER *q_u) +static WERROR convert_to_openprinterex(TALLOC_CTX *ctx, SPOOL_Q_OPEN_PRINTER_EX *q_u_ex, SPOOL_Q_OPEN_PRINTER *q_u) { if (!q_u_ex || !q_u) - return; + return WERR_OK; DEBUG(8,("convert_to_openprinterex\n")); if ( q_u->printername ) { - q_u_ex->printername = TALLOC_P( ctx, UNISTR2 ); + q_u_ex->printername = TALLOC_ZERO_P( ctx, UNISTR2 ); + if (q_u_ex->printername == NULL) + return WERR_NOMEM; copy_unistr2(q_u_ex->printername, q_u->printername); } copy_printer_default(ctx, &q_u_ex->printer_default, &q_u->printer_default); + + return WERR_OK; } /******************************************************************** @@ -1522,7 +1526,9 @@ WERROR _spoolss_open_printer(pipes_struct *p, SPOOL_Q_OPEN_PRINTER *q_u, SPOOL_R /* convert the OpenPrinter() call to OpenPrinterEx() */ - convert_to_openprinterex(p->mem_ctx, &q_u_ex, q_u); + r_u_ex.status = convert_to_openprinterex(p->mem_ctx, &q_u_ex, q_u); + if (!W_ERROR_IS_OK(r_u_ex.status)) + return r_u_ex.status; r_u_ex.status = _spoolss_open_printer_ex(p, &q_u_ex, &r_u_ex); -- cgit From d04c1efd0ff130acbf17a0167a878cf27d9bdec5 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 12 Aug 2005 16:00:54 +0000 Subject: r9264: fix valgrind invalid write error in enumprinterdata() (This used to be commit bfebbc86fc0f90e580888da25006d8e5e50b6304) --- source3/rpc_server/srv_spoolss_nt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 692dacf159..5391ac5f41 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -8040,13 +8040,14 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S /* data - counted in bytes */ *out_max_data_len = in_data_len; - if ( (*data_out = (uint8 *)TALLOC_ZERO(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) + if ( in_data_len && (*data_out = (uint8 *)TALLOC_ZERO(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) { result = WERR_NOMEM; goto done; } data_len = regval_size(val); - memcpy( *data_out, regval_data_p(val), data_len ); + if ( *data_out ) + memcpy( *data_out, regval_data_p(val), data_len ); *out_data_len = data_len; } -- cgit From 44707ad2e00a91f459e80efbe8f362b5853b0a62 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 29 Aug 2005 14:55:40 +0000 Subject: r9739: conver the reg_objects (REGSUBKEY_CTR & REGVAL_CTR) to use the new talloc() features: Note that the REGSUB_CTR and REGVAL_CTR objects *must* be talloc()'d since the methods use the object pointer as the talloc context for internal private data. There is no longer a regXXX_ctr_intit() and regXXX_ctr_destroy() pair of functions. Simply TALLOC_ZERO_P() and TALLOC_FREE() the object. Also had to convert the printer_info_2->NT_PRINTER_DATA field to be talloc()'d as well. This is just a stop on the road to cleaning up the printer memory management. (This used to be commit ef721333ab9639cb5346067497e99fbd0d4425dd) --- source3/rpc_server/srv_spoolss_nt.c | 167 ++++++++---------------------------- 1 file changed, 38 insertions(+), 129 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 5391ac5f41..ee35b5853f 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -274,62 +274,6 @@ static Printer_entry *find_printer_index_by_hnd(pipes_struct *p, POLICY_HND *hnd return find_printer; } -#ifdef ENABLE_PRINT_HND_OBJECT_CACHE -/**************************************************************************** - look for a printer object cached on an open printer handle -****************************************************************************/ - -WERROR find_printer_in_print_hnd_cache( TALLOC_CTX *ctx, NT_PRINTER_INFO_LEVEL_2 **info2, - const char *servername, const char *printername ) -{ - Printer_entry *p; - - DEBUG(10,("find_printer_in_print_hnd_cache: printer [\\\\%s\\%s]\n", - servername, printername)); - - for ( p=printers_list; p; p=p->next ) - { - if ( p->printer_type==PRINTER_HANDLE_IS_PRINTER - && p->printer_info - && strequal( p->sharename, printername ) - && strequal( p->servername, servername ) ) - { - DEBUG(10,("Found printer\n")); - *info2 = dup_printer_2( ctx, p->printer_info->info_2 ); - if ( *info2 ) - return WERR_OK; - } - } - - return WERR_INVALID_PRINTER_NAME; -} - -/**************************************************************************** - destroy any cached printer_info_2 structures on open handles -****************************************************************************/ - -void invalidate_printer_hnd_cache( char *printername ) -{ - Printer_entry *p; - - DEBUG(10,("invalidate_printer_hnd_cache: printer [%s]\n", printername)); - - for ( p=printers_list; p; p=p->next ) - { - if ( p->printer_type==PRINTER_HANDLE_IS_PRINTER - && p->printer_info - && StrCaseCmp(p->sharename, printername)==0) - { - DEBUG(10,("invalidating printer_info cache for handl:\n")); - free_a_printer( &p->printer_info, 2 ); - p->printer_info = NULL; - } - } - - return; -} -#endif - /**************************************************************************** Close printer index by handle. ****************************************************************************/ @@ -1216,24 +1160,6 @@ static void receive_notify2_message_list(int msg_type, pid_t src, void *msg, siz return; } -#ifdef ENABLE_PRINT_HND_OBJECT_CACHE -/******************************************************************** - callback to MSG_PRINTER_CHANGED. When a printer is changed by - one smbd, all of processes must clear their printer cache immediately. - ********************************************************************/ - -void receive_printer_mod_msg(int msg_type, pid_t src, void *buf, size_t len) -{ - fstring printername; - - fstrcpy( printername, buf ); - - DEBUG(10,("receive_printer_mod_msg: Printer change [%s]\n", printername )); - - invalidate_printer_hnd_cache( printername ); -} -#endif - /******************************************************************** Send a message to ourself about new driver being installed so we can upgrade the information for each printer bound to this @@ -1804,7 +1730,10 @@ static BOOL convert_printer_info(const SPOOL_PRINTER_INFO_LEVEL *uni, switch (level) { case 2: - ret = uni_2_asc_printer_info_2(uni->info_2, &printer->info_2); + /* printer->info_2 is already a valid printer */ + ret = uni_2_asc_printer_info_2(uni->info_2, printer->info_2); + printer->info_2->setuptime = time(NULL); + break; default: break; @@ -2272,8 +2201,8 @@ static WERROR delete_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char WERROR set_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char *key, const char *value, uint32 type, uint8 *data, int real_len ) { - delete_printer_data( printer->info_2, key, value ); - + /* the registry objects enforce uniqueness based on value name */ + return add_printer_data( printer->info_2, key, value, type, data, real_len ); } @@ -4234,22 +4163,19 @@ static BOOL construct_printer_info_2(Printer_entry *print_hnd, PRINTER_INFO_2 *p printer->cjobs = count; /* jobs */ printer->averageppm = ntprinter->info_2->averageppm; /* average pages per minute */ - if((printer->devmode = construct_dev_mode(snum)) == NULL) { + if ( !(printer->devmode = construct_dev_mode(snum)) ) DEBUG(8, ("Returning NULL Devicemode!\n")); - } - if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->len != 0) { - /* steal the printer info sec_desc structure. [badly done]. */ - printer->secdesc = ntprinter->info_2->secdesc_buf->sec; - ntprinter->info_2->secdesc_buf->sec = NULL; /* Stolen memory. */ - ntprinter->info_2->secdesc_buf->len = 0; /* Stolen memory. */ - ntprinter->info_2->secdesc_buf->max_len = 0; /* Stolen memory. */ - } - else { - printer->secdesc = NULL; + printer->secdesc = NULL; + + if ( ntprinter->info_2->secdesc_buf + && ntprinter->info_2->secdesc_buf->len != 0 ) + { + printer->secdesc = dup_sec_desc( get_talloc_ctx(), ntprinter->info_2->secdesc_buf->sec ); } free_a_printer(&ntprinter, 2); + return True; } @@ -4274,32 +4200,12 @@ static BOOL construct_printer_info_3(Printer_entry *print_hnd, PRINTER_INFO_3 ** ZERO_STRUCTP(printer); - printer->flags = 4; /* These are the components of the SD we are returning. */ - if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->len != 0) { - /* steal the printer info sec_desc structure. [badly done]. */ - printer->secdesc = ntprinter->info_2->secdesc_buf->sec; - -#if 0 - /* - * Set the flags for the components we are returning. - */ + /* These are the components of the SD we are returning. */ - if (printer->secdesc->owner_sid) - printer->flags |= OWNER_SECURITY_INFORMATION; + printer->flags = 0x4; - if (printer->secdesc->grp_sid) - printer->flags |= GROUP_SECURITY_INFORMATION; - - if (printer->secdesc->dacl) - printer->flags |= DACL_SECURITY_INFORMATION; - - if (printer->secdesc->sacl) - printer->flags |= SACL_SECURITY_INFORMATION; -#endif - - ntprinter->info_2->secdesc_buf->sec = NULL; /* Stolen the malloced memory. */ - ntprinter->info_2->secdesc_buf->len = 0; /* Stolen the malloced memory. */ - ntprinter->info_2->secdesc_buf->max_len = 0; /* Stolen the malloced memory. */ + if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->len != 0) { + printer->secdesc = dup_sec_desc( get_talloc_ctx(), ntprinter->info_2->secdesc_buf->sec ); } free_a_printer(&ntprinter, 2); @@ -4582,16 +4488,20 @@ static WERROR enum_all_printers_info_2(RPC_BUFFER *buffer, uint32 offered, uint3 if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) { DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum)); - if (construct_printer_info_2(NULL, ¤t_prt, snum)) { - if((tp=SMB_REALLOC_ARRAY(printers, PRINTER_INFO_2, *returned +1)) == NULL) { + if (construct_printer_info_2(NULL, ¤t_prt, snum)) + { + if ( !(tp=SMB_REALLOC_ARRAY(printers, PRINTER_INFO_2, *returned +1)) ) { DEBUG(2,("enum_all_printers_info_2: failed to enlarge printers buffer!\n")); SAFE_FREE(printers); *returned = 0; return WERR_NOMEM; } - else printers = tp; + DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_2\n", *returned)); + + printers = tp; memcpy(&printers[*returned], ¤t_prt, sizeof(PRINTER_INFO_2)); + (*returned)++; } } @@ -4617,9 +4527,10 @@ static WERROR enum_all_printers_info_2(RPC_BUFFER *buffer, uint32 offered, uint3 out: /* clear memory */ - for (i=0; i<*returned; i++) { + + for (i=0; i<*returned; i++) free_devmode(printers[i].devmode); - } + SAFE_FREE(printers); if ( !W_ERROR_IS_OK(result) ) @@ -7905,8 +7816,6 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S int i, key_index, num_values; int name_length; - ZERO_STRUCT( printer ); - *out_type = 0; *out_max_data_len = 0; @@ -7927,7 +7836,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S if (!W_ERROR_IS_OK(result)) return result; - p_data = &printer->info_2->data; + p_data = printer->info_2->data; key_index = lookup_printerkey( p_data, SPOOL_PRINTERDATA_KEY ); result = WERR_OK; @@ -7945,11 +7854,11 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S biggest_valuesize = 0; biggest_datasize = 0; - num_values = regval_ctr_numvals( &p_data->keys[key_index].values ); - + num_values = regval_ctr_numvals( p_data->keys[key_index].values ); + for ( i=0; ikeys[key_index].values, i ); + val = regval_ctr_specific_value( p_data->keys[key_index].values, i ); name_length = strlen(val->valuename); if ( strlen(val->valuename) > biggest_valuesize ) @@ -7979,7 +7888,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S */ if ( key_index != -1 ) - val = regval_ctr_specific_value( &p_data->keys[key_index].values, idx ); + val = regval_ctr_specific_value( p_data->keys[key_index].values, idx ); if ( !val ) { @@ -8937,7 +8846,7 @@ WERROR _spoolss_getprinterdataex(pipes_struct *p, SPOOL_Q_GETPRINTERDATAEX *q_u, goto done; } - if ( lookup_printerkey( &printer->info_2->data, keyname ) == -1 ) { + if ( lookup_printerkey( printer->info_2->data, keyname ) == -1 ) { DEBUG(4,("_spoolss_getprinterdataex: Invalid keyname [%s]\n", keyname )); free_a_printer( &printer, 2 ); status = WERR_BADFILE; @@ -9158,7 +9067,7 @@ WERROR _spoolss_enumprinterkey(pipes_struct *p, SPOOL_Q_ENUMPRINTERKEY *q_u, SPO /* get the list of subkey names */ unistr2_to_ascii( key, &q_u->key, sizeof(key)-1 ); - data = &printer->info_2->data; + data = printer->info_2->data; num_keys = get_printer_subkeys( data, key, &keynames ); @@ -9301,7 +9210,7 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ /* now look for a match on the key name */ - p_data = &printer->info_2->data; + p_data = printer->info_2->data; unistr2_to_ascii(key, &q_u->key, sizeof(key) - 1); if ( (key_index = lookup_printerkey( p_data, key)) == -1 ) @@ -9316,7 +9225,7 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ /* allocate the memory for the array of pointers -- if necessary */ - num_entries = regval_ctr_numvals( &p_data->keys[key_index].values ); + num_entries = regval_ctr_numvals( p_data->keys[key_index].values ); if ( num_entries ) { if ( (enum_values=TALLOC_ARRAY(p->mem_ctx, PRINTER_ENUM_VALUES, num_entries)) == NULL ) @@ -9339,7 +9248,7 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ { /* lookup the registry value */ - val = regval_ctr_specific_value( &p_data->keys[key_index].values, i ); + val = regval_ctr_specific_value( p_data->keys[key_index].values, i ); DEBUG(10,("retrieved value number [%d] [%s]\n", i, regval_name(val) )); /* copy the data */ -- cgit From c53e760ea52871b476617c6caad64ca88154ff10 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 29 Aug 2005 17:48:01 +0000 Subject: r9752: figured out why talloc_steal() is a bad idea for SEC_DESC* Add a comment so someone else doesn't get bitten by this as well. (This used to be commit 050364ef34b1e69260bd9df9e2140c45263e92f5) --- source3/rpc_server/srv_spoolss_nt.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index ee35b5853f..33eeec91de 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4171,7 +4171,11 @@ static BOOL construct_printer_info_2(Printer_entry *print_hnd, PRINTER_INFO_2 *p if ( ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->len != 0 ) { - printer->secdesc = dup_sec_desc( get_talloc_ctx(), ntprinter->info_2->secdesc_buf->sec ); + /* don't use talloc_steal() here unless you do a deep steal of all + the SEC_DESC members */ + + printer->secdesc = dup_sec_desc( get_talloc_ctx(), + ntprinter->info_2->secdesc_buf->sec ); } free_a_printer(&ntprinter, 2); @@ -4205,7 +4209,11 @@ static BOOL construct_printer_info_3(Printer_entry *print_hnd, PRINTER_INFO_3 ** printer->flags = 0x4; if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->len != 0) { - printer->secdesc = dup_sec_desc( get_talloc_ctx(), ntprinter->info_2->secdesc_buf->sec ); + /* don't use talloc_steal() here unless you do a deep steal of all + the SEC_DESC members */ + + printer->secdesc = dup_sec_desc( get_talloc_ctx(), + ntprinter->info_2->secdesc_buf->sec ); } free_a_printer(&ntprinter, 2); -- cgit From 513e81458f89b6c32262d7e9645be4750f299393 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 2 Sep 2005 09:10:42 +0000 Subject: r9945: fix typos. Guenther (This used to be commit 12029e902277053a4066eae1b3ae311fae5e6422) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 33eeec91de..cda3f26137 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1594,7 +1594,7 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, if (printer_default->access_required & ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) { - DEBUG(3, ("access DENIED for non-printserver bits")); + DEBUG(3, ("access DENIED for non-printserver bits\n")); close_printer_handle(p, handle); return WERR_ACCESS_DENIED; } -- cgit From 54abd2aa66069e6baf7769c496f46d9dba18db39 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 30 Sep 2005 17:13:37 +0000 Subject: r10656: BIG merge from trunk. Features not copied over * \PIPE\unixinfo * winbindd's {group,alias}membership new functions * winbindd's lookupsids() functionality * swat (trunk changes to be reverted as per discussion with Deryck) (This used to be commit 939c3cb5d78e3a2236209b296aa8aba8bdce32d3) --- source3/rpc_server/srv_spoolss_nt.c | 55 +++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 26 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index cda3f26137..5233d6c252 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -75,7 +75,7 @@ typedef struct _counter_printer_0 { static counter_printer_0 *counter_list; -static struct cli_state notify_cli; /* print notify back-channel */ +static struct rpc_pipe_client *notify_cli_pipe; /* print notify back-channel pipe handle*/ static uint32 smb_connections=0; @@ -166,7 +166,7 @@ static void srv_spoolss_replycloseprinter(int snum, POLICY_HND *handle) return; } - result = cli_spoolss_reply_close_printer(¬ify_cli, notify_cli.mem_ctx, handle); + result = rpccli_spoolss_reply_close_printer(notify_cli_pipe, notify_cli_pipe->cli->mem_ctx, handle); if (!W_ERROR_IS_OK(result)) DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed [%s].\n", @@ -174,9 +174,8 @@ static void srv_spoolss_replycloseprinter(int snum, POLICY_HND *handle) /* if it's the last connection, deconnect the IPC$ share */ if (smb_connections==1) { - cli_nt_session_close(¬ify_cli); - cli_ulogoff(¬ify_cli); - cli_shutdown(¬ify_cli); + cli_shutdown(notify_cli_pipe->cli); + notify_cli_pipe = NULL; /* The above call shuts downn the pipe also. */ message_deregister(MSG_PRINTER_NOTIFY2); /* Tell the connections db we're no longer interested in @@ -688,7 +687,7 @@ static void notify_system_time(struct spoolss_notify_msg *msg, return; } - if (!prs_init(&ps, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) { + if (!prs_init(&ps, RPC_MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) { DEBUG(5, ("notify_system_time: prs_init() failed\n")); return; } @@ -1021,7 +1020,7 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) } if ( sending_msg_count ) { - cli_spoolss_rrpcn( ¬ify_cli, mem_ctx, &p->notify.client_hnd, + rpccli_spoolss_rrpcn( notify_cli_pipe, mem_ctx, &p->notify.client_hnd, data_len, data, p->notify.change, 0 ); } } @@ -1075,7 +1074,8 @@ static BOOL notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, voi Receive a notify2 message list ********************************************************************/ -static void receive_notify2_message_list(int msg_type, pid_t src, void *msg, size_t len) +static void receive_notify2_message_list(int msg_type, struct process_id src, + void *msg, size_t len) { size_t msg_count, i; char *buf = (char *)msg; @@ -1176,7 +1176,8 @@ static BOOL srv_spoolss_drv_upgrade_printer(char* drivername) DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n", drivername)); - message_send_pid(sys_getpid(), MSG_PRINTER_DRVUPGRADE, drivername, len+1, False); + message_send_pid(pid_to_procid(sys_getpid()), + MSG_PRINTER_DRVUPGRADE, drivername, len+1, False); return True; } @@ -1186,7 +1187,7 @@ static BOOL srv_spoolss_drv_upgrade_printer(char* drivername) over all printers, upgrading ones as necessary **********************************************************************/ -void do_drv_upgrade_printer(int msg_type, pid_t src, void *buf, size_t len) +void do_drv_upgrade_printer(int msg_type, struct process_id src, void *buf, size_t len) { fstring drivername; int snum; @@ -1272,7 +1273,8 @@ static BOOL srv_spoolss_reset_printerdata(char* drivername) DEBUG(10,("srv_spoolss_reset_printerdata: Sending message about resetting printerdata [%s]\n", drivername)); - message_send_pid(sys_getpid(), MSG_PRINTERDATA_INIT_RESET, drivername, len+1, False); + message_send_pid(pid_to_procid(sys_getpid()), + MSG_PRINTERDATA_INIT_RESET, drivername, len+1, False); return True; } @@ -1282,7 +1284,8 @@ static BOOL srv_spoolss_reset_printerdata(char* drivername) over all printers, resetting printer data as neessary **********************************************************************/ -void reset_all_printerdata(int msg_type, pid_t src, void *buf, size_t len) +void reset_all_printerdata(int msg_type, struct process_id src, + void *buf, size_t len) { fstring drivername; int snum; @@ -2001,7 +2004,10 @@ WERROR _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER /* this should not have failed---if it did, report to client */ if ( !W_ERROR_IS_OK(status_win2k) ) + { + status = status_win2k; goto done; + } } } @@ -2479,9 +2485,10 @@ done: Connect to the client machine. **********************************************************/ -static BOOL spoolss_connect_to_client(struct cli_state *the_cli, +static BOOL spoolss_connect_to_client(struct cli_state *the_cli, struct rpc_pipe_client **pp_pipe, struct in_addr *client_ip, const char *remote_machine) { + NTSTATUS ret; ZERO_STRUCTP(the_cli); if(cli_initialise(the_cli) == NULL) { @@ -2563,10 +2570,10 @@ static BOOL spoolss_connect_to_client(struct cli_state *the_cli, * Now start the NT Domain stuff :-). */ - if(cli_nt_session_open(the_cli, PI_SPOOLSS) == False) { - DEBUG(0,("spoolss_connect_to_client: unable to open the domain client session to machine %s. Error was : %s.\n", remote_machine, cli_errstr(the_cli))); - cli_nt_session_close(the_cli); - cli_ulogoff(the_cli); + *pp_pipe = cli_rpc_pipe_open_noauth(the_cli, PI_SPOOLSS, &ret); + if(!*pp_pipe) { + DEBUG(0,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n", + remote_machine, nt_errstr(ret))); cli_shutdown(the_cli); return False; } @@ -2589,13 +2596,14 @@ static BOOL srv_spoolss_replyopenprinter(int snum, const char *printer, * and connect to the IPC$ share anonymously */ if (smb_connections==0) { + struct cli_state notify_cli; /* print notify back-channel */ fstring unix_printer; fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */ ZERO_STRUCT(notify_cli); - if(!spoolss_connect_to_client(¬ify_cli, client_ip, unix_printer)) + if(!spoolss_connect_to_client(¬ify_cli, ¬ify_cli_pipe, client_ip, unix_printer)) return False; message_register(MSG_PRINTER_NOTIFY2, receive_notify2_message_list); @@ -2614,7 +2622,7 @@ static BOOL srv_spoolss_replyopenprinter(int snum, const char *printer, smb_connections++; - result = cli_spoolss_reply_open_printer(¬ify_cli, notify_cli.mem_ctx, printer, localprinter, + result = rpccli_spoolss_reply_open_printer(notify_cli_pipe, notify_cli_pipe->cli->mem_ctx, printer, localprinter, type, handle); if (!W_ERROR_IS_OK(result)) @@ -6117,17 +6125,12 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, || !strequal(printer->info_2->portname, old_printer->info_2->portname) || !strequal(printer->info_2->location, old_printer->info_2->location)) ) { + /* add_printer_hook() will call reload_services() */ + if ( !add_printer_hook(p->pipe_user.nt_user_token, printer) ) { result = WERR_ACCESS_DENIED; goto done; } - - /* - * make sure we actually reload the services after - * this as smb.conf could have a new section in it - * .... shouldn't .... but could - */ - reload_services(False); } /* -- cgit From 6f72169c7cee4d8334c15e3add711cd1716e618a Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 18 Oct 2005 02:37:13 +0000 Subject: r11135: should fix seg fault in addprinter code reported by Marcin. Allocate memory in convert_printer_info() if necessary (This used to be commit 7ada5da8e94a08a9a3e488172fa04ce688882299) --- source3/rpc_server/srv_spoolss_nt.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 5233d6c252..a8fc1bc229 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1729,20 +1729,29 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, static BOOL convert_printer_info(const SPOOL_PRINTER_INFO_LEVEL *uni, NT_PRINTER_INFO_LEVEL *printer, uint32 level) { - BOOL ret = True; + BOOL ret; switch (level) { case 2: - /* printer->info_2 is already a valid printer */ + /* allocate memory if needed. Messy because + convert_printer_info is used to update an existing + printer or build a new one */ + + if ( !printer->info_2 ) { + printer->info_2 = TALLOC_ZERO_P( printer, NT_PRINTER_INFO_LEVEL_2 ); + if ( !printer->info_2 ) { + DEBUG(0,("convert_printer_info: talloc() failed!\n")); + return False; + } + } + ret = uni_2_asc_printer_info_2(uni->info_2, printer->info_2); printer->info_2->setuptime = time(NULL); - break; - default: - break; + return ret; } - return ret; + return False; } static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL *uni, -- cgit From 6fc9098dcc1a1ef232b96f5d4c562bf340db8988 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 20 Oct 2005 20:26:11 +0000 Subject: r11235: fix segfault in addprinter due to mixing talloc() and malloc()'d memory (This used to be commit f6f78877b485be5efd5cf1f3147b2e9fee647e52) --- source3/rpc_server/srv_spoolss_nt.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a8fc1bc229..026e7681e0 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -7413,13 +7413,11 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ int snum; WERROR err = WERR_OK; - if ((printer = SMB_MALLOC_P(NT_PRINTER_INFO_LEVEL)) == NULL) { + if ( !(printer = TALLOC_ZERO_P(NULL, NT_PRINTER_INFO_LEVEL)) ) { DEBUG(0,("spoolss_addprinterex_level_2: malloc fail.\n")); return WERR_NOMEM; } - ZERO_STRUCTP(printer); - /* convert from UNICODE to ASCII - this allocates the info_2 struct inside *printer.*/ if (!convert_printer_info(info, printer, 2)) { free_a_printer(&printer, 2); -- cgit From cd310c19cefddc799ec5f8b374bc9c5ea9dec5f1 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 21 Oct 2005 02:14:23 +0000 Subject: r11240: * fix invalid read reported by valgrind in the spoolss backchannel connection by rewriting spoolss_connect_to_client(). Ensure that we save the cli_state* in the rpc_pipe_client struct. * fix typo in debug message in cli_start_connection" (This used to be commit 18400f96628ffdd332c2fb2aa52b5e9aee5cb3ce) --- source3/rpc_server/srv_spoolss_nt.c | 102 ++++++++++++------------------------ 1 file changed, 34 insertions(+), 68 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 026e7681e0..e5b3ca3947 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -174,8 +174,10 @@ static void srv_spoolss_replycloseprinter(int snum, POLICY_HND *handle) /* if it's the last connection, deconnect the IPC$ share */ if (smb_connections==1) { - cli_shutdown(notify_cli_pipe->cli); + + cli_shutdown( notify_cli_pipe->cli ); notify_cli_pipe = NULL; /* The above call shuts downn the pipe also. */ + message_deregister(MSG_PRINTER_NOTIFY2); /* Tell the connections db we're no longer interested in @@ -2494,99 +2496,66 @@ done: Connect to the client machine. **********************************************************/ -static BOOL spoolss_connect_to_client(struct cli_state *the_cli, struct rpc_pipe_client **pp_pipe, +static BOOL spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe, struct in_addr *client_ip, const char *remote_machine) { NTSTATUS ret; - ZERO_STRUCTP(the_cli); - - if(cli_initialise(the_cli) == NULL) { - DEBUG(0,("spoolss_connect_to_client: unable to initialize client connection.\n")); - return False; - } - + struct cli_state *the_cli; + struct in_addr rm_addr; + if ( is_zero_ip(*client_ip) ) { - if(!resolve_name( remote_machine, &the_cli->dest_ip, 0x20)) { - DEBUG(0,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine)); - cli_shutdown(the_cli); - return False; + if ( !resolve_name( remote_machine, &rm_addr, 0x20) ) { + DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine)); + return False; } - if (ismyip(the_cli->dest_ip)) { + if ( ismyip( rm_addr )) { DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n", remote_machine)); - cli_shutdown(the_cli); return False; } - } - else { - the_cli->dest_ip.s_addr = client_ip->s_addr; + } else { + rm_addr.s_addr = client_ip->s_addr; DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n", inet_ntoa(*client_ip) )); } - if (!cli_connect(the_cli, remote_machine, &the_cli->dest_ip)) { - DEBUG(0,("spoolss_connect_to_client: unable to connect to SMB server on machine %s. Error was : %s.\n", remote_machine, cli_errstr(the_cli) )); - cli_shutdown(the_cli); - return False; - } - - if (!attempt_netbios_session_request(the_cli, global_myname(), remote_machine, &the_cli->dest_ip)) { - DEBUG(0,("spoolss_connect_to_client: machine %s rejected the NetBIOS session request.\n", - remote_machine)); - cli_shutdown(the_cli); - return False; - } + /* setup the connection */ - the_cli->protocol = PROTOCOL_NT1; - cli_setup_signing_state(the_cli, lp_client_signing()); - - if (!cli_negprot(the_cli)) { - DEBUG(0,("spoolss_connect_to_client: machine %s rejected the negotiate protocol. Error was : %s.\n", remote_machine, cli_errstr(the_cli) )); - cli_shutdown(the_cli); - return False; - } + ret = cli_full_connection( &the_cli, global_myname(), remote_machine, + &rm_addr, 0, "IPC$", "IPC", + "", /* username */ + "", /* domain */ + "", /* password */ + 0, lp_client_signing(), NULL ); - if (the_cli->protocol != PROTOCOL_NT1) { - DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine)); - cli_shutdown(the_cli); - return False; - } - - /* - * Do an anonymous session setup. - */ - - if (!cli_session_setup(the_cli, "", "", 0, "", 0, "")) { - DEBUG(0,("spoolss_connect_to_client: machine %s rejected the session setup. Error was : %s.\n", remote_machine, cli_errstr(the_cli) )); - cli_shutdown(the_cli); + if ( !NT_STATUS_IS_OK( ret ) ) { + DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n", + remote_machine )); return False; - } - - if (!(the_cli->sec_mode & 1)) { - DEBUG(0,("spoolss_connect_to_client: machine %s isn't in user level security mode\n", remote_machine)); + } + + if ( the_cli->protocol != PROTOCOL_NT1 ) { + DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine)); cli_shutdown(the_cli); return False; } - if (!cli_send_tconX(the_cli, "IPC$", "IPC", "", 1)) { - DEBUG(0,("spoolss_connect_to_client: machine %s rejected the tconX on the IPC$ share. Error was : %s.\n", remote_machine, cli_errstr(the_cli) )); - cli_shutdown(the_cli); - return False; - } - /* * Ok - we have an anonymous connection to the IPC$ share. * Now start the NT Domain stuff :-). */ - *pp_pipe = cli_rpc_pipe_open_noauth(the_cli, PI_SPOOLSS, &ret); - if(!*pp_pipe) { - DEBUG(0,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n", + if ( !(*pp_pipe = cli_rpc_pipe_open_noauth(the_cli, PI_SPOOLSS, &ret)) ) { + DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n", remote_machine, nt_errstr(ret))); cli_shutdown(the_cli); return False; } + /* make sure to save the cli_state pointer. Keep its own talloc_ctx */ + + (*pp_pipe)->cli = the_cli; + return True; } @@ -2605,14 +2574,11 @@ static BOOL srv_spoolss_replyopenprinter(int snum, const char *printer, * and connect to the IPC$ share anonymously */ if (smb_connections==0) { - struct cli_state notify_cli; /* print notify back-channel */ fstring unix_printer; fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */ - ZERO_STRUCT(notify_cli); - - if(!spoolss_connect_to_client(¬ify_cli, ¬ify_cli_pipe, client_ip, unix_printer)) + if ( !spoolss_connect_to_client( ¬ify_cli_pipe, client_ip, unix_printer )) return False; message_register(MSG_PRINTER_NOTIFY2, receive_notify2_message_list); -- cgit From f2ecd4fed0ed11b73fa330588501a0ac37583174 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 22 Nov 2005 15:52:22 +0000 Subject: r11860: BUG 3156: don't use find_service() when explicitly looking for a printer as the username map might get in the way (This used to be commit 46bf28c81c27dfdc412318a83bf565211a58a47d) --- source3/rpc_server/srv_spoolss_nt.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index e5b3ca3947..f0ba863b4d 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -479,29 +479,30 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) DEBUGADD(5, ("searching for [%s]\n", aprinter )); /* Search all sharenames first as this is easier than pulling - the printer_info_2 off of disk */ + the printer_info_2 off of disk. Don't use find_service() since + that calls out to map_username() */ - snum = find_service(aprinter); - - if ( lp_snum_ok(snum) && lp_print_ok(snum) ) { - found = True; - fstrcpy( sname, aprinter ); - } - /* do another loop to look for printernames */ for (snum=0; !found && snum Date: Sat, 3 Dec 2005 06:46:46 +0000 Subject: r12043: It's amazing the warnings you find when compiling on a 64-bit box with gcc4 and -O6... Fix a bunch of C99 dereferencing type-punned pointer will break strict-aliasing rules errors. Also added prs_int32 (not uint32...) as it's needed in one place. Find places where prs_uint32 was being used to marshall/unmarshall a time_t (a big no no on 64-bits). More warning fixes to come. Thanks to Volker for nudging me to compile like this. Jeremy. (This used to be commit c65b752604f8f58abc4e7ae8514dc2c7f086271c) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index f0ba863b4d..334158bbbd 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -267,7 +267,7 @@ static Printer_entry *find_printer_index_by_hnd(pipes_struct *p, POLICY_HND *hnd { Printer_entry *find_printer = NULL; - if(!find_policy_by_hnd(p,hnd,(void **)&find_printer)) { + if(!find_policy_by_hnd(p,hnd,(void **)(void *)&find_printer)) { DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: ")); return NULL; } -- cgit From d14af63e6ab600eb3ac705f2f425c860e927553a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 2 Feb 2006 20:44:50 +0000 Subject: r13293: Rather a big patch I'm afraid, but this should fix bug #3347 by saving the UNIX token used to set a delete on close flag, and using it when doing the delete. libsmbsharemodes.so still needs updating to cope with this change. Samba4 torture tests to follow. Jeremy. (This used to be commit 23f16cbc2e8cde97c486831e26bcafd4ab4a9654) --- source3/rpc_server/srv_spoolss_nt.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 334158bbbd..a22d6db266 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1620,9 +1620,9 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege, and not a printer admin, then fail */ - if ( user.uid != 0 + if ( user.ut.uid != 0 && !user_has_privileges( user.nt_user_token, &se_printop ) - && !user_in_list(uidtoname(user.uid), lp_printer_admin(snum), user.groups, user.ngroups) ) + && !user_in_list(uidtoname(user.ut.uid), lp_printer_admin(snum), user.ut.groups, user.ut.ngroups) ) { close_printer_handle(p, handle); return WERR_ACCESS_DENIED; @@ -1676,7 +1676,7 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, return WERR_ACCESS_DENIED; } - if (!user_ok(uidtoname(user.uid), snum, user.groups, user.ngroups) || !print_access_check(&user, snum, printer_default->access_required)) { + if (!user_ok(uidtoname(user.ut.uid), snum, user.ut.groups, user.ut.ngroups) || !print_access_check(&user, snum, printer_default->access_required)) { DEBUG(3, ("access DENIED for printer open\n")); close_printer_handle(p, handle); return WERR_ACCESS_DENIED; @@ -1869,7 +1869,7 @@ static WERROR _spoolss_enddocprinter_internal(pipes_struct *p, POLICY_HND *handl return WERR_BADFID; Printer->document_started=False; - print_job_end(snum, Printer->jobid,True); + print_job_end(snum, Printer->jobid,NORMAL_CLOSE); /* error codes unhandled so far ... */ return WERR_OK; @@ -7554,12 +7554,12 @@ WERROR _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u, case 3: fstrcpy(driver_name, driver.info_3->name ? driver.info_3->name : ""); sys_adminlog(LOG_INFO,"Added printer driver. Print driver name: %s. Print driver OS: %s. Administrator name: %s.", - driver_name, get_drv_ver_to_os(driver.info_3->cversion),uidtoname(user.uid)); + driver_name, get_drv_ver_to_os(driver.info_3->cversion),uidtoname(user.ut.uid)); break; case 6: fstrcpy(driver_name, driver.info_6->name ? driver.info_6->name : ""); sys_adminlog(LOG_INFO,"Added printer driver. Print driver name: %s. Print driver OS: %s. Administrator name: %s.", - driver_name, get_drv_ver_to_os(driver.info_6->version),uidtoname(user.uid)); + driver_name, get_drv_ver_to_os(driver.info_6->version),uidtoname(user.ut.uid)); break; } /* END_ADMIN_LOG */ -- cgit From 0af1500fc0bafe61019f1b2ab1d9e1d369221240 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 3 Feb 2006 22:19:41 +0000 Subject: r13316: Let the carnage begin.... Sync with trunk as off r13315 (This used to be commit 17e63ac4ed8325c0d44fe62b2442449f3298559f) --- source3/rpc_server/srv_spoolss_nt.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a22d6db266..e6d45f76ec 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1620,10 +1620,13 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege, and not a printer admin, then fail */ - if ( user.ut.uid != 0 - && !user_has_privileges( user.nt_user_token, &se_printop ) - && !user_in_list(uidtoname(user.ut.uid), lp_printer_admin(snum), user.ut.groups, user.ut.ngroups) ) - { + if ((user.ut.uid != 0) && + !user_has_privileges(user.nt_user_token, + &se_printop ) && + !token_contains_name_in_list( + uidtoname(user.ut.uid), NULL, + user.nt_user_token, + lp_printer_admin(snum))) { close_printer_handle(p, handle); return WERR_ACCESS_DENIED; } @@ -1676,7 +1679,10 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, return WERR_ACCESS_DENIED; } - if (!user_ok(uidtoname(user.ut.uid), snum, user.ut.groups, user.ut.ngroups) || !print_access_check(&user, snum, printer_default->access_required)) { + if (!user_ok_token(uidtoname(user.ut.uid), user.nt_user_token, + snum) || + !print_access_check(&user, snum, + printer_default->access_required)) { DEBUG(3, ("access DENIED for printer open\n")); close_printer_handle(p, handle); return WERR_ACCESS_DENIED; @@ -5997,7 +6003,7 @@ BOOL add_printer_hook(NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer) numlines = 0; /* Get lines and convert them back to dos-codepage */ - qlines = fd_lines_load(fd, &numlines); + qlines = fd_lines_load(fd, &numlines, 0); DEBUGADD(10,("Lines returned = [%d]\n", numlines)); close(fd); @@ -7195,7 +7201,7 @@ WERROR enumports_hook( int *count, char ***lines ) } numlines = 0; - qlines = fd_lines_load(fd, &numlines); + qlines = fd_lines_load(fd, &numlines, 0); DEBUGADD(10,("Lines returned = [%d]\n", numlines)); close(fd); } -- cgit From b2ae6e08daee619936f2858eafb31b3a8d8ecfcb Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 17 Feb 2006 21:07:26 +0000 Subject: r13547: add earlier checks to deny deleting a printer driver. The previous code relied upon file permissions alone. Now we check that the user is a printer administrator and that the share has not been marked read only for that user. (This used to be commit 117d9fd9e16a7afbc6772506a4f8c33ff99d33f7) --- source3/rpc_server/srv_spoolss_nt.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index e6d45f76ec..c767daf88c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1973,9 +1973,21 @@ WERROR _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER struct current_user user; WERROR status; WERROR status_win2k = WERR_ACCESS_DENIED; + SE_PRIV se_printop = SE_PRINT_OPERATOR; get_current_user(&user, p); + /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege, + and not a printer admin, then fail */ + + if ( (user.ut.uid != 0) + && !user_has_privileges(user.nt_user_token, &se_printop ) + && !token_contains_name_in_list( uidtoname(user.ut.uid), + NULL, user.nt_user_token, lp_printer_admin(-1)) ) + { + return WERR_ACCESS_DENIED; + } + unistr2_to_ascii(driver, &q_u->driver, sizeof(driver)-1 ); unistr2_to_ascii(arch, &q_u->arch, sizeof(arch)-1 ); @@ -2059,9 +2071,21 @@ WERROR _spoolss_deleteprinterdriverex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIV struct current_user user; WERROR status; WERROR status_win2k = WERR_ACCESS_DENIED; + SE_PRIV se_printop = SE_PRINT_OPERATOR; get_current_user(&user, p); + /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege, + and not a printer admin, then fail */ + + if ( (user.ut.uid != 0) + && !user_has_privileges(user.nt_user_token, &se_printop ) + && !token_contains_name_in_list( uidtoname(user.ut.uid), + NULL, user.nt_user_token, lp_printer_admin(-1)) ) + { + return WERR_ACCESS_DENIED; + } + unistr2_to_ascii(driver, &q_u->driver, sizeof(driver)-1 ); unistr2_to_ascii(arch, &q_u->arch, sizeof(arch)-1 ); -- cgit From e33b728c7b2076917e2149191222b259e5c1d942 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 3 Mar 2006 16:44:30 +0000 Subject: r13815: "Into the blind world let us now descend," Began the poet, his face as pale as death. "I will go first, and you will follow me." --- Adding XcvDataPort() to the spoolss code for remotely add ports. The design is to allow an intuitive means of creating a new CUPS print queue from the Windows 2000/XP APW without hacks like specifying the deviceURI in the location field of the printer properties dialog. Also set 'default devmode = yes' as the new default since it causes no harm and only is executed when you have a NULL devmode anyways. (This used to be commit 123e478ce5b5f63a61d00197332b847e83722468) --- source3/rpc_server/srv_spoolss_nt.c | 149 ++++++++++++++---------------------- 1 file changed, 58 insertions(+), 91 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index c767daf88c..cfa0cc7cba 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -435,7 +435,10 @@ static BOOL set_printer_hnd_printertype(Printer_entry *Printer, char *handlename } /**************************************************************************** - Set printer handle name. + Set printer handle name.. Accept names like \\server, \\server\printer, + \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See + the MSDN docs regarding OpenPrinter() for details on the XcvData() and + XcvDataPort() interface. ****************************************************************************/ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) @@ -477,6 +480,14 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) return False; DEBUGADD(5, ("searching for [%s]\n", aprinter )); + + /* check for the TCPMON interface */ + + if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) { + Printer->printer_type = PRINTER_HANDLE_IS_TCPMON; + fstrcpy(sname, SPL_XCV_MONITOR_TCPMON); + found = True; + } /* Search all sharenames first as this is easier than pulling the printer_info_2 off of disk. Don't use find_service() since @@ -1473,60 +1484,6 @@ WERROR _spoolss_open_printer(pipes_struct *p, SPOOL_Q_OPEN_PRINTER *q_u, SPOOL_R } /******************************************************************** - * spoolss_open_printer - * - * If the openprinterex rpc call contains a devmode, - * it's a per-user one. This per-user devmode is derivated - * from the global devmode. Openprinterex() contains a per-user - * devmode for when you do EMF printing and spooling. - * In the EMF case, the NT workstation is only doing half the job - * of rendering the page. The other half is done by running the printer - * driver on the server. - * The EMF file doesn't contain the page description (paper size, orientation, ...). - * The EMF file only contains what is to be printed on the page. - * So in order for the server to know how to print, the NT client sends - * a devicemode attached to the openprinterex call. - * But this devicemode is short lived, it's only valid for the current print job. - * - * If Samba would have supported EMF spooling, this devicemode would - * have been attached to the handle, to sent it to the driver to correctly - * rasterize the EMF file. - * - * As Samba only supports RAW spooling, we only receive a ready-to-print file, - * we just act as a pass-thru between windows and the printer. - * - * In order to know that Samba supports only RAW spooling, NT has to call - * getprinter() at level 2 (attribute field) or NT has to call startdoc() - * and until NT sends a RAW job, we refuse it. - * - * But to call getprinter() or startdoc(), you first need a valid handle, - * and to get an handle you have to call openprintex(). Hence why you have - * a devicemode in the openprinterex() call. - * - * - * Differences between NT4 and NT 2000. - * NT4: - * --- - * On NT4, you only have a global devicemode. This global devicemode can be changed - * by the administrator (or by a user with enough privs). Everytime a user - * wants to print, the devicemode is resetted to the default. In Word, everytime - * you print, the printer's characteristics are always reset to the global devicemode. - * - * NT 2000: - * ------- - * In W2K, there is the notion of per-user devicemode. The first time you use - * a printer, a per-user devicemode is build from the global devicemode. - * If you change your per-user devicemode, it is saved in the registry, under the - * H_KEY_CURRENT_KEY sub_tree. So that everytime you print, you have your default - * printer preferences available. - * - * To change the per-user devicemode: it's the "Printing Preferences ..." button - * on the General Tab of the printer properties windows. - * - * To change the global devicemode: it's the "Printing Defaults..." button - * on the Advanced Tab of the printer properties window. - * - * JFM. ********************************************************************/ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, SPOOL_R_OPEN_PRINTER_EX *r_u) @@ -1581,10 +1538,15 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, * Second case: the user is opening a printer: * NT doesn't let us connect to a printer if the connecting user * doesn't have print permission. + * + * Third case: user is opening the TCP/IP port monitor + * access checks same as opening a handle to the print server. */ - if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) + switch (Printer->printer_type ) { + case PRINTER_HANDLE_IS_PRINTSERVER: + case PRINTER_HANDLE_IS_TCPMON: /* Printserver handles use global struct... */ snum = -1; @@ -1642,10 +1604,9 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" )); /* We fall through to return WERR_OK */ - - } - else - { + break; + + case PRINTER_HANDLE_IS_PRINTER: /* NT doesn't let us connect to a printer if the connecting user doesn't have print permission. */ @@ -1702,6 +1663,11 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, DEBUG(4,("Setting printer access = %s\n", (printer_default->access_required == PRINTER_ACCESS_ADMINISTER) ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" )); + break; + + default: + /* sanity check to prevent programmer error */ + return WERR_BADFID; } Printer->access_granted = printer_default->access_required; @@ -8496,18 +8462,22 @@ WERROR _spoolss_enumprintprocdatatypes(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCDAT static WERROR enumprintmonitors_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { - PRINTMONITOR_1 *info_1=NULL; + PRINTMONITOR_1 *info_1; WERROR result = WERR_OK; + int i; - if((info_1 = SMB_MALLOC_P(PRINTMONITOR_1)) == NULL) + if((info_1 = SMB_MALLOC_ARRAY(PRINTMONITOR_1, 2)) == NULL) return WERR_NOMEM; - (*returned) = 0x1; + *returned = 2; - init_unistr(&info_1->name, "Local Port"); - - *needed += spoolss_size_printmonitor_info_1(info_1); + init_unistr(&(info_1[0].name), "Local Port"); + init_unistr(&(info_1[1].name), "Standard TCP/IP Port"); + for ( i=0; i<*returned; i++ ) { + *needed += spoolss_size_printmonitor_info_1(&info_1[i]); + } + if (*needed > offered) { result = WERR_INSUFFICIENT_BUFFER; goto out; @@ -8518,7 +8488,9 @@ static WERROR enumprintmonitors_level_1(RPC_BUFFER *buffer, uint32 offered, uint goto out; } - smb_io_printmonitor_info_1("", buffer, info_1, 0); + for ( i=0; i<*returned; i++ ) { + smb_io_printmonitor_info_1("", buffer, &info_1[i], 0); + } out: SAFE_FREE(info_1); @@ -8535,20 +8507,27 @@ out: static WERROR enumprintmonitors_level_2(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { - PRINTMONITOR_2 *info_2=NULL; + PRINTMONITOR_2 *info_2; WERROR result = WERR_OK; + int i; - if((info_2 = SMB_MALLOC_P(PRINTMONITOR_2)) == NULL) + if((info_2 = SMB_MALLOC_ARRAY(PRINTMONITOR_2, 2)) == NULL) return WERR_NOMEM; - (*returned) = 0x1; + *returned = 2; - init_unistr(&info_2->name, "Local Port"); - init_unistr(&info_2->environment, "Windows NT X86"); - init_unistr(&info_2->dll_name, "localmon.dll"); - - *needed += spoolss_size_printmonitor_info_2(info_2); + init_unistr(&(info_2[0].name), "Local Port"); + init_unistr(&(info_2[0].environment), "Windows NT X86"); + init_unistr(&(info_2[0].dll_name), "localmon.dll"); + + init_unistr(&(info_2[1].name), "Standard TCP/IP Port"); + init_unistr(&(info_2[1].environment), "Windows NT X86"); + init_unistr(&(info_2[1].dll_name), "tcpmon.dll"); + for ( i=0; i<*returned; i++ ) { + *needed += spoolss_size_printmonitor_info_2(&info_2[i]); + } + if (*needed > offered) { result = WERR_INSUFFICIENT_BUFFER; goto out; @@ -8559,7 +8538,9 @@ static WERROR enumprintmonitors_level_2(RPC_BUFFER *buffer, uint32 offered, uint goto out; } - smb_io_printmonitor_info_2("", buffer, info_2, 0); + for ( i=0; i<*returned; i++ ) { + smb_io_printmonitor_info_2("", buffer, &info_2[i], 0); + } out: SAFE_FREE(info_2); @@ -9398,23 +9379,9 @@ WERROR _spoolss_getprintprocessordirectory(pipes_struct *p, SPOOL_Q_GETPRINTPROC return result; } -#if 0 - -WERROR _spoolss_replyopenprinter(pipes_struct *p, SPOOL_Q_REPLYOPENPRINTER *q_u, - SPOOL_R_REPLYOPENPRINTER *r_u) +WERROR _spoolss_xcvdataport(pipes_struct *p, SPOOL_Q_XCVDATAPORT *q_u, SPOOL_R_XCVDATAPORT *r_u) { - DEBUG(5,("_spoolss_replyopenprinter\n")); - - DEBUG(10, ("replyopenprinter for localprinter %d\n", q_u->printer)); - return WERR_OK; } -WERROR _spoolss_replycloseprinter(pipes_struct *p, SPOOL_Q_REPLYCLOSEPRINTER *q_u, - SPOOL_R_REPLYCLOSEPRINTER *r_u) -{ - DEBUG(5,("_spoolss_replycloseprinter\n")); - return WERR_OK; -} -#endif -- cgit From 354c24d5257bad429c300b5cb7052d034d48d7a9 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 3 Mar 2006 19:28:51 +0000 Subject: r13820: * Start fleshing out the XcvDataPort() server implementation * Add support for the "Local Port" monitor as well through this API (This used to be commit ba9cdd88a0abf90a9c04959e554d7e4f10d17ff7) --- source3/rpc_server/srv_spoolss_nt.c | 135 ++++++++++++++++++++++++++---------- 1 file changed, 99 insertions(+), 36 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index cfa0cc7cba..2f2f599f43 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -200,10 +200,10 @@ static void free_printer_entry(void *ptr) if (Printer->notify.client_connected==True) { int snum = -1; - if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) { + if ( Printer->printer_type == SPLHND_SERVER) { snum = -1; srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd); - } else if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTER) { + } else if (Printer->printer_type == SPLHND_PRINTER) { snum = print_queue_snum(Printer->sharename); if (snum != -1) srv_spoolss_replycloseprinter(snum, @@ -395,11 +395,11 @@ static BOOL get_printer_snum(pipes_struct *p, POLICY_HND *hnd, int *number) } switch (Printer->printer_type) { - case PRINTER_HANDLE_IS_PRINTER: + case SPLHND_PRINTER: DEBUG(4,("short name:%s\n", Printer->sharename)); *number = print_queue_snum(Printer->sharename); return (*number != -1); - case PRINTER_HANDLE_IS_PRINTSERVER: + case SPLHND_SERVER: return False; default: return False; @@ -423,12 +423,12 @@ static BOOL set_printer_hnd_printertype(Printer_entry *Printer, char *handlename /* it's a print server */ if (*handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) { DEBUGADD(4,("Printer is a print server\n")); - Printer->printer_type = PRINTER_HANDLE_IS_PRINTSERVER; + Printer->printer_type = SPLHND_SERVER; } - /* it's a printer */ + /* it's a printer (set_printer_hnd_name() will handle port monitors */ else { DEBUGADD(4,("Printer is a printer\n")); - Printer->printer_type = PRINTER_HANDLE_IS_PRINTER; + Printer->printer_type = SPLHND_PRINTER; } return True; @@ -473,21 +473,26 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) fstrcpy( Printer->servername, servername ); - if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER ) + if ( Printer->printer_type == SPLHND_SERVER ) return True; - if ( Printer->printer_type != PRINTER_HANDLE_IS_PRINTER ) + if ( Printer->printer_type != SPLHND_PRINTER ) return False; DEBUGADD(5, ("searching for [%s]\n", aprinter )); - /* check for the TCPMON interface */ + /* check for the Port Monitor Interface */ if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) { - Printer->printer_type = PRINTER_HANDLE_IS_TCPMON; + Printer->printer_type = SPLHND_PORTMON_TCP; fstrcpy(sname, SPL_XCV_MONITOR_TCPMON); found = True; } + else if ( strequal( aprinter, SPL_XCV_MONITOR_LOCALMON ) ) { + Printer->printer_type = SPLHND_PORTMON_LOCAL; + fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON); + found = True; + } /* Search all sharenames first as this is easier than pulling the printer_info_2 off of disk. Don't use find_service() since @@ -954,7 +959,7 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) /* For this printer? Print servers always receive notifications. */ - if ( ( p->printer_type == PRINTER_HANDLE_IS_PRINTER ) && + if ( ( p->printer_type == SPLHND_PRINTER ) && ( !strequal(msg_group->printername, p->sharename) ) ) continue; @@ -996,7 +1001,7 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) * --jerry */ - if ( ( p->printer_type == PRINTER_HANDLE_IS_PRINTER ) && ( msg->type == PRINTER_NOTIFY_TYPE ) ) + if ( ( p->printer_type == SPLHND_PRINTER ) && ( msg->type == PRINTER_NOTIFY_TYPE ) ) id = 0; else id = msg->id; @@ -1260,7 +1265,7 @@ void update_monitored_printq_cache( void ) client_connected == True */ while ( printer ) { - if ( (printer->printer_type == PRINTER_HANDLE_IS_PRINTER) + if ( (printer->printer_type == SPLHND_PRINTER) && printer->notify.client_connected ) { snum = print_queue_snum(printer->sharename); @@ -1539,14 +1544,15 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, * NT doesn't let us connect to a printer if the connecting user * doesn't have print permission. * - * Third case: user is opening the TCP/IP port monitor + * Third case: user is opening a Port Monitor * access checks same as opening a handle to the print server. */ switch (Printer->printer_type ) { - case PRINTER_HANDLE_IS_PRINTSERVER: - case PRINTER_HANDLE_IS_TCPMON: + case SPLHND_SERVER: + case SPLHND_PORTMON_TCP: + case SPLHND_PORTMON_LOCAL: /* Printserver handles use global struct... */ snum = -1; @@ -1606,7 +1612,7 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, /* We fall through to return WERR_OK */ break; - case PRINTER_HANDLE_IS_PRINTER: + case SPLHND_PRINTER: /* NT doesn't let us connect to a printer if the connecting user doesn't have print permission. */ @@ -1677,7 +1683,7 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, * save it here in case we get a job submission on this handle */ - if ( (Printer->printer_type != PRINTER_HANDLE_IS_PRINTSERVER) + if ( (Printer->printer_type != SPLHND_SERVER) && q_u->printer_default.devmode_cont.devmode_ptr ) { convert_devicemode( Printer->sharename, q_u->printer_default.devmode_cont.devmode, @@ -2431,7 +2437,7 @@ WERROR _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO unistr2_to_ascii(value, valuename, sizeof(value)-1); - if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER ) + if ( Printer->printer_type == SPLHND_SERVER ) status = getprinterdata_printer_server( p->mem_ctx, value, type, data, needed, *out_size ); else { @@ -2650,9 +2656,9 @@ WERROR _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE /* Connect to the client machine and send a ReplyOpenPrinter */ - if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) + if ( Printer->printer_type == SPLHND_SERVER) snum = -1; - else if ( (Printer->printer_type == PRINTER_HANDLE_IS_PRINTER) && + else if ( (Printer->printer_type == SPLHND_PRINTER) && !get_printer_snum(p, handle, &snum) ) return WERR_BADFID; @@ -3842,11 +3848,11 @@ WERROR _spoolss_rfnpcnex( pipes_struct *p, SPOOL_Q_RFNPCNEX *q_u, SPOOL_R_RFNPCN /* just ignore the SPOOL_NOTIFY_OPTION */ switch (Printer->printer_type) { - case PRINTER_HANDLE_IS_PRINTSERVER: + case SPLHND_SERVER: result = printserver_notify_info(p, handle, info, p->mem_ctx); break; - case PRINTER_HANDLE_IS_PRINTER: + case SPLHND_PRINTER: result = printer_notify_info(p, handle, info, p->mem_ctx); break; } @@ -6287,9 +6293,9 @@ WERROR _spoolss_fcpn(pipes_struct *p, SPOOL_Q_FCPN *q_u, SPOOL_R_FCPN *r_u) if (Printer->notify.client_connected==True) { int snum = -1; - if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) + if ( Printer->printer_type == SPLHND_SERVER) snum = -1; - else if ( (Printer->printer_type == PRINTER_HANDLE_IS_PRINTER) && + else if ( (Printer->printer_type == SPLHND_PRINTER) && !get_printer_snum(p, handle, &snum) ) return WERR_BADFID; @@ -7971,7 +7977,7 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP return WERR_BADFID; } - if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER ) { + if ( Printer->printer_type == SPLHND_SERVER ) { DEBUG(10,("_spoolss_setprinterdata: Not implemented for server handles yet\n")); return WERR_INVALID_PARAM; } @@ -8128,7 +8134,7 @@ WERROR _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM /* forms can be added on printer of on the print server handle */ - if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTER ) + if ( Printer->printer_type == SPLHND_PRINTER ) { if (!get_printer_snum(p,handle, &snum)) return WERR_BADFID; @@ -8164,7 +8170,7 @@ WERROR _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM * ChangeID must always be set if this is a printer */ - if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTER ) + if ( Printer->printer_type == SPLHND_PRINTER ) status = mod_a_printer(printer, 2); done: @@ -8199,7 +8205,7 @@ WERROR _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE /* forms can be deleted on printer of on the print server handle */ - if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTER ) + if ( Printer->printer_type == SPLHND_PRINTER ) { if (!get_printer_snum(p,handle, &snum)) return WERR_BADFID; @@ -8231,7 +8237,7 @@ WERROR _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE * ChangeID must always be set if this is a printer */ - if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTER ) + if ( Printer->printer_type == SPLHND_PRINTER ) status = mod_a_printer(printer, 2); done: @@ -8267,7 +8273,7 @@ WERROR _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM * /* forms can be modified on printer of on the print server handle */ - if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTER ) + if ( Printer->printer_type == SPLHND_PRINTER ) { if (!get_printer_snum(p,handle, &snum)) return WERR_BADFID; @@ -8297,7 +8303,7 @@ WERROR _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM * * ChangeID must always be set if this is a printer */ - if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTER ) + if ( Printer->printer_type == SPLHND_PRINTER ) status = mod_a_printer(printer, 2); @@ -8824,7 +8830,7 @@ WERROR _spoolss_getprinterdataex(pipes_struct *p, SPOOL_Q_GETPRINTERDATAEX *q_u, /* Is the handle to a printer or to the server? */ - if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER) { + if (Printer->printer_type == SPLHND_SERVER) { DEBUG(10,("_spoolss_getprinterdataex: Not implemented for server handles yet\n")); status = WERR_INVALID_PARAM; goto done; @@ -8911,7 +8917,7 @@ WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, return WERR_BADFID; } - if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER ) { + if ( Printer->printer_type == SPLHND_SERVER ) { DEBUG(10,("_spoolss_setprinterdataex: Not implemented for server handles yet\n")); return WERR_INVALID_PARAM; } @@ -9379,9 +9385,66 @@ WERROR _spoolss_getprintprocessordirectory(pipes_struct *p, SPOOL_Q_GETPRINTPROC return result; } -WERROR _spoolss_xcvdataport(pipes_struct *p, SPOOL_Q_XCVDATAPORT *q_u, SPOOL_R_XCVDATAPORT *r_u) +/******************************************************************* +*******************************************************************/ + +static WERROR process_xcvtcp_command( const char *command, RPC_BUFFER *inbuf, RPC_BUFFER *outbuf ) +{ + DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command)); + + return WERR_OK; +} + +/******************************************************************* +*******************************************************************/ + +static WERROR process_xcvlocal_command( const char *command, RPC_BUFFER *inbuf, RPC_BUFFER *outbuf ) { + DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command)); + return WERR_OK; } +/******************************************************************* +*******************************************************************/ + +WERROR _spoolss_xcvdataport(pipes_struct *p, SPOOL_Q_XCVDATAPORT *q_u, SPOOL_R_XCVDATAPORT *r_u) +{ + Printer_entry *Printer = find_printer_index_by_hnd(p, &q_u->handle); + fstring command; + + if (!Printer) { + DEBUG(2,("_spoolss_xcvdataport: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(&q_u->handle))); + return WERR_BADFID; + } + + /* Has to be a handle to the TCP/IP port monitor */ + + if ( Printer->printer_type != SPLHND_PORTMON_TCP ) { + DEBUG(2,("_spoolss_xcvdataport: Call only valid for the TCP/IP Port Monitor\n")); + return WERR_BADFID; + } + + /* requires administrative access to the server */ + + if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) { + DEBUG(2,("_spoolss_xcvdataport: denied by handle permissions.\n")); + return WERR_ACCESS_DENIED; + } + + /* Get the command name. There's numerous commands supported by the + TCPMON interface. */ + + rpcstr_pull(command, q_u->dataname.buffer, sizeof(command), q_u->dataname.uni_str_len*2, 0); + + switch ( Printer->printer_type ) { + case SPLHND_PORTMON_TCP: + return process_xcvtcp_command( command, &q_u->indata, &r_u->outdata ); + case SPLHND_PORTMON_LOCAL: + return process_xcvlocal_command( command, &q_u->indata, &r_u->outdata ); + } + + return WERR_INVALID_PRINT_MONITOR; +} + -- cgit From 2a7847ea378ca71e7901c1bed6fdcf87ff8f1d70 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 3 Mar 2006 19:39:59 +0000 Subject: r13821: replacing some strings with macros (This used to be commit a34ab5c827630a5517e4c706877a172e6063f227) --- source3/rpc_server/srv_spoolss_nt.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 2f2f599f43..98abd9d15e 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -7147,13 +7147,15 @@ static void fill_port_1(PORT_INFO_1 *port, const char *name) } /**************************************************************************** + TODO: This probably needs distinguish between TCP/IP and Local ports + somehow. ****************************************************************************/ static void fill_port_2(PORT_INFO_2 *port, const char *name) { init_unistr(&port->port_name, name); init_unistr(&port->monitor_name, "Local Monitor"); - init_unistr(&port->description, "Local Port"); + init_unistr(&port->description, SPL_LOCAL_PORT ); port->port_type=PORT_TYPE_WRITE; port->reserved=0x0; } @@ -8477,8 +8479,8 @@ static WERROR enumprintmonitors_level_1(RPC_BUFFER *buffer, uint32 offered, uint *returned = 2; - init_unistr(&(info_1[0].name), "Local Port"); - init_unistr(&(info_1[1].name), "Standard TCP/IP Port"); + init_unistr(&(info_1[0].name), SPL_LOCAL_PORT ); + init_unistr(&(info_1[1].name), SPL_TCPIP_PORT ); for ( i=0; i<*returned; i++ ) { *needed += spoolss_size_printmonitor_info_1(&info_1[i]); @@ -8522,13 +8524,13 @@ static WERROR enumprintmonitors_level_2(RPC_BUFFER *buffer, uint32 offered, uint *returned = 2; - init_unistr(&(info_2[0].name), "Local Port"); - init_unistr(&(info_2[0].environment), "Windows NT X86"); - init_unistr(&(info_2[0].dll_name), "localmon.dll"); + init_unistr( &(info_2[0].name), SPL_LOCAL_PORT ); + init_unistr( &(info_2[0].environment), "Windows NT X86" ); + init_unistr( &(info_2[0].dll_name), "localmon.dll" ); - init_unistr(&(info_2[1].name), "Standard TCP/IP Port"); - init_unistr(&(info_2[1].environment), "Windows NT X86"); - init_unistr(&(info_2[1].dll_name), "tcpmon.dll"); + init_unistr( &(info_2[1].name), SPL_TCPIP_PORT ); + init_unistr( &(info_2[1].environment), "Windows NT X86" ); + init_unistr( &(info_2[1].dll_name), "tcpmon.dll" ); for ( i=0; i<*returned; i++ ) { *needed += spoolss_size_printmonitor_info_2(&info_2[i]); -- cgit From 889ff32b5eb6ac60bc6f490ceb85dceee77c18d9 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 3 Mar 2006 20:49:31 +0000 Subject: r13824: * add api table for Xcv TCPMON and LOCALMON calls starting with the "MonitorUI" call * Fix some parsing errors This gets us to the Add Port Wizard dialog. (This used to be commit a444aa7f0088fb71ff89df8c280209188b33ec3d) --- source3/rpc_server/srv_spoolss_nt.c | 101 +++++++++++++++++++++++++++++++++--- 1 file changed, 93 insertions(+), 8 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 98abd9d15e..126c2cc140 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -86,6 +86,15 @@ extern STANDARD_MAPPING printer_std_mapping, printserver_std_mapping; #define OUR_HANDLE(hnd) (((hnd)==NULL)?"NULL":(IVAL((hnd)->data5,4)==(uint32)sys_getpid()?"OURS":"OTHER")), \ ((unsigned int)IVAL((hnd)->data5,4)),((unsigned int)sys_getpid()) + +/* API table for Xcv Monitor functions */ + +struct xcv_api_table { + const char *name; + WERROR(*fn) (RPC_BUFFER *in, RPC_BUFFER *out, uint32 *needed); +}; + + /* translate between internal status numbers and NT status numbers */ static int nt_printj_status(int v) { @@ -9387,24 +9396,95 @@ WERROR _spoolss_getprintprocessordirectory(pipes_struct *p, SPOOL_Q_GETPRINTPROC return result; } +/******************************************************************* + Streams the monitor UI DLL name in UNICODE +*******************************************************************/ + +static WERROR xcvtcp_monitorui( RPC_BUFFER *in, RPC_BUFFER *out, uint32 *needed ) +{ + const char *dllname = "tcpmonui.dll"; + + *needed = (strlen(dllname)+1) * 2; + + if ( rpcbuf_get_size(out) < *needed ) { + return WERR_INSUFFICIENT_BUFFER; + } + + if ( !make_monitorui_buf( out, dllname ) ) { + return WERR_NOMEM; + } + + return WERR_OK; +} + /******************************************************************* *******************************************************************/ -static WERROR process_xcvtcp_command( const char *command, RPC_BUFFER *inbuf, RPC_BUFFER *outbuf ) +struct xcv_api_table xcvtcp_cmds[] = { + { "MonitorUI", xcvtcp_monitorui }, + { NULL, NULL } +}; + +static WERROR process_xcvtcp_command( const char *command, RPC_BUFFER *inbuf, + RPC_BUFFER *outbuf, uint32 *needed ) { + int i; + DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command)); + for ( i=0; xcvtcp_cmds[i].name; i++ ) { + if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 ) + return xcvtcp_cmds[i].fn( inbuf, outbuf, needed ); + } + + return WERR_BADFUNC; +} + +/******************************************************************* +*******************************************************************/ + +static WERROR xcvlocal_monitorui( RPC_BUFFER *in, RPC_BUFFER *out, uint32 *needed ) +{ + const char *dllname = "localui.dll"; + + *needed = (strlen(dllname)+1) * 2; + + if ( rpcbuf_get_size(out) < *needed ) { + return WERR_INSUFFICIENT_BUFFER; + } + + if ( !make_monitorui_buf( out, dllname )) { + return WERR_NOMEM; + } + return WERR_OK; } /******************************************************************* *******************************************************************/ -static WERROR process_xcvlocal_command( const char *command, RPC_BUFFER *inbuf, RPC_BUFFER *outbuf ) +struct xcv_api_table xcvlocal_cmds[] = { + { "MonitorUI", xcvlocal_monitorui }, + { NULL, NULL } +}; + + +/******************************************************************* +*******************************************************************/ + +static WERROR process_xcvlocal_command( const char *command, RPC_BUFFER *inbuf, + RPC_BUFFER *outbuf, uint32 *needed ) { + int i; + DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command)); - return WERR_OK; + + for ( i=0; xcvlocal_cmds[i].name; i++ ) { + if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 ) + return xcvlocal_cmds[i].fn( inbuf, outbuf , needed ); + } + return WERR_BADFUNC; } /******************************************************************* @@ -9422,8 +9502,8 @@ WERROR _spoolss_xcvdataport(pipes_struct *p, SPOOL_Q_XCVDATAPORT *q_u, SPOOL_R_X /* Has to be a handle to the TCP/IP port monitor */ - if ( Printer->printer_type != SPLHND_PORTMON_TCP ) { - DEBUG(2,("_spoolss_xcvdataport: Call only valid for the TCP/IP Port Monitor\n")); + if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) { + DEBUG(2,("_spoolss_xcvdataport: Call only valid for Port Monitors\n")); return WERR_BADFID; } @@ -9437,13 +9517,18 @@ WERROR _spoolss_xcvdataport(pipes_struct *p, SPOOL_Q_XCVDATAPORT *q_u, SPOOL_R_X /* Get the command name. There's numerous commands supported by the TCPMON interface. */ - rpcstr_pull(command, q_u->dataname.buffer, sizeof(command), q_u->dataname.uni_str_len*2, 0); + rpcstr_pull(command, q_u->dataname.buffer, sizeof(command), + q_u->dataname.uni_str_len*2, 0); + + /* Allocate the outgoing buffer */ + + rpcbuf_init( &r_u->outdata, q_u->offered, p->mem_ctx ); switch ( Printer->printer_type ) { case SPLHND_PORTMON_TCP: - return process_xcvtcp_command( command, &q_u->indata, &r_u->outdata ); + return process_xcvtcp_command( command, &q_u->indata, &r_u->outdata, &r_u->needed ); case SPLHND_PORTMON_LOCAL: - return process_xcvlocal_command( command, &q_u->indata, &r_u->outdata ); + return process_xcvlocal_command( command, &q_u->indata, &r_u->outdata, &r_u->needed ); } return WERR_INVALID_PRINT_MONITOR; -- cgit From 5df58c38f3c29d87c5918d1611c17e016c6f7545 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sat, 4 Mar 2006 00:05:40 +0000 Subject: r13829: From the "It's not pretty but it works" category * Finish prototype of the "add port command" implementation Format is "addportcommand portname deviceURI" * DeviceURI is either - socket://hostname:port/ - lpr://hostname/queue depending on what the client sent in the request (This used to be commit 6d74de7a676b71e83a3c3714743e6380c04e4425) --- source3/rpc_server/srv_spoolss_nt.c | 112 ++++++++++++++++++++++++++++++++---- 1 file changed, 101 insertions(+), 11 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 126c2cc140..a9d4e14aae 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -91,7 +91,7 @@ extern STANDARD_MAPPING printer_std_mapping, printserver_std_mapping; struct xcv_api_table { const char *name; - WERROR(*fn) (RPC_BUFFER *in, RPC_BUFFER *out, uint32 *needed); + WERROR(*fn) (NT_USER_TOKEN *token, RPC_BUFFER *in, RPC_BUFFER *out, uint32 *needed); }; @@ -5956,6 +5956,52 @@ static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) /**************************************************************************** ****************************************************************************/ +WERROR add_port_hook(NT_USER_TOKEN *token, const char *portname, const char *uri ) +{ + char *cmd = lp_addport_cmd(); + pstring command; + int ret; + int fd; + SE_PRIV se_printop = SE_PRINT_OPERATOR; + BOOL is_print_op = False; + + if ( !*cmd ) { + return WERR_ACCESS_DENIED; + } + + slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\"", cmd, portname, uri ); + + if ( token ) + is_print_op = user_has_privileges( token, &se_printop ); + + DEBUG(10,("Running [%s]\n", command)); + + /********* BEGIN SePrintOperatorPrivilege **********/ + + if ( is_print_op ) + become_root(); + + ret = smbrun(command, &fd); + + if ( is_print_op ) + unbecome_root(); + + /********* END SePrintOperatorPrivilege **********/ + + DEBUGADD(10,("returned [%d]\n", ret)); + + if ( ret != 0 ) { + if (fd != -1) + close(fd); + return WERR_ACCESS_DENIED; + } + + return WERR_OK; +} + +/**************************************************************************** +****************************************************************************/ + BOOL add_printer_hook(NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer) { char *cmd = lp_addprinter_cmd(); @@ -6025,6 +6071,7 @@ BOOL add_printer_hook(NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer) return True; } + /******************************************************************** * Called by spoolss_api_setprinter * when updating a printer description. @@ -9400,7 +9447,8 @@ WERROR _spoolss_getprintprocessordirectory(pipes_struct *p, SPOOL_Q_GETPRINTPROC Streams the monitor UI DLL name in UNICODE *******************************************************************/ -static WERROR xcvtcp_monitorui( RPC_BUFFER *in, RPC_BUFFER *out, uint32 *needed ) +static WERROR xcvtcp_monitorui( NT_USER_TOKEN *token, RPC_BUFFER *in, + RPC_BUFFER *out, uint32 *needed ) { const char *dllname = "tcpmonui.dll"; @@ -9417,16 +9465,54 @@ static WERROR xcvtcp_monitorui( RPC_BUFFER *in, RPC_BUFFER *out, uint32 *needed return WERR_OK; } +/******************************************************************* + Create a new TCP/IP port +*******************************************************************/ + +static WERROR xcvtcp_addport( NT_USER_TOKEN *token, RPC_BUFFER *in, + RPC_BUFFER *out, uint32 *needed ) +{ + NT_PORT_DATA_1 port1; + pstring device_uri; + + ZERO_STRUCT( port1 ); + + /* convert to our internal port data structure */ + + if ( !convert_port_data_1( &port1, in ) ) { + return WERR_NOMEM; + } + + /* create the device URI and call the add_port_hook() */ + + switch ( port1.protocol ) { + case PORT_PROTOCOL_DIRECT: + pstr_sprintf( device_uri, "socket://%s:%d/", port1.hostaddr, port1.port ); + break; + + case PORT_PROTOCOL_LPR: + pstr_sprintf( device_uri, "lpr://%s/%s", port1.hostaddr, port1.queue ); + break; + + default: + return WERR_UNKNOWN_PORT; + } + + return add_port_hook( token, port1.name, device_uri ); +} + /******************************************************************* *******************************************************************/ struct xcv_api_table xcvtcp_cmds[] = { { "MonitorUI", xcvtcp_monitorui }, + { "AddPort", xcvtcp_addport}, { NULL, NULL } }; -static WERROR process_xcvtcp_command( const char *command, RPC_BUFFER *inbuf, - RPC_BUFFER *outbuf, uint32 *needed ) +static WERROR process_xcvtcp_command( NT_USER_TOKEN *token, const char *command, + RPC_BUFFER *inbuf, RPC_BUFFER *outbuf, + uint32 *needed ) { int i; @@ -9434,7 +9520,7 @@ static WERROR process_xcvtcp_command( const char *command, RPC_BUFFER *inbuf, for ( i=0; xcvtcp_cmds[i].name; i++ ) { if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 ) - return xcvtcp_cmds[i].fn( inbuf, outbuf, needed ); + return xcvtcp_cmds[i].fn( token, inbuf, outbuf, needed ); } return WERR_BADFUNC; @@ -9443,7 +9529,8 @@ static WERROR process_xcvtcp_command( const char *command, RPC_BUFFER *inbuf, /******************************************************************* *******************************************************************/ -static WERROR xcvlocal_monitorui( RPC_BUFFER *in, RPC_BUFFER *out, uint32 *needed ) +static WERROR xcvlocal_monitorui( NT_USER_TOKEN *token, RPC_BUFFER *in, + RPC_BUFFER *out, uint32 *needed ) { const char *dllname = "localui.dll"; @@ -9472,8 +9559,9 @@ struct xcv_api_table xcvlocal_cmds[] = { /******************************************************************* *******************************************************************/ -static WERROR process_xcvlocal_command( const char *command, RPC_BUFFER *inbuf, - RPC_BUFFER *outbuf, uint32 *needed ) +static WERROR process_xcvlocal_command( NT_USER_TOKEN *token, const char *command, + RPC_BUFFER *inbuf, RPC_BUFFER *outbuf, + uint32 *needed ) { int i; @@ -9482,7 +9570,7 @@ static WERROR process_xcvlocal_command( const char *command, RPC_BUFFER *inbuf, for ( i=0; xcvlocal_cmds[i].name; i++ ) { if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 ) - return xcvlocal_cmds[i].fn( inbuf, outbuf , needed ); + return xcvlocal_cmds[i].fn( token, inbuf, outbuf , needed ); } return WERR_BADFUNC; } @@ -9526,9 +9614,11 @@ WERROR _spoolss_xcvdataport(pipes_struct *p, SPOOL_Q_XCVDATAPORT *q_u, SPOOL_R_X switch ( Printer->printer_type ) { case SPLHND_PORTMON_TCP: - return process_xcvtcp_command( command, &q_u->indata, &r_u->outdata, &r_u->needed ); + return process_xcvtcp_command( p->pipe_user.nt_user_token, command, + &q_u->indata, &r_u->outdata, &r_u->needed ); case SPLHND_PORTMON_LOCAL: - return process_xcvlocal_command( command, &q_u->indata, &r_u->outdata, &r_u->needed ); + return process_xcvlocal_command( p->pipe_user.nt_user_token, command, + &q_u->indata, &r_u->outdata, &r_u->needed ); } return WERR_INVALID_PRINT_MONITOR; -- cgit From 129fd6c5c641cf4c2db31eb093baebd08df63107 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 6 Mar 2006 18:40:00 +0000 Subject: r13878: move PORT_DATA_1 to use static sized UNICODE strings as per MSDN (This used to be commit c803e1b2afdfc5bd983f046c976c01adebcfa1ad) --- source3/rpc_server/srv_spoolss_nt.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a9d4e14aae..938658c479 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -9528,6 +9528,7 @@ static WERROR process_xcvtcp_command( NT_USER_TOKEN *token, const char *command, /******************************************************************* *******************************************************************/ +#if 0 /* don't support management using the "Local Port" monitor */ static WERROR xcvlocal_monitorui( NT_USER_TOKEN *token, RPC_BUFFER *in, RPC_BUFFER *out, uint32 *needed ) @@ -9554,6 +9555,12 @@ struct xcv_api_table xcvlocal_cmds[] = { { "MonitorUI", xcvlocal_monitorui }, { NULL, NULL } }; +#else +struct xcv_api_table xcvlocal_cmds[] = { + { NULL, NULL } +}; +#endif + /******************************************************************* @@ -9566,7 +9573,6 @@ static WERROR process_xcvlocal_command( NT_USER_TOKEN *token, const char *comman int i; DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command)); - for ( i=0; xcvlocal_cmds[i].name; i++ ) { if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 ) -- cgit From 894358a8f3e338b339b6c37233edef794b312087 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 7 Mar 2006 06:31:04 +0000 Subject: r13915: Fixed a very interesting class of realloc() bugs found by Coverity. realloc can return NULL in one of two cases - (1) the realloc failed, (2) realloc succeeded but the new size requested was zero, in which case this is identical to a free() call. The error paths dealing with these two cases should be different, but mostly weren't. Secondly the standard idiom for dealing with realloc when you know the new size is non-zero is the following : tmp = realloc(p, size); if (!tmp) { SAFE_FREE(p); return error; } else { p = tmp; } However, there were *many* *many* places in Samba where we were using the old (broken) idiom of : p = realloc(p, size) if (!p) { return error; } which will leak the memory pointed to by p on realloc fail. This commit (hopefully) fixes all these cases by moving to a standard idiom of : p = SMB_REALLOC(p, size) if (!p) { return error; } Where if the realloc returns null due to the realloc failing or size == 0 we *guarentee* that the storage pointed to by p has been freed. This allows me to remove a lot of code that was dealing with the standard (more verbose) method that required a tmp pointer. This is almost always what you want. When a realloc fails you never usually want the old memory, you want to free it and get into your error processing asap. For the 11 remaining cases where we really do need to keep the old pointer I have invented the new macro SMB_REALLOC_KEEP_OLD_ON_ERROR, which can be used as follows : tmp = SMB_REALLOC_KEEP_OLD_ON_ERROR(p, size); if (!tmp) { SAFE_FREE(p); return error; } else { p = tmp; } SMB_REALLOC_KEEP_OLD_ON_ERROR guarentees never to free the pointer p, even on size == 0 or realloc fail. All this is done by a hidden extra argument to Realloc(), BOOL free_old_on_error which is set appropriately by the SMB_REALLOC and SMB_REALLOC_KEEP_OLD_ON_ERROR macros (and their array counterparts). It remains to be seen what this will do to our Coverity bug count :-). Jeremy. (This used to be commit 1d710d06a214f3f1740e80e0bffd6aab44aac2b0) --- source3/rpc_server/srv_spoolss_nt.c | 55 ++++++++++++++----------------------- 1 file changed, 20 insertions(+), 35 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 938658c479..cc51df98c1 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3540,7 +3540,7 @@ static BOOL construct_notify_printer_info(Printer_entry *print_hnd, SPOOL_NOTIFY uint16 type; uint16 field; - SPOOL_NOTIFY_INFO_DATA *current_data, *tid; + SPOOL_NOTIFY_INFO_DATA *current_data; NT_PRINTER_INFO_LEVEL *printer = NULL; print_queue_struct *queue=NULL; @@ -3561,11 +3561,10 @@ static BOOL construct_notify_printer_info(Printer_entry *print_hnd, SPOOL_NOTIFY if (!search_notify(type, field, &j) ) continue; - if((tid=SMB_REALLOC_ARRAY(info->data, SPOOL_NOTIFY_INFO_DATA, info->count+1)) == NULL) { + if((info->data=SMB_REALLOC_ARRAY(info->data, SPOOL_NOTIFY_INFO_DATA, info->count+1)) == NULL) { DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n")); return False; - } else - info->data = tid; + } current_data = &info->data[info->count]; @@ -3601,7 +3600,7 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, uint16 type; uint16 field; - SPOOL_NOTIFY_INFO_DATA *current_data, *tid; + SPOOL_NOTIFY_INFO_DATA *current_data; DEBUG(4,("construct_notify_jobs_info\n")); @@ -3617,11 +3616,10 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue, if (!search_notify(type, field, &j) ) continue; - if((tid=SMB_REALLOC_ARRAY(info->data, SPOOL_NOTIFY_INFO_DATA, info->count+1)) == NULL) { + if((info->data=SMB_REALLOC_ARRAY(info->data, SPOOL_NOTIFY_INFO_DATA, info->count+1)) == NULL) { DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n")); return False; } - else info->data = tid; current_data=&(info->data[info->count]); @@ -4296,7 +4294,7 @@ static WERROR enum_all_printers_info_1(uint32 flags, RPC_BUFFER *buffer, uint32 int snum; int i; int n_services=lp_numservices(); - PRINTER_INFO_1 *tp, *printers=NULL; + PRINTER_INFO_1 *printers=NULL; PRINTER_INFO_1 current_prt; WERROR result = WERR_OK; @@ -4307,13 +4305,11 @@ static WERROR enum_all_printers_info_1(uint32 flags, RPC_BUFFER *buffer, uint32 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum)); if (construct_printer_info_1(NULL, flags, ¤t_prt, snum)) { - if((tp=SMB_REALLOC_ARRAY(printers, PRINTER_INFO_1, *returned +1)) == NULL) { + if((printers=SMB_REALLOC_ARRAY(printers, PRINTER_INFO_1, *returned +1)) == NULL) { DEBUG(2,("enum_all_printers_info_1: failed to enlarge printers buffer!\n")); - SAFE_FREE(printers); *returned=0; return WERR_NOMEM; } - else printers = tp; DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_1\n", *returned)); memcpy(&printers[*returned], ¤t_prt, sizeof(PRINTER_INFO_1)); @@ -4484,7 +4480,7 @@ static WERROR enum_all_printers_info_2(RPC_BUFFER *buffer, uint32 offered, uint3 int snum; int i; int n_services=lp_numservices(); - PRINTER_INFO_2 *tp, *printers=NULL; + PRINTER_INFO_2 *printers=NULL; PRINTER_INFO_2 current_prt; WERROR result = WERR_OK; @@ -4492,18 +4488,15 @@ static WERROR enum_all_printers_info_2(RPC_BUFFER *buffer, uint32 offered, uint3 if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) { DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum)); - if (construct_printer_info_2(NULL, ¤t_prt, snum)) - { - if ( !(tp=SMB_REALLOC_ARRAY(printers, PRINTER_INFO_2, *returned +1)) ) { + if (construct_printer_info_2(NULL, ¤t_prt, snum)) { + if ( !(printers=SMB_REALLOC_ARRAY(printers, PRINTER_INFO_2, *returned +1)) ) { DEBUG(2,("enum_all_printers_info_2: failed to enlarge printers buffer!\n")); - SAFE_FREE(printers); *returned = 0; return WERR_NOMEM; } - DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_2\n", *returned)); + DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_2\n", *returned + 1)); - printers = tp; memcpy(&printers[*returned], ¤t_prt, sizeof(PRINTER_INFO_2)); (*returned)++; @@ -5074,7 +5067,6 @@ static uint32 init_unistr_array(uint16 **uni_array, fstring *char_array, const c int j=0; const char *v; pstring line; - uint16 *tuary; DEBUG(6,("init_unistr_array\n")); *uni_array=NULL; @@ -5102,12 +5094,11 @@ static uint32 init_unistr_array(uint16 **uni_array, fstring *char_array, const c /* add one extra unit16 for the second terminating NULL */ - if ( (tuary=SMB_REALLOC_ARRAY(*uni_array, uint16, j+1+strlen(line)+2)) == NULL ) { + if ( (*uni_array=SMB_REALLOC_ARRAY(*uni_array, uint16, j+1+strlen(line)+2)) == NULL ) { DEBUG(2,("init_unistr_array: Realloc error\n" )); return 0; - } else - *uni_array = tuary; - + } + if ( !strlen(v) ) break; @@ -6699,7 +6690,7 @@ static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture uint32 version; fstring *list = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; - DRIVER_INFO_1 *tdi1, *driver_info_1=NULL; + DRIVER_INFO_1 *driver_info_1=NULL; WERROR result = WERR_OK; *returned=0; @@ -6713,13 +6704,11 @@ static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture return WERR_NOMEM; if(ndrivers != 0) { - if((tdi1=SMB_REALLOC_ARRAY(driver_info_1, DRIVER_INFO_1, *returned+ndrivers )) == NULL) { + if((driver_info_1=SMB_REALLOC_ARRAY(driver_info_1, DRIVER_INFO_1, *returned+ndrivers )) == NULL) { DEBUG(0,("enumprinterdrivers_level1: failed to enlarge driver info buffer!\n")); - SAFE_FREE(driver_info_1); SAFE_FREE(list); return WERR_NOMEM; } - else driver_info_1 = tdi1; } for (i=0; i Date: Tue, 7 Mar 2006 21:13:19 +0000 Subject: r13994: Belt and braces - ensure RPC_BUFFER is valid. Jeremy. (This used to be commit d993797191865878ebfd2ff9028d341017605cd6) --- source3/rpc_server/srv_spoolss_nt.c | 119 +++++++++++++++++++++++------------- 1 file changed, 75 insertions(+), 44 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index cc51df98c1..6a1be53738 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4624,11 +4624,13 @@ WERROR _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOOL_ /* that's an [in out] buffer */ - if ( q_u->buffer ) { - rpcbuf_move(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + if (!q_u->buffer) { + return WERR_INVALID_PARAM; } + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + DEBUG(4,("_spoolss_enumprinters\n")); *needed=0; @@ -4933,11 +4935,13 @@ WERROR _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GET /* that's an [in out] buffer */ - if ( q_u->buffer ) { - rpcbuf_move(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + if (!q_u->buffer) { + return WERR_INVALID_PARAM; } + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + *needed=0; if (!get_printer_snum(p, handle, &snum)) @@ -5530,11 +5534,13 @@ WERROR _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_ /* that's an [in out] buffer */ - if ( q_u->buffer ) { - rpcbuf_move(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + if (!q_u->buffer) { + return WERR_INVALID_PARAM; } + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + DEBUG(4,("_spoolss_getprinterdriver2\n")); if ( !(printer = find_printer_index_by_hnd( p, handle )) ) { @@ -6367,8 +6373,11 @@ WERROR _spoolss_addjob(pipes_struct *p, SPOOL_Q_ADDJOB *q_u, SPOOL_R_ADDJOB *r_u { /* that's an [in out] buffer */ - if ( q_u->buffer ) - rpcbuf_move(q_u->buffer, &r_u->buffer); + if (!q_u->buffer) { + return WERR_INVALID_PARAM; + } + + rpcbuf_move(q_u->buffer, &r_u->buffer); r_u->needed = 0; return WERR_INVALID_PARAM; /* this is what a NT server @@ -6579,11 +6588,13 @@ WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO /* that's an [in out] buffer */ - if ( q_u->buffer ) { - rpcbuf_move(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + if (!q_u->buffer) { + return WERR_INVALID_PARAM; } + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + DEBUG(4,("_spoolss_enumjobs\n")); *needed=0; @@ -6944,11 +6955,13 @@ WERROR _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS /* that's an [in out] buffer */ - if ( q_u->buffer ) { - rpcbuf_move(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + if (!q_u->buffer) { + return WERR_INVALID_PARAM; } + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + DEBUG(4,("_spoolss_enumprinterdrivers\n")); *needed = 0; @@ -7007,11 +7020,13 @@ WERROR _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMF /* that's an [in out] buffer */ - if ( q_u->buffer ) { - rpcbuf_move(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + if (!q_u->buffer) { + return WERR_INVALID_PARAM; } + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + DEBUG(4,("_spoolss_enumforms\n")); DEBUGADD(5,("Offered buffer size [%d]\n", offered)); DEBUGADD(5,("Info level [%d]\n", level)); @@ -7114,11 +7129,13 @@ WERROR _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * /* that's an [in out] buffer */ - if ( q_u->buffer ) { - rpcbuf_move(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + if (!q_u->buffer) { + return WERR_INVALID_PARAM; } + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + unistr2_to_ascii(form_name, uni_formname, sizeof(form_name)-1); DEBUG(4,("_spoolss_getform\n")); @@ -7392,11 +7409,13 @@ WERROR _spoolss_enumports( pipes_struct *p, SPOOL_Q_ENUMPORTS *q_u, SPOOL_R_ENUM /* that's an [in out] buffer */ - if ( q_u->buffer ) { - rpcbuf_move(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + if (!q_u->buffer) { + return WERR_INVALID_PARAM; } + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + DEBUG(4,("_spoolss_enumports\n")); *returned=0; @@ -7800,11 +7819,13 @@ WERROR _spoolss_getprinterdriverdirectory(pipes_struct *p, SPOOL_Q_GETPRINTERDRI /* that's an [in out] buffer */ - if ( q_u->buffer ) { - rpcbuf_move(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + if (!q_u->buffer ) { + return WERR_INVALID_PARAM; } + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + DEBUG(4,("_spoolss_getprinterdriverdirectory\n")); *needed=0; @@ -8410,11 +8431,13 @@ WERROR _spoolss_enumprintprocessors(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCESSORS /* that's an [in out] buffer */ - if ( q_u->buffer ) { - rpcbuf_move(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + if (!q_u->buffer) { + return WERR_INVALID_PARAM; } + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + DEBUG(5,("spoolss_enumprintprocessors\n")); /* @@ -8487,11 +8510,13 @@ WERROR _spoolss_enumprintprocdatatypes(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCDAT /* that's an [in out] buffer */ - if ( q_u->buffer ) { - rpcbuf_move(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + if (!q_u->buffer) { + return WERR_INVALID_PARAM; } + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + DEBUG(5,("_spoolss_enumprintprocdatatypes\n")); *returned=0; @@ -8613,11 +8638,13 @@ WERROR _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS *q_ /* that's an [in out] buffer */ - if ( q_u->buffer ) { - rpcbuf_move(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + if (!q_u->buffer) { + return WERR_INVALID_PARAM; } + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + DEBUG(5,("spoolss_enumprintmonitors\n")); /* @@ -8787,11 +8814,13 @@ WERROR _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_ /* that's an [in out] buffer */ - if ( q_u->buffer ) { - rpcbuf_move(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + if (!q_u->buffer) { + return WERR_INVALID_PARAM; } + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + DEBUG(5,("spoolss_getjob\n")); *needed = 0; @@ -9407,11 +9436,13 @@ WERROR _spoolss_getprintprocessordirectory(pipes_struct *p, SPOOL_Q_GETPRINTPROC /* that's an [in out] buffer */ - if ( q_u->buffer ) { - rpcbuf_move(q_u->buffer, &r_u->buffer); - buffer = r_u->buffer; + if (!q_u->buffer) { + return WERR_INVALID_PARAM; } + rpcbuf_move(q_u->buffer, &r_u->buffer); + buffer = r_u->buffer; + DEBUG(5,("_spoolss_getprintprocessordirectory\n")); *needed=0; -- cgit From 5a1c225c18ee778490c2d6f789afc3fad3a34703 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 10 Mar 2006 23:52:37 +0000 Subject: r14178: Clarify code for Coverity #49. Ensure we know we can't have an uninitialized *returned val. Jeremy. (This used to be commit e83515afd2cb63b0dfa4f7fe00b6b7163bf35f2f) --- source3/rpc_server/srv_spoolss_nt.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 6a1be53738..af413b8b70 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4484,6 +4484,8 @@ static WERROR enum_all_printers_info_2(RPC_BUFFER *buffer, uint32 offered, uint3 PRINTER_INFO_2 current_prt; WERROR result = WERR_OK; + *returned = 0; + for (snum=0; snum Date: Sun, 12 Mar 2006 10:47:02 +0000 Subject: r14233: Fix Coverity bug # 206 (This used to be commit 0dc3030bce7bc7a58c509c70fe503a70db80b62d) --- source3/rpc_server/srv_spoolss_nt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index af413b8b70..2424c46691 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4823,8 +4823,10 @@ static WERROR getprinter_level_4(Printer_entry *print_hnd, int snum, RPC_BUFFER if((printer=SMB_MALLOC_P(PRINTER_INFO_4))==NULL) return WERR_NOMEM; - if (!construct_printer_info_4(print_hnd, printer, snum)) + if (!construct_printer_info_4(print_hnd, printer, snum)) { + SAFE_FREE(printer); return WERR_NOMEM; + } /* check the required size. */ *needed += spoolss_size_printer_info_4(printer); -- cgit From 05b4d0b38e53de20b7aad2bbb3c6a6788d23313f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 12 Mar 2006 19:16:45 +0000 Subject: r14250: Fix coverity bug #107. Resource leak on error path. Jeremy. (This used to be commit ca96c7be778d01594a540917acd3c5c218d6459c) --- source3/rpc_server/srv_spoolss_nt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 2424c46691..951757d4c8 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4862,8 +4862,10 @@ static WERROR getprinter_level_5(Printer_entry *print_hnd, int snum, RPC_BUFFER if((printer=SMB_MALLOC_P(PRINTER_INFO_5))==NULL) return WERR_NOMEM; - if (!construct_printer_info_5(print_hnd, printer, snum)) + if (!construct_printer_info_5(print_hnd, printer, snum)) { + free_printer_info_5(printer); return WERR_NOMEM; + } /* check the required size. */ *needed += spoolss_size_printer_info_5(printer); -- cgit From 65eb331afcabe76ef6a5a688fb2709dad4369295 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 13 Mar 2006 00:23:17 +0000 Subject: r14264: Fix coverity #207. Resource leak on error path. Jeremy. (This used to be commit 0429b6e8c34a99d4b2a9a4849075ef2a5acadf9e) --- source3/rpc_server/srv_spoolss_nt.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 951757d4c8..d31b68d24e 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6900,6 +6900,7 @@ static WERROR enumprinterdrivers_level3(fstring servername, fstring architecture architecture, version); if (!W_ERROR_IS_OK(status)) { SAFE_FREE(list); + SAFE_FREE(driver_info_3); return status; } fill_printer_driver_info_3(&driver_info_3[*returned+i], driver, servername); -- cgit From 88dda37184d4282da1f9facf953003f0d1e82406 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 13 Mar 2006 00:25:04 +0000 Subject: r14266: Fix coverity #205. Resource leak on error path. Jeremy. (This used to be commit 23d69758bbff9687ab508e12931a5a49691d7e0d) --- source3/rpc_server/srv_spoolss_nt.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index d31b68d24e..57ca89379e 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6818,6 +6818,7 @@ static WERROR enumprinterdrivers_level2(fstring servername, fstring architecture architecture, version); if (!W_ERROR_IS_OK(status)) { SAFE_FREE(list); + SAFE_FREE(driver_info_2); return status; } fill_printer_driver_info_2(&driver_info_2[*returned+i], driver, servername); -- cgit From bb0d6f04598ea8eb489137f2a23d98ad9f9a0eee Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 13 Mar 2006 00:26:38 +0000 Subject: r14268: Fix coverity error #204. Resource leak on error path. Jeremy. (This used to be commit 5f74e56b865e0bdde0e574cd5f97cf29b06ad155) --- source3/rpc_server/srv_spoolss_nt.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 57ca89379e..e86b36a5fe 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6736,6 +6736,7 @@ static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture architecture, version); if (!W_ERROR_IS_OK(status)) { SAFE_FREE(list); + SAFE_FREE(driver_info_1); return status; } fill_printer_driver_info_1(&driver_info_1[*returned+i], driver, servername, architecture ); -- cgit From e4600491cf847668172c37857e972364b87b0c7a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 13 Mar 2006 03:56:24 +0000 Subject: r14284: Fix coverity bug #103. Make code clearer - probably not a real issue but this code is easier to read. Jeremy. (This used to be commit 6621acc68f9a65540330d5c0d07db2488a3e8678) --- source3/rpc_server/srv_spoolss_nt.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index e86b36a5fe..475862bc4c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -7241,6 +7241,8 @@ WERROR enumports_hook( int *count, char ***lines ) int ret; int fd; + *count = 0; + *lines = NULL; /* if no hook then just fill in the default port */ @@ -7259,9 +7261,9 @@ WERROR enumports_hook( int *count, char ***lines ) ret = smbrun(command, &fd); DEBUG(10,("Returned [%d]\n", ret)); if (ret != 0) { - if (fd != -1) + if (fd != -1) { close(fd); - + } return WERR_ACCESS_DENIED; } @@ -7289,8 +7291,11 @@ static WERROR enumports_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *need char **qlines; int numlines; - if ( !W_ERROR_IS_OK(result = enumports_hook( &numlines, &qlines )) ) + result = enumports_hook( &numlines, &qlines ); + if (!W_ERROR_IS_OK(result)) { + file_lines_free(qlines); return result; + } if(numlines) { if((ports=SMB_MALLOC_ARRAY( PORT_INFO_1, numlines )) == NULL) { @@ -7304,9 +7309,8 @@ static WERROR enumports_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *need DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i])); fill_port_1(&ports[i], qlines[i]); } - - file_lines_free(qlines); } + file_lines_free(qlines); *returned = numlines; -- cgit From acc651a31be5f099aa5a13ba854b0a130be5d30d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 13 Mar 2006 03:59:53 +0000 Subject: r14286: Similar clarifiction fix for coverity #102. Jeremy. (This used to be commit f458596b0edd958321c5d4061f034846348a3fe6) --- source3/rpc_server/srv_spoolss_nt.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 475862bc4c..573603b659 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -7288,8 +7288,8 @@ static WERROR enumports_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *need PORT_INFO_1 *ports=NULL; int i=0; WERROR result = WERR_OK; - char **qlines; - int numlines; + char **qlines = NULL; + int numlines = 0; result = enumports_hook( &numlines, &qlines ); if (!W_ERROR_IS_OK(result)) { @@ -7354,12 +7354,14 @@ static WERROR enumports_level_2(RPC_BUFFER *buffer, uint32 offered, uint32 *need PORT_INFO_2 *ports=NULL; int i=0; WERROR result = WERR_OK; - char **qlines; - int numlines; + char **qlines = NULL; + int numlines = 0; - if ( !W_ERROR_IS_OK(result = enumports_hook( &numlines, &qlines )) ) + result = enumports_hook( &numlines, &qlines ); + if ( !W_ERROR_IS_OK(result)) { + file_lines_free(qlines); return result; - + } if(numlines) { if((ports=SMB_MALLOC_ARRAY( PORT_INFO_2, numlines)) == NULL) { @@ -7371,10 +7373,10 @@ static WERROR enumports_level_2(RPC_BUFFER *buffer, uint32 offered, uint32 *need DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i])); fill_port_2(&(ports[i]), qlines[i]); } - - file_lines_free(qlines); } + file_lines_free(qlines); + *returned = numlines; /* check the required size. */ -- cgit From 19879eba8378f58db403c27202b9cc0af60db559 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 13 Mar 2006 04:05:47 +0000 Subject: r14289: Fix coverity #101, resource leak on error code path. Jeremy. (This used to be commit d9e1d6fed099e7651807aa839a743fc7756ee326) --- source3/rpc_server/srv_spoolss_nt.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 573603b659..dd706b68ed 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -7046,12 +7046,17 @@ WERROR _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMF DEBUGADD(5,("Number of user forms [%d]\n", *numofforms)); *numofforms += numbuiltinforms; - if (*numofforms == 0) + if (*numofforms == 0) { + SAFE_FREE(builtinlist); + SAFE_FREE(list); return WERR_NO_MORE_ITEMS; + } switch (level) { case 1: if ((forms_1=SMB_MALLOC_ARRAY(FORM_1, *numofforms)) == NULL) { + SAFE_FREE(builtinlist); + SAFE_FREE(list); *numofforms=0; return WERR_NOMEM; } @@ -7114,7 +7119,6 @@ WERROR _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMF SAFE_FREE(builtinlist); return WERR_UNKNOWN_LEVEL; } - } /**************************************************************************** -- cgit From 860015db1fe89944e37163234505d26b7cfe5386 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 13 Mar 2006 06:48:41 +0000 Subject: r14299: Fix coverity #225. In a loop we were forgetting to free resources on error exit path. Jeremy. (This used to be commit 1c0b4ed0acdb7fccb148d714796752fefc6dd78c) --- source3/rpc_server/srv_spoolss_nt.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index dd706b68ed..57509fcd87 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6871,8 +6871,8 @@ static WERROR enumprinterdrivers_level3(fstring servername, fstring architecture int ndrivers; uint32 version; fstring *list = NULL; - NT_PRINTER_DRIVER_INFO_LEVEL driver; DRIVER_INFO_3 *driver_info_3=NULL; + NT_PRINTER_DRIVER_INFO_LEVEL driver; WERROR result = WERR_OK; *returned=0; @@ -6882,8 +6882,10 @@ static WERROR enumprinterdrivers_level3(fstring servername, fstring architecture ndrivers=get_ntdrivers(&list, architecture, version); DEBUGADD(4,("we have:[%d] drivers in environment [%s] and version [%d]\n", ndrivers, architecture, version)); - if(ndrivers == -1) + if(ndrivers == -1) { + SAFE_FREE(driver_info_3); return WERR_NOMEM; + } if(ndrivers != 0) { if((driver_info_3=SMB_REALLOC_ARRAY(driver_info_3, DRIVER_INFO_3, *returned+ndrivers )) == NULL) { @@ -6936,8 +6938,9 @@ static WERROR enumprinterdrivers_level3(fstring servername, fstring architecture } out: - for (i=0; i<*returned; i++) + for (i=0; i<*returned; i++) { SAFE_FREE(driver_info_3[i].dependentfiles); + } SAFE_FREE(driver_info_3); -- cgit From ad838bf65e3e67a0a19cd3be4c969a01928f9636 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 13 Mar 2006 06:50:33 +0000 Subject: r14301: Fix coverity #224. In a loop we were forgetting to free resources on error exit path. Jeremy. (This used to be commit f1a5e5aefeeb78512c41cc8fc075b240696a3eb7) --- source3/rpc_server/srv_spoolss_nt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 57509fcd87..31a278f7f3 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6799,8 +6799,10 @@ static WERROR enumprinterdrivers_level2(fstring servername, fstring architecture ndrivers=get_ntdrivers(&list, architecture, version); DEBUGADD(4,("we have:[%d] drivers in environment [%s] and version [%d]\n", ndrivers, architecture, version)); - if(ndrivers == -1) + if(ndrivers == -1) { + SAFE_FREE(driver_info_2); return WERR_NOMEM; + } if(ndrivers != 0) { if((driver_info_2=SMB_REALLOC_ARRAY(driver_info_2, DRIVER_INFO_2, *returned+ndrivers )) == NULL) { -- cgit From d72bb5627ccc14f2396f3e464686b6dfebee6ec5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 13 Mar 2006 06:52:03 +0000 Subject: r14303: Fix coverity #223. In a loop we were forgetting to free resources on error exit path. Jeremy. (This used to be commit f71aa3ab8fdfd08c1bec57b6506ead7c4af7299d) --- source3/rpc_server/srv_spoolss_nt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 31a278f7f3..70432c34ca 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6717,8 +6717,10 @@ static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture ndrivers=get_ntdrivers(&list, architecture, version); DEBUGADD(4,("we have:[%d] drivers in environment [%s] and version [%d]\n", ndrivers, architecture, version)); - if(ndrivers == -1) + if(ndrivers == -1) { + SAFE_FREE(driver_info_1); return WERR_NOMEM; + } if(ndrivers != 0) { if((driver_info_1=SMB_REALLOC_ARRAY(driver_info_1, DRIVER_INFO_1, *returned+ndrivers )) == NULL) { -- cgit From d1684fa82ef8720341179238b65a768777681f34 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 13 Mar 2006 23:07:14 +0000 Subject: r14353: Fix coverity bugs #61 and #62. Remember to divide by the size of the data table. Clean up the struct a little. Jeremy. (This used to be commit 338538410d484a9358b60b05a86180275344ffa4) --- source3/rpc_server/srv_spoolss_nt.c | 45 +++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 25 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 70432c34ca..9fd51c9e27 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3441,25 +3441,22 @@ static uint32 size_of_notify_info_data(uint16 type, uint16 field) { int i=0; - for (i = 0; i < sizeof(notify_info_data_table); i++) - { + for (i = 0; i < (sizeof(notify_info_data_table)/sizeof(struct s_notify_info_data_table)); i++) { if ( (notify_info_data_table[i].type == type) - && (notify_info_data_table[i].field == field) ) - { - switch(notify_info_data_table[i].size) - { - case NOTIFY_ONE_VALUE: - case NOTIFY_TWO_VALUE: - return 1; - case NOTIFY_STRING: - return 2; - - /* The only pointer notify data I have seen on - the wire is the submitted time and this has - the notify size set to 4. -tpot */ - - case NOTIFY_POINTER: - return 4; + && (notify_info_data_table[i].field == field) ) { + switch(notify_info_data_table[i].size) { + case NOTIFY_ONE_VALUE: + case NOTIFY_TWO_VALUE: + return 1; + case NOTIFY_STRING: + return 2; + + /* The only pointer notify data I have seen on + the wire is the submitted time and this has + the notify size set to 4. -tpot */ + + case NOTIFY_POINTER: + return 4; case NOTIFY_SECDESC: return 5; @@ -3476,23 +3473,23 @@ static uint32 size_of_notify_info_data(uint16 type, uint16 field) Return the type of notify_info_data. ********************************************************************/ -static int type_of_notify_info_data(uint16 type, uint16 field) +static uint32 type_of_notify_info_data(uint16 type, uint16 field) { - int i=0; + uint32 i=0; - for (i = 0; i < sizeof(notify_info_data_table); i++) { + for (i = 0; i < (sizeof(notify_info_data_table)/sizeof(struct s_notify_info_data_table)); i++) { if (notify_info_data_table[i].type == type && notify_info_data_table[i].field == field) return notify_info_data_table[i].size; } - return False; + return 0; } /**************************************************************************** ****************************************************************************/ -static int search_notify(uint16 type, uint16 field, int *value) +static BOOL search_notify(uint16 type, uint16 field, int *value) { int i; @@ -3521,10 +3518,8 @@ void construct_info_data(SPOOL_NOTIFY_INFO_DATA *info_data, uint16 type, uint16 info_data->enc_type = type_of_notify_info_data(type, field); info_data->id = id; - } - /******************************************************************* * * fill a notify_info struct with info asked -- cgit From e6676a9a6928deb03c2a43a66c1245dd05d03e71 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 14 Mar 2006 17:21:30 +0000 Subject: r14387: Try and fix the coverity issues (#53, #54) with negative sink by ensuring all uses of rpcstr_push are consistent with a size_t dest size arg. Jeremy. (This used to be commit f65d7afe1977d9d85046732842f9643716c15088) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 9fd51c9e27..38d2827956 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -8013,7 +8013,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S goto done; } - *out_value_len = (uint32)rpcstr_push((char *)*out_value, regval_name(val), in_value_len, 0); + *out_value_len = (uint32)rpcstr_push((char *)*out_value, regval_name(val), (size_t)in_value_len, 0); /* type */ -- cgit From f4a5c016e31f8254800b6aec971f9397f0ee8ed1 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 16 Mar 2006 16:46:23 +0000 Subject: r14482: Fixes for spoolss code (after coverity fixes) when the client sends a NULL RPC_BUFFER* (This used to be commit 69f816e9f885bdeb6e8c67222b6fdca76d9d1025) --- source3/rpc_server/srv_spoolss_nt.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 38d2827956..350e9d3562 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4621,7 +4621,7 @@ WERROR _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOOL_ /* that's an [in out] buffer */ - if (!q_u->buffer) { + if (!q_u->buffer && (offered!=0)) { return WERR_INVALID_PARAM; } @@ -4936,7 +4936,7 @@ WERROR _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GET /* that's an [in out] buffer */ - if (!q_u->buffer) { + if (!q_u->buffer && (offered!=0)) { return WERR_INVALID_PARAM; } @@ -5535,7 +5535,7 @@ WERROR _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_ /* that's an [in out] buffer */ - if (!q_u->buffer) { + if (!q_u->buffer && (offered!=0)) { return WERR_INVALID_PARAM; } @@ -6374,7 +6374,7 @@ WERROR _spoolss_addjob(pipes_struct *p, SPOOL_Q_ADDJOB *q_u, SPOOL_R_ADDJOB *r_u { /* that's an [in out] buffer */ - if (!q_u->buffer) { + if (!q_u->buffer && (q_u->offered!=0)) { return WERR_INVALID_PARAM; } @@ -6589,7 +6589,7 @@ WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO /* that's an [in out] buffer */ - if (!q_u->buffer) { + if (!q_u->buffer && (offered!=0)) { return WERR_INVALID_PARAM; } @@ -6966,7 +6966,7 @@ WERROR _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS /* that's an [in out] buffer */ - if (!q_u->buffer) { + if (!q_u->buffer && (offered!=0)) { return WERR_INVALID_PARAM; } @@ -7031,7 +7031,7 @@ WERROR _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMF /* that's an [in out] buffer */ - if (!q_u->buffer) { + if (!q_u->buffer && (offered!=0) ) { return WERR_INVALID_PARAM; } @@ -7144,7 +7144,7 @@ WERROR _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * /* that's an [in out] buffer */ - if (!q_u->buffer) { + if (!q_u->buffer && (offered!=0)) { return WERR_INVALID_PARAM; } @@ -7430,7 +7430,7 @@ WERROR _spoolss_enumports( pipes_struct *p, SPOOL_Q_ENUMPORTS *q_u, SPOOL_R_ENUM /* that's an [in out] buffer */ - if (!q_u->buffer) { + if (!q_u->buffer && (offered!=0)) { return WERR_INVALID_PARAM; } @@ -7840,7 +7840,7 @@ WERROR _spoolss_getprinterdriverdirectory(pipes_struct *p, SPOOL_Q_GETPRINTERDRI /* that's an [in out] buffer */ - if (!q_u->buffer ) { + if (!q_u->buffer && (offered!=0)) { return WERR_INVALID_PARAM; } @@ -8452,7 +8452,7 @@ WERROR _spoolss_enumprintprocessors(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCESSORS /* that's an [in out] buffer */ - if (!q_u->buffer) { + if (!q_u->buffer && (offered!=0)) { return WERR_INVALID_PARAM; } @@ -8531,7 +8531,7 @@ WERROR _spoolss_enumprintprocdatatypes(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCDAT /* that's an [in out] buffer */ - if (!q_u->buffer) { + if (!q_u->buffer && (offered!=0)) { return WERR_INVALID_PARAM; } @@ -8659,7 +8659,7 @@ WERROR _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS *q_ /* that's an [in out] buffer */ - if (!q_u->buffer) { + if (!q_u->buffer && (offered!=0)) { return WERR_INVALID_PARAM; } @@ -8835,7 +8835,7 @@ WERROR _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_ /* that's an [in out] buffer */ - if (!q_u->buffer) { + if (!q_u->buffer && (offered!=0)) { return WERR_INVALID_PARAM; } @@ -9457,7 +9457,7 @@ WERROR _spoolss_getprintprocessordirectory(pipes_struct *p, SPOOL_Q_GETPRINTPROC /* that's an [in out] buffer */ - if (!q_u->buffer) { + if (!q_u->buffer && (offered!=0)) { return WERR_INVALID_PARAM; } -- cgit From 00fb5e431d9e418597cadcc7914818f8cf1cc102 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 29 Mar 2006 23:35:16 +0000 Subject: r14786: Fix coverity #275. null deref. Jeremy. (This used to be commit 363d31c9ec2d2a4429ab4d26b3d7c78b76f60626) --- source3/rpc_server/srv_spoolss_nt.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 350e9d3562..44a0aeba90 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -723,14 +723,21 @@ static void notify_system_time(struct spoolss_notify_msg *msg, if (!make_systemtime(&systime, gmtime((time_t *)msg->notify.data))) { DEBUG(5, ("notify_system_time: unable to make systemtime\n")); + prs_mem_free(&ps); return; } - if (!spoolss_io_system_time("", &ps, 0, &systime)) + if (!spoolss_io_system_time("", &ps, 0, &systime)) { + prs_mem_free(&ps); return; + } data->notify_data.data.length = prs_offset(&ps); data->notify_data.data.string = TALLOC(mem_ctx, prs_offset(&ps)); + if (!data->notify_data.data.string) { + prs_mem_free(&ps); + return; + } prs_copy_all_data_out((char *)data->notify_data.data.string, &ps); -- cgit From 2178bcaa39ec20e055537611619f694a0ebd7248 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 29 Mar 2006 23:42:03 +0000 Subject: r14788: Fix coverity bug #276. null deref. Jeremy. (This used to be commit 0217f7d7bf4c8b5b7de2433485fb6f78b62ac817) --- source3/rpc_server/srv_spoolss_nt.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 44a0aeba90..aede762ed4 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -984,6 +984,10 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) /* allocate the max entries possible */ data = TALLOC_ARRAY( mem_ctx, SPOOL_NOTIFY_INFO_DATA, msg_group->num_msgs); + if (!data) { + return; + } + ZERO_STRUCTP(data); /* build the array of change notifications */ @@ -1400,6 +1404,9 @@ static DEVICEMODE* dup_devicemode(TALLOC_CTX *ctx, DEVICEMODE *devmode) len = unistrlen(devmode->devicename.buffer); if (len != -1) { d->devicename.buffer = TALLOC_ARRAY(ctx, uint16, len); + if (!d->devicename.buffer) { + return NULL; + } if (unistrcpy(d->devicename.buffer, devmode->devicename.buffer) != len) return NULL; } @@ -1408,12 +1415,17 @@ static DEVICEMODE* dup_devicemode(TALLOC_CTX *ctx, DEVICEMODE *devmode) len = unistrlen(devmode->formname.buffer); if (len != -1) { d->devicename.buffer = TALLOC_ARRAY(ctx, uint16, len); + if (!d->devicename.buffer) { + return NULL; + } if (unistrcpy(d->formname.buffer, devmode->formname.buffer) != len) return NULL; } d->dev_private = TALLOC_MEMDUP(ctx, devmode->dev_private, devmode->driverextra); - + if (!d->dev_private) { + return NULL; + } return d; } @@ -5894,6 +5906,10 @@ static WERROR update_printer_sec(POLICY_HND *handle, uint32 level, } new_secdesc_ctr = sec_desc_merge(p->mem_ctx, secdesc_ctr, old_secdesc_ctr); + if (!new_secdesc_ctr) { + result = WERR_NOMEM; + goto done; + } if (sec_desc_equal(new_secdesc_ctr->sec, old_secdesc_ctr->sec)) { result = WERR_OK; -- cgit From d4a51cc5009ac2794070e8f9b159d17be7af8a47 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 28 Apr 2006 15:35:42 +0000 Subject: r15309: normalize printing keys when deleting (This used to be commit 037f9f831e001a12261419e37c725558dd717af9) --- source3/rpc_server/srv_spoolss_nt.c | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index aede762ed4..70470a45e7 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -7657,21 +7657,6 @@ WERROR _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u, goto done; } - /* BEGIN_ADMIN_LOG */ - switch(level) { - case 3: - fstrcpy(driver_name, driver.info_3->name ? driver.info_3->name : ""); - sys_adminlog(LOG_INFO,"Added printer driver. Print driver name: %s. Print driver OS: %s. Administrator name: %s.", - driver_name, get_drv_ver_to_os(driver.info_3->cversion),uidtoname(user.ut.uid)); - break; - case 6: - fstrcpy(driver_name, driver.info_6->name ? driver.info_6->name : ""); - sys_adminlog(LOG_INFO,"Added printer driver. Print driver name: %s. Print driver OS: %s. Administrator name: %s.", - driver_name, get_drv_ver_to_os(driver.info_6->version),uidtoname(user.ut.uid)); - break; - } - /* END_ADMIN_LOG */ - /* * I think this is where he DrvUpgradePrinter() hook would be * be called in a driver's interface DLL on a Windows NT 4.0/2k -- cgit From 1f3fe6a50451c6e0b223fa70ddceb7543f060d89 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 29 Apr 2006 23:36:57 +0000 Subject: r15334: Fix warning. This table and function not used anymore. Jerry please check. Jeremy. (This used to be commit 9f676603aaf84829d52dc8d0e0872a058a4d3d4e) --- source3/rpc_server/srv_spoolss_nt.c | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 70470a45e7..2e224896c4 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -40,23 +40,6 @@ extern userdom_struct current_user_info; #define MAGIC_DISPLAY_FREQUENCY 0xfade2bad #define PHANTOM_DEVMODE_KEY "_p_f_a_n_t_0_m_" - -/* Table to map the driver version */ -/* to OS */ -static const char * drv_ver_to_os[] = { - "WIN9X", /* driver version/cversion 0 */ - "", /* unused ? */ - "WINNT", /* driver version/cversion 2 */ - "WIN2K", /* driver version/cversion 3 */ -}; - -static const char *get_drv_ver_to_os(int ver) -{ - if (ver < 0 || ver > 3) - return ""; - return drv_ver_to_os[ver]; -} - struct table_node { const char *long_archi; const char *short_archi; -- cgit From 1a850a4f37654282039e4b8712a874365ca16681 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 31 May 2006 01:31:01 +0000 Subject: r15975: Only call the printer publishing calls if 'security = ads' (prevent a segv) (This used to be commit a2ef525d9e3b4f050cb4e02fad67808d3e916373) --- source3/rpc_server/srv_spoolss_nt.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 2e224896c4..0281e3da0c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6279,7 +6279,13 @@ static WERROR publish_or_unpublish_printer(pipes_struct *p, POLICY_HND *handle, #ifdef HAVE_ADS SPOOL_PRINTER_INFO_LEVEL_7 *info7 = info->info_7; int snum; - Printer_entry *Printer = find_printer_index_by_hnd(p, handle); + Printer_entry *Printer; + + if ( lp_security() != SEC_ADS ) { + return WERR_UNKNOWN_LEVEL; + } + + Printer = find_printer_index_by_hnd(p, handle); DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action)); -- cgit From fbdcf2663b56007a438ac4f0d8d82436b1bfe688 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 11 Jul 2006 18:01:26 +0000 Subject: r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need to do the upper layer directories but this is what everyone is waiting for.... Jeremy. (This used to be commit 9dafb7f48ca3e7af956b0a7d1720c2546fc4cfb8) --- source3/rpc_server/srv_spoolss_nt.c | 98 ++++++++++++++----------------------- 1 file changed, 38 insertions(+), 60 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 0281e3da0c..3dbad208cc 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -331,7 +331,7 @@ WERROR delete_printer_hook( NT_USER_TOKEN *token, const char *sharename ) /* go ahead and re-read the services immediately */ reload_services( False ); - if ( lp_servicenumber( sharename ) < 0 ) + if ( !share_defined( sharename ) ) return WERR_ACCESS_DENIED; return WERR_OK; @@ -1509,7 +1509,6 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, fstring name; int snum; - struct current_user user; Printer_entry *Printer=NULL; if ( !q_u->printername ) @@ -1533,8 +1532,6 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, return WERR_INVALID_PRINTER_NAME; } - get_current_user(&user, p); - /* * First case: the user is opening the print server: * @@ -1599,12 +1596,12 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege, and not a printer admin, then fail */ - if ((user.ut.uid != 0) && - !user_has_privileges(user.nt_user_token, + if ((p->pipe_user.ut.uid != 0) && + !user_has_privileges(p->pipe_user.nt_user_token, &se_printop ) && !token_contains_name_in_list( - uidtoname(user.ut.uid), NULL, - user.nt_user_token, + uidtoname(p->pipe_user.ut.uid), NULL, + p->pipe_user.nt_user_token, lp_printer_admin(snum))) { close_printer_handle(p, handle); return WERR_ACCESS_DENIED; @@ -1657,9 +1654,9 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, return WERR_ACCESS_DENIED; } - if (!user_ok_token(uidtoname(user.ut.uid), user.nt_user_token, - snum) || - !print_access_check(&user, snum, + if (!user_ok_token(uidtoname(p->pipe_user.ut.uid), + p->pipe_user.nt_user_token, snum) || + !print_access_check(&p->pipe_user, snum, printer_default->access_required)) { DEBUG(3, ("access DENIED for printer open\n")); close_printer_handle(p, handle); @@ -1953,20 +1950,17 @@ WERROR _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER NT_PRINTER_DRIVER_INFO_LEVEL info; NT_PRINTER_DRIVER_INFO_LEVEL info_win2k; int version; - struct current_user user; WERROR status; WERROR status_win2k = WERR_ACCESS_DENIED; SE_PRIV se_printop = SE_PRINT_OPERATOR; - get_current_user(&user, p); - /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege, and not a printer admin, then fail */ - if ( (user.ut.uid != 0) - && !user_has_privileges(user.nt_user_token, &se_printop ) - && !token_contains_name_in_list( uidtoname(user.ut.uid), - NULL, user.nt_user_token, lp_printer_admin(-1)) ) + if ( (p->pipe_user.ut.uid != 0) + && !user_has_privileges(p->pipe_user.nt_user_token, &se_printop ) + && !token_contains_name_in_list( uidtoname(p->pipe_user.ut.uid), + NULL, p->pipe_user.nt_user_token, lp_printer_admin(-1)) ) { return WERR_ACCESS_DENIED; } @@ -2013,7 +2007,7 @@ 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, &user, 3, False ); + status_win2k = delete_printer_driver(info_win2k.info_3, &p->pipe_user, 3, False ); free_a_printer_driver( info_win2k, 3 ); /* this should not have failed---if it did, report to client */ @@ -2025,7 +2019,7 @@ WERROR _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER } } - status = delete_printer_driver(info.info_3, &user, version, False); + status = delete_printer_driver(info.info_3, &p->pipe_user, version, False); /* if at least one of the deletes succeeded return OK */ @@ -2051,20 +2045,17 @@ WERROR _spoolss_deleteprinterdriverex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIV int version; uint32 flags = q_u->delete_flags; BOOL delete_files; - struct current_user user; WERROR status; WERROR status_win2k = WERR_ACCESS_DENIED; SE_PRIV se_printop = SE_PRINT_OPERATOR; - get_current_user(&user, p); - /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege, and not a printer admin, then fail */ - if ( (user.ut.uid != 0) - && !user_has_privileges(user.nt_user_token, &se_printop ) - && !token_contains_name_in_list( uidtoname(user.ut.uid), - NULL, user.nt_user_token, lp_printer_admin(-1)) ) + if ( (p->pipe_user.ut.uid != 0) + && !user_has_privileges(p->pipe_user.nt_user_token, &se_printop ) + && !token_contains_name_in_list( uidtoname(p->pipe_user.ut.uid), + NULL, p->pipe_user.nt_user_token, lp_printer_admin(-1)) ) { return WERR_ACCESS_DENIED; } @@ -2150,7 +2141,7 @@ 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, &user, 3, delete_files); + status_win2k = delete_printer_driver(info_win2k.info_3, &p->pipe_user, 3, delete_files); free_a_printer_driver( info_win2k, 3 ); /* this should not have failed---if it did, report to client */ @@ -2160,7 +2151,7 @@ WERROR _spoolss_deleteprinterdriverex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIV } } - status = delete_printer_driver(info.info_3, &user, version, delete_files); + status = delete_printer_driver(info.info_3, &p->pipe_user, version, delete_files); if ( W_ERROR_IS_OK(status) || W_ERROR_IS_OK(status_win2k) ) status = WERR_OK; @@ -4073,7 +4064,7 @@ static BOOL convert_nt_devicemode( DEVICEMODE *devmode, NT_DEVICEMODE *ntdevmode Create a DEVMODE struct. Returns malloced memory. ****************************************************************************/ -DEVICEMODE *construct_dev_mode(int snum) +DEVICEMODE *construct_dev_mode(const char *servicename) { NT_PRINTER_INFO_LEVEL *printer = NULL; DEVICEMODE *devmode = NULL; @@ -4082,7 +4073,7 @@ DEVICEMODE *construct_dev_mode(int snum) DEBUGADD(8,("getting printer characteristics\n")); - if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, lp_const_servicename(snum)))) + if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, servicename))) return NULL; if ( !printer->info_2->devmode ) { @@ -4154,7 +4145,7 @@ static BOOL construct_printer_info_2(Printer_entry *print_hnd, PRINTER_INFO_2 *p printer->cjobs = count; /* jobs */ printer->averageppm = ntprinter->info_2->averageppm; /* average pages per minute */ - if ( !(printer->devmode = construct_dev_mode(snum)) ) + if ( !(printer->devmode = construct_dev_mode(lp_const_servicename(snum))) ) DEBUG(8, ("Returning NULL Devicemode!\n")); printer->secdesc = NULL; @@ -5640,15 +5631,12 @@ WERROR _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, S pstring jobname; fstring datatype; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); - struct current_user user; if (!Printer) { DEBUG(2,("_spoolss_startdocprinter: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle))); return WERR_BADFID; } - get_current_user(&user, p); - /* * a nice thing with NT is it doesn't listen to what you tell it. * when asked to send _only_ RAW datas, it tries to send datas @@ -5672,7 +5660,7 @@ WERROR _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, S unistr2_to_ascii(jobname, &info_1->docname, sizeof(jobname)); - Printer->jobid = print_job_start(&user, snum, jobname, Printer->nt_devmode); + Printer->jobid = print_job_start(&p->pipe_user, snum, jobname, Printer->nt_devmode); /* An error occured in print_job_start() so return an appropriate NT error code. */ @@ -5745,13 +5733,10 @@ WERROR _spoolss_writeprinter(pipes_struct *p, SPOOL_Q_WRITEPRINTER *q_u, SPOOL_R static WERROR control_printer(POLICY_HND *handle, uint32 command, pipes_struct *p) { - struct current_user user; int snum; WERROR errcode = WERR_BADFUNC; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); - get_current_user(&user, p); - if (!Printer) { DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle))); return WERR_BADFID; @@ -5762,18 +5747,18 @@ static WERROR control_printer(POLICY_HND *handle, uint32 command, switch (command) { case PRINTER_CONTROL_PAUSE: - if (print_queue_pause(&user, snum, &errcode)) { + if (print_queue_pause(&p->pipe_user, snum, &errcode)) { errcode = WERR_OK; } break; case PRINTER_CONTROL_RESUME: case PRINTER_CONTROL_UNPAUSE: - if (print_queue_resume(&user, snum, &errcode)) { + if (print_queue_resume(&p->pipe_user, snum, &errcode)) { errcode = WERR_OK; } break; case PRINTER_CONTROL_PURGE: - if (print_queue_purge(&user, snum, &errcode)) { + if (print_queue_purge(&p->pipe_user, snum, &errcode)) { errcode = WERR_OK; } break; @@ -5795,7 +5780,6 @@ WERROR _spoolss_abortprinter(pipes_struct *p, SPOOL_Q_ABORTPRINTER *q_u, SPOOL_R POLICY_HND *handle = &q_u->handle; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); int snum; - struct current_user user; WERROR errcode = WERR_OK; if (!Printer) { @@ -5806,9 +5790,7 @@ WERROR _spoolss_abortprinter(pipes_struct *p, SPOOL_Q_ABORTPRINTER *q_u, SPOOL_R if (!get_printer_snum(p, handle, &snum)) return WERR_BADFID; - get_current_user( &user, p ); - - print_job_delete( &user, snum, Printer->jobid, &errcode ); + print_job_delete( &p->pipe_user, snum, Printer->jobid, &errcode ); return errcode; } @@ -6018,7 +6000,9 @@ BOOL add_printer_hook(NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer) SE_PRIV se_printop = SE_PRINT_OPERATOR; BOOL is_print_op = False; - standard_sub_basic(current_user_info.smb_name, remote_machine,sizeof(remote_machine)); + standard_sub_basic(current_user_info.smb_name, + current_user_info.domain, + remote_machine,sizeof(remote_machine)); slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"", cmd, printer->info_2->printername, printer->info_2->sharename, @@ -6544,7 +6528,7 @@ static WERROR enumjobs_level2(print_queue_struct *queue, int snum, /* this should not be a failure condition if the devmode is NULL */ - devmode = construct_dev_mode(snum); + devmode = construct_dev_mode(lp_const_servicename(snum)); for (i=0; i<*returned; i++) fill_job_info_2(&(info[i]), &queue[i], i, snum, ntprinter, devmode); @@ -6664,7 +6648,6 @@ WERROR _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u uint32 jobid = q_u->jobid; uint32 command = q_u->command; - struct current_user user; int snum; WERROR errcode = WERR_BADFUNC; @@ -6676,23 +6659,21 @@ WERROR _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u return WERR_INVALID_PRINTER_NAME; } - get_current_user(&user, p); - switch (command) { case JOB_CONTROL_CANCEL: case JOB_CONTROL_DELETE: - if (print_job_delete(&user, snum, jobid, &errcode)) { + if (print_job_delete(&p->pipe_user, snum, jobid, &errcode)) { errcode = WERR_OK; } break; case JOB_CONTROL_PAUSE: - if (print_job_pause(&user, snum, jobid, &errcode)) { + if (print_job_pause(&p->pipe_user, snum, jobid, &errcode)) { errcode = WERR_OK; } break; case JOB_CONTROL_RESTART: case JOB_CONTROL_RESUME: - if (print_job_resume(&user, snum, jobid, &errcode)) { + if (print_job_resume(&p->pipe_user, snum, jobid, &errcode)) { errcode = WERR_OK; } break; @@ -7618,26 +7599,23 @@ WERROR _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u, SPOOL_PRINTER_DRIVER_INFO_LEVEL *info = &q_u->info; WERROR err = WERR_OK; NT_PRINTER_DRIVER_INFO_LEVEL driver; - struct current_user user; fstring driver_name; uint32 version; ZERO_STRUCT(driver); - get_current_user(&user, p); - if (!convert_printer_driver_info(info, &driver, level)) { err = WERR_NOMEM; goto done; } DEBUG(5,("Cleaning driver's information\n")); - err = clean_up_driver_struct(driver, level, &user); + err = clean_up_driver_struct(driver, level, &p->pipe_user); if (!W_ERROR_IS_OK(err)) goto done; DEBUG(5,("Moving driver to final destination\n")); - if( !W_ERROR_IS_OK(err = move_driver_to_download_area(driver, level, &user, &err)) ) { + if( !W_ERROR_IS_OK(err = move_driver_to_download_area(driver, level, &p->pipe_user, &err)) ) { goto done; } @@ -8777,7 +8755,7 @@ static WERROR getjob_level_2(print_queue_struct **queue, int count, int snum, */ if ( !(nt_devmode=print_job_devmode( lp_const_servicename(snum), jobid )) ) - devmode = construct_dev_mode(snum); + devmode = construct_dev_mode(lp_const_servicename(snum)); else { if ((devmode = SMB_MALLOC_P(DEVICEMODE)) != NULL) { ZERO_STRUCTP( devmode ); -- cgit From 9d4fa2b27b746d6a5716bfa049b2a1ee191ba6d5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 25 Jul 2006 21:23:34 +0000 Subject: r17244: There were several error paths where NT_PRINTER_INFO_LEVEL wasn't being freed - also one enum jobs case where the NT_PRINTER_INFO_LEVEL and queue weren't being freed. Strange that Coverity or Klokwork didn't pick these up. Hopefully will fix #3962. Jeremy. (This used to be commit bb264123872bfec42ad85ec0c8afa3a8c7d1811e) --- source3/rpc_server/srv_spoolss_nt.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 3dbad208cc..db098e74be 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -441,7 +441,7 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) const char *servername; fstring sname; BOOL found=False; - NT_PRINTER_INFO_LEVEL *printer; + NT_PRINTER_INFO_LEVEL *printer = NULL; WERROR result; DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename, (unsigned long)strlen(handlename))); @@ -532,6 +532,7 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) printername++; if ( strequal(printername, aprinter) ) { + free_a_printer( &printer, 2); found = True; break; } @@ -541,6 +542,8 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) free_a_printer( &printer, 2); } + free_a_printer( &printer, 2); + if ( !found ) { DEBUGADD(4,("Printer not found\n")); return False; @@ -3551,6 +3554,7 @@ static BOOL construct_notify_printer_info(Printer_entry *print_hnd, SPOOL_NOTIFY if((info->data=SMB_REALLOC_ARRAY(info->data, SPOOL_NOTIFY_INFO_DATA, info->count+1)) == NULL) { DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n")); + free_a_printer(&printer, 2); return False; } @@ -4181,6 +4185,7 @@ static BOOL construct_printer_info_3(Printer_entry *print_hnd, PRINTER_INFO_3 ** *pp_printer = NULL; if ((printer = SMB_MALLOC_P(PRINTER_INFO_3)) == NULL) { DEBUG(2,("construct_printer_info_3: malloc fail.\n")); + free_a_printer(&ntprinter, 2); return False; } @@ -4983,8 +4988,10 @@ static WERROR construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, fst if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, lp_const_servicename(snum)))) return WERR_INVALID_PRINTER_NAME; - if (!W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version))) + if (!W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version))) { + free_a_printer(&printer, 2); return WERR_UNKNOWN_PRINTER_DRIVER; + } fill_printer_driver_info_1(info, driver, servername, architecture); @@ -5043,8 +5050,10 @@ static WERROR construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fst if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, lp_const_servicename(snum)))) return WERR_INVALID_PRINTER_NAME; - if (!W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version))) + if (!W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version))) { + free_a_printer(&printer, 2); return WERR_UNKNOWN_PRINTER_DRIVER; + } fill_printer_driver_info_2(info, driver, servername); @@ -6611,22 +6620,24 @@ WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO if (*returned == 0) { SAFE_FREE(queue); + free_a_printer(&ntprinter, 2); return WERR_OK; } switch (level) { case 1: wret = enumjobs_level1(queue, snum, ntprinter, buffer, offered, needed, returned); - return wret; + break; case 2: wret = enumjobs_level2(queue, snum, ntprinter, buffer, offered, needed, returned); - return wret; + break; default: - SAFE_FREE(queue); *returned=0; wret = WERR_UNKNOWN_LEVEL; + break; } + SAFE_FREE(queue); free_a_printer( &ntprinter, 2 ); return wret; } -- cgit From 29a4d666bad176483a5a346d24dc1b044bf67b2b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 25 Jul 2006 21:33:13 +0000 Subject: r17245: Second part of fix for #3962. Don't do a double free in the infolevel2 case. Free both queue and NT_PRINTER_INFO_LEVEL in the same place. Jeremy. (This used to be commit 6ac3a4ce78f42949013ae7bd675ff292fb0383ca) --- source3/rpc_server/srv_spoolss_nt.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index db098e74be..cd0a4f2bb3 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6395,9 +6395,9 @@ WERROR _spoolss_addjob(pipes_struct *p, SPOOL_Q_ADDJOB *q_u, SPOOL_R_ADDJOB *r_u /**************************************************************************** ****************************************************************************/ -static void fill_job_info_1(JOB_INFO_1 *job_info, print_queue_struct *queue, +static void fill_job_info_1(JOB_INFO_1 *job_info, const print_queue_struct *queue, int position, int snum, - NT_PRINTER_INFO_LEVEL *ntprinter) + const NT_PRINTER_INFO_LEVEL *ntprinter) { struct tm *t; @@ -6422,9 +6422,9 @@ static void fill_job_info_1(JOB_INFO_1 *job_info, print_queue_struct *queue, /**************************************************************************** ****************************************************************************/ -static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, +static BOOL fill_job_info_2(JOB_INFO_2 *job_info, const print_queue_struct *queue, int position, int snum, - NT_PRINTER_INFO_LEVEL *ntprinter, + const NT_PRINTER_INFO_LEVEL *ntprinter, DEVICEMODE *devmode) { struct tm *t; @@ -6467,8 +6467,8 @@ static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue, Enumjobs at level 1. ****************************************************************************/ -static WERROR enumjobs_level1(print_queue_struct *queue, int snum, - NT_PRINTER_INFO_LEVEL *ntprinter, +static WERROR enumjobs_level1(const print_queue_struct *queue, int snum, + const NT_PRINTER_INFO_LEVEL *ntprinter, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { @@ -6478,7 +6478,6 @@ static WERROR enumjobs_level1(print_queue_struct *queue, int snum, info=SMB_MALLOC_ARRAY(JOB_INFO_1,*returned); if (info==NULL) { - SAFE_FREE(queue); *returned=0; return WERR_NOMEM; } @@ -6486,8 +6485,6 @@ static WERROR enumjobs_level1(print_queue_struct *queue, int snum, for (i=0; i<*returned; i++) fill_job_info_1( &info[i], &queue[i], i, snum, ntprinter ); - SAFE_FREE(queue); - /* check the required size. */ for (i=0; i<*returned; i++) (*needed) += spoolss_size_job_info_1(&info[i]); @@ -6520,8 +6517,8 @@ out: Enumjobs at level 2. ****************************************************************************/ -static WERROR enumjobs_level2(print_queue_struct *queue, int snum, - NT_PRINTER_INFO_LEVEL *ntprinter, +static WERROR enumjobs_level2(const print_queue_struct *queue, int snum, + const NT_PRINTER_INFO_LEVEL *ntprinter, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { @@ -6542,9 +6539,6 @@ static WERROR enumjobs_level2(print_queue_struct *queue, int snum, for (i=0; i<*returned; i++) fill_job_info_2(&(info[i]), &queue[i], i, snum, ntprinter, devmode); - free_a_printer(&ntprinter, 2); - SAFE_FREE(queue); - /* check the required size. */ for (i=0; i<*returned; i++) (*needed) += spoolss_size_job_info_2(&info[i]); -- cgit From 430fa0eba08cbf180d83740a895a0018af1c7f21 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 31 Jul 2006 21:40:25 +0000 Subject: r17348: Some C++ warnings (This used to be commit ae6b9b34e59167e3958bfdb9997fa25340b9a0a3) --- source3/rpc_server/srv_spoolss_nt.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index cd0a4f2bb3..fc25614963 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -719,7 +719,8 @@ static void notify_system_time(struct spoolss_notify_msg *msg, } data->notify_data.data.length = prs_offset(&ps); - data->notify_data.data.string = TALLOC(mem_ctx, prs_offset(&ps)); + data->notify_data.data.string = (uint16 *) + TALLOC(mem_ctx, prs_offset(&ps)); if (!data->notify_data.data.string) { prs_mem_free(&ps); return; @@ -911,7 +912,8 @@ static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MS /* need to allocate own copy of data */ if ( msg->len != 0 ) - msg_grp->msgs[new_slot].notify.data = TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len ); + msg_grp->msgs[new_slot].notify.data = (char *) + TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len ); return ctr->num_groups; } @@ -1220,7 +1222,7 @@ void do_drv_upgrade_printer(int msg_type, struct process_id src, void *buf, size int n_services = lp_numservices(); len = MIN(len,sizeof(drivername)-1); - strncpy(drivername, buf, len); + strncpy(drivername, (const char *)buf, len); DEBUG(10,("do_drv_upgrade_printer: Got message for new driver [%s]\n", drivername )); @@ -1318,7 +1320,7 @@ void reset_all_printerdata(int msg_type, struct process_id src, int n_services = lp_numservices(); len = MIN( len, sizeof(drivername)-1 ); - strncpy( drivername, buf, len ); + strncpy( drivername, (const char *)buf, len ); DEBUG(10,("reset_all_printerdata: Got message for new driver [%s]\n", drivername )); @@ -1381,7 +1383,7 @@ static DEVICEMODE* dup_devicemode(TALLOC_CTX *ctx, DEVICEMODE *devmode) /* bulk copy first */ - d = TALLOC_MEMDUP(ctx, devmode, sizeof(DEVICEMODE)); + d = (DEVICEMODE *)TALLOC_MEMDUP(ctx, devmode, sizeof(DEVICEMODE)); if (!d) return NULL; @@ -1408,7 +1410,8 @@ static DEVICEMODE* dup_devicemode(TALLOC_CTX *ctx, DEVICEMODE *devmode) return NULL; } - d->dev_private = TALLOC_MEMDUP(ctx, devmode->dev_private, devmode->driverextra); + d->dev_private = (uint8 *)TALLOC_MEMDUP(ctx, devmode->dev_private, + devmode->driverextra); if (!d->dev_private) { return NULL; } @@ -9046,7 +9049,8 @@ WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, */ set_printer_dataex( printer, keyname, valuename, - REG_SZ, (void*)oid_string, strlen(oid_string)+1 ); + REG_SZ, (uint8 *)oid_string, + strlen(oid_string)+1 ); } status = mod_a_printer(printer, 2); @@ -9336,7 +9340,7 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ data_len = regval_size( val ); if ( data_len ) { - if ( !(enum_values[i].data = TALLOC_MEMDUP(p->mem_ctx, regval_data_p(val), data_len)) ) + if ( !(enum_values[i].data = (uint8 *)TALLOC_MEMDUP(p->mem_ctx, regval_data_p(val), data_len)) ) { DEBUG(0,("talloc_memdup failed to allocate memory [data_len=%d] for data!\n", data_len )); -- cgit From 22c9a3151e1aba83b6a72612440a230fd70f1e5a Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 3 Aug 2006 15:19:01 +0000 Subject: r17386: fix inverted logic pointed out by Volker. When deleting a printer return access denied if the printer still exists after the delete_printer_hook() is called (This used to be commit c05e2bdc0c068eb832035daea7962ab1a9e787b2) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index fc25614963..6548bf3c6d 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -331,7 +331,7 @@ WERROR delete_printer_hook( NT_USER_TOKEN *token, const char *sharename ) /* go ahead and re-read the services immediately */ reload_services( False ); - if ( !share_defined( sharename ) ) + if ( share_defined( sharename ) ) return WERR_ACCESS_DENIED; return WERR_OK; -- cgit From 995205fc60f87e1a02aa1c6f309db55ae18e908a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 6 Sep 2006 18:32:20 +0000 Subject: r18188: merge 3.0-libndr branch (This used to be commit 1115745caed3093c25d6be01ffee21819fb0a675) --- source3/rpc_server/srv_spoolss_nt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 6548bf3c6d..e60a431846 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -5287,8 +5287,7 @@ static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_IN info->previousdrivernames=NULL; init_unistr_array(&info->previousdrivernames, &nullstr, servername); - info->driver_date.low=0; - info->driver_date.high=0; + info->driver_date=0; info->padding=0; info->driver_version_low=0; -- cgit From 5e1146ab5845169aba57dcd216f88589276e5df8 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 11 Sep 2006 22:02:34 +0000 Subject: r18404: * swap from POLICY_HND to the struct policy_handle from ndr/misc.h * move OUR_HANDLE macro to include/rpc_misc.h (This used to be commit 2b37079af2f569df7a58878150a61980c6fe06ee) --- source3/rpc_server/srv_spoolss_nt.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index e60a431846..5f8e705ea3 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -66,10 +66,6 @@ static uint32 smb_connections=0; extern STANDARD_MAPPING printer_std_mapping, printserver_std_mapping; -#define OUR_HANDLE(hnd) (((hnd)==NULL)?"NULL":(IVAL((hnd)->data5,4)==(uint32)sys_getpid()?"OURS":"OTHER")), \ -((unsigned int)IVAL((hnd)->data5,4)),((unsigned int)sys_getpid()) - - /* API table for Xcv Monitor functions */ struct xcv_api_table { -- cgit From 4e7d11449ad419f4fa791e26e059a9f73d6d4042 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 19 Sep 2006 00:12:11 +0000 Subject: r18654: Rename "struct uuid" => "struct GUID" for consistency. (This used to be commit 5de76767e857e9d159ea46e2ded612ccd6d6bf19) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 5f8e705ea3..16dec45318 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4262,7 +4262,7 @@ static BOOL construct_printer_info_5(Printer_entry *print_hnd, PRINTER_INFO_5 *p static BOOL construct_printer_info_7(Printer_entry *print_hnd, PRINTER_INFO_7 *printer, int snum) { char *guid_str = NULL; - struct uuid guid; + struct GUID guid; if (is_printer_published(print_hnd, snum, &guid)) { asprintf(&guid_str, "{%s}", smb_uuid_string_static(guid)); -- cgit From 4db7642caa99c1b054322a8971c4b673556487ce Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 20 Sep 2006 22:23:12 +0000 Subject: r18745: Use the Samba4 data structures for security descriptors and security descriptor buffers. Make security access masks simply a uint32 rather than a structure with a uint32 in it. (This used to be commit b41c52b9db5fc4a553b20a7a5a051a4afced9366) --- source3/rpc_server/srv_spoolss_nt.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 16dec45318..1a396a2391 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -3008,8 +3008,8 @@ static void spoolss_notify_security_desc(int snum, NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) { - data->notify_data.sd.size = printer->info_2->secdesc_buf->len; - data->notify_data.sd.desc = dup_sec_desc( mem_ctx, printer->info_2->secdesc_buf->sec ) ; + data->notify_data.sd.size = printer->info_2->secdesc_buf->sd_size; + data->notify_data.sd.desc = dup_sec_desc( mem_ctx, printer->info_2->secdesc_buf->sd ) ; } /******************************************************************* @@ -4154,13 +4154,13 @@ static BOOL construct_printer_info_2(Printer_entry *print_hnd, PRINTER_INFO_2 *p printer->secdesc = NULL; if ( ntprinter->info_2->secdesc_buf - && ntprinter->info_2->secdesc_buf->len != 0 ) + && ntprinter->info_2->secdesc_buf->sd_size != 0 ) { /* don't use talloc_steal() here unless you do a deep steal of all the SEC_DESC members */ printer->secdesc = dup_sec_desc( get_talloc_ctx(), - ntprinter->info_2->secdesc_buf->sec ); + ntprinter->info_2->secdesc_buf->sd ); } free_a_printer(&ntprinter, 2); @@ -4194,12 +4194,12 @@ static BOOL construct_printer_info_3(Printer_entry *print_hnd, PRINTER_INFO_3 ** printer->flags = 0x4; - if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->len != 0) { + if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->sd_size != 0) { /* don't use talloc_steal() here unless you do a deep steal of all the SEC_DESC members */ printer->secdesc = dup_sec_desc( get_talloc_ctx(), - ntprinter->info_2->secdesc_buf->sec ); + ntprinter->info_2->secdesc_buf->sd ); } free_a_printer(&ntprinter, 2); @@ -5845,20 +5845,20 @@ static WERROR update_printer_sec(POLICY_HND *handle, uint32 level, SEC_ACL *the_acl; int i; - the_acl = old_secdesc_ctr->sec->dacl; + the_acl = old_secdesc_ctr->sd->dacl; DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n", PRINTERNAME(snum), the_acl->num_aces)); for (i = 0; i < the_acl->num_aces; i++) { fstring sid_str; - sid_to_string(sid_str, &the_acl->ace[i].trustee); + sid_to_string(sid_str, &the_acl->aces[i].trustee); DEBUG(10, ("%s 0x%08x\n", sid_str, - the_acl->ace[i].info.mask)); + the_acl->aces[i].access_mask)); } - the_acl = secdesc_ctr->sec->dacl; + the_acl = secdesc_ctr->sd->dacl; if (the_acl) { DEBUG(10, ("secdesc_ctr for %s has %d aces:\n", @@ -5867,10 +5867,10 @@ static WERROR update_printer_sec(POLICY_HND *handle, uint32 level, for (i = 0; i < the_acl->num_aces; i++) { fstring sid_str; - sid_to_string(sid_str, &the_acl->ace[i].trustee); + sid_to_string(sid_str, &the_acl->aces[i].trustee); DEBUG(10, ("%s 0x%08x\n", sid_str, - the_acl->ace[i].info.mask)); + the_acl->aces[i].access_mask)); } } else { DEBUG(10, ("dacl for secdesc_ctr is NULL\n")); @@ -5883,7 +5883,7 @@ static WERROR update_printer_sec(POLICY_HND *handle, uint32 level, goto done; } - if (sec_desc_equal(new_secdesc_ctr->sec, old_secdesc_ctr->sec)) { + if (sec_desc_equal(new_secdesc_ctr->sd, old_secdesc_ctr->sd)) { result = WERR_OK; goto done; } -- cgit From fec98506440bbff0c340cc6e35767f0e81398519 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 25 Sep 2006 16:26:25 +0000 Subject: r18898: Fix for bug #4100 from Udo Eberhardt . Ensure we initialize values for smb_io_notify_info_data_strings to fix crash. Jeremy. (This used to be commit ceefb8dd3ca67449d5afbf556e9879abb37830ac) --- source3/rpc_server/srv_spoolss_nt.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 1a396a2391..cd69fdf107 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2887,6 +2887,9 @@ static void spoolss_notify_devmode(int snum, NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) { + /* for a dummy implementation we have to zero the fields */ + data->notify_data.data.length = 0; + data->notify_data.data.string = NULL; } /******************************************************************* -- cgit From 7ced2e983d29d769a9ad1055f244ecd1e3d08918 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 2 Oct 2006 08:38:54 +0000 Subject: r19028: Implement getprinterinfo level 6 (only the status) and get rid of snum in the getprinter calls. Survives the RPC-SAMBA3-SPOOLSS test which I will activate when the Samba4 build farm has picked it up. Volker (This used to be commit d7248b6cfa4d6e639d92afdd092136d900d90e19) --- source3/rpc_server/srv_spoolss_nt.c | 294 ++++++++++++++++++++++++++---------- 1 file changed, 214 insertions(+), 80 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index cd69fdf107..8d9ba7cb90 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -373,7 +373,8 @@ static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) Return the snum of a printer corresponding to an handle. ****************************************************************************/ -static BOOL get_printer_snum(pipes_struct *p, POLICY_HND *hnd, int *number) +static BOOL get_printer_snum(pipes_struct *p, POLICY_HND *hnd, int *number, + struct share_params **params) { Printer_entry *Printer = find_printer_index_by_hnd(p, hnd); @@ -386,6 +387,13 @@ static BOOL get_printer_snum(pipes_struct *p, POLICY_HND *hnd, int *number) case SPLHND_PRINTER: DEBUG(4,("short name:%s\n", Printer->sharename)); *number = print_queue_snum(Printer->sharename); + if ((*number != -1) && (params != NULL)) { + *params = get_share_params(tmp_talloc_ctx(), + Printer->sharename); + if (*params == NULL) { + return False; + } + } return (*number != -1); case SPLHND_SERVER: return False; @@ -1626,7 +1634,7 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, /* NT doesn't let us connect to a printer if the connecting user doesn't have print permission. */ - if (!get_printer_snum(p, handle, &snum)) { + if (!get_printer_snum(p, handle, &snum, NULL)) { close_printer_handle(p, handle); return WERR_BADFID; } @@ -1853,7 +1861,7 @@ static WERROR _spoolss_enddocprinter_internal(pipes_struct *p, POLICY_HND *handl return WERR_BADFID; } - if (!get_printer_snum(p, handle, &snum)) + if (!get_printer_snum(p, handle, &snum, NULL)) return WERR_BADFID; Printer->document_started=False; @@ -2445,7 +2453,7 @@ WERROR _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO status = getprinterdata_printer_server( p->mem_ctx, value, type, data, needed, *out_size ); else { - if ( !get_printer_snum(p,handle, &snum) ) { + if ( !get_printer_snum(p,handle, &snum, NULL) ) { status = WERR_BADFID; goto done; } @@ -2663,7 +2671,7 @@ WERROR _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE if ( Printer->printer_type == SPLHND_SERVER) snum = -1; else if ( (Printer->printer_type == SPLHND_PRINTER) && - !get_printer_snum(p, handle, &snum) ) + !get_printer_snum(p, handle, &snum, NULL) ) return WERR_BADFID; client_ip.s_addr = inet_addr(p->conn->client_address); @@ -3751,7 +3759,7 @@ static WERROR printer_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY if ( !option ) return WERR_BADFID; - get_printer_snum(p, hnd, &snum); + get_printer_snum(p, hnd, &snum, NULL); for (i=0; icount; i++) { option_type=&option->ctr.type[i]; @@ -3869,7 +3877,9 @@ done: * fill a printer_info_0 struct ********************************************************************/ -static BOOL construct_printer_info_0(Printer_entry *print_hnd, PRINTER_INFO_0 *printer, int snum) +static BOOL construct_printer_info_0(Printer_entry *print_hnd, + PRINTER_INFO_0 *printer, + const struct share_params *params) { pstring chaine; int count; @@ -3880,14 +3890,15 @@ static BOOL construct_printer_info_0(Printer_entry *print_hnd, PRINTER_INFO_0 *p time_t setuptime; print_status_struct status; - if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum)))) + if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, + lp_const_servicename(params->service)))) return False; - count = print_queue_length(snum, &status); + count = print_queue_length(params->service, &status); /* check if we already have a counter for this printer */ for(session_counter = counter_list; session_counter; session_counter = session_counter->next) { - if (session_counter->snum == snum) + if (session_counter->snum == params->service) break; } @@ -3898,7 +3909,7 @@ static BOOL construct_printer_info_0(Printer_entry *print_hnd, PRINTER_INFO_0 *p return False; } ZERO_STRUCTP(session_counter); - session_counter->snum=snum; + session_counter->snum=params->service; session_counter->counter=0; DLIST_ADD(counter_list, session_counter); } @@ -3974,21 +3985,25 @@ static BOOL construct_printer_info_0(Printer_entry *print_hnd, PRINTER_INFO_0 *p * construct_printer_info_1 * fill a printer_info_1 struct ********************************************************************/ -static BOOL construct_printer_info_1(Printer_entry *print_hnd, uint32 flags, PRINTER_INFO_1 *printer, int snum) +static BOOL construct_printer_info_1(Printer_entry *print_hnd, uint32 flags, + PRINTER_INFO_1 *printer, + const struct share_params *params) { pstring chaine; pstring chaine2; NT_PRINTER_INFO_LEVEL *ntprinter = NULL; - if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum)))) + if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, + lp_const_servicename(params->service)))) return False; printer->flags=flags; if (*ntprinter->info_2->comment == '\0') { - init_unistr(&printer->comment, lp_comment(snum)); + init_unistr(&printer->comment, lp_comment(params->service)); slprintf(chaine,sizeof(chaine)-1,"%s,%s,%s", ntprinter->info_2->printername, - ntprinter->info_2->drivername, lp_comment(snum)); + ntprinter->info_2->drivername, + lp_comment(params->service)); } else { init_unistr(&printer->comment, ntprinter->info_2->comment); /* saved comment. */ @@ -4112,26 +4127,29 @@ done: * fill a printer_info_2 struct ********************************************************************/ -static BOOL construct_printer_info_2(Printer_entry *print_hnd, PRINTER_INFO_2 *printer, int snum) +static BOOL construct_printer_info_2(Printer_entry *print_hnd, + PRINTER_INFO_2 *printer, + const struct share_params *params) { int count; NT_PRINTER_INFO_LEVEL *ntprinter = NULL; print_status_struct status; - if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum)))) + if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, + lp_const_servicename(params->service)))) return False; - count = print_queue_length(snum, &status); + count = print_queue_length(params->service, &status); init_unistr(&printer->servername, ntprinter->info_2->servername); /* servername*/ init_unistr(&printer->printername, ntprinter->info_2->printername); /* printername*/ - init_unistr(&printer->sharename, lp_servicename(snum)); /* sharename */ + init_unistr(&printer->sharename, lp_servicename(params->service)); /* sharename */ init_unistr(&printer->portname, ntprinter->info_2->portname); /* port */ init_unistr(&printer->drivername, ntprinter->info_2->drivername); /* drivername */ if (*ntprinter->info_2->comment == '\0') - init_unistr(&printer->comment, lp_comment(snum)); /* comment */ + init_unistr(&printer->comment, lp_comment(params->service)); /* comment */ else init_unistr(&printer->comment, ntprinter->info_2->comment); /* saved comment. */ @@ -4151,7 +4169,8 @@ static BOOL construct_printer_info_2(Printer_entry *print_hnd, PRINTER_INFO_2 *p printer->cjobs = count; /* jobs */ printer->averageppm = ntprinter->info_2->averageppm; /* average pages per minute */ - if ( !(printer->devmode = construct_dev_mode(lp_const_servicename(snum))) ) + if ( !(printer->devmode = construct_dev_mode( + lp_const_servicename(params->service))) ) DEBUG(8, ("Returning NULL Devicemode!\n")); printer->secdesc = NULL; @@ -4176,12 +4195,15 @@ static BOOL construct_printer_info_2(Printer_entry *print_hnd, PRINTER_INFO_2 *p * fill a printer_info_3 struct ********************************************************************/ -static BOOL construct_printer_info_3(Printer_entry *print_hnd, PRINTER_INFO_3 **pp_printer, int snum) +static BOOL construct_printer_info_3(Printer_entry *print_hnd, + PRINTER_INFO_3 **pp_printer, + const struct share_params *params) { NT_PRINTER_INFO_LEVEL *ntprinter = NULL; PRINTER_INFO_3 *printer = NULL; - if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum)))) + if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, + lp_const_servicename(params->service)))) return False; *pp_printer = NULL; @@ -4216,11 +4238,14 @@ static BOOL construct_printer_info_3(Printer_entry *print_hnd, PRINTER_INFO_3 ** * fill a printer_info_4 struct ********************************************************************/ -static BOOL construct_printer_info_4(Printer_entry *print_hnd, PRINTER_INFO_4 *printer, int snum) +static BOOL construct_printer_info_4(Printer_entry *print_hnd, + PRINTER_INFO_4 *printer, + const struct share_params *params) { NT_PRINTER_INFO_LEVEL *ntprinter = NULL; - if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum)))) + if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, + lp_const_servicename(params->service)))) return False; init_unistr(&printer->printername, ntprinter->info_2->printername); /* printername*/ @@ -4236,11 +4261,14 @@ static BOOL construct_printer_info_4(Printer_entry *print_hnd, PRINTER_INFO_4 *p * fill a printer_info_5 struct ********************************************************************/ -static BOOL construct_printer_info_5(Printer_entry *print_hnd, PRINTER_INFO_5 *printer, int snum) +static BOOL construct_printer_info_5(Printer_entry *print_hnd, + PRINTER_INFO_5 *printer, + const struct share_params *params) { NT_PRINTER_INFO_LEVEL *ntprinter = NULL; - if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum)))) + if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, + lp_const_servicename(params->service)))) return False; init_unistr(&printer->printername, ntprinter->info_2->printername); @@ -4257,17 +4285,45 @@ static BOOL construct_printer_info_5(Printer_entry *print_hnd, PRINTER_INFO_5 *p return True; } +/******************************************************************** + * construct_printer_info_6 + * fill a printer_info_6 struct + ********************************************************************/ + +static BOOL construct_printer_info_6(Printer_entry *print_hnd, + PRINTER_INFO_6 *printer, + const struct share_params *params) +{ + NT_PRINTER_INFO_LEVEL *ntprinter = NULL; + int count; + print_status_struct status; + + if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, + lp_const_servicename(params->service)))) + return False; + + count = print_queue_length(params->service, &status); + + printer->status = nt_printq_status(status.status); + + free_a_printer(&ntprinter, 2); + + return True; +} + /******************************************************************** * construct_printer_info_7 * fill a printer_info_7 struct ********************************************************************/ -static BOOL construct_printer_info_7(Printer_entry *print_hnd, PRINTER_INFO_7 *printer, int snum) +static BOOL construct_printer_info_7(Printer_entry *print_hnd, + PRINTER_INFO_7 *printer, + const struct share_params *params) { char *guid_str = NULL; struct GUID guid; - if (is_printer_published(print_hnd, snum, &guid)) { + if (is_printer_published(print_hnd, params->service, &guid)) { asprintf(&guid_str, "{%s}", smb_uuid_string_static(guid)); strupper_m(guid_str); init_unistr(&printer->guid, guid_str); @@ -4297,9 +4353,12 @@ static WERROR enum_all_printers_info_1(uint32 flags, RPC_BUFFER *buffer, uint32 for (snum=0; snum offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; + } + + if (!rpcbuf_alloc_size(buffer, *needed)) { + result = WERR_NOMEM; + goto out; + } + + /* fill the buffer with the structures */ + smb_io_printer_info_6("", buffer, printer, 0); + +out: + /* clear memory */ + free_printer_info_6(printer); + + return result; +} + +static WERROR getprinter_level_7(Printer_entry *print_hnd, + const struct share_params *params, + RPC_BUFFER *buffer, uint32 offered, + uint32 *needed) { PRINTER_INFO_7 *printer=NULL; WERROR result = WERR_OK; @@ -4893,7 +5016,7 @@ static WERROR getprinter_level_7(Printer_entry *print_hnd, int snum, RPC_BUFFER if((printer=SMB_MALLOC_P(PRINTER_INFO_7))==NULL) return WERR_NOMEM; - if (!construct_printer_info_7(print_hnd, printer, snum)) + if (!construct_printer_info_7(print_hnd, printer, params)) return WERR_NOMEM; /* check the required size. */ @@ -4931,6 +5054,7 @@ WERROR _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GET uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; Printer_entry *Printer=find_printer_index_by_hnd(p, handle); + struct share_params *params; int snum; @@ -4945,24 +5069,34 @@ WERROR _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GET *needed=0; - if (!get_printer_snum(p, handle, &snum)) + if (!get_printer_snum(p, handle, &snum, ¶ms)) return WERR_BADFID; switch (level) { case 0: - return getprinter_level_0(Printer, snum, buffer, offered, needed); + return getprinter_level_0(Printer, params, buffer, offered, + needed); case 1: - return getprinter_level_1(Printer, snum, buffer, offered, needed); + return getprinter_level_1(Printer, params, buffer, offered, + needed); case 2: - return getprinter_level_2(Printer, snum, buffer, offered, needed); + return getprinter_level_2(Printer, params, buffer, offered, + needed); case 3: - return getprinter_level_3(Printer, snum, buffer, offered, needed); + return getprinter_level_3(Printer, params, buffer, offered, + needed); case 4: - return getprinter_level_4(Printer, snum, buffer, offered, needed); + return getprinter_level_4(Printer, params, buffer, offered, + needed); case 5: - return getprinter_level_5(Printer, snum, buffer, offered, needed); + return getprinter_level_5(Printer, params, buffer, offered, + needed); + case 6: + return getprinter_level_6(Printer, params, buffer, offered, + needed); case 7: - return getprinter_level_7(Printer, snum, buffer, offered, needed); + return getprinter_level_7(Printer, params, buffer, offered, + needed); } return WERR_UNKNOWN_LEVEL; } @@ -5559,7 +5693,7 @@ WERROR _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_ fstrcpy(servername, get_server_name( printer )); unistr2_to_ascii(architecture, uni_arch, sizeof(architecture)-1); - if (!get_printer_snum(p, handle, &snum)) + if (!get_printer_snum(p, handle, &snum, NULL)) return WERR_BADFID; switch (level) { @@ -5615,7 +5749,7 @@ WERROR _spoolss_endpageprinter(pipes_struct *p, SPOOL_Q_ENDPAGEPRINTER *q_u, SPO return WERR_BADFID; } - if (!get_printer_snum(p, handle, &snum)) + if (!get_printer_snum(p, handle, &snum, NULL)) return WERR_BADFID; Printer->page_started=False; @@ -5664,7 +5798,7 @@ WERROR _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, S } /* get the share number of the printer */ - if (!get_printer_snum(p, handle, &snum)) { + if (!get_printer_snum(p, handle, &snum, NULL)) { return WERR_BADFID; } @@ -5716,7 +5850,7 @@ WERROR _spoolss_writeprinter(pipes_struct *p, SPOOL_Q_WRITEPRINTER *q_u, SPOOL_R return WERR_BADFID; } - if (!get_printer_snum(p, handle, &snum)) + if (!get_printer_snum(p, handle, &snum, NULL)) return WERR_BADFID; (*buffer_written) = (uint32)print_job_write(snum, Printer->jobid, (const char *)buffer, @@ -5752,7 +5886,7 @@ static WERROR control_printer(POLICY_HND *handle, uint32 command, return WERR_BADFID; } - if (!get_printer_snum(p, handle, &snum)) + if (!get_printer_snum(p, handle, &snum, NULL)) return WERR_BADFID; switch (command) { @@ -5797,7 +5931,7 @@ WERROR _spoolss_abortprinter(pipes_struct *p, SPOOL_Q_ABORTPRINTER *q_u, SPOOL_R return WERR_BADFID; } - if (!get_printer_snum(p, handle, &snum)) + if (!get_printer_snum(p, handle, &snum, NULL)) return WERR_BADFID; print_job_delete( &p->pipe_user, snum, Printer->jobid, &errcode ); @@ -5820,7 +5954,7 @@ static WERROR update_printer_sec(POLICY_HND *handle, uint32 level, Printer_entry *Printer = find_printer_index_by_hnd(p, handle); - if (!Printer || !get_printer_snum(p, handle, &snum)) { + if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) { DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle))); @@ -6095,7 +6229,7 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, goto done; } - if (!get_printer_snum(p, handle, &snum)) { + if (!get_printer_snum(p, handle, &snum, NULL)) { result = WERR_BADFID; goto done; } @@ -6286,7 +6420,7 @@ static WERROR publish_or_unpublish_printer(pipes_struct *p, POLICY_HND *handle, if (!Printer) return WERR_BADFID; - if (!get_printer_snum(p, handle, &snum)) + if (!get_printer_snum(p, handle, &snum, NULL)) return WERR_BADFID; nt_printer_publish(Printer, snum, info7->action); @@ -6356,7 +6490,7 @@ WERROR _spoolss_fcpn(pipes_struct *p, SPOOL_Q_FCPN *q_u, SPOOL_R_FCPN *r_u) if ( Printer->printer_type == SPLHND_SERVER) snum = -1; else if ( (Printer->printer_type == SPLHND_PRINTER) && - !get_printer_snum(p, handle, &snum) ) + !get_printer_snum(p, handle, &snum, NULL) ) return WERR_BADFID; srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd); @@ -6603,7 +6737,7 @@ WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO /* lookup the printer snum and tdb entry */ - if (!get_printer_snum(p, handle, &snum)) + if (!get_printer_snum(p, handle, &snum, NULL)) return WERR_BADFID; wret = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum)); @@ -6657,7 +6791,7 @@ WERROR _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u int snum; WERROR errcode = WERR_BADFUNC; - if (!get_printer_snum(p, handle, &snum)) { + if (!get_printer_snum(p, handle, &snum, NULL)) { return WERR_BADFID; } @@ -7883,7 +8017,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S return WERR_BADFID; } - if (!get_printer_snum(p,handle, &snum)) + if (!get_printer_snum(p,handle, &snum, NULL)) return WERR_BADFID; result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); @@ -8048,7 +8182,7 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP return WERR_INVALID_PARAM; } - if (!get_printer_snum(p,handle, &snum)) + if (!get_printer_snum(p,handle, &snum, NULL)) return WERR_BADFID; /* @@ -8120,7 +8254,7 @@ WERROR _spoolss_resetprinter(pipes_struct *p, SPOOL_Q_RESETPRINTER *q_u, SPOOL_R return WERR_BADFID; } - if (!get_printer_snum(p,handle, &snum)) + if (!get_printer_snum(p,handle, &snum, NULL)) return WERR_BADFID; @@ -8150,7 +8284,7 @@ WERROR _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_ return WERR_BADFID; } - if (!get_printer_snum(p, handle, &snum)) + if (!get_printer_snum(p, handle, &snum, NULL)) return WERR_BADFID; if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) { @@ -8202,7 +8336,7 @@ WERROR _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM if ( Printer->printer_type == SPLHND_PRINTER ) { - if (!get_printer_snum(p,handle, &snum)) + if (!get_printer_snum(p,handle, &snum, NULL)) return WERR_BADFID; status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); @@ -8273,7 +8407,7 @@ WERROR _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE if ( Printer->printer_type == SPLHND_PRINTER ) { - if (!get_printer_snum(p,handle, &snum)) + if (!get_printer_snum(p,handle, &snum, NULL)) return WERR_BADFID; status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); @@ -8341,7 +8475,7 @@ WERROR _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM * if ( Printer->printer_type == SPLHND_PRINTER ) { - if (!get_printer_snum(p,handle, &snum)) + if (!get_printer_snum(p,handle, &snum, NULL)) return WERR_BADFID; status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); @@ -8827,7 +8961,7 @@ WERROR _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_ *needed = 0; - if (!get_printer_snum(p, handle, &snum)) + if (!get_printer_snum(p, handle, &snum, NULL)) return WERR_BADFID; wstatus = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum)); @@ -8910,7 +9044,7 @@ WERROR _spoolss_getprinterdataex(pipes_struct *p, SPOOL_Q_GETPRINTERDATAEX *q_u, goto done; } - if ( !get_printer_snum(p,handle, &snum) ) + if ( !get_printer_snum(p,handle, &snum, NULL) ) return WERR_BADFID; status = get_a_printer(Printer, &printer, 2, lp_servicename(snum)); @@ -8996,7 +9130,7 @@ WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, return WERR_INVALID_PARAM; } - if ( !get_printer_snum(p,handle, &snum) ) + if ( !get_printer_snum(p,handle, &snum, NULL) ) return WERR_BADFID; /* @@ -9083,7 +9217,7 @@ WERROR _spoolss_deleteprinterdataex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATAEX return WERR_BADFID; } - if (!get_printer_snum(p, handle, &snum)) + if (!get_printer_snum(p, handle, &snum, NULL)) return WERR_BADFID; if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) { @@ -9135,7 +9269,7 @@ WERROR _spoolss_enumprinterkey(pipes_struct *p, SPOOL_Q_ENUMPRINTERKEY *q_u, SPO return WERR_BADFID; } - if ( !get_printer_snum(p,handle, &snum) ) + if ( !get_printer_snum(p,handle, &snum, NULL) ) return WERR_BADFID; status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); @@ -9205,7 +9339,7 @@ WERROR _spoolss_deleteprinterkey(pipes_struct *p, SPOOL_Q_DELETEPRINTERKEY *q_u, if ( !q_u->keyname.buffer ) return WERR_INVALID_PARAM; - if (!get_printer_snum(p, handle, &snum)) + if (!get_printer_snum(p, handle, &snum, NULL)) return WERR_BADFID; if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) { @@ -9278,7 +9412,7 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ /* get the printer off of disk */ - if (!get_printer_snum(p,handle, &snum)) + if (!get_printer_snum(p,handle, &snum, NULL)) return WERR_BADFID; ZERO_STRUCT(printer); -- cgit From e918cf3abfa14d85cc21bb66d00b9e7cbb0d0626 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 6 Oct 2006 19:07:23 +0000 Subject: r19154: Trivial logic simplification: Get rid of two indentation levels. Survives the consistency checks just checked into Samba4. Volker (This used to be commit c48bb4b37b32fac9d01d243290532641d3701ec7) --- source3/rpc_server/srv_spoolss_nt.c | 83 +++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 32 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 8d9ba7cb90..32cd5766af 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4346,30 +4346,41 @@ static WERROR enum_all_printers_info_1(uint32 flags, RPC_BUFFER *buffer, uint32 int i; int n_services=lp_numservices(); PRINTER_INFO_1 *printers=NULL; - PRINTER_INFO_1 current_prt; WERROR result = WERR_OK; DEBUG(4,("enum_all_printers_info_1\n")); for (snum=0; snum Date: Fri, 6 Oct 2006 19:32:52 +0000 Subject: r19156: Make enumprinters use the share iterators. Volker (This used to be commit 9b1759617ce7841a78d9f792254a9e4fa814858f) --- source3/rpc_server/srv_spoolss_nt.c | 54 ++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 25 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 32cd5766af..b6af6b0b80 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4342,29 +4342,27 @@ static BOOL construct_printer_info_7(Printer_entry *print_hnd, static WERROR enum_all_printers_info_1(uint32 flags, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { - int snum; int i; - int n_services=lp_numservices(); + struct share_iterator *shares; + struct share_params *printer; PRINTER_INFO_1 *printers=NULL; WERROR result = WERR_OK; DEBUG(4,("enum_all_printers_info_1\n")); - for (snum=0; snumservice))); if (!construct_printer_info_1(NULL, flags, ¤t_prt, - ¶ms)) { + printer)) { continue; } @@ -4373,6 +4371,7 @@ static WERROR enum_all_printers_info_1(uint32 flags, RPC_BUFFER *buffer, uint32 DEBUG(2,("enum_all_printers_info_1: failed to enlarge " "printers buffer!\n")); *returned=0; + TALLOC_FREE(shares); return WERR_NOMEM; } DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_1\n", @@ -4381,6 +4380,7 @@ static WERROR enum_all_printers_info_1(uint32 flags, RPC_BUFFER *buffer, uint32 memcpy(&printers[*returned], ¤t_prt, sizeof(PRINTER_INFO_1)); (*returned)++; + TALLOC_FREE(printer); } /* check the required size. */ @@ -4405,6 +4405,7 @@ out: /* clear memory */ SAFE_FREE(printers); + TALLOC_FREE(shares); if ( !W_ERROR_IS_OK(result) ) *returned = 0; @@ -4542,27 +4543,27 @@ static WERROR enum_all_printers_info_1_network(fstring name, RPC_BUFFER *buffer, static WERROR enum_all_printers_info_2(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { - int snum; int i; - int n_services=lp_numservices(); + struct share_iterator *shares; + struct share_params *printer; PRINTER_INFO_2 *printers=NULL; WERROR result = WERR_OK; *returned = 0; - for (snum=0; snumservice))); if (!construct_printer_info_2(NULL, ¤t_prt, - ¶ms)) { + printer)) { continue; } if ( !(printers=SMB_REALLOC_ARRAY(printers, PRINTER_INFO_2, @@ -4570,6 +4571,7 @@ static WERROR enum_all_printers_info_2(RPC_BUFFER *buffer, uint32 offered, uint3 DEBUG(2,("enum_all_printers_info_2: failed to enlarge " "printers buffer!\n")); *returned = 0; + TALLOC_FREE(shares); return WERR_NOMEM; } @@ -4579,6 +4581,7 @@ static WERROR enum_all_printers_info_2(RPC_BUFFER *buffer, uint32 offered, uint3 memcpy(&printers[*returned], ¤t_prt, sizeof(PRINTER_INFO_2)); (*returned)++; + TALLOC_FREE(printer); } /* check the required size. */ @@ -4606,6 +4609,7 @@ out: free_devmode(printers[i].devmode); SAFE_FREE(printers); + TALLOC_FREE(shares); if ( !W_ERROR_IS_OK(result) ) *returned = 0; -- cgit From caf8c6a76be051559ffcfe97084edca43e0a3cee Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 30 Jan 2007 22:22:06 +0000 Subject: r21064: The core of this patch is void message_register(int msg_type, void (*fn)(int msg_type, struct process_id pid, - void *buf, size_t len)) + void *buf, size_t len, + void *private_data), + void *private_data) { struct dispatch_fns *dfn; So this adds a (so far unused) private pointer that is passed from message_register to the message handler. A prerequisite to implement a tiny samba4-API compatible wrapper around our messaging system. That itself is necessary for the Samba4 notify system. Yes, I know, I could import the whole Samba4 messaging system, but I want to do it step by step and I think getting notify in is more important in this step. Volker (This used to be commit c8ae60ed65dcce9660ee39c75488f2838cf9a28b) --- source3/rpc_server/srv_spoolss_nt.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index b6af6b0b80..a655b7054b 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1107,7 +1107,8 @@ static BOOL notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, voi ********************************************************************/ static void receive_notify2_message_list(int msg_type, struct process_id src, - void *msg, size_t len) + void *msg, size_t len, + void *private_data) { size_t msg_count, i; char *buf = (char *)msg; @@ -1219,7 +1220,8 @@ static BOOL srv_spoolss_drv_upgrade_printer(char* drivername) over all printers, upgrading ones as necessary **********************************************************************/ -void do_drv_upgrade_printer(int msg_type, struct process_id src, void *buf, size_t len) +void do_drv_upgrade_printer(int msg_type, struct process_id src, + void *buf, size_t len, void *private_data) { fstring drivername; int snum; @@ -1317,7 +1319,7 @@ static BOOL srv_spoolss_reset_printerdata(char* drivername) **********************************************************************/ void reset_all_printerdata(int msg_type, struct process_id src, - void *buf, size_t len) + void *buf, size_t len, void *private_data) { fstring drivername; int snum; @@ -2597,7 +2599,8 @@ static BOOL srv_spoolss_replyopenprinter(int snum, const char *printer, if ( !spoolss_connect_to_client( ¬ify_cli_pipe, client_ip, unix_printer )) return False; - message_register(MSG_PRINTER_NOTIFY2, receive_notify2_message_list); + message_register(MSG_PRINTER_NOTIFY2, + receive_notify2_message_list, NULL); /* Tell the connections db we're now interested in printer * notify messages. */ register_message_flags( True, FLAG_MSG_PRINT_NOTIFY ); -- cgit From 0150bd394ba73c7fb379294f7a78d710abdcbabf Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 31 Jan 2007 20:28:32 +0000 Subject: r21099: Protect ourselves from null pointer deref. This isn't the correct fix for the Vista bug, but it needed as protection against invalid RPC. Thanks to Martin Zielinski for pointing this out. Jeremy. (This used to be commit fbab8e4ba93325f68353ee345a257a5445d78e67) --- source3/rpc_server/srv_spoolss_nt.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a655b7054b..3270801fc2 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -5988,6 +5988,12 @@ static WERROR update_printer_sec(POLICY_HND *handle, uint32 level, goto done; } + if (!secdesc_ctr) { + DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n")); + result = WERR_INVALID_PARAM; + goto done; + } + /* Check the user has permissions to change the security descriptor. By experimentation with two NT machines, the user requires Full Access to the printer to change security -- cgit From d4135a3bdbe70bf87632396b79af5b17c7da5dd5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 3 Feb 2007 00:50:47 +0000 Subject: r21129: Fix from Martin Zielinski - ensure the hand marshalled container size is a multiple of 4 bytes for RPC alignment. Jeremy. (This used to be commit 0e9ad2b29f1c05dc3f5d5e9659fe0557fa077d2e) --- source3/rpc_server/srv_spoolss_nt.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 3270801fc2..d0a754f281 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -9532,6 +9532,16 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ /* copy data into the reply */ r_u->ctr.size = r_u->needed; + + /* Fix from Martin Zielinski - ensure + * the hand marshalled container size is a multiple + * of 4 bytes for RPC alignment. + */ + + if (needed % 4) { + r_u->ctr.size += 4-(needed % 4); + } + r_u->ctr.size_of_array = r_u->returned; r_u->ctr.values = enum_values; -- cgit From 3ad849db21c7ba7171f3980629de031d5c8adc95 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 5 Feb 2007 19:32:31 +0000 Subject: r21164: Fix from Martin Zielinski for EnumprinterdataEX on Vista. Jeremy. (This used to be commit b16707a8615e1d00839d31e7a3061fb111336691) --- source3/rpc_server/srv_spoolss_nt.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index d0a754f281..48b34755a6 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -9521,6 +9521,15 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ /* housekeeping information in the reply */ + /* Fix from Martin Zielinski - ensure + * the hand marshalled container size is a multiple + * of 4 bytes for RPC alignment. + */ + + if (needed % 4) { + needed += 4-(needed % 4); + } + r_u->needed = needed; r_u->returned = num_entries; @@ -9533,15 +9542,6 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ r_u->ctr.size = r_u->needed; - /* Fix from Martin Zielinski - ensure - * the hand marshalled container size is a multiple - * of 4 bytes for RPC alignment. - */ - - if (needed % 4) { - r_u->ctr.size += 4-(needed % 4); - } - r_u->ctr.size_of_array = r_u->returned; r_u->ctr.values = enum_values; -- cgit From 8c5846acf241307ebd82b41fd454f0f50825a37a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 27 Feb 2007 22:04:23 +0000 Subject: r21569: Fix bug reported by Martin Zielinski where return value was incorrectly initialized. Jeremy. (This used to be commit 8d45f1f3b524031a34cfba21b677be8a09fc192c) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 48b34755a6..958e9d81fe 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -8633,7 +8633,7 @@ WERROR _spoolss_enumprintprocessors(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCESSORS static WERROR enumprintprocdatatypes_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { PRINTPROCDATATYPE_1 *info_1=NULL; - WERROR result = WERR_NOMEM; + WERROR result = WERR_OK; if((info_1 = SMB_MALLOC_P(PRINTPROCDATATYPE_1)) == NULL) return WERR_NOMEM; -- cgit From 56ba44766854ed7cda265bdaf85913f2a1008282 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 28 Mar 2007 13:34:59 +0000 Subject: r22001: change prototype of dump_data(), so that it takes unsigned char * now, which matches what samba4 has. also fix all the callers to prevent compiler warnings metze (This used to be commit fa322f0cc9c26a9537ba3f0a7d4e4a25941317e7) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 958e9d81fe..e06d613c74 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1097,7 +1097,7 @@ static BOOL notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, voi DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0], msg->notify.value[1])); else - dump_data(3, msg->notify.data, msg->len); + dump_data(3, (uint8 *)msg->notify.data, msg->len); return True; } -- cgit From bc2b6436d0f5f3e9ffdfaeb7f1b32996a83d5478 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 29 Mar 2007 09:35:51 +0000 Subject: r22009: change TDB_DATA from char * to unsigned char * and fix all compiler warnings in the users metze (This used to be commit 3a28443079c141a6ce8182c65b56ca210e34f37f) --- source3/rpc_server/srv_spoolss_nt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index e06d613c74..b33fc6b5b0 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1073,18 +1073,18 @@ static BOOL notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, voi /* Unpack message */ - offset += tdb_unpack((char *)buf + offset, len - offset, "f", + offset += tdb_unpack((uint8 *)buf + offset, len - offset, "f", msg->printer); - offset += tdb_unpack((char *)buf + offset, len - offset, "ddddddd", + offset += tdb_unpack((uint8 *)buf + offset, len - offset, "ddddddd", &tv_sec, &tv_usec, &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags); if (msg->len == 0) - tdb_unpack((char *)buf + offset, len - offset, "dd", + tdb_unpack((uint8 *)buf + offset, len - offset, "dd", &msg->notify.value[0], &msg->notify.value[1]); else - tdb_unpack((char *)buf + offset, len - offset, "B", + tdb_unpack((uint8 *)buf + offset, len - offset, "B", &msg->len, &msg->notify.data); DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n", -- cgit From 7f8d89bc5488cea1b85161dec98dc1a2dddd7b45 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 3 Apr 2007 19:47:19 +0000 Subject: r22062: Fix the parsing of info level 3. Flags is not a flags field, but an offset. Fixed 64-bit display of ACLs on printers. Jeremy. (This used to be commit 0c8949ff5d742dbe59f2af0f57a289f238e3592c) --- source3/rpc_server/srv_spoolss_nt.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index b33fc6b5b0..3e1c1a2408 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4220,8 +4220,6 @@ static BOOL construct_printer_info_3(Printer_entry *print_hnd, /* These are the components of the SD we are returning. */ - printer->flags = 0x4; - if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->sd_size != 0) { /* don't use talloc_steal() here unless you do a deep steal of all the SEC_DESC members */ -- cgit From 12ba88574bf91bdcc4447bfc3d429b799064bfd9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 27 Apr 2007 23:18:41 +0000 Subject: r22542: Move over to using the _strict varients of the talloc calls. No functional changes. Looks bigger than it is :-). Jeremy. (This used to be commit f6fa3080fee1b20df9f1968500840a88cf0ee592) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 3e1c1a2408..beb3b5aef0 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -9504,7 +9504,7 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ if ( data_len ) { if ( !(enum_values[i].data = (uint8 *)TALLOC_MEMDUP(p->mem_ctx, regval_data_p(val), data_len)) ) { - DEBUG(0,("talloc_memdup failed to allocate memory [data_len=%d] for data!\n", + DEBUG(0,("TALLOC_MEMDUP failed to allocate memory [data_len=%d] for data!\n", data_len )); result = WERR_NOMEM; goto done; -- cgit From 1e362c0e7fff603cffa32863a5b07ecbc50f8a2d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 30 Apr 2007 01:17:34 +0000 Subject: r22587: Ensure TALLOC_ZERO_ARRAY is consistent. Jeremy. (This used to be commit c3df5d08dd6a983f9d53dc6628a50e571d322e8d) --- source3/rpc_server/srv_spoolss_nt.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index beb3b5aef0..08c3a46133 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2495,9 +2495,8 @@ done: if ( printer ) free_a_printer( &printer, 2 ); return WERR_NOMEM; - } - } - else { + } + } else { *data = NULL; } } -- cgit From 79de0ad9463a5cd64978beae37df79fbb4f74632 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 30 Apr 2007 01:34:28 +0000 Subject: r22588: Make all uses of TALLOC_MEMDUP consistent. Jeremy. (This used to be commit 8ad13718af0ba1fcb10a6f1631b1ed3cb8d11175) --- source3/rpc_server/srv_spoolss_nt.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 08c3a46133..abe944322e 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1416,11 +1416,15 @@ static DEVICEMODE* dup_devicemode(TALLOC_CTX *ctx, DEVICEMODE *devmode) return NULL; } - d->dev_private = (uint8 *)TALLOC_MEMDUP(ctx, devmode->dev_private, + if (devmode->driverextra) { + d->dev_private = (uint8 *)TALLOC_MEMDUP(ctx, devmode->dev_private, devmode->driverextra); - if (!d->dev_private) { - return NULL; - } + if (!d->dev_private) { + return NULL; + } + } else { + d->dev_private = NULL; + } return d; } -- cgit From 879081236d634c6483ac17a563171ad30f3af53b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 30 Apr 2007 04:16:56 +0000 Subject: r22593: Finish doing the same for raw TALLOC. Jeremy. (This used to be commit aef3c262b724d1283187e732833519c4e6fb088c) --- source3/rpc_server/srv_spoolss_nt.c | 281 ++++++++++++++++++++++-------------- 1 file changed, 172 insertions(+), 109 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index abe944322e..5a19f2de20 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -723,15 +723,18 @@ static void notify_system_time(struct spoolss_notify_msg *msg, } data->notify_data.data.length = prs_offset(&ps); - data->notify_data.data.string = (uint16 *) - TALLOC(mem_ctx, prs_offset(&ps)); - if (!data->notify_data.data.string) { - prs_mem_free(&ps); - return; + if (prs_offset(&ps)) { + data->notify_data.data.string = (uint16 *) + TALLOC(mem_ctx, prs_offset(&ps)); + if (!data->notify_data.data.string) { + prs_mem_free(&ps); + return; + } + prs_copy_all_data_out((char *)data->notify_data.data.string, &ps); + } else { + data->notify_data.data.string = NULL; } - prs_copy_all_data_out((char *)data->notify_data.data.string, &ps); - prs_mem_free(&ps); } @@ -2708,14 +2711,17 @@ void spoolss_notify_server_name(int snum, len = rpcstr_push(temp, printer->info_2->servername, sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; - } + if (len) { + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } - memcpy(data->notify_data.data.string, temp, len); + memcpy(data->notify_data.data.string, temp, len); + } else { + data->notify_data.data.string = NULL; + } } /******************************************************************* @@ -2743,14 +2749,16 @@ void spoolss_notify_printer_name(int snum, len = rpcstr_push(temp, p, sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; + if (len) { + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } + memcpy(data->notify_data.data.string, temp, len); + } else { + data->notify_data.data.string = NULL; } - - memcpy(data->notify_data.data.string, temp, len); } /******************************************************************* @@ -2769,14 +2777,17 @@ void spoolss_notify_share_name(int snum, len = rpcstr_push(temp, lp_servicename(snum), sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; + if (len) { + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } + memcpy(data->notify_data.data.string, temp, len); + } else { + data->notify_data.data.string = NULL; } - memcpy(data->notify_data.data.string, temp, len); } /******************************************************************* @@ -2797,14 +2808,18 @@ void spoolss_notify_port_name(int snum, len = rpcstr_push(temp, printer->info_2->portname, sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); + if (len) { + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; - } + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } - memcpy(data->notify_data.data.string, temp, len); + memcpy(data->notify_data.data.string, temp, len); + } else { + data->notify_data.data.string = NULL; + } } /******************************************************************* @@ -2824,14 +2839,18 @@ void spoolss_notify_driver_name(int snum, len = rpcstr_push(temp, printer->info_2->drivername, sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); + if (len) { + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; - } + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } - memcpy(data->notify_data.data.string, temp, len); + memcpy(data->notify_data.data.string, temp, len); + } else { + data->notify_data.data.string = NULL; + } } /******************************************************************* @@ -2853,14 +2872,18 @@ void spoolss_notify_comment(int snum, len = rpcstr_push(temp, printer->info_2->comment, sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); + if (len) { + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; - } + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } - memcpy(data->notify_data.data.string, temp, len); + memcpy(data->notify_data.data.string, temp, len); + } else { + data->notify_data.data.string = NULL; + } } /******************************************************************* @@ -2880,14 +2903,18 @@ void spoolss_notify_location(int snum, len = rpcstr_push(temp, printer->info_2->location,sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); + if (len) { + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; - } + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } - memcpy(data->notify_data.data.string, temp, len); + memcpy(data->notify_data.data.string, temp, len); + } else { + data->notify_data.data.string = NULL; + } } /******************************************************************* @@ -2922,14 +2949,18 @@ void spoolss_notify_sepfile(int snum, len = rpcstr_push(temp, printer->info_2->sepfile, sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); + if (len) { + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; - } + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } - memcpy(data->notify_data.data.string, temp, len); + memcpy(data->notify_data.data.string, temp, len); + } else { + data->notify_data.data.string = NULL; + } } /******************************************************************* @@ -2949,14 +2980,18 @@ void spoolss_notify_print_processor(int snum, len = rpcstr_push(temp, printer->info_2->printprocessor, sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); + if (len) { + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; - } + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } - memcpy(data->notify_data.data.string, temp, len); + memcpy(data->notify_data.data.string, temp, len); + } else { + data->notify_data.data.string = NULL; + } } /******************************************************************* @@ -2976,14 +3011,18 @@ void spoolss_notify_parameters(int snum, len = rpcstr_push(temp, printer->info_2->parameters, sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); + if (len) { + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; - } + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } - memcpy(data->notify_data.data.string, temp, len); + memcpy(data->notify_data.data.string, temp, len); + } else { + data->notify_data.data.string = NULL; + } } /******************************************************************* @@ -3003,14 +3042,18 @@ void spoolss_notify_datatype(int snum, len = rpcstr_push(temp, printer->info_2->datatype, sizeof(pstring)-2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); + if (len) { + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; - } + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } - memcpy(data->notify_data.data.string, temp, len); + memcpy(data->notify_data.data.string, temp, len); + } else { + data->notify_data.data.string = NULL; + } } /******************************************************************* @@ -3163,14 +3206,18 @@ static void spoolss_notify_username(int snum, len = rpcstr_push(temp, queue->fs_user, sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); + if (len) { + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; - } + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } - memcpy(data->notify_data.data.string, temp, len); + memcpy(data->notify_data.data.string, temp, len); + } else { + data->notify_data.data.string = NULL; + } } /******************************************************************* @@ -3203,14 +3250,18 @@ static void spoolss_notify_job_name(int snum, len = rpcstr_push(temp, queue->fs_file, sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); + if (len) { + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; - } + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } - memcpy(data->notify_data.data.string, temp, len); + memcpy(data->notify_data.data.string, temp, len); + } else { + data->notify_data.data.string = NULL; + } } /******************************************************************* @@ -3253,14 +3304,18 @@ static void spoolss_notify_job_status_string(int snum, len = rpcstr_push(temp, p, sizeof(temp) - 2, STR_TERMINATE); data->notify_data.data.length = len; - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); + if (len) { + data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; - } + if (!data->notify_data.data.string) { + data->notify_data.data.length = 0; + return; + } - memcpy(data->notify_data.data.string, temp, len); + memcpy(data->notify_data.data.string, temp, len); + } else { + data->notify_data.data.string = NULL; + } } /******************************************************************* @@ -8119,14 +8174,18 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S *out_max_value_len=(in_value_len/sizeof(uint16)); - if((*out_value=(uint16 *)TALLOC_ZERO(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL) - { - result = WERR_NOMEM; - goto done; + if (in_value_len) { + if((*out_value=(uint16 *)TALLOC_ZERO(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL) + { + result = WERR_NOMEM; + goto done; + } + *out_value_len = (uint32)rpcstr_push((char *)*out_value, "", in_value_len, 0); + } else { + *out_value=NULL; + *out_value_len = 0; } - *out_value_len = (uint32)rpcstr_push((char *)*out_value, "", in_value_len, 0); - /* the data is counted in bytes */ *out_max_data_len = in_data_len; @@ -8155,13 +8214,18 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S /* name */ *out_max_value_len=(in_value_len/sizeof(uint16)); - if ( (*out_value = (uint16 *)TALLOC_ZERO(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL ) - { - result = WERR_NOMEM; - goto done; - } + if (in_value_len) { + if ( (*out_value = (uint16 *)TALLOC_ZERO(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL ) + { + result = WERR_NOMEM; + goto done; + } - *out_value_len = (uint32)rpcstr_push((char *)*out_value, regval_name(val), (size_t)in_value_len, 0); + *out_value_len = (uint32)rpcstr_push((char *)*out_value, regval_name(val), (size_t)in_value_len, 0); + } else { + *out_value = NULL; + *out_value_len = 0; + } /* type */ @@ -8176,7 +8240,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S goto done; } data_len = regval_size(val); - if ( *data_out ) + if ( *data_out && data_len ) memcpy( *data_out, regval_data_p(val), data_len ); *out_data_len = data_len; } @@ -9117,10 +9181,9 @@ done: status = WERR_NOMEM; goto done; } - } - else { + } else { *data = NULL; - } + } } if ( printer ) -- cgit From e6383f47629368d9dd4e803f17566a24e9d7359e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 7 May 2007 09:35:35 +0000 Subject: r22736: Start to merge the low-hanging fruit from the now 7000-line cluster patch. This changes "struct process_id" to "struct server_id", keeping both is just too much hassle. No functional change (I hope ;-)) Volker (This used to be commit 0ad4b1226c9d91b72136310d3bbb640d2c5d67b8) --- source3/rpc_server/srv_spoolss_nt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 5a19f2de20..7e46541b94 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1109,7 +1109,7 @@ static BOOL notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, voi Receive a notify2 message list ********************************************************************/ -static void receive_notify2_message_list(int msg_type, struct process_id src, +static void receive_notify2_message_list(int msg_type, struct server_id src, void *msg, size_t len, void *private_data) { @@ -1223,7 +1223,7 @@ static BOOL srv_spoolss_drv_upgrade_printer(char* drivername) over all printers, upgrading ones as necessary **********************************************************************/ -void do_drv_upgrade_printer(int msg_type, struct process_id src, +void do_drv_upgrade_printer(int msg_type, struct server_id src, void *buf, size_t len, void *private_data) { fstring drivername; @@ -1321,7 +1321,7 @@ static BOOL srv_spoolss_reset_printerdata(char* drivername) over all printers, resetting printer data as neessary **********************************************************************/ -void reset_all_printerdata(int msg_type, struct process_id src, +void reset_all_printerdata(int msg_type, struct server_id src, void *buf, size_t len, void *private_data) { fstring drivername; -- cgit From 4aa44f7475e03dcc596f6a13fffffda7268074a1 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 8 May 2007 13:44:36 +0000 Subject: r22761: This introduces lib/conn_tdb.c with two main functions: connections_traverse and connections_forall. This centralizes all the routines that did individual tdb_open("connections.tdb") and direct tdb_traverse. Volker (This used to be commit e43e94cda1ad8876b3cb5d1129080b57fa6ec214) --- source3/rpc_server/srv_spoolss_nt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 7e46541b94..a4edeb2cfd 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -311,7 +311,7 @@ WERROR delete_printer_hook( NT_USER_TOKEN *token, const char *sharename ) if ( (ret = smbrun(command, NULL)) == 0 ) { /* Tell everyone we updated smb.conf. */ - message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL); + message_send_all(MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL); } if ( is_print_op ) @@ -6253,7 +6253,7 @@ BOOL add_printer_hook(NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer) if ( (ret = smbrun(command, &fd)) == 0 ) { /* Tell everyone we updated smb.conf. */ - message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL); + message_send_all(MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL); } if ( is_print_op ) -- cgit From fb99bbe67597555109ebd65613a5aab395b43499 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 15 May 2007 10:50:44 +0000 Subject: r22895: Convert some more calls from message_send_buf to messaging_send_buf (This used to be commit c8b98273406242a89a7e5d1fb5d79120ebe5822a) --- source3/rpc_server/srv_spoolss_nt.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a4edeb2cfd..cbc44a224a 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1212,8 +1212,9 @@ static BOOL srv_spoolss_drv_upgrade_printer(char* drivername) DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n", drivername)); - message_send_pid(pid_to_procid(sys_getpid()), - MSG_PRINTER_DRVUPGRADE, drivername, len+1, False); + messaging_send_buf(smbd_messaging_context(), procid_self(), + MSG_PRINTER_DRVUPGRADE, + (uint8 *)drivername, len+1); return True; } @@ -1310,8 +1311,9 @@ static BOOL srv_spoolss_reset_printerdata(char* drivername) DEBUG(10,("srv_spoolss_reset_printerdata: Sending message about resetting printerdata [%s]\n", drivername)); - message_send_pid(pid_to_procid(sys_getpid()), - MSG_PRINTERDATA_INIT_RESET, drivername, len+1, False); + messaging_send_buf(smbd_messaging_context(), procid_self(), + MSG_PRINTERDATA_INIT_RESET, + (uint8 *)drivername, len+1); return True; } -- cgit From 8c3f8e5697f29f1a9829298e0561ff7305b62082 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 15 May 2007 15:49:55 +0000 Subject: r22911: Pass a messaging_context to message_send_all (This used to be commit cc92ce665dcfe9054d09429219883b18a4cab090) --- source3/rpc_server/srv_spoolss_nt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index cbc44a224a..e2dd773c04 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -311,7 +311,8 @@ WERROR delete_printer_hook( NT_USER_TOKEN *token, const char *sharename ) if ( (ret = smbrun(command, NULL)) == 0 ) { /* Tell everyone we updated smb.conf. */ - message_send_all(MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL); + message_send_all(smbd_messaging_context(), + MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL); } if ( is_print_op ) @@ -6255,7 +6256,8 @@ BOOL add_printer_hook(NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer) if ( (ret = smbrun(command, &fd)) == 0 ) { /* Tell everyone we updated smb.conf. */ - message_send_all(MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL); + message_send_all(smbd_messaging_context(), + MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL); } if ( is_print_op ) -- cgit From e95942ed84fef4dd34c380d59145d3e182b01702 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 16 May 2007 20:56:39 +0000 Subject: r22954: More messaging_register (This used to be commit 9b8df24107ffe3016031e5257c5680689f061886) --- source3/rpc_server/srv_spoolss_nt.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index e2dd773c04..49782dca43 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1225,15 +1225,19 @@ static BOOL srv_spoolss_drv_upgrade_printer(char* drivername) over all printers, upgrading ones as necessary **********************************************************************/ -void do_drv_upgrade_printer(int msg_type, struct server_id src, - void *buf, size_t len, void *private_data) +void do_drv_upgrade_printer(struct messaging_context *msg, + void *private_data, + uint32_t msg_type, + struct server_id server_id, + DATA_BLOB *data) { fstring drivername; int snum; int n_services = lp_numservices(); + size_t len; - len = MIN(len,sizeof(drivername)-1); - strncpy(drivername, (const char *)buf, len); + len = MIN(data->length,sizeof(drivername)-1); + strncpy(drivername, (const char *)data->data, len); DEBUG(10,("do_drv_upgrade_printer: Got message for new driver [%s]\n", drivername )); @@ -1324,15 +1328,19 @@ static BOOL srv_spoolss_reset_printerdata(char* drivername) over all printers, resetting printer data as neessary **********************************************************************/ -void reset_all_printerdata(int msg_type, struct server_id src, - void *buf, size_t len, void *private_data) +void reset_all_printerdata(struct messaging_context *msg, + void *private_data, + uint32_t msg_type, + struct server_id server_id, + DATA_BLOB *data) { fstring drivername; int snum; int n_services = lp_numservices(); + size_t len; - len = MIN( len, sizeof(drivername)-1 ); - strncpy( drivername, (const char *)buf, len ); + len = MIN( data->length, sizeof(drivername)-1 ); + strncpy( drivername, (const char *)data->data, len ); DEBUG(10,("reset_all_printerdata: Got message for new driver [%s]\n", drivername )); -- cgit From 4d5f58c2b945e7a2263ba42749f73c7ba72ab3c7 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 19 May 2007 21:53:28 +0000 Subject: r23015: Make message_(de)register static to messages.c (This used to be commit a8082a3c7c3d1e68c27fc3bf42f3d44402cc6f9f) --- source3/rpc_server/srv_spoolss_nt.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 49782dca43..890d2e0885 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -166,7 +166,8 @@ static void srv_spoolss_replycloseprinter(int snum, POLICY_HND *handle) cli_shutdown( notify_cli_pipe->cli ); notify_cli_pipe = NULL; /* The above call shuts downn the pipe also. */ - message_deregister(MSG_PRINTER_NOTIFY2); + messaging_deregister(smbd_messaging_context(), + MSG_PRINTER_NOTIFY2, NULL); /* Tell the connections db we're no longer interested in * printer notify messages. */ @@ -1110,19 +1111,21 @@ static BOOL notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, voi Receive a notify2 message list ********************************************************************/ -static void receive_notify2_message_list(int msg_type, struct server_id src, - void *msg, size_t len, - void *private_data) +static void receive_notify2_message_list(struct messaging_context *msg, + void *private_data, + uint32_t msg_type, + struct server_id server_id, + DATA_BLOB *data) { size_t msg_count, i; - char *buf = (char *)msg; + char *buf = (char *)data->data; char *msg_ptr; size_t msg_len; SPOOLSS_NOTIFY_MSG notify; SPOOLSS_NOTIFY_MSG_CTR messages; int num_groups; - if (len < 4) { + if (data->length < 4) { DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n")); return; } @@ -1152,7 +1155,7 @@ static void receive_notify2_message_list(int msg_type, struct server_id src, for ( i=0; i len) { + if (msg_ptr + 4 - buf > data->length) { DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n")); return; } @@ -1160,7 +1163,7 @@ static void receive_notify2_message_list(int msg_type, struct server_id src, msg_len = IVAL(msg_ptr,0); msg_ptr += 4; - if (msg_ptr + msg_len - buf > len) { + if (msg_ptr + msg_len - buf > data->length) { DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n")); return; } @@ -2616,8 +2619,9 @@ static BOOL srv_spoolss_replyopenprinter(int snum, const char *printer, if ( !spoolss_connect_to_client( ¬ify_cli_pipe, client_ip, unix_printer )) return False; - message_register(MSG_PRINTER_NOTIFY2, - receive_notify2_message_list, NULL); + messaging_register(smbd_messaging_context(), NULL, + MSG_PRINTER_NOTIFY2, + receive_notify2_message_list); /* Tell the connections db we're now interested in printer * notify messages. */ register_message_flags( True, FLAG_MSG_PRINT_NOTIFY ); -- cgit From ac3f08ddbe0b484375624db0e35999a8584b57f4 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 21 May 2007 22:17:13 +0000 Subject: r23055: Rewrite messages.c to use auto-generated marshalling in the tdb. I'm doing this because for the clustering the marshalling is needed in more than one place, so I wanted a decent routine to marshall a message_rec struct which was not there before. Tridge, this seems about the same speed as it used to be before, the librpc/ndr overhead in my tests was under the noise. Volker (This used to be commit eaefd00563173dfabb7716c5695ac0a2f7139bb6) --- source3/rpc_server/srv_spoolss_nt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 890d2e0885..2047e13df3 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -313,7 +313,7 @@ WERROR delete_printer_hook( NT_USER_TOKEN *token, const char *sharename ) if ( (ret = smbrun(command, NULL)) == 0 ) { /* Tell everyone we updated smb.conf. */ message_send_all(smbd_messaging_context(), - MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL); + MSG_SMB_CONF_UPDATED, NULL, 0, NULL); } if ( is_print_op ) @@ -6269,7 +6269,7 @@ BOOL add_printer_hook(NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer) if ( (ret = smbrun(command, &fd)) == 0 ) { /* Tell everyone we updated smb.conf. */ message_send_all(smbd_messaging_context(), - MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL); + MSG_SMB_CONF_UPDATED, NULL, 0, NULL); } if ( is_print_op ) -- cgit From 65f7a9d084ec455a0c8a504c978e49b56e37af32 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 9 Jul 2007 08:04:43 +0000 Subject: r23758: Fix Coverity id 385 (This used to be commit 4d9f627cc8081307da3f84f784602533bd20c1e6) --- source3/rpc_server/srv_spoolss_nt.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 2047e13df3..464ca36f3c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -7490,8 +7490,13 @@ WERROR enumports_hook( int *count, char ***lines ) /* if no hook then just fill in the default port */ if ( !*cmd ) { - qlines = SMB_MALLOC_ARRAY( char*, 2 ); - qlines[0] = SMB_STRDUP( SAMBA_PRINTER_PORT_NAME ); + if (!(qlines = SMB_MALLOC_ARRAY( char*, 2 ))) { + return WERR_NOMEM; + } + if (!(qlines[0] = SMB_STRDUP( SAMBA_PRINTER_PORT_NAME ))) { + SAFE_FREE(qlines); + return WERR_NOMEM; + } qlines[1] = NULL; numlines = 1; } -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 464ca36f3c..94bc0f80aa 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -10,7 +10,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, -- cgit From 153cfb9c83534b09f15cc16205d7adb19b394928 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 05:23:25 +0000 Subject: r23801: The FSF has moved around a lot. This fixes their Mass Ave address. (This used to be commit 87c91e4362c51819032bfbebbb273c52e203b227) --- source3/rpc_server/srv_spoolss_nt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 94bc0f80aa..f8e109fb34 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -19,8 +19,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program; if not, see . */ /* Since the SPOOLSS rpc routines are basically DOS 16-bit calls wrapped -- cgit From 22b30d2a372bc9a018c592991a6478dc963e670d Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 10 Aug 2007 20:03:31 +0000 Subject: r24316: Fix an uninitialized read Jerry, please check this! Thanks, Volker (This used to be commit db1b89072c3f214c3cb4be844cd7b417e5361615) --- source3/rpc_server/srv_spoolss_nt.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index f8e109fb34..b50e1e7558 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2275,6 +2275,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint *type = REG_DWORD; if ( !(*data = TALLOC_ARRAY(ctx, uint8, sizeof(uint32) )) ) return WERR_NOMEM; + SIVAL(*data, 0, 0x00); *needed = 0x4; return WERR_OK; } -- cgit From 929e1d99209e20a9c2c95c8bdfc8eaa37b2c2291 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 30 Aug 2007 19:48:31 +0000 Subject: r24809: Consolidate the use of temporary talloc contexts. This adds the two functions talloc_stackframe() and talloc_tos(). * When a new talloc stackframe is allocated with talloc_stackframe(), then * the TALLOC_CTX returned with talloc_tos() is reset to that new * frame. Whenever that stack frame is TALLOC_FREE()'ed, then the reverse * happens: The previous talloc_tos() is restored. * * This API is designed to be robust in the sense that if someone forgets to * TALLOC_FREE() a stackframe, then the next outer one correctly cleans up and * resets the talloc_tos(). The original motivation for this patch was to get rid of the sid_string_static & friends buffers. Explicitly passing talloc context everywhere clutters code too much for my taste, so an implicit talloc_tos() is introduced here. Many of these static buffers are replaced by a single static pointer. The intended use would thus be that low-level functions can rather freely push stuff to talloc_tos, the upper layers clean up by freeing the stackframe. The more of these stackframes are used and correctly freed the more exact the memory cleanup happens. This patch removes the main_loop_talloc_ctx, tmp_talloc_ctx and lp_talloc_ctx (did I forget any?) So, never do a tmp_ctx = talloc_init("foo"); anymore, instead, use tmp_ctx = talloc_stackframe() :-) Volker (This used to be commit 6585ea2cb7f417e14540495b9c7380fe9c8c717b) --- source3/rpc_server/srv_spoolss_nt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index b50e1e7558..600eb2f688 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -389,7 +389,7 @@ static BOOL get_printer_snum(pipes_struct *p, POLICY_HND *hnd, int *number, DEBUG(4,("short name:%s\n", Printer->sharename)); *number = print_queue_snum(Printer->sharename); if ((*number != -1) && (params != NULL)) { - *params = get_share_params(tmp_talloc_ctx(), + *params = get_share_params(talloc_tos(), Printer->sharename); if (*params == NULL) { return False; @@ -4257,7 +4257,7 @@ static BOOL construct_printer_info_2(Printer_entry *print_hnd, /* don't use talloc_steal() here unless you do a deep steal of all the SEC_DESC members */ - printer->secdesc = dup_sec_desc( get_talloc_ctx(), + printer->secdesc = dup_sec_desc( talloc_tos(), ntprinter->info_2->secdesc_buf->sd ); } @@ -4297,7 +4297,7 @@ static BOOL construct_printer_info_3(Printer_entry *print_hnd, /* don't use talloc_steal() here unless you do a deep steal of all the SEC_DESC members */ - printer->secdesc = dup_sec_desc( get_talloc_ctx(), + printer->secdesc = dup_sec_desc( talloc_tos(), ntprinter->info_2->secdesc_buf->sd ); } -- cgit From c97fe37ea3d92a631e8da17c21dafae1db15e97b Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 21 Sep 2007 14:37:35 +0000 Subject: r25294: Tidy up callers of unistr2_to_ascii() to pass sizeof(target_area) to the maxeln parameter instead of sizeof(target_area) - 1 (or even sizeof(fstring) - 1 in some places. I hope these were really all there were. Michael (This used to be commit 9a28be220df622322857dfe102fa35e108f932dc) --- source3/rpc_server/srv_spoolss_nt.c | 54 ++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 600eb2f688..f573d3fdc6 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1549,7 +1549,7 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, /* some sanity check because you can open a printer or a print server */ /* aka: \\server\printer or \\server */ - unistr2_to_ascii(name, q_u->printername, sizeof(name)-1); + unistr2_to_ascii(name, q_u->printername, sizeof(name)); DEBUGADD(3,("checking name: %s\n",name)); @@ -1997,8 +1997,8 @@ WERROR _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER return WERR_ACCESS_DENIED; } - unistr2_to_ascii(driver, &q_u->driver, sizeof(driver)-1 ); - unistr2_to_ascii(arch, &q_u->arch, sizeof(arch)-1 ); + unistr2_to_ascii(driver, &q_u->driver, sizeof(driver)); + unistr2_to_ascii(arch, &q_u->arch, sizeof(arch)); /* check that we have a valid driver name first */ @@ -2092,8 +2092,8 @@ WERROR _spoolss_deleteprinterdriverex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIV return WERR_ACCESS_DENIED; } - unistr2_to_ascii(driver, &q_u->driver, sizeof(driver)-1 ); - unistr2_to_ascii(arch, &q_u->arch, sizeof(arch)-1 ); + unistr2_to_ascii(driver, &q_u->driver, sizeof(driver)); + unistr2_to_ascii(arch, &q_u->arch, sizeof(arch)); /* check that we have a valid driver name first */ if ((version=get_version_id(arch)) == -1) { @@ -2470,7 +2470,7 @@ WERROR _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO goto done; } - unistr2_to_ascii(value, valuename, sizeof(value)-1); + unistr2_to_ascii(value, valuename, sizeof(value)); if ( Printer->printer_type == SPLHND_SERVER ) status = getprinterdata_printer_server( p->mem_ctx, value, type, data, needed, *out_size ); @@ -2688,7 +2688,7 @@ WERROR _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE Printer->notify.option=dup_spool_notify_option(option); unistr2_to_ascii(Printer->notify.localmachine, localmachine, - sizeof(Printer->notify.localmachine)-1); + sizeof(Printer->notify.localmachine)); /* Connect to the client machine and send a ReplyOpenPrinter */ @@ -4804,7 +4804,7 @@ WERROR _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOOL_ * Level 5: same as Level 2 */ - unistr2_to_ascii(name, servername, sizeof(name)-1); + unistr2_to_ascii(name, servername, sizeof(name)); strupper_m(name); switch (level) { @@ -5788,7 +5788,7 @@ WERROR _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_ *serverminorversion = 0; fstrcpy(servername, get_server_name( printer )); - unistr2_to_ascii(architecture, uni_arch, sizeof(architecture)-1); + unistr2_to_ascii(architecture, uni_arch, sizeof(architecture)); if (!get_printer_snum(p, handle, &snum, NULL)) return WERR_BADFID; @@ -7215,8 +7215,8 @@ WERROR _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS *needed = 0; *returned = 0; - unistr2_to_ascii(architecture, &q_u->environment, sizeof(architecture)-1); - unistr2_to_ascii(servername, &q_u->name, sizeof(servername)-1); + unistr2_to_ascii(architecture, &q_u->environment, sizeof(architecture)); + unistr2_to_ascii(servername, &q_u->name, sizeof(servername)); if ( !is_myname_or_ipaddr( servername ) ) return WERR_UNKNOWN_PRINTER_DRIVER; @@ -7388,7 +7388,7 @@ WERROR _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * rpcbuf_move(q_u->buffer, &r_u->buffer); buffer = r_u->buffer; - unistr2_to_ascii(form_name, uni_formname, sizeof(form_name)-1); + unistr2_to_ascii(form_name, uni_formname, sizeof(form_name)); DEBUG(4,("_spoolss_getform\n")); DEBUGADD(5,("Offered buffer size [%d]\n", offered)); @@ -8004,8 +8004,8 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen DRIVER_DIRECTORY_1 *info=NULL; WERROR result = WERR_OK; - unistr2_to_ascii(servername, name, sizeof(servername)-1); - unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)-1); + unistr2_to_ascii(servername, name, sizeof(servername)); + unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)); /* check for beginning double '\'s and that the server long enough */ @@ -8322,7 +8322,7 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP if (!W_ERROR_IS_OK(status)) return status; - unistr2_to_ascii( valuename, value, sizeof(valuename)-1 ); + unistr2_to_ascii(valuename, value, sizeof(valuename)); /* * When client side code sets a magic printer data key, detect it and save @@ -8414,7 +8414,7 @@ WERROR _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_ if (!W_ERROR_IS_OK(status)) return status; - unistr2_to_ascii( valuename, value, sizeof(valuename)-1 ); + unistr2_to_ascii(valuename, value, sizeof(valuename)); status = delete_printer_dataex( printer, SPOOL_PRINTERDATA_KEY, valuename ); @@ -9136,8 +9136,8 @@ WERROR _spoolss_getprinterdataex(pipes_struct *p, SPOOL_Q_GETPRINTERDATAEX *q_u, DEBUG(4,("_spoolss_getprinterdataex\n")); - unistr2_to_ascii(keyname, &q_u->keyname, sizeof(keyname) - 1); - unistr2_to_ascii(valuename, &q_u->valuename, sizeof(valuename) - 1); + unistr2_to_ascii(keyname, &q_u->keyname, sizeof(keyname)); + unistr2_to_ascii(valuename, &q_u->valuename, sizeof(valuename)); DEBUG(10, ("_spoolss_getprinterdataex: key => [%s], value => [%s]\n", keyname, valuename)); @@ -9268,8 +9268,8 @@ WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, if (!W_ERROR_IS_OK(status)) return status; - unistr2_to_ascii( valuename, &q_u->value, sizeof(valuename) - 1); - unistr2_to_ascii( keyname, &q_u->key, sizeof(keyname) - 1); + unistr2_to_ascii( valuename, &q_u->value, sizeof(valuename)); + unistr2_to_ascii( keyname, &q_u->key, sizeof(keyname)); /* check for OID in valuename */ @@ -9346,8 +9346,8 @@ WERROR _spoolss_deleteprinterdataex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATAEX if (!W_ERROR_IS_OK(status)) return status; - unistr2_to_ascii( valuename, value, sizeof(valuename)-1 ); - unistr2_to_ascii( keyname, key, sizeof(keyname)-1 ); + unistr2_to_ascii(valuename, value, sizeof(valuename)); + unistr2_to_ascii(keyname, key, sizeof(keyname)); status = delete_printer_dataex( printer, keyname, valuename ); @@ -9395,7 +9395,7 @@ WERROR _spoolss_enumprinterkey(pipes_struct *p, SPOOL_Q_ENUMPRINTERKEY *q_u, SPO /* get the list of subkey names */ - unistr2_to_ascii( key, &q_u->key, sizeof(key)-1 ); + unistr2_to_ascii(key, &q_u->key, sizeof(key)); data = printer->info_2->data; num_keys = get_printer_subkeys( data, key, &keynames ); @@ -9470,7 +9470,7 @@ WERROR _spoolss_deleteprinterkey(pipes_struct *p, SPOOL_Q_DELETEPRINTERKEY *q_u, /* delete the key and all subneys */ - unistr2_to_ascii(key, &q_u->keyname, sizeof(key) - 1); + unistr2_to_ascii(key, &q_u->keyname, sizeof(key)); status = delete_all_printer_data( printer->info_2, key ); @@ -9521,7 +9521,7 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ * --jerry */ - unistr2_to_ascii(key, &q_u->key, sizeof(key) - 1); + unistr2_to_ascii(key, &q_u->key, sizeof(key)); if ( !strlen(key) ) { result = WERR_INVALID_PARAM; goto done; @@ -9541,7 +9541,7 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ p_data = printer->info_2->data; - unistr2_to_ascii(key, &q_u->key, sizeof(key) - 1); + unistr2_to_ascii(key, &q_u->key, sizeof(key)); if ( (key_index = lookup_printerkey( p_data, key)) == -1 ) { DEBUG(10,("_spoolss_enumprinterdataex: Unknown keyname [%s]\n", key)); @@ -9658,7 +9658,7 @@ static WERROR getprintprocessordirectory_level_1(UNISTR2 *name, PRINTPROCESSOR_DIRECTORY_1 *info=NULL; WERROR result = WERR_OK; - unistr2_to_ascii(long_archi, environment, sizeof(long_archi)-1); + unistr2_to_ascii(long_archi, environment, sizeof(long_archi)); if (!get_short_archi(long_archi)) return WERR_INVALID_ENVIRONMENT; -- cgit From 0ebab65706e7e2ef82d8af81225db05a5f78b5c4 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 5 Oct 2007 21:41:17 +0000 Subject: r25534: Apply some const Why? It moves these structs from the data into the text segment, so they will never been copy-on-write copied. Not much, but as in German you say "Kleinvieh macht auch Mist...." (This used to be commit 0141e64ad4972232de867137064d0dae62da22ee) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index f573d3fdc6..d5795cca25 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -63,7 +63,7 @@ static uint32 smb_connections=0; /* in printing/nt_printing.c */ -extern STANDARD_MAPPING printer_std_mapping, printserver_std_mapping; +extern struct standard_mapping printer_std_mapping, printserver_std_mapping; /* API table for Xcv Monitor functions */ -- cgit From e5a951325a6cac8567af3a66de6d2df577508ae4 Mon Sep 17 00:00:00 2001 From: "Gerald (Jerry) Carter" Date: Wed, 10 Oct 2007 15:34:30 -0500 Subject: [GLUE] Rsync SAMBA_3_2_0 SVN r25598 in order to create the v3-2-test branch. (This used to be commit 5c6c8e1fe93f340005110a7833946191659d88ab) --- source3/rpc_server/srv_spoolss_nt.c | 261 ++++++++++++------------------------ 1 file changed, 87 insertions(+), 174 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index d5795cca25..11827c223b 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -328,7 +328,7 @@ WERROR delete_printer_hook( NT_USER_TOKEN *token, const char *sharename ) /* go ahead and re-read the services immediately */ reload_services( False ); - if ( share_defined( sharename ) ) + if ( lp_servicenumber( sharename ) < 0 ) return WERR_ACCESS_DENIED; return WERR_OK; @@ -388,13 +388,6 @@ static BOOL get_printer_snum(pipes_struct *p, POLICY_HND *hnd, int *number, case SPLHND_PRINTER: DEBUG(4,("short name:%s\n", Printer->sharename)); *number = print_queue_snum(Printer->sharename); - if ((*number != -1) && (params != NULL)) { - *params = get_share_params(talloc_tos(), - Printer->sharename); - if (*params == NULL) { - return False; - } - } return (*number != -1); case SPLHND_SERVER: return False; @@ -3953,9 +3946,7 @@ done: * fill a printer_info_0 struct ********************************************************************/ -static BOOL construct_printer_info_0(Printer_entry *print_hnd, - PRINTER_INFO_0 *printer, - const struct share_params *params) +static BOOL construct_printer_info_0(Printer_entry *print_hnd, PRINTER_INFO_0 *printer, int snum) { pstring chaine; int count; @@ -3966,15 +3957,14 @@ static BOOL construct_printer_info_0(Printer_entry *print_hnd, time_t setuptime; print_status_struct status; - if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, - lp_const_servicename(params->service)))) + if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum)))) return False; - count = print_queue_length(params->service, &status); + count = print_queue_length(snum, &status); /* check if we already have a counter for this printer */ for(session_counter = counter_list; session_counter; session_counter = session_counter->next) { - if (session_counter->snum == params->service) + if (session_counter->snum == snum) break; } @@ -3985,7 +3975,7 @@ static BOOL construct_printer_info_0(Printer_entry *print_hnd, return False; } ZERO_STRUCTP(session_counter); - session_counter->snum=params->service; + session_counter->snum=snum; session_counter->counter=0; DLIST_ADD(counter_list, session_counter); } @@ -4061,25 +4051,21 @@ static BOOL construct_printer_info_0(Printer_entry *print_hnd, * construct_printer_info_1 * fill a printer_info_1 struct ********************************************************************/ -static BOOL construct_printer_info_1(Printer_entry *print_hnd, uint32 flags, - PRINTER_INFO_1 *printer, - const struct share_params *params) +static BOOL construct_printer_info_1(Printer_entry *print_hnd, uint32 flags, PRINTER_INFO_1 *printer, int snum) { pstring chaine; pstring chaine2; NT_PRINTER_INFO_LEVEL *ntprinter = NULL; - if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, - lp_const_servicename(params->service)))) + if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum)))) return False; printer->flags=flags; if (*ntprinter->info_2->comment == '\0') { - init_unistr(&printer->comment, lp_comment(params->service)); + init_unistr(&printer->comment, lp_comment(snum)); slprintf(chaine,sizeof(chaine)-1,"%s,%s,%s", ntprinter->info_2->printername, - ntprinter->info_2->drivername, - lp_comment(params->service)); + ntprinter->info_2->drivername, lp_comment(snum)); } else { init_unistr(&printer->comment, ntprinter->info_2->comment); /* saved comment. */ @@ -4170,7 +4156,7 @@ DEVICEMODE *construct_dev_mode(const char *servicename) DEBUGADD(8,("getting printer characteristics\n")); - if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, servicename))) + if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, servicename))) return NULL; if ( !printer->info_2->devmode ) { @@ -4203,29 +4189,26 @@ done: * fill a printer_info_2 struct ********************************************************************/ -static BOOL construct_printer_info_2(Printer_entry *print_hnd, - PRINTER_INFO_2 *printer, - const struct share_params *params) +static BOOL construct_printer_info_2(Printer_entry *print_hnd, PRINTER_INFO_2 *printer, int snum) { int count; NT_PRINTER_INFO_LEVEL *ntprinter = NULL; print_status_struct status; - if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, - lp_const_servicename(params->service)))) + if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum)))) return False; - count = print_queue_length(params->service, &status); + count = print_queue_length(snum, &status); init_unistr(&printer->servername, ntprinter->info_2->servername); /* servername*/ init_unistr(&printer->printername, ntprinter->info_2->printername); /* printername*/ - init_unistr(&printer->sharename, lp_servicename(params->service)); /* sharename */ + init_unistr(&printer->sharename, lp_servicename(snum)); /* sharename */ init_unistr(&printer->portname, ntprinter->info_2->portname); /* port */ init_unistr(&printer->drivername, ntprinter->info_2->drivername); /* drivername */ if (*ntprinter->info_2->comment == '\0') - init_unistr(&printer->comment, lp_comment(params->service)); /* comment */ + init_unistr(&printer->comment, lp_comment(snum)); /* comment */ else init_unistr(&printer->comment, ntprinter->info_2->comment); /* saved comment. */ @@ -4246,7 +4229,7 @@ static BOOL construct_printer_info_2(Printer_entry *print_hnd, printer->averageppm = ntprinter->info_2->averageppm; /* average pages per minute */ if ( !(printer->devmode = construct_dev_mode( - lp_const_servicename(params->service))) ) + lp_const_servicename(snum))) ) DEBUG(8, ("Returning NULL Devicemode!\n")); printer->secdesc = NULL; @@ -4271,15 +4254,12 @@ static BOOL construct_printer_info_2(Printer_entry *print_hnd, * fill a printer_info_3 struct ********************************************************************/ -static BOOL construct_printer_info_3(Printer_entry *print_hnd, - PRINTER_INFO_3 **pp_printer, - const struct share_params *params) +static BOOL construct_printer_info_3(Printer_entry *print_hnd, PRINTER_INFO_3 **pp_printer, int snum) { NT_PRINTER_INFO_LEVEL *ntprinter = NULL; PRINTER_INFO_3 *printer = NULL; - if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, - lp_const_servicename(params->service)))) + if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum)))) return False; *pp_printer = NULL; @@ -4312,14 +4292,11 @@ static BOOL construct_printer_info_3(Printer_entry *print_hnd, * fill a printer_info_4 struct ********************************************************************/ -static BOOL construct_printer_info_4(Printer_entry *print_hnd, - PRINTER_INFO_4 *printer, - const struct share_params *params) +static BOOL construct_printer_info_4(Printer_entry *print_hnd, PRINTER_INFO_4 *printer, int snum) { NT_PRINTER_INFO_LEVEL *ntprinter = NULL; - if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, - lp_const_servicename(params->service)))) + if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum)))) return False; init_unistr(&printer->printername, ntprinter->info_2->printername); /* printername*/ @@ -4335,14 +4312,11 @@ static BOOL construct_printer_info_4(Printer_entry *print_hnd, * fill a printer_info_5 struct ********************************************************************/ -static BOOL construct_printer_info_5(Printer_entry *print_hnd, - PRINTER_INFO_5 *printer, - const struct share_params *params) +static BOOL construct_printer_info_5(Printer_entry *print_hnd, PRINTER_INFO_5 *printer, int snum) { NT_PRINTER_INFO_LEVEL *ntprinter = NULL; - if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, - lp_const_servicename(params->service)))) + if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum)))) return False; init_unistr(&printer->printername, ntprinter->info_2->printername); @@ -4366,17 +4340,17 @@ static BOOL construct_printer_info_5(Printer_entry *print_hnd, static BOOL construct_printer_info_6(Printer_entry *print_hnd, PRINTER_INFO_6 *printer, - const struct share_params *params) + int snum) { NT_PRINTER_INFO_LEVEL *ntprinter = NULL; int count; print_status_struct status; if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, - lp_const_servicename(params->service)))) + lp_const_servicename(snum)))) return False; - count = print_queue_length(params->service, &status); + count = print_queue_length(snum, &status); printer->status = nt_printq_status(status.status); @@ -4390,14 +4364,12 @@ static BOOL construct_printer_info_6(Printer_entry *print_hnd, * fill a printer_info_7 struct ********************************************************************/ -static BOOL construct_printer_info_7(Printer_entry *print_hnd, - PRINTER_INFO_7 *printer, - const struct share_params *params) +static BOOL construct_printer_info_7(Printer_entry *print_hnd, PRINTER_INFO_7 *printer, int snum) { char *guid_str = NULL; struct GUID guid; - if (is_printer_published(print_hnd, params->service, &guid)) { + if (is_printer_published(print_hnd, snum, &guid)) { asprintf(&guid_str, "{%s}", smb_uuid_string_static(guid)); strupper_m(guid_str); init_unistr(&printer->guid, guid_str); @@ -4416,45 +4388,31 @@ static BOOL construct_printer_info_7(Printer_entry *print_hnd, static WERROR enum_all_printers_info_1(uint32 flags, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { + int snum; int i; - struct share_iterator *shares; - struct share_params *printer; + int n_services=lp_numservices(); PRINTER_INFO_1 *printers=NULL; + PRINTER_INFO_1 current_prt; WERROR result = WERR_OK; DEBUG(4,("enum_all_printers_info_1\n")); - if (!(shares = share_list_all(NULL))) { - DEBUG(5, ("Could not list printers\n")); - return WERR_ACCESS_DENIED; - } + for (snum=0; snumservice))); - - if (!construct_printer_info_1(NULL, flags, ¤t_prt, - printer)) { - continue; - } + if (construct_printer_info_1(NULL, flags, ¤t_prt, snum)) { + if((printers=SMB_REALLOC_ARRAY(printers, PRINTER_INFO_1, *returned +1)) == NULL) { + DEBUG(2,("enum_all_printers_info_1: failed to enlarge printers buffer!\n")); + *returned=0; + return WERR_NOMEM; + } + DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_1\n", *returned)); - if((printers=SMB_REALLOC_ARRAY(printers, PRINTER_INFO_1, - *returned +1)) == NULL) { - DEBUG(2,("enum_all_printers_info_1: failed to enlarge " - "printers buffer!\n")); - *returned=0; - TALLOC_FREE(shares); - return WERR_NOMEM; + memcpy(&printers[*returned], ¤t_prt, sizeof(PRINTER_INFO_1)); + (*returned)++; + } } - DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_1\n", - *returned)); - - memcpy(&printers[*returned], ¤t_prt, - sizeof(PRINTER_INFO_1)); - (*returned)++; - TALLOC_FREE(printer); } /* check the required size. */ @@ -4479,7 +4437,6 @@ out: /* clear memory */ SAFE_FREE(printers); - TALLOC_FREE(shares); if ( !W_ERROR_IS_OK(result) ) *returned = 0; @@ -4617,45 +4574,33 @@ static WERROR enum_all_printers_info_1_network(fstring name, RPC_BUFFER *buffer, static WERROR enum_all_printers_info_2(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { + int snum; int i; - struct share_iterator *shares; - struct share_params *printer; + int n_services=lp_numservices(); PRINTER_INFO_2 *printers=NULL; + PRINTER_INFO_2 current_prt; WERROR result = WERR_OK; *returned = 0; - if (!(shares = share_list_all(NULL))) { - DEBUG(5, ("Could not list printers\n")); - return WERR_ACCESS_DENIED; - } + for (snum=0; snumservice))); + memcpy(&printers[*returned], ¤t_prt, sizeof(PRINTER_INFO_2)); - if (!construct_printer_info_2(NULL, ¤t_prt, - printer)) { - continue; - } - if ( !(printers=SMB_REALLOC_ARRAY(printers, PRINTER_INFO_2, - *returned +1)) ) { - DEBUG(2,("enum_all_printers_info_2: failed to enlarge " - "printers buffer!\n")); - *returned = 0; - TALLOC_FREE(shares); - return WERR_NOMEM; + (*returned)++; + } } - - DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_2\n", - *returned + 1)); - - memcpy(&printers[*returned], ¤t_prt, - sizeof(PRINTER_INFO_2)); - (*returned)++; - TALLOC_FREE(printer); } /* check the required size. */ @@ -4683,7 +4628,6 @@ out: free_devmode(printers[i].devmode); SAFE_FREE(printers); - TALLOC_FREE(shares); if ( !W_ERROR_IS_OK(result) ) *returned = 0; @@ -4824,10 +4768,7 @@ WERROR _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOOL_ /**************************************************************************** ****************************************************************************/ -static WERROR getprinter_level_0(Printer_entry *print_hnd, - const struct share_params *params, - RPC_BUFFER *buffer, uint32 offered, - uint32 *needed) +static WERROR getprinter_level_0(Printer_entry *print_hnd, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_0 *printer=NULL; WERROR result = WERR_OK; @@ -4835,7 +4776,7 @@ static WERROR getprinter_level_0(Printer_entry *print_hnd, if((printer=SMB_MALLOC_P(PRINTER_INFO_0)) == NULL) return WERR_NOMEM; - construct_printer_info_0(print_hnd, printer, params); + construct_printer_info_0(print_hnd, printer, snum); /* check the required size. */ *needed += spoolss_size_printer_info_0(printer); @@ -4864,10 +4805,7 @@ out: /**************************************************************************** ****************************************************************************/ -static WERROR getprinter_level_1(Printer_entry *print_hnd, - const struct share_params *params, - RPC_BUFFER *buffer, uint32 offered, - uint32 *needed) +static WERROR getprinter_level_1(Printer_entry *print_hnd, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_1 *printer=NULL; WERROR result = WERR_OK; @@ -4875,8 +4813,7 @@ static WERROR getprinter_level_1(Printer_entry *print_hnd, if((printer=SMB_MALLOC_P(PRINTER_INFO_1)) == NULL) return WERR_NOMEM; - construct_printer_info_1(print_hnd, PRINTER_ENUM_ICON8, printer, - params); + construct_printer_info_1(print_hnd, PRINTER_ENUM_ICON8, printer, snum); /* check the required size. */ *needed += spoolss_size_printer_info_1(printer); @@ -4904,10 +4841,7 @@ out: /**************************************************************************** ****************************************************************************/ -static WERROR getprinter_level_2(Printer_entry *print_hnd, - const struct share_params *params, - RPC_BUFFER *buffer, uint32 offered, - uint32 *needed) +static WERROR getprinter_level_2(Printer_entry *print_hnd, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_2 *printer=NULL; WERROR result = WERR_OK; @@ -4915,7 +4849,7 @@ static WERROR getprinter_level_2(Printer_entry *print_hnd, if((printer=SMB_MALLOC_P(PRINTER_INFO_2))==NULL) return WERR_NOMEM; - construct_printer_info_2(print_hnd, printer, params); + construct_printer_info_2(print_hnd, printer, snum); /* check the required size. */ *needed += spoolss_size_printer_info_2(printer); @@ -4944,15 +4878,12 @@ out: /**************************************************************************** ****************************************************************************/ -static WERROR getprinter_level_3(Printer_entry *print_hnd, - const struct share_params *params, - RPC_BUFFER *buffer, uint32 offered, - uint32 *needed) +static WERROR getprinter_level_3(Printer_entry *print_hnd, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_3 *printer=NULL; WERROR result = WERR_OK; - if (!construct_printer_info_3(print_hnd, &printer, params)) + if (!construct_printer_info_3(print_hnd, &printer, snum)) return WERR_NOMEM; /* check the required size. */ @@ -4981,10 +4912,7 @@ out: /**************************************************************************** ****************************************************************************/ -static WERROR getprinter_level_4(Printer_entry *print_hnd, - const struct share_params *params, - RPC_BUFFER *buffer, uint32 offered, - uint32 *needed) +static WERROR getprinter_level_4(Printer_entry *print_hnd, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_4 *printer=NULL; WERROR result = WERR_OK; @@ -4992,7 +4920,7 @@ static WERROR getprinter_level_4(Printer_entry *print_hnd, if((printer=SMB_MALLOC_P(PRINTER_INFO_4))==NULL) return WERR_NOMEM; - if (!construct_printer_info_4(print_hnd, printer, params)) { + if (!construct_printer_info_4(print_hnd, printer, snum)) { SAFE_FREE(printer); return WERR_NOMEM; } @@ -5023,10 +4951,7 @@ out: /**************************************************************************** ****************************************************************************/ -static WERROR getprinter_level_5(Printer_entry *print_hnd, - const struct share_params *params, - RPC_BUFFER *buffer, uint32 offered, - uint32 *needed) +static WERROR getprinter_level_5(Printer_entry *print_hnd, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_5 *printer=NULL; WERROR result = WERR_OK; @@ -5034,7 +4959,7 @@ static WERROR getprinter_level_5(Printer_entry *print_hnd, if((printer=SMB_MALLOC_P(PRINTER_INFO_5))==NULL) return WERR_NOMEM; - if (!construct_printer_info_5(print_hnd, printer, params)) { + if (!construct_printer_info_5(print_hnd, printer, snum)) { free_printer_info_5(printer); return WERR_NOMEM; } @@ -5063,7 +4988,7 @@ out: } static WERROR getprinter_level_6(Printer_entry *print_hnd, - const struct share_params *params, + int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { @@ -5074,7 +4999,7 @@ static WERROR getprinter_level_6(Printer_entry *print_hnd, return WERR_NOMEM; } - if (!construct_printer_info_6(print_hnd, printer, params)) { + if (!construct_printer_info_6(print_hnd, printer, snum)) { free_printer_info_6(printer); return WERR_NOMEM; } @@ -5102,10 +5027,7 @@ out: return result; } -static WERROR getprinter_level_7(Printer_entry *print_hnd, - const struct share_params *params, - RPC_BUFFER *buffer, uint32 offered, - uint32 *needed) +static WERROR getprinter_level_7(Printer_entry *print_hnd, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_7 *printer=NULL; WERROR result = WERR_OK; @@ -5113,7 +5035,7 @@ static WERROR getprinter_level_7(Printer_entry *print_hnd, if((printer=SMB_MALLOC_P(PRINTER_INFO_7))==NULL) return WERR_NOMEM; - if (!construct_printer_info_7(print_hnd, printer, params)) + if (!construct_printer_info_7(print_hnd, printer, snum)) return WERR_NOMEM; /* check the required size. */ @@ -5151,7 +5073,6 @@ WERROR _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GET uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; Printer_entry *Printer=find_printer_index_by_hnd(p, handle); - struct share_params *params; int snum; @@ -5166,34 +5087,26 @@ WERROR _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GET *needed=0; - if (!get_printer_snum(p, handle, &snum, ¶ms)) + if (!get_printer_snum(p, handle, &snum, NULL)) return WERR_BADFID; switch (level) { case 0: - return getprinter_level_0(Printer, params, buffer, offered, - needed); + return getprinter_level_0(Printer, snum, buffer, offered, needed); case 1: - return getprinter_level_1(Printer, params, buffer, offered, - needed); + return getprinter_level_1(Printer, snum, buffer, offered, needed); case 2: - return getprinter_level_2(Printer, params, buffer, offered, - needed); + return getprinter_level_2(Printer, snum, buffer, offered, needed); case 3: - return getprinter_level_3(Printer, params, buffer, offered, - needed); + return getprinter_level_3(Printer, snum, buffer, offered, needed); case 4: - return getprinter_level_4(Printer, params, buffer, offered, - needed); + return getprinter_level_4(Printer, snum, buffer, offered, needed); case 5: - return getprinter_level_5(Printer, params, buffer, offered, - needed); - case 6: - return getprinter_level_6(Printer, params, buffer, offered, - needed); + return getprinter_level_5(Printer, snum, buffer, offered, needed); + case 6: + return getprinter_level_6(Printer, snum, buffer, offered, needed); case 7: - return getprinter_level_7(Printer, params, buffer, offered, - needed); + return getprinter_level_7(Printer, snum, buffer, offered, needed); } return WERR_UNKNOWN_LEVEL; } -- cgit From 8e54530b52fd256137740107e9fdf000f00a7a30 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 10 Oct 2007 18:25:16 -0700 Subject: Add start of IPv6 implementation. Currently most of this is avoiding IPv6 in winbindd, but moves most of the socket functions that were wrongly in lib/util.c into lib/util_sock.c and provides generic IPv4/6 independent versions of most things. Still lots of work to do, but now I can see how I'll fix the access check code. Nasty part that remains is the name resolution code which is used to returning arrays of in_addr structs. Jeremy. (This used to be commit 3f6bd0e1ec5cc6670f3d08f76fc2cd94c9cd1a08) --- source3/rpc_server/srv_spoolss_nt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 11827c223b..1bed2bf095 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2534,13 +2534,13 @@ static BOOL spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe, struct cli_state *the_cli; struct in_addr rm_addr; - if ( is_zero_ip(*client_ip) ) { + if ( is_zero_ip_v4(*client_ip) ) { if ( !resolve_name( remote_machine, &rm_addr, 0x20) ) { DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine)); return False; } - if ( ismyip( rm_addr )) { + if ( ismyip_v4( rm_addr )) { DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n", remote_machine)); return False; } -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/rpc_server/srv_spoolss_nt.c | 80 ++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 40 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 1bed2bf095..658ed99400 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -267,7 +267,7 @@ static Printer_entry *find_printer_index_by_hnd(pipes_struct *p, POLICY_HND *hnd Close printer index by handle. ****************************************************************************/ -static BOOL close_printer_handle(pipes_struct *p, POLICY_HND *hnd) +static bool close_printer_handle(pipes_struct *p, POLICY_HND *hnd) { Printer_entry *Printer = find_printer_index_by_hnd(p, hnd); @@ -290,7 +290,7 @@ WERROR delete_printer_hook( NT_USER_TOKEN *token, const char *sharename ) pstring command; int ret; SE_PRIV se_printop = SE_PRINT_OPERATOR; - BOOL is_print_op = False; + bool is_print_op = False; /* can't fail if we don't try */ @@ -374,7 +374,7 @@ static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) Return the snum of a printer corresponding to an handle. ****************************************************************************/ -static BOOL get_printer_snum(pipes_struct *p, POLICY_HND *hnd, int *number, +static bool get_printer_snum(pipes_struct *p, POLICY_HND *hnd, int *number, struct share_params **params) { Printer_entry *Printer = find_printer_index_by_hnd(p, hnd); @@ -401,7 +401,7 @@ static BOOL get_printer_snum(pipes_struct *p, POLICY_HND *hnd, int *number, Check if it's \\server or \\server\printer ****************************************************************************/ -static BOOL set_printer_hnd_printertype(Printer_entry *Printer, char *handlename) +static bool set_printer_hnd_printertype(Printer_entry *Printer, char *handlename) { DEBUG(3,("Setting printer type=%s\n", handlename)); @@ -431,14 +431,14 @@ static BOOL set_printer_hnd_printertype(Printer_entry *Printer, char *handlename XcvDataPort() interface. ****************************************************************************/ -static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) +static bool set_printer_hnd_name(Printer_entry *Printer, char *handlename) { int snum; int n_services=lp_numservices(); char *aprinter, *printername; const char *servername; fstring sname; - BOOL found=False; + bool found=False; NT_PRINTER_INFO_LEVEL *printer = NULL; WERROR result; @@ -558,7 +558,7 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) Find first available printer slot. creates a printer handle for you. ****************************************************************************/ -static BOOL open_printer_hnd(pipes_struct *p, POLICY_HND *hnd, char *name, uint32 access_granted) +static bool open_printer_hnd(pipes_struct *p, POLICY_HND *hnd, char *name, uint32 access_granted) { Printer_entry *new_printer; @@ -607,13 +607,13 @@ static BOOL open_printer_hnd(pipes_struct *p, POLICY_HND *hnd, char *name, uint3 given by (notify_type, notify_field). **************************************************************************/ -static BOOL is_monitoring_event_flags(uint32 flags, uint16 notify_type, +static bool is_monitoring_event_flags(uint32 flags, uint16 notify_type, uint16 notify_field) { return True; } -static BOOL is_monitoring_event(Printer_entry *p, uint16 notify_type, +static bool is_monitoring_event(Printer_entry *p, uint16 notify_type, uint16 notify_field) { SPOOL_NOTIFY_OPTION *option = p->notify.option; @@ -1062,7 +1062,7 @@ done: /*********************************************************************** **********************************************************************/ -static BOOL notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len ) +static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len ) { uint32 tv_sec, tv_usec; @@ -1198,7 +1198,7 @@ static void receive_notify2_message_list(struct messaging_context *msg, driver ********************************************************************/ -static BOOL srv_spoolss_drv_upgrade_printer(char* drivername) +static bool srv_spoolss_drv_upgrade_printer(char* drivername) { int len = strlen(drivername); @@ -1301,7 +1301,7 @@ void update_monitored_printq_cache( void ) driver ********************************************************************/ -static BOOL srv_spoolss_reset_printerdata(char* drivername) +static bool srv_spoolss_reset_printerdata(char* drivername) { int len = strlen(drivername); @@ -1741,10 +1741,10 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, /**************************************************************************** ****************************************************************************/ -static BOOL convert_printer_info(const SPOOL_PRINTER_INFO_LEVEL *uni, +static bool convert_printer_info(const SPOOL_PRINTER_INFO_LEVEL *uni, NT_PRINTER_INFO_LEVEL *printer, uint32 level) { - BOOL ret; + bool ret; switch (level) { case 2: @@ -1769,10 +1769,10 @@ static BOOL convert_printer_info(const SPOOL_PRINTER_INFO_LEVEL *uni, return False; } -static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL *uni, +static bool convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL *uni, NT_PRINTER_DRIVER_INFO_LEVEL *printer, uint32 level) { - BOOL result = True; + bool result = True; switch (level) { case 3: @@ -1792,7 +1792,7 @@ static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL *u return result; } -BOOL convert_devicemode(const char *printername, const DEVICEMODE *devmode, +bool convert_devicemode(const char *printername, const DEVICEMODE *devmode, NT_DEVICEMODE **pp_nt_devmode) { NT_DEVICEMODE *nt_devmode = *pp_nt_devmode; @@ -2069,7 +2069,7 @@ WERROR _spoolss_deleteprinterdriverex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIV NT_PRINTER_DRIVER_INFO_LEVEL info_win2k; int version; uint32 flags = q_u->delete_flags; - BOOL delete_files; + bool delete_files; WERROR status; WERROR status_win2k = WERR_ACCESS_DENIED; SE_PRIV se_printop = SE_PRINT_OPERATOR; @@ -2527,7 +2527,7 @@ done: Connect to the client machine. **********************************************************/ -static BOOL spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe, +static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe, struct in_addr *client_ip, const char *remote_machine) { NTSTATUS ret; @@ -2594,7 +2594,7 @@ static BOOL spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe, Connect to the client. ****************************************************************************/ -static BOOL srv_spoolss_replyopenprinter(int snum, const char *printer, +static bool srv_spoolss_replyopenprinter(int snum, const char *printer, uint32 localprinter, uint32 type, POLICY_HND *handle, struct in_addr *client_ip) { @@ -3564,7 +3564,7 @@ static uint32 type_of_notify_info_data(uint16 type, uint16 field) /**************************************************************************** ****************************************************************************/ -static BOOL search_notify(uint16 type, uint16 field, int *value) +static bool search_notify(uint16 type, uint16 field, int *value) { int i; @@ -3601,7 +3601,7 @@ void construct_info_data(SPOOL_NOTIFY_INFO_DATA *info_data, uint16 type, uint16 * ********************************************************************/ -static BOOL construct_notify_printer_info(Printer_entry *print_hnd, SPOOL_NOTIFY_INFO *info, int +static bool construct_notify_printer_info(Printer_entry *print_hnd, SPOOL_NOTIFY_INFO *info, int snum, SPOOL_NOTIFY_OPTION_TYPE *option_type, uint32 id, TALLOC_CTX *mem_ctx) @@ -3660,7 +3660,7 @@ static BOOL construct_notify_printer_info(Printer_entry *print_hnd, SPOOL_NOTIFY * ********************************************************************/ -static BOOL construct_notify_jobs_info(print_queue_struct *queue, +static bool construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_INFO *info, NT_PRINTER_INFO_LEVEL *printer, int snum, SPOOL_NOTIFY_OPTION_TYPE @@ -3946,7 +3946,7 @@ done: * fill a printer_info_0 struct ********************************************************************/ -static BOOL construct_printer_info_0(Printer_entry *print_hnd, PRINTER_INFO_0 *printer, int snum) +static bool construct_printer_info_0(Printer_entry *print_hnd, PRINTER_INFO_0 *printer, int snum) { pstring chaine; int count; @@ -4051,7 +4051,7 @@ static BOOL construct_printer_info_0(Printer_entry *print_hnd, PRINTER_INFO_0 *p * construct_printer_info_1 * fill a printer_info_1 struct ********************************************************************/ -static BOOL construct_printer_info_1(Printer_entry *print_hnd, uint32 flags, PRINTER_INFO_1 *printer, int snum) +static bool construct_printer_info_1(Printer_entry *print_hnd, uint32 flags, PRINTER_INFO_1 *printer, int snum) { pstring chaine; pstring chaine2; @@ -4102,7 +4102,7 @@ static void free_dev_mode(DEVICEMODE *dev) should be valid upon entry ****************************************************************************/ -static BOOL convert_nt_devicemode( DEVICEMODE *devmode, NT_DEVICEMODE *ntdevmode ) +static bool convert_nt_devicemode( DEVICEMODE *devmode, NT_DEVICEMODE *ntdevmode ) { if ( !devmode || !ntdevmode ) return False; @@ -4189,7 +4189,7 @@ done: * fill a printer_info_2 struct ********************************************************************/ -static BOOL construct_printer_info_2(Printer_entry *print_hnd, PRINTER_INFO_2 *printer, int snum) +static bool construct_printer_info_2(Printer_entry *print_hnd, PRINTER_INFO_2 *printer, int snum) { int count; NT_PRINTER_INFO_LEVEL *ntprinter = NULL; @@ -4254,7 +4254,7 @@ static BOOL construct_printer_info_2(Printer_entry *print_hnd, PRINTER_INFO_2 *p * fill a printer_info_3 struct ********************************************************************/ -static BOOL construct_printer_info_3(Printer_entry *print_hnd, PRINTER_INFO_3 **pp_printer, int snum) +static bool construct_printer_info_3(Printer_entry *print_hnd, PRINTER_INFO_3 **pp_printer, int snum) { NT_PRINTER_INFO_LEVEL *ntprinter = NULL; PRINTER_INFO_3 *printer = NULL; @@ -4292,7 +4292,7 @@ static BOOL construct_printer_info_3(Printer_entry *print_hnd, PRINTER_INFO_3 ** * fill a printer_info_4 struct ********************************************************************/ -static BOOL construct_printer_info_4(Printer_entry *print_hnd, PRINTER_INFO_4 *printer, int snum) +static bool construct_printer_info_4(Printer_entry *print_hnd, PRINTER_INFO_4 *printer, int snum) { NT_PRINTER_INFO_LEVEL *ntprinter = NULL; @@ -4312,7 +4312,7 @@ static BOOL construct_printer_info_4(Printer_entry *print_hnd, PRINTER_INFO_4 *p * fill a printer_info_5 struct ********************************************************************/ -static BOOL construct_printer_info_5(Printer_entry *print_hnd, PRINTER_INFO_5 *printer, int snum) +static bool construct_printer_info_5(Printer_entry *print_hnd, PRINTER_INFO_5 *printer, int snum) { NT_PRINTER_INFO_LEVEL *ntprinter = NULL; @@ -4338,7 +4338,7 @@ static BOOL construct_printer_info_5(Printer_entry *print_hnd, PRINTER_INFO_5 *p * fill a printer_info_6 struct ********************************************************************/ -static BOOL construct_printer_info_6(Printer_entry *print_hnd, +static bool construct_printer_info_6(Printer_entry *print_hnd, PRINTER_INFO_6 *printer, int snum) { @@ -4364,7 +4364,7 @@ static BOOL construct_printer_info_6(Printer_entry *print_hnd, * fill a printer_info_7 struct ********************************************************************/ -static BOOL construct_printer_info_7(Printer_entry *print_hnd, PRINTER_INFO_7 *printer, int snum) +static bool construct_printer_info_7(Printer_entry *print_hnd, PRINTER_INFO_7 *printer, int snum) { char *guid_str = NULL; struct GUID guid; @@ -6057,7 +6057,7 @@ static WERROR update_printer_sec(POLICY_HND *handle, uint32 level, _spoolss_open_printer_ex(). ********************************************************************/ -static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) +static bool check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) { fstring printername; const char *p; @@ -6109,7 +6109,7 @@ WERROR add_port_hook(NT_USER_TOKEN *token, const char *portname, const char *uri int ret; int fd; SE_PRIV se_printop = SE_PRINT_OPERATOR; - BOOL is_print_op = False; + bool is_print_op = False; if ( !*cmd ) { return WERR_ACCESS_DENIED; @@ -6148,7 +6148,7 @@ WERROR add_port_hook(NT_USER_TOKEN *token, const char *portname, const char *uri /**************************************************************************** ****************************************************************************/ -BOOL add_printer_hook(NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer) +bool add_printer_hook(NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer) { char *cmd = lp_addprinter_cmd(); char **qlines; @@ -6158,7 +6158,7 @@ BOOL add_printer_hook(NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer) int fd; fstring remote_machine = "%m"; SE_PRIV se_printop = SE_PRINT_OPERATOR; - BOOL is_print_op = False; + bool is_print_op = False; standard_sub_basic(current_user_info.smb_name, current_user_info.domain, @@ -6574,7 +6574,7 @@ static void fill_job_info_1(JOB_INFO_1 *job_info, const print_queue_struct *queu /**************************************************************************** ****************************************************************************/ -static BOOL fill_job_info_2(JOB_INFO_2 *job_info, const print_queue_struct *queue, +static bool fill_job_info_2(JOB_INFO_2 *job_info, const print_queue_struct *queue, int position, int snum, const NT_PRINTER_INFO_LEVEL *ntprinter, DEVICEMODE *devmode) @@ -7286,7 +7286,7 @@ WERROR _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * nt_forms_struct *list=NULL; nt_forms_struct builtin_form; - BOOL foundBuiltin; + bool foundBuiltin; FORM_1 form_1; fstring form_name; int buffer_size=0; @@ -8843,7 +8843,7 @@ static WERROR getjob_level_1(print_queue_struct **queue, int count, int snum, uint32 *needed) { int i=0; - BOOL found=False; + bool found=False; JOB_INFO_1 *info_1=NULL; WERROR result = WERR_OK; @@ -8895,7 +8895,7 @@ static WERROR getjob_level_2(print_queue_struct **queue, int count, int snum, uint32 *needed) { int i = 0; - BOOL found = False; + bool found = False; JOB_INFO_2 *info_2; WERROR result; DEVICEMODE *devmode = NULL; -- cgit From f88b7a076be74a29a3bf876b4e2705f4a1ecf42b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 24 Oct 2007 14:16:54 -0700 Subject: This is a large patch (sorry). Migrate from struct in_addr to struct sockaddr_storage in most places that matter (ie. not the nmbd and NetBIOS lookups). This passes make test on an IPv4 box, but I'll have to do more work/testing on IPv6 enabled boxes. This should now give us a framework for testing and finishing the IPv6 migration. It's at the state where someone with a working IPv6 setup should (theorecically) be able to type : smbclient //ipv6-address/share and have it work. Jeremy. (This used to be commit 98e154c3125d5732c37a72d74b0eb5cd7b6155fd) --- source3/rpc_server/srv_spoolss_nt.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 658ed99400..aba56c2d05 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2528,26 +2528,28 @@ done: **********************************************************/ static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe, - struct in_addr *client_ip, const char *remote_machine) + struct sockaddr_storage *client_ss, const char *remote_machine) { NTSTATUS ret; struct cli_state *the_cli; - struct in_addr rm_addr; + struct sockaddr_storage rm_addr; - if ( is_zero_ip_v4(*client_ip) ) { + if ( is_zero_addr(client_ss) ) { if ( !resolve_name( remote_machine, &rm_addr, 0x20) ) { DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine)); return False; } - if ( ismyip_v4( rm_addr )) { + if (ismyaddr(&rm_addr)) { DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n", remote_machine)); return False; } } else { - rm_addr.s_addr = client_ip->s_addr; + char addr[INET6_ADDRSTRLEN]; + rm_addr = *client_ss; + print_sockaddr(addr, sizeof(addr), &rm_addr); DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n", - inet_ntoa(*client_ip) )); + addr)); } /* setup the connection */ @@ -2596,7 +2598,7 @@ static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe, static bool srv_spoolss_replyopenprinter(int snum, const char *printer, uint32 localprinter, uint32 type, - POLICY_HND *handle, struct in_addr *client_ip) + POLICY_HND *handle, struct sockaddr_storage *client_ss) { WERROR result; @@ -2609,7 +2611,7 @@ static bool srv_spoolss_replyopenprinter(int snum, const char *printer, fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */ - if ( !spoolss_connect_to_client( ¬ify_cli_pipe, client_ip, unix_printer )) + if ( !spoolss_connect_to_client( ¬ify_cli_pipe, client_ss, unix_printer )) return False; messaging_register(smbd_messaging_context(), NULL, @@ -2660,7 +2662,7 @@ WERROR _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE uint32 printerlocal = q_u->printerlocal; int snum = -1; SPOOL_NOTIFY_OPTION *option = q_u->option; - struct in_addr client_ip; + struct sockaddr_storage client_ss; /* store the notify value in the printer struct */ @@ -2690,12 +2692,16 @@ WERROR _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE else if ( (Printer->printer_type == SPLHND_PRINTER) && !get_printer_snum(p, handle, &snum, NULL) ) return WERR_BADFID; - - client_ip.s_addr = inet_addr(p->conn->client_address); + + if (!interpret_string_addr(&client_ss, + p->conn->client_address, + AI_NUMERICHOST)) { + return WERR_SERVER_UNAVAILABLE; + } if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine, Printer->notify.printerlocal, 1, - &Printer->notify.client_hnd, &client_ip)) + &Printer->notify.client_hnd, &client_ss)) return WERR_SERVER_UNAVAILABLE; Printer->notify.client_connected=True; -- cgit From d40e47db4b5da41c8604a2058f3a0b0a82164f08 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 8 Nov 2007 17:25:45 -0800 Subject: Remove more fstring/pstring bad useage. Go talloc ! Jeremy. (This used to be commit 2a0173743d2cf615d52278f3dd87cc804abe2d16) --- source3/rpc_server/srv_spoolss_nt.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index aba56c2d05..fe7a12940e 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2401,20 +2401,20 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint return WERR_OK; } - if (!StrCaseCmp(value, "DNSMachineName")) { - pstring hostname; - - if (!get_mydnsfullname(hostname)) + if (!StrCaseCmp(value, "DNSMachineName")) { + const char *hostname = get_mydnsfullname(); + + if (!hostname) return WERR_BADFILE; *type = REG_SZ; - *needed = 2*(strlen(hostname)+1); + *needed = 2*(strlen(hostname)+1); if((*data = (uint8 *)TALLOC(ctx, (*needed > in_size) ? *needed:in_size )) == NULL) return WERR_NOMEM; memset(*data, 0, (*needed > in_size) ? *needed:in_size); for (i=0; i Date: Sun, 25 Nov 2007 10:10:52 +0100 Subject: Remove some statics (This used to be commit 1fab16ffb888cd4ec18e52d9da33976a67a5d104) --- source3/rpc_server/srv_spoolss_nt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index fe7a12940e..d49731272f 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4376,7 +4376,8 @@ static bool construct_printer_info_7(Printer_entry *print_hnd, PRINTER_INFO_7 *p struct GUID guid; if (is_printer_published(print_hnd, snum, &guid)) { - asprintf(&guid_str, "{%s}", smb_uuid_string_static(guid)); + asprintf(&guid_str, "{%s}", + smb_uuid_string(talloc_tos(), guid)); strupper_m(guid_str); init_unistr(&printer->guid, guid_str); printer->action = SPOOL_DS_PUBLISH; -- cgit From 2cda3e78445da8f53f8358ae38892ab799c3dd3a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 27 Nov 2007 17:48:59 -0800 Subject: Whitespace cleanup. Jeremy. (This used to be commit 3052172d2bfe9d787777525e90816394aac2dd54) --- source3/rpc_server/srv_spoolss_nt.c | 2072 +++++++++++++++++------------------ 1 file changed, 1035 insertions(+), 1037 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index d49731272f..f18c120a9f 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -50,7 +50,7 @@ static Printer_entry *printers_list; typedef struct _counter_printer_0 { struct _counter_printer_0 *next; struct _counter_printer_0 *prev; - + int snum; uint32 counter; } counter_printer_0; @@ -139,7 +139,7 @@ static void srv_spoolss_replycloseprinter(int snum, POLICY_HND *handle) { WERROR result; - /* + /* * Tell the specific printing tdb we no longer want messages for this printer * by deregistering our PID. */ @@ -154,7 +154,7 @@ static void srv_spoolss_replycloseprinter(int snum, POLICY_HND *handle) } result = rpccli_spoolss_reply_close_printer(notify_cli_pipe, notify_cli_pipe->cli->mem_ctx, handle); - + if (!W_ERROR_IS_OK(result)) DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed [%s].\n", dos_errstr(result))); @@ -206,10 +206,10 @@ static void free_printer_entry(void *ptr) free_spool_notify_option(&Printer->notify.option); Printer->notify.option=NULL; Printer->notify.client_connected=False; - + free_nt_devicemode( &Printer->nt_devmode ); free_a_printer( &Printer->printer_info, 2 ); - + talloc_destroy( Printer->ctx ); /* Remove from the internal list. */ @@ -279,7 +279,7 @@ static bool close_printer_handle(pipes_struct *p, POLICY_HND *hnd) close_policy_hnd(p, hnd); return True; -} +} /**************************************************************************** Delete a printer given a handle. @@ -291,46 +291,46 @@ WERROR delete_printer_hook( NT_USER_TOKEN *token, const char *sharename ) int ret; SE_PRIV se_printop = SE_PRINT_OPERATOR; bool is_print_op = False; - + /* can't fail if we don't try */ - + if ( !*cmd ) return WERR_OK; - + pstr_sprintf(command, "%s \"%s\"", cmd, sharename); if ( token ) is_print_op = user_has_privileges( token, &se_printop ); - + DEBUG(10,("Running [%s]\n", command)); /********** BEGIN SePrintOperatorPrivlege BLOCK **********/ - + if ( is_print_op ) become_root(); - + if ( (ret = smbrun(command, NULL)) == 0 ) { /* Tell everyone we updated smb.conf. */ message_send_all(smbd_messaging_context(), MSG_SMB_CONF_UPDATED, NULL, 0, NULL); } - + if ( is_print_op ) unbecome_root(); /********** END SePrintOperatorPrivlege BLOCK **********/ - + DEBUGADD(10,("returned [%d]\n", ret)); - if (ret != 0) + if (ret != 0) return WERR_BADFID; /* What to return here? */ /* go ahead and re-read the services immediately */ reload_services( False ); - + if ( lp_servicenumber( sharename ) < 0 ) return WERR_ACCESS_DENIED; - + return WERR_OK; } @@ -347,7 +347,7 @@ static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) return WERR_BADFID; } - /* + /* * It turns out that Windows allows delete printer on a handle * opened by an admin user, then used on a pipe handle created * by an anonymous user..... but they're working on security.... riiight ! @@ -358,10 +358,10 @@ static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) DEBUG(3, ("delete_printer_handle: denied by handle\n")); return WERR_ACCESS_DENIED; } - - /* this does not need a become root since the access check has been + + /* this does not need a become root since the access check has been done on the handle already */ - + if (del_a_printer( Printer->sharename ) != 0) { DEBUG(3,("Error deleting printer %s\n", Printer->sharename)); return WERR_BADFID; @@ -378,15 +378,15 @@ static bool get_printer_snum(pipes_struct *p, POLICY_HND *hnd, int *number, struct share_params **params) { Printer_entry *Printer = find_printer_index_by_hnd(p, hnd); - + if (!Printer) { DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(hnd))); return False; } - + switch (Printer->printer_type) { - case SPLHND_PRINTER: - DEBUG(4,("short name:%s\n", Printer->sharename)); + case SPLHND_PRINTER: + DEBUG(4,("short name:%s\n", Printer->sharename)); *number = print_queue_snum(Printer->sharename); return (*number != -1); case SPLHND_SERVER: @@ -413,7 +413,7 @@ static bool set_printer_hnd_printertype(Printer_entry *Printer, char *handlename /* it's a print server */ if (*handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) { DEBUGADD(4,("Printer is a print server\n")); - Printer->printer_type = SPLHND_SERVER; + Printer->printer_type = SPLHND_SERVER; } /* it's a printer (set_printer_hnd_name() will handle port monitors */ else { @@ -425,9 +425,9 @@ static bool set_printer_hnd_printertype(Printer_entry *Printer, char *handlename } /**************************************************************************** - Set printer handle name.. Accept names like \\server, \\server\printer, + Set printer handle name.. Accept names like \\server, \\server\printer, \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See - the MSDN docs regarding OpenPrinter() for details on the XcvData() and + the MSDN docs regarding OpenPrinter() for details on the XcvData() and XcvDataPort() interface. ****************************************************************************/ @@ -441,7 +441,7 @@ static bool set_printer_hnd_name(Printer_entry *Printer, char *handlename) bool found=False; NT_PRINTER_INFO_LEVEL *printer = NULL; WERROR result; - + DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename, (unsigned long)strlen(handlename))); aprinter = handlename; @@ -455,14 +455,14 @@ static bool set_printer_hnd_name(Printer_entry *Printer, char *handlename) else { servername = ""; } - + /* save the servername to fill in replies on this handle */ - + if ( !is_myname_or_ipaddr( servername ) ) return False; fstrcpy( Printer->servername, servername ); - + if ( Printer->printer_type == SPLHND_SERVER ) return True; @@ -470,9 +470,9 @@ static bool set_printer_hnd_name(Printer_entry *Printer, char *handlename) return False; 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); @@ -484,12 +484,12 @@ static bool set_printer_hnd_name(Printer_entry *Printer, char *handlename) found = True; } - /* Search all sharenames first as this is easier than pulling + /* Search all sharenames first as this is easier than pulling the printer_info_2 off of disk. Don't use find_service() since 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", @@ -526,17 +526,17 @@ static bool set_printer_hnd_name(Printer_entry *Printer, char *handlename) free_a_printer( &printer, 2); continue; } - + printername++; - + if ( strequal(printername, aprinter) ) { free_a_printer( &printer, 2); found = True; break; } - + DEBUGADD(10, ("printername: %s\n", printername)); - + free_a_printer( &printer, 2); } @@ -546,7 +546,7 @@ static bool set_printer_hnd_name(Printer_entry *Printer, char *handlename) DEBUGADD(4,("Printer not found\n")); return False; } - + DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname)); fstrcpy(Printer->sharename, sname); @@ -568,28 +568,28 @@ static bool open_printer_hnd(pipes_struct *p, POLICY_HND *hnd, char *name, uint3 return False; ZERO_STRUCTP(new_printer); - + if (!create_policy_hnd(p, hnd, free_printer_entry, new_printer)) { SAFE_FREE(new_printer); return False; } - + /* Add to the internal list. */ DLIST_ADD(printers_list, new_printer); - + new_printer->notify.option=NULL; - + if ( !(new_printer->ctx = talloc_init("Printer Entry [%p]", hnd)) ) { DEBUG(0,("open_printer_hnd: talloc_init() failed!\n")); close_printer_handle(p, hnd); return False; } - + if (!set_printer_hnd_printertype(new_printer, name)) { close_printer_handle(p, hnd); return False; } - + if (!set_printer_hnd_name(new_printer, name)) { close_printer_handle(p, hnd); return False; @@ -619,10 +619,10 @@ static bool is_monitoring_event(Printer_entry *p, uint16 notify_type, SPOOL_NOTIFY_OPTION *option = p->notify.option; uint32 i, j; - /* + /* * Flags should always be zero when the change notify * is registered by the client's spooler. A user Win32 app - * might use the flags though instead of the NOTIFY_OPTION_INFO + * might use the flags though instead of the NOTIFY_OPTION_INFO * --jerry */ @@ -635,24 +635,24 @@ static bool is_monitoring_event(Printer_entry *p, uint16 notify_type, p->notify.flags, notify_type, notify_field); for (i = 0; i < option->count; i++) { - + /* Check match for notify_type */ - + if (option->ctr.type[i].type != notify_type) continue; /* Check match for field */ - + for (j = 0; j < option->ctr.type[i].count; j++) { if (option->ctr.type[i].fields[j] == notify_field) { return True; } } } - + DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n", p->servername, p->sharename, notify_type, notify_field)); - + return False; } @@ -671,7 +671,7 @@ static void notify_string(struct spoolss_notify_msg *msg, TALLOC_CTX *mem_ctx) { UNISTR2 unistr; - + /* The length of the message includes the trailing \0 */ init_unistr2(&unistr, msg->notify.data, UNI_STR_TERMINATE); @@ -683,7 +683,7 @@ static void notify_string(struct spoolss_notify_msg *msg, data->notify_data.data.length = 0; return; } - + memcpy(data->notify_data.data.string, unistr.buffer, msg->len * 2); } @@ -791,21 +791,21 @@ static struct notify2_message_table job_notify_table[] = { /*********************************************************************** Allocate talloc context for container object **********************************************************************/ - + static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr ) { if ( !ctr ) return; ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr); - + return; } /*********************************************************************** release all allocated memory and zero out structure **********************************************************************/ - + static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr ) { if ( !ctr ) @@ -813,34 +813,34 @@ static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr ) if ( ctr->ctx ) talloc_destroy(ctr->ctx); - + ZERO_STRUCTP(ctr); - + return; } /*********************************************************************** **********************************************************************/ - + static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr ) { if ( !ctr ) return NULL; - + return ctr->ctx; } /*********************************************************************** **********************************************************************/ - + static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) { if ( !ctr || !ctr->msg_groups ) return NULL; - + if ( idx >= ctr->num_groups ) return NULL; - + return &ctr->msg_groups[idx]; } @@ -848,38 +848,38 @@ static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ct /*********************************************************************** How many groups of change messages do we have ? **********************************************************************/ - + static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr ) { if ( !ctr ) return 0; - + return ctr->num_groups; } /*********************************************************************** Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group **********************************************************************/ - + static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg ) { SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL; SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL; SPOOLSS_NOTIFY_MSG *msg_list = NULL; int i, new_slot; - + if ( !ctr || !msg ) return 0; - + /* loop over all groups looking for a matching printer name */ - + for ( i=0; inum_groups; i++ ) { if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 ) break; } - + /* add a new group? */ - + if ( i == ctr->num_groups ) { ctr->num_groups++; @@ -890,37 +890,37 @@ static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MS ctr->msg_groups = groups; /* clear the new entry and set the printer name */ - + ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] ); fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer ); } - + /* add the change messages; 'i' is the correct index now regardless */ - + msg_grp = &ctr->msg_groups[i]; - + msg_grp->num_msgs++; - + if ( !(msg_list = TALLOC_REALLOC_ARRAY( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) { DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs)); return 0; } msg_grp->msgs = msg_list; - + new_slot = msg_grp->num_msgs-1; memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) ); - + /* need to allocate own copy of data */ - - if ( msg->len != 0 ) + + if ( msg->len != 0 ) msg_grp->msgs[new_slot].notify.data = (char *) TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len ); - + return ctr->num_groups; } /*********************************************************************** - Send a change notication message on all handles which have a call + Send a change notication message on all handles which have a call back registered **********************************************************************/ @@ -931,23 +931,23 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx ); SPOOLSS_NOTIFY_MSG *messages; int sending_msg_count; - + if ( !msg_group ) { DEBUG(5,("send_notify2_changes() called with no msg group!\n")); return; } - + messages = msg_group->msgs; - + if ( !messages ) { DEBUG(5,("send_notify2_changes() called with no messages!\n")); return; } - + DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername)); - + /* loop over all printers */ - + for (p = printers_list; p; p = p->next) { SPOOL_NOTIFY_INFO_DATA *data; uint32 data_len = 0; @@ -961,7 +961,7 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) DEBUG(10,("Client connected! [\\\\%s\\%s]\n", p->servername, p->sharename)); - /* For this printer? Print servers always receive + /* For this printer? Print servers always receive notifications. */ if ( ( p->printer_type == SPLHND_PRINTER ) && @@ -969,40 +969,40 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) continue; DEBUG(10,("Our printer\n")); - + /* allocate the max entries possible */ - + data = TALLOC_ARRAY( mem_ctx, SPOOL_NOTIFY_INFO_DATA, msg_group->num_msgs); if (!data) { return; } ZERO_STRUCTP(data); - + /* build the array of change notifications */ - + sending_msg_count = 0; - + for ( i=0; inum_msgs; i++ ) { SPOOLSS_NOTIFY_MSG *msg = &messages[i]; - + /* Are we monitoring this event? */ if (!is_monitoring_event(p, msg->type, msg->field)) continue; sending_msg_count++; - - + + DEBUG(10,("process_notify2_message: Sending message type [0x%x] field [0x%2x] for printer [%s]\n", msg->type, msg->field, p->sharename)); - /* - * if the is a printer notification handle and not a job notification + /* + * if the is a printer notification handle and not a job notification * type, then set the id to 0. Other wise just use what was specified - * in the message. + * in the message. * - * When registering change notification on a print server handle + * When registering change notification on a print server handle * we always need to send back the id (snum) matching the printer * for which the change took place. For change notify registered * on a printer handle, this does not matter and the id should be 0. @@ -1034,7 +1034,7 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) if ( printer_notify_table[msg->field].fn ) printer_notify_table[msg->field].fn(msg, &data[data_len], mem_ctx); break; - + case JOB_NOTIFY_TYPE: if ( job_notify_table[msg->field].fn ) job_notify_table[msg->field].fn(msg, &data[data_len], mem_ctx); @@ -1049,11 +1049,11 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) } if ( sending_msg_count ) { - rpccli_spoolss_rrpcn( notify_cli_pipe, mem_ctx, &p->notify.client_hnd, + rpccli_spoolss_rrpcn( notify_cli_pipe, mem_ctx, &p->notify.client_hnd, data_len, data, p->notify.change, 0 ); } } - + done: DEBUG(8,("send_notify2_changes: Exit...\n")); return; @@ -1072,7 +1072,7 @@ static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, voi offset += tdb_unpack((uint8 *)buf + offset, len - offset, "f", msg->printer); - + offset += tdb_unpack((uint8 *)buf + offset, len - offset, "ddddddd", &tv_sec, &tv_usec, &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags); @@ -1081,7 +1081,7 @@ static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, voi tdb_unpack((uint8 *)buf + offset, len - offset, "dd", &msg->notify.value[0], &msg->notify.value[1]); else - tdb_unpack((uint8 *)buf + offset, len - offset, "B", + tdb_unpack((uint8 *)buf + offset, len - offset, "B", &msg->len, &msg->notify.data); DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n", @@ -1121,7 +1121,7 @@ static void receive_notify2_message_list(struct messaging_context *msg, DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n")); return; } - + msg_count = IVAL(buf, 0); msg_ptr = buf + 4; @@ -1133,17 +1133,17 @@ static void receive_notify2_message_list(struct messaging_context *msg, } /* initialize the container */ - + ZERO_STRUCT( messages ); notify_msg_ctr_init( &messages ); - - /* + + /* * build message groups for each printer identified * in a change_notify msg. Remember that a PCN message * includes the handle returned for the srv_spoolss_replyopenprinter() * call. Therefore messages are grouped according to printer handle. */ - + for ( i=0; ilength,sizeof(drivername)-1); strncpy(drivername, (const char *)data->data, len); - + DEBUG(10,("do_drv_upgrade_printer: Got message for new driver [%s]\n", drivername )); /* Iterate the printer list */ - + for (snum=0; snuminfo_2 && !strcmp(drivername, printer->info_2->drivername)) + + if (printer && printer->info_2 && !strcmp(drivername, printer->info_2->drivername)) { DEBUG(6,("Updating printer [%s]\n", printer->info_2->printername)); - + /* all we care about currently is the change_id */ - + result = mod_a_printer(printer, 2); if (!W_ERROR_IS_OK(result)) { - DEBUG(3,("do_drv_upgrade_printer: mod_a_printer() failed with status [%s]\n", + DEBUG(3,("do_drv_upgrade_printer: mod_a_printer() failed with status [%s]\n", dos_errstr(result))); } } - - free_a_printer(&printer, 2); + + free_a_printer(&printer, 2); } } - - /* all done */ + + /* all done */ } /******************************************************************** - Update the cache for all printq's with a registered client + Update the cache for all printq's with a registered client connection ********************************************************************/ @@ -1278,21 +1278,21 @@ void update_monitored_printq_cache( void ) { Printer_entry *printer = printers_list; int snum; - - /* loop through all printers and update the cache where + + /* loop through all printers and update the cache where client_connected == True */ - while ( printer ) + while ( printer ) { - if ( (printer->printer_type == SPLHND_PRINTER) - && printer->notify.client_connected ) + if ( (printer->printer_type == SPLHND_PRINTER) + && printer->notify.client_connected ) { snum = print_queue_snum(printer->sharename); print_queue_status( snum, NULL, NULL ); } - + printer = printer->next; } - + return; } /******************************************************************** @@ -1300,17 +1300,17 @@ void update_monitored_printq_cache( void ) so we can upgrade the information for each printer bound to this driver ********************************************************************/ - + static bool srv_spoolss_reset_printerdata(char* drivername) { int len = strlen(drivername); - + if (!len) return False; DEBUG(10,("srv_spoolss_reset_printerdata: Sending message about resetting printerdata [%s]\n", drivername)); - + messaging_send_buf(smbd_messaging_context(), procid_self(), MSG_PRINTERDATA_INIT_RESET, (uint8 *)drivername, len+1); @@ -1320,9 +1320,9 @@ static bool srv_spoolss_reset_printerdata(char* drivername) /********************************************************************** callback to receive a MSG_PRINTERDATA_INIT_RESET message and interate - over all printers, resetting printer data as neessary + over all printers, resetting printer data as neessary **********************************************************************/ - + void reset_all_printerdata(struct messaging_context *msg, void *private_data, uint32_t msg_type, @@ -1333,52 +1333,52 @@ void reset_all_printerdata(struct messaging_context *msg, int snum; int n_services = lp_numservices(); size_t len; - + len = MIN( data->length, sizeof(drivername)-1 ); strncpy( drivername, (const char *)data->data, len ); - + DEBUG(10,("reset_all_printerdata: Got message for new driver [%s]\n", drivername )); /* Iterate the printer list */ - + for ( snum=0; snuminfo_2 && !strcmp(drivername, printer->info_2->drivername) ) + + if ( printer && printer->info_2 && !strcmp(drivername, printer->info_2->drivername) ) { DEBUG(6,("reset_all_printerdata: Updating printer [%s]\n", printer->info_2->printername)); - + if ( !set_driver_init(printer, 2) ) { DEBUG(5,("reset_all_printerdata: Error resetting printer data for printer [%s], driver [%s]!\n", printer->info_2->printername, printer->info_2->drivername)); - } - + } + result = mod_a_printer( printer, 2 ); if ( !W_ERROR_IS_OK(result) ) { - DEBUG(3,("reset_all_printerdata: mod_a_printer() failed! (%s)\n", + DEBUG(3,("reset_all_printerdata: mod_a_printer() failed! (%s)\n", get_dos_error_msg(result))); } } - + free_a_printer( &printer, 2 ); } } - - /* all done */ - + + /* all done */ + return; } @@ -1393,17 +1393,17 @@ static DEVICEMODE* dup_devicemode(TALLOC_CTX *ctx, DEVICEMODE *devmode) if (!devmode) return NULL; - + DEBUG (8,("dup_devmode\n")); - + /* bulk copy first */ - + d = (DEVICEMODE *)TALLOC_MEMDUP(ctx, devmode, sizeof(DEVICEMODE)); if (!d) return NULL; - + /* dup the pointer members separately */ - + len = unistrlen(devmode->devicename.buffer); if (len != -1) { d->devicename.buffer = TALLOC_ARRAY(ctx, uint16, len); @@ -1413,7 +1413,7 @@ static DEVICEMODE* dup_devicemode(TALLOC_CTX *ctx, DEVICEMODE *devmode) if (unistrcpy(d->devicename.buffer, devmode->devicename.buffer) != len) return NULL; } - + len = unistrlen(devmode->formname.buffer); if (len != -1) { @@ -1430,7 +1430,7 @@ static DEVICEMODE* dup_devicemode(TALLOC_CTX *ctx, DEVICEMODE *devmode) devmode->driverextra); if (!d->dev_private) { return NULL; - } + } } else { d->dev_private = NULL; } @@ -1441,12 +1441,12 @@ static void copy_devmode_ctr(TALLOC_CTX *ctx, DEVMODE_CTR *new_ctr, DEVMODE_CTR { if (!new_ctr || !ctr) return; - + DEBUG(8,("copy_devmode_ctr\n")); - + new_ctr->size = ctr->size; new_ctr->devmode_ptr = ctr->devmode_ptr; - + if(ctr->devmode_ptr) new_ctr->devmode = dup_devicemode(ctx, ctr->devmode); } @@ -1455,21 +1455,21 @@ static void copy_printer_default(TALLOC_CTX *ctx, PRINTER_DEFAULT *new_def, PRIN { if (!new_def || !def) return; - + DEBUG(8,("copy_printer_defaults\n")); - + new_def->datatype_ptr = def->datatype_ptr; - + if (def->datatype_ptr) copy_unistr2(&new_def->datatype, &def->datatype); - + copy_devmode_ctr(ctx, &new_def->devmode_cont, &def->devmode_cont); - + new_def->access_required = def->access_required; } /******************************************************************** - * Convert a SPOOL_Q_OPEN_PRINTER structure to a + * Convert a SPOOL_Q_OPEN_PRINTER structure to a * SPOOL_Q_OPEN_PRINTER_EX structure ********************************************************************/ @@ -1479,14 +1479,14 @@ static WERROR convert_to_openprinterex(TALLOC_CTX *ctx, SPOOL_Q_OPEN_PRINTER_EX return WERR_OK; DEBUG(8,("convert_to_openprinterex\n")); - + if ( q_u->printername ) { q_u_ex->printername = TALLOC_ZERO_P( ctx, UNISTR2 ); if (q_u_ex->printername == NULL) return WERR_NOMEM; copy_unistr2(q_u_ex->printername, q_u->printername); } - + copy_printer_default(ctx, &q_u_ex->printer_default, &q_u->printer_default); return WERR_OK; @@ -1502,25 +1502,25 @@ WERROR _spoolss_open_printer(pipes_struct *p, SPOOL_Q_OPEN_PRINTER *q_u, SPOOL_R { SPOOL_Q_OPEN_PRINTER_EX q_u_ex; SPOOL_R_OPEN_PRINTER_EX r_u_ex; - + if (!q_u || !r_u) return WERR_NOMEM; - + ZERO_STRUCT(q_u_ex); ZERO_STRUCT(r_u_ex); - + /* convert the OpenPrinter() call to OpenPrinterEx() */ - + r_u_ex.status = convert_to_openprinterex(p->mem_ctx, &q_u_ex, q_u); if (!W_ERROR_IS_OK(r_u_ex.status)) return r_u_ex.status; - + r_u_ex.status = _spoolss_open_printer_ex(p, &q_u_ex, &r_u_ex); - + /* convert back to OpenPrinter() */ - + memcpy(r_u, &r_u_ex, sizeof(*r_u)); - + return r_u->status; } @@ -1548,7 +1548,7 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, if (!open_printer_hnd(p, handle, name, 0)) return WERR_INVALID_PRINTER_NAME; - + Printer=find_printer_index_by_hnd(p, handle); if ( !Printer ) { DEBUG(0,(" _spoolss_open_printer_ex: logic error. Can't find printer " @@ -1572,16 +1572,16 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, * * Note: this test needs code to check access rights here too. Jeremy * could you look at this? - * + * * Second case: the user is opening a printer: * NT doesn't let us connect to a printer if the connecting user * doesn't have print permission. - * + * * Third case: user is opening a Port Monitor * access checks same as opening a handle to the print server. */ - switch (Printer->printer_type ) + switch (Printer->printer_type ) { case SPLHND_SERVER: case SPLHND_PORTMON_TCP: @@ -1591,10 +1591,10 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, snum = -1; /* Map standard access rights to object specific access rights */ - - se_map_standard(&printer_default->access_required, + + se_map_standard(&printer_default->access_required, &printserver_std_mapping); - + /* Deny any object specific bits that don't apply to print servers (i.e printer and job specific bits) */ @@ -1609,7 +1609,7 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, /* Allow admin access */ - if ( printer_default->access_required & SERVER_ACCESS_ADMINISTER ) + if ( printer_default->access_required & SERVER_ACCESS_ADMINISTER ) { SE_PRIV se_printop = SE_PRINT_OPERATOR; @@ -1620,7 +1620,7 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege, and not a printer admin, then fail */ - + if ((p->pipe_user.ut.uid != 0) && !user_has_privileges(p->pipe_user.nt_user_token, &se_printop ) && @@ -1631,7 +1631,7 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, close_printer_handle(p, handle); return WERR_ACCESS_DENIED; } - + printer_default->access_required = SERVER_ACCESS_ADMINISTER; } else @@ -1639,9 +1639,9 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, printer_default->access_required = SERVER_ACCESS_ENUMERATE; } - DEBUG(4,("Setting print server access = %s\n", (printer_default->access_required == SERVER_ACCESS_ADMINISTER) + DEBUG(4,("Setting print server access = %s\n", (printer_default->access_required == SERVER_ACCESS_ADMINISTER) ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" )); - + /* We fall through to return WERR_OK */ break; @@ -1655,7 +1655,7 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, } se_map_standard(&printer_default->access_required, &printer_std_mapping); - + /* map an empty access mask to the minimum access mask */ if (printer_default->access_required == 0x0) printer_default->access_required = PRINTER_ACCESS_USE; @@ -1663,18 +1663,18 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, /* * If we are not serving the printer driver for this printer, * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This - * will keep NT clients happy --jerry + * will keep NT clients happy --jerry */ - - if (lp_use_client_driver(snum) + + if (lp_use_client_driver(snum) && (printer_default->access_required & PRINTER_ACCESS_ADMINISTER)) { printer_default->access_required = PRINTER_ACCESS_USE; } /* check smb.conf parameters and the the sec_desc */ - - if ( !check_access(smbd_server_fd(), lp_hostsallow(snum), lp_hostsdeny(snum)) ) { + + if ( !check_access(smbd_server_fd(), lp_hostsallow(snum), lp_hostsdeny(snum)) ) { DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n")); return WERR_ACCESS_DENIED; } @@ -1699,7 +1699,7 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, else printer_default->access_required = PRINTER_ACCESS_USE; - DEBUG(4,("Setting printer access = %s\n", (printer_default->access_required == PRINTER_ACCESS_ADMINISTER) + DEBUG(4,("Setting printer access = %s\n", (printer_default->access_required == PRINTER_ACCESS_ADMINISTER) ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" )); break; @@ -1708,26 +1708,26 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, /* sanity check to prevent programmer error */ return WERR_BADFID; } - + Printer->access_granted = printer_default->access_required; - - /* + + /* * If the client sent a devmode in the OpenPrinter() call, then * save it here in case we get a job submission on this handle */ - + if ( (Printer->printer_type != SPLHND_SERVER) && q_u->printer_default.devmode_cont.devmode_ptr ) - { + { convert_devicemode( Printer->sharename, q_u->printer_default.devmode_cont.devmode, &Printer->nt_devmode ); } #if 0 /* JERRY -- I'm doubtful this is really effective */ - /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN + /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN optimization in Windows 2000 clients --jerry */ - if ( (printer_default->access_required == PRINTER_ACCESS_ADMINISTER) + if ( (printer_default->access_required == PRINTER_ACCESS_ADMINISTER) && (RA_WIN2K == get_remote_arch()) ) { DEBUG(10,("_spoolss_open_printer_ex: Enabling LAN/WAN hack for Win2k clients.\n")); @@ -1748,8 +1748,8 @@ static bool convert_printer_info(const SPOOL_PRINTER_INFO_LEVEL *uni, switch (level) { case 2: - /* allocate memory if needed. Messy because - convert_printer_info is used to update an existing + /* allocate memory if needed. Messy because + convert_printer_info is used to update an existing printer or build a new one */ if ( !printer->info_2 ) { @@ -1801,7 +1801,7 @@ bool convert_devicemode(const char *printername, const DEVICEMODE *devmode, * Ensure nt_devmode is a valid pointer * as we will be overwriting it. */ - + if (nt_devmode == NULL) { DEBUG(5, ("convert_devicemode: allocating a generic devmode\n")); if ((nt_devmode = construct_nt_devicemode(printername)) == NULL) @@ -1875,7 +1875,7 @@ static WERROR _spoolss_enddocprinter_internal(pipes_struct *p, POLICY_HND *handl DEBUG(2,("_spoolss_enddocprinter_internal: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle))); return WERR_BADFID; } - + if (!get_printer_snum(p, handle, &snum, NULL)) return WERR_BADFID; @@ -1900,9 +1900,9 @@ WERROR _spoolss_closeprinter(pipes_struct *p, SPOOL_Q_CLOSEPRINTER *q_u, SPOOL_R _spoolss_enddocprinter_internal(p, handle); /* print job was not closed */ if (!close_printer_handle(p, handle)) - return WERR_BADFID; - - /* clear the returned printer handle. Observed behavior + return WERR_BADFID; + + /* clear the returned printer handle. Observed behavior from Win2k server. Don't think this really matters. Previous code just copied the value of the closed handle. --jerry */ @@ -1944,23 +1944,23 @@ static int get_version_id (char * arch) { int i; struct table_node archi_table[]= { - + {"Windows 4.0", "WIN40", 0 }, {"Windows NT x86", "W32X86", 2 }, - {"Windows NT R4000", "W32MIPS", 2 }, + {"Windows NT R4000", "W32MIPS", 2 }, {"Windows NT Alpha_AXP", "W32ALPHA", 2 }, {"Windows NT PowerPC", "W32PPC", 2 }, {"Windows IA64", "IA64", 3 }, {"Windows x64", "x64", 3 }, {NULL, "", -1 } }; - + for (i=0; archi_table[i].long_archi != NULL; i++) { if (strcmp(arch, archi_table[i].long_archi) == 0) return (archi_table[i].version); } - + return -1; } @@ -1977,34 +1977,34 @@ WERROR _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER int version; WERROR status; WERROR status_win2k = WERR_ACCESS_DENIED; - SE_PRIV se_printop = SE_PRINT_OPERATOR; - + SE_PRIV se_printop = SE_PRINT_OPERATOR; + /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege, and not a printer admin, then fail */ - - if ( (p->pipe_user.ut.uid != 0) - && !user_has_privileges(p->pipe_user.nt_user_token, &se_printop ) - && !token_contains_name_in_list( uidtoname(p->pipe_user.ut.uid), - NULL, p->pipe_user.nt_user_token, lp_printer_admin(-1)) ) + + if ( (p->pipe_user.ut.uid != 0) + && !user_has_privileges(p->pipe_user.nt_user_token, &se_printop ) + && !token_contains_name_in_list( uidtoname(p->pipe_user.ut.uid), + NULL, p->pipe_user.nt_user_token, lp_printer_admin(-1)) ) { return WERR_ACCESS_DENIED; } unistr2_to_ascii(driver, &q_u->driver, sizeof(driver)); unistr2_to_ascii(arch, &q_u->arch, sizeof(arch)); - + /* check that we have a valid driver name first */ - - if ((version=get_version_id(arch)) == -1) + + if ((version=get_version_id(arch)) == -1) return WERR_INVALID_ENVIRONMENT; - + ZERO_STRUCT(info); ZERO_STRUCT(info_win2k); - - if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, driver, arch, version))) + + if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, driver, arch, version))) { /* try for Win2k driver if "Windows NT x86" */ - + if ( version == 2 ) { version = 3; if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, driver, arch, version))) { @@ -2017,24 +2017,24 @@ WERROR _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER status = WERR_UNKNOWN_PRINTER_DRIVER; goto done; } - + } - + if (printer_driver_in_use(info.info_3)) { status = WERR_PRINTER_DRIVER_IN_USE; goto done; } - + if ( version == 2 ) - { + { if (W_ERROR_IS_OK(get_a_printer_driver(&info_win2k, 3, driver, arch, 3))) { /* 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 ); free_a_printer_driver( info_win2k, 3 ); - + /* this should not have failed---if it did, report to client */ if ( !W_ERROR_IS_OK(status_win2k) ) { @@ -2043,14 +2043,14 @@ WERROR _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER } } } - + status = delete_printer_driver(info.info_3, &p->pipe_user, version, False); - + /* if at least one of the deletes succeeded return OK */ - + if ( W_ERROR_IS_OK(status) || W_ERROR_IS_OK(status_win2k) ) status = WERR_OK; - + done: free_a_printer_driver( info, 3 ); @@ -2072,19 +2072,19 @@ WERROR _spoolss_deleteprinterdriverex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIV bool delete_files; WERROR status; WERROR status_win2k = WERR_ACCESS_DENIED; - SE_PRIV se_printop = SE_PRINT_OPERATOR; - + SE_PRIV se_printop = SE_PRINT_OPERATOR; + /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege, and not a printer admin, then fail */ - - if ( (p->pipe_user.ut.uid != 0) - && !user_has_privileges(p->pipe_user.nt_user_token, &se_printop ) - && !token_contains_name_in_list( uidtoname(p->pipe_user.ut.uid), - NULL, p->pipe_user.nt_user_token, lp_printer_admin(-1)) ) + + if ( (p->pipe_user.ut.uid != 0) + && !user_has_privileges(p->pipe_user.nt_user_token, &se_printop ) + && !token_contains_name_in_list( uidtoname(p->pipe_user.ut.uid), + NULL, p->pipe_user.nt_user_token, lp_printer_admin(-1)) ) { return WERR_ACCESS_DENIED; } - + unistr2_to_ascii(driver, &q_u->driver, sizeof(driver)); unistr2_to_ascii(arch, &q_u->arch, sizeof(arch)); @@ -2093,84 +2093,84 @@ WERROR _spoolss_deleteprinterdriverex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIV /* this is what NT returns */ return WERR_INVALID_ENVIRONMENT; } - + if ( flags & DPD_DELETE_SPECIFIC_VERSION ) version = q_u->version; - + ZERO_STRUCT(info); ZERO_STRUCT(info_win2k); - + status = get_a_printer_driver(&info, 3, driver, arch, version); - - if ( !W_ERROR_IS_OK(status) ) + + if ( !W_ERROR_IS_OK(status) ) { - /* - * if the client asked for a specific version, + /* + * if the client asked for a specific version, * or this is something other than Windows NT x86, - * then we've failed + * then we've failed */ - + if ( (flags&DPD_DELETE_SPECIFIC_VERSION) || (version !=2) ) goto done; - + /* try for Win2k driver if "Windows NT x86" */ - + version = 3; if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, driver, arch, version))) { status = WERR_UNKNOWN_PRINTER_DRIVER; goto done; } } - + if ( printer_driver_in_use(info.info_3) ) { status = WERR_PRINTER_DRIVER_IN_USE; goto done; } - - /* - * we have a couple of cases to consider. + + /* + * we have a couple of cases to consider. * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set, - * then the delete should fail if **any** files overlap with - * other drivers + * then the delete should fail if **any** files overlap with + * other drivers * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all - * non-overlapping files + * non-overlapping files * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES * is set, the do not delete any files * Refer to MSDN docs on DeletePrinterDriverEx() for details. */ - + delete_files = flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES); - + /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */ - + if ( delete_files && printer_driver_files_in_use(info.info_3) & (flags&DPD_DELETE_ALL_FILES) ) { /* no idea of the correct error here */ - status = WERR_ACCESS_DENIED; + status = WERR_ACCESS_DENIED; goto done; } - + /* also check for W32X86/3 if necessary; maybe we already have? */ - + if ( (version == 2) && ((flags&DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) { - if (W_ERROR_IS_OK(get_a_printer_driver(&info_win2k, 3, driver, arch, 3))) + if (W_ERROR_IS_OK(get_a_printer_driver(&info_win2k, 3, driver, arch, 3))) { - + if ( delete_files && printer_driver_files_in_use(info_win2k.info_3) & (flags&DPD_DELETE_ALL_FILES) ) { /* no idea of the correct error here */ free_a_printer_driver( info_win2k, 3 ); - status = WERR_ACCESS_DENIED; + status = WERR_ACCESS_DENIED; goto done; } - + /* 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); free_a_printer_driver( info_win2k, 3 ); - + /* this should not have failed---if it did, report to client */ - + if ( !W_ERROR_IS_OK(status_win2k) ) goto done; } @@ -2182,7 +2182,7 @@ WERROR _spoolss_deleteprinterdriverex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIV status = WERR_OK; done: free_a_printer_driver( info, 3 ); - + return status; } @@ -2191,28 +2191,28 @@ done: Internal routine for retreiving printerdata ***************************************************************************/ -static WERROR get_printer_dataex( TALLOC_CTX *ctx, NT_PRINTER_INFO_LEVEL *printer, - const char *key, const char *value, uint32 *type, uint8 **data, +static WERROR get_printer_dataex( TALLOC_CTX *ctx, NT_PRINTER_INFO_LEVEL *printer, + const char *key, const char *value, uint32 *type, uint8 **data, uint32 *needed, uint32 in_size ) { REGISTRY_VALUE *val; uint32 size; int data_len; - + if ( !(val = get_printer_data( printer->info_2, key, value)) ) return WERR_BADFILE; - + *type = regval_type( val ); DEBUG(5,("get_printer_dataex: allocating %d\n", in_size)); size = regval_size( val ); - + /* copy the min(in_size, len) */ - + if ( in_size ) { data_len = (size > in_size) ? in_size : size*sizeof(uint8); - + /* special case for 0 length values */ if ( data_len ) { if ( (*data = (uint8 *)TALLOC_MEMDUP(ctx, regval_data_p(val), data_len)) == NULL ) @@ -2227,7 +2227,7 @@ static WERROR get_printer_dataex( TALLOC_CTX *ctx, NT_PRINTER_INFO_LEVEL *printe *data = NULL; *needed = size; - + DEBUG(5,("get_printer_dataex: copy done\n")); return WERR_OK; @@ -2246,7 +2246,7 @@ static WERROR delete_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char Internal routine for storing printerdata ***************************************************************************/ -WERROR set_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char *key, const char *value, +WERROR set_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char *key, const char *value, uint32 type, uint8 *data, int real_len ) { /* the registry objects enforce uniqueness based on value name */ @@ -2259,11 +2259,11 @@ WERROR set_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char *key, cons ********************************************************************/ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint32 *type, uint8 **data, uint32 *needed, uint32 in_size) -{ +{ int i; - + DEBUG(8,("getprinterdata_printer_server:%s\n", value)); - + if (!StrCaseCmp(value, "W3SvcInstalled")) { *type = REG_DWORD; if ( !(*data = TALLOC_ARRAY(ctx, uint8, sizeof(uint32) )) ) @@ -2278,7 +2278,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint if ( !(*data = TALLOC_ARRAY(ctx, uint8, sizeof(uint32) )) ) return WERR_NOMEM; SIVAL(*data, 0, 0x00); - *needed = 0x4; + *needed = 0x4; return WERR_OK; } @@ -2288,7 +2288,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint return WERR_NOMEM; /* formally was 0x1b */ SIVAL(*data, 0, 0x0); - *needed = 0x4; + *needed = 0x4; return WERR_OK; } @@ -2315,7 +2315,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint SIVAL(*data, 0, 2); else SIVAL(*data, 0, 3); - + *needed = 0x4; return WERR_OK; } @@ -2347,9 +2347,9 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint SIVAL(*data, 4, 5); /* Windows 2000 == 5.0 */ SIVAL(*data, 8, 0); SIVAL(*data, 12, 2195); /* build */ - + /* leave extra string empty */ - + return WERR_OK; } @@ -2357,30 +2357,30 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint if (!StrCaseCmp(value, "DefaultSpoolDirectory")) { const char *string="C:\\PRINTERS"; *type = REG_SZ; - *needed = 2*(strlen(string)+1); + *needed = 2*(strlen(string)+1); if((*data = (uint8 *)TALLOC(ctx, (*needed > in_size) ? *needed:in_size )) == NULL) return WERR_NOMEM; memset(*data, 0, (*needed > in_size) ? *needed:in_size); - + /* it's done by hand ready to go on the wire */ for (i=0; i in_size) ? *needed:in_size )) == NULL) return WERR_NOMEM; memset(*data, 0, (*needed > in_size) ? *needed:in_size); for (i=0; iprinter_type == SPLHND_SERVER ) status = getprinterdata_printer_server( p->mem_ctx, value, type, data, needed, *out_size ); else @@ -2496,30 +2496,30 @@ WERROR _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO if (*needed > *out_size) status = WERR_MORE_DATA; - + done: - if ( !W_ERROR_IS_OK(status) ) + if ( !W_ERROR_IS_OK(status) ) { DEBUG(5, ("error %d: allocating %d\n", W_ERROR_V(status),*out_size)); - + /* reply this param doesn't exist */ - + if ( *out_size ) { if((*data=(uint8 *)TALLOC_ZERO_ARRAY(p->mem_ctx, uint8, *out_size)) == NULL) { - if ( printer ) + if ( printer ) free_a_printer( &printer, 2 ); return WERR_NOMEM; - } + } } else { *data = NULL; } } - + /* cleanup & exit */ if ( printer ) free_a_printer( &printer, 2 ); - + return status; } @@ -2554,7 +2554,7 @@ static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe, /* setup the connection */ - ret = cli_full_connection( &the_cli, global_myname(), remote_machine, + ret = cli_full_connection( &the_cli, global_myname(), remote_machine, &rm_addr, 0, "IPC$", "IPC", "", /* username */ "", /* domain */ @@ -2562,17 +2562,17 @@ static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe, 0, lp_client_signing(), NULL ); if ( !NT_STATUS_IS_OK( ret ) ) { - DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n", + DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n", remote_machine )); return False; - } - + } + if ( the_cli->protocol != PROTOCOL_NT1 ) { DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine)); cli_shutdown(the_cli); return False; } - + /* * Ok - we have an anonymous connection to the IPC$ share. * Now start the NT Domain stuff :-). @@ -2583,7 +2583,7 @@ static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe, remote_machine, nt_errstr(ret))); cli_shutdown(the_cli); return False; - } + } /* make sure to save the cli_state pointer. Keep its own talloc_ctx */ @@ -2596,8 +2596,8 @@ static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe, Connect to the client. ****************************************************************************/ -static bool srv_spoolss_replyopenprinter(int snum, const char *printer, - uint32 localprinter, uint32 type, +static bool srv_spoolss_replyopenprinter(int snum, const char *printer, + uint32 localprinter, uint32 type, POLICY_HND *handle, struct sockaddr_storage *client_ss) { WERROR result; @@ -2613,7 +2613,7 @@ static bool srv_spoolss_replyopenprinter(int snum, const char *printer, if ( !spoolss_connect_to_client( ¬ify_cli_pipe, client_ss, unix_printer )) return False; - + messaging_register(smbd_messaging_context(), NULL, MSG_PRINTER_NOTIFY2, receive_notify2_message_list); @@ -2622,7 +2622,7 @@ static bool srv_spoolss_replyopenprinter(int snum, const char *printer, register_message_flags( True, FLAG_MSG_PRINT_NOTIFY ); } - /* + /* * Tell the specific printing tdb we want messages for this printer * by registering our PID. */ @@ -2632,14 +2632,14 @@ static bool srv_spoolss_replyopenprinter(int snum, const char *printer, smb_connections++; - result = rpccli_spoolss_reply_open_printer(notify_cli_pipe, notify_cli_pipe->cli->mem_ctx, printer, localprinter, + result = rpccli_spoolss_reply_open_printer(notify_cli_pipe, notify_cli_pipe->cli->mem_ctx, printer, localprinter, type, handle); - + if (!W_ERROR_IS_OK(result)) DEBUG(5,("srv_spoolss_reply_open_printer: Client RPC returned [%s]\n", dos_errstr(result))); - return (W_ERROR_IS_OK(result)); + return (W_ERROR_IS_OK(result)); } /******************************************************************** @@ -2647,7 +2647,7 @@ static bool srv_spoolss_replyopenprinter(int snum, const char *printer, * ReplyFindFirstPrinterChangeNotifyEx * * before replying OK: status=0 a rpc call is made to the workstation - * asking ReplyOpenPrinter + * asking ReplyOpenPrinter * * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe * called from api_spoolss_rffpcnex @@ -2682,7 +2682,7 @@ WERROR _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE Printer->notify.option=dup_spool_notify_option(option); - unistr2_to_ascii(Printer->notify.localmachine, localmachine, + unistr2_to_ascii(Printer->notify.localmachine, localmachine, sizeof(Printer->notify.localmachine)); /* Connect to the client machine and send a ReplyOpenPrinter */ @@ -2713,11 +2713,11 @@ WERROR _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE * fill a notify_info_data with the servername ********************************************************************/ -void spoolss_notify_server_name(int snum, - SPOOL_NOTIFY_INFO_DATA *data, +void spoolss_notify_server_name(int snum, + SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, - TALLOC_CTX *mem_ctx) + TALLOC_CTX *mem_ctx) { pstring temp; uint32 len; @@ -2731,7 +2731,7 @@ void spoolss_notify_server_name(int snum, data->notify_data.data.length = 0; return; } - + memcpy(data->notify_data.data.string, temp, len); } else { data->notify_data.data.string = NULL; @@ -2742,15 +2742,15 @@ void spoolss_notify_server_name(int snum, * fill a notify_info_data with the printername (not including the servername). ********************************************************************/ -void spoolss_notify_printer_name(int snum, - SPOOL_NOTIFY_INFO_DATA *data, +void spoolss_notify_printer_name(int snum, + SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) { pstring temp; uint32 len; - + /* the notify name should not contain the \\server\ part */ char *p = strrchr(printer->info_2->printername, '\\'); @@ -2779,8 +2779,8 @@ void spoolss_notify_printer_name(int snum, * fill a notify_info_data with the servicename ********************************************************************/ -void spoolss_notify_share_name(int snum, - SPOOL_NOTIFY_INFO_DATA *data, +void spoolss_notify_share_name(int snum, + SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) @@ -2801,15 +2801,15 @@ void spoolss_notify_share_name(int snum, } else { data->notify_data.data.string = NULL; } - + } /******************************************************************* * fill a notify_info_data with the port name ********************************************************************/ -void spoolss_notify_port_name(int snum, - SPOOL_NOTIFY_INFO_DATA *data, +void spoolss_notify_port_name(int snum, + SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) @@ -2824,12 +2824,12 @@ void spoolss_notify_port_name(int snum, data->notify_data.data.length = len; if (len) { data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - + if (!data->notify_data.data.string) { data->notify_data.data.length = 0; return; } - + memcpy(data->notify_data.data.string, temp, len); } else { data->notify_data.data.string = NULL; @@ -2841,7 +2841,7 @@ void spoolss_notify_port_name(int snum, * but it doesn't exist, have to see what to do ********************************************************************/ -void spoolss_notify_driver_name(int snum, +void spoolss_notify_driver_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -2855,12 +2855,12 @@ void spoolss_notify_driver_name(int snum, data->notify_data.data.length = len; if (len) { data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - + if (!data->notify_data.data.string) { data->notify_data.data.length = 0; return; } - + memcpy(data->notify_data.data.string, temp, len); } else { data->notify_data.data.string = NULL; @@ -2871,7 +2871,7 @@ void spoolss_notify_driver_name(int snum, * fill a notify_info_data with the comment ********************************************************************/ -void spoolss_notify_comment(int snum, +void spoolss_notify_comment(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -2888,12 +2888,12 @@ void spoolss_notify_comment(int snum, data->notify_data.data.length = len; if (len) { data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - + if (!data->notify_data.data.string) { data->notify_data.data.length = 0; return; } - + memcpy(data->notify_data.data.string, temp, len); } else { data->notify_data.data.string = NULL; @@ -2905,7 +2905,7 @@ void spoolss_notify_comment(int snum, * location = "Room 1, floor 2, building 3" ********************************************************************/ -void spoolss_notify_location(int snum, +void spoolss_notify_location(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -2919,12 +2919,12 @@ void spoolss_notify_location(int snum, data->notify_data.data.length = len; if (len) { data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - + if (!data->notify_data.data.string) { data->notify_data.data.length = 0; return; } - + memcpy(data->notify_data.data.string, temp, len); } else { data->notify_data.data.string = NULL; @@ -2936,7 +2936,7 @@ void spoolss_notify_location(int snum, * jfm:xxxx don't to it for know but that's a real problem !!! ********************************************************************/ -static void spoolss_notify_devmode(int snum, +static void spoolss_notify_devmode(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -2951,8 +2951,8 @@ static void spoolss_notify_devmode(int snum, * fill a notify_info_data with the separator file name ********************************************************************/ -void spoolss_notify_sepfile(int snum, - SPOOL_NOTIFY_INFO_DATA *data, +void spoolss_notify_sepfile(int snum, + SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) @@ -2965,12 +2965,12 @@ void spoolss_notify_sepfile(int snum, data->notify_data.data.length = len; if (len) { data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - + if (!data->notify_data.data.string) { data->notify_data.data.length = 0; return; } - + memcpy(data->notify_data.data.string, temp, len); } else { data->notify_data.data.string = NULL; @@ -2982,7 +2982,7 @@ void spoolss_notify_sepfile(int snum, * jfm:xxxx return always winprint to indicate we don't do anything to it ********************************************************************/ -void spoolss_notify_print_processor(int snum, +void spoolss_notify_print_processor(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -2996,12 +2996,12 @@ void spoolss_notify_print_processor(int snum, data->notify_data.data.length = len; if (len) { data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - + if (!data->notify_data.data.string) { data->notify_data.data.length = 0; return; } - + memcpy(data->notify_data.data.string, temp, len); } else { data->notify_data.data.string = NULL; @@ -3013,7 +3013,7 @@ void spoolss_notify_print_processor(int snum, * jfm:xxxx send an empty string ********************************************************************/ -void spoolss_notify_parameters(int snum, +void spoolss_notify_parameters(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -3027,12 +3027,12 @@ void spoolss_notify_parameters(int snum, data->notify_data.data.length = len; if (len) { data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - + if (!data->notify_data.data.string) { data->notify_data.data.length = 0; return; } - + memcpy(data->notify_data.data.string, temp, len); } else { data->notify_data.data.string = NULL; @@ -3044,7 +3044,7 @@ void spoolss_notify_parameters(int snum, * jfm:xxxx always send RAW as data type ********************************************************************/ -void spoolss_notify_datatype(int snum, +void spoolss_notify_datatype(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -3058,12 +3058,12 @@ void spoolss_notify_datatype(int snum, data->notify_data.data.length = len; if (len) { data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - + if (!data->notify_data.data.string) { data->notify_data.data.length = 0; return; } - + memcpy(data->notify_data.data.string, temp, len); } else { data->notify_data.data.string = NULL; @@ -3076,7 +3076,7 @@ void spoolss_notify_datatype(int snum, * have to implement security before ! ********************************************************************/ -static void spoolss_notify_security_desc(int snum, +static void spoolss_notify_security_desc(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -3091,7 +3091,7 @@ static void spoolss_notify_security_desc(int snum, * jfm:xxxx a samba printer is always shared ********************************************************************/ -void spoolss_notify_attributes(int snum, +void spoolss_notify_attributes(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -3105,7 +3105,7 @@ void spoolss_notify_attributes(int snum, * fill a notify_info_data with the priority ********************************************************************/ -static void spoolss_notify_priority(int snum, +static void spoolss_notify_priority(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -3119,7 +3119,7 @@ static void spoolss_notify_priority(int snum, * fill a notify_info_data with the default priority ********************************************************************/ -static void spoolss_notify_default_priority(int snum, +static void spoolss_notify_default_priority(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -3133,7 +3133,7 @@ static void spoolss_notify_default_priority(int snum, * fill a notify_info_data with the start time ********************************************************************/ -static void spoolss_notify_start_time(int snum, +static void spoolss_notify_start_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -3147,7 +3147,7 @@ static void spoolss_notify_start_time(int snum, * fill a notify_info_data with the until time ********************************************************************/ -static void spoolss_notify_until_time(int snum, +static void spoolss_notify_until_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -3161,7 +3161,7 @@ static void spoolss_notify_until_time(int snum, * fill a notify_info_data with the status ********************************************************************/ -static void spoolss_notify_status(int snum, +static void spoolss_notify_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -3178,10 +3178,10 @@ static void spoolss_notify_status(int snum, * fill a notify_info_data with the number of jobs queued ********************************************************************/ -void spoolss_notify_cjobs(int snum, +void spoolss_notify_cjobs(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, - NT_PRINTER_INFO_LEVEL *printer, + NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) { data->notify_data.value[0] = print_queue_length(snum, NULL); @@ -3192,7 +3192,7 @@ void spoolss_notify_cjobs(int snum, * fill a notify_info_data with the average ppm ********************************************************************/ -static void spoolss_notify_average_ppm(int snum, +static void spoolss_notify_average_ppm(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -3208,7 +3208,7 @@ static void spoolss_notify_average_ppm(int snum, * fill a notify_info_data with username ********************************************************************/ -static void spoolss_notify_username(int snum, +static void spoolss_notify_username(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -3222,12 +3222,12 @@ static void spoolss_notify_username(int snum, data->notify_data.data.length = len; if (len) { data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - + if (!data->notify_data.data.string) { data->notify_data.data.length = 0; return; } - + memcpy(data->notify_data.data.string, temp, len); } else { data->notify_data.data.string = NULL; @@ -3238,7 +3238,7 @@ static void spoolss_notify_username(int snum, * fill a notify_info_data with job status ********************************************************************/ -static void spoolss_notify_job_status(int snum, +static void spoolss_notify_job_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -3252,7 +3252,7 @@ static void spoolss_notify_job_status(int snum, * fill a notify_info_data with job name ********************************************************************/ -static void spoolss_notify_job_name(int snum, +static void spoolss_notify_job_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -3266,12 +3266,12 @@ static void spoolss_notify_job_name(int snum, data->notify_data.data.length = len; if (len) { data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - + if (!data->notify_data.data.string) { data->notify_data.data.length = 0; return; } - + memcpy(data->notify_data.data.string, temp, len); } else { data->notify_data.data.string = NULL; @@ -3282,10 +3282,10 @@ static void spoolss_notify_job_name(int snum, * fill a notify_info_data with job status ********************************************************************/ -static void spoolss_notify_job_status_string(int snum, +static void spoolss_notify_job_status_string(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, - NT_PRINTER_INFO_LEVEL *printer, + NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) { /* @@ -3320,12 +3320,12 @@ static void spoolss_notify_job_status_string(int snum, data->notify_data.data.length = len; if (len) { data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - + if (!data->notify_data.data.string) { data->notify_data.data.length = 0; return; } - + memcpy(data->notify_data.data.string, temp, len); } else { data->notify_data.data.string = NULL; @@ -3336,7 +3336,7 @@ static void spoolss_notify_job_status_string(int snum, * fill a notify_info_data with job time ********************************************************************/ -static void spoolss_notify_job_time(int snum, +static void spoolss_notify_job_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -3350,7 +3350,7 @@ static void spoolss_notify_job_time(int snum, * fill a notify_info_data with job size ********************************************************************/ -static void spoolss_notify_job_size(int snum, +static void spoolss_notify_job_size(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -3390,7 +3390,7 @@ static void spoolss_notify_pages_printed(int snum, Fill a notify_info_data with job position. ********************************************************************/ -static void spoolss_notify_job_position(int snum, +static void spoolss_notify_job_position(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -3404,7 +3404,7 @@ static void spoolss_notify_job_position(int snum, Fill a notify_info_data with submitted time. ********************************************************************/ -static void spoolss_notify_submitted_time(int snum, +static void spoolss_notify_submitted_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, @@ -3426,11 +3426,11 @@ static void spoolss_notify_submitted_time(int snum, data->notify_data.data.length = 0; return; } - + make_systemtime(&st, t); /* - * Systemtime must be linearized as a set of UINT16's. + * Systemtime must be linearized as a set of UINT16's. * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au */ @@ -3538,7 +3538,7 @@ static uint32 size_of_notify_info_data(uint16 type, uint16 field) case NOTIFY_POINTER: return 4; - + case NOTIFY_SECDESC: return 5; } @@ -3571,7 +3571,7 @@ static uint32 type_of_notify_info_data(uint16 type, uint16 field) ****************************************************************************/ static bool search_notify(uint16 type, uint16 field, int *value) -{ +{ int i; for (i = 0; notify_info_data_table[i].type != PRINT_TABLE_END; i++) { @@ -3582,8 +3582,8 @@ static bool search_notify(uint16 type, uint16 field, int *value) return True; } } - - return False; + + return False; } /**************************************************************************** @@ -3610,7 +3610,7 @@ void construct_info_data(SPOOL_NOTIFY_INFO_DATA *info_data, uint16 type, uint16 static bool construct_notify_printer_info(Printer_entry *print_hnd, SPOOL_NOTIFY_INFO *info, int snum, SPOOL_NOTIFY_OPTION_TYPE *option_type, uint32 id, - TALLOC_CTX *mem_ctx) + TALLOC_CTX *mem_ctx) { int field_num,j; uint16 type; @@ -3625,13 +3625,13 @@ static bool construct_notify_printer_info(Printer_entry *print_hnd, SPOOL_NOTIFY DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n", (option_type->type==PRINTER_NOTIFY_TYPE?"PRINTER_NOTIFY_TYPE":"JOB_NOTIFY_TYPE"), option_type->count, lp_servicename(snum))); - + if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &printer, 2, lp_const_servicename(snum)))) return False; for(field_num=0; field_numcount; field_num++) { field = option_type->fields[field_num]; - + DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field)); if (!search_notify(type, field, &j) ) @@ -3671,16 +3671,16 @@ static bool construct_notify_jobs_info(print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer, int snum, SPOOL_NOTIFY_OPTION_TYPE *option_type, uint32 id, - TALLOC_CTX *mem_ctx) + TALLOC_CTX *mem_ctx) { int field_num,j; uint16 type; uint16 field; SPOOL_NOTIFY_INFO_DATA *current_data; - + DEBUG(4,("construct_notify_jobs_info\n")); - + type = option_type->type; DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n", @@ -3739,7 +3739,7 @@ static bool construct_notify_jobs_info(print_queue_struct *queue, * ********************************************************************/ -static WERROR printserver_notify_info(pipes_struct *p, POLICY_HND *hnd, +static WERROR printserver_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info, TALLOC_CTX *mem_ctx) { @@ -3751,7 +3751,7 @@ static WERROR printserver_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY_OPTION_TYPE *option_type; DEBUG(4,("printserver_notify_info\n")); - + if (!Printer) return WERR_BADFID; @@ -3760,7 +3760,7 @@ static WERROR printserver_notify_info(pipes_struct *p, POLICY_HND *hnd, info->data=NULL; info->count=0; - /* a bug in xp sp2 rc2 causes it to send a fnpcn request without + /* a bug in xp sp2 rc2 causes it to send a fnpcn request without sending a ffpcn() request first */ if ( !option ) @@ -3768,18 +3768,18 @@ static WERROR printserver_notify_info(pipes_struct *p, POLICY_HND *hnd, for (i=0; icount; i++) { option_type=&(option->ctr.type[i]); - + if (option_type->type!=PRINTER_NOTIFY_TYPE) continue; - + for (snum=0; snumversion:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count)); DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n")); - + for (i=0; icount; i++) { DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n", i, info->data[i].type, info->data[i].field, info->data[i].reserved, info->data[i].id, info->data[i].size, info->data[i].enc_type)); } #endif - + return WERR_OK; } @@ -3816,7 +3816,7 @@ static WERROR printer_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY int count,j; print_queue_struct *queue=NULL; print_status_struct status; - + DEBUG(4,("printer_notify_info\n")); if (!Printer) @@ -3828,7 +3828,7 @@ static WERROR printer_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY info->data=NULL; info->count=0; - /* a bug in xp sp2 rc2 causes it to send a fnpcn request without + /* a bug in xp sp2 rc2 causes it to send a fnpcn request without sending a ffpcn() request first */ if ( !option ) @@ -3838,15 +3838,15 @@ static WERROR printer_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY for (i=0; icount; i++) { option_type=&option->ctr.type[i]; - + switch ( option_type->type ) { case PRINTER_NOTIFY_TYPE: - if(construct_notify_printer_info(Printer, info, snum, + if(construct_notify_printer_info(Printer, info, snum, option_type, id, - mem_ctx)) + mem_ctx)) id--; break; - + case JOB_NOTIFY_TYPE: { NT_PRINTER_INFO_LEVEL *printer = NULL; @@ -3860,18 +3860,18 @@ static WERROR printer_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY printer, snum, option_type, queue[j].job, - mem_ctx); + mem_ctx); } free_a_printer(&printer, 2); - + done: SAFE_FREE(queue); break; } } } - + /* * Debugging information, don't delete. */ @@ -3879,7 +3879,7 @@ static WERROR printer_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY DEBUG(1,("dumping the NOTIFY_INFO\n")); DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count)); DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n")); - + for (i=0; icount; i++) { DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n", i, info->data[i].type, info->data[i].field, info->data[i].reserved, @@ -3913,13 +3913,13 @@ WERROR _spoolss_rfnpcnex( pipes_struct *p, SPOOL_Q_RFNPCNEX *q_u, SPOOL_R_RFNPCN DEBUG(4,("Printer type %x\n",Printer->printer_type)); /* - * We are now using the change value, and + * We are now using the change value, and * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as * I don't have a global notification system, I'm sending back all the * informations even when _NOTHING_ has changed. */ - /* We need to keep track of the change value to send back in + /* We need to keep track of the change value to send back in RRPCN replies otherwise our updates are ignored. */ Printer->notify.fnpcn = True; @@ -3930,19 +3930,19 @@ WERROR _spoolss_rfnpcnex( pipes_struct *p, SPOOL_Q_RFNPCNEX *q_u, SPOOL_R_RFNPCN } /* just ignore the SPOOL_NOTIFY_OPTION */ - + switch (Printer->printer_type) { case SPLHND_SERVER: result = printserver_notify_info(p, handle, info, p->mem_ctx); break; - + case SPLHND_PRINTER: result = printer_notify_info(p, handle, info, p->mem_ctx); break; } - + Printer->notify.fnpcn = False; - + done: return result; } @@ -3962,13 +3962,13 @@ static bool construct_printer_info_0(Printer_entry *print_hnd, PRINTER_INFO_0 *p struct tm *t; time_t setuptime; print_status_struct status; - + if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum)))) return False; count = print_queue_length(snum, &status); - /* check if we already have a counter for this printer */ + /* check if we already have a counter for this printer */ for(session_counter = counter_list; session_counter; session_counter = session_counter->next) { if (session_counter->snum == snum) break; @@ -3985,23 +3985,23 @@ static bool construct_printer_info_0(Printer_entry *print_hnd, PRINTER_INFO_0 *p session_counter->counter=0; DLIST_ADD(counter_list, session_counter); } - + /* increment it */ session_counter->counter++; - + /* JFM: * the global_counter should be stored in a TDB as it's common to all the clients * and should be zeroed on samba startup */ global_counter=session_counter->counter; - + pstrcpy(chaine,ntprinter->info_2->printername); init_unistr(&printer->printername, chaine); - + slprintf(chaine,sizeof(chaine)-1,"\\\\%s", get_server_name(print_hnd)); init_unistr(&printer->servername, chaine); - + printer->cjobs = count; printer->total_jobs = 0; printer->total_bytes = 0; @@ -4020,11 +4020,11 @@ static bool construct_printer_info_0(Printer_entry *print_hnd, PRINTER_INFO_0 *p printer->global_counter = global_counter; printer->total_pages = 0; - + /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */ printer->major_version = 0x0005; /* NT 5 */ printer->build_version = 0x0893; /* build 2195 */ - + printer->unknown7 = 0x1; printer->unknown8 = 0x0; printer->unknown9 = 0x0; @@ -4048,9 +4048,9 @@ static bool construct_printer_info_0(Printer_entry *print_hnd, PRINTER_INFO_0 *p printer->unknown27 = 0; printer->unknown28 = 0; printer->unknown29 = 0; - + free_a_printer(&ntprinter,2); - return (True); + return (True); } /******************************************************************** @@ -4078,12 +4078,12 @@ static bool construct_printer_info_1(Printer_entry *print_hnd, uint32 flags, PRI slprintf(chaine,sizeof(chaine)-1,"%s,%s,%s", ntprinter->info_2->printername, ntprinter->info_2->drivername, ntprinter->info_2->comment); } - + slprintf(chaine2,sizeof(chaine)-1,"%s", ntprinter->info_2->printername); init_unistr(&printer->description, chaine); - init_unistr(&printer->name, chaine2); - + init_unistr(&printer->name, chaine2); + free_a_printer(&ntprinter,2); return True; @@ -4099,12 +4099,12 @@ static void free_dev_mode(DEVICEMODE *dev) return; SAFE_FREE(dev->dev_private); - SAFE_FREE(dev); + SAFE_FREE(dev); } /**************************************************************************** - Convert an NT_DEVICEMODE to a DEVICEMODE structure. Both pointers + Convert an NT_DEVICEMODE to a DEVICEMODE structure. Both pointers should be valid upon entry ****************************************************************************/ @@ -4112,7 +4112,7 @@ static bool convert_nt_devicemode( DEVICEMODE *devmode, NT_DEVICEMODE *ntdevmode { if ( !devmode || !ntdevmode ) return False; - + init_unistr(&devmode->devicename, ntdevmode->devicename); init_unistr(&devmode->formname, ntdevmode->formname); @@ -4122,8 +4122,8 @@ static bool convert_nt_devicemode( DEVICEMODE *devmode, NT_DEVICEMODE *ntdevmode devmode->size = ntdevmode->size; devmode->driverextra = ntdevmode->driverextra; devmode->fields = ntdevmode->fields; - - devmode->orientation = ntdevmode->orientation; + + devmode->orientation = ntdevmode->orientation; devmode->papersize = ntdevmode->papersize; devmode->paperlength = ntdevmode->paperlength; devmode->paperwidth = ntdevmode->paperwidth; @@ -4145,7 +4145,7 @@ static bool convert_nt_devicemode( DEVICEMODE *devmode, NT_DEVICEMODE *ntdevmode if ((devmode->dev_private=(uint8 *)memdup(ntdevmode->nt_dev_private, ntdevmode->driverextra)) == NULL) return False; } - + return True; } @@ -4157,12 +4157,12 @@ DEVICEMODE *construct_dev_mode(const char *servicename) { NT_PRINTER_INFO_LEVEL *printer = NULL; DEVICEMODE *devmode = NULL; - + DEBUG(7,("construct_dev_mode\n")); - + DEBUGADD(8,("getting printer characteristics\n")); - if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, servicename))) + if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, servicename))) return NULL; if ( !printer->info_2->devmode ) { @@ -4175,8 +4175,8 @@ DEVICEMODE *construct_dev_mode(const char *servicename) goto done; } - ZERO_STRUCTP(devmode); - + ZERO_STRUCTP(devmode); + DEBUGADD(8,("loading DEVICEMODE\n")); if ( !convert_nt_devicemode( devmode, printer->info_2->devmode ) ) { @@ -4204,46 +4204,46 @@ static bool construct_printer_info_2(Printer_entry *print_hnd, PRINTER_INFO_2 *p if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum)))) return False; - + count = print_queue_length(snum, &status); init_unistr(&printer->servername, ntprinter->info_2->servername); /* servername*/ init_unistr(&printer->printername, ntprinter->info_2->printername); /* printername*/ init_unistr(&printer->sharename, lp_servicename(snum)); /* sharename */ - init_unistr(&printer->portname, ntprinter->info_2->portname); /* port */ + init_unistr(&printer->portname, ntprinter->info_2->portname); /* port */ init_unistr(&printer->drivername, ntprinter->info_2->drivername); /* drivername */ if (*ntprinter->info_2->comment == '\0') - init_unistr(&printer->comment, lp_comment(snum)); /* comment */ + init_unistr(&printer->comment, lp_comment(snum)); /* comment */ else init_unistr(&printer->comment, ntprinter->info_2->comment); /* saved comment. */ - init_unistr(&printer->location, ntprinter->info_2->location); /* location */ + init_unistr(&printer->location, ntprinter->info_2->location); /* location */ init_unistr(&printer->sepfile, ntprinter->info_2->sepfile); /* separator file */ init_unistr(&printer->printprocessor, ntprinter->info_2->printprocessor);/* print processor */ - init_unistr(&printer->datatype, ntprinter->info_2->datatype); /* datatype */ - init_unistr(&printer->parameters, ntprinter->info_2->parameters); /* parameters (of print processor) */ + init_unistr(&printer->datatype, ntprinter->info_2->datatype); /* datatype */ + init_unistr(&printer->parameters, ntprinter->info_2->parameters); /* parameters (of print processor) */ printer->attributes = ntprinter->info_2->attributes; - printer->priority = ntprinter->info_2->priority; /* priority */ + printer->priority = ntprinter->info_2->priority; /* priority */ printer->defaultpriority = ntprinter->info_2->default_priority; /* default priority */ printer->starttime = ntprinter->info_2->starttime; /* starttime */ printer->untiltime = ntprinter->info_2->untiltime; /* untiltime */ printer->status = nt_printq_status(status.status); /* status */ printer->cjobs = count; /* jobs */ printer->averageppm = ntprinter->info_2->averageppm; /* average pages per minute */ - + if ( !(printer->devmode = construct_dev_mode( lp_const_servicename(snum))) ) DEBUG(8, ("Returning NULL Devicemode!\n")); printer->secdesc = NULL; - if ( ntprinter->info_2->secdesc_buf - && ntprinter->info_2->secdesc_buf->sd_size != 0 ) + if ( ntprinter->info_2->secdesc_buf + && ntprinter->info_2->secdesc_buf->sd_size != 0 ) { - /* don't use talloc_steal() here unless you do a deep steal of all + /* don't use talloc_steal() here unless you do a deep steal of all the SEC_DESC members */ printer->secdesc = dup_sec_desc( talloc_tos(), @@ -4276,11 +4276,11 @@ static bool construct_printer_info_3(Printer_entry *print_hnd, PRINTER_INFO_3 ** } ZERO_STRUCTP(printer); - + /* These are the components of the SD we are returning. */ if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->sd_size != 0) { - /* don't use talloc_steal() here unless you do a deep steal of all + /* don't use talloc_steal() here unless you do a deep steal of all the SEC_DESC members */ printer->secdesc = dup_sec_desc( talloc_tos(), @@ -4304,7 +4304,7 @@ static bool construct_printer_info_4(Printer_entry *print_hnd, PRINTER_INFO_4 *p if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum)))) return False; - + init_unistr(&printer->printername, ntprinter->info_2->printername); /* printername*/ init_unistr(&printer->servername, ntprinter->info_2->servername); /* servername*/ printer->attributes = ntprinter->info_2->attributes; @@ -4324,9 +4324,9 @@ static bool construct_printer_info_5(Printer_entry *print_hnd, PRINTER_INFO_5 *p if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum)))) return False; - + init_unistr(&printer->printername, ntprinter->info_2->printername); - init_unistr(&printer->portname, ntprinter->info_2->portname); + init_unistr(&printer->portname, ntprinter->info_2->portname); printer->attributes = ntprinter->info_2->attributes; /* these two are not used by NT+ according to MSDN */ @@ -4359,7 +4359,7 @@ static bool construct_printer_info_6(Printer_entry *print_hnd, count = print_queue_length(snum, &status); printer->status = nt_printq_status(status.status); - + free_a_printer(&ntprinter, 2); return True; @@ -4373,8 +4373,8 @@ static bool construct_printer_info_6(Printer_entry *print_hnd, static bool construct_printer_info_7(Printer_entry *print_hnd, PRINTER_INFO_7 *printer, int snum) { char *guid_str = NULL; - struct GUID guid; - + struct GUID guid; + if (is_printer_published(print_hnd, snum, &guid)) { asprintf(&guid_str, "{%s}", smb_uuid_string(talloc_tos(), guid)); @@ -4401,8 +4401,8 @@ static WERROR enum_all_printers_info_1(uint32 flags, RPC_BUFFER *buffer, uint32 PRINTER_INFO_1 *printers=NULL; PRINTER_INFO_1 current_prt; WERROR result = WERR_OK; - - DEBUG(4,("enum_all_printers_info_1\n")); + + DEBUG(4,("enum_all_printers_info_1\n")); for (snum=0; snumdescription, desc); - init_unistr(&printer->name, printername); + init_unistr(&printer->name, printername); init_unistr(&printer->comment, comment); printer->flags=PRINTER_ENUM_ICON3|PRINTER_ENUM_CONTAINER; - - /* check the required size. */ + + /* check the required size. */ *needed += spoolss_size_printer_info_1(printer); if (*needed > offered) { @@ -4532,7 +4532,7 @@ static WERROR enum_all_printers_info_1_remote(fstring name, RPC_BUFFER *buffer, } /* fill the buffer with the structures */ - smb_io_printer_info_1("", buffer, printer, 0); + smb_io_printer_info_1("", buffer, printer, 0); out: /* clear memory */ @@ -4554,15 +4554,15 @@ static WERROR enum_all_printers_info_1_network(fstring name, RPC_BUFFER *buffer, { char *s = name; - DEBUG(4,("enum_all_printers_info_1_network\n")); - + DEBUG(4,("enum_all_printers_info_1_network\n")); + /* If we respond to a enum_printers level 1 on our name with flags set to PRINTER_ENUM_REMOTE with a list of printers then these printers incorrectly appear in the APW browse list. Specifically the printers for the server appear at the workgroup level where all the other servers in the domain are listed. Windows responds to this call with a - WERR_CAN_NOT_COMPLETE so we should do the same. */ + WERR_CAN_NOT_COMPLETE so we should do the same. */ if (name[0] == '\\' && name[1] == '\\') s = name + 2; @@ -4593,7 +4593,7 @@ static WERROR enum_all_printers_info_2(RPC_BUFFER *buffer, uint32 offered, uint3 for (snum=0; snum offered) { result = WERR_INSUFFICIENT_BUFFER; goto out; @@ -4626,12 +4626,12 @@ static WERROR enum_all_printers_info_2(RPC_BUFFER *buffer, uint32 offered, uint3 /* fill the buffer with the structures */ for (i=0; i<*returned; i++) - smb_io_printer_info_2("", buffer, &(printers[i]), 0); - + smb_io_printer_info_2("", buffer, &(printers[i]), 0); + out: /* clear memory */ - for (i=0; i<*returned; i++) + for (i=0; i<*returned; i++) free_devmode(printers[i].devmode); SAFE_FREE(printers); @@ -4727,7 +4727,7 @@ WERROR _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOOL_ uint32 *returned = &r_u->returned; fstring name; - + /* that's an [in out] buffer */ if (!q_u->buffer && (offered!=0)) { @@ -4741,7 +4741,7 @@ WERROR _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOOL_ *needed=0; *returned=0; - + /* * Level 1: * flags==PRINTER_ENUM_NAME @@ -4784,8 +4784,8 @@ static WERROR getprinter_level_0(Printer_entry *print_hnd, int snum, RPC_BUFFER return WERR_NOMEM; construct_printer_info_0(print_hnd, printer, snum); - - /* check the required size. */ + + /* check the required size. */ *needed += spoolss_size_printer_info_0(printer); if (*needed > offered) { @@ -4799,8 +4799,8 @@ static WERROR getprinter_level_0(Printer_entry *print_hnd, int snum, RPC_BUFFER } /* fill the buffer with the structures */ - smb_io_printer_info_0("", buffer, printer, 0); - + smb_io_printer_info_0("", buffer, printer, 0); + out: /* clear memory */ @@ -4821,8 +4821,8 @@ static WERROR getprinter_level_1(Printer_entry *print_hnd, int snum, RPC_BUFFER return WERR_NOMEM; construct_printer_info_1(print_hnd, PRINTER_ENUM_ICON8, printer, snum); - - /* check the required size. */ + + /* check the required size. */ *needed += spoolss_size_printer_info_1(printer); if (*needed > offered) { @@ -4836,13 +4836,13 @@ static WERROR getprinter_level_1(Printer_entry *print_hnd, int snum, RPC_BUFFER } /* fill the buffer with the structures */ - smb_io_printer_info_1("", buffer, printer, 0); - + smb_io_printer_info_1("", buffer, printer, 0); + out: /* clear memory */ SAFE_FREE(printer); - return result; + return result; } /**************************************************************************** @@ -4855,12 +4855,12 @@ static WERROR getprinter_level_2(Printer_entry *print_hnd, int snum, RPC_BUFFER if((printer=SMB_MALLOC_P(PRINTER_INFO_2))==NULL) return WERR_NOMEM; - + construct_printer_info_2(print_hnd, printer, snum); - - /* check the required size. */ + + /* check the required size. */ *needed += spoolss_size_printer_info_2(printer); - + if (*needed > offered) { result = WERR_INSUFFICIENT_BUFFER; goto out; @@ -4872,14 +4872,14 @@ static WERROR getprinter_level_2(Printer_entry *print_hnd, int snum, RPC_BUFFER } /* fill the buffer with the structures */ - if (!smb_io_printer_info_2("", buffer, printer, 0)) + if (!smb_io_printer_info_2("", buffer, printer, 0)) result = WERR_NOMEM; - + out: /* clear memory */ free_printer_info_2(printer); - return result; + return result; } /**************************************************************************** @@ -4892,8 +4892,8 @@ static WERROR getprinter_level_3(Printer_entry *print_hnd, int snum, RPC_BUFFER if (!construct_printer_info_3(print_hnd, &printer, snum)) return WERR_NOMEM; - - /* check the required size. */ + + /* check the required size. */ *needed += spoolss_size_printer_info_3(printer); if (*needed > offered) { @@ -4907,13 +4907,13 @@ static WERROR getprinter_level_3(Printer_entry *print_hnd, int snum, RPC_BUFFER } /* fill the buffer with the structures */ - smb_io_printer_info_3("", buffer, printer, 0); - + smb_io_printer_info_3("", buffer, printer, 0); + out: /* clear memory */ free_printer_info_3(printer); - - return result; + + return result; } /**************************************************************************** @@ -4931,8 +4931,8 @@ static WERROR getprinter_level_4(Printer_entry *print_hnd, int snum, RPC_BUFFER SAFE_FREE(printer); return WERR_NOMEM; } - - /* check the required size. */ + + /* check the required size. */ *needed += spoolss_size_printer_info_4(printer); if (*needed > offered) { @@ -4946,13 +4946,13 @@ static WERROR getprinter_level_4(Printer_entry *print_hnd, int snum, RPC_BUFFER } /* fill the buffer with the structures */ - smb_io_printer_info_4("", buffer, printer, 0); - + smb_io_printer_info_4("", buffer, printer, 0); + out: /* clear memory */ free_printer_info_4(printer); - - return result; + + return result; } /**************************************************************************** @@ -4970,8 +4970,8 @@ static WERROR getprinter_level_5(Printer_entry *print_hnd, int snum, RPC_BUFFER free_printer_info_5(printer); return WERR_NOMEM; } - - /* check the required size. */ + + /* check the required size. */ *needed += spoolss_size_printer_info_5(printer); if (*needed > offered) { @@ -4985,13 +4985,13 @@ static WERROR getprinter_level_5(Printer_entry *print_hnd, int snum, RPC_BUFFER } /* fill the buffer with the structures */ - smb_io_printer_info_5("", buffer, printer, 0); - + smb_io_printer_info_5("", buffer, printer, 0); + out: /* clear memory */ free_printer_info_5(printer); - - return result; + + return result; } static WERROR getprinter_level_6(Printer_entry *print_hnd, @@ -5025,13 +5025,13 @@ static WERROR getprinter_level_6(Printer_entry *print_hnd, } /* fill the buffer with the structures */ - smb_io_printer_info_6("", buffer, printer, 0); - + smb_io_printer_info_6("", buffer, printer, 0); + out: /* clear memory */ free_printer_info_6(printer); - - return result; + + return result; } static WERROR getprinter_level_7(Printer_entry *print_hnd, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) @@ -5044,8 +5044,8 @@ static WERROR getprinter_level_7(Printer_entry *print_hnd, int snum, RPC_BUFFER if (!construct_printer_info_7(print_hnd, printer, snum)) return WERR_NOMEM; - - /* check the required size. */ + + /* check the required size. */ *needed += spoolss_size_printer_info_7(printer); if (*needed > offered) { @@ -5060,13 +5060,13 @@ static WERROR getprinter_level_7(Printer_entry *print_hnd, int snum, RPC_BUFFER } /* fill the buffer with the structures */ - smb_io_printer_info_7("", buffer, printer, 0); - + smb_io_printer_info_7("", buffer, printer, 0); + out: /* clear memory */ free_printer_info_7(printer); - - return result; + + return result; } /**************************************************************************** @@ -5102,22 +5102,22 @@ WERROR _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GET return getprinter_level_0(Printer, snum, buffer, offered, needed); case 1: return getprinter_level_1(Printer, snum, buffer, offered, needed); - case 2: + case 2: return getprinter_level_2(Printer, snum, buffer, offered, needed); - case 3: + case 3: return getprinter_level_3(Printer, snum, buffer, offered, needed); - case 4: + case 4: return getprinter_level_4(Printer, snum, buffer, offered, needed); - case 5: + case 5: return getprinter_level_5(Printer, snum, buffer, offered, needed); - case 6: + case 6: return getprinter_level_6(Printer, snum, buffer, offered, needed); case 7: return getprinter_level_7(Printer, snum, buffer, offered, needed); } return WERR_UNKNOWN_LEVEL; -} - +} + /******************************************************************** * fill a DRIVER_INFO_1 struct ********************************************************************/ @@ -5132,7 +5132,7 @@ static void fill_printer_driver_info_1(DRIVER_INFO_1 *info, NT_PRINTER_DRIVER_IN ********************************************************************/ static WERROR construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, fstring servername, fstring architecture, uint32 version) -{ +{ NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; @@ -5179,10 +5179,10 @@ static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, NT_PRINTER_DRIVER_IN init_unistr( &info->datafile, temp ); } else init_unistr( &info->datafile, "" ); - + if (strlen(driver.info_3->configfile)) { slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->configfile); - init_unistr( &info->configfile, temp ); + init_unistr( &info->configfile, temp ); } else init_unistr( &info->configfile, "" ); } @@ -5231,52 +5231,52 @@ static uint32 init_unistr_array(uint16 **uni_array, fstring *char_array, const c DEBUG(6,("init_unistr_array\n")); *uni_array=NULL; - while (True) + while (True) { if ( !char_array ) v = ""; - else + else { v = char_array[i]; - if (!v) + if (!v) v = ""; /* hack to handle null lists */ } - - /* hack to allow this to be used in places other than when generating + + /* hack to allow this to be used in places other than when generating the list of dependent files */ - + if ( servername ) slprintf( line, sizeof(line)-1, "\\\\%s%s", servername, v ); else pstrcpy( line, v ); - + DEBUGADD(6,("%d:%s:%lu\n", i, line, (unsigned long)strlen(line))); /* add one extra unit16 for the second terminating NULL */ - + if ( (*uni_array=SMB_REALLOC_ARRAY(*uni_array, uint16, j+1+strlen(line)+2)) == NULL ) { DEBUG(2,("init_unistr_array: Realloc error\n" )); return 0; } - if ( !strlen(v) ) + if ( !strlen(v) ) break; - + j += (rpcstr_push((*uni_array+j), line, sizeof(uint16)*strlen(line)+2, STR_TERMINATE) / sizeof(uint16)); i++; } - + if (*uni_array) { /* special case for ""; we need to add both NULL's here */ if (!j) - (*uni_array)[j++]=0x0000; + (*uni_array)[j++]=0x0000; (*uni_array)[j]=0x0000; } - + DEBUGADD(6,("last one:done\n")); /* return size of array in uint16's */ - + return j+1; } @@ -5293,15 +5293,15 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_IN info->version=driver.info_3->cversion; - init_unistr( &info->name, driver.info_3->name ); + init_unistr( &info->name, driver.info_3->name ); init_unistr( &info->architecture, driver.info_3->environment ); if (strlen(driver.info_3->driverpath)) { - slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->driverpath); + slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->driverpath); init_unistr( &info->driverpath, temp ); } else init_unistr( &info->driverpath, "" ); - + if (strlen(driver.info_3->datafile)) { slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->datafile); init_unistr( &info->datafile, temp ); @@ -5310,7 +5310,7 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_IN if (strlen(driver.info_3->configfile)) { slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->configfile); - init_unistr( &info->configfile, temp ); + init_unistr( &info->configfile, temp ); } else init_unistr( &info->configfile, "" ); @@ -5333,7 +5333,7 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_IN ********************************************************************/ static WERROR construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fstring servername, fstring architecture, uint32 version) -{ +{ NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; WERROR status; @@ -5344,13 +5344,13 @@ static WERROR construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fst if (!W_ERROR_IS_OK(status)) return WERR_INVALID_PRINTER_NAME; - status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version); + status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version); DEBUG(8,("construct_printer_driver_info_3: status: %s\n", dos_errstr(status))); #if 0 /* JERRY */ - /* - * I put this code in during testing. Helpful when commenting out the + /* + * I put this code in during testing. Helpful when commenting out the * support for DRIVER_INFO_6 in regards to win2k. Not needed in general * as win2k always queries the driver using an infor level of 6. * I've left it in (but ifdef'd out) because I'll probably @@ -5364,7 +5364,7 @@ static WERROR construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fst if (version == 3) { /* Yes - try again with a WinNT driver. */ version = 2; - status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version); + status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version); DEBUG(8,("construct_printer_driver_info_3: status: %s\n", dos_errstr(status))); } #endif @@ -5373,11 +5373,11 @@ static WERROR construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fst free_a_printer(&printer,2); return WERR_UNKNOWN_PRINTER_DRIVER; } - + #if 0 /* JERRY */ } #endif - + fill_printer_driver_info_3(info, driver, servername); @@ -5401,11 +5401,11 @@ static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_IN info->version=driver.info_3->cversion; - init_unistr( &info->name, driver.info_3->name ); + init_unistr( &info->name, driver.info_3->name ); init_unistr( &info->architecture, driver.info_3->environment ); if (strlen(driver.info_3->driverpath)) { - slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->driverpath); + slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->driverpath); init_unistr( &info->driverpath, temp ); } else init_unistr( &info->driverpath, "" ); @@ -5418,7 +5418,7 @@ static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_IN if (strlen(driver.info_3->configfile)) { slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->configfile); - init_unistr( &info->configfile, temp ); + init_unistr( &info->configfile, temp ); } else init_unistr( &info->configfile, "" ); @@ -5427,7 +5427,7 @@ static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_IN init_unistr( &info->helpfile, temp ); } else init_unistr( &info->helpfile, "" ); - + init_unistr( &info->monitorname, driver.info_3->monitorname ); init_unistr( &info->defaultdatatype, driver.info_3->defaultdatatype ); @@ -5454,27 +5454,27 @@ static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_IN * fill a printer_info_6 struct ********************************************************************/ -static WERROR construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, +static WERROR construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, fstring servername, fstring architecture, uint32 version) -{ +{ NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; WERROR status; - + ZERO_STRUCT(driver); status=get_a_printer(NULL, &printer, 2, lp_const_servicename(snum) ); - + DEBUG(8,("construct_printer_driver_info_6: status: %s\n", dos_errstr(status))); - + if (!W_ERROR_IS_OK(status)) return WERR_INVALID_PRINTER_NAME; status = get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version); - + DEBUG(8,("construct_printer_driver_info_6: status: %s\n", dos_errstr(status))); - - if (!W_ERROR_IS_OK(status)) + + if (!W_ERROR_IS_OK(status)) { /* * Is this a W2k client ? @@ -5487,7 +5487,7 @@ static WERROR construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, /* Yes - try again with a WinNT driver. */ version = 2; - status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version); + status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version); DEBUG(8,("construct_printer_driver_info_6: status: %s\n", dos_errstr(status))); if (!W_ERROR_IS_OK(status)) { free_a_printer(&printer,2); @@ -5526,15 +5526,15 @@ static WERROR getprinterdriver2_level1(fstring servername, fstring architecture, { DRIVER_INFO_1 *info=NULL; WERROR result; - + if((info=SMB_MALLOC_P(DRIVER_INFO_1)) == NULL) return WERR_NOMEM; - + result = construct_printer_driver_info_1(info, snum, servername, architecture, version); - if (!W_ERROR_IS_OK(result)) + if (!W_ERROR_IS_OK(result)) goto out; - /* check the required size. */ + /* check the required size. */ *needed += spoolss_size_printer_driver_info_1(info); if (*needed > offered) { @@ -5548,7 +5548,7 @@ static WERROR getprinterdriver2_level1(fstring servername, fstring architecture, } /* fill the buffer with the structures */ - smb_io_printer_driver_info_1("", buffer, info, 0); + smb_io_printer_driver_info_1("", buffer, info, 0); out: /* clear memory */ @@ -5564,29 +5564,29 @@ static WERROR getprinterdriver2_level2(fstring servername, fstring architecture, { DRIVER_INFO_2 *info=NULL; WERROR result; - + if((info=SMB_MALLOC_P(DRIVER_INFO_2)) == NULL) return WERR_NOMEM; - + result = construct_printer_driver_info_2(info, snum, servername, architecture, version); - if (!W_ERROR_IS_OK(result)) + if (!W_ERROR_IS_OK(result)) goto out; - /* check the required size. */ + /* check the required size. */ *needed += spoolss_size_printer_driver_info_2(info); if (*needed > offered) { result = WERR_INSUFFICIENT_BUFFER; goto out; } - + if (!rpcbuf_alloc_size(buffer, *needed)) { result = WERR_NOMEM; goto out; } /* fill the buffer with the structures */ - smb_io_printer_driver_info_2("", buffer, info, 0); + smb_io_printer_driver_info_2("", buffer, info, 0); out: /* clear memory */ @@ -5609,7 +5609,7 @@ static WERROR getprinterdriver2_level3(fstring servername, fstring architecture, if (!W_ERROR_IS_OK(result)) goto out; - /* check the required size. */ + /* check the required size. */ *needed += spoolss_size_printer_driver_info_3(&info); if (*needed > offered) { @@ -5642,17 +5642,17 @@ static WERROR getprinterdriver2_level6(fstring servername, fstring architecture, ZERO_STRUCT(info); result = construct_printer_driver_info_6(&info, snum, servername, architecture, version); - if (!W_ERROR_IS_OK(result)) + if (!W_ERROR_IS_OK(result)) goto out; - /* check the required size. */ + /* check the required size. */ *needed += spoolss_size_printer_driver_info_6(&info); if (*needed > offered) { result = WERR_INSUFFICIENT_BUFFER; goto out; } - + if (!rpcbuf_alloc_size(buffer, *needed)) { result = WERR_NOMEM; goto out; @@ -5723,8 +5723,8 @@ WERROR _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_ case 6: return getprinterdriver2_level6(servername, architecture, clientmajorversion, snum, buffer, offered, needed); #if 0 /* JERRY */ - case 101: - /* apparently this call is the equivalent of + case 101: + /* apparently this call is the equivalent of EnumPrinterDataEx() for the DsDriver key */ break; #endif @@ -5765,7 +5765,7 @@ WERROR _spoolss_endpageprinter(pipes_struct *p, SPOOL_Q_ENDPAGEPRINTER *q_u, SPO DEBUG(2,("_spoolss_endpageprinter: Invalid handle (%s:%u:%u).\n",OUR_HANDLE(handle))); return WERR_BADFID; } - + if (!get_printer_snum(p, handle, &snum, NULL)) return WERR_BADFID; @@ -5805,22 +5805,22 @@ WERROR _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, S * * So I add checks like in NT Server ... */ - + if (info_1->p_datatype != 0) { unistr2_to_ascii(datatype, &info_1->datatype, sizeof(datatype)); if (strcmp(datatype, "RAW") != 0) { (*jobid)=0; return WERR_INVALID_DATATYPE; - } - } - + } + } + /* get the share number of the printer */ if (!get_printer_snum(p, handle, &snum, NULL)) { return WERR_BADFID; } unistr2_to_ascii(jobname, &info_1->docname, sizeof(jobname)); - + Printer->jobid = print_job_start(&p->pipe_user, snum, jobname, Printer->nt_devmode); /* An error occured in print_job_start() so return an appropriate @@ -5829,7 +5829,7 @@ WERROR _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, S if (Printer->jobid == -1) { return map_werror_from_unix(errno); } - + Printer->document_started=True; (*jobid) = Printer->jobid; @@ -5860,7 +5860,7 @@ WERROR _spoolss_writeprinter(pipes_struct *p, SPOOL_Q_WRITEPRINTER *q_u, SPOOL_R uint32 *buffer_written = &q_u->buffer_size2; int snum; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); - + if (!Printer) { DEBUG(2,("_spoolss_writeprinter: Invalid handle (%s:%u:%u)\n",OUR_HANDLE(handle))); r_u->buffer_written = q_u->buffer_size2; @@ -5942,17 +5942,17 @@ WERROR _spoolss_abortprinter(pipes_struct *p, SPOOL_Q_ABORTPRINTER *q_u, SPOOL_R Printer_entry *Printer = find_printer_index_by_hnd(p, handle); int snum; WERROR errcode = WERR_OK; - + if (!Printer) { DEBUG(2,("_spoolss_abortprinter: Invalid handle (%s:%u:%u)\n",OUR_HANDLE(handle))); return WERR_BADFID; } - + if (!get_printer_snum(p, handle, &snum, NULL)) return WERR_BADFID; - - print_job_delete( &p->pipe_user, snum, Printer->jobid, &errcode ); - + + print_job_delete( &p->pipe_user, snum, Printer->jobid, &errcode ); + return errcode; } @@ -5978,7 +5978,7 @@ static WERROR update_printer_sec(POLICY_HND *handle, uint32 level, result = WERR_BADFID; goto done; } - + if (!secdesc_ctr) { DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n")); result = WERR_INVALID_PARAM; @@ -6006,7 +6006,7 @@ static WERROR update_printer_sec(POLICY_HND *handle, uint32 level, int i; the_acl = old_secdesc_ctr->sd->dacl; - DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n", + DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n", PRINTERNAME(snum), the_acl->num_aces)); for (i = 0; i < the_acl->num_aces; i++) { @@ -6014,22 +6014,22 @@ static WERROR update_printer_sec(POLICY_HND *handle, uint32 level, sid_to_string(sid_str, &the_acl->aces[i].trustee); - DEBUG(10, ("%s 0x%08x\n", sid_str, + DEBUG(10, ("%s 0x%08x\n", sid_str, the_acl->aces[i].access_mask)); } the_acl = secdesc_ctr->sd->dacl; if (the_acl) { - DEBUG(10, ("secdesc_ctr for %s has %d aces:\n", + DEBUG(10, ("secdesc_ctr for %s has %d aces:\n", PRINTERNAME(snum), the_acl->num_aces)); for (i = 0; i < the_acl->num_aces; i++) { fstring sid_str; - + sid_to_string(sid_str, &the_acl->aces[i].trustee); - - DEBUG(10, ("%s 0x%08x\n", sid_str, + + DEBUG(10, ("%s 0x%08x\n", sid_str, the_acl->aces[i].access_mask)); } } else { @@ -6058,9 +6058,9 @@ static WERROR update_printer_sec(POLICY_HND *handle, uint32 level, /******************************************************************** Canonicalize printer info from a client - ATTN: It does not matter what we set the servername to hear - since we do the necessary work in get_a_printer() to set it to - the correct value based on what the client sent in the + ATTN: It does not matter what we set the servername to hear + since we do the necessary work in get_a_printer() to set it to + the correct value based on what the client sent in the _spoolss_open_printer_ex(). ********************************************************************/ @@ -6068,16 +6068,16 @@ static bool check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) { fstring printername; const char *p; - + DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s " "portname=%s drivername=%s comment=%s location=%s\n", - info->servername, info->printername, info->sharename, + info->servername, info->printername, info->sharename, info->portname, info->drivername, info->comment, info->location)); /* we force some elements to "correct" values */ slprintf(info->servername, sizeof(info->servername)-1, "\\\\%s", global_myname()); fstrcpy(info->sharename, lp_servicename(snum)); - + /* check to see if we allow printername != sharename */ if ( lp_force_printername(snum) ) { @@ -6086,23 +6086,23 @@ static bool check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) } else { /* make sure printername is in \\server\printername format */ - + fstrcpy( printername, info->printername ); p = printername; if ( printername[0] == '\\' && printername[1] == '\\' ) { if ( (p = strchr_m( &printername[2], '\\' )) != NULL ) p++; } - + slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s", global_myname(), p ); } info->attributes |= PRINTER_ATTRIBUTE_SAMBA; info->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA; - - - + + + return True; } @@ -6121,7 +6121,7 @@ WERROR add_port_hook(NT_USER_TOKEN *token, const char *portname, const char *uri if ( !*cmd ) { return WERR_ACCESS_DENIED; } - + slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\"", cmd, portname, uri ); if ( token ) @@ -6133,7 +6133,7 @@ WERROR add_port_hook(NT_USER_TOKEN *token, const char *portname, const char *uri if ( is_print_op ) become_root(); - + ret = smbrun(command, &fd); if ( is_print_op ) @@ -6148,7 +6148,7 @@ WERROR add_port_hook(NT_USER_TOKEN *token, const char *portname, const char *uri close(fd); return WERR_ACCESS_DENIED; } - + return WERR_OK; } @@ -6170,7 +6170,7 @@ bool add_printer_hook(NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer) standard_sub_basic(current_user_info.smb_name, current_user_info.domain, remote_machine,sizeof(remote_machine)); - + slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"", cmd, printer->info_2->printername, printer->info_2->sharename, printer->info_2->portname, printer->info_2->drivername, @@ -6185,7 +6185,7 @@ bool add_printer_hook(NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer) if ( is_print_op ) become_root(); - + if ( (ret = smbrun(command, &fd)) == 0 ) { /* Tell everyone we updated smb.conf. */ message_send_all(smbd_messaging_context(), @@ -6296,7 +6296,7 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, goto done; } - /* FIXME!!! If the driver has changed we really should verify that + /* FIXME!!! If the driver has changed we really should verify that it is installed before doing much else --jerry */ /* Check calling user has permission to update printer description */ @@ -6309,8 +6309,8 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, /* Call addprinter hook */ /* Check changes to see if this is really needed */ - - if ( *lp_addprinter_cmd() + + if ( *lp_addprinter_cmd() && (!strequal(printer->info_2->drivername, old_printer->info_2->drivername) || !strequal(printer->info_2->comment, old_printer->info_2->comment) || !strequal(printer->info_2->portname, old_printer->info_2->portname) @@ -6323,7 +6323,7 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, goto done; } } - + /* * When a *new* driver is bound to a printer, the drivername is used to * lookup previously saved driver initialization info, which is then @@ -6331,21 +6331,21 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, */ if (!strequal(printer->info_2->drivername, old_printer->info_2->drivername)) { - if (!set_driver_init(printer, 2)) + if (!set_driver_init(printer, 2)) { DEBUG(5,("update_printer: Error restoring driver initialization data for driver [%s]!\n", printer->info_2->drivername)); } - + DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n", printer->info_2->drivername)); - + notify_printer_driver(snum, printer->info_2->drivername); } - /* - * flag which changes actually occured. This is a small subset of - * all the possible changes. We also have to update things in the + /* + * flag which changes actually occured. This is a small subset of + * all the possible changes. We also have to update things in the * DsSpooler key. */ @@ -6367,12 +6367,12 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, if (!strequal(printer->info_2->printername, old_printer->info_2->printername)) { char *pname; - + if ( (pname = strchr_m( printer->info_2->printername+2, '\\' )) != NULL ) pname++; else pname = printer->info_2->printername; - + init_unistr2( &buffer, pname, UNI_STR_TERMINATE); set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "printerName", @@ -6380,7 +6380,7 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, notify_printer_printername( snum, pname ); } - + if (!strequal(printer->info_2->portname, old_printer->info_2->portname)) { init_unistr2( &buffer, printer->info_2->portname, UNI_STR_TERMINATE); set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "portName", @@ -6396,10 +6396,10 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, notify_printer_location(snum, printer->info_2->location); } - + /* here we need to update some more DsSpooler keys */ /* uNCName, serverName, shortServerName */ - + init_unistr2( &buffer, global_myname(), UNI_STR_TERMINATE); set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "serverName", REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 ); @@ -6446,9 +6446,9 @@ static WERROR publish_or_unpublish_printer(pipes_struct *p, POLICY_HND *handle, if (!get_printer_snum(p, handle, &snum, NULL)) return WERR_BADFID; - + nt_printer_publish(Printer, snum, info7->action); - + return WERR_OK; #else return WERR_UNKNOWN_LEVEL; @@ -6468,19 +6468,19 @@ WERROR _spoolss_setprinter(pipes_struct *p, SPOOL_Q_SETPRINTER *q_u, SPOOL_R_SET WERROR result; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); - + if (!Printer) { DEBUG(2,("_spoolss_setprinter: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle))); return WERR_BADFID; } - /* check the level */ + /* check the level */ switch (level) { case 0: return control_printer(handle, command, p); case 2: result = update_printer(p, handle, level, info, devmode_ctr.devmode); - if (!W_ERROR_IS_OK(result)) + if (!W_ERROR_IS_OK(result)) return result; if (secdesc_ctr) result = update_printer_sec(handle, level, info, p, secdesc_ctr); @@ -6502,7 +6502,7 @@ WERROR _spoolss_fcpn(pipes_struct *p, SPOOL_Q_FCPN *q_u, SPOOL_R_FCPN *r_u) { POLICY_HND *handle = &q_u->handle; Printer_entry *Printer= find_printer_index_by_hnd(p, handle); - + if (!Printer) { DEBUG(2,("_spoolss_fcpn: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle))); return WERR_BADFID; @@ -6555,14 +6555,14 @@ WERROR _spoolss_addjob(pipes_struct *p, SPOOL_Q_ADDJOB *q_u, SPOOL_R_ADDJOB *r_u ****************************************************************************/ static void fill_job_info_1(JOB_INFO_1 *job_info, const print_queue_struct *queue, - int position, int snum, + int position, int snum, const NT_PRINTER_INFO_LEVEL *ntprinter) { struct tm *t; - + t=gmtime(&queue->time); - job_info->jobid=queue->job; + job_info->jobid=queue->job; init_unistr(&job_info->printername, lp_servicename(snum)); init_unistr(&job_info->machinename, ntprinter->info_2->servername); init_unistr(&job_info->username, queue->fs_user); @@ -6582,7 +6582,7 @@ static void fill_job_info_1(JOB_INFO_1 *job_info, const print_queue_struct *queu ****************************************************************************/ static bool fill_job_info_2(JOB_INFO_2 *job_info, const print_queue_struct *queue, - int position, int snum, + int position, int snum, const NT_PRINTER_INFO_LEVEL *ntprinter, DEVICEMODE *devmode) { @@ -6591,9 +6591,9 @@ static bool fill_job_info_2(JOB_INFO_2 *job_info, const print_queue_struct *queu t=gmtime(&queue->time); job_info->jobid=queue->job; - + init_unistr(&job_info->printername, ntprinter->info_2->printername); - + init_unistr(&job_info->machinename, ntprinter->info_2->servername); init_unistr(&job_info->username, queue->fs_user); init_unistr(&job_info->document, queue->fs_file); @@ -6603,7 +6603,7 @@ static bool fill_job_info_2(JOB_INFO_2 *job_info, const print_queue_struct *queu init_unistr(&job_info->parameters, ""); init_unistr(&job_info->drivername, ntprinter->info_2->drivername); init_unistr(&job_info->text_status, ""); - + /* and here the security descriptor */ job_info->status=nt_printj_status(queue->status); @@ -6634,17 +6634,17 @@ static WERROR enumjobs_level1(const print_queue_struct *queue, int snum, JOB_INFO_1 *info; int i; WERROR result = WERR_OK; - + info=SMB_MALLOC_ARRAY(JOB_INFO_1,*returned); if (info==NULL) { *returned=0; return WERR_NOMEM; } - + for (i=0; i<*returned; i++) fill_job_info_1( &info[i], &queue[i], i, snum, ntprinter ); - /* check the required size. */ + /* check the required size. */ for (i=0; i<*returned; i++) (*needed) += spoolss_size_job_info_1(&info[i]); @@ -6660,7 +6660,7 @@ static WERROR enumjobs_level1(const print_queue_struct *queue, int snum, /* fill the buffer with the structures */ for (i=0; i<*returned; i++) - smb_io_job_info_1("", buffer, &info[i], 0); + smb_io_job_info_1("", buffer, &info[i], 0); out: /* clear memory */ @@ -6685,20 +6685,20 @@ static WERROR enumjobs_level2(const print_queue_struct *queue, int snum, int i; WERROR result = WERR_OK; DEVICEMODE *devmode = NULL; - + if ( !(info = SMB_MALLOC_ARRAY(JOB_INFO_2,*returned)) ) { *returned=0; return WERR_NOMEM; } - + /* this should not be a failure condition if the devmode is NULL */ - + devmode = construct_dev_mode(lp_const_servicename(snum)); for (i=0; i<*returned; i++) fill_job_info_2(&(info[i]), &queue[i], i, snum, ntprinter, devmode); - /* check the required size. */ + /* check the required size. */ for (i=0; i<*returned; i++) (*needed) += spoolss_size_job_info_2(&info[i]); @@ -6714,7 +6714,7 @@ static WERROR enumjobs_level2(const print_queue_struct *queue, int snum, /* fill the buffer with the structures */ for (i=0; i<*returned; i++) - smb_io_job_info_2("", buffer, &info[i], 0); + smb_io_job_info_2("", buffer, &info[i], 0); out: free_devmode(devmode); @@ -6732,7 +6732,7 @@ out: ****************************************************************************/ WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJOBS *r_u) -{ +{ POLICY_HND *handle = &q_u->handle; uint32 level = q_u->level; RPC_BUFFER *buffer = NULL; @@ -6760,14 +6760,14 @@ WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO *returned=0; /* lookup the printer snum and tdb entry */ - + if (!get_printer_snum(p, handle, &snum, NULL)) return WERR_BADFID; wret = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum)); if ( !W_ERROR_IS_OK(wret) ) return wret; - + *returned = print_queue_status(snum, &queue, &prt_status); DEBUGADD(4,("count:[%d], status:[%d], [%s]\n", *returned, prt_status.status, prt_status.message)); @@ -6789,7 +6789,7 @@ WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO wret = WERR_UNKNOWN_LEVEL; break; } - + SAFE_FREE(queue); free_a_printer( &ntprinter, 2 ); return wret; @@ -6814,7 +6814,7 @@ WERROR _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u int snum; WERROR errcode = WERR_BADFUNC; - + if (!get_printer_snum(p, handle, &snum, NULL)) { return WERR_BADFID; } @@ -6833,7 +6833,7 @@ WERROR _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u case JOB_CONTROL_PAUSE: if (print_job_pause(&p->pipe_user, snum, jobid, &errcode)) { errcode = WERR_OK; - } + } break; case JOB_CONTROL_RESTART: case JOB_CONTROL_RESUME: @@ -6886,21 +6886,21 @@ static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture WERROR status; DEBUGADD(5,("\tdriver: [%s]\n", list[i])); ZERO_STRUCT(driver); - status = get_a_printer_driver(&driver, 3, list[i], + status = get_a_printer_driver(&driver, 3, list[i], architecture, version); if (!W_ERROR_IS_OK(status)) { SAFE_FREE(list); SAFE_FREE(driver_info_1); return status; } - fill_printer_driver_info_1(&driver_info_1[*returned+i], driver, servername, architecture ); + fill_printer_driver_info_1(&driver_info_1[*returned+i], driver, servername, architecture ); free_a_printer_driver(driver, 3); - } + } *returned+=ndrivers; SAFE_FREE(list); } - + /* check the required size. */ for (i=0; i<*returned; i++) { DEBUGADD(6,("adding driver [%d]'s size\n",i)); @@ -6913,7 +6913,7 @@ static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture } if (!rpcbuf_alloc_size(buffer, *needed)) { - result = WERR_NOMEM; + result = WERR_NOMEM; goto out; } @@ -6965,27 +6965,27 @@ static WERROR enumprinterdrivers_level2(fstring servername, fstring architecture return WERR_NOMEM; } } - + for (i=0; ibuffer; DEBUG(4,("_spoolss_enumprinterdrivers\n")); - + *needed = 0; *returned = 0; @@ -7165,9 +7165,9 @@ static void fill_form_1(FORM_1 *form, nt_forms_struct *list) form->left=list->left; form->top=list->top; form->right=list->right; - form->bottom=list->bottom; + form->bottom=list->bottom; } - + /**************************************************************************** ****************************************************************************/ @@ -7225,14 +7225,14 @@ WERROR _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMF DEBUGADD(6,("Filling form number [%d]\n",i)); fill_form_1(&forms_1[i], &builtinlist[i]); } - + SAFE_FREE(builtinlist); for (; i<*numofforms; i++) { DEBUGADD(6,("Filling form number [%d]\n",i)); fill_form_1(&forms_1[i], &list[i-numbuiltinforms]); } - + SAFE_FREE(list); /* check the required size. */ @@ -7245,14 +7245,14 @@ WERROR _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMF buffer_size += spoolss_size_form_1(&forms_1[i]); } - *needed=buffer_size; - + *needed=buffer_size; + if (*needed > offered) { SAFE_FREE(forms_1); *numofforms=0; return WERR_INSUFFICIENT_BUFFER; } - + if (!rpcbuf_alloc_size(buffer, buffer_size)){ SAFE_FREE(forms_1); *numofforms=0; @@ -7272,7 +7272,7 @@ WERROR _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMF SAFE_FREE(forms_1); return WERR_OK; - + default: SAFE_FREE(list); SAFE_FREE(builtinlist); @@ -7340,7 +7340,7 @@ WERROR _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * break; } } - + SAFE_FREE(list); if (i == numofforms) { return WERR_BADFID; @@ -7349,8 +7349,8 @@ WERROR _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * /* check the required size. */ *needed=spoolss_size_form_1(&form_1); - - if (*needed > offered) + + if (*needed > offered) return WERR_INSUFFICIENT_BUFFER; if (!rpcbuf_alloc_size(buffer, buffer_size)) @@ -7361,7 +7361,7 @@ WERROR _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM * smb_io_form_1("", buffer, &form_1, 0); return WERR_OK; - + default: SAFE_FREE(list); return WERR_UNKNOWN_LEVEL; @@ -7377,7 +7377,7 @@ static void fill_port_1(PORT_INFO_1 *port, const char *name) } /**************************************************************************** - TODO: This probably needs distinguish between TCP/IP and Local ports + TODO: This probably needs distinguish between TCP/IP and Local ports somehow. ****************************************************************************/ @@ -7387,7 +7387,7 @@ static void fill_port_2(PORT_INFO_2 *port, const char *name) init_unistr(&port->monitor_name, "Local Monitor"); init_unistr(&port->description, SPL_LOCAL_PORT ); port->port_type=PORT_TYPE_WRITE; - port->reserved=0x0; + port->reserved=0x0; } @@ -7408,7 +7408,7 @@ WERROR enumports_hook( int *count, char ***lines ) *lines = NULL; /* if no hook then just fill in the default port */ - + if ( !*cmd ) { if (!(qlines = SMB_MALLOC_ARRAY( char*, 2 ))) { return WERR_NOMEM; @@ -7422,7 +7422,7 @@ WERROR enumports_hook( int *count, char ***lines ) } else { /* we have a valid enumport command */ - + slprintf(command, sizeof(command)-1, "%s \"%d\"", cmd, 1); DEBUG(10,("Running [%s]\n", command)); @@ -7440,7 +7440,7 @@ WERROR enumports_hook( int *count, char ***lines ) DEBUGADD(10,("Lines returned = [%d]\n", numlines)); close(fd); } - + *count = numlines; *lines = qlines; @@ -7464,10 +7464,10 @@ static WERROR enumports_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *need file_lines_free(qlines); return result; } - + if(numlines) { if((ports=SMB_MALLOC_ARRAY( PORT_INFO_1, numlines )) == NULL) { - DEBUG(10,("Returning WERR_NOMEM [%s]\n", + DEBUG(10,("Returning WERR_NOMEM [%s]\n", dos_errstr(WERR_NOMEM))); file_lines_free(qlines); return WERR_NOMEM; @@ -7487,7 +7487,7 @@ static WERROR enumports_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *need DEBUGADD(6,("adding port [%d]'s size\n", i)); *needed += spoolss_size_port_info_1(&ports[i]); } - + if (*needed > offered) { result = WERR_INSUFFICIENT_BUFFER; goto out; @@ -7530,7 +7530,7 @@ static WERROR enumports_level_2(RPC_BUFFER *buffer, uint32 offered, uint32 *need file_lines_free(qlines); return result; } - + if(numlines) { if((ports=SMB_MALLOC_ARRAY( PORT_INFO_2, numlines)) == NULL) { file_lines_free(qlines); @@ -7552,7 +7552,7 @@ static WERROR enumports_level_2(RPC_BUFFER *buffer, uint32 offered, uint32 *need DEBUGADD(6,("adding port [%d]'s size\n", i)); *needed += spoolss_size_port_info_2(&ports[i]); } - + if (*needed > offered) { result = WERR_INSUFFICIENT_BUFFER; goto out; @@ -7600,10 +7600,10 @@ WERROR _spoolss_enumports( pipes_struct *p, SPOOL_Q_ENUMPORTS *q_u, SPOOL_R_ENUM buffer = r_u->buffer; DEBUG(4,("_spoolss_enumports\n")); - + *returned=0; *needed=0; - + switch (level) { case 1: return enumports_level_1(buffer, offered, needed, returned); @@ -7642,12 +7642,12 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ /* check to see if the printer already exists */ if ((snum = print_queue_snum(printer->info_2->sharename)) != -1) { - DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n", + DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n", printer->info_2->sharename)); free_a_printer(&printer, 2); return WERR_PRINTER_ALREADY_EXISTS; } - + /* FIXME!!! smbd should check to see if the driver is installed before trying to add a printer like this --jerry */ @@ -7663,13 +7663,13 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ printer->info_2->sharename )); } - /* use our primary netbios name since get_a_printer() will convert + /* use our primary netbios name since get_a_printer() will convert it to what the client expects on a case by case basis */ slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname(), printer->info_2->sharename); - + if ((snum = print_queue_snum(printer->info_2->sharename)) == -1) { free_a_printer(&printer,2); return WERR_ACCESS_DENIED; @@ -7678,9 +7678,9 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ /* you must be a printer admin to add a new printer */ if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) { free_a_printer(&printer,2); - return WERR_ACCESS_DENIED; + return WERR_ACCESS_DENIED; } - + /* * Do sanity check on the requested changes for Samba. */ @@ -7692,7 +7692,7 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ /* * When a printer is created, the drivername bound to the printer is used - * to lookup previously saved driver initialization info, which is then + * to lookup previously saved driver initialization info, which is then * bound to the new printer, simulating what happens in the Windows arch. */ @@ -7700,7 +7700,7 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ { set_driver_init(printer, 2); } - else + else { /* A valid devmode was included, convert and link it */ @@ -7793,13 +7793,13 @@ WERROR _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u, goto done; } - /* + /* * I think this is where he DrvUpgradePrinter() hook would be * be called in a driver's interface DLL on a Windows NT 4.0/2k * server. Right now, we just need to send ourselves a message - * to update each printer bound to this driver. --jerry + * to update each printer bound to this driver. --jerry */ - + if (!srv_spoolss_drv_upgrade_printer(driver_name)) { DEBUG(0,("_spoolss_addprinterdriver: Failed to send message about upgrading driver [%s]!\n", driver_name)); @@ -7825,11 +7825,11 @@ WERROR _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u, /* * 9x printer driver - never delete init data */ - case 0: + case 0: DEBUG(10,("_spoolss_addprinterdriver: init data not deleted for 9x driver [%s]\n", driver_name)); break; - + /* * Nt or 2k (compatiblity mode) printer driver - only delete init data if * there is no 2k/Xp driver init data for this driver name. @@ -7849,7 +7849,7 @@ WERROR _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u, * a 2k/Xp driver was found, don't delete init data because Nt driver will use it. */ free_a_printer_driver(driver1,3); - DEBUG(10,("_spoolss_addprinterdriver: init data not deleted for Nt driver [%s]\n", + DEBUG(10,("_spoolss_addprinterdriver: init data not deleted for Nt driver [%s]\n", driver_name)); } } @@ -7858,7 +7858,7 @@ WERROR _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u, /* * 2k or Xp printer driver - always delete init data */ - case 3: + case 3: if (!del_driver_init(driver_name)) DEBUG(6,("_spoolss_addprinterdriver: del_driver_init(%s) 2k/Xp failed!\n", driver_name)); break; @@ -7868,7 +7868,7 @@ WERROR _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u, break; } - + done: free_a_printer_driver(driver, level); return err; @@ -7882,15 +7882,15 @@ WERROR _spoolss_addprinterdriverex(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVEREX * { SPOOL_Q_ADDPRINTERDRIVER q_u_local; SPOOL_R_ADDPRINTERDRIVER r_u_local; - - /* + + /* * we only support the semantics of AddPrinterDriver() * i.e. only copy files that are newer than existing ones */ - + if ( q_u->copy_flags != APD_COPY_NEW_FILES ) return WERR_ACCESS_DENIED; - + ZERO_STRUCT(q_u_local); ZERO_STRUCT(r_u_local); @@ -7899,7 +7899,7 @@ WERROR _spoolss_addprinterdriverex(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVEREX * copy_unistr2(&q_u_local.server_name, &q_u->server_name); q_u_local.level = q_u->level; memcpy( &q_u_local.info, &q_u->info, sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL) ); - + return _spoolss_addprinterdriver( p, &q_u_local, &r_u_local ); } @@ -7919,7 +7919,7 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen pstring path; pstring long_archi; fstring servername; - char *pservername; + char *pservername; const char *short_archi; DRIVER_DIRECTORY_1 *info=NULL; WERROR result = WERR_OK; @@ -7933,8 +7933,8 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen pservername = servername; if ( *pservername == '\\' && strlen(servername)>2 ) { pservername += 2; - } - + } + if ( !is_myname_or_ipaddr( pservername ) ) return WERR_INVALID_PARAM; @@ -7949,7 +7949,7 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen DEBUG(4,("printer driver directory: [%s]\n", path)); fill_driverdir_1(info, path); - + *needed += spoolss_size_driverdir_info_1(info); if (*needed > offered) { @@ -7966,7 +7966,7 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen out: SAFE_FREE(info); - + return result; } @@ -8002,7 +8002,7 @@ WERROR _spoolss_getprinterdriverdirectory(pipes_struct *p, SPOOL_Q_GETPRINTERDRI return WERR_UNKNOWN_LEVEL; } } - + /**************************************************************************** ****************************************************************************/ @@ -8021,7 +8021,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S uint32 *out_data_len = &r_u->realdatasize; NT_PRINTER_INFO_LEVEL *printer = NULL; - + uint32 biggest_valuesize; uint32 biggest_datasize; uint32 data_len; @@ -8032,7 +8032,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S NT_PRINTER_DATA *p_data; int i, key_index, num_values; int name_length; - + *out_type = 0; *out_max_data_len = 0; @@ -8048,12 +8048,12 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S if (!get_printer_snum(p,handle, &snum, NULL)) return WERR_BADFID; - + result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(result)) return result; - - p_data = printer->info_2->data; + + p_data = printer->info_2->data; key_index = lookup_printerkey( p_data, SPOOL_PRINTERDATA_KEY ); result = WERR_OK; @@ -8063,34 +8063,34 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S * * cf: MSDN EnumPrinterData remark section */ - - if ( !in_value_len && !in_data_len && (key_index != -1) ) + + if ( !in_value_len && !in_data_len && (key_index != -1) ) { DEBUGADD(6,("Activating NT mega-hack to find sizes\n")); biggest_valuesize = 0; biggest_datasize = 0; - + num_values = regval_ctr_numvals( p_data->keys[key_index].values ); - + for ( i=0; ikeys[key_index].values, i ); - + name_length = strlen(val->valuename); - if ( strlen(val->valuename) > biggest_valuesize ) + if ( strlen(val->valuename) > biggest_valuesize ) biggest_valuesize = name_length; - + if ( val->size > biggest_datasize ) biggest_datasize = val->size; - - DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize, + + DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize, biggest_datasize)); } - /* the value is an UNICODE string but real_value_size is the length + /* the value is an UNICODE string but real_value_size is the length in bytes including the trailing 0 */ - + *out_value_len = 2 * (1+biggest_valuesize); *out_data_len = biggest_datasize; @@ -8098,23 +8098,23 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S goto done; } - + /* * the value len is wrong in NT sp3 * that's the number of bytes not the number of unicode chars */ - + if ( key_index != -1 ) val = regval_ctr_specific_value( p_data->keys[key_index].values, idx ); - if ( !val ) + if ( !val ) { /* out_value should default to "" or else NT4 has problems unmarshalling the response */ *out_max_value_len=(in_value_len/sizeof(uint16)); - + if (in_value_len) { if((*out_value=(uint16 *)TALLOC_ZERO(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL) { @@ -8128,12 +8128,12 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S } /* the data is counted in bytes */ - + *out_max_data_len = in_data_len; *out_data_len = in_data_len; - + /* only allocate when given a non-zero data_len */ - + if ( in_data_len && ((*data_out=(uint8 *)TALLOC_ZERO(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) ) { result = WERR_NOMEM; @@ -8142,7 +8142,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S result = WERR_NO_MORE_ITEMS; } - else + else { /* * the value is: @@ -8152,16 +8152,16 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S * * take a pause *before* coding not *during* coding */ - + /* name */ *out_max_value_len=(in_value_len/sizeof(uint16)); if (in_value_len) { - if ( (*out_value = (uint16 *)TALLOC_ZERO(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL ) + if ( (*out_value = (uint16 *)TALLOC_ZERO(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL ) { result = WERR_NOMEM; goto done; } - + *out_value_len = (uint32)rpcstr_push((char *)*out_value, regval_name(val), (size_t)in_value_len, 0); } else { *out_value = NULL; @@ -8169,13 +8169,13 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S } /* type */ - + *out_type = regval_type( val ); /* data - counted in bytes */ *out_max_data_len = in_data_len; - if ( in_data_len && (*data_out = (uint8 *)TALLOC_ZERO(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) + if ( in_data_len && (*data_out = (uint8 *)TALLOC_ZERO(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) { result = WERR_NOMEM; goto done; @@ -8207,7 +8207,7 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP WERROR status = WERR_OK; Printer_entry *Printer=find_printer_index_by_hnd(p, handle); fstring valuename; - + DEBUG(5,("spoolss_setprinterdata\n")); if (!Printer) { @@ -8223,15 +8223,15 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP if (!get_printer_snum(p,handle, &snum, NULL)) return WERR_BADFID; - /* - * Access check : NT returns "access denied" if you make a + /* + * Access check : NT returns "access denied" if you make a * SetPrinterData call without the necessary privildge. * we were originally returning OK if nothing changed * which made Win2k issue **a lot** of SetPrinterData * when connecting to a printer --jerry */ - if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) + if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) { DEBUG(3, ("_spoolss_setprinterdata: change denied by handle access permissions\n")); status = WERR_ACCESS_DENIED; @@ -8243,22 +8243,22 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP return status; unistr2_to_ascii(valuename, value, sizeof(valuename)); - + /* * When client side code sets a magic printer data key, detect it and save * the current printer data and the magic key's data (its the DEVMODE) for * future printer/driver initializations. */ - if ( (type == REG_BINARY) && strequal( valuename, PHANTOM_DEVMODE_KEY)) + if ( (type == REG_BINARY) && strequal( valuename, PHANTOM_DEVMODE_KEY)) { /* Set devmode and printer initialization info */ status = save_driver_init( printer, 2, data, real_len ); - + srv_spoolss_reset_printerdata( printer->info_2->drivername ); } - else + else { - status = set_printer_dataex( printer, SPOOL_PRINTERDATA_KEY, valuename, + status = set_printer_dataex( printer, SPOOL_PRINTERDATA_KEY, valuename, type, data, real_len ); if ( W_ERROR_IS_OK(status) ) status = mod_a_printer(printer, 2); @@ -8278,7 +8278,7 @@ WERROR _spoolss_resetprinter(pipes_struct *p, SPOOL_Q_RESETPRINTER *q_u, SPOOL_R POLICY_HND *handle = &q_u->handle; Printer_entry *Printer=find_printer_index_by_hnd(p, handle); int snum; - + DEBUG(5,("_spoolss_resetprinter\n")); /* @@ -8286,7 +8286,7 @@ WERROR _spoolss_resetprinter(pipes_struct *p, SPOOL_Q_RESETPRINTER *q_u, SPOOL_R * This call really doesn't mean anything to us because we only * support RAW printing. --jerry */ - + if (!Printer) { DEBUG(2,("_spoolss_resetprinter: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); return WERR_BADFID; @@ -8296,7 +8296,7 @@ WERROR _spoolss_resetprinter(pipes_struct *p, SPOOL_Q_RESETPRINTER *q_u, SPOOL_R return WERR_BADFID; - /* blindly return success */ + /* blindly return success */ return WERR_OK; } @@ -8314,9 +8314,9 @@ WERROR _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_ WERROR status = WERR_OK; Printer_entry *Printer=find_printer_index_by_hnd(p, handle); pstring valuename; - + DEBUG(5,("spoolss_deleteprinterdata\n")); - + if (!Printer) { DEBUG(2,("_spoolss_deleteprinterdata: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); return WERR_BADFID; @@ -8337,7 +8337,7 @@ WERROR _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_ unistr2_to_ascii(valuename, value, sizeof(valuename)); status = delete_printer_dataex( printer, SPOOL_PRINTERDATA_KEY, valuename ); - + if ( W_ERROR_IS_OK(status) ) mod_a_printer( printer, 2 ); @@ -8368,15 +8368,15 @@ WERROR _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM DEBUG(2,("_spoolss_addform: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); return WERR_BADFID; } - - + + /* forms can be added on printer of on the print server handle */ - + if ( Printer->printer_type == SPLHND_PRINTER ) { if (!get_printer_snum(p,handle, &snum, NULL)) return WERR_BADFID; - + status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(status)) goto done; @@ -8387,30 +8387,30 @@ WERROR _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM status = WERR_ACCESS_DENIED; goto done; } - + /* can't add if builtin */ - + if (get_a_builtin_ntform(&form->name,&tmpForm)) { status = WERR_ALREADY_EXISTS; goto done; } count = get_ntforms(&list); - + if(!add_a_form(&list, form, &count)) { status = WERR_NOMEM; goto done; } - + write_ntforms(&list, count); - + /* * ChangeID must always be set if this is a printer */ - + if ( Printer->printer_type == SPLHND_PRINTER ) status = mod_a_printer(printer, 2); - + done: if ( printer ) free_a_printer(&printer, 2); @@ -8442,12 +8442,12 @@ WERROR _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE } /* forms can be deleted on printer of on the print server handle */ - + if ( Printer->printer_type == SPLHND_PRINTER ) { if (!get_printer_snum(p,handle, &snum, NULL)) return WERR_BADFID; - + status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(status)) goto done; @@ -8460,24 +8460,24 @@ WERROR _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE } /* can't delete if builtin */ - + if (get_a_builtin_ntform(form_name,&tmpForm)) { status = WERR_INVALID_PARAM; goto done; } count = get_ntforms(&list); - + if ( !delete_a_form(&list, form_name, &count, &status )) goto done; /* * ChangeID must always be set if this is a printer */ - + if ( Printer->printer_type == SPLHND_PRINTER ) status = mod_a_printer(printer, 2); - + done: if ( printer ) free_a_printer(&printer, 2); @@ -8510,12 +8510,12 @@ WERROR _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM * } /* forms can be modified on printer of on the print server handle */ - + if ( Printer->printer_type == SPLHND_PRINTER ) { if (!get_printer_snum(p,handle, &snum, NULL)) return WERR_BADFID; - + status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(status)) goto done; @@ -8540,11 +8540,11 @@ WERROR _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM * /* * ChangeID must always be set if this is a printer */ - + if ( Printer->printer_type == SPLHND_PRINTER ) status = mod_a_printer(printer, 2); - - + + done: if ( printer ) free_a_printer(&printer, 2); @@ -8561,12 +8561,12 @@ static WERROR enumprintprocessors_level_1(RPC_BUFFER *buffer, uint32 offered, ui { PRINTPROCESSOR_1 *info_1=NULL; WERROR result = WERR_OK; - + if((info_1 = SMB_MALLOC_P(PRINTPROCESSOR_1)) == NULL) return WERR_NOMEM; (*returned) = 0x1; - + init_unistr(&info_1->name, "winprint"); *needed += spoolss_size_printprocessor_info_1(info_1); @@ -8620,10 +8620,10 @@ WERROR _spoolss_enumprintprocessors(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCESSORS * Just reply with "winprint", to keep NT happy * and I can use my nice printer checker. */ - + *returned=0; *needed=0; - + switch (level) { case 1: return enumprintprocessors_level_1(buffer, offered, needed, returned); @@ -8640,12 +8640,12 @@ static WERROR enumprintprocdatatypes_level_1(RPC_BUFFER *buffer, uint32 offered, { PRINTPROCDATATYPE_1 *info_1=NULL; WERROR result = WERR_OK; - + if((info_1 = SMB_MALLOC_P(PRINTPROCDATATYPE_1)) == NULL) return WERR_NOMEM; (*returned) = 0x1; - + init_unistr(&info_1->name, "RAW"); *needed += spoolss_size_printprocdatatype_info_1(info_1); @@ -8692,10 +8692,10 @@ WERROR _spoolss_enumprintprocdatatypes(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCDAT buffer = r_u->buffer; DEBUG(5,("_spoolss_enumprintprocdatatypes\n")); - + *returned=0; *needed=0; - + switch (level) { case 1: return enumprintprocdatatypes_level_1(buffer, offered, needed, returned); @@ -8713,19 +8713,19 @@ static WERROR enumprintmonitors_level_1(RPC_BUFFER *buffer, uint32 offered, uint PRINTMONITOR_1 *info_1; WERROR result = WERR_OK; int i; - + if((info_1 = SMB_MALLOC_ARRAY(PRINTMONITOR_1, 2)) == NULL) return WERR_NOMEM; *returned = 2; - - init_unistr(&(info_1[0].name), SPL_LOCAL_PORT ); + + init_unistr(&(info_1[0].name), SPL_LOCAL_PORT ); init_unistr(&(info_1[1].name), SPL_TCPIP_PORT ); for ( i=0; i<*returned; i++ ) { *needed += spoolss_size_printmonitor_info_1(&info_1[i]); } - + if (*needed > offered) { result = WERR_INSUFFICIENT_BUFFER; goto out; @@ -8758,16 +8758,16 @@ static WERROR enumprintmonitors_level_2(RPC_BUFFER *buffer, uint32 offered, uint PRINTMONITOR_2 *info_2; WERROR result = WERR_OK; int i; - + if((info_2 = SMB_MALLOC_ARRAY(PRINTMONITOR_2, 2)) == NULL) return WERR_NOMEM; *returned = 2; - + init_unistr( &(info_2[0].name), SPL_LOCAL_PORT ); init_unistr( &(info_2[0].environment), "Windows NT X86" ); init_unistr( &(info_2[0].dll_name), "localmon.dll" ); - + init_unistr( &(info_2[1].name), SPL_TCPIP_PORT ); init_unistr( &(info_2[1].environment), "Windows NT X86" ); init_unistr( &(info_2[1].dll_name), "tcpmon.dll" ); @@ -8775,7 +8775,7 @@ static WERROR enumprintmonitors_level_2(RPC_BUFFER *buffer, uint32 offered, uint for ( i=0; i<*returned; i++ ) { *needed += spoolss_size_printmonitor_info_2(&info_2[i]); } - + if (*needed > offered) { result = WERR_INSUFFICIENT_BUFFER; goto out; @@ -8795,7 +8795,7 @@ out: if ( !W_ERROR_IS_OK(result) ) *returned = 0; - + return result; } @@ -8827,10 +8827,10 @@ WERROR _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS *q_ * Just reply with "Local Port", to keep NT happy * and I can use my nice printer checker. */ - + *returned=0; *needed=0; - + switch (level) { case 1: return enumprintmonitors_level_1(buffer, offered, needed, returned); @@ -8846,7 +8846,7 @@ WERROR _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS *q_ static WERROR getjob_level_1(print_queue_struct **queue, int count, int snum, NT_PRINTER_INFO_LEVEL *ntprinter, - uint32 jobid, RPC_BUFFER *buffer, uint32 offered, + uint32 jobid, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { int i=0; @@ -8859,20 +8859,20 @@ static WERROR getjob_level_1(print_queue_struct **queue, int count, int snum, if (info_1 == NULL) { return WERR_NOMEM; } - - for (i=0; i offered) { @@ -8896,9 +8896,9 @@ out: /**************************************************************************** ****************************************************************************/ -static WERROR getjob_level_2(print_queue_struct **queue, int count, int snum, +static WERROR getjob_level_2(print_queue_struct **queue, int count, int snum, NT_PRINTER_INFO_LEVEL *ntprinter, - uint32 jobid, RPC_BUFFER *buffer, uint32 offered, + uint32 jobid, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { int i = 0; @@ -8913,25 +8913,25 @@ static WERROR getjob_level_2(print_queue_struct **queue, int count, int snum, ZERO_STRUCTP(info_2); - for ( i=0; i offered) { @@ -8958,7 +8958,7 @@ static WERROR getjob_level_2(print_queue_struct **queue, int count, int snum, smb_io_job_info_2("", buffer, info_2, 0); result = WERR_OK; - + done: /* Cleanup allocated memory */ @@ -8996,44 +8996,44 @@ WERROR _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_ buffer = r_u->buffer; DEBUG(5,("spoolss_getjob\n")); - + *needed = 0; - + if (!get_printer_snum(p, handle, &snum, NULL)) return WERR_BADFID; - + wstatus = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum)); if ( !W_ERROR_IS_OK(wstatus) ) return wstatus; - + count = print_queue_status(snum, &queue, &prt_status); - + DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n", count, prt_status.status, prt_status.message)); - + switch ( level ) { case 1: - wstatus = getjob_level_1(&queue, count, snum, ntprinter, jobid, + wstatus = getjob_level_1(&queue, count, snum, ntprinter, jobid, buffer, offered, needed); break; case 2: - wstatus = getjob_level_2(&queue, count, snum, ntprinter, jobid, + wstatus = getjob_level_2(&queue, count, snum, ntprinter, jobid, buffer, offered, needed); break; default: wstatus = WERR_UNKNOWN_LEVEL; break; } - + SAFE_FREE(queue); free_a_printer( &ntprinter, 2 ); - + return wstatus; } /******************************************************************** spoolss_getprinterdataex - + From MSDN documentation of GetPrinterDataEx: pass request to GetPrinterData if key is "PrinterDriverData". ********************************************************************/ @@ -9047,9 +9047,9 @@ WERROR _spoolss_getprinterdataex(pipes_struct *p, SPOOL_Q_GETPRINTERDATAEX *q_u, uint8 **data = &r_u->data; uint32 *needed = &r_u->needed; fstring keyname, valuename; - + Printer_entry *Printer = find_printer_index_by_hnd(p, handle); - + NT_PRINTER_INFO_LEVEL *printer = NULL; int snum = 0; WERROR status = WERR_OK; @@ -9058,12 +9058,12 @@ WERROR _spoolss_getprinterdataex(pipes_struct *p, SPOOL_Q_GETPRINTERDATAEX *q_u, unistr2_to_ascii(keyname, &q_u->keyname, sizeof(keyname)); unistr2_to_ascii(valuename, &q_u->valuename, sizeof(valuename)); - - DEBUG(10, ("_spoolss_getprinterdataex: key => [%s], value => [%s]\n", + + DEBUG(10, ("_spoolss_getprinterdataex: key => [%s], value => [%s]\n", keyname, valuename)); /* in case of problem, return some default values */ - + *needed = 0; *type = 0; *out_size = in_size; @@ -9081,7 +9081,7 @@ WERROR _spoolss_getprinterdataex(pipes_struct *p, SPOOL_Q_GETPRINTERDATAEX *q_u, status = WERR_INVALID_PARAM; goto done; } - + if ( !get_printer_snum(p,handle, &snum, NULL) ) return WERR_BADFID; @@ -9094,29 +9094,29 @@ WERROR _spoolss_getprinterdataex(pipes_struct *p, SPOOL_Q_GETPRINTERDATAEX *q_u, status = WERR_INVALID_PARAM; goto done; } - + if ( lookup_printerkey( printer->info_2->data, keyname ) == -1 ) { DEBUG(4,("_spoolss_getprinterdataex: Invalid keyname [%s]\n", keyname )); free_a_printer( &printer, 2 ); status = WERR_BADFILE; goto done; } - + /* When given a new keyname, we should just create it */ status = get_printer_dataex( p->mem_ctx, printer, keyname, valuename, type, data, needed, in_size ); - + if (*needed > *out_size) status = WERR_MORE_DATA; done: - if ( !W_ERROR_IS_OK(status) ) + if ( !W_ERROR_IS_OK(status) ) { DEBUG(5, ("error: allocating %d\n", *out_size)); - + /* reply this param doesn't exist */ - - if ( *out_size ) + + if ( *out_size ) { if( (*data=(uint8 *)TALLOC_ZERO(p->mem_ctx, *out_size*sizeof(uint8))) == NULL ) { status = WERR_NOMEM; @@ -9126,10 +9126,10 @@ done: *data = NULL; } } - + if ( printer ) free_a_printer( &printer, 2 ); - + return status; } @@ -9139,7 +9139,7 @@ done: WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, SPOOL_R_SETPRINTERDATAEX *r_u) { - POLICY_HND *handle = &q_u->handle; + POLICY_HND *handle = &q_u->handle; uint32 type = q_u->type; uint8 *data = q_u->data; uint32 real_len = q_u->real_len; @@ -9151,7 +9151,7 @@ WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, fstring valuename; fstring keyname; char *oid_string; - + DEBUG(4,("_spoolss_setprinterdataex\n")); /* From MSDN documentation of SetPrinterDataEx: pass request to @@ -9170,15 +9170,15 @@ WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, if ( !get_printer_snum(p,handle, &snum, NULL) ) return WERR_BADFID; - /* - * Access check : NT returns "access denied" if you make a + /* + * Access check : NT returns "access denied" if you make a * SetPrinterData call without the necessary privildge. * we were originally returning OK if nothing changed * which made Win2k issue **a lot** of SetPrinterData * when connecting to a printer --jerry */ - if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) + if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) { DEBUG(3, ("_spoolss_setprinterdataex: change denied by handle access permissions\n")); return WERR_ACCESS_DENIED; @@ -9190,9 +9190,9 @@ WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, unistr2_to_ascii( valuename, &q_u->value, sizeof(valuename)); unistr2_to_ascii( keyname, &q_u->key, sizeof(keyname)); - + /* check for OID in valuename */ - + if ( (oid_string = strchr( valuename, ',' )) != NULL ) { *oid_string = '\0'; @@ -9200,31 +9200,31 @@ WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, } /* save the registry data */ - - status = set_printer_dataex( printer, keyname, valuename, type, data, real_len ); - + + status = set_printer_dataex( printer, keyname, valuename, type, data, real_len ); + if ( W_ERROR_IS_OK(status) ) { /* save the OID if one was specified */ if ( oid_string ) { fstrcat( keyname, "\\" ); fstrcat( keyname, SPOOL_OID_KEY ); - - /* - * I'm not checking the status here on purpose. Don't know - * if this is right, but I'm returning the status from the - * previous set_printer_dataex() call. I have no idea if + + /* + * I'm not checking the status here on purpose. Don't know + * if this is right, but I'm returning the status from the + * previous set_printer_dataex() call. I have no idea if * this is right. --jerry */ - - set_printer_dataex( printer, keyname, valuename, + + set_printer_dataex( printer, keyname, valuename, REG_SZ, (uint8 *)oid_string, strlen(oid_string)+1 ); } - + status = mod_a_printer(printer, 2); } - + free_a_printer(&printer, 2); return status; @@ -9246,9 +9246,9 @@ WERROR _spoolss_deleteprinterdataex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATAEX WERROR status = WERR_OK; Printer_entry *Printer=find_printer_index_by_hnd(p, handle); pstring valuename, keyname; - + DEBUG(5,("spoolss_deleteprinterdataex\n")); - + if (!Printer) { DEBUG(2,("_spoolss_deleteprinterdata: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); return WERR_BADFID; @@ -9273,7 +9273,7 @@ WERROR _spoolss_deleteprinterdataex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATAEX if ( W_ERROR_IS_OK(status) ) mod_a_printer( printer, 2 ); - + free_a_printer(&printer, 2); return status; @@ -9297,8 +9297,8 @@ WERROR _spoolss_enumprinterkey(pipes_struct *p, SPOOL_Q_ENUMPRINTERKEY *q_u, SPO NT_PRINTER_INFO_LEVEL *printer = NULL; int snum = 0; WERROR status = WERR_BADFILE; - - + + DEBUG(4,("_spoolss_enumprinterkey\n")); if (!Printer) { @@ -9312,9 +9312,9 @@ WERROR _spoolss_enumprinterkey(pipes_struct *p, SPOOL_Q_ENUMPRINTERKEY *q_u, SPO status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(status)) return status; - + /* get the list of subkey names */ - + unistr2_to_ascii(key, &q_u->key, sizeof(key)); data = printer->info_2->data; @@ -9338,16 +9338,16 @@ WERROR _spoolss_enumprinterkey(pipes_struct *p, SPOOL_Q_ENUMPRINTERKEY *q_u, SPO status = WERR_NOMEM; goto done; } - + status = WERR_OK; - if ( q_u->size < r_u->needed ) + if ( q_u->size < r_u->needed ) status = WERR_MORE_DATA; done: free_a_printer( &printer, 2 ); SAFE_FREE( keynames ); - + return status; } @@ -9363,19 +9363,19 @@ WERROR _spoolss_deleteprinterkey(pipes_struct *p, SPOOL_Q_DELETEPRINTERKEY *q_u, NT_PRINTER_INFO_LEVEL *printer = NULL; int snum=0; WERROR status; - + DEBUG(5,("spoolss_deleteprinterkey\n")); - + if (!Printer) { DEBUG(2,("_spoolss_deleteprinterkey: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle))); return WERR_BADFID; } /* if keyname == NULL, return error */ - + if ( !q_u->keyname.buffer ) return WERR_INVALID_PARAM; - + if (!get_printer_snum(p, handle, &snum, NULL)) return WERR_BADFID; @@ -9387,18 +9387,18 @@ WERROR _spoolss_deleteprinterkey(pipes_struct *p, SPOOL_Q_DELETEPRINTERKEY *q_u, status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(status)) return status; - + /* delete the key and all subneys */ - + unistr2_to_ascii(key, &q_u->keyname, sizeof(key)); - - status = delete_all_printer_data( printer->info_2, key ); + + status = delete_all_printer_data( printer->info_2, key ); if ( W_ERROR_IS_OK(status) ) status = mod_a_printer(printer, 2); - + free_a_printer( &printer, 2 ); - + return status; } @@ -9409,9 +9409,9 @@ WERROR _spoolss_deleteprinterkey(pipes_struct *p, SPOOL_Q_DELETEPRINTERKEY *q_u, WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_u, SPOOL_R_ENUMPRINTERDATAEX *r_u) { - POLICY_HND *handle = &q_u->handle; + POLICY_HND *handle = &q_u->handle; uint32 in_size = q_u->size; - uint32 num_entries, + uint32 num_entries, needed; NT_PRINTER_INFO_LEVEL *printer = NULL; PRINTER_ENUM_VALUES *enum_values = NULL; @@ -9425,7 +9425,7 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ REGISTRY_VALUE *val; char *value_name; uint32 data_len; - + DEBUG(4,("_spoolss_enumprinterdataex\n")); @@ -9434,13 +9434,13 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ return WERR_BADFID; } - /* - * first check for a keyname of NULL or "". Win2k seems to send + /* + * first check for a keyname of NULL or "". Win2k seems to send * this a lot and we should send back WERR_INVALID_PARAM * no need to spend time looking up the printer in this case. * --jerry */ - + unistr2_to_ascii(key, &q_u->key, sizeof(key)); if ( !strlen(key) ) { result = WERR_INVALID_PARAM; @@ -9448,19 +9448,19 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ } /* get the printer off of disk */ - + if (!get_printer_snum(p,handle, &snum, NULL)) return WERR_BADFID; - + ZERO_STRUCT(printer); result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(result)) return result; - + /* now look for a match on the key name */ - + p_data = printer->info_2->data; - + unistr2_to_ascii(key, &q_u->key, sizeof(key)); if ( (key_index = lookup_printerkey( p_data, key)) == -1 ) { @@ -9468,12 +9468,12 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ result = WERR_INVALID_PARAM; goto done; } - + result = WERR_OK; needed = 0; - + /* allocate the memory for the array of pointers -- if necessary */ - + num_entries = regval_ctr_numvals( p_data->keys[key_index].values ); if ( num_entries ) { @@ -9487,31 +9487,31 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ memset( enum_values, 0x0, num_entries*sizeof(PRINTER_ENUM_VALUES) ); } - - /* - * loop through all params and build the array to pass - * back to the client + + /* + * loop through all params and build the array to pass + * back to the client */ - + for ( i=0; ikeys[key_index].values, i ); DEBUG(10,("retrieved value number [%d] [%s]\n", i, regval_name(val) )); /* copy the data */ - + value_name = regval_name( val ); init_unistr( &enum_values[i].valuename, value_name ); enum_values[i].value_len = (strlen(value_name)+1) * 2; enum_values[i].type = regval_type( val ); - + data_len = regval_size( val ); if ( data_len ) { - if ( !(enum_values[i].data = (uint8 *)TALLOC_MEMDUP(p->mem_ctx, regval_data_p(val), data_len)) ) + if ( !(enum_values[i].data = (uint8 *)TALLOC_MEMDUP(p->mem_ctx, regval_data_p(val), data_len)) ) { - DEBUG(0,("TALLOC_MEMDUP failed to allocate memory [data_len=%d] for data!\n", + DEBUG(0,("TALLOC_MEMDUP failed to allocate memory [data_len=%d] for data!\n", data_len )); result = WERR_NOMEM; goto done; @@ -9520,12 +9520,12 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ enum_values[i].data_len = data_len; /* keep track of the size of the array in bytes */ - + needed += spoolss_size_printer_enum_values(&enum_values[i]); } - + /* housekeeping information in the reply */ - + /* Fix from Martin Zielinski - ensure * the hand marshalled container size is a multiple * of 4 bytes for RPC alignment. @@ -9542,17 +9542,17 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ result = WERR_MORE_DATA; goto done; } - + /* copy data into the reply */ - + r_u->ctr.size = r_u->needed; r_u->ctr.size_of_array = r_u->returned; r_u->ctr.values = enum_values; - - - -done: + + + +done: if ( printer ) free_a_printer(&printer, 2); @@ -9567,10 +9567,10 @@ static void fill_printprocessordirectory_1(PRINTPROCESSOR_DIRECTORY_1 *info, cha init_unistr(&info->name, name); } -static WERROR getprintprocessordirectory_level_1(UNISTR2 *name, - UNISTR2 *environment, - RPC_BUFFER *buffer, - uint32 offered, +static WERROR getprintprocessordirectory_level_1(UNISTR2 *name, + UNISTR2 *environment, + RPC_BUFFER *buffer, + uint32 offered, uint32 *needed) { pstring path; @@ -9589,7 +9589,7 @@ static WERROR getprintprocessordirectory_level_1(UNISTR2 *name, pstrcpy(path, "C:\\WINNT\\System32\\spool\\PRTPROCS\\W32X86"); fill_printprocessordirectory_1(info, path); - + *needed += spoolss_size_printprocessordirectory_info_1(info); if (*needed > offered) { @@ -9606,7 +9606,7 @@ static WERROR getprintprocessordirectory_level_1(UNISTR2 *name, out: SAFE_FREE(info); - + return result; } @@ -9628,7 +9628,7 @@ WERROR _spoolss_getprintprocessordirectory(pipes_struct *p, SPOOL_Q_GETPRINTPROC buffer = r_u->buffer; DEBUG(5,("_spoolss_getprintprocessordirectory\n")); - + *needed=0; switch(level) { @@ -9647,21 +9647,21 @@ WERROR _spoolss_getprintprocessordirectory(pipes_struct *p, SPOOL_Q_GETPRINTPROC Streams the monitor UI DLL name in UNICODE *******************************************************************/ -static WERROR xcvtcp_monitorui( NT_USER_TOKEN *token, RPC_BUFFER *in, +static WERROR xcvtcp_monitorui( NT_USER_TOKEN *token, RPC_BUFFER *in, RPC_BUFFER *out, uint32 *needed ) { const char *dllname = "tcpmonui.dll"; - + *needed = (strlen(dllname)+1) * 2; - + if ( rpcbuf_get_size(out) < *needed ) { - return WERR_INSUFFICIENT_BUFFER; + return WERR_INSUFFICIENT_BUFFER; } - + if ( !make_monitorui_buf( out, dllname ) ) { return WERR_NOMEM; } - + return WERR_OK; } @@ -9669,7 +9669,7 @@ static WERROR xcvtcp_monitorui( NT_USER_TOKEN *token, RPC_BUFFER *in, Create a new TCP/IP port *******************************************************************/ -static WERROR xcvtcp_addport( NT_USER_TOKEN *token, RPC_BUFFER *in, +static WERROR xcvtcp_addport( NT_USER_TOKEN *token, RPC_BUFFER *in, RPC_BUFFER *out, uint32 *needed ) { NT_PORT_DATA_1 port1; @@ -9693,7 +9693,7 @@ static WERROR xcvtcp_addport( NT_USER_TOKEN *token, RPC_BUFFER *in, case PORT_PROTOCOL_LPR: pstr_sprintf( device_uri, "lpr://%s/%s", port1.hostaddr, port1.queue ); break; - + default: return WERR_UNKNOWN_PORT; } @@ -9710,19 +9710,19 @@ struct xcv_api_table xcvtcp_cmds[] = { { NULL, NULL } }; -static WERROR process_xcvtcp_command( NT_USER_TOKEN *token, const char *command, - RPC_BUFFER *inbuf, RPC_BUFFER *outbuf, +static WERROR process_xcvtcp_command( NT_USER_TOKEN *token, const char *command, + RPC_BUFFER *inbuf, RPC_BUFFER *outbuf, uint32 *needed ) { int i; - + DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command)); - + for ( i=0; xcvtcp_cmds[i].name; i++ ) { if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 ) return xcvtcp_cmds[i].fn( token, inbuf, outbuf, needed ); } - + return WERR_BADFUNC; } @@ -9730,21 +9730,21 @@ static WERROR process_xcvtcp_command( NT_USER_TOKEN *token, const char *command, *******************************************************************/ #if 0 /* don't support management using the "Local Port" monitor */ -static WERROR xcvlocal_monitorui( NT_USER_TOKEN *token, RPC_BUFFER *in, +static WERROR xcvlocal_monitorui( NT_USER_TOKEN *token, RPC_BUFFER *in, RPC_BUFFER *out, uint32 *needed ) { const char *dllname = "localui.dll"; - + *needed = (strlen(dllname)+1) * 2; - + if ( rpcbuf_get_size(out) < *needed ) { - return WERR_INSUFFICIENT_BUFFER; + return WERR_INSUFFICIENT_BUFFER; } - + if ( !make_monitorui_buf( out, dllname )) { return WERR_NOMEM; } - + return WERR_OK; } @@ -9766,12 +9766,12 @@ struct xcv_api_table xcvlocal_cmds[] = { /******************************************************************* *******************************************************************/ -static WERROR process_xcvlocal_command( NT_USER_TOKEN *token, const char *command, - RPC_BUFFER *inbuf, RPC_BUFFER *outbuf, +static WERROR process_xcvlocal_command( NT_USER_TOKEN *token, const char *command, + RPC_BUFFER *inbuf, RPC_BUFFER *outbuf, uint32 *needed ) { int i; - + DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command)); for ( i=0; xcvlocal_cmds[i].name; i++ ) { @@ -9785,7 +9785,7 @@ static WERROR process_xcvlocal_command( NT_USER_TOKEN *token, const char *comman *******************************************************************/ WERROR _spoolss_xcvdataport(pipes_struct *p, SPOOL_Q_XCVDATAPORT *q_u, SPOOL_R_XCVDATAPORT *r_u) -{ +{ Printer_entry *Printer = find_printer_index_by_hnd(p, &q_u->handle); fstring command; @@ -9795,39 +9795,37 @@ WERROR _spoolss_xcvdataport(pipes_struct *p, SPOOL_Q_XCVDATAPORT *q_u, SPOOL_R_X } /* Has to be a handle to the TCP/IP port monitor */ - + if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) { DEBUG(2,("_spoolss_xcvdataport: Call only valid for Port Monitors\n")); return WERR_BADFID; } - + /* requires administrative access to the server */ - + if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) { DEBUG(2,("_spoolss_xcvdataport: denied by handle permissions.\n")); return WERR_ACCESS_DENIED; } - /* Get the command name. There's numerous commands supported by the + /* Get the command name. There's numerous commands supported by the TCPMON interface. */ - - rpcstr_pull(command, q_u->dataname.buffer, sizeof(command), + + rpcstr_pull(command, q_u->dataname.buffer, sizeof(command), q_u->dataname.uni_str_len*2, 0); - + /* Allocate the outgoing buffer */ - + rpcbuf_init( &r_u->outdata, q_u->offered, p->mem_ctx ); - + switch ( Printer->printer_type ) { case SPLHND_PORTMON_TCP: - return process_xcvtcp_command( p->pipe_user.nt_user_token, command, + return process_xcvtcp_command( p->pipe_user.nt_user_token, command, &q_u->indata, &r_u->outdata, &r_u->needed ); case SPLHND_PORTMON_LOCAL: - return process_xcvlocal_command( p->pipe_user.nt_user_token, command, + return process_xcvlocal_command( p->pipe_user.nt_user_token, command, &q_u->indata, &r_u->outdata, &r_u->needed ); } return WERR_INVALID_PRINT_MONITOR; } - - -- cgit From 93bfb6ca542e1e99ae7ae93fca94a0e33d99bca5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 27 Nov 2007 17:50:39 -0800 Subject: Fix old cut-and-paste bug where the wrong field was being written to. Jerry please check. Jeremy. (This used to be commit 6a556fd73ac8c247c15df664f7910f8688abfdbc) --- source3/rpc_server/srv_spoolss_nt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index f18c120a9f..a6f3bfba17 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1417,8 +1417,8 @@ static DEVICEMODE* dup_devicemode(TALLOC_CTX *ctx, DEVICEMODE *devmode) len = unistrlen(devmode->formname.buffer); if (len != -1) { - d->devicename.buffer = TALLOC_ARRAY(ctx, uint16, len); - if (!d->devicename.buffer) { + d->formname.buffer = TALLOC_ARRAY(ctx, uint16, len); + if (!d->formname.buffer) { return NULL; } if (unistrcpy(d->formname.buffer, devmode->formname.buffer) != len) -- cgit From 0bc4ff7b287e2cd6f7b225861d6c3fda9347adfc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 27 Nov 2007 19:05:08 -0800 Subject: Remove pstring from srv_spoolss_nt.c. All gone from rpc_server/*.c Jeremy. (This used to be commit b5a2a1e3f82a0d319fc9a1d76f5166150680f4d4) --- source3/rpc_server/srv_spoolss_nt.c | 538 ++++++++++++++++++++---------------- 1 file changed, 306 insertions(+), 232 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a6f3bfba17..b01f10b71d 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -284,10 +284,11 @@ static bool close_printer_handle(pipes_struct *p, POLICY_HND *hnd) /**************************************************************************** Delete a printer given a handle. ****************************************************************************/ -WERROR delete_printer_hook( NT_USER_TOKEN *token, const char *sharename ) + +WERROR delete_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *sharename ) { char *cmd = lp_deleteprinter_cmd(); - pstring command; + char *command = NULL; int ret; SE_PRIV se_printop = SE_PRINT_OPERATOR; bool is_print_op = False; @@ -297,8 +298,12 @@ WERROR delete_printer_hook( NT_USER_TOKEN *token, const char *sharename ) if ( !*cmd ) return WERR_OK; - pstr_sprintf(command, "%s \"%s\"", cmd, sharename); - + command = talloc_asprintf(ctx, + "%s \"%s\"", + cmd, sharename); + if (!command) { + return WERR_NOMEM; + } if ( token ) is_print_op = user_has_privileges( token, &se_printop ); @@ -322,6 +327,8 @@ WERROR delete_printer_hook( NT_USER_TOKEN *token, const char *sharename ) DEBUGADD(10,("returned [%d]\n", ret)); + TALLOC_FREE(command); + if (ret != 0) return WERR_BADFID; /* What to return here? */ @@ -367,7 +374,7 @@ static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd) return WERR_BADFID; } - return delete_printer_hook( p->pipe_user.nt_user_token, Printer->sharename ); + return delete_printer_hook(p->mem_ctx, p->pipe_user.nt_user_token, Printer->sharename ); } /**************************************************************************** @@ -2719,20 +2726,17 @@ void spoolss_notify_server_name(int snum, NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) { - pstring temp; + smb_ucs2_t *temp = NULL; uint32 len; - len = rpcstr_push(temp, printer->info_2->servername, sizeof(temp)-2, STR_TERMINATE); + len = rpcstr_push_talloc(mem_ctx, &temp, printer->info_2->servername); + if (len == (uint32)-1) { + len = 0; + } data->notify_data.data.length = len; if (len) { - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; - } - - memcpy(data->notify_data.data.string, temp, len); + data->notify_data.data.string = (uint16 *)temp; } else { data->notify_data.data.string = NULL; } @@ -2748,7 +2752,7 @@ void spoolss_notify_printer_name(int snum, NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) { - pstring temp; + smb_ucs2_t *temp = NULL; uint32 len; /* the notify name should not contain the \\server\ part */ @@ -2760,16 +2764,14 @@ void spoolss_notify_printer_name(int snum, p++; } - len = rpcstr_push(temp, p, sizeof(temp)-2, STR_TERMINATE); + len = rpcstr_push_talloc(mem_ctx, &temp, p); + if (len == (uint32)-1) { + len = 0; + } data->notify_data.data.length = len; if (len) { - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; - } - memcpy(data->notify_data.data.string, temp, len); + data->notify_data.data.string = (uint16 *)temp; } else { data->notify_data.data.string = NULL; } @@ -2785,19 +2787,17 @@ void spoolss_notify_share_name(int snum, NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) { - pstring temp; + smb_ucs2_t *temp = NULL; uint32 len; - len = rpcstr_push(temp, lp_servicename(snum), sizeof(temp)-2, STR_TERMINATE); + len = rpcstr_push_talloc(mem_ctx, &temp, lp_servicename(snum)); + if (len == (uint32)-1) { + len = 0; + } data->notify_data.data.length = len; if (len) { - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; - } - memcpy(data->notify_data.data.string, temp, len); + data->notify_data.data.string = (uint16 *)temp; } else { data->notify_data.data.string = NULL; } @@ -2814,23 +2814,19 @@ void spoolss_notify_port_name(int snum, NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) { - pstring temp; + smb_ucs2_t *temp = NULL; uint32 len; /* even if it's strange, that's consistant in all the code */ - len = rpcstr_push(temp, printer->info_2->portname, sizeof(temp)-2, STR_TERMINATE); + len = rpcstr_push_talloc(mem_ctx, &temp, printer->info_2->portname); + if (len == (uint32)-1) { + len = 0; + } data->notify_data.data.length = len; if (len) { - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; - } - - memcpy(data->notify_data.data.string, temp, len); + data->notify_data.data.string = (uint16 *)temp; } else { data->notify_data.data.string = NULL; } @@ -2847,21 +2843,17 @@ void spoolss_notify_driver_name(int snum, NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) { - pstring temp; + smb_ucs2_t *temp = NULL; uint32 len; - len = rpcstr_push(temp, printer->info_2->drivername, sizeof(temp)-2, STR_TERMINATE); + len = rpcstr_push_talloc(mem_ctx, &temp, printer->info_2->drivername); + if (len == (uint32)-1) { + len = 0; + } data->notify_data.data.length = len; if (len) { - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; - } - - memcpy(data->notify_data.data.string, temp, len); + data->notify_data.data.string = (uint16 *)temp; } else { data->notify_data.data.string = NULL; } @@ -2877,24 +2869,20 @@ void spoolss_notify_comment(int snum, NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) { - pstring temp; + smb_ucs2_t *temp = NULL; uint32 len; if (*printer->info_2->comment == '\0') - len = rpcstr_push(temp, lp_comment(snum), sizeof(temp)-2, STR_TERMINATE); + len = rpcstr_push_talloc(mem_ctx, &temp, lp_comment(snum)); else - len = rpcstr_push(temp, printer->info_2->comment, sizeof(temp)-2, STR_TERMINATE); + len = rpcstr_push_talloc(mem_ctx, &temp, printer->info_2->comment); + if (len == (uint32)-1) { + len = 0; + } data->notify_data.data.length = len; if (len) { - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; - } - - memcpy(data->notify_data.data.string, temp, len); + data->notify_data.data.string = (uint16 *)temp; } else { data->notify_data.data.string = NULL; } @@ -2911,21 +2899,17 @@ void spoolss_notify_location(int snum, NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) { - pstring temp; + smb_ucs2_t *temp = NULL; uint32 len; - len = rpcstr_push(temp, printer->info_2->location,sizeof(temp)-2, STR_TERMINATE); + len = rpcstr_push_talloc(mem_ctx, &temp, printer->info_2->location); + if (len == (uint32)-1) { + len = 0; + } data->notify_data.data.length = len; if (len) { - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; - } - - memcpy(data->notify_data.data.string, temp, len); + data->notify_data.data.string = (uint16 *)temp; } else { data->notify_data.data.string = NULL; } @@ -2957,21 +2941,17 @@ void spoolss_notify_sepfile(int snum, NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) { - pstring temp; + smb_ucs2_t *temp = NULL; uint32 len; - len = rpcstr_push(temp, printer->info_2->sepfile, sizeof(temp)-2, STR_TERMINATE); + len = rpcstr_push_talloc(mem_ctx, &temp, printer->info_2->sepfile); + if (len == (uint32)-1) { + len = 0; + } data->notify_data.data.length = len; if (len) { - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; - } - - memcpy(data->notify_data.data.string, temp, len); + data->notify_data.data.string = (uint16 *)temp; } else { data->notify_data.data.string = NULL; } @@ -2988,21 +2968,17 @@ void spoolss_notify_print_processor(int snum, NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) { - pstring temp; + smb_ucs2_t *temp = NULL; uint32 len; - len = rpcstr_push(temp, printer->info_2->printprocessor, sizeof(temp)-2, STR_TERMINATE); + len = rpcstr_push_talloc(mem_ctx, &temp, printer->info_2->printprocessor); + if (len == (uint32)-1) { + len = 0; + } data->notify_data.data.length = len; if (len) { - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; - } - - memcpy(data->notify_data.data.string, temp, len); + data->notify_data.data.string = (uint16 *)temp; } else { data->notify_data.data.string = NULL; } @@ -3019,21 +2995,17 @@ void spoolss_notify_parameters(int snum, NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) { - pstring temp; + smb_ucs2_t *temp = NULL; uint32 len; - len = rpcstr_push(temp, printer->info_2->parameters, sizeof(temp)-2, STR_TERMINATE); + len = rpcstr_push_talloc(mem_ctx, &temp, printer->info_2->parameters); + if (len == (uint32)-1) { + len = 0; + } data->notify_data.data.length = len; if (len) { - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; - } - - memcpy(data->notify_data.data.string, temp, len); + data->notify_data.data.string = (uint16 *)temp; } else { data->notify_data.data.string = NULL; } @@ -3050,21 +3022,17 @@ void spoolss_notify_datatype(int snum, NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) { - pstring temp; + smb_ucs2_t *temp = NULL; uint32 len; - len = rpcstr_push(temp, printer->info_2->datatype, sizeof(pstring)-2, STR_TERMINATE); + len = rpcstr_push_talloc(mem_ctx, &temp, printer->info_2->datatype); + if (len == (uint32)-1) { + len = 0; + } data->notify_data.data.length = len; if (len) { - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; - } - - memcpy(data->notify_data.data.string, temp, len); + data->notify_data.data.string = (uint16 *)temp; } else { data->notify_data.data.string = NULL; } @@ -3214,21 +3182,17 @@ static void spoolss_notify_username(int snum, NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) { - pstring temp; + smb_ucs2_t *temp = NULL; uint32 len; - len = rpcstr_push(temp, queue->fs_user, sizeof(temp)-2, STR_TERMINATE); + len = rpcstr_push_talloc(mem_ctx, &temp, queue->fs_user); + if (len == (uint32)-1) { + len = 0; + } data->notify_data.data.length = len; if (len) { - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; - } - - memcpy(data->notify_data.data.string, temp, len); + data->notify_data.data.string = (uint16 *)temp; } else { data->notify_data.data.string = NULL; } @@ -3258,21 +3222,17 @@ static void spoolss_notify_job_name(int snum, NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) { - pstring temp; + smb_ucs2_t *temp = NULL; uint32 len; - len = rpcstr_push(temp, queue->fs_file, sizeof(temp)-2, STR_TERMINATE); + len = rpcstr_push_talloc(mem_ctx, &temp, queue->fs_file); + if (len == (uint32)-1) { + len = 0; + } data->notify_data.data.length = len; if (len) { - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; - } - - memcpy(data->notify_data.data.string, temp, len); + data->notify_data.data.string = (uint16 *)temp; } else { data->notify_data.data.string = NULL; } @@ -3293,7 +3253,7 @@ static void spoolss_notify_job_status_string(int snum, */ const char *p = ""; - pstring temp; + smb_ucs2_t *temp = NULL; uint32 len; #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */ @@ -3315,18 +3275,14 @@ static void spoolss_notify_job_status_string(int snum, } #endif /* NO LONGER NEEDED. */ - len = rpcstr_push(temp, p, sizeof(temp) - 2, STR_TERMINATE); + len = rpcstr_push_talloc(mem_ctx, &temp, p); + if (len == (uint32)-1) { + len = 0; + } data->notify_data.data.length = len; if (len) { - data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len); - - if (!data->notify_data.data.string) { - data->notify_data.data.length = 0; - return; - } - - memcpy(data->notify_data.data.string, temp, len); + data->notify_data.data.string = (uint16 *)temp; } else { data->notify_data.data.string = NULL; } @@ -3954,7 +3910,7 @@ done: static bool construct_printer_info_0(Printer_entry *print_hnd, PRINTER_INFO_0 *printer, int snum) { - pstring chaine; + char *chaine = NULL; int count; NT_PRINTER_INFO_LEVEL *ntprinter = NULL; counter_printer_0 *session_counter; @@ -3962,10 +3918,19 @@ static bool construct_printer_info_0(Printer_entry *print_hnd, PRINTER_INFO_0 *p struct tm *t; time_t setuptime; print_status_struct status; + TALLOC_CTX *ctx = talloc_tos(); if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum)))) return False; + init_unistr(&printer->printername, ntprinter->info_2->printername); + + chaine = talloc_asprintf(ctx, "\\\\%s", get_server_name(print_hnd)); + if (!chaine) { + free_a_printer(&ntprinter,2); + return false; + } + count = print_queue_length(snum, &status); /* check if we already have a counter for this printer */ @@ -3974,6 +3939,8 @@ static bool construct_printer_info_0(Printer_entry *print_hnd, PRINTER_INFO_0 *p break; } + init_unistr(&printer->servername, chaine); + /* it's the first time, add it to the list */ if (session_counter==NULL) { if((session_counter=SMB_MALLOC_P(counter_printer_0)) == NULL) { @@ -3994,14 +3961,6 @@ static bool construct_printer_info_0(Printer_entry *print_hnd, PRINTER_INFO_0 *p * and should be zeroed on samba startup */ global_counter=session_counter->counter; - - pstrcpy(chaine,ntprinter->info_2->printername); - - init_unistr(&printer->printername, chaine); - - slprintf(chaine,sizeof(chaine)-1,"\\\\%s", get_server_name(print_hnd)); - init_unistr(&printer->servername, chaine); - printer->cjobs = count; printer->total_jobs = 0; printer->total_bytes = 0; @@ -4059,30 +4018,35 @@ static bool construct_printer_info_0(Printer_entry *print_hnd, PRINTER_INFO_0 *p ********************************************************************/ static bool construct_printer_info_1(Printer_entry *print_hnd, uint32 flags, PRINTER_INFO_1 *printer, int snum) { - pstring chaine; - pstring chaine2; + char *chaine = NULL; NT_PRINTER_INFO_LEVEL *ntprinter = NULL; + TALLOC_CTX *ctx = talloc_tos(); if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum)))) - return False; + return false; printer->flags=flags; if (*ntprinter->info_2->comment == '\0') { init_unistr(&printer->comment, lp_comment(snum)); - slprintf(chaine,sizeof(chaine)-1,"%s,%s,%s", ntprinter->info_2->printername, - ntprinter->info_2->drivername, lp_comment(snum)); + chaine = talloc_asprintf(ctx, + "%s,%s,%s", ntprinter->info_2->printername, + ntprinter->info_2->drivername, lp_comment(snum)); } else { init_unistr(&printer->comment, ntprinter->info_2->comment); /* saved comment. */ - slprintf(chaine,sizeof(chaine)-1,"%s,%s,%s", ntprinter->info_2->printername, - ntprinter->info_2->drivername, ntprinter->info_2->comment); + chaine = talloc_asprintf(ctx, + "%s,%s,%s", ntprinter->info_2->printername, + ntprinter->info_2->drivername, ntprinter->info_2->comment); } - slprintf(chaine2,sizeof(chaine)-1,"%s", ntprinter->info_2->printername); + if (!chaine) { + free_a_printer(&ntprinter,2); + return false; + } init_unistr(&printer->description, chaine); - init_unistr(&printer->name, chaine2); + init_unistr(&printer->name, ntprinter->info_2->printername); free_a_printer(&ntprinter,2); @@ -5160,7 +5124,8 @@ static WERROR construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, fst static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername) { - pstring temp; + TALLOC_CTX *ctx = talloc_tos(); + char *temp = NULL; info->version=driver.info_3->cversion; @@ -5168,20 +5133,32 @@ static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, NT_PRINTER_DRIVER_IN init_unistr( &info->architecture, driver.info_3->environment ); - if (strlen(driver.info_3->driverpath)) { - slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->driverpath); + if (strlen(driver.info_3->driverpath)) { + temp = talloc_asprintf(ctx, + "\\\\%s%s", + servername, + driver.info_3->driverpath); init_unistr( &info->driverpath, temp ); - } else - init_unistr( &info->driverpath, "" ); + } else { + init_unistr( &info->driverpath, "" ); + } + TALLOC_FREE(temp); if (strlen(driver.info_3->datafile)) { - slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->datafile); + temp = talloc_asprintf(ctx, + "\\\\%s%s", + servername, + driver.info_3->datafile); init_unistr( &info->datafile, temp ); } else init_unistr( &info->datafile, "" ); + TALLOC_FREE(temp); if (strlen(driver.info_3->configfile)) { - slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->configfile); + temp = talloc_asprintf(ctx, + "\\\\%s%s", + servername, + driver.info_3->configfile); init_unistr( &info->configfile, temp ); } else init_unistr( &info->configfile, "" ); @@ -5226,17 +5203,16 @@ static uint32 init_unistr_array(uint16 **uni_array, fstring *char_array, const c int i=0; int j=0; const char *v; - pstring line; + char *line = NULL; + TALLOC_CTX *ctx = talloc_tos(); DEBUG(6,("init_unistr_array\n")); *uni_array=NULL; - while (True) - { - if ( !char_array ) + while (true) { + if ( !char_array ) { v = ""; - else - { + } else { v = char_array[i]; if (!v) v = ""; /* hack to handle null lists */ @@ -5244,12 +5220,21 @@ static uint32 init_unistr_array(uint16 **uni_array, fstring *char_array, const c /* hack to allow this to be used in places other than when generating the list of dependent files */ - - if ( servername ) - slprintf( line, sizeof(line)-1, "\\\\%s%s", servername, v ); - else - pstrcpy( line, v ); + TALLOC_FREE(line); + if ( servername ) { + line = talloc_asprintf(ctx, + "\\\\%s%s", + servername, + v); + } else { + line = talloc_strdup(ctx, v); + } + + if (!line) { + SAFE_FREE(*uni_array); + return 0; + } DEBUGADD(6,("%d:%s:%lu\n", i, line, (unsigned long)strlen(line))); /* add one extra unit16 for the second terminating NULL */ @@ -5287,7 +5272,8 @@ static uint32 init_unistr_array(uint16 **uni_array, fstring *char_array, const c static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername) { - pstring temp; + char *temp = NULL; + TALLOC_CTX *ctx = talloc_tos(); ZERO_STRUCTP(info); @@ -5297,29 +5283,45 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_IN init_unistr( &info->architecture, driver.info_3->environment ); if (strlen(driver.info_3->driverpath)) { - slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->driverpath); + temp = talloc_asprintf(ctx, + "\\\\%s%s", + servername, + driver.info_3->driverpath); init_unistr( &info->driverpath, temp ); } else init_unistr( &info->driverpath, "" ); + TALLOC_FREE(temp); if (strlen(driver.info_3->datafile)) { - slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->datafile); + temp = talloc_asprintf(ctx, + "\\\\%s%s", + servername, + driver.info_3->datafile); init_unistr( &info->datafile, temp ); } else init_unistr( &info->datafile, "" ); + TALLOC_FREE(temp); if (strlen(driver.info_3->configfile)) { - slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->configfile); + temp = talloc_asprintf(ctx, + "\\\\%s%s", + servername, + driver.info_3->configfile); init_unistr( &info->configfile, temp ); } else init_unistr( &info->configfile, "" ); + TALLOC_FREE(temp); if (strlen(driver.info_3->helpfile)) { - slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->helpfile); + temp = talloc_asprintf(ctx, + "\\\\%s%s", + servername, + driver.info_3->helpfile); init_unistr( &info->helpfile, temp ); } else init_unistr( &info->helpfile, "" ); + TALLOC_FREE(temp); init_unistr( &info->monitorname, driver.info_3->monitorname ); init_unistr( &info->defaultdatatype, driver.info_3->defaultdatatype ); @@ -5393,8 +5395,9 @@ static WERROR construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fst static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername) { - pstring temp; + char *temp = NULL; fstring nullstr; + TALLOC_CTX *ctx = talloc_tos(); ZERO_STRUCTP(info); memset(&nullstr, '\0', sizeof(fstring)); @@ -5405,29 +5408,45 @@ static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_IN init_unistr( &info->architecture, driver.info_3->environment ); if (strlen(driver.info_3->driverpath)) { - slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->driverpath); + temp = talloc_asprintf(ctx, + "\\\\%s%s", + servername, + driver.info_3->driverpath); init_unistr( &info->driverpath, temp ); } else init_unistr( &info->driverpath, "" ); + TALLOC_FREE(temp); if (strlen(driver.info_3->datafile)) { - slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->datafile); + temp = talloc_asprintf(ctx, + "\\\\%s%s", + servername, + driver.info_3->datafile); init_unistr( &info->datafile, temp ); } else init_unistr( &info->datafile, "" ); + TALLOC_FREE(temp); if (strlen(driver.info_3->configfile)) { - slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->configfile); + temp = talloc_asprintf(ctx, + "\\\\%s%s", + servername, + driver.info_3->configfile); init_unistr( &info->configfile, temp ); } else init_unistr( &info->configfile, "" ); + TALLOC_FREE(temp); if (strlen(driver.info_3->helpfile)) { - slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->helpfile); + temp = talloc_asprintf(ctx, + "\\\\%s%s", + servername, + driver.info_3->helpfile); init_unistr( &info->helpfile, temp ); } else init_unistr( &info->helpfile, "" ); + TALLOC_FREE(temp); init_unistr( &info->monitorname, driver.info_3->monitorname ); init_unistr( &info->defaultdatatype, driver.info_3->defaultdatatype ); @@ -5786,10 +5805,10 @@ WERROR _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, S POLICY_HND *handle = &q_u->handle; DOC_INFO *docinfo = &q_u->doc_info_container.docinfo; uint32 *jobid = &r_u->jobid; - + TALLOC_CTX *ctx = p->mem_ctx; DOC_INFO_1 *info_1 = &docinfo->doc_info_1; int snum; - pstring jobname; + char *jobname = NULL; fstring datatype; Printer_entry *Printer = find_printer_index_by_hnd(p, handle); @@ -5819,7 +5838,7 @@ WERROR _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, S return WERR_BADFID; } - unistr2_to_ascii(jobname, &info_1->docname, sizeof(jobname)); + jobname = unistr2_to_ascii_talloc(ctx, &info_1->docname); Printer->jobid = print_job_start(&p->pipe_user, snum, jobname, Printer->nt_devmode); @@ -6109,10 +6128,10 @@ static bool check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) /**************************************************************************** ****************************************************************************/ -WERROR add_port_hook(NT_USER_TOKEN *token, const char *portname, const char *uri ) +WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *portname, const char *uri ) { char *cmd = lp_addport_cmd(); - pstring command; + char *command = NULL; int ret; int fd; SE_PRIV se_printop = SE_PRINT_OPERATOR; @@ -6122,7 +6141,11 @@ WERROR add_port_hook(NT_USER_TOKEN *token, const char *portname, const char *uri return WERR_ACCESS_DENIED; } - slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\"", cmd, portname, uri ); + command = talloc_asprintf(ctx, + "%s \"%s\" \"%s\"", cmd, portname, uri ); + if (!command) { + return WERR_NOMEM; + } if ( token ) is_print_op = user_has_privileges( token, &se_printop ); @@ -6143,6 +6166,8 @@ WERROR add_port_hook(NT_USER_TOKEN *token, const char *portname, const char *uri DEBUGADD(10,("returned [%d]\n", ret)); + TALLOC_FREE(command); + if ( ret != 0 ) { if (fd != -1) close(fd); @@ -6155,26 +6180,37 @@ WERROR add_port_hook(NT_USER_TOKEN *token, const char *portname, const char *uri /**************************************************************************** ****************************************************************************/ -bool add_printer_hook(NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer) +bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer) { char *cmd = lp_addprinter_cmd(); char **qlines; - pstring command; + char *command = NULL; int numlines; int ret; int fd; - fstring remote_machine = "%m"; SE_PRIV se_printop = SE_PRINT_OPERATOR; bool is_print_op = False; + char *remote_machine = talloc_strdup(ctx, "%m"); - standard_sub_basic(current_user_info.smb_name, - current_user_info.domain, - remote_machine,sizeof(remote_machine)); + if (!remote_machine) { + return false; + } + remote_machine = talloc_sub_basic(ctx, + current_user_info.smb_name, + current_user_info.domain, + remote_machine); + if (!remote_machine) { + return false; + } - slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"", + command = talloc_asprintf(ctx, + "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"", cmd, printer->info_2->printername, printer->info_2->sharename, printer->info_2->portname, printer->info_2->drivername, printer->info_2->location, printer->info_2->comment, remote_machine); + if (!command) { + return false; + } if ( token ) is_print_op = user_has_privileges( token, &se_printop ); @@ -6199,6 +6235,9 @@ bool add_printer_hook(NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer) DEBUGADD(10,("returned [%d]\n", ret)); + TALLOC_FREE(command); + TALLOC_FREE(remote_machine); + if ( ret != 0 ) { if (fd != -1) close(fd); @@ -6318,7 +6357,7 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, { /* add_printer_hook() will call reload_services() */ - if ( !add_printer_hook(p->pipe_user.nt_user_token, printer) ) { + if ( !add_printer_hook(p->mem_ctx, p->pipe_user.nt_user_token, printer) ) { result = WERR_ACCESS_DENIED; goto done; } @@ -7395,11 +7434,11 @@ static void fill_port_2(PORT_INFO_2 *port, const char *name) wrapper around the enumer ports command ****************************************************************************/ -WERROR enumports_hook( int *count, char ***lines ) +WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines ) { char *cmd = lp_enumports_cmd(); - char **qlines; - pstring command; + char **qlines = NULL; + char *command = NULL; int numlines; int ret; int fd; @@ -7423,11 +7462,15 @@ WERROR enumports_hook( int *count, char ***lines ) else { /* we have a valid enumport command */ - slprintf(command, sizeof(command)-1, "%s \"%d\"", cmd, 1); + command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1); + if (!command) { + return WERR_NOMEM; + } DEBUG(10,("Running [%s]\n", command)); ret = smbrun(command, &fd); DEBUG(10,("Returned [%d]\n", ret)); + TALLOC_FREE(command); if (ret != 0) { if (fd != -1) { close(fd); @@ -7459,7 +7502,7 @@ static WERROR enumports_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *need char **qlines = NULL; int numlines = 0; - result = enumports_hook( &numlines, &qlines ); + result = enumports_hook(talloc_tos(), &numlines, &qlines ); if (!W_ERROR_IS_OK(result)) { file_lines_free(qlines); return result; @@ -7525,7 +7568,7 @@ static WERROR enumports_level_2(RPC_BUFFER *buffer, uint32 offered, uint32 *need char **qlines = NULL; int numlines = 0; - result = enumports_hook( &numlines, &qlines ); + result = enumports_hook(talloc_tos(), &numlines, &qlines ); if ( !W_ERROR_IS_OK(result)) { file_lines_free(qlines); return result; @@ -7652,7 +7695,7 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ trying to add a printer like this --jerry */ if (*lp_addprinter_cmd() ) { - if ( !add_printer_hook(p->pipe_user.nt_user_token, printer) ) { + if ( !add_printer_hook(p->mem_ctx, p->pipe_user.nt_user_token, printer) ) { free_a_printer(&printer,2); return WERR_ACCESS_DENIED; } @@ -7916,16 +7959,23 @@ static void fill_driverdir_1(DRIVER_DIRECTORY_1 *info, char *name) static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environment, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { - pstring path; - pstring long_archi; - fstring servername; - char *pservername; + char *path = NULL; + char *long_archi = NULL; + char *servername = NULL; + char *pservername = NULL; const char *short_archi; DRIVER_DIRECTORY_1 *info=NULL; WERROR result = WERR_OK; + TALLOC_CTX *ctx = talloc_tos(); - unistr2_to_ascii(servername, name, sizeof(servername)); - unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)); + servername = unistr2_to_ascii_talloc(ctx, name); + if (!servername) { + return WERR_NOMEM; + } + long_archi = unistr2_to_ascii_talloc(ctx, uni_environment); + if (!long_archi) { + return WERR_NOMEM; + } /* check for beginning double '\'s and that the server long enough */ @@ -7944,7 +7994,12 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen if((info=SMB_MALLOC_P(DRIVER_DIRECTORY_1)) == NULL) return WERR_NOMEM; - slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", pservername, short_archi); + path = talloc_asprintf(ctx, + "\\\\%s\\print$\\%s", pservername, short_archi); + if (!path) { + result = WERR_NOMEM; + goto out; + } DEBUG(4,("printer driver directory: [%s]\n", path)); @@ -8313,7 +8368,8 @@ WERROR _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_ int snum=0; WERROR status = WERR_OK; Printer_entry *Printer=find_printer_index_by_hnd(p, handle); - pstring valuename; + char *valuename = NULL; + TALLOC_CTX *ctx = p->mem_ctx; DEBUG(5,("spoolss_deleteprinterdata\n")); @@ -8334,7 +8390,11 @@ WERROR _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_ if (!W_ERROR_IS_OK(status)) return status; - unistr2_to_ascii(valuename, value, sizeof(valuename)); + valuename = unistr2_to_ascii_talloc(ctx, value); + if (!valuename) { + free_a_printer(&printer, 2); + return WERR_NOMEM; + } status = delete_printer_dataex( printer, SPOOL_PRINTERDATA_KEY, valuename ); @@ -8342,6 +8402,7 @@ WERROR _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_ mod_a_printer( printer, 2 ); free_a_printer(&printer, 2); + TALLOC_FREE(valuename); return status; } @@ -9245,7 +9306,9 @@ WERROR _spoolss_deleteprinterdataex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATAEX int snum=0; WERROR status = WERR_OK; Printer_entry *Printer=find_printer_index_by_hnd(p, handle); - pstring valuename, keyname; + char *valuename = NULL; + char *keyname = NULL; + TALLOC_CTX *ctx = p->mem_ctx; DEBUG(5,("spoolss_deleteprinterdataex\n")); @@ -9262,13 +9325,16 @@ WERROR _spoolss_deleteprinterdataex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATAEX return WERR_ACCESS_DENIED; } + valuename = unistr2_to_ascii_talloc(ctx, value); + keyname = unistr2_to_ascii_talloc(ctx, key); + if (!valuename || !keyname) { + return WERR_NOMEM; + } + status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(status)) return status; - unistr2_to_ascii(valuename, value, sizeof(valuename)); - unistr2_to_ascii(keyname, key, sizeof(keyname)); - status = delete_printer_dataex( printer, keyname, valuename ); if ( W_ERROR_IS_OK(status) ) @@ -9562,7 +9628,7 @@ done: /**************************************************************************** ****************************************************************************/ -static void fill_printprocessordirectory_1(PRINTPROCESSOR_DIRECTORY_1 *info, char *name) +static void fill_printprocessordirectory_1(PRINTPROCESSOR_DIRECTORY_1 *info, const char *name) { init_unistr(&info->name, name); } @@ -9573,12 +9639,15 @@ static WERROR getprintprocessordirectory_level_1(UNISTR2 *name, uint32 offered, uint32 *needed) { - pstring path; - pstring long_archi; + char *long_archi = NULL; PRINTPROCESSOR_DIRECTORY_1 *info=NULL; WERROR result = WERR_OK; + TALLOC_CTX *ctx = talloc_tos(); - unistr2_to_ascii(long_archi, environment, sizeof(long_archi)); + long_archi = unistr2_to_ascii_talloc(ctx, environment); + if (!long_archi) { + return WERR_NOMEM; + } if (!get_short_archi(long_archi)) return WERR_INVALID_ENVIRONMENT; @@ -9586,9 +9655,7 @@ static WERROR getprintprocessordirectory_level_1(UNISTR2 *name, if((info=SMB_MALLOC_P(PRINTPROCESSOR_DIRECTORY_1)) == NULL) return WERR_NOMEM; - pstrcpy(path, "C:\\WINNT\\System32\\spool\\PRTPROCS\\W32X86"); - - fill_printprocessordirectory_1(info, path); + fill_printprocessordirectory_1(info, "C:\\WINNT\\System32\\spool\\PRTPROCS\\W32X86"); *needed += spoolss_size_printprocessordirectory_info_1(info); @@ -9673,7 +9740,8 @@ static WERROR xcvtcp_addport( NT_USER_TOKEN *token, RPC_BUFFER *in, RPC_BUFFER *out, uint32 *needed ) { NT_PORT_DATA_1 port1; - pstring device_uri; + TALLOC_CTX *ctx = talloc_tos(); + char *device_uri = NULL; ZERO_STRUCT( port1 ); @@ -9687,18 +9755,24 @@ static WERROR xcvtcp_addport( NT_USER_TOKEN *token, RPC_BUFFER *in, switch ( port1.protocol ) { case PORT_PROTOCOL_DIRECT: - pstr_sprintf( device_uri, "socket://%s:%d/", port1.hostaddr, port1.port ); + device_uri = talloc_asprintf(ctx, + "socket://%s:%d/", port1.hostaddr, port1.port ); break; case PORT_PROTOCOL_LPR: - pstr_sprintf( device_uri, "lpr://%s/%s", port1.hostaddr, port1.queue ); + device_uri = talloc_asprintf(ctx, + "lpr://%s/%s", port1.hostaddr, port1.queue ); break; default: return WERR_UNKNOWN_PORT; } - return add_port_hook( token, port1.name, device_uri ); + if (!device_uri) { + return WERR_NOMEM; + } + + return add_port_hook(ctx, token, port1.name, device_uri ); } /******************************************************************* -- cgit From d2cf97aeba14a4d336fb57b01f19bd5a08dcb003 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 29 Nov 2007 13:24:54 -0800 Subject: Remove the explicit TALLOC_CTX * from cli_struct. Make us very explicit about how long a talloc ctx should last. Jeremy. (This used to be commit ba9e2be2b5a59684e854609f9d82ea1633448c62) --- source3/rpc_server/srv_spoolss_nt.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index b01f10b71d..a17a8ebf26 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -153,7 +153,9 @@ static void srv_spoolss_replycloseprinter(int snum, POLICY_HND *handle) return; } - result = rpccli_spoolss_reply_close_printer(notify_cli_pipe, notify_cli_pipe->cli->mem_ctx, handle); + result = rpccli_spoolss_reply_close_printer(notify_cli_pipe, + talloc_tos(), + handle); if (!W_ERROR_IS_OK(result)) DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed [%s].\n", @@ -2639,8 +2641,12 @@ static bool srv_spoolss_replyopenprinter(int snum, const char *printer, smb_connections++; - result = rpccli_spoolss_reply_open_printer(notify_cli_pipe, notify_cli_pipe->cli->mem_ctx, printer, localprinter, - type, handle); + result = rpccli_spoolss_reply_open_printer(notify_cli_pipe, + talloc_tos(), + printer, + localprinter, + type, + handle); if (!W_ERROR_IS_OK(result)) DEBUG(5,("srv_spoolss_reply_open_printer: Client RPC returned [%s]\n", -- cgit From 6dd89174ecef8b68774924de8b94a24c73ea4f44 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 10 Dec 2007 12:11:45 -0800 Subject: Fix return values for invalid printers. Found by kblin spoolss test. Jeremy. (This used to be commit bb8c044d425cf62b76e487103c8fb0b6cd4c83c2) --- source3/rpc_server/srv_spoolss_nt.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a17a8ebf26..c1e422657b 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1530,6 +1530,13 @@ WERROR _spoolss_open_printer(pipes_struct *p, SPOOL_Q_OPEN_PRINTER *q_u, SPOOL_R memcpy(r_u, &r_u_ex, sizeof(*r_u)); + if (W_ERROR_EQUAL(r_u->status, WERR_INVALID_PARAM)) { + /* OpenPrinterEx returns this for a bad + * printer name. We must return WERR_INVALID_PRINTER_NAME + * instead. + */ + r_u->status = WERR_INVALID_PRINTER_NAME; + } return r_u->status; } @@ -1545,8 +1552,9 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, int snum; Printer_entry *Printer=NULL; - if ( !q_u->printername ) - return WERR_INVALID_PRINTER_NAME; + if (!q_u->printername) { + return WERR_INVALID_PARAM; + } /* some sanity check because you can open a printer or a print server */ /* aka: \\server\printer or \\server */ @@ -1555,15 +1563,16 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, DEBUGADD(3,("checking name: %s\n",name)); - if (!open_printer_hnd(p, handle, name, 0)) - return WERR_INVALID_PRINTER_NAME; + if (!open_printer_hnd(p, handle, name, 0)) { + return WERR_INVALID_PARAM; + } Printer=find_printer_index_by_hnd(p, handle); if ( !Printer ) { DEBUG(0,(" _spoolss_open_printer_ex: logic error. Can't find printer " "handle we created for printer %s\n", name )); close_printer_handle(p,handle); - return WERR_INVALID_PRINTER_NAME; + return WERR_INVALID_PARAM; } /* -- cgit From 900288a2b86abd247f9eb4cd15dc5617a17cfef1 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 15 Dec 2007 21:11:36 +0100 Subject: Replace sid_string_static by sid_string_dbg in DEBUGs (This used to be commit bb35e794ec129805e874ceba882bcc1e84791a09) --- source3/rpc_server/srv_spoolss_nt.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index c1e422657b..3758c8fd63 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6044,11 +6044,8 @@ static WERROR update_printer_sec(POLICY_HND *handle, uint32 level, PRINTERNAME(snum), the_acl->num_aces)); for (i = 0; i < the_acl->num_aces; i++) { - fstring sid_str; - - sid_to_string(sid_str, &the_acl->aces[i].trustee); - - DEBUG(10, ("%s 0x%08x\n", sid_str, + DEBUG(10, ("%s 0x%08x\n", sid_string_dbg( + &the_acl->aces[i].trustee), the_acl->aces[i].access_mask)); } @@ -6059,11 +6056,8 @@ static WERROR update_printer_sec(POLICY_HND *handle, uint32 level, PRINTERNAME(snum), the_acl->num_aces)); for (i = 0; i < the_acl->num_aces; i++) { - fstring sid_str; - - sid_to_string(sid_str, &the_acl->aces[i].trustee); - - DEBUG(10, ("%s 0x%08x\n", sid_str, + DEBUG(10, ("%s 0x%08x\n", sid_string_dbg( + &the_acl->aces[i].trustee), the_acl->aces[i].access_mask)); } } else { -- cgit From e06aa46b9fab1e107fea8f6453fb13deffa91e96 Mon Sep 17 00:00:00 2001 From: Marc VanHeyningen Date: Fri, 14 Mar 2008 14:26:28 -0800 Subject: Coverity fixes (This used to be commit 3fc85d22590550f0539215d020e4411bf5b14363) --- source3/rpc_server/srv_spoolss_nt.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 3758c8fd63..403beb6782 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6033,7 +6033,11 @@ static WERROR update_printer_sec(POLICY_HND *handle, uint32 level, /* NT seems to like setting the security descriptor even though nothing may have actually changed. */ - nt_printing_getsec(p->mem_ctx, Printer->sharename, &old_secdesc_ctr); + if ( !nt_printing_getsec(p->mem_ctx, Printer->sharename, &old_secdesc_ctr)) { + DEBUG(2,("update_printer_sec: nt_printing_getsec() failed\n")); + result = WERR_BADFID; + goto done; + } if (DEBUGLEVEL >= 10) { SEC_ACL *the_acl; -- cgit From 40d16fa275888b0dbb5894d484966c858187997c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 4 Apr 2008 11:14:09 -0700 Subject: Fix bug #5372. With a large CUPS installation with a remote server, contacting the server when searching for a name for the location and comment fields can take so much time the client times out. When searching for a name we don't use these fields anyway, so add a function get_a_printer_search() which doesn't contact the CUPS server. Jeremy. (This used to be commit 92d9f20852d5384e92a93dd0b051034718840ca8) --- source3/rpc_server/srv_spoolss_nt.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 403beb6782..7788e763fa 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -521,7 +521,13 @@ static bool set_printer_hnd_name(Printer_entry *Printer, char *handlename) fstrcpy(sname, lp_servicename(snum)); printer = NULL; - result = get_a_printer( NULL, &printer, 2, sname ); + + /* This call doesn't fill in the location or comment from + * a CUPS server for efficiency with large numbers of printers. + * JRA. + */ + + result = get_a_printer_search( NULL, &printer, 2, sname ); if ( !W_ERROR_IS_OK(result) ) { DEBUG(0,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n", sname, dos_errstr(result))); -- cgit From 0c17878e2189431fcb7d63c4ddd0f4647ba411b9 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 20 Apr 2008 14:02:21 +0200 Subject: Remove a redundant reference to rpc_pipe_state->cli from srv_spoolss This assignment is done in cli_rpc_pipe_open called from cli_rpc_pipe_open_noauth already. (This used to be commit 7331c4c2781bf7904942c119f1a8de8eda00ae7e) --- source3/rpc_server/srv_spoolss_nt.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 7788e763fa..722ad54951 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2609,10 +2609,6 @@ static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe, return False; } - /* make sure to save the cli_state pointer. Keep its own talloc_ctx */ - - (*pp_pipe)->cli = the_cli; - return True; } -- cgit From b9cc05506273e5ce3398a5912b9c9e5989717480 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 20 Apr 2008 14:05:25 +0200 Subject: Introduce rpc_pipe_np_smb_conn() This abstracts away all references to rpc_pipe_client->cli, the only reference is now in cli_pipe.c. (This used to be commit c56e1c08cef107ff33a34346ceeca3475a102b19) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 722ad54951..4c5fcf5341 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -164,7 +164,7 @@ static void srv_spoolss_replycloseprinter(int snum, POLICY_HND *handle) /* if it's the last connection, deconnect the IPC$ share */ if (smb_connections==1) { - cli_shutdown( notify_cli_pipe->cli ); + cli_shutdown( rpc_pipe_np_smb_conn(notify_cli_pipe) ); notify_cli_pipe = NULL; /* The above call shuts downn the pipe also. */ messaging_deregister(smbd_messaging_context(), -- cgit From 189eb93b73c4ff0737b702a0682727f5a22bcc38 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 24 Apr 2008 14:04:47 -0700 Subject: The first of Martin Zielinski Vista printing patches. Jerry will test and should get into 3.2 final (and the next 3.0.x release). Jeremy. (This used to be commit 3fc1ab210b8772ee9f867499c0b1a7bb4bcdd285) --- source3/rpc_server/srv_spoolss_nt.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 4c5fcf5341..a7b477e17d 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -9626,13 +9626,16 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ /* copy data into the reply */ - r_u->ctr.size = r_u->needed; + /* mz: Vista x64 returns 0x6f7 (The stub received bad data), if the + response buffer size is != the offered buffer size + + r_u->ctr.size = r_u->needed; + */ + r_u->ctr.size = in_size; r_u->ctr.size_of_array = r_u->returned; r_u->ctr.values = enum_values; - - done: if ( printer ) free_a_printer(&printer, 2); -- cgit From 1409ed60e2176e16fdd65b79ca502d9da6f11a74 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 6 May 2008 15:06:12 +0200 Subject: Fix a memleak in construct_printer_info_7() Also fix a "ignoring asprintf result" warning (This used to be commit 64d21f39636019d6a17f84efc6fb9e61e67a235e) --- source3/rpc_server/srv_spoolss_nt.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index a7b477e17d..0e98a39426 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -4357,10 +4357,13 @@ static bool construct_printer_info_7(Printer_entry *print_hnd, PRINTER_INFO_7 *p struct GUID guid; if (is_printer_published(print_hnd, snum, &guid)) { - asprintf(&guid_str, "{%s}", - smb_uuid_string(talloc_tos(), guid)); + if (asprintf(&guid_str, "{%s}", + smb_uuid_string(talloc_tos(), guid)) == -1) { + return false; + } strupper_m(guid_str); init_unistr(&printer->guid, guid_str); + SAFE_FREE(guid_str); printer->action = SPOOL_DS_PUBLISH; } else { init_unistr(&printer->guid, ""); -- cgit From 320fadd8fc600262d26ea417a92d395aeb16ef57 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 11 May 2008 01:03:45 +0200 Subject: Remove the reference to current_user_info from share_access.c This required to pass around the domain a bit (This used to be commit 17b0db20d28d1b737c5e86b78106657e8ca5ce9c) --- source3/rpc_server/srv_spoolss_nt.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 0e98a39426..06b3d4a07a 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1649,7 +1649,8 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, !user_has_privileges(p->pipe_user.nt_user_token, &se_printop ) && !token_contains_name_in_list( - uidtoname(p->pipe_user.ut.uid), NULL, + uidtoname(p->pipe_user.ut.uid), + NULL, NULL, p->pipe_user.nt_user_token, lp_printer_admin(snum))) { close_printer_handle(p, handle); @@ -1703,7 +1704,7 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, return WERR_ACCESS_DENIED; } - if (!user_ok_token(uidtoname(p->pipe_user.ut.uid), + if (!user_ok_token(uidtoname(p->pipe_user.ut.uid), NULL, p->pipe_user.nt_user_token, snum) || !print_access_check(&p->pipe_user, snum, printer_default->access_required)) { @@ -2008,8 +2009,10 @@ WERROR _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER if ( (p->pipe_user.ut.uid != 0) && !user_has_privileges(p->pipe_user.nt_user_token, &se_printop ) - && !token_contains_name_in_list( uidtoname(p->pipe_user.ut.uid), - NULL, p->pipe_user.nt_user_token, lp_printer_admin(-1)) ) + && !token_contains_name_in_list( + uidtoname(p->pipe_user.ut.uid), NULL, + NULL, p->pipe_user.nt_user_token, + lp_printer_admin(-1)) ) { return WERR_ACCESS_DENIED; } @@ -2103,8 +2106,9 @@ WERROR _spoolss_deleteprinterdriverex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIV if ( (p->pipe_user.ut.uid != 0) && !user_has_privileges(p->pipe_user.nt_user_token, &se_printop ) - && !token_contains_name_in_list( uidtoname(p->pipe_user.ut.uid), - NULL, p->pipe_user.nt_user_token, lp_printer_admin(-1)) ) + && !token_contains_name_in_list( + uidtoname(p->pipe_user.ut.uid), NULL, NULL, + p->pipe_user.nt_user_token, lp_printer_admin(-1)) ) { return WERR_ACCESS_DENIED; } -- cgit From 9ff4001245d718515cb90036659109e23833e5fe Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 23 Jun 2008 08:38:27 +0200 Subject: Remove "conn" from pipes_struct For spoolss, we need the client's IP address (This used to be commit 64a4dfaa826cf9319ef3f5c65023352bf8af539e) --- source3/rpc_server/srv_spoolss_nt.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 06b3d4a07a..eaf563eaa9 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2721,9 +2721,8 @@ WERROR _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE !get_printer_snum(p, handle, &snum, NULL) ) return WERR_BADFID; - if (!interpret_string_addr(&client_ss, - p->conn->client_address, - AI_NUMERICHOST)) { + if (!interpret_string_addr(&client_ss, p->client_address, + AI_NUMERICHOST)) { return WERR_SERVER_UNAVAILABLE; } -- cgit From a3c0be63256b7db6325d8dcb599497e8e7905f08 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 24 Jun 2008 16:03:28 +0200 Subject: Change print_access_check to take auth_serversupplied_info instead of current_user Reason: This is the main user of p->current_user which I would like to remove (This used to be commit fd43059b3dfa8cdac9814de1c76f963ba5de9bcb) --- source3/rpc_server/srv_spoolss_nt.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index eaf563eaa9..d58b16c206 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1706,7 +1706,7 @@ WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, if (!user_ok_token(uidtoname(p->pipe_user.ut.uid), NULL, p->pipe_user.nt_user_token, snum) || - !print_access_check(&p->pipe_user, snum, + !print_access_check(p->server_info, snum, printer_default->access_required)) { DEBUG(3, ("access DENIED for printer open\n")); close_printer_handle(p, handle); @@ -5863,7 +5863,8 @@ WERROR _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, S jobname = unistr2_to_ascii_talloc(ctx, &info_1->docname); - Printer->jobid = print_job_start(&p->pipe_user, snum, jobname, Printer->nt_devmode); + Printer->jobid = print_job_start(p->server_info, snum, jobname, + Printer->nt_devmode); /* An error occured in print_job_start() so return an appropriate NT error code. */ @@ -5950,18 +5951,18 @@ static WERROR control_printer(POLICY_HND *handle, uint32 command, switch (command) { case PRINTER_CONTROL_PAUSE: - if (print_queue_pause(&p->pipe_user, snum, &errcode)) { + if (print_queue_pause(p->server_info, snum, &errcode)) { errcode = WERR_OK; } break; case PRINTER_CONTROL_RESUME: case PRINTER_CONTROL_UNPAUSE: - if (print_queue_resume(&p->pipe_user, snum, &errcode)) { + if (print_queue_resume(p->server_info, snum, &errcode)) { errcode = WERR_OK; } break; case PRINTER_CONTROL_PURGE: - if (print_queue_purge(&p->pipe_user, snum, &errcode)) { + if (print_queue_purge(p->server_info, snum, &errcode)) { errcode = WERR_OK; } break; @@ -5993,7 +5994,7 @@ WERROR _spoolss_abortprinter(pipes_struct *p, SPOOL_Q_ABORTPRINTER *q_u, SPOOL_R if (!get_printer_snum(p, handle, &snum, NULL)) return WERR_BADFID; - print_job_delete( &p->pipe_user, snum, Printer->jobid, &errcode ); + print_job_delete(p->server_info, snum, Printer->jobid, &errcode ); return errcode; } @@ -6886,18 +6887,18 @@ WERROR _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u switch (command) { case JOB_CONTROL_CANCEL: case JOB_CONTROL_DELETE: - if (print_job_delete(&p->pipe_user, snum, jobid, &errcode)) { + if (print_job_delete(p->server_info, snum, jobid, &errcode)) { errcode = WERR_OK; } break; case JOB_CONTROL_PAUSE: - if (print_job_pause(&p->pipe_user, snum, jobid, &errcode)) { + if (print_job_pause(p->server_info, snum, jobid, &errcode)) { errcode = WERR_OK; } break; case JOB_CONTROL_RESTART: case JOB_CONTROL_RESUME: - if (print_job_resume(&p->pipe_user, snum, jobid, &errcode)) { + if (print_job_resume(p->server_info, snum, jobid, &errcode)) { errcode = WERR_OK; } break; -- cgit From 8fffa902e06a1ce1f5ca20aab911eed6321f4055 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 26 Jun 2008 16:51:45 +0200 Subject: Fix valgrind errors in _spoolss_addprinterdriver Jerry, this was dropped as part of your SVN r15309 (037f9f83). Can you please check? Thanks, Volker (cherry picked from commit 5aa2411f0b3720b790439359a2dadb23008e936e) (This used to be commit 8e7effd58f7790d6e71e38c990f6cb05456e47e1) --- source3/rpc_server/srv_spoolss_nt.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index d58b16c206..cb784a6539 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -7858,6 +7858,17 @@ WERROR _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u, goto done; } + switch(level) { + case 3: + fstrcpy(driver_name, + driver.info_3->name ? driver.info_3->name : ""); + break; + case 6: + fstrcpy(driver_name, + driver.info_6->name ? driver.info_6->name : ""); + break; + } + /* * I think this is where he DrvUpgradePrinter() hook would be * be called in a driver's interface DLL on a Windows NT 4.0/2k -- cgit From 7b3541f39bda595631188787fca989365478ef33 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 28 Jun 2008 16:09:34 +0200 Subject: Fix a file descriptor leak in add_port_hook This was probably cut&paste from add_printer_hook which further down has the unconditional close(fd). In add_port_hook() we're not interested in the output of 'addport command', so don't create the out fd. (cherry picked from commit 0c5ca2127ac6e3c71e369242376d27429c3aee5e) (This used to be commit 9fe09398b79ae7c5e78182112a8cd2c9b5f99ad3) --- source3/rpc_server/srv_spoolss_nt.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index cb784a6539..72ceb1d517 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -6155,7 +6155,6 @@ WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *portname char *cmd = lp_addport_cmd(); char *command = NULL; int ret; - int fd; SE_PRIV se_printop = SE_PRINT_OPERATOR; bool is_print_op = False; @@ -6179,7 +6178,7 @@ WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *portname if ( is_print_op ) become_root(); - ret = smbrun(command, &fd); + ret = smbrun(command, NULL); if ( is_print_op ) unbecome_root(); @@ -6191,8 +6190,6 @@ WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *portname TALLOC_FREE(command); if ( ret != 0 ) { - if (fd != -1) - close(fd); return WERR_ACCESS_DENIED; } -- cgit From 7cd752bce353923ed10a47670bc4e184f0aa6b8c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 2 Jul 2008 16:11:59 -0700 Subject: Canonicalize servername in the printer functions to remove leading '\\' characters. Ensure we always return consistent names. Jeremy. (This used to be commit fc2178b04743d2f94be7b489b793fc67826557ac) --- source3/rpc_server/srv_spoolss_nt.c | 113 +++++++++++++++++++----------------- 1 file changed, 59 insertions(+), 54 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 72ceb1d517..ca2574f984 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -72,6 +72,18 @@ struct xcv_api_table { WERROR(*fn) (NT_USER_TOKEN *token, RPC_BUFFER *in, RPC_BUFFER *out, uint32 *needed); }; +/******************************************************************** + * Canonicalize servername. + ********************************************************************/ + +static const char *canon_servername(const char *servername) +{ + const char *pservername = servername; + while (*pservername == '\\') { + pservername++; + } + return pservername; +} /* translate between internal status numbers and NT status numbers */ static int nt_printj_status(int v) @@ -455,13 +467,12 @@ static bool set_printer_hnd_name(Printer_entry *Printer, char *handlename) aprinter = handlename; if ( *handlename == '\\' ) { - servername = handlename + 2; - if ( (aprinter = strchr_m( handlename+2, '\\' )) != NULL ) { + servername = canon_servername(handlename); + if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) { *aprinter = '\0'; aprinter++; } - } - else { + } else { servername = ""; } @@ -4660,20 +4671,16 @@ static WERROR enumprinters_level1( uint32 flags, fstring name, * handle enumeration of printers at level 2 ********************************************************************/ -static WERROR enumprinters_level2( uint32 flags, fstring servername, +static WERROR enumprinters_level2( uint32 flags, const char *servername, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { - char *s = servername; - if (flags & PRINTER_ENUM_LOCAL) { return enum_all_printers_info_2(buffer, offered, needed, returned); } if (flags & PRINTER_ENUM_NAME) { - if ((servername[0] == '\\') && (servername[1] == '\\')) - s = servername + 2; - if (is_myname_or_ipaddr(s)) + if (is_myname_or_ipaddr(canon_servername(servername))) return enum_all_printers_info_2(buffer, offered, needed, returned); else return WERR_INVALID_NAME; @@ -4689,7 +4696,7 @@ static WERROR enumprinters_level2( uint32 flags, fstring servername, * handle enumeration of printers at level 5 ********************************************************************/ -static WERROR enumprinters_level5( uint32 flags, fstring servername, +static WERROR enumprinters_level5( uint32 flags, const char *servername, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { @@ -5109,7 +5116,7 @@ WERROR _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GET * fill a DRIVER_INFO_1 struct ********************************************************************/ -static void fill_printer_driver_info_1(DRIVER_INFO_1 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername, fstring architecture) +static void fill_printer_driver_info_1(DRIVER_INFO_1 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, const char *servername, fstring architecture) { init_unistr( &info->name, driver.info_3->name); } @@ -5118,7 +5125,7 @@ static void fill_printer_driver_info_1(DRIVER_INFO_1 *info, NT_PRINTER_DRIVER_IN * construct_printer_driver_info_1 ********************************************************************/ -static WERROR construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, fstring servername, fstring architecture, uint32 version) +static WERROR construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, const char *servername, fstring architecture, uint32 version) { NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; @@ -5145,21 +5152,21 @@ static WERROR construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, fst * fill a printer_info_2 struct ********************************************************************/ -static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername) +static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, const char *servername) { TALLOC_CTX *ctx = talloc_tos(); char *temp = NULL; + const char *cservername = canon_servername(servername); info->version=driver.info_3->cversion; init_unistr( &info->name, driver.info_3->name ); init_unistr( &info->architecture, driver.info_3->environment ); - if (strlen(driver.info_3->driverpath)) { temp = talloc_asprintf(ctx, "\\\\%s%s", - servername, + cservername, driver.info_3->driverpath); init_unistr( &info->driverpath, temp ); } else { @@ -5170,7 +5177,7 @@ static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, NT_PRINTER_DRIVER_IN if (strlen(driver.info_3->datafile)) { temp = talloc_asprintf(ctx, "\\\\%s%s", - servername, + cservername, driver.info_3->datafile); init_unistr( &info->datafile, temp ); } else @@ -5180,7 +5187,7 @@ static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, NT_PRINTER_DRIVER_IN if (strlen(driver.info_3->configfile)) { temp = talloc_asprintf(ctx, "\\\\%s%s", - servername, + cservername, driver.info_3->configfile); init_unistr( &info->configfile, temp ); } else @@ -5192,7 +5199,7 @@ static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, NT_PRINTER_DRIVER_IN * fill a printer_info_2 struct ********************************************************************/ -static WERROR construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fstring servername, fstring architecture, uint32 version) +static WERROR construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, const char *servername, fstring architecture, uint32 version) { NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; @@ -5248,7 +5255,7 @@ static uint32 init_unistr_array(uint16 **uni_array, fstring *char_array, const c if ( servername ) { line = talloc_asprintf(ctx, "\\\\%s%s", - servername, + canon_servername(servername), v); } else { line = talloc_strdup(ctx, v); @@ -5293,10 +5300,11 @@ static uint32 init_unistr_array(uint16 **uni_array, fstring *char_array, const c * fill a printer_info_3 struct ********************************************************************/ -static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername) +static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, const char *servername) { char *temp = NULL; TALLOC_CTX *ctx = talloc_tos(); + const char *cservername = canon_servername(servername); ZERO_STRUCTP(info); @@ -5308,7 +5316,7 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_IN if (strlen(driver.info_3->driverpath)) { temp = talloc_asprintf(ctx, "\\\\%s%s", - servername, + cservername, driver.info_3->driverpath); init_unistr( &info->driverpath, temp ); } else @@ -5318,7 +5326,7 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_IN if (strlen(driver.info_3->datafile)) { temp = talloc_asprintf(ctx, "\\\\%s%s", - servername, + cservername, driver.info_3->datafile); init_unistr( &info->datafile, temp ); } else @@ -5328,7 +5336,7 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_IN if (strlen(driver.info_3->configfile)) { temp = talloc_asprintf(ctx, "\\\\%s%s", - servername, + cservername, driver.info_3->configfile); init_unistr( &info->configfile, temp ); } else @@ -5338,7 +5346,7 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_IN if (strlen(driver.info_3->helpfile)) { temp = talloc_asprintf(ctx, "\\\\%s%s", - servername, + cservername, driver.info_3->helpfile); init_unistr( &info->helpfile, temp ); } else @@ -5349,7 +5357,7 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_IN init_unistr( &info->defaultdatatype, driver.info_3->defaultdatatype ); info->dependentfiles=NULL; - init_unistr_array(&info->dependentfiles, driver.info_3->dependentfiles, servername); + init_unistr_array(&info->dependentfiles, driver.info_3->dependentfiles, cservername); } /******************************************************************** @@ -5357,7 +5365,7 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_IN * fill a printer_info_3 struct ********************************************************************/ -static WERROR construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fstring servername, fstring architecture, uint32 version) +static WERROR construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, const char *servername, fstring architecture, uint32 version) { NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; @@ -5416,11 +5424,12 @@ static WERROR construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fst * fill a printer_info_6 struct - we know that driver is really level 3. This sucks. JRA. ********************************************************************/ -static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername) +static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, const char *servername) { char *temp = NULL; fstring nullstr; TALLOC_CTX *ctx = talloc_tos(); + const char *cservername = canon_servername(servername); ZERO_STRUCTP(info); memset(&nullstr, '\0', sizeof(fstring)); @@ -5433,7 +5442,7 @@ static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_IN if (strlen(driver.info_3->driverpath)) { temp = talloc_asprintf(ctx, "\\\\%s%s", - servername, + cservername, driver.info_3->driverpath); init_unistr( &info->driverpath, temp ); } else @@ -5443,7 +5452,7 @@ static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_IN if (strlen(driver.info_3->datafile)) { temp = talloc_asprintf(ctx, "\\\\%s%s", - servername, + cservername, driver.info_3->datafile); init_unistr( &info->datafile, temp ); } else @@ -5453,7 +5462,7 @@ static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_IN if (strlen(driver.info_3->configfile)) { temp = talloc_asprintf(ctx, "\\\\%s%s", - servername, + cservername, driver.info_3->configfile); init_unistr( &info->configfile, temp ); } else @@ -5463,7 +5472,7 @@ static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_IN if (strlen(driver.info_3->helpfile)) { temp = talloc_asprintf(ctx, "\\\\%s%s", - servername, + cservername, driver.info_3->helpfile); init_unistr( &info->helpfile, temp ); } else @@ -5497,7 +5506,7 @@ static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_IN ********************************************************************/ static WERROR construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, - fstring servername, fstring architecture, uint32 version) + const char *servername, fstring architecture, uint32 version) { NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; @@ -5564,7 +5573,7 @@ static void free_printer_driver_info_6(DRIVER_INFO_6 *info) /**************************************************************************** ****************************************************************************/ -static WERROR getprinterdriver2_level1(fstring servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinterdriver2_level1(const char *servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_1 *info=NULL; WERROR result; @@ -5602,7 +5611,7 @@ out: /**************************************************************************** ****************************************************************************/ -static WERROR getprinterdriver2_level2(fstring servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinterdriver2_level2(const char *servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_2 *info=NULL; WERROR result; @@ -5640,7 +5649,7 @@ out: /**************************************************************************** ****************************************************************************/ -static WERROR getprinterdriver2_level3(fstring servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinterdriver2_level3(const char *servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_3 info; WERROR result; @@ -5676,7 +5685,7 @@ out: /**************************************************************************** ****************************************************************************/ -static WERROR getprinterdriver2_level6(fstring servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinterdriver2_level6(const char *servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_6 info; WERROR result; @@ -6910,7 +6919,7 @@ WERROR _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u Enumerates all printer drivers at level 1. ****************************************************************************/ -static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enumprinterdrivers_level1(const char *servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int i; int ndrivers; @@ -6994,7 +7003,7 @@ out: Enumerates all printer drivers at level 2. ****************************************************************************/ -static WERROR enumprinterdrivers_level2(fstring servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enumprinterdrivers_level2(const char *servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int i; int ndrivers; @@ -7079,7 +7088,7 @@ out: Enumerates all printer drivers at level 3. ****************************************************************************/ -static WERROR enumprinterdrivers_level3(fstring servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enumprinterdrivers_level3(const char *servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int i; int ndrivers; @@ -7175,7 +7184,7 @@ WERROR _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; uint32 *returned = &r_u->returned; - + const char *cservername; fstring servername; fstring architecture; @@ -7196,16 +7205,18 @@ WERROR _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS unistr2_to_ascii(architecture, &q_u->environment, sizeof(architecture)); unistr2_to_ascii(servername, &q_u->name, sizeof(servername)); - if ( !is_myname_or_ipaddr( servername ) ) + cservername = canon_servername(servername); + + if (!is_myname_or_ipaddr(cservername)) return WERR_UNKNOWN_PRINTER_DRIVER; switch (level) { case 1: - return enumprinterdrivers_level1(servername, architecture, buffer, offered, needed, returned); + return enumprinterdrivers_level1(cservername, architecture, buffer, offered, needed, returned); case 2: - return enumprinterdrivers_level2(servername, architecture, buffer, offered, needed, returned); + return enumprinterdrivers_level2(cservername, architecture, buffer, offered, needed, returned); case 3: - return enumprinterdrivers_level3(servername, architecture, buffer, offered, needed, returned); + return enumprinterdrivers_level3(cservername, architecture, buffer, offered, needed, returned); default: return WERR_UNKNOWN_LEVEL; } @@ -7992,7 +8003,7 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen char *path = NULL; char *long_archi = NULL; char *servername = NULL; - char *pservername = NULL; + const char *pservername = NULL; const char *short_archi; DRIVER_DIRECTORY_1 *info=NULL; WERROR result = WERR_OK; @@ -8007,15 +8018,9 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen return WERR_NOMEM; } - /* check for beginning double '\'s and that the server - long enough */ - - pservername = servername; - if ( *pservername == '\\' && strlen(servername)>2 ) { - pservername += 2; - } + pservername = canon_servername(servername); - if ( !is_myname_or_ipaddr( pservername ) ) + if ( !is_myname_or_ipaddr(pservername)) return WERR_INVALID_PARAM; if (!(short_archi = get_short_archi(long_archi))) -- cgit From 1335da2a7cc639310e5d389e8e8dbe67c4e7ca25 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 20 Jul 2008 11:04:31 +0200 Subject: Refactoring: Change calling conventions for cli_rpc_pipe_open_noauth Pass in ndr_syntax_id instead of pipe_idx, return NTSTATUS (This used to be commit 9abc9dc4dc13bd3e42f98eff64eacf24b51f5779) --- source3/rpc_server/srv_spoolss_nt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index ca2574f984..f80240042c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2617,7 +2617,8 @@ static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe, * Now start the NT Domain stuff :-). */ - if ( !(*pp_pipe = cli_rpc_pipe_open_noauth(the_cli, PI_SPOOLSS, &ret)) ) { + ret = cli_rpc_pipe_open_noauth(the_cli, &syntax_spoolss, pp_pipe); + if (!NT_STATUS_IS_OK(ret)) { DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n", remote_machine, nt_errstr(ret))); cli_shutdown(the_cli); -- cgit From 40b133eb88600049d1aed403540d441c7f23c5b9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 13 Aug 2008 16:52:53 -0700 Subject: Fix coverity CID: 594. Resource leak on error path. Jeremy. (This used to be commit 1f38b9963c4ec0d73da496a72ba4ee74d8d581c9) --- source3/rpc_server/srv_spoolss_nt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/rpc_server/srv_spoolss_nt.c') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index f80240042c..635898a9d5 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -5037,8 +5037,10 @@ static WERROR getprinter_level_7(Printer_entry *print_hnd, int snum, RPC_BUFFER if((printer=SMB_MALLOC_P(PRINTER_INFO_7))==NULL) return WERR_NOMEM; - if (!construct_printer_info_7(print_hnd, printer, snum)) - return WERR_NOMEM; + if (!construct_printer_info_7(print_hnd, printer, snum)) { + result = WERR_NOMEM; + goto out; + } /* check the required size. */ *needed += spoolss_size_printer_info_7(printer); -- cgit