2 * Unix SMB/Netbios implementation.
4 * RPC Pipe client / server routines
5 * Copyright (C) Andrew Tridgell 1992-2000,
6 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
7 * Copyright (C) Jean François Micouleau 1998-2000.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * 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 /****************************************************************************
86 initialise printer handle states...
87 ****************************************************************************/
88 void init_printer_hnd(void)
90 ubi_dlInitList(&Printer_list);
91 ubi_dlInitList(&counter_list);
94 /****************************************************************************
95 create a unique printer handle
96 ****************************************************************************/
97 static void create_printer_hnd(POLICY_HND *hnd)
99 static uint32 prt_hnd_low = 0;
100 static uint32 prt_hnd_high = 0;
102 if (hnd == NULL) return;
104 /* i severely doubt that prt_hnd_high will ever be non-zero... */
106 if (prt_hnd_low == 0) prt_hnd_high++;
108 SIVAL(hnd->data, 0 , 0x0); /* first bit must be null */
109 SIVAL(hnd->data, 4 , prt_hnd_low ); /* second bit is incrementing */
110 SIVAL(hnd->data, 8 , prt_hnd_high); /* second bit is incrementing */
111 SIVAL(hnd->data, 12, time(NULL)); /* something random */
112 SIVAL(hnd->data, 16, getpid()); /* something more random */
115 /****************************************************************************
116 find printer index by handle
117 ****************************************************************************/
118 static Printer_entry *find_printer_index_by_hnd(const POLICY_HND *hnd)
120 Printer_entry *find_printer;
122 find_printer = (Printer_entry *)ubi_dlFirst(&Printer_list);
124 for(; find_printer; find_printer = (Printer_entry *)ubi_dlNext(find_printer)) {
126 if (memcmp(&(find_printer->printer_hnd), hnd, sizeof(*hnd)) == 0)
128 DEBUG(4,("Found printer handle \n"));
129 /*dump_data(4, hnd->data, sizeof(hnd->data));*/
134 DEBUG(3,("Whoops, Printer handle not found: "));
135 /*dump_data(4, hnd->data, sizeof(hnd->data));*/
139 /****************************************************************************
141 ****************************************************************************/
142 static void clear_handle(POLICY_HND *hnd)
144 memset(hnd->data, 0, POLICY_HND_SIZE);
147 /****************************************************************************
148 close printer index by handle
149 ****************************************************************************/
150 static BOOL close_printer_handle(POLICY_HND *hnd)
152 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
154 if (!OPEN_HANDLE(Printer))
156 DEBUG(3,("Error closing printer handle\n"));
161 Printer->notify.flags=0;
162 Printer->notify.options=0;
163 Printer->notify.localmachine[0]='\0';
164 Printer->notify.printerlocal=0;
165 safe_free(Printer->notify.option);
166 Printer->notify.option=NULL;
170 ubi_dlRemThis(&Printer_list, Printer);
177 /****************************************************************************
178 return the snum of a printer corresponding to an handle
179 ****************************************************************************/
180 static BOOL get_printer_snum(const POLICY_HND *hnd, int *number)
182 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
184 if (!OPEN_HANDLE(Printer)) {
185 DEBUG(3,("Error getting printer - take a nap quickly !\n"));
189 switch (Printer->printer_type) {
190 case PRINTER_HANDLE_IS_PRINTER:
191 DEBUG(4,("short name:%s\n", Printer->dev.printername));
192 *number = print_queue_snum(Printer->dev.printername);
193 return (*number != -1);
194 case PRINTER_HANDLE_IS_PRINTSERVER:
203 /****************************************************************************
204 find first available printer slot. creates a printer handle for you.
205 ****************************************************************************/
206 static BOOL open_printer_hnd(POLICY_HND *hnd)
208 Printer_entry *new_printer;
210 if((new_printer=(Printer_entry *)malloc(sizeof(Printer_entry))) == NULL)
213 ZERO_STRUCTP(new_printer);
215 new_printer->open = True;
216 new_printer->notify.option=NULL;
218 memcpy(&(new_printer->printer_hnd), hnd, sizeof(*hnd));
220 ubi_dlAddHead( &Printer_list, (ubi_dlNode *)new_printer);
225 /****************************************************************************
226 set printer handle type.
227 ****************************************************************************/
228 static BOOL set_printer_hnd_accesstype(POLICY_HND *hnd, uint32 access_required)
230 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
232 if (!OPEN_HANDLE(Printer)) {
233 DEBUG(4,("Error setting printer type=%x", access_required));
237 DEBUG(4,("Setting printer access=%x\n", access_required));
238 Printer->access = access_required;
242 /****************************************************************************
243 set printer handle type.
244 check if it's \\server or \\server\printer
245 ****************************************************************************/
246 static BOOL set_printer_hnd_printertype(POLICY_HND *hnd, char *printername)
248 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
250 if (!OPEN_HANDLE(Printer)) {
251 DEBUGADD(4,("Error setting printer name %s", printername));
255 DEBUG(3,("Setting printer type=%s\n", printername));
257 if ( strlen(printername) < 3 ) {
258 DEBUGADD(4,("A print server must have at least 1 char ! %s\n", printername));
262 /* it's a print server */
263 if (!strchr(printername+2, '\\')) {
264 DEBUGADD(4,("Printer is a print server\n"));
265 Printer->printer_type = PRINTER_HANDLE_IS_PRINTSERVER;
270 DEBUGADD(4,("Printer is a printer\n"));
271 Printer->printer_type = PRINTER_HANDLE_IS_PRINTER;
278 /****************************************************************************
279 set printer handle printername.
280 ****************************************************************************/
281 static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername)
283 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
284 NT_PRINTER_INFO_LEVEL printer;
286 int n_services=lp_numservices();
290 if (!OPEN_HANDLE(Printer)) {
291 DEBUG(0,("Error setting printer name=%s\n", printername));
295 DEBUG(4,("Setting printer name=%s (len=%d)\n", printername, strlen(printername)));
297 if (Printer->printer_type==PRINTER_HANDLE_IS_PRINTSERVER) {
298 ZERO_STRUCT(Printer->dev.printerservername);
299 strncpy(Printer->dev.printerservername, printername, strlen(printername));
303 if (Printer->printer_type!=PRINTER_HANDLE_IS_PRINTER)
306 aprinter=strchr(printername+2, '\\');
309 DEBUGADD(5,("searching for [%s] (len=%d)\n", aprinter, strlen(aprinter)));
312 * store the Samba share name in it
313 * in back we have the long printer name
314 * need to iterate all the snum and do a
315 * get_a_printer each time to find the printer
316 * faster to do it here than later.
319 for (snum=0;snum<n_services && found==False;snum++) {
321 if ( !(lp_snum_ok(snum) && lp_print_ok(snum) ) )
324 DEBUGADD(5,("share:%s\n",lp_servicename(snum)));
326 if (get_a_printer(&printer, 2, lp_servicename(snum))!=0)
329 DEBUG(10,("set_printer_hnd_printername: printername [%s], aprinter [%s]\n",
330 printer.info_2->printername, aprinter ));
332 if ( strlen(printer.info_2->printername) != strlen(aprinter) ) {
333 free_a_printer(printer, 2);
337 if ( strncasecmp(printer.info_2->printername, aprinter, strlen(aprinter))) {
338 free_a_printer(printer, 2);
346 * if we haven't found a printer with the given printername
347 * then it can be a share name as you can open both \\server\printer and
352 * we still check if the printer description file exists as NT won't be happy
353 * if we reply OK in the openprinter call and can't reply in the subsequent RPC calls
357 DEBUGADD(5,("Printer not found, checking for share now\n"));
359 for (snum=0;snum<n_services && found==False;snum++) {
361 if ( !(lp_snum_ok(snum) && lp_print_ok(snum) ) )
364 DEBUGADD(5,("share:%s\n",lp_servicename(snum)));
366 if (get_a_printer(&printer, 2, lp_servicename(snum))!=0)
369 DEBUG(10,("set_printer_hnd_printername: printername [%s], aprinter [%s]\n",
370 printer.info_2->printername, aprinter ));
372 if ( strlen(lp_servicename(snum)) != strlen(aprinter) ) {
373 free_a_printer(printer, 2);
377 if ( strncasecmp(lp_servicename(snum), aprinter, strlen(aprinter))) {
378 free_a_printer(printer, 2);
387 DEBUGADD(4,("Printer not found\n"));
392 DEBUGADD(4,("Printer found: %s -> %s[%x]\n",printer.info_2->printername, lp_servicename(snum),snum));
393 ZERO_STRUCT(Printer->dev.printername);
394 strncpy(Printer->dev.printername, lp_servicename(snum), strlen(lp_servicename(snum)));
395 free_a_printer(printer, 2);
400 /********************************************************************
401 Return True is the handle is a print server.
402 ********************************************************************/
403 static BOOL handle_is_printserver(const POLICY_HND *handle)
405 Printer_entry *Printer=find_printer_index_by_hnd(handle);
407 if (!OPEN_HANDLE(Printer))
410 if (Printer->printer_type != PRINTER_HANDLE_IS_PRINTSERVER)
416 /****************************************************************************
417 allocate more memory for a BUFFER.
418 ****************************************************************************/
419 static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size)
427 /* damn, I'm doing the reverse operation of prs_grow() :) */
428 if (buffer_size < prs_data_size(ps))
431 extra_space = buffer_size - prs_data_size(ps);
434 * save the offset and move to the end of the buffer
435 * prs_grow() checks the extra_space against the offset
437 old_offset=prs_offset(ps);
438 prs_set_offset(ps, prs_data_size(ps));
440 if (!prs_grow(ps, extra_space))
443 prs_set_offset(ps, old_offset);
445 buffer->string_at_end=prs_data_size(ps);
450 /********************************************************************
451 * spoolss_open_printer
453 * called from the spoolss dispatcher
454 ********************************************************************/
455 uint32 _spoolss_open_printer_ex( const UNISTR2 *printername,
456 const PRINTER_DEFAULT *printer_default,
457 uint32 user_switch, SPOOL_USER_CTR user_ctr,
462 clear_handle(handle);
464 if (printername == NULL)
465 return ERROR_INVALID_PRINTER_NAME;
467 /* some sanity check because you can open a printer or a print server */
468 /* aka: \\server\printer or \\server */
469 unistr2_to_ascii(name, printername, sizeof(name)-1);
471 DEBUGADD(3,("checking name: %s\n",name));
473 create_printer_hnd(handle);
475 open_printer_hnd(handle);
477 if (!set_printer_hnd_printertype(handle, name)) {
478 close_printer_handle(handle);
479 return ERROR_INVALID_PRINTER_NAME;
482 if (!set_printer_hnd_printername(handle, name)) {
483 close_printer_handle(handle);
484 return ERROR_INVALID_PRINTER_NAME;
488 if (printer_default->datatype_ptr != NULL)
490 unistr2_to_ascii(datatype, printer_default->datatype, sizeof(datatype)-1);
491 set_printer_hnd_datatype(handle, datatype);
494 set_printer_hnd_datatype(handle, "");
497 if (!set_printer_hnd_accesstype(handle, printer_default->access_required)) {
498 close_printer_handle(handle);
499 return ERROR_ACCESS_DENIED;
502 return NT_STATUS_NO_PROBLEMO;
505 /****************************************************************************
506 ****************************************************************************/
507 static BOOL convert_printer_info(const SPOOL_PRINTER_INFO_LEVEL *uni,
508 NT_PRINTER_INFO_LEVEL *printer, uint32 level)
512 uni_2_asc_printer_info_2(uni->info_2, &(printer->info_2));
521 static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL *uni,
522 NT_PRINTER_DRIVER_INFO_LEVEL *printer, uint32 level)
526 printer->info_3=NULL;
527 uni_2_asc_printer_driver_3(uni->info_3, &(printer->info_3));
536 static BOOL convert_devicemode(DEVICEMODE devmode, NT_DEVICEMODE *nt_devmode)
538 unistr_to_ascii(nt_devmode->devicename, devmode.devicename.buffer, 31);
539 unistr_to_ascii(nt_devmode->formname, devmode.formname.buffer, 31);
541 nt_devmode->specversion=devmode.specversion;
542 nt_devmode->driverversion=devmode.driverversion;
543 nt_devmode->size=devmode.size;
544 nt_devmode->driverextra=devmode.driverextra;
545 nt_devmode->fields=devmode.fields;
546 nt_devmode->orientation=devmode.orientation;
547 nt_devmode->papersize=devmode.papersize;
548 nt_devmode->paperlength=devmode.paperlength;
549 nt_devmode->paperwidth=devmode.paperwidth;
550 nt_devmode->scale=devmode.scale;
551 nt_devmode->copies=devmode.copies;
552 nt_devmode->defaultsource=devmode.defaultsource;
553 nt_devmode->printquality=devmode.printquality;
554 nt_devmode->color=devmode.color;
555 nt_devmode->duplex=devmode.duplex;
556 nt_devmode->yresolution=devmode.yresolution;
557 nt_devmode->ttoption=devmode.ttoption;
558 nt_devmode->collate=devmode.collate;
560 nt_devmode->logpixels=devmode.logpixels;
561 nt_devmode->bitsperpel=devmode.bitsperpel;
562 nt_devmode->pelswidth=devmode.pelswidth;
563 nt_devmode->pelsheight=devmode.pelsheight;
564 nt_devmode->displayflags=devmode.displayflags;
565 nt_devmode->displayfrequency=devmode.displayfrequency;
566 nt_devmode->icmmethod=devmode.icmmethod;
567 nt_devmode->icmintent=devmode.icmintent;
568 nt_devmode->mediatype=devmode.mediatype;
569 nt_devmode->dithertype=devmode.dithertype;
570 nt_devmode->reserved1=devmode.reserved1;
571 nt_devmode->reserved2=devmode.reserved2;
572 nt_devmode->panningwidth=devmode.panningwidth;
573 nt_devmode->panningheight=devmode.panningheight;
575 if (nt_devmode->driverextra != 0)
577 /* if we had a previous private delete it and make a new one */
578 if (nt_devmode->private != NULL)
579 free(nt_devmode->private);
580 if((nt_devmode->private=(uint8 *)malloc(nt_devmode->driverextra * sizeof(uint8))) == NULL)
582 memcpy(nt_devmode->private, devmode.private, nt_devmode->driverextra);
588 /********************************************************************
589 * api_spoolss_closeprinter
590 ********************************************************************/
591 uint32 _spoolss_closeprinter(POLICY_HND *handle)
593 if (!close_printer_handle(handle))
594 return ERROR_INVALID_HANDLE;
596 return NT_STATUS_NO_PROBLEMO;
599 /********************************************************************
600 GetPrinterData on a printer server Handle.
601 ********************************************************************/
602 static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **data, uint32 *needed, uint32 in_size)
606 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
608 if (!strcmp(value, "BeepEnabled"))
611 if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL)
613 SIVAL(*data, 0, 0x01);
618 if (!strcmp(value, "EventLog"))
621 if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL)
623 SIVAL(*data, 0, 0x1B);
628 if (!strcmp(value, "NetPopup"))
631 if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL)
633 SIVAL(*data, 0, 0x01);
638 if (!strcmp(value, "MajorVersion"))
641 if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL)
643 SIVAL(*data, 0, 0x02);
648 if (!strcmp(value, "DefaultSpoolDirectory"))
650 pstring string="You are using a Samba server";
652 *needed = 2*(strlen(string)+1);
653 if((*data = (uint8 *)malloc( ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL)
655 memset(*data, 0, (*needed > in_size) ? *needed:in_size);
657 /* it's done by hand ready to go on the wire */
658 for (i=0; i<strlen(string); i++)
660 (*data)[2*i]=string[i];
666 if (!strcmp(value, "Architecture"))
668 pstring string="Windows NT x86";
670 *needed = 2*(strlen(string)+1);
671 if((*data = (uint8 *)malloc( ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL)
673 memset(*data, 0, (*needed > in_size) ? *needed:in_size);
674 for (i=0; i<strlen(string); i++)
676 (*data)[2*i]=string[i];
685 /********************************************************************
686 GetPrinterData on a printer Handle.
687 ********************************************************************/
688 static BOOL getprinterdata_printer(const POLICY_HND *handle,
689 fstring value, uint32 *type,
690 uint8 **data, uint32 *needed, uint32 in_size )
692 NT_PRINTER_INFO_LEVEL printer;
696 Printer_entry *Printer = find_printer_index_by_hnd(handle);
698 DEBUG(5,("getprinterdata_printer\n"));
700 if (!OPEN_HANDLE(Printer))
703 if(!get_printer_snum(handle, &snum))
706 if(get_a_printer(&printer, 2, lp_servicename(snum)) != 0)
709 if (!get_specific_param(printer, 2, value, &idata, type, &len)) {
710 free_a_printer(printer, 2);
714 DEBUG(5,("getprinterdata_printer:allocating %d\n", in_size));
716 if((*data = (uint8 *)malloc( in_size *sizeof(uint8) )) == NULL) {
717 free_a_printer(printer, 2);
721 memset(*data, 0, in_size *sizeof(uint8));
722 /* copy the min(in_size, len) */
723 memcpy(*data, idata, (len>in_size)?in_size:len *sizeof(uint8));
727 DEBUG(5,("getprinterdata_printer:copy done\n"));
729 free_a_printer(printer, 2);
735 /********************************************************************
736 * spoolss_getprinterdata
737 ********************************************************************/
738 uint32 _spoolss_getprinterdata(const POLICY_HND *handle, UNISTR2 *valuename,
747 Printer_entry *Printer = find_printer_index_by_hnd(handle);
750 * Reminder: when it's a string, the length is in BYTES
751 * even if UNICODE is negociated.
758 /* in case of problem, return some default values */
762 DEBUG(4,("_spoolss_getprinterdata\n"));
764 if (!OPEN_HANDLE(Printer)) {
765 if((*data=(uint8 *)malloc(4*sizeof(uint8))) == NULL)
766 return ERROR_NOT_ENOUGH_MEMORY;
767 return ERROR_INVALID_HANDLE;
770 unistr2_to_ascii(value, valuename, sizeof(value)-1);
772 if (handle_is_printserver(handle))
773 found=getprinterdata_printer_server(value, type, data, needed, *out_size);
775 found=getprinterdata_printer(handle, value, type, data, needed, *out_size);
778 DEBUG(5, ("value not found, allocating %d\n", *out_size));
779 /* reply this param doesn't exist */
780 if((*data=(uint8 *)malloc(*out_size*sizeof(uint8))) == NULL)
781 return ERROR_NOT_ENOUGH_MEMORY;
782 memset(*data, 0x0, *out_size*sizeof(uint8));
783 return ERROR_INVALID_PARAMETER;
786 if (*needed > *out_size)
787 return ERROR_INSUFFICIENT_BUFFER;
789 return NT_STATUS_NO_PROBLEMO;
792 /********************************************************************
794 * ReplyFindFirstPrinterChangeNotifyEx
796 * jfmxxxx: before replying OK: status=0
797 * should do a rpc call to the workstation asking ReplyOpenPrinter
798 * have to code it, later.
800 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
801 * called from api_spoolss_rffpcnex
802 ********************************************************************/
803 uint32 _spoolss_rffpcnex(const POLICY_HND *handle, uint32 flags, uint32 options,
804 const UNISTR2 *localmachine, uint32 printerlocal,
805 SPOOL_NOTIFY_OPTION *option)
807 /* store the notify value in the printer struct */
809 Printer_entry *Printer=find_printer_index_by_hnd(handle);
811 if (!OPEN_HANDLE(Printer))
812 return ERROR_INVALID_HANDLE;
814 Printer->notify.flags=flags;
815 Printer->notify.options=options;
816 Printer->notify.printerlocal=printerlocal;
817 Printer->notify.option=option;
818 unistr2_to_ascii(Printer->notify.localmachine, localmachine, sizeof(Printer->notify.localmachine)-1);
820 return NT_STATUS_NO_PROBLEMO;
823 /*******************************************************************
824 * fill a notify_info_data with the servername
825 ********************************************************************/
826 static void spoolss_notify_server_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
830 snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname);
832 data->notify_data.data.length=strlen(temp_name);
833 ascii_to_unistr(data->notify_data.data.string, temp_name, sizeof(data->notify_data.data.string)-1);
836 /*******************************************************************
837 * fill a notify_info_data with the servicename
838 * jfmxxxx: it's incorrect should be long_printername
839 ********************************************************************/
840 static void spoolss_notify_printer_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
843 data->notify_data.data.length=strlen(lp_servicename(snum));
844 ascii_to_unistr(data->notify_data.data.string, lp_servicename(snum), sizeof(data->notify_data.data.string)-1);
846 data->notify_data.data.length=strlen(printer->info_2->printername);
847 ascii_to_unistr(data->notify_data.data.string,
848 printer->info_2->printername,
849 sizeof(data->notify_data.data.string)-1);
852 /*******************************************************************
853 * fill a notify_info_data with the servicename
854 ********************************************************************/
855 static void spoolss_notify_share_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
857 data->notify_data.data.length=strlen(lp_servicename(snum));
858 ascii_to_unistr(data->notify_data.data.string,
859 lp_servicename(snum),
860 sizeof(data->notify_data.data.string)-1);
863 /*******************************************************************
864 * fill a notify_info_data with the port name
865 ********************************************************************/
866 static void spoolss_notify_port_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
868 /* even if it's strange, that's consistant in all the code */
870 data->notify_data.data.length=strlen(lp_servicename(snum));
871 ascii_to_unistr(data->notify_data.data.string,
872 lp_servicename(snum),
873 sizeof(data->notify_data.data.string)-1);
876 /*******************************************************************
877 * fill a notify_info_data with the printername
878 * jfmxxxx: it's incorrect, should be lp_printerdrivername()
879 * but it doesn't exist, have to see what to do
880 ********************************************************************/
881 static void spoolss_notify_driver_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
883 data->notify_data.data.length=strlen(printer->info_2->drivername);
884 ascii_to_unistr(data->notify_data.data.string,
885 printer->info_2->drivername,
886 sizeof(data->notify_data.data.string)-1);
889 /*******************************************************************
890 * fill a notify_info_data with the comment
891 ********************************************************************/
892 static void spoolss_notify_comment(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
894 data->notify_data.data.length=strlen(lp_comment(snum));
895 ascii_to_unistr(data->notify_data.data.string,
897 sizeof(data->notify_data.data.string)-1);
900 /*******************************************************************
901 * fill a notify_info_data with the comment
902 * jfm:xxxx incorrect, have to create a new smb.conf option
903 * location = "Room 1, floor 2, building 3"
904 ********************************************************************/
905 static void spoolss_notify_location(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
907 data->notify_data.data.length=strlen(printer->info_2->location);
908 ascii_to_unistr(data->notify_data.data.string,
909 printer->info_2->location,
910 sizeof(data->notify_data.data.string)-1);
913 /*******************************************************************
914 * fill a notify_info_data with the device mode
915 * jfm:xxxx don't to it for know but that's a real problem !!!
916 ********************************************************************/
917 static void spoolss_notify_devmode(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
921 /*******************************************************************
922 * fill a notify_info_data with the separator file name
923 * jfm:xxxx just return no file could add an option to smb.conf
924 * separator file = "separator.txt"
925 ********************************************************************/
926 static void spoolss_notify_sepfile(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
928 data->notify_data.data.length=strlen(printer->info_2->sepfile);
929 ascii_to_unistr(data->notify_data.data.string,
930 printer->info_2->sepfile,
931 sizeof(data->notify_data.data.string)-1);
934 /*******************************************************************
935 * fill a notify_info_data with the print processor
936 * jfm:xxxx return always winprint to indicate we don't do anything to it
937 ********************************************************************/
938 static void spoolss_notify_print_processor(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
940 data->notify_data.data.length=strlen(printer->info_2->printprocessor);
941 ascii_to_unistr(data->notify_data.data.string,
942 printer->info_2->printprocessor,
943 sizeof(data->notify_data.data.string)-1);
946 /*******************************************************************
947 * fill a notify_info_data with the print processor options
948 * jfm:xxxx send an empty string
949 ********************************************************************/
950 static void spoolss_notify_parameters(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
952 data->notify_data.data.length=strlen(printer->info_2->parameters);
953 ascii_to_unistr(data->notify_data.data.string,
954 printer->info_2->parameters,
955 sizeof(data->notify_data.data.string)-1);
958 /*******************************************************************
959 * fill a notify_info_data with the data type
960 * jfm:xxxx always send RAW as data type
961 ********************************************************************/
962 static void spoolss_notify_datatype(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
964 data->notify_data.data.length=strlen(printer->info_2->datatype);
965 ascii_to_unistr(data->notify_data.data.string,
966 printer->info_2->datatype,
967 sizeof(data->notify_data.data.string)-1);
970 /*******************************************************************
971 * fill a notify_info_data with the security descriptor
972 * jfm:xxxx send an null pointer to say no security desc
973 * have to implement security before !
974 ********************************************************************/
975 static void spoolss_notify_security_desc(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
977 data->notify_data.data.length=0;
978 data->notify_data.data.string[0]=0x00;
981 /*******************************************************************
982 * fill a notify_info_data with the attributes
983 * jfm:xxxx a samba printer is always shared
984 ********************************************************************/
985 static void spoolss_notify_attributes(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
987 data->notify_data.value[0] = PRINTER_ATTRIBUTE_SHARED \
988 | PRINTER_ATTRIBUTE_NETWORK \
989 | PRINTER_ATTRIBUTE_RAW_ONLY ;
992 /*******************************************************************
993 * fill a notify_info_data with the priority
994 ********************************************************************/
995 static void spoolss_notify_priority(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
997 data->notify_data.value[0] = printer->info_2->priority;
1000 /*******************************************************************
1001 * fill a notify_info_data with the default priority
1002 ********************************************************************/
1003 static void spoolss_notify_default_priority(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1005 data->notify_data.value[0] = printer->info_2->default_priority;
1008 /*******************************************************************
1009 * fill a notify_info_data with the start time
1010 ********************************************************************/
1011 static void spoolss_notify_start_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1013 data->notify_data.value[0] = printer->info_2->starttime;
1016 /*******************************************************************
1017 * fill a notify_info_data with the until time
1018 ********************************************************************/
1019 static void spoolss_notify_until_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1021 data->notify_data.value[0] = printer->info_2->untiltime;
1024 /*******************************************************************
1025 * fill a notify_info_data with the status
1026 ********************************************************************/
1027 static void spoolss_notify_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1030 print_queue_struct *q=NULL;
1031 print_status_struct status;
1033 memset(&status, 0, sizeof(status));
1034 count = print_queue_status(snum, &q, &status);
1035 data->notify_data.value[0]=(uint32) status.status;
1039 /*******************************************************************
1040 * fill a notify_info_data with the number of jobs queued
1041 ********************************************************************/
1042 static void spoolss_notify_cjobs(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1044 print_queue_struct *q=NULL;
1045 print_status_struct status;
1047 memset(&status, 0, sizeof(status));
1048 data->notify_data.value[0] = print_queue_status(snum, &q, &status);
1052 /*******************************************************************
1053 * fill a notify_info_data with the average ppm
1054 ********************************************************************/
1055 static void spoolss_notify_average_ppm(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1057 /* always respond 8 pages per minutes */
1058 /* a little hard ! */
1059 data->notify_data.value[0] = printer->info_2->averageppm;
1062 /*******************************************************************
1063 * fill a notify_info_data with
1064 ********************************************************************/
1065 static void spoolss_notify_username(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1067 data->notify_data.data.length=strlen(queue->user);
1068 ascii_to_unistr(data->notify_data.data.string, queue->user, sizeof(data->notify_data.data.string)-1);
1071 /*******************************************************************
1072 * fill a notify_info_data with
1073 ********************************************************************/
1074 static void spoolss_notify_job_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1076 data->notify_data.value[0]=queue->status;
1079 /*******************************************************************
1080 * fill a notify_info_data with
1081 ********************************************************************/
1082 static void spoolss_notify_job_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1084 data->notify_data.data.length=strlen(queue->file);
1085 ascii_to_unistr(data->notify_data.data.string, queue->file, sizeof(data->notify_data.data.string)-1);
1088 /*******************************************************************
1089 * fill a notify_info_data with
1090 ********************************************************************/
1091 static void spoolss_notify_job_status_string(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1093 data->notify_data.data.length=strlen("En attente");
1094 ascii_to_unistr(data->notify_data.data.string, "En attente", sizeof(data->notify_data.data.string)-1);
1097 /*******************************************************************
1098 * fill a notify_info_data with
1099 ********************************************************************/
1100 static void spoolss_notify_job_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1102 data->notify_data.value[0]=0x0;
1105 /*******************************************************************
1106 * fill a notify_info_data with
1107 ********************************************************************/
1108 static void spoolss_notify_job_size(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1110 data->notify_data.value[0]=queue->size;
1113 /*******************************************************************
1114 * fill a notify_info_data with
1115 ********************************************************************/
1116 static void spoolss_notify_job_position(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1118 data->notify_data.value[0]=queue->job;
1123 struct s_notify_info_data_table notify_info_data_table[] =
1125 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SERVER_NAME, "PRINTER_NOTIFY_SERVER_NAME", POINTER, spoolss_notify_server_name },
1126 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINTER_NAME, "PRINTER_NOTIFY_PRINTER_NAME", POINTER, spoolss_notify_printer_name },
1127 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SHARE_NAME, "PRINTER_NOTIFY_SHARE_NAME", POINTER, spoolss_notify_share_name },
1128 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PORT_NAME, "PRINTER_NOTIFY_PORT_NAME", POINTER, spoolss_notify_port_name },
1129 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DRIVER_NAME, "PRINTER_NOTIFY_DRIVER_NAME", POINTER, spoolss_notify_driver_name },
1130 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_COMMENT, "PRINTER_NOTIFY_COMMENT", POINTER, spoolss_notify_comment },
1131 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_LOCATION, "PRINTER_NOTIFY_LOCATION", POINTER, spoolss_notify_location },
1132 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DEVMODE, "PRINTER_NOTIFY_DEVMODE", POINTER, spoolss_notify_devmode },
1133 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SEPFILE, "PRINTER_NOTIFY_SEPFILE", POINTER, spoolss_notify_sepfile },
1134 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINT_PROCESSOR, "PRINTER_NOTIFY_PRINT_PROCESSOR", POINTER, spoolss_notify_print_processor },
1135 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PARAMETERS, "PRINTER_NOTIFY_PARAMETERS", POINTER, spoolss_notify_parameters },
1136 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DATATYPE, "PRINTER_NOTIFY_DATATYPE", POINTER, spoolss_notify_datatype },
1137 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_SECURITY_DESCRIPTOR", POINTER, spoolss_notify_security_desc },
1138 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_ATTRIBUTES, "PRINTER_NOTIFY_ATTRIBUTES", ONE_VALUE, spoolss_notify_attributes },
1139 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRIORITY, "PRINTER_NOTIFY_PRIORITY", ONE_VALUE, spoolss_notify_priority },
1140 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DEFAULT_PRIORITY, "PRINTER_NOTIFY_DEFAULT_PRIORITY", ONE_VALUE, spoolss_notify_default_priority },
1141 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_START_TIME, "PRINTER_NOTIFY_START_TIME", ONE_VALUE, spoolss_notify_start_time },
1142 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_UNTIL_TIME, "PRINTER_NOTIFY_UNTIL_TIME", ONE_VALUE, spoolss_notify_until_time },
1143 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_STATUS, "PRINTER_NOTIFY_STATUS", ONE_VALUE, spoolss_notify_status },
1144 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_STATUS_STRING, "PRINTER_NOTIFY_STATUS_STRING", POINTER, NULL },
1145 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_CJOBS, "PRINTER_NOTIFY_CJOBS", ONE_VALUE, spoolss_notify_cjobs },
1146 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_AVERAGE_PPM, "PRINTER_NOTIFY_AVERAGE_PPM", ONE_VALUE, spoolss_notify_average_ppm },
1147 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_PAGES, "PRINTER_NOTIFY_TOTAL_PAGES", POINTER, NULL },
1148 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PAGES_PRINTED, "PRINTER_NOTIFY_PAGES_PRINTED", POINTER, NULL },
1149 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_BYTES, "PRINTER_NOTIFY_TOTAL_BYTES", POINTER, NULL },
1150 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_BYTES_PRINTED, "PRINTER_NOTIFY_BYTES_PRINTED", POINTER, NULL },
1151 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINTER_NAME, "JOB_NOTIFY_PRINTER_NAME", POINTER, spoolss_notify_printer_name },
1152 { JOB_NOTIFY_TYPE, JOB_NOTIFY_MACHINE_NAME, "JOB_NOTIFY_MACHINE_NAME", POINTER, spoolss_notify_server_name },
1153 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PORT_NAME, "JOB_NOTIFY_PORT_NAME", POINTER, spoolss_notify_port_name },
1154 { JOB_NOTIFY_TYPE, JOB_NOTIFY_USER_NAME, "JOB_NOTIFY_USER_NAME", POINTER, spoolss_notify_username },
1155 { JOB_NOTIFY_TYPE, JOB_NOTIFY_NOTIFY_NAME, "JOB_NOTIFY_NOTIFY_NAME", POINTER, spoolss_notify_username },
1156 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DATATYPE, "JOB_NOTIFY_DATATYPE", POINTER, spoolss_notify_datatype },
1157 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINT_PROCESSOR, "JOB_NOTIFY_PRINT_PROCESSOR", POINTER, spoolss_notify_print_processor },
1158 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PARAMETERS, "JOB_NOTIFY_PARAMETERS", POINTER, spoolss_notify_parameters },
1159 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DRIVER_NAME, "JOB_NOTIFY_DRIVER_NAME", POINTER, spoolss_notify_driver_name },
1160 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DEVMODE, "JOB_NOTIFY_DEVMODE", POINTER, spoolss_notify_devmode },
1161 { JOB_NOTIFY_TYPE, JOB_NOTIFY_STATUS, "JOB_NOTIFY_STATUS", ONE_VALUE, spoolss_notify_job_status },
1162 { JOB_NOTIFY_TYPE, JOB_NOTIFY_STATUS_STRING, "JOB_NOTIFY_STATUS_STRING", POINTER, spoolss_notify_job_status_string },
1163 { JOB_NOTIFY_TYPE, JOB_NOTIFY_SECURITY_DESCRIPTOR, "JOB_NOTIFY_SECURITY_DESCRIPTOR", POINTER, NULL },
1164 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DOCUMENT, "JOB_NOTIFY_DOCUMENT", POINTER, spoolss_notify_job_name },
1165 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRIORITY, "JOB_NOTIFY_PRIORITY", ONE_VALUE, spoolss_notify_priority },
1166 { JOB_NOTIFY_TYPE, JOB_NOTIFY_POSITION, "JOB_NOTIFY_POSITION", ONE_VALUE, spoolss_notify_job_position },
1167 { JOB_NOTIFY_TYPE, JOB_NOTIFY_SUBMITTED, "JOB_NOTIFY_SUBMITTED", POINTER, NULL },
1168 { JOB_NOTIFY_TYPE, JOB_NOTIFY_START_TIME, "JOB_NOTIFY_START_TIME", ONE_VALUE, spoolss_notify_start_time },
1169 { JOB_NOTIFY_TYPE, JOB_NOTIFY_UNTIL_TIME, "JOB_NOTIFY_UNTIL_TIME", ONE_VALUE, spoolss_notify_until_time },
1170 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TIME, "JOB_NOTIFY_TIME", ONE_VALUE, spoolss_notify_job_time },
1171 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_PAGES, "JOB_NOTIFY_TOTAL_PAGES", ONE_VALUE, NULL },
1172 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PAGES_PRINTED, "JOB_NOTIFY_PAGES_PRINTED", ONE_VALUE, NULL },
1173 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_BYTES, "JOB_NOTIFY_TOTAL_BYTES", ONE_VALUE, spoolss_notify_job_size },
1174 { JOB_NOTIFY_TYPE, JOB_NOTIFY_BYTES_PRINTED, "JOB_NOTIFY_BYTES_PRINTED", ONE_VALUE, NULL },
1175 { END, END, "", END, NULL }
1178 /*******************************************************************
1179 return the size of info_data structure
1180 ********************************************************************/
1181 static uint32 size_of_notify_info_data(uint16 type, uint16 field)
1185 while (notify_info_data_table[i].type != END)
1187 if ( (notify_info_data_table[i].type == type ) &&
1188 (notify_info_data_table[i].field == field ) )
1190 return (notify_info_data_table[i].size);
1198 /*******************************************************************
1199 return the type of notify_info_data
1200 ********************************************************************/
1201 static BOOL type_of_notify_info_data(uint16 type, uint16 field)
1205 while (notify_info_data_table[i].type != END)
1207 if ( (notify_info_data_table[i].type == type ) &&
1208 (notify_info_data_table[i].field == field ) )
1210 if (notify_info_data_table[i].size == POINTER)
1225 /****************************************************************************
1226 ****************************************************************************/
1227 static int search_notify(uint16 type, uint16 field, int *value)
1232 for (j=0, found=False; found==False && notify_info_data_table[j].type != END ; j++)
1234 if ( (notify_info_data_table[j].type == type ) &&
1235 (notify_info_data_table[j].field == field ) )
1240 if ( found && (notify_info_data_table[j].fn != NULL) )
1246 /****************************************************************************
1247 ****************************************************************************/
1248 static void construct_info_data(SPOOL_NOTIFY_INFO_DATA *info_data, uint16 type, uint16 field, int id)
1250 info_data->type = type;
1251 info_data->field = field;
1252 info_data->reserved = 0;
1254 info_data->size = size_of_notify_info_data(type, field);
1255 info_data->enc_type = type_of_notify_info_data(type, field);
1259 /*******************************************************************
1261 * fill a notify_info struct with info asked
1263 ********************************************************************/
1264 static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPOOL_NOTIFY_OPTION_TYPE *option_type, uint32 id)
1270 SPOOL_NOTIFY_INFO_DATA *current_data;
1271 NT_PRINTER_INFO_LEVEL printer;
1272 print_queue_struct *queue=NULL;
1274 DEBUG(4,("construct_notify_printer_info\n"));
1276 type=option_type->type;
1278 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
1279 (option_type->type==PRINTER_NOTIFY_TYPE?"PRINTER_NOTIFY_TYPE":"JOB_NOTIFY_TYPE"),
1280 option_type->count, lp_servicename(snum)));
1282 if (get_a_printer(&printer, 2, lp_servicename(snum))!=0)
1287 for(field_num=0; field_num<option_type->count; field_num++)
1289 field = option_type->fields[field_num];
1290 DEBUGADD(4,("notify [%d]: type [%x], field [%x]\n", field_num, type, field));
1292 if (!search_notify(type, field, &j) )
1295 if((info->data=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) {
1296 free_a_printer(printer, 2);
1299 current_data=&(info->data[info->count]);
1301 construct_info_data(current_data, type, field, id);
1302 notify_info_data_table[j].fn(snum, current_data, queue, &printer);
1307 free_a_printer(printer, 2);
1311 /*******************************************************************
1313 * fill a notify_info struct with info asked
1315 ********************************************************************/
1316 static BOOL construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_INFO *info, int snum, SPOOL_NOTIFY_OPTION_TYPE *option_type, uint32 id)
1322 SPOOL_NOTIFY_INFO_DATA *current_data;
1323 NT_PRINTER_INFO_LEVEL printer;
1325 DEBUG(4,("construct_notify_jobs_info\n"));
1327 type = option_type->type;
1329 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
1330 (option_type->type==PRINTER_NOTIFY_TYPE?"PRINTER_NOTIFY_TYPE":"JOB_NOTIFY_TYPE"),
1331 option_type->count));
1333 if (get_a_printer(&printer, 2, lp_servicename(snum))!=0)
1338 for(field_num=0; field_num<option_type->count; field_num++)
1340 field = option_type->fields[field_num];
1342 if (!search_notify(type, field, &j) )
1345 if((info->data=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) {
1346 free_a_printer(printer, 2);
1350 current_data=&(info->data[info->count]);
1352 construct_info_data(current_data, type, field, id);
1353 notify_info_data_table[j].fn(snum, current_data, queue, &printer);
1357 free_a_printer(printer, 2);
1363 * JFM: The enumeration is not that simple, it's even non obvious.
1365 * let's take an example: I want to monitor the PRINTER SERVER for
1366 * the printer's name and the number of jobs currently queued.
1367 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
1368 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
1370 * I have 3 printers on the back of my server.
1372 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
1375 * 1 printer 1 name 1
1376 * 2 printer 1 cjob 1
1377 * 3 printer 2 name 2
1378 * 4 printer 2 cjob 2
1379 * 5 printer 3 name 3
1380 * 6 printer 3 name 3
1382 * that's the print server case, the printer case is even worse.
1387 /*******************************************************************
1389 * enumerate all printers on the printserver
1390 * fill a notify_info struct with info asked
1392 ********************************************************************/
1393 static uint32 printserver_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info)
1396 Printer_entry *Printer=find_printer_index_by_hnd(hnd);
1397 int n_services=lp_numservices();
1400 SPOOL_NOTIFY_OPTION *option;
1401 SPOOL_NOTIFY_OPTION_TYPE *option_type;
1403 DEBUG(4,("printserver_notify_info\n"));
1405 option=Printer->notify.option;
1411 for (i=0; i<option->count; i++)
1413 option_type=&(option->ctr.type[i]);
1415 if (option_type->type!=PRINTER_NOTIFY_TYPE)
1418 for (snum=0; snum<n_services; snum++)
1419 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
1420 if (construct_notify_printer_info(info, snum, option_type, id))
1425 * Debugging information, don't delete.
1428 DEBUG(1,("dumping the NOTIFY_INFO\n"));
1429 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
1430 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
1432 for (i=0; i<info->count; i++)
1434 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
1435 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
1436 info->data[i].id, info->data[i].size, info->data[i].enc_type));
1440 return NT_STATUS_NO_PROBLEMO;
1443 /*******************************************************************
1445 * fill a notify_info struct with info asked
1447 ********************************************************************/
1448 static uint32 printer_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info)
1451 Printer_entry *Printer=find_printer_index_by_hnd(hnd);
1454 SPOOL_NOTIFY_OPTION *option;
1455 SPOOL_NOTIFY_OPTION_TYPE *option_type;
1457 print_queue_struct *queue=NULL;
1458 print_status_struct status;
1460 DEBUG(4,("printer_notify_info\n"));
1462 option=Printer->notify.option;
1468 get_printer_snum(hnd, &snum);
1470 for (i=0; i<option->count; i++)
1472 option_type=&(option->ctr.type[i]);
1474 switch ( option_type->type ) {
1475 case PRINTER_NOTIFY_TYPE:
1476 if(construct_notify_printer_info(info, snum, option_type, id))
1480 case JOB_NOTIFY_TYPE:
1481 memset(&status, 0, sizeof(status));
1482 count = print_queue_status(snum, &queue, &status);
1483 for (j=0; j<count; j++)
1484 construct_notify_jobs_info(&(queue[j]), info, snum, option_type, queue[j].job);
1491 * Debugging information, don't delete.
1494 DEBUG(1,("dumping the NOTIFY_INFO\n"));
1495 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
1496 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
1498 for (i=0; i<info->count; i++)
1500 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
1501 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
1502 info->data[i].id, info->data[i].size, info->data[i].enc_type));
1505 return NT_STATUS_NO_PROBLEMO;
1508 /********************************************************************
1510 ********************************************************************/
1511 uint32 _spoolss_rfnpcnex( const POLICY_HND *handle, uint32 change,
1512 SPOOL_NOTIFY_OPTION *option, SPOOL_NOTIFY_INFO *info)
1514 Printer_entry *Printer=find_printer_index_by_hnd(handle);
1516 if (!OPEN_HANDLE(Printer))
1517 return ERROR_INVALID_HANDLE;
1519 DEBUG(4,("Printer type %x\n",Printer->printer_type));
1521 /* jfm: the change value isn't used right now.
1522 * we will honour it when
1523 * a) we'll be able to send notification to the client
1524 * b) we'll have a way to communicate between the spoolss process.
1526 * same thing for option->flags
1527 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
1528 * I don't have a global notification system, I'm sending back all the
1529 * informations even when _NOTHING_ has changed.
1532 /* just discard the SPOOL_NOTIFY_OPTION */
1534 safe_free(option->ctr.type);
1538 switch (Printer->printer_type) {
1539 case PRINTER_HANDLE_IS_PRINTSERVER:
1540 return printserver_notify_info(handle, info);
1542 case PRINTER_HANDLE_IS_PRINTER:
1543 return printer_notify_info(handle, info);
1547 return ERROR_INVALID_HANDLE;
1550 /********************************************************************
1551 * construct_printer_info_0
1552 * fill a printer_info_1 struct
1553 ********************************************************************/
1554 static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, pstring servername)
1558 NT_PRINTER_INFO_LEVEL ntprinter;
1559 counter_printer_0 *session_counter;
1560 uint32 global_counter;
1563 print_queue_struct *queue=NULL;
1564 print_status_struct status;
1566 memset(&status, 0, sizeof(status));
1568 if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) != 0)
1571 count = print_queue_status(snum, &queue, &status);
1573 /* check if we already have a counter for this printer */
1574 session_counter = (counter_printer_0 *)ubi_dlFirst(&counter_list);
1576 for(; session_counter; session_counter = (counter_printer_0 *)ubi_dlNext(session_counter)) {
1577 if (session_counter->snum == snum)
1581 /* it's the first time, add it to the list */
1582 if (session_counter==NULL) {
1583 if((session_counter=(counter_printer_0 *)malloc(sizeof(counter_printer_0))) == NULL)
1585 ZERO_STRUCTP(session_counter);
1586 session_counter->snum=snum;
1587 session_counter->counter=0;
1588 ubi_dlAddHead( &counter_list, (ubi_dlNode *)session_counter);
1592 session_counter->counter++;
1595 * the global_counter should be stored in a TDB as it's common to all the clients
1596 * and should be zeroed on samba startup
1598 global_counter=session_counter->counter;
1600 /* the description and the name are of the form \\server\share */
1601 slprintf(chaine,sizeof(chaine)-1,"\\\\%s\\%s",servername, ntprinter.info_2->printername);
1603 init_unistr(&(printer->printername), chaine);
1605 slprintf(chaine,sizeof(chaine)-1,"\\\\%s", servername);
1606 init_unistr(&(printer->servername), chaine);
1608 printer->cjobs = count;
1609 printer->total_jobs = 0;
1610 printer->total_bytes = 0;
1612 t=gmtime(&ntprinter.info_2->setuptime);
1614 printer->year = t->tm_year+1900;
1615 printer->month = t->tm_mon+1;
1616 printer->dayofweek = t->tm_wday;
1617 printer->day = t->tm_mday;
1618 printer->hour = t->tm_hour;
1619 printer->minute = t->tm_min;
1620 printer->second = t->tm_sec;
1621 printer->milliseconds = 0;
1623 printer->global_counter = global_counter;
1624 printer->total_pages = 0;
1625 printer->major_version = 0x0004; /* NT 4 */
1626 printer->build_version = 0x0565; /* build 1381 */
1627 printer->unknown7 = 0x1;
1628 printer->unknown8 = 0x0;
1629 printer->unknown9 = 0x0;
1630 printer->session_counter = session_counter->counter;
1631 printer->unknown11 = 0x0;
1632 printer->printer_errors = 0x0; /* number of print failure */
1633 printer->unknown13 = 0x0;
1634 printer->unknown14 = 0x1;
1635 printer->unknown15 = 0x024a; /* 586 Pentium ? */
1636 printer->unknown16 = 0x0;
1637 printer->change_id = ntprinter.info_2->changeid; /* ChangeID in milliseconds*/
1638 printer->unknown18 = 0x0;
1639 printer->status = status.status;
1640 printer->unknown20 = 0x0;
1641 printer->c_setprinter = ntprinter.info_2->c_setprinter; /* how many times setprinter has been called */
1642 printer->unknown22 = 0x0;
1643 printer->unknown23 = 0x6; /* 6 ???*/
1644 printer->unknown24 = 0; /* unknown 24 to 26 are always 0 */
1645 printer->unknown25 = 0;
1646 printer->unknown26 = 0;
1647 printer->unknown27 = 0;
1648 printer->unknown28 = 0;
1649 printer->unknown29 = 0;
1653 free_a_printer(ntprinter, 2);
1657 /********************************************************************
1658 * construct_printer_info_1
1659 * fill a printer_info_1 struct
1660 ********************************************************************/
1661 static BOOL construct_printer_info_1(fstring server, uint32 flags, PRINTER_INFO_1 *printer, int snum)
1665 NT_PRINTER_INFO_LEVEL ntprinter;
1667 if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) != 0)
1670 printer->flags=flags;
1672 snprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",server, ntprinter.info_2->printername,
1673 ntprinter.info_2->drivername, lp_comment(snum));
1675 snprintf(chaine2,sizeof(chaine)-1,"%s%s", server, ntprinter.info_2->printername);
1677 init_unistr(&printer->description, chaine);
1678 init_unistr(&printer->name, chaine2);
1679 init_unistr(&printer->comment, lp_comment(snum));
1681 free_a_printer(ntprinter, 2);
1686 /****************************************************************************
1687 ****************************************************************************/
1688 static BOOL construct_dev_mode(DEVICEMODE *devmode, int snum, char *servername)
1692 NT_PRINTER_INFO_LEVEL printer;
1693 NT_DEVICEMODE *ntdevmode;
1695 DEBUG(7,("construct_dev_mode\n"));
1697 memset(&(devmode->devicename), 0, 2*sizeof(adevice));
1698 memset(&(devmode->formname), 0, 2*sizeof(aform));
1700 DEBUGADD(8,("getting printer characteristics\n"));
1702 get_a_printer(&printer, 2, lp_servicename(snum));
1703 ntdevmode=(printer.info_2)->devmode;
1705 DEBUGADD(8,("loading DEVICEMODE\n"));
1706 snprintf(adevice, sizeof(adevice), "\\\\%s\\%s", global_myname,
1707 printer.info_2->printername);
1708 init_unistr(&(devmode->devicename), adevice);
1710 snprintf(aform, sizeof(aform), ntdevmode->formname);
1711 init_unistr(&(devmode->formname), aform);
1713 devmode->specversion = ntdevmode->specversion;
1714 devmode->driverversion = ntdevmode->driverversion;
1715 devmode->size = ntdevmode->size;
1716 devmode->driverextra = ntdevmode->driverextra;
1717 devmode->fields = ntdevmode->fields;
1719 devmode->orientation = ntdevmode->orientation;
1720 devmode->papersize = ntdevmode->papersize;
1721 devmode->paperlength = ntdevmode->paperlength;
1722 devmode->paperwidth = ntdevmode->paperwidth;
1723 devmode->scale = ntdevmode->scale;
1724 devmode->copies = ntdevmode->copies;
1725 devmode->defaultsource = ntdevmode->defaultsource;
1726 devmode->printquality = ntdevmode->printquality;
1727 devmode->color = ntdevmode->color;
1728 devmode->duplex = ntdevmode->duplex;
1729 devmode->yresolution = ntdevmode->yresolution;
1730 devmode->ttoption = ntdevmode->ttoption;
1731 devmode->collate = ntdevmode->collate;
1732 devmode->icmmethod = ntdevmode->icmmethod;
1733 devmode->icmintent = ntdevmode->icmintent;
1734 devmode->mediatype = ntdevmode->mediatype;
1735 devmode->dithertype = ntdevmode->dithertype;
1737 if (ntdevmode->private != NULL)
1739 if((devmode->private=(uint8 *)malloc(devmode->driverextra*sizeof(uint8))) == NULL) {
1740 free_a_printer(printer, 2);
1743 memcpy(devmode->private, ntdevmode->private, devmode->driverextra);
1746 free_a_printer(printer, 2);
1751 /********************************************************************
1752 * construct_printer_info_2
1753 * fill a printer_info_2 struct
1754 ********************************************************************/
1755 static BOOL construct_printer_info_2(pstring servername, PRINTER_INFO_2 *printer, int snum)
1761 DEVICEMODE *devmode;
1762 NT_PRINTER_INFO_LEVEL ntprinter;
1764 print_queue_struct *queue=NULL;
1765 print_status_struct status;
1766 memset(&status, 0, sizeof(status));
1768 if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0 )
1771 memset(&status, 0, sizeof(status));
1772 count = print_queue_status(snum, &queue, &status);
1774 snprintf(chaine, sizeof(chaine)-1, "%s", servername);
1776 if (strlen(servername)!=0)
1781 snprintf(chaine2, sizeof(chaine)-1, "%s%s%s", servername, sl, ntprinter.info_2->printername);
1783 init_unistr(&printer->servername, chaine); /* servername*/
1784 init_unistr(&printer->printername, chaine2); /* printername*/
1785 init_unistr(&printer->sharename, lp_servicename(snum)); /* sharename */
1786 init_unistr(&printer->portname, lp_servicename(snum)); /* port */
1787 init_unistr(&printer->drivername, ntprinter.info_2->drivername); /* drivername */
1788 init_unistr(&printer->comment, lp_comment(snum)); /* comment */
1789 init_unistr(&printer->location, ntprinter.info_2->location); /* location */
1790 init_unistr(&printer->sepfile, ntprinter.info_2->sepfile); /* separator file */
1791 init_unistr(&printer->printprocessor, ntprinter.info_2->printprocessor);/* print processor */
1792 init_unistr(&printer->datatype, ntprinter.info_2->datatype); /* datatype */
1793 init_unistr(&printer->parameters, ntprinter.info_2->parameters); /* parameters (of print processor) */
1795 printer->attributes = PRINTER_ATTRIBUTE_SHARED \
1796 | PRINTER_ATTRIBUTE_LOCAL \
1797 | PRINTER_ATTRIBUTE_RAW_ONLY ; /* attributes */
1799 printer->priority = ntprinter.info_2->priority; /* priority */
1800 printer->defaultpriority = ntprinter.info_2->default_priority; /* default priority */
1801 printer->starttime = ntprinter.info_2->starttime; /* starttime */
1802 printer->untiltime = ntprinter.info_2->untiltime; /* untiltime */
1803 printer->status = status.status; /* status */
1804 printer->cjobs = count; /* jobs */
1805 printer->averageppm = ntprinter.info_2->averageppm; /* average pages per minute */
1807 if((devmode=(DEVICEMODE *)malloc(sizeof(DEVICEMODE))) == NULL)
1810 ZERO_STRUCTP(devmode);
1812 if(!construct_dev_mode(devmode, snum, servername))
1815 printer->devmode=devmode;
1818 free_a_printer(ntprinter, 2);
1824 free_a_printer(ntprinter, 2);
1828 /********************************************************************
1829 Spoolss_enumprinters.
1830 ********************************************************************/
1831 static BOOL enum_all_printers_info_1(fstring server, uint32 flags, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
1835 int n_services=lp_numservices();
1836 PRINTER_INFO_1 *printers=NULL;
1837 PRINTER_INFO_1 current_prt;
1839 DEBUG(4,("enum_all_printers_info_1\n"));
1841 for (snum=0; snum<n_services; snum++) {
1842 if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
1843 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum));
1845 if (construct_printer_info_1(server, flags, ¤t_prt, snum)) {
1846 if((printers=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_1))) == NULL) {
1848 return ERROR_NOT_ENOUGH_MEMORY;
1850 DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_1\n", *returned));
1851 memcpy(&(printers[*returned]), ¤t_prt, sizeof(PRINTER_INFO_1));
1857 /* check the required size. */
1858 for (i=0; i<*returned; i++)
1859 (*needed) += spoolss_size_printer_info_1(&(printers[i]));
1861 if (!alloc_buffer_size(buffer, *needed))
1862 return ERROR_INSUFFICIENT_BUFFER;
1864 /* fill the buffer with the structures */
1865 for (i=0; i<*returned; i++)
1866 new_smb_io_printer_info_1("", buffer, &(printers[i]), 0);
1869 safe_free(printers);
1871 if (*needed > offered) {
1873 return ERROR_INSUFFICIENT_BUFFER;
1876 return NT_STATUS_NO_PROBLEMO;
1879 /********************************************************************
1880 enum_all_printers_info_1_local.
1881 *********************************************************************/
1882 static BOOL enum_all_printers_info_1_local(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
1885 DEBUG(4,("enum_all_printers_info_1_local\n"));
1887 fstrcpy(temp, "\\\\");
1888 fstrcat(temp, global_myname);
1890 if (!strcmp(name, temp)) {
1891 fstrcat(temp, "\\");
1892 return enum_all_printers_info_1(temp, PRINTER_ENUM_ICON8, buffer, offered, needed, returned);
1895 return enum_all_printers_info_1("", PRINTER_ENUM_ICON8, buffer, offered, needed, returned);
1898 /********************************************************************
1899 enum_all_printers_info_1_name.
1900 *********************************************************************/
1901 static BOOL enum_all_printers_info_1_name(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
1904 DEBUG(4,("enum_all_printers_info_1_name\n"));
1906 fstrcpy(temp, "\\\\");
1907 fstrcat(temp, global_myname);
1909 if (!strcmp(name, temp)) {
1910 fstrcat(temp, "\\");
1911 return enum_all_printers_info_1(temp, PRINTER_ENUM_ICON8, buffer, offered, needed, returned);
1914 return ERROR_INVALID_NAME;
1917 /********************************************************************
1918 enum_all_printers_info_1_remote.
1919 *********************************************************************/
1920 static BOOL enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
1922 PRINTER_INFO_1 *printer;
1923 fstring printername;
1926 DEBUG(4,("enum_all_printers_info_1_remote\n"));
1928 /* JFM: currently it's more a place holder than anything else.
1929 * In the spooler world there is a notion of server registration.
1930 * the print servers are registring (sp ?) on the PDC (in the same domain)
1932 * We should have a TDB here. The registration is done thru an undocumented RPC call.
1935 if((printer=(PRINTER_INFO_1 *)malloc(sizeof(PRINTER_INFO_1))) == NULL)
1936 return ERROR_NOT_ENOUGH_MEMORY;
1940 snprintf(printername, sizeof(printername)-1,"Windows NT Remote Printers!!\\\\%s", global_myname);
1941 snprintf(desc, sizeof(desc)-1,"%s", global_myname);
1942 snprintf(comment, sizeof(comment)-1, "Logged on Domain");
1944 init_unistr(&printer->description, desc);
1945 init_unistr(&printer->name, printername);
1946 init_unistr(&printer->comment, comment);
1947 printer->flags=PRINTER_ENUM_ICON3|PRINTER_ENUM_CONTAINER;
1949 /* check the required size. */
1950 *needed += spoolss_size_printer_info_1(printer);
1952 if (!alloc_buffer_size(buffer, *needed)) {
1954 return ERROR_INSUFFICIENT_BUFFER;
1957 /* fill the buffer with the structures */
1958 new_smb_io_printer_info_1("", buffer, printer, 0);
1963 if (*needed > offered) {
1965 return ERROR_INSUFFICIENT_BUFFER;
1968 return NT_STATUS_NO_PROBLEMO;
1971 /********************************************************************
1972 enum_all_printers_info_1_network.
1973 *********************************************************************/
1974 static BOOL enum_all_printers_info_1_network(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
1977 DEBUG(4,("enum_all_printers_info_1_network\n"));
1979 fstrcpy(temp, "\\\\");
1980 fstrcat(temp, global_myname);
1981 fstrcat(temp, "\\");
1982 return enum_all_printers_info_1(temp, PRINTER_ENUM_UNKNOWN_8, buffer, offered, needed, returned);
1985 /********************************************************************
1986 * api_spoolss_enumprinters
1988 * called from api_spoolss_enumprinters (see this to understand)
1989 ********************************************************************/
1990 static BOOL enum_all_printers_info_2(fstring servername, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
1994 int n_services=lp_numservices();
1995 PRINTER_INFO_2 *printers=NULL;
1996 PRINTER_INFO_2 current_prt;
1998 for (snum=0; snum<n_services; snum++) {
1999 if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
2000 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum));
2002 if (construct_printer_info_2(servername, ¤t_prt, snum)) {
2003 if((printers=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_2))) == NULL)
2004 return ERROR_NOT_ENOUGH_MEMORY;
2005 DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_2\n", *returned));
2006 memcpy(&(printers[*returned]), ¤t_prt, sizeof(PRINTER_INFO_2));
2012 /* check the required size. */
2013 for (i=0; i<*returned; i++)
2014 (*needed) += spoolss_size_printer_info_2(&(printers[i]));
2016 if (!alloc_buffer_size(buffer, *needed)) {
2017 for (i=0; i<*returned; i++) {
2018 safe_free(printers[i].devmode->private);
2019 safe_free(printers[i].devmode);
2021 safe_free(printers);
2022 return ERROR_INSUFFICIENT_BUFFER;
2025 /* fill the buffer with the structures */
2026 for (i=0; i<*returned; i++)
2027 new_smb_io_printer_info_2("", buffer, &(printers[i]), 0);
2030 for (i=0; i<*returned; i++) {
2031 safe_free(printers[i].devmode->private);
2032 safe_free(printers[i].devmode);
2034 safe_free(printers);
2036 if (*needed > offered) {
2038 return ERROR_INSUFFICIENT_BUFFER;
2041 return NT_STATUS_NO_PROBLEMO;
2044 /********************************************************************
2045 * handle enumeration of printers at level 1
2046 ********************************************************************/
2047 static uint32 enumprinters_level1( uint32 flags, fstring name,
2048 NEW_BUFFER *buffer, uint32 offered,
2049 uint32 *needed, uint32 *returned)
2051 /* Not all the flags are equals */
2053 if (flags & PRINTER_ENUM_LOCAL)
2054 return enum_all_printers_info_1_local(name, buffer, offered, needed, returned);
2056 if (flags & PRINTER_ENUM_NAME)
2057 return enum_all_printers_info_1_name(name, buffer, offered, needed, returned);
2059 if (flags & PRINTER_ENUM_REMOTE)
2060 return enum_all_printers_info_1_remote(name, buffer, offered, needed, returned);
2062 if (flags & PRINTER_ENUM_NETWORK)
2063 return enum_all_printers_info_1_network(name, buffer, offered, needed, returned);
2065 return NT_STATUS_NO_PROBLEMO; /* NT4sp5 does that */
2068 /********************************************************************
2069 * handle enumeration of printers at level 2
2070 ********************************************************************/
2071 static uint32 enumprinters_level2( uint32 flags, fstring servername,
2072 NEW_BUFFER *buffer, uint32 offered,
2073 uint32 *needed, uint32 *returned)
2077 fstrcpy(temp, "\\\\");
2078 fstrcat(temp, global_myname);
2080 if (flags & PRINTER_ENUM_LOCAL) {
2081 if (!strcmp(servername, temp))
2082 return enum_all_printers_info_2(temp, buffer, offered, needed, returned);
2084 return enum_all_printers_info_2("", buffer, offered, needed, returned);
2087 if (flags & PRINTER_ENUM_NAME) {
2088 if (!strcmp(servername, temp))
2089 return enum_all_printers_info_2(temp, buffer, offered, needed, returned);
2091 return ERROR_INVALID_NAME;
2094 if (flags & PRINTER_ENUM_REMOTE)
2095 return ERROR_INVALID_LEVEL;
2097 return NT_STATUS_NO_PROBLEMO;
2100 /********************************************************************
2101 * handle enumeration of printers at level 5
2102 ********************************************************************/
2103 static uint32 enumprinters_level5( uint32 flags, fstring servername,
2104 NEW_BUFFER *buffer, uint32 offered,
2105 uint32 *needed, uint32 *returned)
2107 /* return enum_all_printers_info_5(buffer, offered, needed, returned);*/
2108 return NT_STATUS_NO_PROBLEMO;
2111 /********************************************************************
2112 * api_spoolss_enumprinters
2114 * called from api_spoolss_enumprinters (see this to understand)
2115 ********************************************************************/
2116 uint32 _spoolss_enumprinters( uint32 flags, const UNISTR2 *servername, uint32 level,
2117 NEW_BUFFER *buffer, uint32 offered,
2118 uint32 *needed, uint32 *returned)
2122 DEBUG(4,("_spoolss_enumprinters\n"));
2129 * flags==PRINTER_ENUM_NAME
2130 * if name=="" then enumerates all printers
2131 * if name!="" then enumerate the printer
2132 * flags==PRINTER_ENUM_REMOTE
2133 * name is NULL, enumerate printers
2134 * Level 2: name!="" enumerates printers, name can't be NULL
2135 * Level 3: doesn't exist
2136 * Level 4: does a local registry lookup
2137 * Level 5: same as Level 2
2140 unistr2_to_ascii(name, servername, sizeof(name)-1);
2145 return enumprinters_level1(flags, name, buffer, offered, needed, returned);
2148 return enumprinters_level2(flags, name, buffer, offered, needed, returned);
2151 return enumprinters_level5(flags, name, buffer, offered, needed, returned);
2156 return ERROR_INVALID_LEVEL;
2161 /****************************************************************************
2162 ****************************************************************************/
2163 static uint32 getprinter_level_0(pstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2165 PRINTER_INFO_0 *printer=NULL;
2167 if((printer=(PRINTER_INFO_0*)malloc(sizeof(PRINTER_INFO_0))) == NULL)
2168 return ERROR_NOT_ENOUGH_MEMORY;
2170 construct_printer_info_0(printer, snum, servername);
2172 /* check the required size. */
2173 *needed += spoolss_size_printer_info_0(printer);
2175 if (!alloc_buffer_size(buffer, *needed)) {
2177 return ERROR_INSUFFICIENT_BUFFER;
2180 /* fill the buffer with the structures */
2181 new_smb_io_printer_info_0("", buffer, printer, 0);
2186 if (*needed > offered) {
2187 return ERROR_INSUFFICIENT_BUFFER;
2190 return NT_STATUS_NO_PROBLEMO;
2193 /****************************************************************************
2194 ****************************************************************************/
2195 static uint32 getprinter_level_1(pstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2197 PRINTER_INFO_1 *printer=NULL;
2199 if((printer=(PRINTER_INFO_1*)malloc(sizeof(PRINTER_INFO_1))) == NULL)
2200 return ERROR_NOT_ENOUGH_MEMORY;
2202 construct_printer_info_1(servername, PRINTER_ENUM_ICON8, printer, snum);
2204 /* check the required size. */
2205 *needed += spoolss_size_printer_info_1(printer);
2207 if (!alloc_buffer_size(buffer, *needed)) {
2209 return ERROR_INSUFFICIENT_BUFFER;
2212 /* fill the buffer with the structures */
2213 new_smb_io_printer_info_1("", buffer, printer, 0);
2218 if (*needed > offered) {
2219 return ERROR_INSUFFICIENT_BUFFER;
2222 return NT_STATUS_NO_PROBLEMO;
2225 /****************************************************************************
2226 ****************************************************************************/
2227 static uint32 getprinter_level_2(pstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2229 PRINTER_INFO_2 *printer=NULL;
2232 if((printer=(PRINTER_INFO_2*)malloc(sizeof(PRINTER_INFO_2)))==NULL)
2233 return ERROR_NOT_ENOUGH_MEMORY;
2235 fstrcpy(temp, "\\\\");
2236 fstrcat(temp, servername);
2237 construct_printer_info_2(temp, printer, snum);
2239 /* check the required size. */
2240 *needed += spoolss_size_printer_info_2(printer);
2242 if (!alloc_buffer_size(buffer, *needed)) {
2244 return ERROR_INSUFFICIENT_BUFFER;
2247 /* fill the buffer with the structures */
2248 new_smb_io_printer_info_2("", buffer, printer, 0);
2251 safe_free(printer->devmode->private);
2252 safe_free(printer->devmode);
2255 if (*needed > offered) {
2256 return ERROR_INSUFFICIENT_BUFFER;
2259 return NT_STATUS_NO_PROBLEMO;
2262 /****************************************************************************
2263 ****************************************************************************/
2264 uint32 _spoolss_getprinter(POLICY_HND *handle, uint32 level,
2265 NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2272 pstrcpy(servername, global_myname);
2274 if (!get_printer_snum(handle, &snum))
2275 return ERROR_INVALID_HANDLE;
2279 return getprinter_level_0(servername, snum, buffer, offered, needed);
2282 return getprinter_level_1(servername,snum, buffer, offered, needed);
2285 return getprinter_level_2(servername,snum, buffer, offered, needed);
2288 return ERROR_INVALID_LEVEL;
2293 /********************************************************************
2294 * construct_printer_driver_info_1
2295 * fill a construct_printer_driver_info_1 struct
2296 ********************************************************************/
2297 static void fill_printer_driver_info_1(DRIVER_INFO_1 *info,
2298 NT_PRINTER_DRIVER_INFO_LEVEL driver,
2299 pstring servername, fstring architecture)
2301 init_unistr( &(info->name), driver.info_3->name);
2304 static void construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum,
2305 pstring servername, fstring architecture)
2307 NT_PRINTER_INFO_LEVEL printer;
2308 NT_PRINTER_DRIVER_INFO_LEVEL driver;
2310 get_a_printer(&printer, 2, lp_servicename(snum) );
2311 get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture);
2313 fill_printer_driver_info_1(info, driver, servername, architecture);
2315 free_a_printer_driver(driver, 3);
2316 free_a_printer(printer, 2);
2319 /********************************************************************
2320 * construct_printer_driver_info_2
2321 * fill a printer_info_2 struct
2322 ********************************************************************/
2323 static void fill_printer_driver_info_2(DRIVER_INFO_2 *info,
2324 NT_PRINTER_DRIVER_INFO_LEVEL driver,
2325 pstring servername, fstring architecture)
2328 pstring temp_driverpath;
2329 pstring temp_datafile;
2330 pstring temp_configfile;
2331 fstring short_archi;
2333 get_short_archi(short_archi,architecture);
2335 snprintf(where,sizeof(where)-1,"\\\\%s\\print$\\%s\\", servername, short_archi);
2337 info->version=driver.info_3->cversion;
2339 init_unistr( &(info->name), driver.info_3->name );
2340 init_unistr( &(info->architecture), architecture );
2342 snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "%s%s", where,
2343 driver.info_3->driverpath);
2344 init_unistr( &(info->driverpath), temp_driverpath );
2346 snprintf(temp_datafile, sizeof(temp_datafile)-1, "%s%s", where,
2347 driver.info_3->datafile);
2348 init_unistr( &(info->datafile), temp_datafile );
2350 snprintf(temp_configfile, sizeof(temp_configfile)-1, "%s%s", where,
2351 driver.info_3->configfile);
2352 init_unistr( &(info->configfile), temp_configfile );
2355 /********************************************************************
2356 * construct_printer_driver_info_2
2357 * fill a printer_info_2 struct
2358 ********************************************************************/
2359 static void construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, pstring servername, fstring architecture)
2361 NT_PRINTER_INFO_LEVEL printer;
2362 NT_PRINTER_DRIVER_INFO_LEVEL driver;
2364 get_a_printer(&printer, 2, lp_servicename(snum) );
2365 get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture);
2367 fill_printer_driver_info_2(info, driver, servername, architecture);
2369 free_a_printer_driver(driver, 3);
2370 free_a_printer(printer, 2);
2373 /********************************************************************
2374 * copy a strings array and convert to UNICODE
2376 * convert an array of ascii string to a UNICODE string
2377 ********************************************************************/
2378 static void init_unistr_array(uint16 **uni_array, char **char_array, char *where)
2385 DEBUG(6,("init_unistr_array\n"));
2388 for (v=char_array[i]; *v!='\0'; v=char_array[i]) {
2389 snprintf(line, sizeof(line)-1, "%s%s", where, v);
2390 DEBUGADD(6,("%d:%s:%d\n", i, line, strlen(line)));
2391 if((*uni_array=Realloc(*uni_array, (j+strlen(line)+2)*sizeof(uint16))) == NULL) {
2392 DEBUG(0,("init_unistr_array: Realloc error\n" ));
2395 ascii_to_unistr( *uni_array+j, line , strlen(line));
2400 (*uni_array)[j]=0x0000;
2402 DEBUGADD(6,("last one:done\n"));
2405 /********************************************************************
2406 * construct_printer_info_3
2407 * fill a printer_info_3 struct
2408 ********************************************************************/
2409 static void fill_printer_driver_info_3(DRIVER_INFO_3 *info,
2410 NT_PRINTER_DRIVER_INFO_LEVEL driver,
2411 pstring servername, fstring architecture)
2414 pstring temp_driverpath;
2415 pstring temp_datafile;
2416 pstring temp_configfile;
2417 pstring temp_helpfile;
2418 fstring short_archi;
2420 get_short_archi(short_archi, architecture);
2422 snprintf(where,sizeof(where)-1,"\\\\%s\\print$\\%s\\", servername, short_archi);
2424 info->version=driver.info_3->cversion;
2426 init_unistr( &(info->name), driver.info_3->name );
2427 init_unistr( &(info->architecture), architecture );
2429 snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "%s%s", where, driver.info_3->driverpath);
2430 init_unistr( &(info->driverpath), temp_driverpath );
2432 snprintf(temp_datafile, sizeof(temp_datafile)-1, "%s%s", where, driver.info_3->datafile);
2433 init_unistr( &(info->datafile), temp_datafile );
2435 snprintf(temp_configfile, sizeof(temp_configfile)-1, "%s%s", where, driver.info_3->configfile);
2436 init_unistr( &(info->configfile), temp_configfile );
2438 snprintf(temp_helpfile, sizeof(temp_helpfile)-1, "%s%s", where, driver.info_3->helpfile);
2439 init_unistr( &(info->helpfile), temp_helpfile );
2441 init_unistr( &(info->monitorname), driver.info_3->monitorname );
2442 init_unistr( &(info->defaultdatatype), driver.info_3->defaultdatatype );
2444 info->dependentfiles=NULL;
2445 init_unistr_array(&(info->dependentfiles), driver.info_3->dependentfiles, where);
2448 /********************************************************************
2449 * construct_printer_info_3
2450 * fill a printer_info_3 struct
2451 ********************************************************************/
2452 static void construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum,
2453 pstring servername, fstring architecture)
2455 NT_PRINTER_INFO_LEVEL printer;
2456 NT_PRINTER_DRIVER_INFO_LEVEL driver;
2458 get_a_printer(&printer, 2, lp_servicename(snum) );
2459 get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture);
2461 fill_printer_driver_info_3(info, driver, servername, architecture);
2463 free_a_printer_driver(driver, 3);
2464 free_a_printer(printer, 2);
2467 /****************************************************************************
2468 ****************************************************************************/
2469 static uint32 getprinterdriver2_level1(pstring servername, pstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2471 DRIVER_INFO_1 *info=NULL;
2473 if((info=(DRIVER_INFO_1 *)malloc(sizeof(DRIVER_INFO_1))) == NULL)
2474 return ERROR_NOT_ENOUGH_MEMORY;
2476 construct_printer_driver_info_1(info, snum, servername, architecture);
2478 /* check the required size. */
2479 *needed += spoolss_size_printer_driver_info_1(info);
2481 if (!alloc_buffer_size(buffer, *needed)) {
2483 return ERROR_INSUFFICIENT_BUFFER;
2486 /* fill the buffer with the structures */
2487 new_smb_io_printer_driver_info_1("", buffer, info, 0);
2492 if (*needed > offered)
2493 return ERROR_INSUFFICIENT_BUFFER;
2495 return NT_STATUS_NO_PROBLEMO;
2498 /****************************************************************************
2499 ****************************************************************************/
2500 static uint32 getprinterdriver2_level2(pstring servername, pstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2502 DRIVER_INFO_2 *info=NULL;
2504 if((info=(DRIVER_INFO_2 *)malloc(sizeof(DRIVER_INFO_2))) == NULL)
2505 return ERROR_NOT_ENOUGH_MEMORY;
2507 construct_printer_driver_info_2(info, snum, servername, architecture);
2509 /* check the required size. */
2510 *needed += spoolss_size_printer_driver_info_2(info);
2512 if (!alloc_buffer_size(buffer, *needed)) {
2514 return ERROR_INSUFFICIENT_BUFFER;
2517 /* fill the buffer with the structures */
2518 new_smb_io_printer_driver_info_2("", buffer, info, 0);
2523 if (*needed > offered)
2524 return ERROR_INSUFFICIENT_BUFFER;
2526 return NT_STATUS_NO_PROBLEMO;
2529 /****************************************************************************
2530 ****************************************************************************/
2531 static uint32 getprinterdriver2_level3(pstring servername, pstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2533 DRIVER_INFO_3 *info=NULL;
2535 if((info=(DRIVER_INFO_3 *)malloc(sizeof(DRIVER_INFO_3)))==NULL)
2536 return ERROR_NOT_ENOUGH_MEMORY;
2538 construct_printer_driver_info_3(info, snum, servername, architecture);
2540 /* check the required size. */
2541 *needed += spoolss_size_printer_driver_info_3(info);
2543 if (!alloc_buffer_size(buffer, *needed)) {
2545 return ERROR_INSUFFICIENT_BUFFER;
2548 /* fill the buffer with the structures */
2549 new_smb_io_printer_driver_info_3("", buffer, info, 0);
2552 safe_free(info->dependentfiles);
2555 if (*needed > offered)
2556 return ERROR_INSUFFICIENT_BUFFER;
2558 return NT_STATUS_NO_PROBLEMO;
2561 /****************************************************************************
2562 ****************************************************************************/
2563 uint32 _spoolss_getprinterdriver2(const POLICY_HND *handle, const UNISTR2 *uni_arch, uint32 level,
2564 uint32 clientmajorversion, uint32 clientminorversion,
2565 NEW_BUFFER *buffer, uint32 offered,
2566 uint32 *needed, uint32 *servermajorversion, uint32 *serverminorversion)
2569 fstring architecture;
2572 DEBUG(4,("_spoolss_getprinterdriver2\n"));
2575 *servermajorversion=0;
2576 *serverminorversion=0;
2578 pstrcpy(servername, global_myname);
2579 unistr2_to_ascii(architecture, uni_arch, sizeof(architecture)-1);
2581 if (!get_printer_snum(handle, &snum))
2582 return ERROR_INVALID_HANDLE;
2586 return getprinterdriver2_level1(servername, architecture, snum, buffer, offered, needed);
2589 return getprinterdriver2_level2(servername, architecture, snum, buffer, offered, needed);
2592 return getprinterdriver2_level3(servername, architecture, snum, buffer, offered, needed);
2595 return ERROR_INVALID_LEVEL;
2600 /****************************************************************************
2601 ****************************************************************************/
2602 uint32 _spoolss_startpageprinter(const POLICY_HND *handle)
2604 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2606 if (OPEN_HANDLE(Printer))
2608 Printer->page_started=True;
2612 DEBUG(3,("Error in startpageprinter printer handle\n"));
2613 return ERROR_INVALID_HANDLE;
2616 /****************************************************************************
2617 ****************************************************************************/
2618 uint32 _spoolss_endpageprinter(const POLICY_HND *handle)
2620 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2622 if (!OPEN_HANDLE(Printer))
2624 DEBUG(3,("Error in endpageprinter printer handle\n"));
2625 return ERROR_INVALID_HANDLE;
2628 Printer->page_started=False;
2630 return NT_STATUS_NO_PROBLEMO;
2634 /********************************************************************
2635 * api_spoolss_getprinter
2636 * called from the spoolss dispatcher
2638 ********************************************************************/
2639 uint32 _spoolss_startdocprinter( const POLICY_HND *handle, uint32 level,
2640 DOC_INFO *docinfo, uint32 *jobid)
2642 DOC_INFO_1 *info_1 = &docinfo->doc_info_1;
2646 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2648 if (!OPEN_HANDLE(Printer))
2650 return ERROR_INVALID_HANDLE;
2654 * a nice thing with NT is it doesn't listen to what you tell it.
2655 * when asked to send _only_ RAW datas, it tries to send datas
2658 * So I add checks like in NT Server ...
2660 * lkclXXXX jean-francois, i love this kind of thing. oh, well,
2661 * there's a bug in NT client-side code, so we'll fix it in the
2662 * server-side code. *nnnnnggggh!*
2665 if (info_1->p_datatype != 0)
2667 unistr2_to_ascii(datatype, &(info_1->docname), sizeof(datatype));
2668 if (strcmp(datatype, "RAW") != 0)
2671 return ERROR_INVALID_DATATYPE;
2675 /* get the share number of the printer */
2676 if (!get_printer_snum(handle, &snum))
2678 return ERROR_INVALID_HANDLE;
2681 unistr2_to_ascii(jobname, &info_1->docname, sizeof(jobname));
2683 Printer->jobid = print_job_start(snum, jobname);
2685 /* need to map error codes properly - for now give out of
2686 memory as I don't know the correct codes (tridge) */
2687 if (Printer->jobid == -1) {
2688 return ERROR_NOT_ENOUGH_MEMORY;
2691 Printer->document_started=True;
2692 (*jobid) = Printer->jobid;
2697 /********************************************************************
2698 * api_spoolss_getprinter
2699 * called from the spoolss dispatcher
2701 ********************************************************************/
2702 uint32 _spoolss_enddocprinter(const POLICY_HND *handle)
2704 Printer_entry *Printer=find_printer_index_by_hnd(handle);
2706 if (!OPEN_HANDLE(Printer))
2708 DEBUG(3,("Error in enddocprinter handle\n"));
2709 return ERROR_INVALID_HANDLE;
2712 Printer->document_started=False;
2713 print_job_end(Printer->jobid);
2714 /* error codes unhandled so far ... */
2719 /****************************************************************************
2720 ****************************************************************************/
2721 uint32 _spoolss_writeprinter( const POLICY_HND *handle,
2723 const uint8 *buffer,
2724 uint32 *buffer_written)
2726 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2728 if (!OPEN_HANDLE(Printer))
2730 DEBUG(3,("Error in writeprinter handle\n"));
2731 return ERROR_INVALID_HANDLE;
2734 (*buffer_written) = print_job_write(Printer->jobid, buffer, buffer_size);
2739 /********************************************************************
2740 * api_spoolss_getprinter
2741 * called from the spoolss dispatcher
2743 ********************************************************************/
2744 static uint32 control_printer(const POLICY_HND *handle, uint32 command)
2747 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2749 if (!OPEN_HANDLE(Printer))
2750 return ERROR_INVALID_HANDLE;
2752 if (!get_printer_snum(handle, &snum) )
2753 return ERROR_INVALID_HANDLE;
2756 case PRINTER_CONTROL_PAUSE:
2757 if (print_queue_pause(snum)) {
2761 case PRINTER_CONTROL_RESUME:
2762 case PRINTER_CONTROL_UNPAUSE:
2763 if (print_queue_resume(snum)) {
2767 case PRINTER_CONTROL_PURGE:
2768 if (print_queue_purge(snum)) {
2774 return ERROR_INVALID_FUNCTION;
2777 /********************************************************************
2778 * called by spoolss_api_setprinter
2779 * when updating a printer description
2780 ********************************************************************/
2781 static uint32 update_printer(const POLICY_HND *handle, uint32 level,
2782 const SPOOL_PRINTER_INFO_LEVEL *info,
2783 const DEVICEMODE *devmode)
2786 NT_PRINTER_INFO_LEVEL printer;
2787 NT_DEVICEMODE *nt_devmode;
2788 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2792 DEBUG(8,("update_printer\n"));
2795 DEBUG(0,("Send a mail to jfm@samba.org\n"));
2796 DEBUGADD(0,("with the following message: update_printer: level!=2\n"));
2797 return ERROR_INVALID_LEVEL;
2800 if (!OPEN_HANDLE(Printer))
2801 return ERROR_INVALID_HANDLE;
2803 if (!get_printer_snum(handle, &snum) )
2804 return ERROR_INVALID_HANDLE;
2806 get_a_printer(&printer, 2, lp_servicename(snum));
2808 DEBUGADD(8,("Converting info_2 struct\n"));
2809 convert_printer_info(info, &printer, level);
2811 if ((info->info_2)->devmode_ptr != 0) {
2812 /* we have a valid devmode
2813 convert it and link it*/
2815 /* the nt_devmode memory is already alloced
2816 * while doing the get_a_printer call
2817 * but the devmode private part is not
2818 * it's done by convert_devicemode
2820 DEBUGADD(8,("Converting the devicemode struct\n"));
2821 nt_devmode=printer.info_2->devmode;
2823 init_devicemode(nt_devmode);
2825 convert_devicemode(*devmode, nt_devmode);
2828 if (printer.info_2->devmode != NULL)
2829 free(printer.info_2->devmode);
2830 printer.info_2->devmode=NULL;
2833 if (add_a_printer(printer, 2)!=0) {
2834 free_a_printer(printer, 2);
2836 /* I don't really know what to return here !!! */
2837 return ERROR_ACCESS_DENIED;
2840 free_a_printer(printer, 2);
2842 return NT_STATUS_NO_PROBLEMO;
2845 /****************************************************************************
2846 ****************************************************************************/
2847 uint32 _spoolss_setprinter(const POLICY_HND *handle, uint32 level,
2848 const SPOOL_PRINTER_INFO_LEVEL *info,
2849 const DEVMODE_CTR devmode_ctr,
2852 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2854 if (!OPEN_HANDLE(Printer))
2855 return ERROR_INVALID_HANDLE;
2857 /* check the level */
2860 return control_printer(handle, command);
2863 return update_printer(handle, level, info, devmode_ctr.devmode);
2866 return ERROR_INVALID_LEVEL;
2871 /****************************************************************************
2872 ****************************************************************************/
2873 uint32 _spoolss_fcpn(const POLICY_HND *handle)
2875 Printer_entry *Printer= find_printer_index_by_hnd(handle);
2877 if (!OPEN_HANDLE(Printer))
2878 return ERROR_INVALID_HANDLE;
2880 Printer->notify.flags=0;
2881 Printer->notify.options=0;
2882 Printer->notify.localmachine[0]='\0';
2883 Printer->notify.printerlocal=0;
2884 safe_free(Printer->notify.option);
2885 Printer->notify.option=NULL;
2887 return NT_STATUS_NO_PROBLEMO;
2890 /****************************************************************************
2891 ****************************************************************************/
2892 uint32 _spoolss_addjob(const POLICY_HND *handle, uint32 level,
2893 NEW_BUFFER *buffer, uint32 offered)
2895 return NT_STATUS_NO_PROBLEMO;
2898 /****************************************************************************
2899 ****************************************************************************/
2900 static void fill_job_info_1(JOB_INFO_1 *job_info, print_queue_struct *queue,
2901 int position, int snum)
2906 time_t unixdate = time(NULL);
2908 t=gmtime(&unixdate);
2909 snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname);
2911 job_info->jobid=queue->job;
2912 init_unistr(&(job_info->printername), lp_servicename(snum));
2913 init_unistr(&(job_info->machinename), temp_name);
2914 init_unistr(&(job_info->username), queue->user);
2915 init_unistr(&(job_info->document), queue->file);
2916 init_unistr(&(job_info->datatype), "RAW");
2917 init_unistr(&(job_info->text_status), "");
2918 job_info->status=queue->status;
2919 job_info->priority=queue->priority;
2920 job_info->position=position;
2921 job_info->totalpages=0;
2922 job_info->pagesprinted=0;
2924 make_systemtime(&(job_info->submitted), t);
2927 /****************************************************************************
2928 ****************************************************************************/
2929 static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue,
2930 int position, int snum)
2933 DEVICEMODE *devmode;
2934 NT_PRINTER_INFO_LEVEL ntprinter;
2938 time_t unixdate = time(NULL);
2940 if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0 )
2943 t=gmtime(&unixdate);
2944 snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname);
2946 job_info->jobid=queue->job;
2948 snprintf(chaine, sizeof(chaine)-1, "\\\\%s\\%s", global_myname, ntprinter.info_2->printername);
2949 init_unistr(&(job_info->printername), chaine);
2951 init_unistr(&(job_info->machinename), temp_name);
2952 init_unistr(&(job_info->username), queue->user);
2953 init_unistr(&(job_info->document), queue->file);
2954 init_unistr(&(job_info->notifyname), queue->user);
2955 init_unistr(&(job_info->datatype), "RAW");
2956 init_unistr(&(job_info->printprocessor), "winprint");
2957 init_unistr(&(job_info->parameters), "");
2958 init_unistr(&(job_info->text_status), "");
2960 /* and here the security descriptor */
2962 job_info->status=queue->status;
2963 job_info->priority=queue->priority;
2964 job_info->position=position;
2965 job_info->starttime=0;
2966 job_info->untiltime=0;
2967 job_info->totalpages=0;
2968 job_info->size=queue->size;
2969 make_systemtime(&(job_info->submitted), t);
2970 job_info->timeelapsed=0;
2971 job_info->pagesprinted=0;
2973 if((devmode=(DEVICEMODE *)malloc(sizeof(DEVICEMODE))) == NULL) {
2974 free_a_printer(ntprinter, 2);
2978 ZERO_STRUCTP(devmode);
2979 if(!construct_dev_mode(devmode, snum, global_myname)) {
2980 free_a_printer(ntprinter, 2);
2983 job_info->devmode=devmode;
2985 free_a_printer(ntprinter, 2);
2989 /****************************************************************************
2990 Enumjobs at level 1.
2991 ****************************************************************************/
2992 static uint32 enumjobs_level1(print_queue_struct *queue, int snum,
2993 NEW_BUFFER *buffer, uint32 offered,
2994 uint32 *needed, uint32 *returned)
2999 info=(JOB_INFO_1 *)malloc(*returned*sizeof(JOB_INFO_1));
3003 return ERROR_NOT_ENOUGH_MEMORY;
3006 for (i=0; i<*returned; i++)
3007 fill_job_info_1(&(info[i]), &(queue[i]), i, snum);
3011 /* check the required size. */
3012 for (i=0; i<*returned; i++)
3013 (*needed) += spoolss_size_job_info_1(&(info[i]));
3015 if (!alloc_buffer_size(buffer, *needed)) {
3017 return ERROR_INSUFFICIENT_BUFFER;
3020 /* fill the buffer with the structures */
3021 for (i=0; i<*returned; i++)
3022 new_smb_io_job_info_1("", buffer, &(info[i]), 0);
3027 if (*needed > offered) {
3029 return ERROR_INSUFFICIENT_BUFFER;
3032 return NT_STATUS_NO_PROBLEMO;
3035 /****************************************************************************
3036 Enumjobs at level 2.
3037 ****************************************************************************/
3038 static uint32 enumjobs_level2(print_queue_struct *queue, int snum,
3039 NEW_BUFFER *buffer, uint32 offered,
3040 uint32 *needed, uint32 *returned)
3045 info=(JOB_INFO_2 *)malloc(*returned*sizeof(JOB_INFO_2));
3049 return ERROR_NOT_ENOUGH_MEMORY;
3052 for (i=0; i<*returned; i++)
3053 fill_job_info_2(&(info[i]), &(queue[i]), i, snum);
3057 /* check the required size. */
3058 for (i=0; i<*returned; i++)
3059 (*needed) += spoolss_size_job_info_2(&(info[i]));
3061 if (!alloc_buffer_size(buffer, *needed)) {
3063 return ERROR_INSUFFICIENT_BUFFER;
3066 /* fill the buffer with the structures */
3067 for (i=0; i<*returned; i++)
3068 new_smb_io_job_info_2("", buffer, &(info[i]), 0);
3073 if (*needed > offered) {
3075 return ERROR_INSUFFICIENT_BUFFER;
3078 return NT_STATUS_NO_PROBLEMO;
3081 /****************************************************************************
3083 ****************************************************************************/
3084 uint32 _spoolss_enumjobs( POLICY_HND *handle, uint32 firstjob, uint32 numofjobs, uint32 level,
3085 NEW_BUFFER *buffer, uint32 offered,
3086 uint32 *needed, uint32 *returned)
3089 print_queue_struct *queue=NULL;
3090 print_status_struct prt_status;
3092 DEBUG(4,("_spoolss_enumjobs\n"));
3094 ZERO_STRUCT(prt_status);
3099 if (!get_printer_snum(handle, &snum))
3100 return ERROR_INVALID_HANDLE;
3102 *returned = print_queue_status(snum, &queue, &prt_status);
3103 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n", *returned, prt_status.status, prt_status.message));
3107 return enumjobs_level1(queue, snum, buffer, offered, needed, returned);
3110 return enumjobs_level2(queue, snum, buffer, offered, needed, returned);
3115 return ERROR_INVALID_LEVEL;
3121 /****************************************************************************
3122 ****************************************************************************/
3123 uint32 _spoolss_schedulejob( const POLICY_HND *handle, uint32 jobid)
3128 /****************************************************************************
3129 ****************************************************************************/
3130 uint32 _spoolss_setjob( const POLICY_HND *handle,
3138 print_status_struct prt_status;
3140 memset(&prt_status, 0, sizeof(prt_status));
3142 if (!get_printer_snum(handle, &snum)) {
3143 return ERROR_INVALID_HANDLE;
3146 if (!print_job_exists(jobid)) {
3147 return ERROR_INVALID_PRINTER_NAME;
3151 case JOB_CONTROL_CANCEL:
3152 case JOB_CONTROL_DELETE:
3153 if (print_job_delete(jobid)) return 0x0;
3155 case JOB_CONTROL_PAUSE:
3156 if (print_job_pause(jobid)) return 0x0;
3158 case JOB_CONTROL_RESUME:
3159 if (print_job_resume(jobid)) return 0x0;
3162 return ERROR_INVALID_LEVEL;
3165 return ERROR_INVALID_HANDLE;
3168 /****************************************************************************
3169 Enumerates all printer drivers at level 1.
3170 ****************************************************************************/
3171 static uint32 enumprinterdrivers_level1(fstring *list, fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3174 NT_PRINTER_DRIVER_INFO_LEVEL driver;
3175 DRIVER_INFO_1 *driver_info_1=NULL;
3177 if((driver_info_1=(DRIVER_INFO_1 *)malloc(*returned * sizeof(DRIVER_INFO_1))) == NULL)
3178 return ERROR_NOT_ENOUGH_MEMORY;
3180 for (i=0; i<*returned; i++) {
3181 get_a_printer_driver(&driver, 3, list[i], architecture);
3182 fill_printer_driver_info_1(&(driver_info_1[i]), driver, servername, architecture );
3183 free_a_printer_driver(driver, 3);
3188 /* check the required size. */
3189 for (i=0; i<*returned; i++) {
3190 DEBUGADD(6,("adding driver [%d]'s size\n",i));
3191 *needed += spoolss_size_printer_driver_info_1(&(driver_info_1[i]));
3194 if (!alloc_buffer_size(buffer, *needed)) {
3195 safe_free(driver_info_1);
3196 return ERROR_INSUFFICIENT_BUFFER;
3199 /* fill the buffer with the form structures */
3200 for (i=0; i<*returned; i++) {
3201 DEBUGADD(6,("adding driver [%d] to buffer\n",i));
3202 new_smb_io_printer_driver_info_1("", buffer, &(driver_info_1[i]), 0);
3205 safe_free(driver_info_1);
3207 if (*needed > offered) {
3209 return ERROR_INSUFFICIENT_BUFFER;
3212 return NT_STATUS_NO_PROBLEMO;
3215 /****************************************************************************
3216 Enumerates all printer drivers at level 2.
3217 ****************************************************************************/
3218 static uint32 enumprinterdrivers_level2(fstring *list, fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3221 NT_PRINTER_DRIVER_INFO_LEVEL driver;
3222 DRIVER_INFO_2 *driver_info_2=NULL;
3224 if((driver_info_2=(DRIVER_INFO_2 *)malloc(*returned * sizeof(DRIVER_INFO_2))) == NULL)
3225 return ERROR_NOT_ENOUGH_MEMORY;
3227 for (i=0; i<*returned; i++) {
3228 get_a_printer_driver(&driver, 3, list[i], architecture);
3229 fill_printer_driver_info_2(&(driver_info_2[i]), driver, servername, architecture );
3230 free_a_printer_driver(driver, 3);
3235 /* check the required size. */
3236 for (i=0; i<*returned; i++) {
3237 DEBUGADD(6,("adding driver [%d]'s size\n",i));
3238 *needed += spoolss_size_printer_driver_info_2(&(driver_info_2[i]));
3241 if (!alloc_buffer_size(buffer, *needed)) {
3242 safe_free(driver_info_2);
3243 return ERROR_INSUFFICIENT_BUFFER;
3246 /* fill the buffer with the form structures */
3247 for (i=0; i<*returned; i++) {
3248 DEBUGADD(6,("adding driver [%d] to buffer\n",i));
3249 new_smb_io_printer_driver_info_2("", buffer, &(driver_info_2[i]), 0);
3252 safe_free(driver_info_2);
3254 if (*needed > offered) {
3256 return ERROR_INSUFFICIENT_BUFFER;
3259 return NT_STATUS_NO_PROBLEMO;
3262 /****************************************************************************
3263 Enumerates all printer drivers at level 3.
3264 ****************************************************************************/
3265 static uint32 enumprinterdrivers_level3(fstring *list, fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3268 NT_PRINTER_DRIVER_INFO_LEVEL driver;
3269 DRIVER_INFO_3 *driver_info_3=NULL;
3271 if((driver_info_3=(DRIVER_INFO_3 *)malloc((*returned)*sizeof(DRIVER_INFO_3))) == NULL)
3272 return ERROR_NOT_ENOUGH_MEMORY;
3274 for (i=0; i<*returned; i++) {
3275 get_a_printer_driver(&driver, 3, list[i], architecture);
3276 fill_printer_driver_info_3(&(driver_info_3[i]), driver, servername, architecture );
3277 free_a_printer_driver(driver, 3);
3282 /* check the required size. */
3283 for (i=0; i<*returned; i++) {
3284 DEBUGADD(6,("adding driver [%d]'s size\n",i));
3285 *needed += spoolss_size_printer_driver_info_3(&(driver_info_3[i]));
3288 if (!alloc_buffer_size(buffer, *needed)) {
3289 safe_free(driver_info_3);
3290 return ERROR_INSUFFICIENT_BUFFER;
3293 /* fill the buffer with the form structures */
3294 for (i=0; i<*returned; i++) {
3295 DEBUGADD(6,("adding form [%d] to buffer\n",i));
3296 new_smb_io_printer_driver_info_3("", buffer, &(driver_info_3[i]), 0);
3299 for (i=0; i<*returned; i++)
3300 safe_free(driver_info_3[i].dependentfiles);
3302 safe_free(driver_info_3);
3304 if (*needed > offered) {
3306 return ERROR_INSUFFICIENT_BUFFER;
3309 return NT_STATUS_NO_PROBLEMO;
3312 /****************************************************************************
3313 Enumerates all printer drivers.
3314 ****************************************************************************/
3315 uint32 _spoolss_enumprinterdrivers( UNISTR2 *name, UNISTR2 *environment, uint32 level,
3316 NEW_BUFFER *buffer, uint32 offered,
3317 uint32 *needed, uint32 *returned)
3322 fstring architecture;
3324 DEBUG(4,("_spoolss_enumprinterdrivers\n"));
3325 fstrcpy(servername, global_myname);
3329 unistr2_to_ascii(architecture, environment, sizeof(architecture)-1);
3330 *returned=get_ntdrivers(&list, architecture);
3332 DEBUGADD(4,("we have: [%d] drivers in environment [%s]\n", *returned, architecture));
3334 return ERROR_NOT_ENOUGH_MEMORY;
3336 for (i=0; i<*returned; i++)
3337 DEBUGADD(5,("driver: [%s]\n", list[i]));
3341 return enumprinterdrivers_level1(list, servername, architecture, buffer, offered, needed, returned);
3344 return enumprinterdrivers_level2(list, servername, architecture, buffer, offered, needed, returned);
3347 return enumprinterdrivers_level3(list, servername, architecture, buffer, offered, needed, returned);
3350 return ERROR_INVALID_LEVEL;
3355 /****************************************************************************
3356 ****************************************************************************/
3357 static void fill_form_1(FORM_1 *form, nt_forms_struct *list, int position)
3359 form->flag=list->flag;
3360 init_unistr(&(form->name), list->name);
3361 form->width=list->width;
3362 form->length=list->length;
3363 form->left=list->left;
3364 form->top=list->top;
3365 form->right=list->right;
3366 form->bottom=list->bottom;
3369 /****************************************************************************
3370 ****************************************************************************/
3371 uint32 _new_spoolss_enumforms( const POLICY_HND *handle, uint32 level,
3372 NEW_BUFFER *buffer, uint32 offered,
3373 uint32 *needed, uint32 *numofforms)
3375 nt_forms_struct *list=NULL;
3380 DEBUG(4,("_new_spoolss_enumforms\n"));
3381 DEBUGADD(5,("Offered buffer size [%d]\n", offered));
3382 DEBUGADD(5,("Info level [%d]\n", level));
3384 *numofforms = get_ntforms(&list);
3385 DEBUGADD(5,("Number of forms [%d]\n", *numofforms));
3389 if((forms_1=(FORM_1 *)malloc(*numofforms * sizeof(FORM_1))) == NULL) {
3391 return ERROR_NOT_ENOUGH_MEMORY;
3394 /* construct the list of form structures */
3395 for (i=0; i<*numofforms; i++) {
3396 DEBUGADD(6,("Filling form number [%d]\n",i));
3397 fill_form_1(&(forms_1[i]), &(list[i]), i);
3402 /* check the required size. */
3403 for (i=0; i<*numofforms; i++) {
3404 DEBUGADD(6,("adding form [%d]'s size\n",i));
3405 buffer_size += spoolss_size_form_1(&(forms_1[i]));
3408 *needed=buffer_size;
3410 if (!alloc_buffer_size(buffer, buffer_size)){
3412 return ERROR_INSUFFICIENT_BUFFER;
3415 /* fill the buffer with the form structures */
3416 for (i=0; i<*numofforms; i++) {
3417 DEBUGADD(6,("adding form [%d] to buffer\n",i));
3418 new_smb_io_form_1("", buffer, &(forms_1[i]), 0);
3423 if (*needed > offered) {
3425 return ERROR_INSUFFICIENT_BUFFER;
3428 return NT_STATUS_NO_PROBLEMO;
3432 return ERROR_INVALID_LEVEL;
3437 /****************************************************************************
3438 ****************************************************************************/
3439 static void fill_port_1(PORT_INFO_1 *port, char *name)
3441 init_unistr(&(port->port_name), name);
3444 /****************************************************************************
3445 ****************************************************************************/
3446 static void fill_port_2(PORT_INFO_2 *port, char *name)
3448 init_unistr(&(port->port_name), name);
3449 init_unistr(&(port->monitor_name), "Moniteur Local");
3450 init_unistr(&(port->description), "Local Port");
3451 #define PORT_TYPE_WRITE 1
3452 port->port_type=PORT_TYPE_WRITE;
3456 /****************************************************************************
3458 ****************************************************************************/
3459 static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3461 int n_services=lp_numservices();
3465 PORT_INFO_1 *ports=NULL;
3467 for (snum=0; snum<n_services; snum++)
3468 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
3471 if((ports=(PORT_INFO_1 *)malloc( (*returned+1) * sizeof(PORT_INFO_1) )) == NULL)
3472 return ERROR_NOT_ENOUGH_MEMORY;
3474 for (snum=0; snum<n_services; snum++) {
3475 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
3476 DEBUGADD(6,("Filling port number [%d]\n", i));
3477 fill_port_1(&(ports[i]), lp_servicename(snum));
3482 /* check the required size. */
3483 for (i=0; i<*returned; i++) {
3484 DEBUGADD(6,("adding port [%d]'s size\n", i));
3485 *needed += spoolss_size_port_info_1(&(ports[i]));
3488 if (!alloc_buffer_size(buffer, *needed)) {
3490 return ERROR_INSUFFICIENT_BUFFER;
3493 /* fill the buffer with the ports structures */
3494 for (i=0; i<*returned; i++) {
3495 DEBUGADD(6,("adding port [%d] to buffer\n", i));
3496 new_smb_io_port_1("", buffer, &(ports[i]), 0);
3501 if (*needed > offered) {
3503 return ERROR_INSUFFICIENT_BUFFER;
3506 return NT_STATUS_NO_PROBLEMO;
3510 /****************************************************************************
3512 ****************************************************************************/
3513 static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3515 int n_services=lp_numservices();
3519 PORT_INFO_2 *ports=NULL;
3521 for (snum=0; snum<n_services; snum++)
3522 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
3525 if((ports=(PORT_INFO_2 *)malloc( (*returned+1) * sizeof(PORT_INFO_2) )) == NULL)
3526 return ERROR_NOT_ENOUGH_MEMORY;
3528 for (snum=0; snum<n_services; snum++) {
3529 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
3530 DEBUGADD(6,("Filling port number [%d]\n", i));
3531 fill_port_2(&(ports[i]), lp_servicename(snum));
3536 /* check the required size. */
3537 for (i=0; i<*returned; i++) {
3538 DEBUGADD(6,("adding port [%d]'s size\n", i));
3539 *needed += spoolss_size_port_info_2(&(ports[i]));
3542 if (!alloc_buffer_size(buffer, *needed)) {
3544 return ERROR_INSUFFICIENT_BUFFER;
3547 /* fill the buffer with the ports structures */
3548 for (i=0; i<*returned; i++) {
3549 DEBUGADD(6,("adding port [%d] to buffer\n", i));
3550 new_smb_io_port_2("", buffer, &(ports[i]), 0);
3555 if (*needed > offered) {
3557 return ERROR_INSUFFICIENT_BUFFER;
3560 return NT_STATUS_NO_PROBLEMO;
3563 /****************************************************************************
3565 ****************************************************************************/
3566 uint32 _spoolss_enumports( UNISTR2 *name, uint32 level,
3567 NEW_BUFFER *buffer, uint32 offered,
3568 uint32 *needed, uint32 *returned)
3570 DEBUG(4,("_spoolss_enumports\n"));
3577 return enumports_level_1(buffer, offered, needed, returned);
3580 return enumports_level_2(buffer, offered, needed, returned);
3583 return ERROR_INVALID_LEVEL;
3588 /****************************************************************************
3589 ****************************************************************************/
3590 static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name,
3591 const SPOOL_PRINTER_INFO_LEVEL *info,
3592 uint32 unk0, uint32 unk1, uint32 unk2, uint32 unk3,
3593 uint32 user_switch, const SPOOL_USER_CTR *user,
3596 NT_PRINTER_INFO_LEVEL printer;
3600 clear_handle(handle);
3602 /* NULLify info_2 here */
3603 /* don't put it in convert_printer_info as it's used also with non-NULL values */
3604 printer.info_2=NULL;
3606 /* convert from UNICODE to ASCII */
3607 convert_printer_info(info, &printer, 2);
3609 unistr2_to_ascii(share_name, &((info->info_2)->printername), sizeof(share_name)-1);
3611 slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname, share_name);
3613 /* write the ASCII on disk */
3614 if (add_a_printer(printer, 2) != 0x0)
3615 return ERROR_ACCESS_DENIED;
3617 create_printer_hnd(handle);
3619 open_printer_hnd(handle);
3621 if (!set_printer_hnd_printertype(handle, name)) {
3622 close_printer_handle(handle);
3623 return ERROR_ACCESS_DENIED;
3626 if (!set_printer_hnd_printername(handle, name)) {
3627 close_printer_handle(handle);
3628 return ERROR_ACCESS_DENIED;
3631 return NT_STATUS_NO_PROBLEMO;
3634 /****************************************************************************
3635 ****************************************************************************/
3636 uint32 _spoolss_addprinterex( const UNISTR2 *uni_srv_name, uint32 level,
3637 const SPOOL_PRINTER_INFO_LEVEL *info,
3638 uint32 unk0, uint32 unk1, uint32 unk2, uint32 unk3,
3639 uint32 user_switch, const SPOOL_USER_CTR *user,
3644 /* we don't handle yet */
3645 /* but I know what to do ... */
3646 return ERROR_INVALID_LEVEL;
3649 return spoolss_addprinterex_level_2(uni_srv_name, info,
3650 unk0, unk1, unk2, unk3,
3651 user_switch, user, handle);
3654 return ERROR_INVALID_LEVEL;
3660 /****************************************************************************
3661 ****************************************************************************/
3662 uint32 _spoolss_addprinterdriver( const UNISTR2 *server_name,
3664 const SPOOL_PRINTER_DRIVER_INFO_LEVEL *info)
3666 NT_PRINTER_DRIVER_INFO_LEVEL driver;
3668 convert_printer_driver_info(info, &driver, level);
3670 if (add_a_printer_driver(driver, level)!=0)
3671 return ERROR_ACCESS_DENIED;
3673 return NT_STATUS_NO_PROBLEMO;
3676 /****************************************************************************
3677 ****************************************************************************/
3678 static void fill_driverdir_1(DRIVER_DIRECTORY_1 *info, char *name)
3680 init_unistr(&(info->name), name);
3683 /****************************************************************************
3684 ****************************************************************************/
3685 static uint32 getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environment, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
3689 pstring short_archi;
3690 DRIVER_DIRECTORY_1 *info=NULL;
3692 if((info=(DRIVER_DIRECTORY_1 *)malloc(sizeof(DRIVER_DIRECTORY_1))) == NULL)
3693 return ERROR_NOT_ENOUGH_MEMORY;
3695 unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)-1);
3696 get_short_archi(short_archi, long_archi);
3698 slprintf(chaine, sizeof(chaine)-1, "\\\\%s\\print$\\%s", global_myname, short_archi);
3700 DEBUG(4,("printer driver directory: [%s]\n", chaine));
3702 fill_driverdir_1(info, chaine);
3704 *needed += spoolss_size_driverdir_info_1(info);
3706 if (!alloc_buffer_size(buffer, *needed)) {
3708 return ERROR_INSUFFICIENT_BUFFER;
3711 new_smb_io_driverdir_1("", buffer, info, 0);
3715 if (*needed > offered)
3716 return ERROR_INSUFFICIENT_BUFFER;
3718 return NT_STATUS_NO_PROBLEMO;
3721 /****************************************************************************
3722 ****************************************************************************/
3723 uint32 _spoolss_getprinterdriverdirectory(UNISTR2 *name, UNISTR2 *uni_environment, uint32 level,
3724 NEW_BUFFER *buffer, uint32 offered,
3727 DEBUG(4,("_spoolss_getprinterdriverdirectory\n"));
3733 return getprinterdriverdir_level_1(name, uni_environment, buffer, offered, needed);
3736 return ERROR_INVALID_LEVEL;
3741 /****************************************************************************
3742 ****************************************************************************/
3743 uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx,
3744 uint32 in_value_len, uint32 in_data_len,
3745 uint32 *out_max_value_len, uint16 **out_value, uint32 *out_value_len,
3747 uint32 *out_max_data_len, uint8 **data_out, uint32 *out_data_len)
3749 NT_PRINTER_INFO_LEVEL printer;
3754 uint32 biggest_valuesize;
3755 uint32 biggest_datasize;
3757 Printer_entry *Printer = find_printer_index_by_hnd(handle);
3762 ZERO_STRUCT(printer);
3764 *out_max_value_len=0;
3770 *out_max_data_len=0;
3774 DEBUG(5,("spoolss_enumprinterdata\n"));
3776 if (!OPEN_HANDLE(Printer))
3777 return ERROR_INVALID_HANDLE;
3779 if (!get_printer_snum(handle, &snum))
3780 return ERROR_INVALID_HANDLE;
3782 if (get_a_printer(&printer, 2, lp_servicename(snum)) != 0x0)
3783 return ERROR_INVALID_HANDLE;
3786 * The NT machine wants to know the biggest size of value and data
3788 * cf: MSDN EnumPrinterData remark section
3790 if ( (in_value_len==0) && (in_data_len==0) ) {
3791 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
3794 biggest_valuesize=0;
3797 while (get_specific_param_by_index(printer, 2, param_index, value, &data, &type, &data_len)) {
3798 if (strlen(value) > biggest_valuesize) biggest_valuesize=strlen(value);
3799 if (data_len > biggest_datasize) biggest_datasize=data_len;
3801 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize, biggest_datasize));
3807 /* the value is an UNICODE string but realvaluesize is the length in bytes including the leading 0 */
3808 *out_value_len=2*(1+biggest_valuesize);
3809 *out_data_len=biggest_datasize;
3811 DEBUG(6,("final values: [%d], [%d]\n", *out_value_len, *out_data_len));
3813 free_a_printer(printer, 2);
3814 return NT_STATUS_NO_PROBLEMO;
3818 * the value len is wrong in NT sp3
3819 * that's the number of bytes not the number of unicode chars
3822 if (!get_specific_param_by_index(printer, 2, idx, value, &data, &type, &data_len)) {
3823 free_a_printer(printer, 2);
3825 return ERROR_NO_MORE_ITEMS;
3830 * - counted in bytes in the request
3831 * - counted in UNICODE chars in the max reply
3832 * - counted in bytes in the real size
3834 * take a pause *before* coding not *during* coding
3837 *out_max_value_len=in_value_len/2;
3838 if((*out_value=(uint16 *)malloc(in_value_len*sizeof(uint8))) == NULL) {
3839 free_a_printer(printer, 2);
3841 return ERROR_NOT_ENOUGH_MEMORY;
3843 ascii_to_unistr(*out_value, value, *out_max_value_len);
3844 *out_value_len=2*(1+strlen(value));
3848 /* the data is counted in bytes */
3849 *out_max_data_len=in_data_len;
3850 if((*data_out=(uint8 *)malloc(in_data_len*sizeof(uint8))) == NULL) {
3851 free_a_printer(printer, 2);
3853 return ERROR_NOT_ENOUGH_MEMORY;
3855 memcpy(*data_out, data, data_len);
3856 *out_data_len=data_len;
3860 free_a_printer(printer, 2);
3861 return NT_STATUS_NO_PROBLEMO;
3864 /****************************************************************************
3865 ****************************************************************************/
3866 uint32 _spoolss_setprinterdata( const POLICY_HND *handle,
3867 const UNISTR2 *value,
3872 uint32 numeric_data)
3874 NT_PRINTER_INFO_LEVEL printer;
3875 NT_PRINTER_PARAM *param = NULL;
3878 uint32 status = 0x0;
3879 Printer_entry *Printer=find_printer_index_by_hnd(handle);
3881 DEBUG(5,("spoolss_setprinterdata\n"));
3884 if (!OPEN_HANDLE(Printer))
3885 return ERROR_INVALID_HANDLE;
3887 if (!get_printer_snum(handle, &snum))
3888 return ERROR_INVALID_HANDLE;
3890 status = get_a_printer(&printer, 2, lp_servicename(snum));
3892 return ERROR_INVALID_NAME;
3894 convert_specific_param(¶m, value , type, data, real_len);
3895 unlink_specific_param_if_exist(printer.info_2, param);
3897 if (!add_a_specific_param(printer.info_2, param))
3898 status = ERROR_INVALID_PARAMETER;
3900 status = add_a_printer(printer, 2);
3902 free_a_printer(printer, 2);
3907 /****************************************************************************
3908 ****************************************************************************/
3909 uint32 _spoolss_addform( const POLICY_HND *handle,
3914 nt_forms_struct *list=NULL;
3915 Printer_entry *Printer = find_printer_index_by_hnd(handle);
3917 DEBUG(5,("spoolss_addform\n"));
3919 if (!OPEN_HANDLE(Printer))
3920 return ERROR_INVALID_HANDLE;
3922 count=get_ntforms(&list);
3923 if(!add_a_form(&list, form, &count))
3924 return ERROR_NOT_ENOUGH_MEMORY;
3925 write_ntforms(&list, count);
3932 /****************************************************************************
3933 ****************************************************************************/
3934 uint32 _spoolss_setform( const POLICY_HND *handle,
3935 const UNISTR2 *uni_name,
3940 nt_forms_struct *list=NULL;
3941 Printer_entry *Printer = find_printer_index_by_hnd(handle);
3943 DEBUG(5,("spoolss_setform\n"));
3945 if (!OPEN_HANDLE(Printer))
3947 return ERROR_INVALID_HANDLE;
3949 count=get_ntforms(&list);
3950 update_a_form(&list, form, count);
3951 write_ntforms(&list, count);
3958 /****************************************************************************
3959 enumprintprocessors level 1.
3960 ****************************************************************************/
3961 static uint32 enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3963 PRINTPROCESSOR_1 *info_1=NULL;
3965 if((info_1 = (PRINTPROCESSOR_1 *)malloc(sizeof(PRINTPROCESSOR_1))) == NULL)
3966 return ERROR_NOT_ENOUGH_MEMORY;
3970 init_unistr(&(info_1->name), "winprint");
3972 *needed += spoolss_size_printprocessor_info_1(info_1);
3974 if (!alloc_buffer_size(buffer, *needed))
3975 return ERROR_INSUFFICIENT_BUFFER;
3977 smb_io_printprocessor_info_1("", buffer, info_1, 0);
3981 if (*needed > offered) {
3983 return ERROR_INSUFFICIENT_BUFFER;
3986 return NT_STATUS_NO_PROBLEMO;
3989 /****************************************************************************
3990 ****************************************************************************/
3991 uint32 _spoolss_enumprintprocessors(UNISTR2 *name, UNISTR2 *environment, uint32 level,
3992 NEW_BUFFER *buffer, uint32 offered,
3993 uint32 *needed, uint32 *returned)
3995 DEBUG(5,("spoolss_enumprintprocessors\n"));
3998 * Enumerate the print processors ...
4000 * Just reply with "winprint", to keep NT happy
4001 * and I can use my nice printer checker.
4009 return enumprintprocessors_level_1(buffer, offered, needed, returned);
4012 return ERROR_INVALID_LEVEL;
4017 /****************************************************************************
4018 enumprintprocdatatypes level 1.
4019 ****************************************************************************/
4020 static uint32 enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4022 PRINTPROCDATATYPE_1 *info_1=NULL;
4024 if((info_1 = (PRINTPROCDATATYPE_1 *)malloc(sizeof(PRINTPROCDATATYPE_1))) == NULL)
4025 return ERROR_NOT_ENOUGH_MEMORY;
4029 init_unistr(&(info_1->name), "RAW");
4031 *needed += spoolss_size_printprocdatatype_info_1(info_1);
4033 if (!alloc_buffer_size(buffer, *needed))
4034 return ERROR_INSUFFICIENT_BUFFER;
4036 smb_io_printprocdatatype_info_1("", buffer, info_1, 0);
4040 if (*needed > offered) {
4042 return ERROR_INSUFFICIENT_BUFFER;
4045 return NT_STATUS_NO_PROBLEMO;
4048 /****************************************************************************
4049 ****************************************************************************/
4050 uint32 _spoolss_enumprintprocdatatypes(UNISTR2 *name, UNISTR2 *processor, uint32 level,
4051 NEW_BUFFER *buffer, uint32 offered,
4052 uint32 *needed, uint32 *returned)
4054 DEBUG(5,("_spoolss_enumprintprocdatatypes\n"));
4061 return enumprintprocdatatypes_level_1(buffer, offered, needed, returned);
4064 return ERROR_INVALID_LEVEL;
4069 /****************************************************************************
4070 enumprintmonitors level 1.
4071 ****************************************************************************/
4072 static uint32 enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4074 PRINTMONITOR_1 *info_1=NULL;
4076 if((info_1 = (PRINTMONITOR_1 *)malloc(sizeof(PRINTMONITOR_1))) == NULL)
4077 return ERROR_NOT_ENOUGH_MEMORY;
4081 init_unistr(&(info_1->name), "Local Port");
4083 *needed += spoolss_size_printmonitor_info_1(info_1);
4085 if (!alloc_buffer_size(buffer, *needed))
4086 return ERROR_INSUFFICIENT_BUFFER;
4088 smb_io_printmonitor_info_1("", buffer, info_1, 0);
4092 if (*needed > offered) {
4094 return ERROR_INSUFFICIENT_BUFFER;
4097 return NT_STATUS_NO_PROBLEMO;
4100 /****************************************************************************
4101 enumprintmonitors level 2.
4102 ****************************************************************************/
4103 static uint32 enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4105 PRINTMONITOR_2 *info_2=NULL;
4107 if((info_2 = (PRINTMONITOR_2 *)malloc(sizeof(PRINTMONITOR_2))) == NULL)
4108 return ERROR_NOT_ENOUGH_MEMORY;
4112 init_unistr(&(info_2->name), "Local Port");
4113 init_unistr(&(info_2->environment), "Windows NT X86");
4114 init_unistr(&(info_2->dll_name), "localmon.dll");
4116 *needed += spoolss_size_printmonitor_info_2(info_2);
4118 if (!alloc_buffer_size(buffer, *needed))
4119 return ERROR_INSUFFICIENT_BUFFER;
4121 smb_io_printmonitor_info_2("", buffer, info_2, 0);
4125 if (*needed > offered) {
4127 return ERROR_INSUFFICIENT_BUFFER;
4130 return NT_STATUS_NO_PROBLEMO;
4133 /****************************************************************************
4134 ****************************************************************************/
4135 uint32 _spoolss_enumprintmonitors(UNISTR2 *name,uint32 level,
4136 NEW_BUFFER *buffer, uint32 offered,
4137 uint32 *needed, uint32 *returned)
4139 DEBUG(5,("spoolss_enumprintmonitors\n"));
4142 * Enumerate the print monitors ...
4144 * Just reply with "Local Port", to keep NT happy
4145 * and I can use my nice printer checker.
4153 return enumprintmonitors_level_1(buffer, offered, needed, returned);
4156 return enumprintmonitors_level_2(buffer, offered, needed, returned);
4159 return ERROR_INVALID_LEVEL;
4164 /****************************************************************************
4165 ****************************************************************************/
4166 static uint32 getjob_level_1(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
4170 JOB_INFO_1 *info_1=NULL;
4172 info_1=(JOB_INFO_1 *)malloc(sizeof(JOB_INFO_1));
4174 if (info_1 == NULL) {
4176 return ERROR_NOT_ENOUGH_MEMORY;
4179 for (i=0; i<count && found==False; i++) {
4180 if (queue[i].job==(int)jobid)
4187 /* I shoud reply something else ... I can't find the good one */
4188 return NT_STATUS_NO_PROBLEMO;
4191 fill_job_info_1(info_1, &(queue[i-1]), i, snum);
4195 *needed += spoolss_size_job_info_1(info_1);
4197 if (!alloc_buffer_size(buffer, *needed)) {
4199 return ERROR_INSUFFICIENT_BUFFER;
4202 new_smb_io_job_info_1("", buffer, info_1, 0);
4206 if (*needed > offered)
4207 return ERROR_INSUFFICIENT_BUFFER;
4209 return NT_STATUS_NO_PROBLEMO;
4213 /****************************************************************************
4214 ****************************************************************************/
4215 static uint32 getjob_level_2(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
4219 JOB_INFO_2 *info_2=NULL;
4220 info_2=(JOB_INFO_2 *)malloc(sizeof(JOB_INFO_2));
4222 if (info_2 == NULL) {
4224 return ERROR_NOT_ENOUGH_MEMORY;
4227 for (i=0; i<count && found==False; i++) {
4228 if (queue[i].job==(int)jobid)
4235 /* I shoud reply something else ... I can't find the good one */
4236 return NT_STATUS_NO_PROBLEMO;
4239 fill_job_info_2(info_2, &(queue[i-1]), i, snum);
4243 *needed += spoolss_size_job_info_2(info_2);
4245 if (!alloc_buffer_size(buffer, *needed)) {
4247 return ERROR_INSUFFICIENT_BUFFER;
4250 new_smb_io_job_info_2("", buffer, info_2, 0);
4254 if (*needed > offered)
4255 return ERROR_INSUFFICIENT_BUFFER;
4257 return NT_STATUS_NO_PROBLEMO;
4260 /****************************************************************************
4261 ****************************************************************************/
4262 uint32 _spoolss_getjob( POLICY_HND *handle, uint32 jobid, uint32 level,
4263 NEW_BUFFER *buffer, uint32 offered,
4268 print_queue_struct *queue=NULL;
4269 print_status_struct prt_status;
4271 DEBUG(5,("spoolss_getjob\n"));
4273 memset(&prt_status, 0, sizeof(prt_status));
4277 if (!get_printer_snum(handle, &snum))
4278 return ERROR_INVALID_HANDLE;
4280 count = print_queue_status(snum, &queue, &prt_status);
4282 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
4283 count, prt_status.status, prt_status.message));
4287 return getjob_level_1(queue, count, snum, jobid, buffer, offered, needed);
4290 return getjob_level_2(queue, count, snum, jobid, buffer, offered, needed);
4294 return ERROR_INVALID_LEVEL;