3 * Unix SMB/Netbios implementation.
5 * RPC Pipe client / server routines
6 * Copyright (C) Andrew Tridgell 1992-2000,
7 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
8 * Copyright (C) Jean François Micouleau 1998-2000.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 extern int DEBUGLEVEL;
29 extern pstring global_myname;
31 #ifndef MAX_OPEN_PRINTER_EXS
32 #define MAX_OPEN_PRINTER_EXS 50
35 #define PRINTER_HANDLE_IS_PRINTER 0
36 #define PRINTER_HANDLE_IS_PRINTSERVER 1
38 /* structure to store the printer handles */
39 /* and a reference to what it's pointing to */
40 /* and the notify info asked about */
41 /* that's the central struct */
42 typedef struct _Printer{
47 BOOL document_started;
49 int jobid; /* jobid in printing backend */
50 POLICY_HND printer_hnd;
54 fstring printerservername;
63 SPOOL_NOTIFY_OPTION *option;
71 typedef struct _counter_printer_0 {
79 static ubi_dlList Printer_list;
80 static ubi_dlList counter_list;
83 #define OPEN_HANDLE(pnum) ((pnum!=NULL) && (pnum->open!=False))
85 /* translate between internal status numbers and NT status numbers */
86 static int nt_printj_status(int v)
90 return PRINTER_STATUS_PAUSED;
99 static int nt_printq_status(int v)
103 return PRINTER_STATUS_ERROR;
112 /****************************************************************************
113 initialise printer handle states...
114 ****************************************************************************/
115 void init_printer_hnd(void)
117 ubi_dlInitList(&Printer_list);
118 ubi_dlInitList(&counter_list);
121 /****************************************************************************
122 create a unique printer handle
123 ****************************************************************************/
124 static void create_printer_hnd(POLICY_HND *hnd)
126 static uint32 prt_hnd_low = 0;
127 static uint32 prt_hnd_high = 0;
129 if (hnd == NULL) return;
131 /* i severely doubt that prt_hnd_high will ever be non-zero... */
133 if (prt_hnd_low == 0) prt_hnd_high++;
135 SIVAL(hnd->data, 0 , 0x0); /* first bit must be null */
136 SIVAL(hnd->data, 4 , prt_hnd_low ); /* second bit is incrementing */
137 SIVAL(hnd->data, 8 , prt_hnd_high); /* second bit is incrementing */
138 SIVAL(hnd->data, 12, time(NULL)); /* something random */
139 SIVAL(hnd->data, 16, sys_getpid()); /* something more random */
142 /****************************************************************************
143 find printer index by handle
144 ****************************************************************************/
145 static Printer_entry *find_printer_index_by_hnd(const POLICY_HND *hnd)
147 Printer_entry *find_printer;
149 find_printer = (Printer_entry *)ubi_dlFirst(&Printer_list);
151 for(; find_printer; find_printer = (Printer_entry *)ubi_dlNext(find_printer)) {
153 if (memcmp(&(find_printer->printer_hnd), hnd, sizeof(*hnd)) == 0)
155 DEBUG(4,("Found printer handle \n"));
156 /*dump_data(4, hnd->data, sizeof(hnd->data));*/
161 DEBUG(3,("Whoops, Printer handle not found: "));
162 /*dump_data(4, hnd->data, sizeof(hnd->data));*/
166 /****************************************************************************
168 ****************************************************************************/
169 static void clear_handle(POLICY_HND *hnd)
171 memset(hnd->data, 0, POLICY_HND_SIZE);
174 /****************************************************************************
175 close printer index by handle
176 ****************************************************************************/
177 static BOOL close_printer_handle(POLICY_HND *hnd)
179 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
181 if (!OPEN_HANDLE(Printer))
183 DEBUG(3,("Error closing printer handle\n"));
188 Printer->notify.flags=0;
189 Printer->notify.options=0;
190 Printer->notify.localmachine[0]='\0';
191 Printer->notify.printerlocal=0;
192 safe_free(Printer->notify.option);
193 Printer->notify.option=NULL;
197 ubi_dlRemThis(&Printer_list, Printer);
204 /****************************************************************************
205 delete a printer given a handle
206 ****************************************************************************/
207 static BOOL delete_printer_handle(POLICY_HND *hnd)
209 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
211 if (!OPEN_HANDLE(Printer))
213 DEBUG(3,("Error closing printer handle\n"));
217 if (del_a_printer(Printer->dev.printername) != 0) {
218 DEBUG(3,("Error deleting printer %s\n", Printer->dev.printername));
225 /****************************************************************************
226 return the snum of a printer corresponding to an handle
227 ****************************************************************************/
228 static BOOL get_printer_snum(const POLICY_HND *hnd, int *number)
230 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
232 if (!OPEN_HANDLE(Printer)) {
233 DEBUG(3,("Error getting printer - take a nap quickly !\n"));
237 switch (Printer->printer_type) {
238 case PRINTER_HANDLE_IS_PRINTER:
239 DEBUG(4,("short name:%s\n", Printer->dev.printername));
240 *number = print_queue_snum(Printer->dev.printername);
241 return (*number != -1);
242 case PRINTER_HANDLE_IS_PRINTSERVER:
251 /****************************************************************************
252 find first available printer slot. creates a printer handle for you.
253 ****************************************************************************/
254 static BOOL open_printer_hnd(POLICY_HND *hnd)
256 Printer_entry *new_printer;
258 if((new_printer=(Printer_entry *)malloc(sizeof(Printer_entry))) == NULL)
261 ZERO_STRUCTP(new_printer);
263 new_printer->open = True;
264 new_printer->notify.option=NULL;
266 memcpy(&(new_printer->printer_hnd), hnd, sizeof(*hnd));
268 ubi_dlAddHead( &Printer_list, (ubi_dlNode *)new_printer);
273 /****************************************************************************
274 set printer handle type.
275 ****************************************************************************/
276 static BOOL set_printer_hnd_accesstype(POLICY_HND *hnd, uint32 access_required)
278 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
280 if (!OPEN_HANDLE(Printer)) {
281 DEBUG(4,("Error setting printer type=%x", access_required));
285 DEBUG(4,("Setting printer access=%x\n", access_required));
286 Printer->access = access_required;
290 /****************************************************************************
291 set printer handle type.
292 check if it's \\server or \\server\printer
293 ****************************************************************************/
294 static BOOL set_printer_hnd_printertype(POLICY_HND *hnd, char *printername)
296 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
298 if (!OPEN_HANDLE(Printer)) {
299 DEBUGADD(4,("Error setting printer name %s", printername));
303 DEBUG(3,("Setting printer type=%s\n", printername));
305 if ( strlen(printername) < 3 ) {
306 DEBUGADD(4,("A print server must have at least 1 char ! %s\n", printername));
310 /* it's a print server */
311 if (!strchr(printername+2, '\\')) {
312 DEBUGADD(4,("Printer is a print server\n"));
313 Printer->printer_type = PRINTER_HANDLE_IS_PRINTSERVER;
318 DEBUGADD(4,("Printer is a printer\n"));
319 Printer->printer_type = PRINTER_HANDLE_IS_PRINTER;
326 /****************************************************************************
327 set printer handle printername.
328 ****************************************************************************/
329 static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername)
331 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
332 NT_PRINTER_INFO_LEVEL printer;
334 int n_services=lp_numservices();
338 if (!OPEN_HANDLE(Printer)) {
339 DEBUG(0,("Error setting printer name=%s\n", printername));
343 DEBUG(4,("Setting printer name=%s (len=%d)\n", printername, strlen(printername)));
345 if (Printer->printer_type==PRINTER_HANDLE_IS_PRINTSERVER) {
346 ZERO_STRUCT(Printer->dev.printerservername);
347 strncpy(Printer->dev.printerservername, printername, strlen(printername));
351 if (Printer->printer_type!=PRINTER_HANDLE_IS_PRINTER)
354 aprinter=strchr(printername+2, '\\');
357 DEBUGADD(5,("searching for [%s] (len=%d)\n", aprinter, strlen(aprinter)));
360 * store the Samba share name in it
361 * in back we have the long printer name
362 * need to iterate all the snum and do a
363 * get_a_printer each time to find the printer
364 * faster to do it here than later.
367 for (snum=0;snum<n_services && found==False;snum++) {
369 if ( !(lp_snum_ok(snum) && lp_print_ok(snum) ) )
372 DEBUGADD(5,("share:%s\n",lp_servicename(snum)));
374 if (get_a_printer(&printer, 2, lp_servicename(snum))!=0)
377 DEBUG(10,("set_printer_hnd_printername: printername [%s], aprinter [%s]\n",
378 printer.info_2->printername, aprinter ));
380 if ( strlen(printer.info_2->printername) != strlen(aprinter) ) {
381 free_a_printer(printer, 2);
385 if ( strncasecmp(printer.info_2->printername, aprinter, strlen(aprinter))) {
386 free_a_printer(printer, 2);
394 * if we haven't found a printer with the given printername
395 * then it can be a share name as you can open both \\server\printer and
400 * we still check if the printer description file exists as NT won't be happy
401 * if we reply OK in the openprinter call and can't reply in the subsequent RPC calls
405 DEBUGADD(5,("Printer not found, checking for share now\n"));
407 for (snum=0;snum<n_services && found==False;snum++) {
409 if ( !(lp_snum_ok(snum) && lp_print_ok(snum) ) )
412 DEBUGADD(5,("share:%s\n",lp_servicename(snum)));
414 if (get_a_printer(&printer, 2, lp_servicename(snum))!=0)
417 DEBUG(10,("set_printer_hnd_printername: printername [%s], aprinter [%s]\n",
418 printer.info_2->printername, aprinter ));
420 if ( strlen(lp_servicename(snum)) != strlen(aprinter) ) {
421 free_a_printer(printer, 2);
425 if ( strncasecmp(lp_servicename(snum), aprinter, strlen(aprinter))) {
426 free_a_printer(printer, 2);
435 DEBUGADD(4,("Printer not found\n"));
440 DEBUGADD(4,("Printer found: %s -> %s[%x]\n",printer.info_2->printername, lp_servicename(snum),snum));
441 ZERO_STRUCT(Printer->dev.printername);
442 strncpy(Printer->dev.printername, lp_servicename(snum), strlen(lp_servicename(snum)));
443 free_a_printer(printer, 2);
448 /********************************************************************
449 Return True is the handle is a print server.
450 ********************************************************************/
451 static BOOL handle_is_printserver(const POLICY_HND *handle)
453 Printer_entry *Printer=find_printer_index_by_hnd(handle);
455 if (!OPEN_HANDLE(Printer))
458 if (Printer->printer_type != PRINTER_HANDLE_IS_PRINTSERVER)
464 /****************************************************************************
465 allocate more memory for a BUFFER.
466 ****************************************************************************/
467 static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size)
475 /* damn, I'm doing the reverse operation of prs_grow() :) */
476 if (buffer_size < prs_data_size(ps))
479 extra_space = buffer_size - prs_data_size(ps);
482 * save the offset and move to the end of the buffer
483 * prs_grow() checks the extra_space against the offset
485 old_offset=prs_offset(ps);
486 prs_set_offset(ps, prs_data_size(ps));
488 if (!prs_grow(ps, extra_space))
491 prs_set_offset(ps, old_offset);
493 buffer->string_at_end=prs_data_size(ps);
498 /********************************************************************
499 * spoolss_open_printer
501 * called from the spoolss dispatcher
502 ********************************************************************/
503 uint32 _spoolss_open_printer_ex( const UNISTR2 *printername,
504 const PRINTER_DEFAULT *printer_default,
505 uint32 user_switch, SPOOL_USER_CTR user_ctr,
510 clear_handle(handle);
512 if (printername == NULL)
513 return ERROR_INVALID_PRINTER_NAME;
515 /* some sanity check because you can open a printer or a print server */
516 /* aka: \\server\printer or \\server */
517 unistr2_to_ascii(name, printername, sizeof(name)-1);
519 DEBUGADD(3,("checking name: %s\n",name));
521 create_printer_hnd(handle);
523 open_printer_hnd(handle);
525 if (!set_printer_hnd_printertype(handle, name)) {
526 close_printer_handle(handle);
527 return ERROR_INVALID_PRINTER_NAME;
530 if (!set_printer_hnd_printername(handle, name)) {
531 close_printer_handle(handle);
532 return ERROR_INVALID_PRINTER_NAME;
536 if (printer_default->datatype_ptr != NULL)
538 unistr2_to_ascii(datatype, printer_default->datatype, sizeof(datatype)-1);
539 set_printer_hnd_datatype(handle, datatype);
542 set_printer_hnd_datatype(handle, "");
545 if (!set_printer_hnd_accesstype(handle, printer_default->access_required)) {
546 close_printer_handle(handle);
547 return ERROR_ACCESS_DENIED;
550 return NT_STATUS_NO_PROBLEMO;
553 /****************************************************************************
554 ****************************************************************************/
555 static BOOL convert_printer_info(const SPOOL_PRINTER_INFO_LEVEL *uni,
556 NT_PRINTER_INFO_LEVEL *printer, uint32 level)
560 uni_2_asc_printer_info_2(uni->info_2, &(printer->info_2));
569 static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL *uni,
570 NT_PRINTER_DRIVER_INFO_LEVEL *printer, uint32 level)
574 printer->info_3=NULL;
575 uni_2_asc_printer_driver_3(uni->info_3, &(printer->info_3));
578 printer->info_6=NULL;
579 uni_2_asc_printer_driver_6(uni->info_6, &(printer->info_6));
588 static BOOL convert_devicemode(DEVICEMODE devmode, NT_DEVICEMODE *nt_devmode)
590 unistr_to_dos(nt_devmode->devicename, (char *)devmode.devicename.buffer, 31);
591 unistr_to_dos(nt_devmode->formname, (char *)devmode.formname.buffer, 31);
593 nt_devmode->specversion=devmode.specversion;
594 nt_devmode->driverversion=devmode.driverversion;
595 nt_devmode->size=devmode.size;
596 nt_devmode->driverextra=devmode.driverextra;
597 nt_devmode->fields=devmode.fields;
598 nt_devmode->orientation=devmode.orientation;
599 nt_devmode->papersize=devmode.papersize;
600 nt_devmode->paperlength=devmode.paperlength;
601 nt_devmode->paperwidth=devmode.paperwidth;
602 nt_devmode->scale=devmode.scale;
603 nt_devmode->copies=devmode.copies;
604 nt_devmode->defaultsource=devmode.defaultsource;
605 nt_devmode->printquality=devmode.printquality;
606 nt_devmode->color=devmode.color;
607 nt_devmode->duplex=devmode.duplex;
608 nt_devmode->yresolution=devmode.yresolution;
609 nt_devmode->ttoption=devmode.ttoption;
610 nt_devmode->collate=devmode.collate;
612 nt_devmode->logpixels=devmode.logpixels;
613 nt_devmode->bitsperpel=devmode.bitsperpel;
614 nt_devmode->pelswidth=devmode.pelswidth;
615 nt_devmode->pelsheight=devmode.pelsheight;
616 nt_devmode->displayflags=devmode.displayflags;
617 nt_devmode->displayfrequency=devmode.displayfrequency;
618 nt_devmode->icmmethod=devmode.icmmethod;
619 nt_devmode->icmintent=devmode.icmintent;
620 nt_devmode->mediatype=devmode.mediatype;
621 nt_devmode->dithertype=devmode.dithertype;
622 nt_devmode->reserved1=devmode.reserved1;
623 nt_devmode->reserved2=devmode.reserved2;
624 nt_devmode->panningwidth=devmode.panningwidth;
625 nt_devmode->panningheight=devmode.panningheight;
627 if (nt_devmode->driverextra != 0)
629 /* if we had a previous private delete it and make a new one */
630 if (nt_devmode->private != NULL)
631 free(nt_devmode->private);
632 if((nt_devmode->private=(uint8 *)malloc(nt_devmode->driverextra * sizeof(uint8))) == NULL)
634 memcpy(nt_devmode->private, devmode.private, nt_devmode->driverextra);
640 /********************************************************************
641 * api_spoolss_closeprinter
642 ********************************************************************/
643 uint32 _spoolss_closeprinter(POLICY_HND *handle)
645 if (!close_printer_handle(handle))
646 return ERROR_INVALID_HANDLE;
648 return NT_STATUS_NO_PROBLEMO;
651 /********************************************************************
652 * api_spoolss_deleteprinter
653 ********************************************************************/
654 uint32 _spoolss_deleteprinter(POLICY_HND *handle)
656 if (!delete_printer_handle(handle))
657 return ERROR_INVALID_HANDLE;
659 return NT_STATUS_NO_PROBLEMO;
662 /********************************************************************
663 GetPrinterData on a printer server Handle.
664 ********************************************************************/
665 static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **data, uint32 *needed, uint32 in_size)
669 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
671 if (!strcmp(value, "BeepEnabled"))
674 if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL)
676 SIVAL(*data, 0, 0x01);
681 if (!strcmp(value, "EventLog"))
684 if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL)
686 SIVAL(*data, 0, 0x1B);
691 if (!strcmp(value, "NetPopup"))
694 if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL)
696 SIVAL(*data, 0, 0x01);
701 if (!strcmp(value, "MajorVersion"))
704 if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL)
706 SIVAL(*data, 0, 0x02);
711 if (!strcmp(value, "DefaultSpoolDirectory"))
713 pstring string="You are using a Samba server";
715 *needed = 2*(strlen(string)+1);
716 if((*data = (uint8 *)malloc( ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL)
718 memset(*data, 0, (*needed > in_size) ? *needed:in_size);
720 /* it's done by hand ready to go on the wire */
721 for (i=0; i<strlen(string); i++)
723 (*data)[2*i]=string[i];
729 if (!strcmp(value, "Architecture"))
731 pstring string="Windows NT x86";
733 *needed = 2*(strlen(string)+1);
734 if((*data = (uint8 *)malloc( ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL)
736 memset(*data, 0, (*needed > in_size) ? *needed:in_size);
737 for (i=0; i<strlen(string); i++)
739 (*data)[2*i]=string[i];
748 /********************************************************************
749 GetPrinterData on a printer Handle.
750 ********************************************************************/
751 static BOOL getprinterdata_printer(const POLICY_HND *handle,
752 fstring value, uint32 *type,
753 uint8 **data, uint32 *needed, uint32 in_size )
755 NT_PRINTER_INFO_LEVEL printer;
759 Printer_entry *Printer = find_printer_index_by_hnd(handle);
761 DEBUG(5,("getprinterdata_printer\n"));
763 if (!OPEN_HANDLE(Printer))
766 if(!get_printer_snum(handle, &snum))
769 if(get_a_printer(&printer, 2, lp_servicename(snum)) != 0)
772 if (!get_specific_param(printer, 2, value, &idata, type, &len)) {
773 free_a_printer(printer, 2);
777 DEBUG(5,("getprinterdata_printer:allocating %d\n", in_size));
779 if((*data = (uint8 *)malloc( in_size *sizeof(uint8) )) == NULL) {
780 free_a_printer(printer, 2);
784 memset(*data, 0, in_size *sizeof(uint8));
785 /* copy the min(in_size, len) */
786 memcpy(*data, idata, (len>in_size)?in_size:len *sizeof(uint8));
790 DEBUG(5,("getprinterdata_printer:copy done\n"));
792 free_a_printer(printer, 2);
798 /********************************************************************
799 * spoolss_getprinterdata
800 ********************************************************************/
801 uint32 _spoolss_getprinterdata(const POLICY_HND *handle, UNISTR2 *valuename,
810 Printer_entry *Printer = find_printer_index_by_hnd(handle);
813 * Reminder: when it's a string, the length is in BYTES
814 * even if UNICODE is negociated.
821 /* in case of problem, return some default values */
825 DEBUG(4,("_spoolss_getprinterdata\n"));
827 if (!OPEN_HANDLE(Printer)) {
828 if((*data=(uint8 *)malloc(4*sizeof(uint8))) == NULL)
829 return ERROR_NOT_ENOUGH_MEMORY;
830 return ERROR_INVALID_HANDLE;
833 unistr2_to_ascii(value, valuename, sizeof(value)-1);
835 if (handle_is_printserver(handle))
836 found=getprinterdata_printer_server(value, type, data, needed, *out_size);
838 found=getprinterdata_printer(handle, value, type, data, needed, *out_size);
841 DEBUG(5, ("value not found, allocating %d\n", *out_size));
842 /* reply this param doesn't exist */
843 if((*data=(uint8 *)malloc(*out_size*sizeof(uint8))) == NULL)
844 return ERROR_NOT_ENOUGH_MEMORY;
845 memset(*data, 0x0, *out_size*sizeof(uint8));
846 return ERROR_INVALID_PARAMETER;
849 if (*needed > *out_size)
850 return ERROR_INSUFFICIENT_BUFFER;
852 return NT_STATUS_NO_PROBLEMO;
855 /********************************************************************
857 * ReplyFindFirstPrinterChangeNotifyEx
859 * jfmxxxx: before replying OK: status=0
860 * should do a rpc call to the workstation asking ReplyOpenPrinter
861 * have to code it, later.
863 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
864 * called from api_spoolss_rffpcnex
865 ********************************************************************/
866 uint32 _spoolss_rffpcnex(const POLICY_HND *handle, uint32 flags, uint32 options,
867 const UNISTR2 *localmachine, uint32 printerlocal,
868 SPOOL_NOTIFY_OPTION *option)
870 /* store the notify value in the printer struct */
872 Printer_entry *Printer=find_printer_index_by_hnd(handle);
874 if (!OPEN_HANDLE(Printer))
875 return ERROR_INVALID_HANDLE;
877 Printer->notify.flags=flags;
878 Printer->notify.options=options;
879 Printer->notify.printerlocal=printerlocal;
880 Printer->notify.option=option;
881 unistr2_to_ascii(Printer->notify.localmachine, localmachine, sizeof(Printer->notify.localmachine)-1);
883 return NT_STATUS_NO_PROBLEMO;
886 /*******************************************************************
887 * fill a notify_info_data with the servername
888 ********************************************************************/
889 static void spoolss_notify_server_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
893 snprintf(temp_name, sizeof(temp_name)-1, "\\\\%s", global_myname);
895 data->notify_data.data.length=strlen(temp_name);
896 ascii_to_unistr((char *)data->notify_data.data.string, temp_name, sizeof(data->notify_data.data.string)-1);
899 /*******************************************************************
900 * fill a notify_info_data with the servicename
901 * jfmxxxx: it's incorrect should be long_printername
902 ********************************************************************/
903 static void spoolss_notify_printer_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
906 data->notify_data.data.length=strlen(lp_servicename(snum));
907 ascii_to_unistr(data->notify_data.data.string, lp_servicename(snum), sizeof(data->notify_data.data.string)-1);
909 data->notify_data.data.length=strlen(printer->info_2->printername);
910 ascii_to_unistr((char *)data->notify_data.data.string,
911 printer->info_2->printername,
912 sizeof(data->notify_data.data.string)-1);
915 /*******************************************************************
916 * fill a notify_info_data with the servicename
917 ********************************************************************/
918 static void spoolss_notify_share_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
920 data->notify_data.data.length=strlen(lp_servicename(snum));
921 ascii_to_unistr((char *)data->notify_data.data.string,
922 lp_servicename(snum),
923 sizeof(data->notify_data.data.string)-1);
926 /*******************************************************************
927 * fill a notify_info_data with the port name
928 ********************************************************************/
929 static void spoolss_notify_port_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
931 /* even if it's strange, that's consistant in all the code */
933 data->notify_data.data.length=strlen(lp_servicename(snum));
934 ascii_to_unistr((char *)data->notify_data.data.string,
935 lp_servicename(snum),
936 sizeof(data->notify_data.data.string)-1);
939 /*******************************************************************
940 * fill a notify_info_data with the printername
941 * jfmxxxx: it's incorrect, should be lp_printerdrivername()
942 * but it doesn't exist, have to see what to do
943 ********************************************************************/
944 static void spoolss_notify_driver_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
946 data->notify_data.data.length=strlen(printer->info_2->drivername);
947 ascii_to_unistr((char *)data->notify_data.data.string,
948 printer->info_2->drivername,
949 sizeof(data->notify_data.data.string)-1);
952 /*******************************************************************
953 * fill a notify_info_data with the comment
954 ********************************************************************/
955 static void spoolss_notify_comment(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
957 data->notify_data.data.length=strlen(lp_comment(snum));
958 ascii_to_unistr((char *)data->notify_data.data.string,
960 sizeof(data->notify_data.data.string)-1);
963 /*******************************************************************
964 * fill a notify_info_data with the comment
965 * jfm:xxxx incorrect, have to create a new smb.conf option
966 * location = "Room 1, floor 2, building 3"
967 ********************************************************************/
968 static void spoolss_notify_location(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
970 data->notify_data.data.length=strlen(printer->info_2->location);
971 ascii_to_unistr((char *)data->notify_data.data.string,
972 printer->info_2->location,
973 sizeof(data->notify_data.data.string)-1);
976 /*******************************************************************
977 * fill a notify_info_data with the device mode
978 * jfm:xxxx don't to it for know but that's a real problem !!!
979 ********************************************************************/
980 static void spoolss_notify_devmode(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
984 /*******************************************************************
985 * fill a notify_info_data with the separator file name
986 * jfm:xxxx just return no file could add an option to smb.conf
987 * separator file = "separator.txt"
988 ********************************************************************/
989 static void spoolss_notify_sepfile(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
991 data->notify_data.data.length=strlen(printer->info_2->sepfile);
992 ascii_to_unistr((char *)data->notify_data.data.string,
993 printer->info_2->sepfile,
994 sizeof(data->notify_data.data.string)-1);
997 /*******************************************************************
998 * fill a notify_info_data with the print processor
999 * jfm:xxxx return always winprint to indicate we don't do anything to it
1000 ********************************************************************/
1001 static void spoolss_notify_print_processor(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1003 data->notify_data.data.length=strlen(printer->info_2->printprocessor);
1004 ascii_to_unistr((char *)data->notify_data.data.string,
1005 printer->info_2->printprocessor,
1006 sizeof(data->notify_data.data.string)-1);
1009 /*******************************************************************
1010 * fill a notify_info_data with the print processor options
1011 * jfm:xxxx send an empty string
1012 ********************************************************************/
1013 static void spoolss_notify_parameters(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1015 data->notify_data.data.length=strlen(printer->info_2->parameters);
1016 ascii_to_unistr((char *)data->notify_data.data.string,
1017 printer->info_2->parameters,
1018 sizeof(data->notify_data.data.string)-1);
1021 /*******************************************************************
1022 * fill a notify_info_data with the data type
1023 * jfm:xxxx always send RAW as data type
1024 ********************************************************************/
1025 static void spoolss_notify_datatype(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1027 data->notify_data.data.length=strlen(printer->info_2->datatype);
1028 ascii_to_unistr((char *)data->notify_data.data.string,
1029 printer->info_2->datatype,
1030 sizeof(data->notify_data.data.string)-1);
1033 /*******************************************************************
1034 * fill a notify_info_data with the security descriptor
1035 * jfm:xxxx send an null pointer to say no security desc
1036 * have to implement security before !
1037 ********************************************************************/
1038 static void spoolss_notify_security_desc(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1040 data->notify_data.data.length=0;
1041 data->notify_data.data.string[0]=0x00;
1044 /*******************************************************************
1045 * fill a notify_info_data with the attributes
1046 * jfm:xxxx a samba printer is always shared
1047 ********************************************************************/
1048 static void spoolss_notify_attributes(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1050 data->notify_data.value[0] = PRINTER_ATTRIBUTE_SHARED \
1051 | PRINTER_ATTRIBUTE_NETWORK \
1052 | PRINTER_ATTRIBUTE_RAW_ONLY ;
1055 /*******************************************************************
1056 * fill a notify_info_data with the priority
1057 ********************************************************************/
1058 static void spoolss_notify_priority(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1060 data->notify_data.value[0] = printer->info_2->priority;
1063 /*******************************************************************
1064 * fill a notify_info_data with the default priority
1065 ********************************************************************/
1066 static void spoolss_notify_default_priority(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1068 data->notify_data.value[0] = printer->info_2->default_priority;
1071 /*******************************************************************
1072 * fill a notify_info_data with the start time
1073 ********************************************************************/
1074 static void spoolss_notify_start_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1076 data->notify_data.value[0] = printer->info_2->starttime;
1079 /*******************************************************************
1080 * fill a notify_info_data with the until time
1081 ********************************************************************/
1082 static void spoolss_notify_until_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1084 data->notify_data.value[0] = printer->info_2->untiltime;
1087 /*******************************************************************
1088 * fill a notify_info_data with the status
1089 ********************************************************************/
1090 static void spoolss_notify_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1093 print_queue_struct *q=NULL;
1094 print_status_struct status;
1096 memset(&status, 0, sizeof(status));
1097 count = print_queue_status(snum, &q, &status);
1098 data->notify_data.value[0]=(uint32) status.status;
1102 /*******************************************************************
1103 * fill a notify_info_data with the number of jobs queued
1104 ********************************************************************/
1105 static void spoolss_notify_cjobs(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1107 print_queue_struct *q=NULL;
1108 print_status_struct status;
1110 memset(&status, 0, sizeof(status));
1111 data->notify_data.value[0] = print_queue_status(snum, &q, &status);
1115 /*******************************************************************
1116 * fill a notify_info_data with the average ppm
1117 ********************************************************************/
1118 static void spoolss_notify_average_ppm(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1120 /* always respond 8 pages per minutes */
1121 /* a little hard ! */
1122 data->notify_data.value[0] = printer->info_2->averageppm;
1125 /*******************************************************************
1126 * fill a notify_info_data with
1127 ********************************************************************/
1128 static void spoolss_notify_username(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1130 data->notify_data.data.length=strlen(queue->user);
1131 ascii_to_unistr((char *)data->notify_data.data.string, queue->user, sizeof(data->notify_data.data.string)-1);
1134 /*******************************************************************
1135 * fill a notify_info_data with
1136 ********************************************************************/
1137 static void spoolss_notify_job_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1139 data->notify_data.value[0]=nt_printj_status(queue->status);
1142 /*******************************************************************
1143 * fill a notify_info_data with
1144 ********************************************************************/
1145 static void spoolss_notify_job_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1147 data->notify_data.data.length=strlen(queue->file);
1148 ascii_to_unistr((char *)data->notify_data.data.string, queue->file, sizeof(data->notify_data.data.string)-1);
1151 /*******************************************************************
1152 * fill a notify_info_data with
1153 ********************************************************************/
1154 static void spoolss_notify_job_status_string(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1156 char *p = "unknown";
1157 switch (queue->status) {
1171 data->notify_data.data.length=strlen(p);
1172 ascii_to_unistr((char *)data->notify_data.data.string, p, sizeof(data->notify_data.data.string)-1);
1175 /*******************************************************************
1176 * fill a notify_info_data with
1177 ********************************************************************/
1178 static void spoolss_notify_job_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1180 data->notify_data.value[0]=0x0;
1183 /*******************************************************************
1184 * fill a notify_info_data with
1185 ********************************************************************/
1186 static void spoolss_notify_job_size(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1188 data->notify_data.value[0]=queue->size;
1191 /*******************************************************************
1192 * fill a notify_info_data with
1193 ********************************************************************/
1194 static void spoolss_notify_job_position(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1196 data->notify_data.value[0]=queue->job;
1201 struct s_notify_info_data_table notify_info_data_table[] =
1203 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SERVER_NAME, "PRINTER_NOTIFY_SERVER_NAME", POINTER, spoolss_notify_server_name },
1204 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINTER_NAME, "PRINTER_NOTIFY_PRINTER_NAME", POINTER, spoolss_notify_printer_name },
1205 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SHARE_NAME, "PRINTER_NOTIFY_SHARE_NAME", POINTER, spoolss_notify_share_name },
1206 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PORT_NAME, "PRINTER_NOTIFY_PORT_NAME", POINTER, spoolss_notify_port_name },
1207 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DRIVER_NAME, "PRINTER_NOTIFY_DRIVER_NAME", POINTER, spoolss_notify_driver_name },
1208 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_COMMENT, "PRINTER_NOTIFY_COMMENT", POINTER, spoolss_notify_comment },
1209 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_LOCATION, "PRINTER_NOTIFY_LOCATION", POINTER, spoolss_notify_location },
1210 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DEVMODE, "PRINTER_NOTIFY_DEVMODE", POINTER, spoolss_notify_devmode },
1211 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SEPFILE, "PRINTER_NOTIFY_SEPFILE", POINTER, spoolss_notify_sepfile },
1212 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINT_PROCESSOR, "PRINTER_NOTIFY_PRINT_PROCESSOR", POINTER, spoolss_notify_print_processor },
1213 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PARAMETERS, "PRINTER_NOTIFY_PARAMETERS", POINTER, spoolss_notify_parameters },
1214 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DATATYPE, "PRINTER_NOTIFY_DATATYPE", POINTER, spoolss_notify_datatype },
1215 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_SECURITY_DESCRIPTOR", POINTER, spoolss_notify_security_desc },
1216 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_ATTRIBUTES, "PRINTER_NOTIFY_ATTRIBUTES", ONE_VALUE, spoolss_notify_attributes },
1217 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRIORITY, "PRINTER_NOTIFY_PRIORITY", ONE_VALUE, spoolss_notify_priority },
1218 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DEFAULT_PRIORITY, "PRINTER_NOTIFY_DEFAULT_PRIORITY", ONE_VALUE, spoolss_notify_default_priority },
1219 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_START_TIME, "PRINTER_NOTIFY_START_TIME", ONE_VALUE, spoolss_notify_start_time },
1220 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_UNTIL_TIME, "PRINTER_NOTIFY_UNTIL_TIME", ONE_VALUE, spoolss_notify_until_time },
1221 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_STATUS, "PRINTER_NOTIFY_STATUS", ONE_VALUE, spoolss_notify_status },
1222 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_STATUS_STRING, "PRINTER_NOTIFY_STATUS_STRING", POINTER, NULL },
1223 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_CJOBS, "PRINTER_NOTIFY_CJOBS", ONE_VALUE, spoolss_notify_cjobs },
1224 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_AVERAGE_PPM, "PRINTER_NOTIFY_AVERAGE_PPM", ONE_VALUE, spoolss_notify_average_ppm },
1225 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_PAGES, "PRINTER_NOTIFY_TOTAL_PAGES", POINTER, NULL },
1226 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PAGES_PRINTED, "PRINTER_NOTIFY_PAGES_PRINTED", POINTER, NULL },
1227 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_BYTES, "PRINTER_NOTIFY_TOTAL_BYTES", POINTER, NULL },
1228 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_BYTES_PRINTED, "PRINTER_NOTIFY_BYTES_PRINTED", POINTER, NULL },
1229 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINTER_NAME, "JOB_NOTIFY_PRINTER_NAME", POINTER, spoolss_notify_printer_name },
1230 { JOB_NOTIFY_TYPE, JOB_NOTIFY_MACHINE_NAME, "JOB_NOTIFY_MACHINE_NAME", POINTER, spoolss_notify_server_name },
1231 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PORT_NAME, "JOB_NOTIFY_PORT_NAME", POINTER, spoolss_notify_port_name },
1232 { JOB_NOTIFY_TYPE, JOB_NOTIFY_USER_NAME, "JOB_NOTIFY_USER_NAME", POINTER, spoolss_notify_username },
1233 { JOB_NOTIFY_TYPE, JOB_NOTIFY_NOTIFY_NAME, "JOB_NOTIFY_NOTIFY_NAME", POINTER, spoolss_notify_username },
1234 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DATATYPE, "JOB_NOTIFY_DATATYPE", POINTER, spoolss_notify_datatype },
1235 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINT_PROCESSOR, "JOB_NOTIFY_PRINT_PROCESSOR", POINTER, spoolss_notify_print_processor },
1236 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PARAMETERS, "JOB_NOTIFY_PARAMETERS", POINTER, spoolss_notify_parameters },
1237 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DRIVER_NAME, "JOB_NOTIFY_DRIVER_NAME", POINTER, spoolss_notify_driver_name },
1238 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DEVMODE, "JOB_NOTIFY_DEVMODE", POINTER, spoolss_notify_devmode },
1239 { JOB_NOTIFY_TYPE, JOB_NOTIFY_STATUS, "JOB_NOTIFY_STATUS", ONE_VALUE, spoolss_notify_job_status },
1240 { JOB_NOTIFY_TYPE, JOB_NOTIFY_STATUS_STRING, "JOB_NOTIFY_STATUS_STRING", POINTER, spoolss_notify_job_status_string },
1241 { JOB_NOTIFY_TYPE, JOB_NOTIFY_SECURITY_DESCRIPTOR, "JOB_NOTIFY_SECURITY_DESCRIPTOR", POINTER, NULL },
1242 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DOCUMENT, "JOB_NOTIFY_DOCUMENT", POINTER, spoolss_notify_job_name },
1243 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRIORITY, "JOB_NOTIFY_PRIORITY", ONE_VALUE, spoolss_notify_priority },
1244 { JOB_NOTIFY_TYPE, JOB_NOTIFY_POSITION, "JOB_NOTIFY_POSITION", ONE_VALUE, spoolss_notify_job_position },
1245 { JOB_NOTIFY_TYPE, JOB_NOTIFY_SUBMITTED, "JOB_NOTIFY_SUBMITTED", POINTER, NULL },
1246 { JOB_NOTIFY_TYPE, JOB_NOTIFY_START_TIME, "JOB_NOTIFY_START_TIME", ONE_VALUE, spoolss_notify_start_time },
1247 { JOB_NOTIFY_TYPE, JOB_NOTIFY_UNTIL_TIME, "JOB_NOTIFY_UNTIL_TIME", ONE_VALUE, spoolss_notify_until_time },
1248 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TIME, "JOB_NOTIFY_TIME", ONE_VALUE, spoolss_notify_job_time },
1249 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_PAGES, "JOB_NOTIFY_TOTAL_PAGES", ONE_VALUE, NULL },
1250 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PAGES_PRINTED, "JOB_NOTIFY_PAGES_PRINTED", ONE_VALUE, NULL },
1251 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_BYTES, "JOB_NOTIFY_TOTAL_BYTES", ONE_VALUE, spoolss_notify_job_size },
1252 { JOB_NOTIFY_TYPE, JOB_NOTIFY_BYTES_PRINTED, "JOB_NOTIFY_BYTES_PRINTED", ONE_VALUE, NULL },
1253 { END, END, "", END, NULL }
1256 /*******************************************************************
1257 return the size of info_data structure
1258 ********************************************************************/
1259 static uint32 size_of_notify_info_data(uint16 type, uint16 field)
1263 while (notify_info_data_table[i].type != END)
1265 if ( (notify_info_data_table[i].type == type ) &&
1266 (notify_info_data_table[i].field == field ) )
1268 return (notify_info_data_table[i].size);
1276 /*******************************************************************
1277 return the type of notify_info_data
1278 ********************************************************************/
1279 static BOOL type_of_notify_info_data(uint16 type, uint16 field)
1283 while (notify_info_data_table[i].type != END)
1285 if ( (notify_info_data_table[i].type == type ) &&
1286 (notify_info_data_table[i].field == field ) )
1288 if (notify_info_data_table[i].size == POINTER)
1303 /****************************************************************************
1304 ****************************************************************************/
1305 static int search_notify(uint16 type, uint16 field, int *value)
1310 for (j=0, found=False; found==False && notify_info_data_table[j].type != END ; j++)
1312 if ( (notify_info_data_table[j].type == type ) &&
1313 (notify_info_data_table[j].field == field ) )
1318 if ( found && (notify_info_data_table[j].fn != NULL) )
1324 /****************************************************************************
1325 ****************************************************************************/
1326 static void construct_info_data(SPOOL_NOTIFY_INFO_DATA *info_data, uint16 type, uint16 field, int id)
1328 info_data->type = type;
1329 info_data->field = field;
1330 info_data->reserved = 0;
1332 info_data->size = size_of_notify_info_data(type, field);
1333 info_data->enc_type = type_of_notify_info_data(type, field);
1337 /*******************************************************************
1339 * fill a notify_info struct with info asked
1341 ********************************************************************/
1342 static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPOOL_NOTIFY_OPTION_TYPE *option_type, uint32 id)
1348 SPOOL_NOTIFY_INFO_DATA *current_data;
1349 NT_PRINTER_INFO_LEVEL printer;
1350 print_queue_struct *queue=NULL;
1352 DEBUG(4,("construct_notify_printer_info\n"));
1354 type=option_type->type;
1356 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
1357 (option_type->type==PRINTER_NOTIFY_TYPE?"PRINTER_NOTIFY_TYPE":"JOB_NOTIFY_TYPE"),
1358 option_type->count, lp_servicename(snum)));
1360 if (get_a_printer(&printer, 2, lp_servicename(snum))!=0)
1365 for(field_num=0; field_num<option_type->count; field_num++)
1367 field = option_type->fields[field_num];
1368 DEBUGADD(4,("notify [%d]: type [%x], field [%x]\n", field_num, type, field));
1370 if (!search_notify(type, field, &j) )
1373 if((info->data=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) {
1374 free_a_printer(printer, 2);
1377 current_data=&(info->data[info->count]);
1379 construct_info_data(current_data, type, field, id);
1380 notify_info_data_table[j].fn(snum, current_data, queue, &printer);
1385 free_a_printer(printer, 2);
1389 /*******************************************************************
1391 * fill a notify_info struct with info asked
1393 ********************************************************************/
1394 static BOOL construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_INFO *info, int snum, SPOOL_NOTIFY_OPTION_TYPE *option_type, uint32 id)
1400 SPOOL_NOTIFY_INFO_DATA *current_data;
1401 NT_PRINTER_INFO_LEVEL printer;
1403 DEBUG(4,("construct_notify_jobs_info\n"));
1405 type = option_type->type;
1407 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
1408 (option_type->type==PRINTER_NOTIFY_TYPE?"PRINTER_NOTIFY_TYPE":"JOB_NOTIFY_TYPE"),
1409 option_type->count));
1411 if (get_a_printer(&printer, 2, lp_servicename(snum))!=0)
1416 for(field_num=0; field_num<option_type->count; field_num++)
1418 field = option_type->fields[field_num];
1420 if (!search_notify(type, field, &j) )
1423 if((info->data=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) {
1424 free_a_printer(printer, 2);
1428 current_data=&(info->data[info->count]);
1430 construct_info_data(current_data, type, field, id);
1431 notify_info_data_table[j].fn(snum, current_data, queue, &printer);
1435 free_a_printer(printer, 2);
1441 * JFM: The enumeration is not that simple, it's even non obvious.
1443 * let's take an example: I want to monitor the PRINTER SERVER for
1444 * the printer's name and the number of jobs currently queued.
1445 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
1446 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
1448 * I have 3 printers on the back of my server.
1450 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
1453 * 1 printer 1 name 1
1454 * 2 printer 1 cjob 1
1455 * 3 printer 2 name 2
1456 * 4 printer 2 cjob 2
1457 * 5 printer 3 name 3
1458 * 6 printer 3 name 3
1460 * that's the print server case, the printer case is even worse.
1465 /*******************************************************************
1467 * enumerate all printers on the printserver
1468 * fill a notify_info struct with info asked
1470 ********************************************************************/
1471 static uint32 printserver_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info)
1474 Printer_entry *Printer=find_printer_index_by_hnd(hnd);
1475 int n_services=lp_numservices();
1478 SPOOL_NOTIFY_OPTION *option;
1479 SPOOL_NOTIFY_OPTION_TYPE *option_type;
1481 DEBUG(4,("printserver_notify_info\n"));
1483 option=Printer->notify.option;
1489 for (i=0; i<option->count; i++)
1491 option_type=&(option->ctr.type[i]);
1493 if (option_type->type!=PRINTER_NOTIFY_TYPE)
1496 for (snum=0; snum<n_services; snum++)
1497 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
1498 if (construct_notify_printer_info(info, snum, option_type, id))
1503 * Debugging information, don't delete.
1506 DEBUG(1,("dumping the NOTIFY_INFO\n"));
1507 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
1508 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
1510 for (i=0; i<info->count; i++)
1512 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
1513 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
1514 info->data[i].id, info->data[i].size, info->data[i].enc_type));
1518 return NT_STATUS_NO_PROBLEMO;
1521 /*******************************************************************
1523 * fill a notify_info struct with info asked
1525 ********************************************************************/
1526 static uint32 printer_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info)
1529 Printer_entry *Printer=find_printer_index_by_hnd(hnd);
1532 SPOOL_NOTIFY_OPTION *option;
1533 SPOOL_NOTIFY_OPTION_TYPE *option_type;
1535 print_queue_struct *queue=NULL;
1536 print_status_struct status;
1538 DEBUG(4,("printer_notify_info\n"));
1540 option=Printer->notify.option;
1546 get_printer_snum(hnd, &snum);
1548 for (i=0; i<option->count; i++)
1550 option_type=&(option->ctr.type[i]);
1552 switch ( option_type->type ) {
1553 case PRINTER_NOTIFY_TYPE:
1554 if(construct_notify_printer_info(info, snum, option_type, id))
1558 case JOB_NOTIFY_TYPE:
1559 memset(&status, 0, sizeof(status));
1560 count = print_queue_status(snum, &queue, &status);
1561 for (j=0; j<count; j++)
1562 construct_notify_jobs_info(&(queue[j]), info, snum, option_type, queue[j].job);
1569 * Debugging information, don't delete.
1572 DEBUG(1,("dumping the NOTIFY_INFO\n"));
1573 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
1574 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
1576 for (i=0; i<info->count; i++)
1578 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
1579 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
1580 info->data[i].id, info->data[i].size, info->data[i].enc_type));
1583 return NT_STATUS_NO_PROBLEMO;
1586 /********************************************************************
1588 ********************************************************************/
1589 uint32 _spoolss_rfnpcnex( const POLICY_HND *handle, uint32 change,
1590 SPOOL_NOTIFY_OPTION *option, SPOOL_NOTIFY_INFO *info)
1592 Printer_entry *Printer=find_printer_index_by_hnd(handle);
1594 if (!OPEN_HANDLE(Printer))
1595 return ERROR_INVALID_HANDLE;
1597 DEBUG(4,("Printer type %x\n",Printer->printer_type));
1599 /* jfm: the change value isn't used right now.
1600 * we will honour it when
1601 * a) we'll be able to send notification to the client
1602 * b) we'll have a way to communicate between the spoolss process.
1604 * same thing for option->flags
1605 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
1606 * I don't have a global notification system, I'm sending back all the
1607 * informations even when _NOTHING_ has changed.
1610 /* just discard the SPOOL_NOTIFY_OPTION */
1612 safe_free(option->ctr.type);
1614 switch (Printer->printer_type) {
1615 case PRINTER_HANDLE_IS_PRINTSERVER:
1616 return printserver_notify_info(handle, info);
1618 case PRINTER_HANDLE_IS_PRINTER:
1619 return printer_notify_info(handle, info);
1623 return ERROR_INVALID_HANDLE;
1626 /********************************************************************
1627 * construct_printer_info_0
1628 * fill a printer_info_1 struct
1629 ********************************************************************/
1630 static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, fstring servername)
1634 NT_PRINTER_INFO_LEVEL ntprinter;
1635 counter_printer_0 *session_counter;
1636 uint32 global_counter;
1640 print_queue_struct *queue=NULL;
1641 print_status_struct status;
1643 memset(&status, 0, sizeof(status));
1645 if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) != 0)
1648 count = print_queue_status(snum, &queue, &status);
1650 /* check if we already have a counter for this printer */
1651 session_counter = (counter_printer_0 *)ubi_dlFirst(&counter_list);
1653 for(; session_counter; session_counter = (counter_printer_0 *)ubi_dlNext(session_counter)) {
1654 if (session_counter->snum == snum)
1658 /* it's the first time, add it to the list */
1659 if (session_counter==NULL) {
1660 if((session_counter=(counter_printer_0 *)malloc(sizeof(counter_printer_0))) == NULL)
1662 ZERO_STRUCTP(session_counter);
1663 session_counter->snum=snum;
1664 session_counter->counter=0;
1665 ubi_dlAddHead( &counter_list, (ubi_dlNode *)session_counter);
1669 session_counter->counter++;
1672 * the global_counter should be stored in a TDB as it's common to all the clients
1673 * and should be zeroed on samba startup
1675 global_counter=session_counter->counter;
1677 /* the description and the name are of the form \\server\share */
1678 slprintf(chaine,sizeof(chaine)-1,"\\\\%s\\%s",servername, ntprinter.info_2->printername);
1680 init_unistr(&(printer->printername), chaine);
1682 slprintf(chaine,sizeof(chaine)-1,"\\\\%s", servername);
1683 init_unistr(&(printer->servername), chaine);
1685 printer->cjobs = count;
1686 printer->total_jobs = 0;
1687 printer->total_bytes = 0;
1689 t=gmtime(&setup_time);
1690 ntprinter.info_2->setuptime = (uint32)setup_time; /* FIXME !! */
1692 printer->year = t->tm_year+1900;
1693 printer->month = t->tm_mon+1;
1694 printer->dayofweek = t->tm_wday;
1695 printer->day = t->tm_mday;
1696 printer->hour = t->tm_hour;
1697 printer->minute = t->tm_min;
1698 printer->second = t->tm_sec;
1699 printer->milliseconds = 0;
1701 printer->global_counter = global_counter;
1702 printer->total_pages = 0;
1703 printer->major_version = 0x0004; /* NT 4 */
1704 printer->build_version = 0x0565; /* build 1381 */
1705 printer->unknown7 = 0x1;
1706 printer->unknown8 = 0x0;
1707 printer->unknown9 = 0x0;
1708 printer->session_counter = session_counter->counter;
1709 printer->unknown11 = 0x0;
1710 printer->printer_errors = 0x0; /* number of print failure */
1711 printer->unknown13 = 0x0;
1712 printer->unknown14 = 0x1;
1713 printer->unknown15 = 0x024a; /* 586 Pentium ? */
1714 printer->unknown16 = 0x0;
1715 printer->change_id = ntprinter.info_2->changeid; /* ChangeID in milliseconds*/
1716 printer->unknown18 = 0x0;
1717 printer->status = nt_printq_status(status.status);
1718 printer->unknown20 = 0x0;
1719 printer->c_setprinter = ntprinter.info_2->c_setprinter; /* how many times setprinter has been called */
1720 printer->unknown22 = 0x0;
1721 printer->unknown23 = 0x6; /* 6 ???*/
1722 printer->unknown24 = 0; /* unknown 24 to 26 are always 0 */
1723 printer->unknown25 = 0;
1724 printer->unknown26 = 0;
1725 printer->unknown27 = 0;
1726 printer->unknown28 = 0;
1727 printer->unknown29 = 0;
1731 free_a_printer(ntprinter, 2);
1735 /********************************************************************
1736 * construct_printer_info_1
1737 * fill a printer_info_1 struct
1738 ********************************************************************/
1739 static BOOL construct_printer_info_1(fstring server, uint32 flags, PRINTER_INFO_1 *printer, int snum)
1743 NT_PRINTER_INFO_LEVEL ntprinter;
1745 if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) != 0)
1748 printer->flags=flags;
1750 snprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",server, ntprinter.info_2->printername,
1751 ntprinter.info_2->drivername, lp_comment(snum));
1753 snprintf(chaine2,sizeof(chaine)-1,"%s%s", server, ntprinter.info_2->printername);
1755 init_unistr(&printer->description, chaine);
1756 init_unistr(&printer->name, chaine2);
1757 init_unistr(&printer->comment, lp_comment(snum));
1759 free_a_printer(ntprinter, 2);
1764 /****************************************************************************
1765 ****************************************************************************/
1766 static BOOL construct_dev_mode(DEVICEMODE *devmode, int snum, char *servername)
1770 NT_PRINTER_INFO_LEVEL printer;
1771 NT_DEVICEMODE *ntdevmode;
1773 DEBUG(7,("construct_dev_mode\n"));
1775 memset(&(devmode->devicename), 0, 2*sizeof(adevice));
1776 memset(&(devmode->formname), 0, 2*sizeof(aform));
1778 DEBUGADD(8,("getting printer characteristics\n"));
1780 get_a_printer(&printer, 2, lp_servicename(snum));
1781 ntdevmode=(printer.info_2)->devmode;
1783 DEBUGADD(8,("loading DEVICEMODE\n"));
1784 snprintf(adevice, sizeof(adevice), "\\\\%s\\%s", global_myname,
1785 printer.info_2->printername);
1786 init_unistr(&(devmode->devicename), adevice);
1788 snprintf(aform, sizeof(aform), ntdevmode->formname);
1789 init_unistr(&(devmode->formname), aform);
1791 devmode->specversion = ntdevmode->specversion;
1792 devmode->driverversion = ntdevmode->driverversion;
1793 devmode->size = ntdevmode->size;
1794 devmode->driverextra = ntdevmode->driverextra;
1795 devmode->fields = ntdevmode->fields;
1797 devmode->orientation = ntdevmode->orientation;
1798 devmode->papersize = ntdevmode->papersize;
1799 devmode->paperlength = ntdevmode->paperlength;
1800 devmode->paperwidth = ntdevmode->paperwidth;
1801 devmode->scale = ntdevmode->scale;
1802 devmode->copies = ntdevmode->copies;
1803 devmode->defaultsource = ntdevmode->defaultsource;
1804 devmode->printquality = ntdevmode->printquality;
1805 devmode->color = ntdevmode->color;
1806 devmode->duplex = ntdevmode->duplex;
1807 devmode->yresolution = ntdevmode->yresolution;
1808 devmode->ttoption = ntdevmode->ttoption;
1809 devmode->collate = ntdevmode->collate;
1810 devmode->icmmethod = ntdevmode->icmmethod;
1811 devmode->icmintent = ntdevmode->icmintent;
1812 devmode->mediatype = ntdevmode->mediatype;
1813 devmode->dithertype = ntdevmode->dithertype;
1815 if (ntdevmode->private != NULL)
1817 if((devmode->private=(uint8 *)malloc(devmode->driverextra*sizeof(uint8))) == NULL) {
1818 free_a_printer(printer, 2);
1821 memcpy(devmode->private, ntdevmode->private, devmode->driverextra);
1824 free_a_printer(printer, 2);
1829 /********************************************************************
1830 * construct_printer_info_2
1831 * fill a printer_info_2 struct
1832 ********************************************************************/
1833 static BOOL construct_printer_info_2(fstring servername, PRINTER_INFO_2 *printer, int snum)
1839 DEVICEMODE *devmode;
1840 NT_PRINTER_INFO_LEVEL ntprinter;
1842 print_queue_struct *queue=NULL;
1843 print_status_struct status;
1844 memset(&status, 0, sizeof(status));
1846 if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0 )
1849 memset(&status, 0, sizeof(status));
1850 count = print_queue_status(snum, &queue, &status);
1852 snprintf(chaine, sizeof(chaine)-1, "%s", servername);
1854 if (strlen(servername)!=0)
1859 snprintf(chaine2, sizeof(chaine)-1, "%s%s%s", servername, sl, ntprinter.info_2->printername);
1861 init_unistr(&printer->servername, chaine); /* servername*/
1862 init_unistr(&printer->printername, chaine2); /* printername*/
1863 init_unistr(&printer->sharename, lp_servicename(snum)); /* sharename */
1864 init_unistr(&printer->portname, lp_servicename(snum)); /* port */
1865 init_unistr(&printer->drivername, ntprinter.info_2->drivername); /* drivername */
1866 init_unistr(&printer->comment, lp_comment(snum)); /* comment */
1867 init_unistr(&printer->location, ntprinter.info_2->location); /* location */
1868 init_unistr(&printer->sepfile, ntprinter.info_2->sepfile); /* separator file */
1869 init_unistr(&printer->printprocessor, ntprinter.info_2->printprocessor);/* print processor */
1870 init_unistr(&printer->datatype, ntprinter.info_2->datatype); /* datatype */
1871 init_unistr(&printer->parameters, ntprinter.info_2->parameters); /* parameters (of print processor) */
1873 printer->attributes = PRINTER_ATTRIBUTE_SHARED \
1874 | PRINTER_ATTRIBUTE_LOCAL \
1875 | PRINTER_ATTRIBUTE_RAW_ONLY ; /* attributes */
1877 printer->priority = ntprinter.info_2->priority; /* priority */
1878 printer->defaultpriority = ntprinter.info_2->default_priority; /* default priority */
1879 printer->starttime = ntprinter.info_2->starttime; /* starttime */
1880 printer->untiltime = ntprinter.info_2->untiltime; /* untiltime */
1881 printer->status = nt_printq_status(status.status); /* status */
1882 printer->cjobs = count; /* jobs */
1883 printer->averageppm = ntprinter.info_2->averageppm; /* average pages per minute */
1885 if((devmode=(DEVICEMODE *)malloc(sizeof(DEVICEMODE))) == NULL)
1888 ZERO_STRUCTP(devmode);
1890 if(!construct_dev_mode(devmode, snum, servername))
1893 printer->devmode=devmode;
1895 if (ntprinter.info_2->secdesc.len != 0)
1897 /* steal the printer info sec_desc structure. [badly done]. */
1898 printer->secdesc = ntprinter.info_2->secdesc.sec;
1899 ZERO_STRUCT(ntprinter.info_2->secdesc);
1903 printer->secdesc = NULL;
1907 free_a_printer(ntprinter, 2);
1913 free_a_printer(ntprinter, 2);
1917 /********************************************************************
1918 * construct_printer_info_3
1919 * fill a printer_info_3 struct
1920 ********************************************************************/
1921 static BOOL construct_printer_info_3(fstring servername,
1922 PRINTER_INFO_3 *printer, int snum)
1924 NT_PRINTER_INFO_LEVEL ntprinter;
1926 if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0 )
1929 printer->flags = 4; /* no idea, yet. see MSDN. */
1930 if (ntprinter.info_2->secdesc.len != 0)
1932 /* steal the printer info sec_desc structure. [badly done]. */
1933 printer->sec = *ntprinter.info_2->secdesc.sec;
1934 safe_free(ntprinter.info_2->secdesc.sec);
1935 ZERO_STRUCT(ntprinter.info_2->secdesc);
1938 free_a_printer(ntprinter, 2);
1942 /********************************************************************
1943 Spoolss_enumprinters.
1944 ********************************************************************/
1945 static BOOL enum_all_printers_info_1(fstring server, uint32 flags, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
1949 int n_services=lp_numservices();
1950 PRINTER_INFO_1 *printers=NULL;
1951 PRINTER_INFO_1 current_prt;
1953 DEBUG(4,("enum_all_printers_info_1\n"));
1955 for (snum=0; snum<n_services; snum++) {
1956 if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
1957 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum));
1959 if (construct_printer_info_1(server, flags, ¤t_prt, snum)) {
1960 if((printers=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_1))) == NULL) {
1962 return ERROR_NOT_ENOUGH_MEMORY;
1964 DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_1\n", *returned));
1965 memcpy(&(printers[*returned]), ¤t_prt, sizeof(PRINTER_INFO_1));
1971 /* check the required size. */
1972 for (i=0; i<*returned; i++)
1973 (*needed) += spoolss_size_printer_info_1(&(printers[i]));
1975 if (!alloc_buffer_size(buffer, *needed))
1976 return ERROR_INSUFFICIENT_BUFFER;
1978 /* fill the buffer with the structures */
1979 for (i=0; i<*returned; i++)
1980 new_smb_io_printer_info_1("", buffer, &(printers[i]), 0);
1983 safe_free(printers);
1985 if (*needed > offered) {
1987 return ERROR_INSUFFICIENT_BUFFER;
1990 return NT_STATUS_NO_PROBLEMO;
1993 /********************************************************************
1994 enum_all_printers_info_1_local.
1995 *********************************************************************/
1996 static BOOL enum_all_printers_info_1_local(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
1999 DEBUG(4,("enum_all_printers_info_1_local\n"));
2001 fstrcpy(temp, "\\\\");
2002 fstrcat(temp, global_myname);
2004 if (!strcmp(name, temp)) {
2005 fstrcat(temp, "\\");
2006 return enum_all_printers_info_1(temp, PRINTER_ENUM_ICON8, buffer, offered, needed, returned);
2009 return enum_all_printers_info_1("", PRINTER_ENUM_ICON8, buffer, offered, needed, returned);
2012 /********************************************************************
2013 enum_all_printers_info_1_name.
2014 *********************************************************************/
2015 static BOOL enum_all_printers_info_1_name(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
2018 DEBUG(4,("enum_all_printers_info_1_name\n"));
2020 fstrcpy(temp, "\\\\");
2021 fstrcat(temp, global_myname);
2023 if (!strcmp(name, temp)) {
2024 fstrcat(temp, "\\");
2025 return enum_all_printers_info_1(temp, PRINTER_ENUM_ICON8, buffer, offered, needed, returned);
2028 return ERROR_INVALID_NAME;
2031 /********************************************************************
2032 enum_all_printers_info_1_remote.
2033 *********************************************************************/
2034 static BOOL enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
2036 PRINTER_INFO_1 *printer;
2037 fstring printername;
2040 DEBUG(4,("enum_all_printers_info_1_remote\n"));
2042 /* JFM: currently it's more a place holder than anything else.
2043 * In the spooler world there is a notion of server registration.
2044 * the print servers are registring (sp ?) on the PDC (in the same domain)
2046 * We should have a TDB here. The registration is done thru an undocumented RPC call.
2049 if((printer=(PRINTER_INFO_1 *)malloc(sizeof(PRINTER_INFO_1))) == NULL)
2050 return ERROR_NOT_ENOUGH_MEMORY;
2054 snprintf(printername, sizeof(printername)-1,"Windows NT Remote Printers!!\\\\%s", global_myname);
2055 snprintf(desc, sizeof(desc)-1,"%s", global_myname);
2056 snprintf(comment, sizeof(comment)-1, "Logged on Domain");
2058 init_unistr(&printer->description, desc);
2059 init_unistr(&printer->name, printername);
2060 init_unistr(&printer->comment, comment);
2061 printer->flags=PRINTER_ENUM_ICON3|PRINTER_ENUM_CONTAINER;
2063 /* check the required size. */
2064 *needed += spoolss_size_printer_info_1(printer);
2066 if (!alloc_buffer_size(buffer, *needed)) {
2068 return ERROR_INSUFFICIENT_BUFFER;
2071 /* fill the buffer with the structures */
2072 new_smb_io_printer_info_1("", buffer, printer, 0);
2077 if (*needed > offered) {
2079 return ERROR_INSUFFICIENT_BUFFER;
2082 return NT_STATUS_NO_PROBLEMO;
2085 /********************************************************************
2086 enum_all_printers_info_1_network.
2087 *********************************************************************/
2088 static BOOL enum_all_printers_info_1_network(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
2091 DEBUG(4,("enum_all_printers_info_1_network\n"));
2093 fstrcpy(temp, "\\\\");
2094 fstrcat(temp, global_myname);
2095 fstrcat(temp, "\\");
2096 return enum_all_printers_info_1(temp, PRINTER_ENUM_UNKNOWN_8, buffer, offered, needed, returned);
2099 /********************************************************************
2100 * api_spoolss_enumprinters
2102 * called from api_spoolss_enumprinters (see this to understand)
2103 ********************************************************************/
2104 static BOOL enum_all_printers_info_2(fstring servername, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
2108 int n_services=lp_numservices();
2109 PRINTER_INFO_2 *printers=NULL;
2110 PRINTER_INFO_2 current_prt;
2112 for (snum=0; snum<n_services; snum++) {
2113 if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
2114 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum));
2116 if (construct_printer_info_2(servername, ¤t_prt, snum)) {
2117 if((printers=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_2))) == NULL)
2118 return ERROR_NOT_ENOUGH_MEMORY;
2119 DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_2\n", *returned));
2120 memcpy(&(printers[*returned]), ¤t_prt, sizeof(PRINTER_INFO_2));
2126 /* check the required size. */
2127 for (i=0; i<*returned; i++)
2128 (*needed) += spoolss_size_printer_info_2(&(printers[i]));
2130 if (!alloc_buffer_size(buffer, *needed)) {
2131 for (i=0; i<*returned; i++) {
2132 safe_free(printers[i].devmode->private);
2133 safe_free(printers[i].devmode);
2135 safe_free(printers);
2136 return ERROR_INSUFFICIENT_BUFFER;
2139 /* fill the buffer with the structures */
2140 for (i=0; i<*returned; i++)
2141 new_smb_io_printer_info_2("", buffer, &(printers[i]), 0);
2144 for (i=0; i<*returned; i++) {
2145 safe_free(printers[i].devmode->private);
2146 safe_free(printers[i].devmode);
2148 safe_free(printers);
2150 if (*needed > offered) {
2152 return ERROR_INSUFFICIENT_BUFFER;
2155 return NT_STATUS_NO_PROBLEMO;
2158 /********************************************************************
2159 * handle enumeration of printers at level 1
2160 ********************************************************************/
2161 static uint32 enumprinters_level1( uint32 flags, fstring name,
2162 NEW_BUFFER *buffer, uint32 offered,
2163 uint32 *needed, uint32 *returned)
2165 /* Not all the flags are equals */
2167 if (flags & PRINTER_ENUM_LOCAL)
2168 return enum_all_printers_info_1_local(name, buffer, offered, needed, returned);
2170 if (flags & PRINTER_ENUM_NAME)
2171 return enum_all_printers_info_1_name(name, buffer, offered, needed, returned);
2173 if (flags & PRINTER_ENUM_REMOTE)
2174 return enum_all_printers_info_1_remote(name, buffer, offered, needed, returned);
2176 if (flags & PRINTER_ENUM_NETWORK)
2177 return enum_all_printers_info_1_network(name, buffer, offered, needed, returned);
2179 return NT_STATUS_NO_PROBLEMO; /* NT4sp5 does that */
2182 /********************************************************************
2183 * handle enumeration of printers at level 2
2184 ********************************************************************/
2185 static uint32 enumprinters_level2( uint32 flags, fstring servername,
2186 NEW_BUFFER *buffer, uint32 offered,
2187 uint32 *needed, uint32 *returned)
2191 fstrcpy(temp, "\\\\");
2192 fstrcat(temp, global_myname);
2194 if (flags & PRINTER_ENUM_LOCAL) {
2195 if (!strcmp(servername, temp))
2196 return enum_all_printers_info_2(temp, buffer, offered, needed, returned);
2198 return enum_all_printers_info_2("", buffer, offered, needed, returned);
2201 if (flags & PRINTER_ENUM_NAME) {
2202 if (!strcmp(servername, temp))
2203 return enum_all_printers_info_2(temp, buffer, offered, needed, returned);
2205 return ERROR_INVALID_NAME;
2208 if (flags & PRINTER_ENUM_REMOTE)
2209 return ERROR_INVALID_LEVEL;
2211 return NT_STATUS_NO_PROBLEMO;
2214 /********************************************************************
2215 * handle enumeration of printers at level 5
2216 ********************************************************************/
2217 static uint32 enumprinters_level5( uint32 flags, fstring servername,
2218 NEW_BUFFER *buffer, uint32 offered,
2219 uint32 *needed, uint32 *returned)
2221 /* return enum_all_printers_info_5(buffer, offered, needed, returned);*/
2222 return NT_STATUS_NO_PROBLEMO;
2225 /********************************************************************
2226 * api_spoolss_enumprinters
2228 * called from api_spoolss_enumprinters (see this to understand)
2229 ********************************************************************/
2230 uint32 _spoolss_enumprinters( uint32 flags, const UNISTR2 *servername, uint32 level,
2231 NEW_BUFFER *buffer, uint32 offered,
2232 uint32 *needed, uint32 *returned)
2236 DEBUG(4,("_spoolss_enumprinters\n"));
2243 * flags==PRINTER_ENUM_NAME
2244 * if name=="" then enumerates all printers
2245 * if name!="" then enumerate the printer
2246 * flags==PRINTER_ENUM_REMOTE
2247 * name is NULL, enumerate printers
2248 * Level 2: name!="" enumerates printers, name can't be NULL
2249 * Level 3: doesn't exist
2250 * Level 4: does a local registry lookup
2251 * Level 5: same as Level 2
2254 unistr2_to_ascii(name, servername, sizeof(name)-1);
2259 return enumprinters_level1(flags, name, buffer, offered, needed, returned);
2262 return enumprinters_level2(flags, name, buffer, offered, needed, returned);
2265 return enumprinters_level5(flags, name, buffer, offered, needed, returned);
2270 return ERROR_INVALID_LEVEL;
2275 /****************************************************************************
2276 ****************************************************************************/
2277 static uint32 getprinter_level_0(fstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2279 PRINTER_INFO_0 *printer=NULL;
2281 if((printer=(PRINTER_INFO_0*)malloc(sizeof(PRINTER_INFO_0))) == NULL)
2282 return ERROR_NOT_ENOUGH_MEMORY;
2284 construct_printer_info_0(printer, snum, servername);
2286 /* check the required size. */
2287 *needed += spoolss_size_printer_info_0(printer);
2289 if (!alloc_buffer_size(buffer, *needed)) {
2291 return ERROR_INSUFFICIENT_BUFFER;
2294 /* fill the buffer with the structures */
2295 new_smb_io_printer_info_0("", buffer, printer, 0);
2300 if (*needed > offered) {
2301 return ERROR_INSUFFICIENT_BUFFER;
2304 return NT_STATUS_NO_PROBLEMO;
2307 /****************************************************************************
2308 ****************************************************************************/
2309 static uint32 getprinter_level_1(fstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2311 PRINTER_INFO_1 *printer=NULL;
2313 if((printer=(PRINTER_INFO_1*)malloc(sizeof(PRINTER_INFO_1))) == NULL)
2314 return ERROR_NOT_ENOUGH_MEMORY;
2316 construct_printer_info_1(servername, PRINTER_ENUM_ICON8, printer, snum);
2318 /* check the required size. */
2319 *needed += spoolss_size_printer_info_1(printer);
2321 if (!alloc_buffer_size(buffer, *needed)) {
2323 return ERROR_INSUFFICIENT_BUFFER;
2326 /* fill the buffer with the structures */
2327 new_smb_io_printer_info_1("", buffer, printer, 0);
2332 if (*needed > offered) {
2333 return ERROR_INSUFFICIENT_BUFFER;
2336 return NT_STATUS_NO_PROBLEMO;
2339 /****************************************************************************
2340 ****************************************************************************/
2341 static uint32 getprinter_level_2(fstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2343 PRINTER_INFO_2 *printer=NULL;
2346 if((printer=(PRINTER_INFO_2*)malloc(sizeof(PRINTER_INFO_2)))==NULL)
2347 return ERROR_NOT_ENOUGH_MEMORY;
2349 fstrcpy(temp, "\\\\");
2350 fstrcat(temp, servername);
2351 construct_printer_info_2(temp, printer, snum);
2353 /* check the required size. */
2354 *needed += spoolss_size_printer_info_2(printer);
2356 if (!alloc_buffer_size(buffer, *needed)) {
2358 return ERROR_INSUFFICIENT_BUFFER;
2361 /* fill the buffer with the structures */
2362 new_smb_io_printer_info_2("", buffer, printer, 0);
2365 safe_free(printer->devmode->private);
2366 safe_free(printer->devmode);
2369 if (*needed > offered) {
2370 return ERROR_INSUFFICIENT_BUFFER;
2373 return NT_STATUS_NO_PROBLEMO;
2376 /****************************************************************************
2377 ****************************************************************************/
2378 static uint32 getprinter_level_3(fstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2380 PRINTER_INFO_3 *printer=NULL;
2383 if((printer=(PRINTER_INFO_3*)malloc(sizeof(PRINTER_INFO_3)))==NULL)
2384 return ERROR_NOT_ENOUGH_MEMORY;
2386 fstrcpy(temp, "\\\\");
2387 fstrcat(temp, servername);
2388 construct_printer_info_3(temp, printer, snum);
2390 /* check the required size. */
2391 *needed += spoolss_size_printer_info_3(printer);
2393 if (!alloc_buffer_size(buffer, *needed)) {
2395 return ERROR_INSUFFICIENT_BUFFER;
2398 /* fill the buffer with the structures */
2399 new_smb_io_printer_info_3("", buffer, printer, 0);
2402 free_sec_desc(&printer->sec);
2404 if (*needed > offered) {
2405 return ERROR_INSUFFICIENT_BUFFER;
2408 return NT_STATUS_NO_PROBLEMO;
2411 /****************************************************************************
2412 ****************************************************************************/
2413 uint32 _spoolss_getprinter(POLICY_HND *handle, uint32 level,
2414 NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2421 pstrcpy(servername, global_myname);
2423 if (!get_printer_snum(handle, &snum))
2424 return ERROR_INVALID_HANDLE;
2428 return getprinter_level_0(servername, snum, buffer, offered, needed);
2430 return getprinter_level_1(servername,snum, buffer, offered, needed);
2432 return getprinter_level_2(servername,snum, buffer, offered, needed);
2434 return getprinter_level_3(servername,snum, buffer, offered, needed);
2436 return ERROR_INVALID_LEVEL;
2441 /********************************************************************
2442 * construct_printer_driver_info_1
2443 * fill a construct_printer_driver_info_1 struct
2444 ********************************************************************/
2445 static void fill_printer_driver_info_1(DRIVER_INFO_1 *info,
2446 NT_PRINTER_DRIVER_INFO_LEVEL driver,
2447 fstring servername, fstring architecture)
2449 init_unistr( &(info->name), driver.info_3->name);
2452 static void construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum,
2453 fstring servername, fstring architecture)
2455 NT_PRINTER_INFO_LEVEL printer;
2456 NT_PRINTER_DRIVER_INFO_LEVEL driver;
2458 ZERO_STRUCT(driver);
2459 ZERO_STRUCT(printer);
2461 get_a_printer(&printer, 2, lp_servicename(snum) );
2462 get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture);
2464 fill_printer_driver_info_1(info, driver, servername, architecture);
2466 free_a_printer_driver(driver, 3);
2467 free_a_printer(printer, 2);
2470 /********************************************************************
2471 * construct_printer_driver_info_2
2472 * fill a printer_info_2 struct
2473 ********************************************************************/
2474 static void fill_printer_driver_info_2(DRIVER_INFO_2 *info,
2475 NT_PRINTER_DRIVER_INFO_LEVEL driver,
2476 fstring servername, fstring architecture)
2479 pstring temp_driverpath;
2480 pstring temp_datafile;
2481 pstring temp_configfile;
2482 fstring short_archi;
2484 get_short_archi(short_archi,architecture);
2486 snprintf(where,sizeof(where)-1,"\\\\%s\\print$\\%s\\%s\\", servername, short_archi, driver.info_3->name);
2488 info->version=driver.info_3->cversion;
2490 init_unistr( &(info->name), driver.info_3->name );
2491 init_unistr( &(info->architecture), architecture );
2493 snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "%s%s", where,
2494 driver.info_3->driverpath);
2495 init_unistr( &(info->driverpath), temp_driverpath );
2497 snprintf(temp_datafile, sizeof(temp_datafile)-1, "%s%s", where,
2498 driver.info_3->datafile);
2499 init_unistr( &(info->datafile), temp_datafile );
2501 snprintf(temp_configfile, sizeof(temp_configfile)-1, "%s%s", where,
2502 driver.info_3->configfile);
2503 init_unistr( &(info->configfile), temp_configfile );
2506 /********************************************************************
2507 * construct_printer_driver_info_2
2508 * fill a printer_info_2 struct
2509 ********************************************************************/
2510 static void construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fstring servername, fstring architecture)
2512 NT_PRINTER_INFO_LEVEL printer;
2513 NT_PRINTER_DRIVER_INFO_LEVEL driver;
2515 ZERO_STRUCT(printer);
2516 ZERO_STRUCT(driver);
2518 get_a_printer(&printer, 2, lp_servicename(snum) );
2519 get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture);
2521 fill_printer_driver_info_2(info, driver, servername, architecture);
2523 free_a_printer_driver(driver, 3);
2524 free_a_printer(printer, 2);
2527 /********************************************************************
2528 * copy a strings array and convert to UNICODE
2530 * convert an array of ascii string to a UNICODE string
2531 ********************************************************************/
2532 static void init_unistr_array(uint16 **uni_array, fstring *char_array, char *where)
2539 DEBUG(6,("init_unistr_array\n"));
2544 snprintf(line, sizeof(line)-1, "%s%s", where, v);
2545 DEBUGADD(6,("%d:%s:%d\n", i, line, strlen(line)));
2546 if((*uni_array=Realloc(*uni_array, (j+strlen(line)+2)*sizeof(uint16))) == NULL) {
2547 DEBUG(0,("init_unistr_array: Realloc error\n" ));
2550 ascii_to_unistr((char *)(*uni_array+j), line , 2*strlen(line));
2553 if (strlen(v) == 0) break;
2557 (*uni_array)[j]=0x0000;
2560 DEBUGADD(6,("last one:done\n"));
2563 /********************************************************************
2564 * construct_printer_info_3
2565 * fill a printer_info_3 struct
2566 ********************************************************************/
2567 static void fill_printer_driver_info_3(DRIVER_INFO_3 *info,
2568 NT_PRINTER_DRIVER_INFO_LEVEL driver,
2569 fstring servername, fstring architecture)
2572 pstring temp_driverpath;
2573 pstring temp_datafile;
2574 pstring temp_configfile;
2575 pstring temp_helpfile;
2576 fstring short_archi;
2578 get_short_archi(short_archi, architecture);
2580 snprintf(where,sizeof(where)-1,"\\\\%s\\print$\\%s\\%s\\", servername, short_archi, driver.info_3->name);
2582 info->version=driver.info_3->cversion;
2584 init_unistr( &(info->name), driver.info_3->name );
2585 init_unistr( &(info->architecture), architecture );
2587 snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "%s%s", where, driver.info_3->driverpath);
2588 init_unistr( &(info->driverpath), temp_driverpath );
2590 snprintf(temp_datafile, sizeof(temp_datafile)-1, "%s%s", where, driver.info_3->datafile);
2591 init_unistr( &(info->datafile), temp_datafile );
2593 snprintf(temp_configfile, sizeof(temp_configfile)-1, "%s%s", where, driver.info_3->configfile);
2594 init_unistr( &(info->configfile), temp_configfile );
2596 snprintf(temp_helpfile, sizeof(temp_helpfile)-1, "%s%s", where, driver.info_3->helpfile);
2597 init_unistr( &(info->helpfile), temp_helpfile );
2599 init_unistr( &(info->monitorname), driver.info_3->monitorname );
2600 init_unistr( &(info->defaultdatatype), driver.info_3->defaultdatatype );
2602 info->dependentfiles=NULL;
2603 init_unistr_array(&(info->dependentfiles), driver.info_3->dependentfiles, where);
2606 /********************************************************************
2607 * construct_printer_info_3
2608 * fill a printer_info_3 struct
2609 ********************************************************************/
2610 static void construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum,
2611 fstring servername, fstring architecture)
2613 NT_PRINTER_INFO_LEVEL printer;
2614 NT_PRINTER_DRIVER_INFO_LEVEL driver;
2616 ZERO_STRUCT(printer);
2617 ZERO_STRUCT(driver);
2619 get_a_printer(&printer, 2, lp_servicename(snum) );
2620 get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture);
2622 fill_printer_driver_info_3(info, driver, servername, architecture);
2625 /****************************************************************************
2626 ****************************************************************************/
2627 static uint32 getprinterdriver2_level1(fstring servername, fstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2629 DRIVER_INFO_1 *info=NULL;
2631 if((info=(DRIVER_INFO_1 *)malloc(sizeof(DRIVER_INFO_1))) == NULL)
2632 return ERROR_NOT_ENOUGH_MEMORY;
2634 construct_printer_driver_info_1(info, snum, servername, architecture);
2636 /* check the required size. */
2637 *needed += spoolss_size_printer_driver_info_1(info);
2639 if (!alloc_buffer_size(buffer, *needed)) {
2641 return ERROR_INSUFFICIENT_BUFFER;
2644 /* fill the buffer with the structures */
2645 new_smb_io_printer_driver_info_1("", buffer, info, 0);
2650 if (*needed > offered)
2651 return ERROR_INSUFFICIENT_BUFFER;
2653 return NT_STATUS_NO_PROBLEMO;
2656 /****************************************************************************
2657 ****************************************************************************/
2658 static uint32 getprinterdriver2_level2(fstring servername, fstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2660 DRIVER_INFO_2 *info=NULL;
2662 if((info=(DRIVER_INFO_2 *)malloc(sizeof(DRIVER_INFO_2))) == NULL)
2663 return ERROR_NOT_ENOUGH_MEMORY;
2665 construct_printer_driver_info_2(info, snum, servername, architecture);
2667 /* check the required size. */
2668 *needed += spoolss_size_printer_driver_info_2(info);
2670 if (!alloc_buffer_size(buffer, *needed)) {
2672 return ERROR_INSUFFICIENT_BUFFER;
2675 /* fill the buffer with the structures */
2676 new_smb_io_printer_driver_info_2("", buffer, info, 0);
2681 if (*needed > offered)
2682 return ERROR_INSUFFICIENT_BUFFER;
2684 return NT_STATUS_NO_PROBLEMO;
2687 /****************************************************************************
2688 ****************************************************************************/
2689 static uint32 getprinterdriver2_level3(fstring servername, fstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2695 construct_printer_driver_info_3(&info, snum, servername, architecture);
2697 /* check the required size. */
2698 *needed += spoolss_size_printer_driver_info_3(&info);
2700 if (!alloc_buffer_size(buffer, *needed)) {
2701 return ERROR_INSUFFICIENT_BUFFER;
2704 /* fill the buffer with the structures */
2705 new_smb_io_printer_driver_info_3("", buffer, &info, 0);
2707 if (*needed > offered)
2708 return ERROR_INSUFFICIENT_BUFFER;
2710 return NT_STATUS_NO_PROBLEMO;
2713 /****************************************************************************
2714 ****************************************************************************/
2715 uint32 _spoolss_getprinterdriver2(const POLICY_HND *handle, const UNISTR2 *uni_arch, uint32 level,
2716 uint32 clientmajorversion, uint32 clientminorversion,
2717 NEW_BUFFER *buffer, uint32 offered,
2718 uint32 *needed, uint32 *servermajorversion, uint32 *serverminorversion)
2721 fstring architecture;
2724 DEBUG(4,("_spoolss_getprinterdriver2\n"));
2727 *servermajorversion=0;
2728 *serverminorversion=0;
2730 pstrcpy(servername, global_myname);
2731 unistr2_to_ascii(architecture, uni_arch, sizeof(architecture)-1);
2733 if (!get_printer_snum(handle, &snum))
2734 return ERROR_INVALID_HANDLE;
2738 return getprinterdriver2_level1(servername, architecture, snum, buffer, offered, needed);
2741 return getprinterdriver2_level2(servername, architecture, snum, buffer, offered, needed);
2744 return getprinterdriver2_level3(servername, architecture, snum, buffer, offered, needed);
2747 return ERROR_INVALID_LEVEL;
2752 /****************************************************************************
2753 ****************************************************************************/
2754 uint32 _spoolss_startpageprinter(const POLICY_HND *handle)
2756 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2758 if (OPEN_HANDLE(Printer))
2760 Printer->page_started=True;
2764 DEBUG(3,("Error in startpageprinter printer handle\n"));
2765 return ERROR_INVALID_HANDLE;
2768 /****************************************************************************
2769 ****************************************************************************/
2770 uint32 _spoolss_endpageprinter(const POLICY_HND *handle)
2772 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2774 if (!OPEN_HANDLE(Printer))
2776 DEBUG(3,("Error in endpageprinter printer handle\n"));
2777 return ERROR_INVALID_HANDLE;
2780 Printer->page_started=False;
2782 return NT_STATUS_NO_PROBLEMO;
2786 /********************************************************************
2787 * api_spoolss_getprinter
2788 * called from the spoolss dispatcher
2790 ********************************************************************/
2791 uint32 _spoolss_startdocprinter( const POLICY_HND *handle, uint32 level,
2792 DOC_INFO *docinfo, uint32 *jobid)
2794 DOC_INFO_1 *info_1 = &docinfo->doc_info_1;
2798 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2800 if (!OPEN_HANDLE(Printer))
2802 return ERROR_INVALID_HANDLE;
2806 * a nice thing with NT is it doesn't listen to what you tell it.
2807 * when asked to send _only_ RAW datas, it tries to send datas
2810 * So I add checks like in NT Server ...
2812 * lkclXXXX jean-francois, i love this kind of thing. oh, well,
2813 * there's a bug in NT client-side code, so we'll fix it in the
2814 * server-side code. *nnnnnggggh!*
2817 if (info_1->p_datatype != 0)
2819 unistr2_to_ascii(datatype, &(info_1->docname), sizeof(datatype));
2820 if (strcmp(datatype, "RAW") != 0)
2823 return ERROR_INVALID_DATATYPE;
2827 /* get the share number of the printer */
2828 if (!get_printer_snum(handle, &snum))
2830 return ERROR_INVALID_HANDLE;
2833 unistr2_to_ascii(jobname, &info_1->docname, sizeof(jobname));
2835 Printer->jobid = print_job_start(snum, jobname);
2837 /* need to map error codes properly - for now give out of
2838 memory as I don't know the correct codes (tridge) */
2839 if (Printer->jobid == -1) {
2840 return ERROR_NOT_ENOUGH_MEMORY;
2843 Printer->document_started=True;
2844 (*jobid) = Printer->jobid;
2849 /********************************************************************
2850 * api_spoolss_getprinter
2851 * called from the spoolss dispatcher
2853 ********************************************************************/
2854 uint32 _spoolss_enddocprinter(const POLICY_HND *handle)
2856 Printer_entry *Printer=find_printer_index_by_hnd(handle);
2858 if (!OPEN_HANDLE(Printer))
2860 DEBUG(3,("Error in enddocprinter handle\n"));
2861 return ERROR_INVALID_HANDLE;
2864 Printer->document_started=False;
2865 print_job_end(Printer->jobid);
2866 /* error codes unhandled so far ... */
2871 /****************************************************************************
2872 ****************************************************************************/
2873 uint32 _spoolss_writeprinter( const POLICY_HND *handle,
2875 const uint8 *buffer,
2876 uint32 *buffer_written)
2878 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2880 if (!OPEN_HANDLE(Printer))
2882 DEBUG(3,("Error in writeprinter handle\n"));
2883 return ERROR_INVALID_HANDLE;
2886 (*buffer_written) = print_job_write(Printer->jobid, buffer, buffer_size);
2891 /********************************************************************
2892 * api_spoolss_getprinter
2893 * called from the spoolss dispatcher
2895 ********************************************************************/
2896 static uint32 control_printer(const POLICY_HND *handle, uint32 command)
2899 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2901 if (!OPEN_HANDLE(Printer))
2902 return ERROR_INVALID_HANDLE;
2904 if (!get_printer_snum(handle, &snum) )
2905 return ERROR_INVALID_HANDLE;
2908 case PRINTER_CONTROL_PAUSE:
2909 if (print_queue_pause(snum)) {
2913 case PRINTER_CONTROL_RESUME:
2914 case PRINTER_CONTROL_UNPAUSE:
2915 if (print_queue_resume(snum)) {
2919 case PRINTER_CONTROL_PURGE:
2920 if (print_queue_purge(snum)) {
2926 return ERROR_INVALID_FUNCTION;
2929 /********************************************************************
2930 * called by spoolss_api_setprinter
2931 * when updating a printer description
2932 ********************************************************************/
2933 static uint32 update_printer_sec(const POLICY_HND *handle, uint32 level,
2934 const SPOOL_PRINTER_INFO_LEVEL *info,
2935 const SEC_DESC_BUF *secdesc_ctr)
2937 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2939 if (!OPEN_HANDLE(Printer))
2940 return ERROR_INVALID_HANDLE;
2942 return nt_printing_setsec(Printer->dev.printername, secdesc_ctr);
2946 /********************************************************************
2947 * called by spoolss_api_setprinter
2948 * when updating a printer description
2949 ********************************************************************/
2950 static uint32 update_printer(const POLICY_HND *handle, uint32 level,
2951 const SPOOL_PRINTER_INFO_LEVEL *info,
2952 const DEVICEMODE *devmode)
2955 NT_PRINTER_INFO_LEVEL printer;
2956 NT_DEVICEMODE *nt_devmode;
2957 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2961 DEBUG(8,("update_printer\n"));
2964 DEBUG(0,("Send a mail to jfm@samba.org\n"));
2965 DEBUGADD(0,("with the following message: update_printer: level!=2\n"));
2966 return ERROR_INVALID_LEVEL;
2969 if (!OPEN_HANDLE(Printer))
2970 return ERROR_INVALID_HANDLE;
2972 if (!get_printer_snum(handle, &snum) )
2973 return ERROR_INVALID_HANDLE;
2975 get_a_printer(&printer, 2, lp_servicename(snum));
2977 DEBUGADD(8,("Converting info_2 struct\n"));
2978 convert_printer_info(info, &printer, level);
2980 if ((info->info_2)->devmode_ptr != 0) {
2981 /* we have a valid devmode
2982 convert it and link it*/
2984 /* the nt_devmode memory is already alloced
2985 * while doing the get_a_printer call
2986 * but the devmode private part is not
2987 * it's done by convert_devicemode
2989 DEBUGADD(8,("Converting the devicemode struct\n"));
2990 nt_devmode=printer.info_2->devmode;
2992 init_devicemode(nt_devmode);
2994 convert_devicemode(*devmode, nt_devmode);
2997 if (printer.info_2->devmode != NULL)
2998 free(printer.info_2->devmode);
2999 printer.info_2->devmode=NULL;
3002 if (add_a_printer(printer, 2)!=0) {
3003 free_a_printer(printer, 2);
3005 /* I don't really know what to return here !!! */
3006 return ERROR_ACCESS_DENIED;
3009 free_a_printer(printer, 2);
3011 return NT_STATUS_NO_PROBLEMO;
3014 /****************************************************************************
3015 ****************************************************************************/
3016 uint32 _spoolss_setprinter(const POLICY_HND *handle, uint32 level,
3017 const SPOOL_PRINTER_INFO_LEVEL *info,
3018 const DEVMODE_CTR devmode_ctr,
3019 const SEC_DESC_BUF *secdesc_ctr,
3022 Printer_entry *Printer = find_printer_index_by_hnd(handle);
3024 if (!OPEN_HANDLE(Printer))
3025 return ERROR_INVALID_HANDLE;
3027 /* check the level */
3030 return control_printer(handle, command);
3033 return update_printer(handle, level, info, devmode_ctr.devmode);
3036 return update_printer_sec(handle, level, info, secdesc_ctr);
3039 return ERROR_INVALID_LEVEL;
3044 /****************************************************************************
3045 ****************************************************************************/
3046 uint32 _spoolss_fcpn(const POLICY_HND *handle)
3048 Printer_entry *Printer= find_printer_index_by_hnd(handle);
3050 if (!OPEN_HANDLE(Printer))
3051 return ERROR_INVALID_HANDLE;
3053 Printer->notify.flags=0;
3054 Printer->notify.options=0;
3055 Printer->notify.localmachine[0]='\0';
3056 Printer->notify.printerlocal=0;
3057 safe_free(Printer->notify.option);
3058 Printer->notify.option=NULL;
3060 return NT_STATUS_NO_PROBLEMO;
3063 /****************************************************************************
3064 ****************************************************************************/
3065 uint32 _spoolss_addjob(const POLICY_HND *handle, uint32 level,
3066 NEW_BUFFER *buffer, uint32 offered)
3068 return NT_STATUS_NO_PROBLEMO;
3071 /****************************************************************************
3072 ****************************************************************************/
3073 static void fill_job_info_1(JOB_INFO_1 *job_info, print_queue_struct *queue,
3074 int position, int snum)
3079 time_t unixdate = time(NULL);
3081 t=gmtime(&unixdate);
3082 snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname);
3084 job_info->jobid=queue->job;
3085 init_unistr(&(job_info->printername), lp_servicename(snum));
3086 init_unistr(&(job_info->machinename), temp_name);
3087 init_unistr(&(job_info->username), queue->user);
3088 init_unistr(&(job_info->document), queue->file);
3089 init_unistr(&(job_info->datatype), "RAW");
3090 init_unistr(&(job_info->text_status), "");
3091 job_info->status=nt_printj_status(queue->status);
3092 job_info->priority=queue->priority;
3093 job_info->position=position;
3094 job_info->totalpages=0;
3095 job_info->pagesprinted=0;
3097 make_systemtime(&(job_info->submitted), t);
3100 /****************************************************************************
3101 ****************************************************************************/
3102 static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue,
3103 int position, int snum)
3106 DEVICEMODE *devmode;
3107 NT_PRINTER_INFO_LEVEL ntprinter;
3111 time_t unixdate = time(NULL);
3113 if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0 )
3116 t=gmtime(&unixdate);
3117 snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname);
3119 job_info->jobid=queue->job;
3121 snprintf(chaine, sizeof(chaine)-1, "\\\\%s\\%s", global_myname, ntprinter.info_2->printername);
3122 init_unistr(&(job_info->printername), chaine);
3124 init_unistr(&(job_info->machinename), temp_name);
3125 init_unistr(&(job_info->username), queue->user);
3126 init_unistr(&(job_info->document), queue->file);
3127 init_unistr(&(job_info->notifyname), queue->user);
3128 init_unistr(&(job_info->datatype), "RAW");
3129 init_unistr(&(job_info->printprocessor), "winprint");
3130 init_unistr(&(job_info->parameters), "");
3131 init_unistr(&(job_info->text_status), "");
3133 /* and here the security descriptor */
3135 job_info->status=nt_printj_status(queue->status);
3136 job_info->priority=queue->priority;
3137 job_info->position=position;
3138 job_info->starttime=0;
3139 job_info->untiltime=0;
3140 job_info->totalpages=0;
3141 job_info->size=queue->size;
3142 make_systemtime(&(job_info->submitted), t);
3143 job_info->timeelapsed=0;
3144 job_info->pagesprinted=0;
3146 if((devmode=(DEVICEMODE *)malloc(sizeof(DEVICEMODE))) == NULL) {
3147 free_a_printer(ntprinter, 2);
3151 ZERO_STRUCTP(devmode);
3152 if(!construct_dev_mode(devmode, snum, global_myname)) {
3153 free_a_printer(ntprinter, 2);
3156 job_info->devmode=devmode;
3158 free_a_printer(ntprinter, 2);
3162 /****************************************************************************
3163 Enumjobs at level 1.
3164 ****************************************************************************/
3165 static uint32 enumjobs_level1(print_queue_struct *queue, int snum,
3166 NEW_BUFFER *buffer, uint32 offered,
3167 uint32 *needed, uint32 *returned)
3172 info=(JOB_INFO_1 *)malloc(*returned*sizeof(JOB_INFO_1));
3176 return ERROR_NOT_ENOUGH_MEMORY;
3179 for (i=0; i<*returned; i++)
3180 fill_job_info_1(&(info[i]), &(queue[i]), i, snum);
3184 /* check the required size. */
3185 for (i=0; i<*returned; i++)
3186 (*needed) += spoolss_size_job_info_1(&(info[i]));
3188 if (!alloc_buffer_size(buffer, *needed)) {
3190 return ERROR_INSUFFICIENT_BUFFER;
3193 /* fill the buffer with the structures */
3194 for (i=0; i<*returned; i++)
3195 new_smb_io_job_info_1("", buffer, &(info[i]), 0);
3200 if (*needed > offered) {
3202 return ERROR_INSUFFICIENT_BUFFER;
3205 return NT_STATUS_NO_PROBLEMO;
3208 /****************************************************************************
3209 Enumjobs at level 2.
3210 ****************************************************************************/
3211 static uint32 enumjobs_level2(print_queue_struct *queue, int snum,
3212 NEW_BUFFER *buffer, uint32 offered,
3213 uint32 *needed, uint32 *returned)
3218 info=(JOB_INFO_2 *)malloc(*returned*sizeof(JOB_INFO_2));
3222 return ERROR_NOT_ENOUGH_MEMORY;
3225 for (i=0; i<*returned; i++)
3226 fill_job_info_2(&(info[i]), &(queue[i]), i, snum);
3230 /* check the required size. */
3231 for (i=0; i<*returned; i++)
3232 (*needed) += spoolss_size_job_info_2(&(info[i]));
3234 if (!alloc_buffer_size(buffer, *needed)) {
3236 return ERROR_INSUFFICIENT_BUFFER;
3239 /* fill the buffer with the structures */
3240 for (i=0; i<*returned; i++)
3241 new_smb_io_job_info_2("", buffer, &(info[i]), 0);
3246 if (*needed > offered) {
3248 return ERROR_INSUFFICIENT_BUFFER;
3251 return NT_STATUS_NO_PROBLEMO;
3254 /****************************************************************************
3256 ****************************************************************************/
3257 uint32 _spoolss_enumjobs( POLICY_HND *handle, uint32 firstjob, uint32 numofjobs, uint32 level,
3258 NEW_BUFFER *buffer, uint32 offered,
3259 uint32 *needed, uint32 *returned)
3262 print_queue_struct *queue=NULL;
3263 print_status_struct prt_status;
3265 DEBUG(4,("_spoolss_enumjobs\n"));
3267 ZERO_STRUCT(prt_status);
3272 if (!get_printer_snum(handle, &snum))
3273 return ERROR_INVALID_HANDLE;
3275 *returned = print_queue_status(snum, &queue, &prt_status);
3276 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n", *returned, prt_status.status, prt_status.message));
3280 return enumjobs_level1(queue, snum, buffer, offered, needed, returned);
3283 return enumjobs_level2(queue, snum, buffer, offered, needed, returned);
3288 return ERROR_INVALID_LEVEL;
3294 /****************************************************************************
3295 ****************************************************************************/
3296 uint32 _spoolss_schedulejob( const POLICY_HND *handle, uint32 jobid)
3301 /****************************************************************************
3302 ****************************************************************************/
3303 uint32 _spoolss_setjob( const POLICY_HND *handle,
3311 print_status_struct prt_status;
3313 memset(&prt_status, 0, sizeof(prt_status));
3315 if (!get_printer_snum(handle, &snum)) {
3316 return ERROR_INVALID_HANDLE;
3319 if (!print_job_exists(jobid)) {
3320 return ERROR_INVALID_PRINTER_NAME;
3324 case JOB_CONTROL_CANCEL:
3325 case JOB_CONTROL_DELETE:
3326 if (print_job_delete(jobid)) return 0x0;
3328 case JOB_CONTROL_PAUSE:
3329 if (print_job_pause(jobid)) return 0x0;
3331 case JOB_CONTROL_RESUME:
3332 if (print_job_resume(jobid)) return 0x0;
3335 return ERROR_INVALID_LEVEL;
3338 return ERROR_INVALID_HANDLE;
3341 /****************************************************************************
3342 Enumerates all printer drivers at level 1.
3343 ****************************************************************************/
3344 static uint32 enumprinterdrivers_level1(fstring *list, fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3347 NT_PRINTER_DRIVER_INFO_LEVEL driver;
3348 DRIVER_INFO_1 *driver_info_1=NULL;
3350 ZERO_STRUCT(driver);
3352 if((driver_info_1=(DRIVER_INFO_1 *)malloc(*returned * sizeof(DRIVER_INFO_1))) == NULL)
3353 return ERROR_NOT_ENOUGH_MEMORY;
3355 for (i=0; i<*returned; i++) {
3356 get_a_printer_driver(&driver, 3, list[i], architecture);
3357 fill_printer_driver_info_1(&(driver_info_1[i]), driver, servername, architecture );
3358 free_a_printer_driver(driver, 3);
3363 /* check the required size. */
3364 for (i=0; i<*returned; i++) {
3365 DEBUGADD(6,("adding driver [%d]'s size\n",i));
3366 *needed += spoolss_size_printer_driver_info_1(&(driver_info_1[i]));
3369 if (!alloc_buffer_size(buffer, *needed)) {
3370 safe_free(driver_info_1);
3371 return ERROR_INSUFFICIENT_BUFFER;
3374 /* fill the buffer with the form structures */
3375 for (i=0; i<*returned; i++) {
3376 DEBUGADD(6,("adding driver [%d] to buffer\n",i));
3377 new_smb_io_printer_driver_info_1("", buffer, &(driver_info_1[i]), 0);
3380 safe_free(driver_info_1);
3382 if (*needed > offered) {
3384 return ERROR_INSUFFICIENT_BUFFER;
3387 return NT_STATUS_NO_PROBLEMO;
3390 /****************************************************************************
3391 Enumerates all printer drivers at level 2.
3392 ****************************************************************************/
3393 static uint32 enumprinterdrivers_level2(fstring *list, fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3396 NT_PRINTER_DRIVER_INFO_LEVEL driver;
3397 DRIVER_INFO_2 *driver_info_2=NULL;
3399 ZERO_STRUCT(driver);
3401 if (*returned > 0 &&
3402 !(driver_info_2=(DRIVER_INFO_2 *)malloc(*returned * sizeof(DRIVER_INFO_2))))
3403 return ERROR_NOT_ENOUGH_MEMORY;
3405 for (i=0; i<*returned; i++) {
3406 get_a_printer_driver(&driver, 3, list[i], architecture);
3407 fill_printer_driver_info_2(&(driver_info_2[i]), driver, servername, architecture );
3408 free_a_printer_driver(driver, 3);
3413 /* check the required size. */
3414 for (i=0; i<*returned; i++) {
3415 DEBUGADD(6,("adding driver [%d]'s size\n",i));
3416 *needed += spoolss_size_printer_driver_info_2(&(driver_info_2[i]));
3419 if (!alloc_buffer_size(buffer, *needed)) {
3420 safe_free(driver_info_2);
3421 return ERROR_INSUFFICIENT_BUFFER;
3424 /* fill the buffer with the form structures */
3425 for (i=0; i<*returned; i++) {
3426 DEBUGADD(6,("adding driver [%d] to buffer\n",i));
3427 new_smb_io_printer_driver_info_2("", buffer, &(driver_info_2[i]), 0);
3430 safe_free(driver_info_2);
3432 if (*needed > offered) {
3434 return ERROR_INSUFFICIENT_BUFFER;
3437 return NT_STATUS_NO_PROBLEMO;
3440 /****************************************************************************
3441 Enumerates all printer drivers at level 3.
3442 ****************************************************************************/
3443 static uint32 enumprinterdrivers_level3(fstring *list, fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3446 NT_PRINTER_DRIVER_INFO_LEVEL driver;
3447 DRIVER_INFO_3 *driver_info_3=NULL;
3449 ZERO_STRUCT(driver);
3451 if((driver_info_3=(DRIVER_INFO_3 *)malloc((*returned)*sizeof(DRIVER_INFO_3))) == NULL)
3452 return ERROR_NOT_ENOUGH_MEMORY;
3454 for (i=0; i<*returned; i++) {
3455 get_a_printer_driver(&driver, 3, list[i], architecture);
3456 fill_printer_driver_info_3(&(driver_info_3[i]), driver, servername, architecture );
3457 free_a_printer_driver(driver, 3);
3462 /* check the required size. */
3463 for (i=0; i<*returned; i++) {
3464 DEBUGADD(6,("adding driver [%d]'s size\n",i));
3465 *needed += spoolss_size_printer_driver_info_3(&(driver_info_3[i]));
3468 if (!alloc_buffer_size(buffer, *needed)) {
3469 safe_free(driver_info_3);
3470 return ERROR_INSUFFICIENT_BUFFER;
3473 /* fill the buffer with the form structures */
3474 for (i=0; i<*returned; i++) {
3475 DEBUGADD(6,("adding form [%d] to buffer\n",i));
3476 new_smb_io_printer_driver_info_3("", buffer, &(driver_info_3[i]), 0);
3479 for (i=0; i<*returned; i++)
3480 safe_free(driver_info_3[i].dependentfiles);
3482 safe_free(driver_info_3);
3484 if (*needed > offered) {
3486 return ERROR_INSUFFICIENT_BUFFER;
3489 return NT_STATUS_NO_PROBLEMO;
3492 /****************************************************************************
3493 Enumerates all printer drivers.
3494 ****************************************************************************/
3495 uint32 _spoolss_enumprinterdrivers( UNISTR2 *name, UNISTR2 *environment, uint32 level,
3496 NEW_BUFFER *buffer, uint32 offered,
3497 uint32 *needed, uint32 *returned)
3500 fstring *list = NULL;
3502 fstring architecture;
3504 DEBUG(4,("_spoolss_enumprinterdrivers\n"));
3505 fstrcpy(servername, global_myname);
3509 unistr2_to_ascii(architecture, environment, sizeof(architecture)-1);
3510 *returned=get_ntdrivers(&list, architecture);
3512 DEBUGADD(4,("we have: [%d] drivers in environment [%s]\n", *returned, architecture));
3514 return ERROR_NOT_ENOUGH_MEMORY;
3516 for (i=0; i<*returned; i++)
3517 DEBUGADD(5,("driver: [%s]\n", list[i]));
3521 return enumprinterdrivers_level1(list, servername, architecture, buffer, offered, needed, returned);
3524 return enumprinterdrivers_level2(list, servername, architecture, buffer, offered, needed, returned);
3527 return enumprinterdrivers_level3(list, servername, architecture, buffer, offered, needed, returned);
3530 return ERROR_INVALID_LEVEL;
3535 /****************************************************************************
3536 ****************************************************************************/
3537 static void fill_form_1(FORM_1 *form, nt_forms_struct *list, int position)
3539 form->flag=list->flag;
3540 init_unistr(&(form->name), list->name);
3541 form->width=list->width;
3542 form->length=list->length;
3543 form->left=list->left;
3544 form->top=list->top;
3545 form->right=list->right;
3546 form->bottom=list->bottom;
3549 /****************************************************************************
3550 ****************************************************************************/
3551 uint32 _new_spoolss_enumforms( const POLICY_HND *handle, uint32 level,
3552 NEW_BUFFER *buffer, uint32 offered,
3553 uint32 *needed, uint32 *numofforms)
3555 nt_forms_struct *list=NULL;
3560 DEBUG(4,("_new_spoolss_enumforms\n"));
3561 DEBUGADD(5,("Offered buffer size [%d]\n", offered));
3562 DEBUGADD(5,("Info level [%d]\n", level));
3564 *numofforms = get_ntforms(&list);
3565 DEBUGADD(5,("Number of forms [%d]\n", *numofforms));
3569 if((forms_1=(FORM_1 *)malloc(*numofforms * sizeof(FORM_1))) == NULL) {
3571 return ERROR_NOT_ENOUGH_MEMORY;
3574 /* construct the list of form structures */
3575 for (i=0; i<*numofforms; i++) {
3576 DEBUGADD(6,("Filling form number [%d]\n",i));
3577 fill_form_1(&(forms_1[i]), &(list[i]), i);
3582 /* check the required size. */
3583 for (i=0; i<*numofforms; i++) {
3584 DEBUGADD(6,("adding form [%d]'s size\n",i));
3585 buffer_size += spoolss_size_form_1(&(forms_1[i]));
3588 *needed=buffer_size;
3590 if (!alloc_buffer_size(buffer, buffer_size)){
3592 return ERROR_INSUFFICIENT_BUFFER;
3595 /* fill the buffer with the form structures */
3596 for (i=0; i<*numofforms; i++) {
3597 DEBUGADD(6,("adding form [%d] to buffer\n",i));
3598 new_smb_io_form_1("", buffer, &(forms_1[i]), 0);
3603 if (*needed > offered) {
3605 return ERROR_INSUFFICIENT_BUFFER;
3608 return NT_STATUS_NO_PROBLEMO;
3612 return ERROR_INVALID_LEVEL;
3617 /****************************************************************************
3618 ****************************************************************************/
3619 static void fill_port_1(PORT_INFO_1 *port, char *name)
3621 init_unistr(&(port->port_name), name);
3624 /****************************************************************************
3625 ****************************************************************************/
3626 static void fill_port_2(PORT_INFO_2 *port, char *name)
3628 init_unistr(&(port->port_name), name);
3629 init_unistr(&(port->monitor_name), "Moniteur Local");
3630 init_unistr(&(port->description), "Local Port");
3631 #define PORT_TYPE_WRITE 1
3632 port->port_type=PORT_TYPE_WRITE;
3636 /****************************************************************************
3638 ****************************************************************************/
3639 static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3641 int n_services=lp_numservices();
3645 PORT_INFO_1 *ports=NULL;
3647 for (snum=0; snum<n_services; snum++)
3648 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
3651 if((ports=(PORT_INFO_1 *)malloc( (*returned+1) * sizeof(PORT_INFO_1) )) == NULL)
3652 return ERROR_NOT_ENOUGH_MEMORY;
3654 for (snum=0; snum<n_services; snum++) {
3655 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
3656 DEBUGADD(6,("Filling port number [%d]\n", i));
3657 fill_port_1(&(ports[i]), lp_servicename(snum));
3662 /* check the required size. */
3663 for (i=0; i<*returned; i++) {
3664 DEBUGADD(6,("adding port [%d]'s size\n", i));
3665 *needed += spoolss_size_port_info_1(&(ports[i]));
3668 if (!alloc_buffer_size(buffer, *needed)) {
3670 return ERROR_INSUFFICIENT_BUFFER;
3673 /* fill the buffer with the ports structures */
3674 for (i=0; i<*returned; i++) {
3675 DEBUGADD(6,("adding port [%d] to buffer\n", i));
3676 new_smb_io_port_1("", buffer, &(ports[i]), 0);
3681 if (*needed > offered) {
3683 return ERROR_INSUFFICIENT_BUFFER;
3686 return NT_STATUS_NO_PROBLEMO;
3690 /****************************************************************************
3692 ****************************************************************************/
3693 static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3695 int n_services=lp_numservices();
3699 PORT_INFO_2 *ports=NULL;
3701 for (snum=0; snum<n_services; snum++)
3702 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
3705 if((ports=(PORT_INFO_2 *)malloc( (*returned+1) * sizeof(PORT_INFO_2) )) == NULL)
3706 return ERROR_NOT_ENOUGH_MEMORY;
3708 for (snum=0; snum<n_services; snum++) {
3709 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
3710 DEBUGADD(6,("Filling port number [%d]\n", i));
3711 fill_port_2(&(ports[i]), lp_servicename(snum));
3716 /* check the required size. */
3717 for (i=0; i<*returned; i++) {
3718 DEBUGADD(6,("adding port [%d]'s size\n", i));
3719 *needed += spoolss_size_port_info_2(&(ports[i]));
3722 if (!alloc_buffer_size(buffer, *needed)) {
3724 return ERROR_INSUFFICIENT_BUFFER;
3727 /* fill the buffer with the ports structures */
3728 for (i=0; i<*returned; i++) {
3729 DEBUGADD(6,("adding port [%d] to buffer\n", i));
3730 new_smb_io_port_2("", buffer, &(ports[i]), 0);
3735 if (*needed > offered) {
3737 return ERROR_INSUFFICIENT_BUFFER;
3740 return NT_STATUS_NO_PROBLEMO;
3743 /****************************************************************************
3745 ****************************************************************************/
3746 uint32 _spoolss_enumports( UNISTR2 *name, uint32 level,
3747 NEW_BUFFER *buffer, uint32 offered,
3748 uint32 *needed, uint32 *returned)
3750 DEBUG(4,("_spoolss_enumports\n"));
3757 return enumports_level_1(buffer, offered, needed, returned);
3760 return enumports_level_2(buffer, offered, needed, returned);
3763 return ERROR_INVALID_LEVEL;
3768 /****************************************************************************
3769 ****************************************************************************/
3770 static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name,
3771 const SPOOL_PRINTER_INFO_LEVEL *info,
3772 uint32 unk0, uint32 unk1, uint32 unk2, uint32 unk3,
3773 uint32 user_switch, const SPOOL_USER_CTR *user,
3776 NT_PRINTER_INFO_LEVEL printer;
3780 clear_handle(handle);
3782 /* NULLify info_2 here */
3783 /* don't put it in convert_printer_info as it's used also with non-NULL values */
3784 printer.info_2=NULL;
3786 /* convert from UNICODE to ASCII */
3787 convert_printer_info(info, &printer, 2);
3789 unistr2_to_ascii(share_name, &((info->info_2)->printername), sizeof(share_name)-1);
3791 slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname, share_name);
3793 /* write the ASCII on disk */
3794 if (add_a_printer(printer, 2) != 0x0)
3795 return ERROR_ACCESS_DENIED;
3797 create_printer_hnd(handle);
3799 open_printer_hnd(handle);
3801 if (!set_printer_hnd_printertype(handle, name)) {
3802 close_printer_handle(handle);
3803 return ERROR_ACCESS_DENIED;
3806 if (!set_printer_hnd_printername(handle, name)) {
3807 close_printer_handle(handle);
3808 return ERROR_ACCESS_DENIED;
3811 return NT_STATUS_NO_PROBLEMO;
3814 /****************************************************************************
3815 ****************************************************************************/
3816 uint32 _spoolss_addprinterex( const UNISTR2 *uni_srv_name, uint32 level,
3817 const SPOOL_PRINTER_INFO_LEVEL *info,
3818 uint32 unk0, uint32 unk1, uint32 unk2, uint32 unk3,
3819 uint32 user_switch, const SPOOL_USER_CTR *user,
3824 /* we don't handle yet */
3825 /* but I know what to do ... */
3826 return ERROR_INVALID_LEVEL;
3829 return spoolss_addprinterex_level_2(uni_srv_name, info,
3830 unk0, unk1, unk2, unk3,
3831 user_switch, user, handle);
3834 return ERROR_INVALID_LEVEL;
3839 /****************************************************************************
3840 Modify internal driver heirarchy.
3841 ****************************************************************************/
3843 static uint32 modify_driver_heirarchy(NT_PRINTER_DRIVER_INFO_LEVEL *driver, uint32 level)
3847 pstring short_archi;
3848 int snum = find_service("print$");
3851 *short_archi = '\0';
3854 get_short_archi(short_archi, driver->info_3->environment);
3855 model = driver->info_3->name;
3858 get_short_archi(short_archi, driver->info_6->environment);
3859 model = driver->info_6->name;
3862 DEBUG(0,("modify_driver_heirarchy: unknown info level (%d)\n", level));
3863 return ERROR_INVALID_LEVEL;
3867 slprintf(path_old, sizeof(path_old)-1, "%s/%s/TMP_%u", lp_pathname(snum), short_archi,
3868 (unsigned int)sys_getpid());
3869 slprintf(path_new, sizeof(path_new)-1, "%s/%s/%s", lp_pathname(snum), short_archi, model);
3871 DEBUG(10,("_spoolss_addprinterdriver: old_path=%s, new_path=%s\n",
3872 path_old, path_new ));
3873 if (dos_rename(path_old, path_new) == -1) {
3874 DEBUG(0,("modify_driver_heirarchy: rename failed (%s)\n", strerror(errno) ));
3875 /* We need to clean up here.... - how ? */
3876 return ERROR_ACCESS_DENIED; /* We need a generic mapping from NT errors here... */
3879 return NT_STATUS_NO_PROBLEMO;
3882 /****************************************************************************
3883 ****************************************************************************/
3884 uint32 _spoolss_addprinterdriver( const UNISTR2 *server_name,
3886 const SPOOL_PRINTER_DRIVER_INFO_LEVEL *info)
3888 NT_PRINTER_DRIVER_INFO_LEVEL driver;
3890 ZERO_STRUCT(driver);
3892 convert_printer_driver_info(info, &driver, level);
3894 if (add_a_printer_driver(driver, level)!=0)
3895 return ERROR_ACCESS_DENIED;
3897 if ((err = modify_driver_heirarchy(&driver, level)) != 0) {
3898 safe_free(driver.info_3);
3899 safe_free(driver.info_6);
3903 safe_free(driver.info_3);
3904 safe_free(driver.info_6);
3906 return NT_STATUS_NO_PROBLEMO;
3909 /****************************************************************************
3910 ****************************************************************************/
3911 static void fill_driverdir_1(DRIVER_DIRECTORY_1 *info, char *name)
3913 init_unistr(&(info->name), name);
3916 /****************************************************************************
3917 ****************************************************************************/
3918 static uint32 getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environment, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
3922 pstring short_archi;
3923 DRIVER_DIRECTORY_1 *info=NULL;
3925 if((info=(DRIVER_DIRECTORY_1 *)malloc(sizeof(DRIVER_DIRECTORY_1))) == NULL)
3926 return ERROR_NOT_ENOUGH_MEMORY;
3928 unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)-1);
3929 get_short_archi(short_archi, long_archi);
3931 slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s\\TMP_%u", global_myname, short_archi,
3932 (unsigned int)sys_getpid());
3933 DEBUG(4,("printer driver directory: [%s]\n", path));
3935 fill_driverdir_1(info, path);
3937 *needed += spoolss_size_driverdir_info_1(info);
3939 if (!alloc_buffer_size(buffer, *needed)) {
3941 return ERROR_INSUFFICIENT_BUFFER;
3944 new_smb_io_driverdir_1("", buffer, info, 0);
3948 if (*needed > offered)
3949 return ERROR_INSUFFICIENT_BUFFER;
3951 return NT_STATUS_NO_PROBLEMO;
3954 /****************************************************************************
3955 ****************************************************************************/
3956 uint32 _spoolss_getprinterdriverdirectory(UNISTR2 *name, UNISTR2 *uni_environment, uint32 level,
3957 NEW_BUFFER *buffer, uint32 offered,
3960 DEBUG(4,("_spoolss_getprinterdriverdirectory\n"));
3966 return getprinterdriverdir_level_1(name, uni_environment, buffer, offered, needed);
3969 return ERROR_INVALID_LEVEL;
3974 /****************************************************************************
3975 ****************************************************************************/
3976 uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx,
3977 uint32 in_value_len, uint32 in_data_len,
3978 uint32 *out_max_value_len, uint16 **out_value, uint32 *out_value_len,
3980 uint32 *out_max_data_len, uint8 **data_out, uint32 *out_data_len)
3982 NT_PRINTER_INFO_LEVEL printer;
3987 uint32 biggest_valuesize;
3988 uint32 biggest_datasize;
3990 Printer_entry *Printer = find_printer_index_by_hnd(handle);
3995 ZERO_STRUCT(printer);
3997 *out_max_value_len=0;
4003 *out_max_data_len=0;
4007 DEBUG(5,("spoolss_enumprinterdata\n"));
4009 if (!OPEN_HANDLE(Printer))
4010 return ERROR_INVALID_HANDLE;
4012 if (!get_printer_snum(handle, &snum))
4013 return ERROR_INVALID_HANDLE;
4015 if (get_a_printer(&printer, 2, lp_servicename(snum)) != 0x0)
4016 return ERROR_INVALID_HANDLE;
4019 * The NT machine wants to know the biggest size of value and data
4021 * cf: MSDN EnumPrinterData remark section
4023 if ( (in_value_len==0) && (in_data_len==0) ) {
4024 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
4027 biggest_valuesize=0;
4030 while (get_specific_param_by_index(printer, 2, param_index, value, &data, &type, &data_len)) {
4031 if (strlen(value) > biggest_valuesize) biggest_valuesize=strlen(value);
4032 if (data_len > biggest_datasize) biggest_datasize=data_len;
4034 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize, biggest_datasize));
4040 /* the value is an UNICODE string but realvaluesize is the length in bytes including the leading 0 */
4041 *out_value_len=2*(1+biggest_valuesize);
4042 *out_data_len=biggest_datasize;
4044 DEBUG(6,("final values: [%d], [%d]\n", *out_value_len, *out_data_len));
4046 free_a_printer(printer, 2);
4047 return NT_STATUS_NO_PROBLEMO;
4051 * the value len is wrong in NT sp3
4052 * that's the number of bytes not the number of unicode chars
4055 if (!get_specific_param_by_index(printer, 2, idx, value, &data, &type, &data_len)) {
4056 free_a_printer(printer, 2);
4058 return ERROR_NO_MORE_ITEMS;
4063 * - counted in bytes in the request
4064 * - counted in UNICODE chars in the max reply
4065 * - counted in bytes in the real size
4067 * take a pause *before* coding not *during* coding
4070 *out_max_value_len=in_value_len;
4071 if((*out_value=(uint16 *)malloc(in_value_len*sizeof(uint8))) == NULL) {
4072 free_a_printer(printer, 2);
4074 return ERROR_NOT_ENOUGH_MEMORY;
4076 ascii_to_unistr((char *)*out_value, value, *out_max_value_len);
4077 *out_value_len=2*(1+strlen(value));
4081 /* the data is counted in bytes */
4082 *out_max_data_len=in_data_len;
4083 if((*data_out=(uint8 *)malloc(in_data_len*sizeof(uint8))) == NULL) {
4084 free_a_printer(printer, 2);
4086 return ERROR_NOT_ENOUGH_MEMORY;
4088 memcpy(*data_out, data, data_len);
4089 *out_data_len=data_len;
4093 free_a_printer(printer, 2);
4094 return NT_STATUS_NO_PROBLEMO;
4097 /****************************************************************************
4098 ****************************************************************************/
4099 uint32 _spoolss_setprinterdata( const POLICY_HND *handle,
4100 const UNISTR2 *value,
4105 uint32 numeric_data)
4107 NT_PRINTER_INFO_LEVEL printer;
4108 NT_PRINTER_PARAM *param = NULL;
4111 uint32 status = 0x0;
4112 Printer_entry *Printer=find_printer_index_by_hnd(handle);
4114 DEBUG(5,("spoolss_setprinterdata\n"));
4117 if (!OPEN_HANDLE(Printer))
4118 return ERROR_INVALID_HANDLE;
4120 if (!get_printer_snum(handle, &snum))
4121 return ERROR_INVALID_HANDLE;
4123 status = get_a_printer(&printer, 2, lp_servicename(snum));
4125 return ERROR_INVALID_NAME;
4127 convert_specific_param(¶m, value , type, data, real_len);
4128 unlink_specific_param_if_exist(printer.info_2, param);
4130 if (!add_a_specific_param(printer.info_2, param))
4131 status = ERROR_INVALID_PARAMETER;
4133 status = add_a_printer(printer, 2);
4135 free_a_printer(printer, 2);
4140 /****************************************************************************
4141 ****************************************************************************/
4142 uint32 _spoolss_addform( const POLICY_HND *handle,
4147 nt_forms_struct *list=NULL;
4148 Printer_entry *Printer = find_printer_index_by_hnd(handle);
4150 DEBUG(5,("spoolss_addform\n"));
4152 if (!OPEN_HANDLE(Printer))
4153 return ERROR_INVALID_HANDLE;
4155 count=get_ntforms(&list);
4156 if(!add_a_form(&list, form, &count))
4157 return ERROR_NOT_ENOUGH_MEMORY;
4158 write_ntforms(&list, count);
4165 /****************************************************************************
4166 ****************************************************************************/
4167 uint32 _spoolss_setform( const POLICY_HND *handle,
4168 const UNISTR2 *uni_name,
4173 nt_forms_struct *list=NULL;
4174 Printer_entry *Printer = find_printer_index_by_hnd(handle);
4176 DEBUG(5,("spoolss_setform\n"));
4178 if (!OPEN_HANDLE(Printer))
4180 return ERROR_INVALID_HANDLE;
4182 count=get_ntforms(&list);
4183 update_a_form(&list, form, count);
4184 write_ntforms(&list, count);
4191 /****************************************************************************
4192 enumprintprocessors level 1.
4193 ****************************************************************************/
4194 static uint32 enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4196 PRINTPROCESSOR_1 *info_1=NULL;
4198 if((info_1 = (PRINTPROCESSOR_1 *)malloc(sizeof(PRINTPROCESSOR_1))) == NULL)
4199 return ERROR_NOT_ENOUGH_MEMORY;
4203 init_unistr(&(info_1->name), "winprint");
4205 *needed += spoolss_size_printprocessor_info_1(info_1);
4207 if (!alloc_buffer_size(buffer, *needed))
4208 return ERROR_INSUFFICIENT_BUFFER;
4210 smb_io_printprocessor_info_1("", buffer, info_1, 0);
4214 if (*needed > offered) {
4216 return ERROR_INSUFFICIENT_BUFFER;
4219 return NT_STATUS_NO_PROBLEMO;
4222 /****************************************************************************
4223 ****************************************************************************/
4224 uint32 _spoolss_enumprintprocessors(UNISTR2 *name, UNISTR2 *environment, uint32 level,
4225 NEW_BUFFER *buffer, uint32 offered,
4226 uint32 *needed, uint32 *returned)
4228 DEBUG(5,("spoolss_enumprintprocessors\n"));
4231 * Enumerate the print processors ...
4233 * Just reply with "winprint", to keep NT happy
4234 * and I can use my nice printer checker.
4242 return enumprintprocessors_level_1(buffer, offered, needed, returned);
4245 return ERROR_INVALID_LEVEL;
4250 /****************************************************************************
4251 enumprintprocdatatypes level 1.
4252 ****************************************************************************/
4253 static uint32 enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4255 PRINTPROCDATATYPE_1 *info_1=NULL;
4257 if((info_1 = (PRINTPROCDATATYPE_1 *)malloc(sizeof(PRINTPROCDATATYPE_1))) == NULL)
4258 return ERROR_NOT_ENOUGH_MEMORY;
4262 init_unistr(&(info_1->name), "RAW");
4264 *needed += spoolss_size_printprocdatatype_info_1(info_1);
4266 if (!alloc_buffer_size(buffer, *needed))
4267 return ERROR_INSUFFICIENT_BUFFER;
4269 smb_io_printprocdatatype_info_1("", buffer, info_1, 0);
4273 if (*needed > offered) {
4275 return ERROR_INSUFFICIENT_BUFFER;
4278 return NT_STATUS_NO_PROBLEMO;
4281 /****************************************************************************
4282 ****************************************************************************/
4283 uint32 _spoolss_enumprintprocdatatypes(UNISTR2 *name, UNISTR2 *processor, uint32 level,
4284 NEW_BUFFER *buffer, uint32 offered,
4285 uint32 *needed, uint32 *returned)
4287 DEBUG(5,("_spoolss_enumprintprocdatatypes\n"));
4294 return enumprintprocdatatypes_level_1(buffer, offered, needed, returned);
4297 return ERROR_INVALID_LEVEL;
4302 /****************************************************************************
4303 enumprintmonitors level 1.
4304 ****************************************************************************/
4305 static uint32 enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4307 PRINTMONITOR_1 *info_1=NULL;
4309 if((info_1 = (PRINTMONITOR_1 *)malloc(sizeof(PRINTMONITOR_1))) == NULL)
4310 return ERROR_NOT_ENOUGH_MEMORY;
4314 init_unistr(&(info_1->name), "Local Port");
4316 *needed += spoolss_size_printmonitor_info_1(info_1);
4318 if (!alloc_buffer_size(buffer, *needed))
4319 return ERROR_INSUFFICIENT_BUFFER;
4321 smb_io_printmonitor_info_1("", buffer, info_1, 0);
4325 if (*needed > offered) {
4327 return ERROR_INSUFFICIENT_BUFFER;
4330 return NT_STATUS_NO_PROBLEMO;
4333 /****************************************************************************
4334 enumprintmonitors level 2.
4335 ****************************************************************************/
4336 static uint32 enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4338 PRINTMONITOR_2 *info_2=NULL;
4340 if((info_2 = (PRINTMONITOR_2 *)malloc(sizeof(PRINTMONITOR_2))) == NULL)
4341 return ERROR_NOT_ENOUGH_MEMORY;
4345 init_unistr(&(info_2->name), "Local Port");
4346 init_unistr(&(info_2->environment), "Windows NT X86");
4347 init_unistr(&(info_2->dll_name), "localmon.dll");
4349 *needed += spoolss_size_printmonitor_info_2(info_2);
4351 if (!alloc_buffer_size(buffer, *needed))
4352 return ERROR_INSUFFICIENT_BUFFER;
4354 smb_io_printmonitor_info_2("", buffer, info_2, 0);
4358 if (*needed > offered) {
4360 return ERROR_INSUFFICIENT_BUFFER;
4363 return NT_STATUS_NO_PROBLEMO;
4366 /****************************************************************************
4367 ****************************************************************************/
4368 uint32 _spoolss_enumprintmonitors(UNISTR2 *name,uint32 level,
4369 NEW_BUFFER *buffer, uint32 offered,
4370 uint32 *needed, uint32 *returned)
4372 DEBUG(5,("spoolss_enumprintmonitors\n"));
4375 * Enumerate the print monitors ...
4377 * Just reply with "Local Port", to keep NT happy
4378 * and I can use my nice printer checker.
4386 return enumprintmonitors_level_1(buffer, offered, needed, returned);
4389 return enumprintmonitors_level_2(buffer, offered, needed, returned);
4392 return ERROR_INVALID_LEVEL;
4397 /****************************************************************************
4398 ****************************************************************************/
4399 static uint32 getjob_level_1(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
4403 JOB_INFO_1 *info_1=NULL;
4405 info_1=(JOB_INFO_1 *)malloc(sizeof(JOB_INFO_1));
4407 if (info_1 == NULL) {
4409 return ERROR_NOT_ENOUGH_MEMORY;
4412 for (i=0; i<count && found==False; i++) {
4413 if (queue[i].job==(int)jobid)
4420 /* I shoud reply something else ... I can't find the good one */
4421 return NT_STATUS_NO_PROBLEMO;
4424 fill_job_info_1(info_1, &(queue[i-1]), i, snum);
4428 *needed += spoolss_size_job_info_1(info_1);
4430 if (!alloc_buffer_size(buffer, *needed)) {
4432 return ERROR_INSUFFICIENT_BUFFER;
4435 new_smb_io_job_info_1("", buffer, info_1, 0);
4439 if (*needed > offered)
4440 return ERROR_INSUFFICIENT_BUFFER;
4442 return NT_STATUS_NO_PROBLEMO;
4446 /****************************************************************************
4447 ****************************************************************************/
4448 static uint32 getjob_level_2(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
4452 JOB_INFO_2 *info_2=NULL;
4453 info_2=(JOB_INFO_2 *)malloc(sizeof(JOB_INFO_2));
4455 if (info_2 == NULL) {
4457 return ERROR_NOT_ENOUGH_MEMORY;
4460 for (i=0; i<count && found==False; i++) {
4461 if (queue[i].job==(int)jobid)
4468 /* I shoud reply something else ... I can't find the good one */
4469 return NT_STATUS_NO_PROBLEMO;
4472 fill_job_info_2(info_2, &(queue[i-1]), i, snum);
4476 *needed += spoolss_size_job_info_2(info_2);
4478 if (!alloc_buffer_size(buffer, *needed)) {
4480 return ERROR_INSUFFICIENT_BUFFER;
4483 new_smb_io_job_info_2("", buffer, info_2, 0);
4487 if (*needed > offered)
4488 return ERROR_INSUFFICIENT_BUFFER;
4490 return NT_STATUS_NO_PROBLEMO;
4493 /****************************************************************************
4494 ****************************************************************************/
4495 uint32 _spoolss_getjob( POLICY_HND *handle, uint32 jobid, uint32 level,
4496 NEW_BUFFER *buffer, uint32 offered,
4501 print_queue_struct *queue=NULL;
4502 print_status_struct prt_status;
4504 DEBUG(5,("spoolss_getjob\n"));
4506 memset(&prt_status, 0, sizeof(prt_status));
4510 if (!get_printer_snum(handle, &snum))
4511 return ERROR_INVALID_HANDLE;
4513 count = print_queue_status(snum, &queue, &prt_status);
4515 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
4516 count, prt_status.status, prt_status.message));
4520 return getjob_level_1(queue, count, snum, jobid, buffer, offered, needed);
4523 return getjob_level_2(queue, count, snum, jobid, buffer, offered, needed);
4527 return ERROR_INVALID_LEVEL;