diff options
author | Jeremy Allison <jra@samba.org> | 2000-07-22 00:48:29 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2000-07-22 00:48:29 +0000 |
commit | 78bbcec21b0683aa859aceeb42b106580d48e467 (patch) | |
tree | c669688332a66ef6ce497e70952e5d776e26527b | |
parent | 9f5e9acf778f093dd1ee559f040ee1b2a7f9e5ec (diff) | |
download | samba-78bbcec21b0683aa859aceeb42b106580d48e467.tar.gz samba-78bbcec21b0683aa859aceeb42b106580d48e467.tar.bz2 samba-78bbcec21b0683aa859aceeb42b106580d48e467.zip |
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)
-rw-r--r-- | source3/include/nt_printing.h | 1 | ||||
-rw-r--r-- | source3/include/proto.h | 42 | ||||
-rw-r--r-- | source3/printing/nt_printing.c | 25 | ||||
-rw-r--r-- | source3/rpc_parse/parse_spoolss.c | 4 | ||||
-rw-r--r-- | source3/rpc_server/srv_spoolss_nt.c | 254 |
5 files changed, 171 insertions, 155 deletions
diff --git a/source3/include/nt_printing.h b/source3/include/nt_printing.h index 9282367885..58a4dec3a0 100644 --- a/source3/include/nt_printing.h +++ b/source3/include/nt_printing.h @@ -239,6 +239,7 @@ typedef struct nt_printer_info_level_2 fstring sharename; fstring portname; fstring drivername; + fstring comment; fstring location; NT_DEVICEMODE *devmode; fstring sepfile; diff --git a/source3/include/proto.h b/source3/include/proto.h index 128079d511..696ccf07c6 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -1671,7 +1671,7 @@ void update_a_form(nt_forms_struct **list, const FORM *form, int count); int get_ntdrivers(fstring **list, char *architecture); void get_short_archi(char *short_archi, char *long_archi); uint32 get_a_printer_driver_9x_compatible(pstring line, fstring model); -uint32 del_a_printer(char *portname); +uint32 del_a_printer(char *sharename); BOOL add_a_specific_param(NT_PRINTER_INFO_LEVEL_2 *info_2, NT_PRINTER_PARAM *param); BOOL unlink_specific_param_if_exist(NT_PRINTER_INFO_LEVEL_2 *info_2, NT_PRINTER_PARAM *param); NT_DEVICEMODE *construct_nt_devicemode(const fstring default_devicename); @@ -3050,49 +3050,49 @@ uint32 _spoolss_open_printer_ex( const UNISTR2 *printername, POLICY_HND *handle); uint32 _spoolss_closeprinter(POLICY_HND *handle); uint32 _spoolss_deleteprinter(POLICY_HND *handle); -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, uint8 **data, uint32 *needed); -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); -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); uint32 _spoolss_enumprinters( uint32 flags, const UNISTR2 *servername, uint32 level, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned); uint32 _spoolss_getprinter(POLICY_HND *handle, uint32 level, NEW_BUFFER *buffer, uint32 offered, uint32 *needed); -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); -uint32 _spoolss_startpageprinter(const POLICY_HND *handle); -uint32 _spoolss_endpageprinter(const POLICY_HND *handle); -uint32 _spoolss_startdocprinter(const POLICY_HND *handle, uint32 level, +uint32 _spoolss_startpageprinter(POLICY_HND *handle); +uint32 _spoolss_endpageprinter(POLICY_HND *handle); +uint32 _spoolss_startdocprinter(POLICY_HND *handle, uint32 level, pipes_struct *p, DOC_INFO *docinfo, uint32 *jobid); -uint32 _spoolss_enddocprinter(const POLICY_HND *handle); -uint32 _spoolss_writeprinter( const POLICY_HND *handle, +uint32 _spoolss_enddocprinter(POLICY_HND *handle); +uint32 _spoolss_writeprinter( POLICY_HND *handle, uint32 buffer_size, - const uint8 *buffer, + uint8 *buffer, uint32 *buffer_written); -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, uint32 command, pipes_struct *p); -uint32 _spoolss_fcpn(const POLICY_HND *handle); -uint32 _spoolss_addjob(const POLICY_HND *handle, uint32 level, +uint32 _spoolss_fcpn(POLICY_HND *handle); +uint32 _spoolss_addjob(POLICY_HND *handle, uint32 level, NEW_BUFFER *buffer, uint32 offered); uint32 _spoolss_enumjobs( POLICY_HND *handle, uint32 firstjob, uint32 numofjobs, uint32 level, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned); -uint32 _spoolss_schedulejob( const POLICY_HND *handle, uint32 jobid); -uint32 _spoolss_setjob( const POLICY_HND *handle, +uint32 _spoolss_schedulejob( POLICY_HND *handle, uint32 jobid); +uint32 _spoolss_setjob( POLICY_HND *handle, uint32 jobid, uint32 level, pipes_struct *p, @@ -3101,7 +3101,7 @@ uint32 _spoolss_setjob( const POLICY_HND *handle, uint32 _spoolss_enumprinterdrivers( UNISTR2 *name, UNISTR2 *environment, uint32 level, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned); -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); uint32 _spoolss_enumports( UNISTR2 *name, uint32 level, @@ -3118,22 +3118,22 @@ uint32 _spoolss_addprinterdriver( const UNISTR2 *server_name, uint32 _spoolss_getprinterdriverdirectory(UNISTR2 *name, UNISTR2 *uni_environment, uint32 level, NEW_BUFFER *buffer, uint32 offered, uint32 *needed); -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, uint32 *out_max_data_len, uint8 **data_out, uint32 *out_data_len); -uint32 _spoolss_setprinterdata( const POLICY_HND *handle, +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_addform( const POLICY_HND *handle, +uint32 _spoolss_addform( POLICY_HND *handle, uint32 level, const FORM *form); -uint32 _spoolss_setform( const POLICY_HND *handle, +uint32 _spoolss_setform( POLICY_HND *handle, const UNISTR2 *uni_name, uint32 level, const FORM *form); diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c index d1cb7e8f34..9e7862eda0 100644 --- a/source3/printing/nt_printing.c +++ b/source3/printing/nt_printing.c @@ -644,13 +644,13 @@ static int pack_specifics(NT_PRINTER_PARAM *param, char *buf, int buflen) delete a printer - this just deletes the printer info file, any open handles are not affected ****************************************************************************/ -uint32 del_a_printer(char *portname) +uint32 del_a_printer(char *sharename) { pstring key; TDB_DATA kbuf; slprintf(key, sizeof(key), "%s%s", - PRINTERS_PREFIX, portname); + PRINTERS_PREFIX, sharename); kbuf.dptr=key; kbuf.dsize=strlen(key)+1; @@ -678,8 +678,8 @@ static uint32 add_a_printer_2(NT_PRINTER_INFO_LEVEL_2 *info) * Samba manages only local printers. * we currently don't support things like path=\\other_server\printer */ - if (info->servername[0]!='\0') - { + + if (info->servername[0]!='\0') { trim_string(info->printername, info->servername, NULL); trim_string(info->printername, "\\", NULL); info->servername[0]='\0'; @@ -704,7 +704,7 @@ static uint32 add_a_printer_2(NT_PRINTER_INFO_LEVEL_2 *info) again: len = 0; - len += tdb_pack(buf+len, buflen-len, "dddddddddddffffffffff", + len += tdb_pack(buf+len, buflen-len, "dddddddddddfffffffffff", info->attributes, info->priority, info->default_priority, @@ -721,6 +721,7 @@ static uint32 add_a_printer_2(NT_PRINTER_INFO_LEVEL_2 *info) info->sharename, info->portname, info->drivername, + info->comment, info->location, info->sepfile, info->printprocessor, @@ -1093,6 +1094,7 @@ static uint32 get_a_printer_2_default(NT_PRINTER_INFO_LEVEL_2 **info_ptr, fstrin fstrcpy(info.printername, sharename); fstrcpy(info.portname, sharename); fstrcpy(info.drivername, lp_printerdriver(snum)); + fstrcpy(info.comment, ""); fstrcpy(info.printprocessor, "winprint"); fstrcpy(info.datatype, "RAW"); @@ -1152,7 +1154,7 @@ static uint32 get_a_printer_2(NT_PRINTER_INFO_LEVEL_2 **info_ptr, fstring sharen if (!dbuf.dptr) return 1; #endif - len += tdb_unpack(dbuf.dptr+len, dbuf.dsize-len, "dddddddddddffffffffff", + len += tdb_unpack(dbuf.dptr+len, dbuf.dsize-len, "dddddddddddfffffffffff", &info.attributes, &info.priority, &info.default_priority, @@ -1169,27 +1171,25 @@ static uint32 get_a_printer_2(NT_PRINTER_INFO_LEVEL_2 **info_ptr, fstring sharen info.sharename, info.portname, info.drivername, + info.comment, info.location, info.sepfile, info.printprocessor, info.datatype, info.parameters); - info.attributes |= PRINTER_ATTRIBUTE_RAW_ONLY; /* Samba has to have raw drivers. */ + /* Samba has to have shared raw drivers. */ + info.attributes |= (PRINTER_ATTRIBUTE_SHARED|PRINTER_ATTRIBUTE_RAW_ONLY); len += unpack_devicemode(&info.devmode,dbuf.dptr+len, dbuf.dsize-len); len += unpack_specifics(&info.specific,dbuf.dptr+len, dbuf.dsize-len); -#if 1 /* JRATEST */ nt_printing_getsec(sharename, &info.secdesc_buf); -#endif /* JRATEST */ - - fstrcpy(info.sharename, ""); safe_free(dbuf.dptr); *info_ptr=memdup(&info, sizeof(info)); - DEBUG(9,("Unpacked printer [%s] running drier [%s]\n", + DEBUG(9,("Unpacked printer [%s] running driver [%s]\n", sharename, info.drivername)); @@ -1233,6 +1233,7 @@ static uint32 dump_a_printer(NT_PRINTER_INFO_LEVEL printer, uint32 level) DEBUGADD(106,("sharename:[%s]\n", info2->sharename)); DEBUGADD(106,("portname:[%s]\n", info2->portname)); DEBUGADD(106,("drivername:[%s]\n", info2->drivername)); + DEBUGADD(106,("comment:[%s]\n", info2->comment)); DEBUGADD(106,("location:[%s]\n", info2->location)); DEBUGADD(106,("sepfile:[%s]\n", info2->sepfile)); DEBUGADD(106,("printprocessor:[%s]\n", info2->printprocessor)); diff --git a/source3/rpc_parse/parse_spoolss.c b/source3/rpc_parse/parse_spoolss.c index 8574112802..fd120a57ec 100644 --- a/source3/rpc_parse/parse_spoolss.c +++ b/source3/rpc_parse/parse_spoolss.c @@ -4236,8 +4236,7 @@ BOOL uni_2_asc_printer_info_2(const SPOOL_PRINTER_INFO_LEVEL_2 *uni, DEBUG(7,("Converting from UNICODE to ASCII\n")); time_unix=time(NULL); - if (*asc==NULL) - { + if (*asc==NULL) { DEBUGADD(8,("allocating memory\n")); *asc=(NT_PRINTER_INFO_LEVEL_2 *)malloc(sizeof(NT_PRINTER_INFO_LEVEL_2)); @@ -4268,6 +4267,7 @@ BOOL uni_2_asc_printer_info_2(const SPOOL_PRINTER_INFO_LEVEL_2 *uni, unistr2_to_ascii(d->sharename, &uni->sharename, sizeof(d->sharename)-1); unistr2_to_ascii(d->portname, &uni->portname, sizeof(d->portname)-1); unistr2_to_ascii(d->drivername, &uni->drivername, sizeof(d->drivername)-1); + unistr2_to_ascii(d->comment, &uni->comment, sizeof(d->comment)-1); unistr2_to_ascii(d->location, &uni->location, sizeof(d->location)-1); unistr2_to_ascii(d->sepfile, &uni->sepfile, sizeof(d->sepfile)-1); unistr2_to_ascii(d->printprocessor, &uni->printprocessor, sizeof(d->printprocessor)-1); 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; @@ -251,28 +251,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. ****************************************************************************/ static BOOL set_printer_hnd_accesstype(POLICY_HND *hnd, uint32 access_required) @@ -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,7 +3050,7 @@ 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); @@ -3063,11 +3058,34 @@ static uint32 update_printer_sec(const POLICY_HND *handle, uint32 level, } /******************************************************************** + 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) |