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;
51 uint32 document_lastwritten;
52 pstring document_name;
54 POLICY_HND printer_hnd;
58 fstring printerservername;
67 SPOOL_NOTIFY_OPTION *option;
75 typedef struct _counter_printer_0 {
83 static ubi_dlList Printer_list;
84 static ubi_dlList counter_list;
87 #define OPEN_HANDLE(pnum) ((pnum!=NULL) && (pnum->open!=False))
89 /****************************************************************************
90 initialise printer handle states...
91 ****************************************************************************/
92 void init_printer_hnd(void)
94 ubi_dlInitList(&Printer_list);
95 ubi_dlInitList(&counter_list);
98 /****************************************************************************
99 create a unique printer handle
100 ****************************************************************************/
101 static void create_printer_hnd(POLICY_HND *hnd)
103 static uint32 prt_hnd_low = 0;
104 static uint32 prt_hnd_high = 0;
106 if (hnd == NULL) return;
108 /* i severely doubt that prt_hnd_high will ever be non-zero... */
110 if (prt_hnd_low == 0) prt_hnd_high++;
112 SIVAL(hnd->data, 0 , 0x0); /* first bit must be null */
113 SIVAL(hnd->data, 4 , prt_hnd_low ); /* second bit is incrementing */
114 SIVAL(hnd->data, 8 , prt_hnd_high); /* second bit is incrementing */
115 SIVAL(hnd->data, 12, time(NULL)); /* something random */
116 SIVAL(hnd->data, 16, getpid()); /* something more random */
119 /****************************************************************************
120 find printer index by handle
121 ****************************************************************************/
122 static Printer_entry *find_printer_index_by_hnd(const POLICY_HND *hnd)
124 Printer_entry *find_printer;
126 find_printer = (Printer_entry *)ubi_dlFirst(&Printer_list);
128 for(; find_printer; find_printer = (Printer_entry *)ubi_dlNext(find_printer)) {
130 if (memcmp(&(find_printer->printer_hnd), hnd, sizeof(*hnd)) == 0)
132 DEBUG(4,("Found printer handle \n"));
133 /*dump_data(4, hnd->data, sizeof(hnd->data));*/
138 DEBUG(3,("Whoops, Printer handle not found: "));
139 /*dump_data(4, hnd->data, sizeof(hnd->data));*/
143 /****************************************************************************
145 ****************************************************************************/
146 static void clear_handle(POLICY_HND *hnd)
148 memset(hnd->data, 0, POLICY_HND_SIZE);
151 /****************************************************************************
152 close printer index by handle
153 ****************************************************************************/
154 static BOOL close_printer_handle(POLICY_HND *hnd)
156 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
158 if (!OPEN_HANDLE(Printer))
160 DEBUG(3,("Error closing printer handle\n"));
165 Printer->notify.flags=0;
166 Printer->notify.options=0;
167 Printer->notify.localmachine[0]='\0';
168 Printer->notify.printerlocal=0;
169 safe_free(Printer->notify.option);
170 Printer->notify.option=NULL;
174 ubi_dlRemThis(&Printer_list, Printer);
181 /****************************************************************************
182 return the snum of a printer corresponding to an handle
183 ****************************************************************************/
184 static BOOL get_printer_snum(const POLICY_HND *hnd, int *number)
187 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
188 int n_services=lp_numservices();
190 if (!OPEN_HANDLE(Printer)) {
191 DEBUG(3,("Error getting printer - take a nap quickly !\n"));
195 switch (Printer->printer_type) {
196 case PRINTER_HANDLE_IS_PRINTER:
197 DEBUG(4,("short name:%s\n", Printer->dev.printername));
198 for (snum=0;snum<n_services; snum++) {
199 if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
200 DEBUG(4,("share:%s\n",lp_servicename(snum)));
201 if ( ( strlen(lp_servicename(snum)) == strlen( Printer->dev.printername ) )
202 && ( !strncasecmp(lp_servicename(snum),
203 Printer->dev.printername,
204 strlen( lp_servicename(snum) ))) ) {
205 DEBUG(4,("Printer found: %s[%x]\n",lp_servicename(snum),snum));
214 case PRINTER_HANDLE_IS_PRINTSERVER:
223 /****************************************************************************
224 find first available printer slot. creates a printer handle for you.
225 ****************************************************************************/
226 static BOOL open_printer_hnd(POLICY_HND *hnd)
228 Printer_entry *new_printer;
230 new_printer=(Printer_entry *)malloc(sizeof(Printer_entry));
231 ZERO_STRUCTP(new_printer);
233 new_printer->open = True;
234 new_printer->notify.option=NULL;
236 memcpy(&(new_printer->printer_hnd), hnd, sizeof(*hnd));
238 ubi_dlAddHead( &Printer_list, (ubi_dlNode *)new_printer);
243 /****************************************************************************
244 set printer handle type.
245 ****************************************************************************/
246 static BOOL set_printer_hnd_accesstype(POLICY_HND *hnd, uint32 access_required)
248 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
250 if (!OPEN_HANDLE(Printer)) {
251 DEBUG(4,("Error setting printer type=%x", access_required));
255 DEBUG(4,("Setting printer access=%x\n", access_required));
256 Printer->access = access_required;
260 /****************************************************************************
261 set printer handle type.
262 check if it's \\server or \\server\printer
263 ****************************************************************************/
264 static BOOL set_printer_hnd_printertype(POLICY_HND *hnd, char *printername)
266 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
268 if (!OPEN_HANDLE(Printer)) {
269 DEBUGADD(4,("Error setting printer name %s", printername));
273 DEBUG(3,("Setting printer type=%s\n", printername));
275 if ( strlen(printername) < 3 ) {
276 DEBUGADD(4,("A print server must have at least 1 char ! %s\n", printername));
280 /* it's a print server */
281 if (!strchr(printername+2, '\\')) {
282 DEBUGADD(4,("Printer is a print server\n"));
283 Printer->printer_type = PRINTER_HANDLE_IS_PRINTSERVER;
288 DEBUGADD(4,("Printer is a printer\n"));
289 Printer->printer_type = PRINTER_HANDLE_IS_PRINTER;
296 /****************************************************************************
297 set printer handle printername.
298 ****************************************************************************/
299 static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername)
301 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
302 NT_PRINTER_INFO_LEVEL printer;
304 int n_services=lp_numservices();
308 if (!OPEN_HANDLE(Printer))
310 DEBUG(0,("Error setting printer name=%s\n", printername));
314 DEBUG(4,("Setting printer name=%s (len=%d)\n", printername, strlen(printername)));
316 if (Printer->printer_type==PRINTER_HANDLE_IS_PRINTSERVER) {
317 ZERO_STRUCT(Printer->dev.printerservername);
318 strncpy(Printer->dev.printerservername, printername, strlen(printername));
322 if (Printer->printer_type!=PRINTER_HANDLE_IS_PRINTER)
325 aprinter=strchr(printername+2, '\\');
328 DEBUGADD(5,("searching for [%s] (len=%d)\n", aprinter, strlen(aprinter)));
330 * store the Samba share name in it
331 * in back we have the long printer name
332 * need to iterate all the snum and do a
333 * get_a_printer each time to find the printer
334 * faster to do it here than later.
337 for (snum=0;snum<n_services && found==False;snum++) {
339 if ( !(lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) )
342 DEBUGADD(5,("share:%s\n",lp_servicename(snum)));
344 if (get_a_printer(&printer, 2, lp_servicename(snum))!=0)
347 if ( strlen(printer.info_2->printername) != strlen(aprinter) ) {
348 free_a_printer(printer, 2);
352 if ( strncasecmp(printer.info_2->printername, aprinter, strlen(aprinter))) {
353 free_a_printer(printer, 2);
362 DEBUGADD(4,("Printer not found\n"));
367 DEBUGADD(4,("Printer found: %s[%x]\n",lp_servicename(snum),snum));
368 ZERO_STRUCT(Printer->dev.printername);
369 strncpy(Printer->dev.printername, lp_servicename(snum), strlen(lp_servicename(snum)));
370 free_a_printer(printer, 2);
375 /********************************************************************
376 Return True is the handle is a print server.
377 ********************************************************************/
378 static BOOL handle_is_printserver(const POLICY_HND *handle)
380 Printer_entry *Printer=find_printer_index_by_hnd(handle);
382 if (!OPEN_HANDLE(Printer))
385 if (Printer->printer_type != PRINTER_HANDLE_IS_PRINTSERVER)
391 /****************************************************************************
392 allocate more memory for a BUFFER.
393 ****************************************************************************/
394 static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size)
402 /* damn, I'm doing the reverse operation of prs_grow() :) */
403 if (buffer_size < prs_data_size(ps))
406 extra_space = buffer_size - prs_data_size(ps);
409 * save the offset and move to the end of the buffer
410 * prs_grow() checks the extra_space against the offset
412 old_offset=prs_offset(ps);
413 prs_set_offset(ps, prs_data_size(ps));
415 if (!prs_grow(ps, extra_space))
418 prs_set_offset(ps, old_offset);
420 buffer->string_at_end=prs_data_size(ps);
425 /********************************************************************
426 * spoolss_open_printer
428 * called from the spoolss dispatcher
429 ********************************************************************/
430 uint32 _spoolss_open_printer_ex( const UNISTR2 *printername,
431 const PRINTER_DEFAULT *printer_default,
432 uint32 user_switch, SPOOL_USER_CTR user_ctr,
437 clear_handle(handle);
439 if (printername == NULL)
440 return NT_STATUS_ACCESS_DENIED;
442 /* some sanity check because you can open a printer or a print server */
443 /* aka: \\server\printer or \\server */
444 unistr2_to_ascii(name, printername, sizeof(name)-1);
446 DEBUGADD(3,("checking name: %s\n",name));
448 create_printer_hnd(handle);
450 open_printer_hnd(handle);
452 if (!set_printer_hnd_printertype(handle, name)) {
453 close_printer_handle(handle);
454 return NT_STATUS_ACCESS_DENIED;
457 if (!set_printer_hnd_printername(handle, name)) {
458 close_printer_handle(handle);
459 return NT_STATUS_ACCESS_DENIED;
463 if (printer_default->datatype_ptr != NULL)
465 unistr2_to_ascii(datatype, printer_default->datatype, sizeof(datatype)-1);
466 set_printer_hnd_datatype(handle, datatype);
469 set_printer_hnd_datatype(handle, "");
472 if (!set_printer_hnd_accesstype(handle, printer_default->access_required)) {
473 close_printer_handle(handle);
474 return NT_STATUS_ACCESS_DENIED;
477 return NT_STATUS_NO_PROBLEMO;
480 /****************************************************************************
481 ****************************************************************************/
482 static BOOL convert_printer_info(const SPOOL_PRINTER_INFO_LEVEL *uni,
483 NT_PRINTER_INFO_LEVEL *printer, uint32 level)
487 uni_2_asc_printer_info_2(uni->info_2, &(printer->info_2));
496 static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL *uni,
497 NT_PRINTER_DRIVER_INFO_LEVEL *printer, uint32 level)
501 printer->info_3=NULL;
502 uni_2_asc_printer_driver_3(uni->info_3, &(printer->info_3));
511 static BOOL convert_devicemode(DEVICEMODE devmode, NT_DEVICEMODE *nt_devmode)
513 unistr_to_ascii(nt_devmode->devicename, devmode.devicename.buffer, 31);
514 unistr_to_ascii(nt_devmode->formname, devmode.formname.buffer, 31);
516 nt_devmode->specversion=devmode.specversion;
517 nt_devmode->driverversion=devmode.driverversion;
518 nt_devmode->size=devmode.size;
519 nt_devmode->driverextra=devmode.driverextra;
520 nt_devmode->fields=devmode.fields;
521 nt_devmode->orientation=devmode.orientation;
522 nt_devmode->papersize=devmode.papersize;
523 nt_devmode->paperlength=devmode.paperlength;
524 nt_devmode->paperwidth=devmode.paperwidth;
525 nt_devmode->scale=devmode.scale;
526 nt_devmode->copies=devmode.copies;
527 nt_devmode->defaultsource=devmode.defaultsource;
528 nt_devmode->printquality=devmode.printquality;
529 nt_devmode->color=devmode.color;
530 nt_devmode->duplex=devmode.duplex;
531 nt_devmode->yresolution=devmode.yresolution;
532 nt_devmode->ttoption=devmode.ttoption;
533 nt_devmode->collate=devmode.collate;
535 nt_devmode->logpixels=devmode.logpixels;
536 nt_devmode->bitsperpel=devmode.bitsperpel;
537 nt_devmode->pelswidth=devmode.pelswidth;
538 nt_devmode->pelsheight=devmode.pelsheight;
539 nt_devmode->displayflags=devmode.displayflags;
540 nt_devmode->displayfrequency=devmode.displayfrequency;
541 nt_devmode->icmmethod=devmode.icmmethod;
542 nt_devmode->icmintent=devmode.icmintent;
543 nt_devmode->mediatype=devmode.mediatype;
544 nt_devmode->dithertype=devmode.dithertype;
545 nt_devmode->reserved1=devmode.reserved1;
546 nt_devmode->reserved2=devmode.reserved2;
547 nt_devmode->panningwidth=devmode.panningwidth;
548 nt_devmode->panningheight=devmode.panningheight;
550 if (nt_devmode->driverextra != 0)
552 /* if we had a previous private delete it and make a new one */
553 if (nt_devmode->private != NULL)
554 free(nt_devmode->private);
555 nt_devmode->private=(uint8 *)malloc(nt_devmode->driverextra * sizeof(uint8));
556 memcpy(nt_devmode->private, devmode.private, nt_devmode->driverextra);
562 /********************************************************************
563 * api_spoolss_closeprinter
564 ********************************************************************/
565 uint32 _spoolss_closeprinter(POLICY_HND *handle)
567 if (!close_printer_handle(handle))
568 return NT_STATUS_INVALID_HANDLE;
570 return NT_STATUS_NO_PROBLEMO;
573 /********************************************************************
574 GetPrinterData on a printer server Handle.
575 ********************************************************************/
576 static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **data, uint32 *needed, uint32 in_size)
580 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
582 if (!strcmp(value, "BeepEnabled"))
585 *data = (uint8 *)malloc( 4*sizeof(uint8) );
586 SIVAL(*data, 0, 0x01);
591 if (!strcmp(value, "EventLog"))
594 *data = (uint8 *)malloc( 4*sizeof(uint8) );
595 SIVAL(*data, 0, 0x1B);
600 if (!strcmp(value, "NetPopup"))
603 *data = (uint8 *)malloc( 4*sizeof(uint8) );
604 SIVAL(*data, 0, 0x01);
609 if (!strcmp(value, "MajorVersion"))
612 *data = (uint8 *)malloc( 4*sizeof(uint8) );
613 SIVAL(*data, 0, 0x02);
618 if (!strcmp(value, "DefaultSpoolDirectory"))
620 pstring string="You are using a Samba server";
622 *needed = 2*(strlen(string)+1);
623 *data = (uint8 *)malloc( ((*needed > in_size) ? *needed:in_size) *sizeof(uint8));
624 memset(*data, 0, (*needed > in_size) ? *needed:in_size);
626 /* it's done by hand ready to go on the wire */
627 for (i=0; i<strlen(string); i++)
629 (*data)[2*i]=string[i];
635 if (!strcmp(value, "Architecture"))
637 pstring string="Windows NT x86";
639 *needed = 2*(strlen(string)+1);
640 *data = (uint8 *)malloc( ((*needed > in_size) ? *needed:in_size) *sizeof(uint8));
641 memset(*data, 0, (*needed > in_size) ? *needed:in_size);
642 for (i=0; i<strlen(string); i++)
644 (*data)[2*i]=string[i];
653 /********************************************************************
654 GetPrinterData on a printer Handle.
655 ********************************************************************/
656 static BOOL getprinterdata_printer(const POLICY_HND *handle,
657 fstring value, uint32 *type,
658 uint8 **data, uint32 *needed, uint32 in_size )
660 NT_PRINTER_INFO_LEVEL printer;
664 Printer_entry *Printer = find_printer_index_by_hnd(handle);
666 DEBUG(5,("getprinterdata_printer\n"));
668 if (OPEN_HANDLE(Printer))
670 get_printer_snum(handle, &snum);
671 get_a_printer(&printer, 2, lp_servicename(snum));
673 if (get_specific_param(printer, 2, value, &idata, type, &len))
675 *data = (uint8 *)malloc( (len>in_size)?len:in_size *sizeof(uint8) );
676 memset(*data, 0, sizeof(uint8)*len);
677 memcpy(*data, idata, (len>in_size)?len:in_size);
680 if (idata) free(idata);
683 free_a_printer(printer, 2);
689 /********************************************************************
690 * spoolss_getprinterdata
691 ********************************************************************/
692 uint32 _spoolss_getprinterdata(const POLICY_HND *handle, UNISTR2 *valuename,
701 Printer_entry *Printer = find_printer_index_by_hnd(handle);
704 * Reminder: when it's a string, the length is in BYTES
705 * even if UNICODE is negociated.
712 /* in case of problem, return some default values */
716 DEBUG(4,("_spoolss_getprinterdata\n"));
718 if (!OPEN_HANDLE(Printer)) {
719 *data=(uint8 *)malloc(4*sizeof(uint8));
720 return NT_STATUS_INVALID_HANDLE;
723 unistr2_to_ascii(value, valuename, sizeof(value)-1);
725 if (handle_is_printserver(handle))
726 found=getprinterdata_printer_server(value, type, data, needed, *out_size);
728 found=getprinterdata_printer(handle, value, type, data, needed, *out_size);
731 /* reply this param doesn't exist */
732 *data=(uint8 *)malloc(4*sizeof(uint8));
733 memset(*data, 0x0, 4);
734 return ERROR_INVALID_PARAMETER;
737 if (*needed > *out_size)
738 return ERROR_INSUFFICIENT_BUFFER;
740 return NT_STATUS_NO_PROBLEMO;
743 /********************************************************************
745 * ReplyFindFirstPrinterChangeNotifyEx
747 * jfmxxxx: before replying OK: status=0
748 * should do a rpc call to the workstation asking ReplyOpenPrinter
749 * have to code it, later.
751 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
752 * called from api_spoolss_rffpcnex
753 ********************************************************************/
754 uint32 _spoolss_rffpcnex(const POLICY_HND *handle, uint32 flags, uint32 options,
755 const UNISTR2 *localmachine, uint32 printerlocal,
756 SPOOL_NOTIFY_OPTION *option)
758 /* store the notify value in the printer struct */
760 Printer_entry *Printer=find_printer_index_by_hnd(handle);
762 if (!OPEN_HANDLE(Printer))
763 return NT_STATUS_INVALID_HANDLE;
765 Printer->notify.flags=flags;
766 Printer->notify.options=options;
767 Printer->notify.printerlocal=printerlocal;
768 Printer->notify.option=option;
769 unistr2_to_ascii(Printer->notify.localmachine, localmachine, sizeof(Printer->notify.localmachine)-1);
771 return NT_STATUS_NO_PROBLEMO;
774 /*******************************************************************
775 * fill a notify_info_data with the servername
776 ********************************************************************/
777 static void spoolss_notify_server_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
781 snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname);
783 data->notify_data.data.length=strlen(temp_name);
784 ascii_to_unistr(data->notify_data.data.string, temp_name, sizeof(data->notify_data.data.string)-1);
787 /*******************************************************************
788 * fill a notify_info_data with the servicename
789 * jfmxxxx: it's incorrect should be long_printername
790 ********************************************************************/
791 static void spoolss_notify_printer_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
794 data->notify_data.data.length=strlen(lp_servicename(snum));
795 ascii_to_unistr(data->notify_data.data.string, lp_servicename(snum), sizeof(data->notify_data.data.string)-1);
797 data->notify_data.data.length=strlen(printer->info_2->printername);
798 ascii_to_unistr(data->notify_data.data.string,
799 printer->info_2->printername,
800 sizeof(data->notify_data.data.string)-1);
803 /*******************************************************************
804 * fill a notify_info_data with the servicename
805 ********************************************************************/
806 static void spoolss_notify_share_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
808 data->notify_data.data.length=strlen(lp_servicename(snum));
809 ascii_to_unistr(data->notify_data.data.string,
810 lp_servicename(snum),
811 sizeof(data->notify_data.data.string)-1);
814 /*******************************************************************
815 * fill a notify_info_data with the port name
816 ********************************************************************/
817 static void spoolss_notify_port_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
819 /* even if it's strange, that's consistant in all the code */
821 data->notify_data.data.length=strlen(lp_servicename(snum));
822 ascii_to_unistr(data->notify_data.data.string,
823 lp_servicename(snum),
824 sizeof(data->notify_data.data.string)-1);
827 /*******************************************************************
828 * fill a notify_info_data with the printername
829 * jfmxxxx: it's incorrect, should be lp_printerdrivername()
830 * but it doesn't exist, have to see what to do
831 ********************************************************************/
832 static void spoolss_notify_driver_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
834 data->notify_data.data.length=strlen(printer->info_2->drivername);
835 ascii_to_unistr(data->notify_data.data.string,
836 printer->info_2->drivername,
837 sizeof(data->notify_data.data.string)-1);
840 /*******************************************************************
841 * fill a notify_info_data with the comment
842 ********************************************************************/
843 static void spoolss_notify_comment(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
845 data->notify_data.data.length=strlen(lp_comment(snum));
846 ascii_to_unistr(data->notify_data.data.string,
848 sizeof(data->notify_data.data.string)-1);
851 /*******************************************************************
852 * fill a notify_info_data with the comment
853 * jfm:xxxx incorrect, have to create a new smb.conf option
854 * location = "Room 1, floor 2, building 3"
855 ********************************************************************/
856 static void spoolss_notify_location(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
858 data->notify_data.data.length=strlen(printer->info_2->location);
859 ascii_to_unistr(data->notify_data.data.string,
860 printer->info_2->location,
861 sizeof(data->notify_data.data.string)-1);
864 /*******************************************************************
865 * fill a notify_info_data with the device mode
866 * jfm:xxxx don't to it for know but that's a real problem !!!
867 ********************************************************************/
868 static void spoolss_notify_devmode(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
872 /*******************************************************************
873 * fill a notify_info_data with the separator file name
874 * jfm:xxxx just return no file could add an option to smb.conf
875 * separator file = "separator.txt"
876 ********************************************************************/
877 static void spoolss_notify_sepfile(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
879 data->notify_data.data.length=strlen(printer->info_2->sepfile);
880 ascii_to_unistr(data->notify_data.data.string,
881 printer->info_2->sepfile,
882 sizeof(data->notify_data.data.string)-1);
885 /*******************************************************************
886 * fill a notify_info_data with the print processor
887 * jfm:xxxx return always winprint to indicate we don't do anything to it
888 ********************************************************************/
889 static void spoolss_notify_print_processor(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
891 data->notify_data.data.length=strlen(printer->info_2->printprocessor);
892 ascii_to_unistr(data->notify_data.data.string,
893 printer->info_2->printprocessor,
894 sizeof(data->notify_data.data.string)-1);
897 /*******************************************************************
898 * fill a notify_info_data with the print processor options
899 * jfm:xxxx send an empty string
900 ********************************************************************/
901 static void spoolss_notify_parameters(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
903 data->notify_data.data.length=strlen(printer->info_2->parameters);
904 ascii_to_unistr(data->notify_data.data.string,
905 printer->info_2->parameters,
906 sizeof(data->notify_data.data.string)-1);
909 /*******************************************************************
910 * fill a notify_info_data with the data type
911 * jfm:xxxx always send RAW as data type
912 ********************************************************************/
913 static void spoolss_notify_datatype(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
915 data->notify_data.data.length=strlen(printer->info_2->datatype);
916 ascii_to_unistr(data->notify_data.data.string,
917 printer->info_2->datatype,
918 sizeof(data->notify_data.data.string)-1);
921 /*******************************************************************
922 * fill a notify_info_data with the security descriptor
923 * jfm:xxxx send an null pointer to say no security desc
924 * have to implement security before !
925 ********************************************************************/
926 static void spoolss_notify_security_desc(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
928 data->notify_data.data.length=0;
929 data->notify_data.data.string[0]=0x00;
932 /*******************************************************************
933 * fill a notify_info_data with the attributes
934 * jfm:xxxx a samba printer is always shared
935 ********************************************************************/
936 static void spoolss_notify_attributes(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
938 data->notify_data.value[0] = PRINTER_ATTRIBUTE_SHARED \
939 | PRINTER_ATTRIBUTE_NETWORK \
940 | PRINTER_ATTRIBUTE_RAW_ONLY ;
943 /*******************************************************************
944 * fill a notify_info_data with the priority
945 ********************************************************************/
946 static void spoolss_notify_priority(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
948 data->notify_data.value[0] = printer->info_2->priority;
951 /*******************************************************************
952 * fill a notify_info_data with the default priority
953 ********************************************************************/
954 static void spoolss_notify_default_priority(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
956 data->notify_data.value[0] = printer->info_2->default_priority;
959 /*******************************************************************
960 * fill a notify_info_data with the start time
961 ********************************************************************/
962 static void spoolss_notify_start_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
964 data->notify_data.value[0] = printer->info_2->starttime;
967 /*******************************************************************
968 * fill a notify_info_data with the until time
969 ********************************************************************/
970 static void spoolss_notify_until_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
972 data->notify_data.value[0] = printer->info_2->untiltime;
975 /*******************************************************************
976 * fill a notify_info_data with the status
977 ********************************************************************/
978 static void spoolss_notify_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
981 print_queue_struct *q=NULL;
982 print_status_struct status;
984 memset(&status, 0, sizeof(status));
985 count=get_printqueue(snum, NULL, &q, &status);
986 data->notify_data.value[0]=(uint32) status.status;
990 /*******************************************************************
991 * fill a notify_info_data with the number of jobs queued
992 ********************************************************************/
993 static void spoolss_notify_cjobs(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
995 print_queue_struct *q=NULL;
996 print_status_struct status;
998 memset(&status, 0, sizeof(status));
999 data->notify_data.value[0]=get_printqueue(snum, NULL, &q, &status);
1003 /*******************************************************************
1004 * fill a notify_info_data with the average ppm
1005 ********************************************************************/
1006 static void spoolss_notify_average_ppm(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1008 /* always respond 8 pages per minutes */
1009 /* a little hard ! */
1010 data->notify_data.value[0] = printer->info_2->averageppm;
1013 /*******************************************************************
1014 * fill a notify_info_data with
1015 ********************************************************************/
1016 static void spoolss_notify_username(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1018 data->notify_data.data.length=strlen(queue->user);
1019 ascii_to_unistr(data->notify_data.data.string, queue->user, sizeof(data->notify_data.data.string)-1);
1022 /*******************************************************************
1023 * fill a notify_info_data with
1024 ********************************************************************/
1025 static void spoolss_notify_job_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1027 data->notify_data.value[0]=queue->status;
1030 /*******************************************************************
1031 * fill a notify_info_data with
1032 ********************************************************************/
1033 static void spoolss_notify_job_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1035 data->notify_data.data.length=strlen(queue->file);
1036 ascii_to_unistr(data->notify_data.data.string, queue->file, sizeof(data->notify_data.data.string)-1);
1039 /*******************************************************************
1040 * fill a notify_info_data with
1041 ********************************************************************/
1042 static void spoolss_notify_job_status_string(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1044 data->notify_data.data.length=strlen("En attente");
1045 ascii_to_unistr(data->notify_data.data.string, "En attente", sizeof(data->notify_data.data.string)-1);
1048 /*******************************************************************
1049 * fill a notify_info_data with
1050 ********************************************************************/
1051 static void spoolss_notify_job_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1053 data->notify_data.value[0]=0x0;
1056 /*******************************************************************
1057 * fill a notify_info_data with
1058 ********************************************************************/
1059 static void spoolss_notify_job_size(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1061 data->notify_data.value[0]=queue->size;
1064 /*******************************************************************
1065 * fill a notify_info_data with
1066 ********************************************************************/
1067 static void spoolss_notify_job_position(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1069 data->notify_data.value[0]=queue->job;
1074 struct s_notify_info_data_table notify_info_data_table[] =
1076 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SERVER_NAME, "PRINTER_NOTIFY_SERVER_NAME", POINTER, spoolss_notify_server_name },
1077 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINTER_NAME, "PRINTER_NOTIFY_PRINTER_NAME", POINTER, spoolss_notify_printer_name },
1078 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SHARE_NAME, "PRINTER_NOTIFY_SHARE_NAME", POINTER, spoolss_notify_share_name },
1079 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PORT_NAME, "PRINTER_NOTIFY_PORT_NAME", POINTER, spoolss_notify_port_name },
1080 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DRIVER_NAME, "PRINTER_NOTIFY_DRIVER_NAME", POINTER, spoolss_notify_driver_name },
1081 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_COMMENT, "PRINTER_NOTIFY_COMMENT", POINTER, spoolss_notify_comment },
1082 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_LOCATION, "PRINTER_NOTIFY_LOCATION", POINTER, spoolss_notify_location },
1083 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DEVMODE, "PRINTER_NOTIFY_DEVMODE", POINTER, spoolss_notify_devmode },
1084 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SEPFILE, "PRINTER_NOTIFY_SEPFILE", POINTER, spoolss_notify_sepfile },
1085 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINT_PROCESSOR, "PRINTER_NOTIFY_PRINT_PROCESSOR", POINTER, spoolss_notify_print_processor },
1086 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PARAMETERS, "PRINTER_NOTIFY_PARAMETERS", POINTER, spoolss_notify_parameters },
1087 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DATATYPE, "PRINTER_NOTIFY_DATATYPE", POINTER, spoolss_notify_datatype },
1088 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_SECURITY_DESCRIPTOR", POINTER, spoolss_notify_security_desc },
1089 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_ATTRIBUTES, "PRINTER_NOTIFY_ATTRIBUTES", ONE_VALUE, spoolss_notify_attributes },
1090 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRIORITY, "PRINTER_NOTIFY_PRIORITY", ONE_VALUE, spoolss_notify_priority },
1091 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DEFAULT_PRIORITY, "PRINTER_NOTIFY_DEFAULT_PRIORITY", ONE_VALUE, spoolss_notify_default_priority },
1092 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_START_TIME, "PRINTER_NOTIFY_START_TIME", ONE_VALUE, spoolss_notify_start_time },
1093 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_UNTIL_TIME, "PRINTER_NOTIFY_UNTIL_TIME", ONE_VALUE, spoolss_notify_until_time },
1094 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_STATUS, "PRINTER_NOTIFY_STATUS", ONE_VALUE, spoolss_notify_status },
1095 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_STATUS_STRING, "PRINTER_NOTIFY_STATUS_STRING", POINTER, NULL },
1096 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_CJOBS, "PRINTER_NOTIFY_CJOBS", ONE_VALUE, spoolss_notify_cjobs },
1097 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_AVERAGE_PPM, "PRINTER_NOTIFY_AVERAGE_PPM", ONE_VALUE, spoolss_notify_average_ppm },
1098 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_PAGES, "PRINTER_NOTIFY_TOTAL_PAGES", POINTER, NULL },
1099 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PAGES_PRINTED, "PRINTER_NOTIFY_PAGES_PRINTED", POINTER, NULL },
1100 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_BYTES, "PRINTER_NOTIFY_TOTAL_BYTES", POINTER, NULL },
1101 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_BYTES_PRINTED, "PRINTER_NOTIFY_BYTES_PRINTED", POINTER, NULL },
1102 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINTER_NAME, "JOB_NOTIFY_PRINTER_NAME", POINTER, spoolss_notify_printer_name },
1103 { JOB_NOTIFY_TYPE, JOB_NOTIFY_MACHINE_NAME, "JOB_NOTIFY_MACHINE_NAME", POINTER, spoolss_notify_server_name },
1104 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PORT_NAME, "JOB_NOTIFY_PORT_NAME", POINTER, spoolss_notify_port_name },
1105 { JOB_NOTIFY_TYPE, JOB_NOTIFY_USER_NAME, "JOB_NOTIFY_USER_NAME", POINTER, spoolss_notify_username },
1106 { JOB_NOTIFY_TYPE, JOB_NOTIFY_NOTIFY_NAME, "JOB_NOTIFY_NOTIFY_NAME", POINTER, spoolss_notify_username },
1107 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DATATYPE, "JOB_NOTIFY_DATATYPE", POINTER, spoolss_notify_datatype },
1108 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINT_PROCESSOR, "JOB_NOTIFY_PRINT_PROCESSOR", POINTER, spoolss_notify_print_processor },
1109 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PARAMETERS, "JOB_NOTIFY_PARAMETERS", POINTER, spoolss_notify_parameters },
1110 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DRIVER_NAME, "JOB_NOTIFY_DRIVER_NAME", POINTER, spoolss_notify_driver_name },
1111 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DEVMODE, "JOB_NOTIFY_DEVMODE", POINTER, spoolss_notify_devmode },
1112 { JOB_NOTIFY_TYPE, JOB_NOTIFY_STATUS, "JOB_NOTIFY_STATUS", ONE_VALUE, spoolss_notify_job_status },
1113 { JOB_NOTIFY_TYPE, JOB_NOTIFY_STATUS_STRING, "JOB_NOTIFY_STATUS_STRING", POINTER, spoolss_notify_job_status_string },
1114 { JOB_NOTIFY_TYPE, JOB_NOTIFY_SECURITY_DESCRIPTOR, "JOB_NOTIFY_SECURITY_DESCRIPTOR", POINTER, NULL },
1115 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DOCUMENT, "JOB_NOTIFY_DOCUMENT", POINTER, spoolss_notify_job_name },
1116 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRIORITY, "JOB_NOTIFY_PRIORITY", ONE_VALUE, spoolss_notify_priority },
1117 { JOB_NOTIFY_TYPE, JOB_NOTIFY_POSITION, "JOB_NOTIFY_POSITION", ONE_VALUE, spoolss_notify_job_position },
1118 { JOB_NOTIFY_TYPE, JOB_NOTIFY_SUBMITTED, "JOB_NOTIFY_SUBMITTED", POINTER, NULL },
1119 { JOB_NOTIFY_TYPE, JOB_NOTIFY_START_TIME, "JOB_NOTIFY_START_TIME", ONE_VALUE, spoolss_notify_start_time },
1120 { JOB_NOTIFY_TYPE, JOB_NOTIFY_UNTIL_TIME, "JOB_NOTIFY_UNTIL_TIME", ONE_VALUE, spoolss_notify_until_time },
1121 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TIME, "JOB_NOTIFY_TIME", ONE_VALUE, spoolss_notify_job_time },
1122 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_PAGES, "JOB_NOTIFY_TOTAL_PAGES", ONE_VALUE, NULL },
1123 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PAGES_PRINTED, "JOB_NOTIFY_PAGES_PRINTED", ONE_VALUE, NULL },
1124 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_BYTES, "JOB_NOTIFY_TOTAL_BYTES", ONE_VALUE, spoolss_notify_job_size },
1125 { JOB_NOTIFY_TYPE, JOB_NOTIFY_BYTES_PRINTED, "JOB_NOTIFY_BYTES_PRINTED", ONE_VALUE, NULL },
1126 { END, END, "", END, NULL }
1129 /*******************************************************************
1130 return the size of info_data structure
1131 ********************************************************************/
1132 static uint32 size_of_notify_info_data(uint16 type, uint16 field)
1136 while (notify_info_data_table[i].type != END)
1138 if ( (notify_info_data_table[i].type == type ) &&
1139 (notify_info_data_table[i].field == field ) )
1141 return (notify_info_data_table[i].size);
1149 /*******************************************************************
1150 return the type of notify_info_data
1151 ********************************************************************/
1152 static BOOL type_of_notify_info_data(uint16 type, uint16 field)
1156 while (notify_info_data_table[i].type != END)
1158 if ( (notify_info_data_table[i].type == type ) &&
1159 (notify_info_data_table[i].field == field ) )
1161 if (notify_info_data_table[i].size == POINTER)
1176 /****************************************************************************
1177 ****************************************************************************/
1178 static int search_notify(uint16 type, uint16 field, int *value)
1183 for (j=0, found=False; found==False && notify_info_data_table[j].type != END ; j++)
1185 if ( (notify_info_data_table[j].type == type ) &&
1186 (notify_info_data_table[j].field == field ) )
1191 if ( found && (notify_info_data_table[j].fn != NULL) )
1197 /****************************************************************************
1198 ****************************************************************************/
1199 static void construct_info_data(SPOOL_NOTIFY_INFO_DATA *info_data, uint16 type, uint16 field, int id)
1201 info_data->type = type;
1202 info_data->field = field;
1203 info_data->reserved = 0;
1205 info_data->size = size_of_notify_info_data(type, field);
1206 info_data->enc_type = type_of_notify_info_data(type, field);
1210 /*******************************************************************
1212 * fill a notify_info struct with info asked
1214 ********************************************************************/
1215 static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPOOL_NOTIFY_OPTION_TYPE *option_type, uint32 id)
1221 SPOOL_NOTIFY_INFO_DATA *current_data;
1222 NT_PRINTER_INFO_LEVEL printer;
1223 print_queue_struct *queue=NULL;
1225 DEBUG(4,("construct_notify_printer_info\n"));
1227 type=option_type->type;
1229 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
1230 (option_type->type==PRINTER_NOTIFY_TYPE?"PRINTER_NOTIFY_TYPE":"JOB_NOTIFY_TYPE"),
1231 option_type->count, lp_servicename(snum)));
1233 if (get_a_printer(&printer, 2, lp_servicename(snum))!=0)
1238 for(field_num=0; field_num<option_type->count; field_num++)
1240 field = option_type->fields[field_num];
1241 DEBUGADD(4,("notify [%d]: type [%x], field [%x]\n", field_num, type, field));
1243 if (!search_notify(type, field, &j) )
1246 info->data=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA));
1247 current_data=&(info->data[info->count]);
1249 construct_info_data(current_data, type, field, id);
1250 notify_info_data_table[j].fn(snum, current_data, queue, &printer);
1255 free_a_printer(printer, 2);
1259 /*******************************************************************
1261 * fill a notify_info struct with info asked
1263 ********************************************************************/
1264 static BOOL construct_notify_jobs_info(print_queue_struct *queue, 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;
1273 DEBUG(4,("construct_notify_jobs_info\n"));
1275 type = option_type->type;
1277 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
1278 (option_type->type==PRINTER_NOTIFY_TYPE?"PRINTER_NOTIFY_TYPE":"JOB_NOTIFY_TYPE"),
1279 option_type->count));
1281 if (get_a_printer(&printer, 2, lp_servicename(snum))!=0)
1286 for(field_num=0; field_num<option_type->count; field_num++)
1288 field = option_type->fields[field_num];
1290 if (!search_notify(type, field, &j) )
1293 info->data=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA));
1294 current_data=&(info->data[info->count]);
1296 construct_info_data(current_data, type, field, id);
1297 notify_info_data_table[j].fn(snum, current_data, queue, &printer);
1301 free_a_printer(printer, 2);
1307 * JFM: The enumeration is not that simple, it's even non obvious.
1309 * let's take an example: I want to monitor the PRINTER SERVER for
1310 * the printer's name and the number of jobs currently queued.
1311 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
1312 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
1314 * I have 3 printers on the back of my server.
1316 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
1319 * 1 printer 1 name 1
1320 * 2 printer 1 cjob 1
1321 * 3 printer 2 name 2
1322 * 4 printer 2 cjob 2
1323 * 5 printer 3 name 3
1324 * 6 printer 3 name 3
1326 * that's the print server case, the printer case is even worse.
1331 /*******************************************************************
1333 * enumerate all printers on the printserver
1334 * fill a notify_info struct with info asked
1336 ********************************************************************/
1337 static uint32 printserver_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info)
1340 Printer_entry *Printer=find_printer_index_by_hnd(hnd);
1341 int n_services=lp_numservices();
1344 SPOOL_NOTIFY_OPTION *option;
1345 SPOOL_NOTIFY_OPTION_TYPE *option_type;
1347 DEBUG(4,("printserver_notify_info\n"));
1349 option=Printer->notify.option;
1355 for (i=0; i<option->count; i++)
1357 option_type=&(option->ctr.type[i]);
1359 if (option_type->type!=PRINTER_NOTIFY_TYPE)
1362 for (snum=0; snum<n_services; snum++)
1363 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
1364 if (construct_notify_printer_info(info, snum, option_type, id))
1369 * Debugging information, don't delete.
1372 DEBUG(1,("dumping the NOTIFY_INFO\n"));
1373 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
1374 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
1376 for (i=0; i<info->count; i++)
1378 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
1379 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
1380 info->data[i].id, info->data[i].size, info->data[i].enc_type));
1384 return NT_STATUS_NO_PROBLEMO;
1387 /*******************************************************************
1389 * fill a notify_info struct with info asked
1391 ********************************************************************/
1392 static uint32 printer_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info)
1395 Printer_entry *Printer=find_printer_index_by_hnd(hnd);
1398 SPOOL_NOTIFY_OPTION *option;
1399 SPOOL_NOTIFY_OPTION_TYPE *option_type;
1401 print_queue_struct *queue=NULL;
1402 print_status_struct status;
1404 DEBUG(4,("printer_notify_info\n"));
1406 option=Printer->notify.option;
1412 get_printer_snum(hnd, &snum);
1414 for (i=0; i<option->count; i++)
1416 option_type=&(option->ctr.type[i]);
1418 switch ( option_type->type ) {
1419 case PRINTER_NOTIFY_TYPE:
1420 if(construct_notify_printer_info(info, snum, option_type, id))
1424 case JOB_NOTIFY_TYPE:
1425 memset(&status, 0, sizeof(status));
1426 count=get_printqueue(snum, NULL, &queue, &status);
1427 for (j=0; j<count; j++)
1428 if (construct_notify_jobs_info(&(queue[j]), info, snum, option_type, id))
1436 * Debugging information, don't delete.
1439 DEBUG(1,("dumping the NOTIFY_INFO\n"));
1440 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
1441 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
1443 for (i=0; i<info->count; i++)
1445 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
1446 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
1447 info->data[i].id, info->data[i].size, info->data[i].enc_type));
1450 return NT_STATUS_NO_PROBLEMO;
1453 /********************************************************************
1455 ********************************************************************/
1456 uint32 _spoolss_rfnpcnex( const POLICY_HND *handle, uint32 change,
1457 SPOOL_NOTIFY_OPTION *option, SPOOL_NOTIFY_INFO *info)
1459 Printer_entry *Printer=find_printer_index_by_hnd(handle);
1461 if (!OPEN_HANDLE(Printer))
1462 return NT_STATUS_INVALID_HANDLE;
1464 DEBUG(4,("Printer type %x\n",Printer->printer_type));
1466 /* jfm: the change value isn't used right now.
1467 * we will honour it when
1468 * a) we'll be able to send notification to the client
1469 * b) we'll have a way to communicate between the spoolss process.
1471 * same thing for option->flags
1472 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
1473 * I don't have a global notification system, I'm sending back all the
1474 * informations even when _NOTHING_ has changed.
1477 /* just discard the SPOOL_NOTIFY_OPTION */
1479 safe_free(option->ctr.type);
1483 switch (Printer->printer_type) {
1484 case PRINTER_HANDLE_IS_PRINTSERVER:
1485 return printserver_notify_info(handle, info);
1487 case PRINTER_HANDLE_IS_PRINTER:
1488 return printer_notify_info(handle, info);
1492 return NT_STATUS_INVALID_INFO_CLASS;
1495 /********************************************************************
1496 * construct_printer_info_0
1497 * fill a printer_info_1 struct
1498 ********************************************************************/
1499 static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, pstring servername)
1503 NT_PRINTER_INFO_LEVEL ntprinter;
1504 counter_printer_0 *session_counter;
1505 uint32 global_counter;
1508 print_queue_struct *queue=NULL;
1509 print_status_struct status;
1511 memset(&status, 0, sizeof(status));
1513 if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) != 0)
1516 count=get_printqueue(snum, NULL, &queue, &status);
1518 /* check if we already have a counter for this printer */
1519 session_counter = (counter_printer_0 *)ubi_dlFirst(&counter_list);
1521 for(; session_counter; session_counter = (counter_printer_0 *)ubi_dlNext(session_counter)) {
1522 if (session_counter->snum == snum)
1526 /* it's the first time, add it to the list */
1527 if (session_counter==NULL) {
1528 session_counter=(counter_printer_0 *)malloc(sizeof(counter_printer_0));
1529 ZERO_STRUCTP(session_counter);
1530 session_counter->snum=snum;
1531 session_counter->counter=0;
1532 ubi_dlAddHead( &counter_list, (ubi_dlNode *)session_counter);
1536 session_counter->counter++;
1539 * the global_counter should be stored in a TDB as it's common to all the clients
1540 * and should be zeroed on samba startup
1542 global_counter=session_counter->counter;
1544 /* the description and the name are of the form \\server\share */
1545 slprintf(chaine,sizeof(chaine)-1,"\\\\%s\\%s",servername, ntprinter.info_2->printername);
1547 init_unistr(&(printer->printername), chaine);
1549 slprintf(chaine,sizeof(chaine)-1,"\\\\%s", servername);
1550 init_unistr(&(printer->servername), chaine);
1552 printer->cjobs = count;
1553 printer->total_jobs = 0;
1554 printer->total_bytes = 0;
1556 t=gmtime(&ntprinter.info_2->setuptime);
1558 printer->year = t->tm_year+1900;
1559 printer->month = t->tm_mon+1;
1560 printer->dayofweek = t->tm_wday;
1561 printer->day = t->tm_mday;
1562 printer->hour = t->tm_hour;
1563 printer->minute = t->tm_min;
1564 printer->second = t->tm_sec;
1565 printer->milliseconds = 0;
1567 printer->global_counter = global_counter;
1568 printer->total_pages = 0;
1569 printer->major_version = 0x0004; /* NT 4 */
1570 printer->build_version = 0x0565; /* build 1381 */
1571 printer->unknown7 = 0x1;
1572 printer->unknown8 = 0x0;
1573 printer->unknown9 = 0x2;
1574 printer->session_counter = session_counter->counter;
1575 printer->unknown11 = 0x0;
1576 printer->printer_errors = 0x0; /* number of print failure */
1577 printer->unknown13 = 0x0;
1578 printer->unknown14 = 0x1;
1579 printer->unknown15 = 0x024a; /* 586 Pentium ? */
1580 printer->unknown16 = 0x0;
1581 printer->change_id = ntprinter.info_2->changeid; /* ChangeID in milliseconds*/
1582 printer->unknown18 = 0x0;
1583 printer->status = status.status;
1584 printer->unknown20 = 0x0;
1585 printer->c_setprinter = ntprinter.info_2->c_setprinter; /* how many times setprinter has been called */
1586 printer->unknown22 = 0x0;
1587 printer->unknown23 = 0x6; /* 6 ???*/
1588 printer->unknown24 = 0; /* unknown 24 to 26 are always 0 */
1589 printer->unknown25 = 0;
1590 printer->unknown26 = 0;
1591 printer->unknown27 = 0;
1592 printer->unknown28 = 0;
1593 printer->unknown29 = 0;
1597 free_a_printer(ntprinter, 2);
1601 /********************************************************************
1602 * construct_printer_info_1
1603 * fill a printer_info_1 struct
1604 ********************************************************************/
1605 static BOOL construct_printer_info_1(fstring server, uint32 flags, PRINTER_INFO_1 *printer, int snum)
1609 NT_PRINTER_INFO_LEVEL ntprinter;
1611 if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) != 0)
1614 printer->flags=flags;
1616 snprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",server, ntprinter.info_2->printername,
1617 ntprinter.info_2->drivername, lp_comment(snum));
1619 snprintf(chaine2,sizeof(chaine)-1,"%s%s", server, ntprinter.info_2->printername);
1621 init_unistr(&printer->description, chaine);
1622 init_unistr(&printer->name, chaine2);
1623 init_unistr(&printer->comment, lp_comment(snum));
1625 free_a_printer(ntprinter, 2);
1630 /****************************************************************************
1631 ****************************************************************************/
1632 static void construct_dev_mode(DEVICEMODE *devmode, int snum, char *servername)
1636 NT_PRINTER_INFO_LEVEL printer;
1637 NT_DEVICEMODE *ntdevmode;
1639 DEBUG(7,("construct_dev_mode\n"));
1641 memset(&(devmode->devicename), 0, 2*sizeof(adevice));
1642 memset(&(devmode->formname), 0, 2*sizeof(aform));
1644 DEBUGADD(8,("getting printer characteristics\n"));
1646 get_a_printer(&printer, 2, lp_servicename(snum));
1647 ntdevmode=(printer.info_2)->devmode;
1649 DEBUGADD(8,("loading DEVICEMODE\n"));
1650 snprintf(adevice, sizeof(adevice), "\\\\%s\\%s", global_myname,
1651 printer.info_2->printername);
1652 init_unistr(&(devmode->devicename), adevice);
1654 snprintf(aform, sizeof(aform), ntdevmode->formname);
1655 init_unistr(&(devmode->formname), aform);
1657 devmode->specversion = ntdevmode->specversion;
1658 devmode->driverversion = ntdevmode->driverversion;
1659 devmode->size = ntdevmode->size;
1660 devmode->driverextra = ntdevmode->driverextra;
1661 devmode->fields = ntdevmode->fields;
1663 devmode->orientation = ntdevmode->orientation;
1664 devmode->papersize = ntdevmode->papersize;
1665 devmode->paperlength = ntdevmode->paperlength;
1666 devmode->paperwidth = ntdevmode->paperwidth;
1667 devmode->scale = ntdevmode->scale;
1668 devmode->copies = ntdevmode->copies;
1669 devmode->defaultsource = ntdevmode->defaultsource;
1670 devmode->printquality = ntdevmode->printquality;
1671 devmode->color = ntdevmode->color;
1672 devmode->duplex = ntdevmode->duplex;
1673 devmode->yresolution = ntdevmode->yresolution;
1674 devmode->ttoption = ntdevmode->ttoption;
1675 devmode->collate = ntdevmode->collate;
1676 devmode->icmmethod = ntdevmode->icmmethod;
1677 devmode->icmintent = ntdevmode->icmintent;
1678 devmode->mediatype = ntdevmode->mediatype;
1679 devmode->dithertype = ntdevmode->dithertype;
1681 if (ntdevmode->private != NULL)
1683 devmode->private=(uint8 *)malloc(devmode->driverextra*sizeof(uint8));
1684 memcpy(devmode->private, ntdevmode->private, devmode->driverextra);
1687 free_a_printer(printer, 2);
1690 /********************************************************************
1691 * construct_printer_info_2
1692 * fill a printer_info_2 struct
1693 ********************************************************************/
1694 static BOOL construct_printer_info_2(pstring servername, PRINTER_INFO_2 *printer, int snum)
1700 DEVICEMODE *devmode;
1701 NT_PRINTER_INFO_LEVEL ntprinter;
1703 print_queue_struct *queue=NULL;
1704 print_status_struct status;
1705 memset(&status, 0, sizeof(status));
1707 if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0 )
1710 memset(&status, 0, sizeof(status));
1711 count=get_printqueue(snum, NULL, &queue, &status);
1713 snprintf(chaine, sizeof(chaine)-1, "%s", servername);
1715 if (strlen(servername)!=0)
1720 snprintf(chaine2, sizeof(chaine)-1, "%s%s%s", servername, sl, ntprinter.info_2->printername);
1722 init_unistr(&printer->servername, chaine); /* servername*/
1723 init_unistr(&printer->printername, chaine2); /* printername*/
1724 init_unistr(&printer->sharename, lp_servicename(snum)); /* sharename */
1725 init_unistr(&printer->portname, lp_servicename(snum)); /* port */
1726 init_unistr(&printer->drivername, ntprinter.info_2->drivername); /* drivername */
1727 init_unistr(&printer->comment, lp_comment(snum)); /* comment */
1728 init_unistr(&printer->location, ntprinter.info_2->location); /* location */
1729 init_unistr(&printer->sepfile, ntprinter.info_2->sepfile); /* separator file */
1730 init_unistr(&printer->printprocessor, ntprinter.info_2->printprocessor);/* print processor */
1731 init_unistr(&printer->datatype, ntprinter.info_2->datatype); /* datatype */
1732 init_unistr(&printer->parameters, ntprinter.info_2->parameters); /* parameters (of print processor) */
1734 printer->attributes = PRINTER_ATTRIBUTE_SHARED \
1735 | PRINTER_ATTRIBUTE_LOCAL \
1736 | PRINTER_ATTRIBUTE_RAW_ONLY ; /* attributes */
1738 printer->priority = ntprinter.info_2->priority; /* priority */
1739 printer->defaultpriority = ntprinter.info_2->default_priority; /* default priority */
1740 printer->starttime = ntprinter.info_2->starttime; /* starttime */
1741 printer->untiltime = ntprinter.info_2->untiltime; /* untiltime */
1742 printer->status = status.status; /* status */
1743 printer->cjobs = count; /* jobs */
1744 printer->averageppm = ntprinter.info_2->averageppm; /* average pages per minute */
1746 devmode=(DEVICEMODE *)malloc(sizeof(DEVICEMODE));
1747 ZERO_STRUCTP(devmode);
1748 construct_dev_mode(devmode, snum, servername);
1749 printer->devmode=devmode;
1752 free_a_printer(ntprinter, 2);
1756 /********************************************************************
1757 Spoolss_enumprinters.
1758 ********************************************************************/
1759 static BOOL enum_all_printers_info_1(fstring server, uint32 flags, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
1763 int n_services=lp_numservices();
1764 PRINTER_INFO_1 *printers=NULL;
1765 PRINTER_INFO_1 current_prt;
1767 DEBUG(4,("enum_all_printers_info_1\n"));
1769 for (snum=0; snum<n_services; snum++) {
1770 if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
1771 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum));
1773 if (construct_printer_info_1(server, flags, ¤t_prt, snum)) {
1774 printers=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_1));
1775 DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_1\n", *returned));
1776 memcpy(&(printers[*returned]), ¤t_prt, sizeof(PRINTER_INFO_1));
1782 /* check the required size. */
1783 for (i=0; i<*returned; i++)
1784 (*needed) += spoolss_size_printer_info_1(&(printers[i]));
1786 if (!alloc_buffer_size(buffer, *needed))
1787 return ERROR_INSUFFICIENT_BUFFER;
1789 /* fill the buffer with the structures */
1790 for (i=0; i<*returned; i++)
1791 new_smb_io_printer_info_1("", buffer, &(printers[i]), 0);
1794 safe_free(printers);
1796 if (*needed > offered) {
1798 return ERROR_INSUFFICIENT_BUFFER;
1801 return NT_STATUS_NO_PROBLEMO;
1804 /********************************************************************
1805 enum_all_printers_info_1_local.
1806 *********************************************************************/
1807 static BOOL enum_all_printers_info_1_local(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
1810 DEBUG(4,("enum_all_printers_info_1_local\n"));
1812 fstrcpy(temp, "\\\\");
1813 fstrcat(temp, global_myname);
1815 if (!strcmp(name, temp)) {
1816 fstrcat(temp, "\\");
1817 return enum_all_printers_info_1(temp, PRINTER_ENUM_ICON8, buffer, offered, needed, returned);
1820 return enum_all_printers_info_1("", PRINTER_ENUM_ICON8, buffer, offered, needed, returned);
1823 /********************************************************************
1824 enum_all_printers_info_1_name.
1825 *********************************************************************/
1826 static BOOL enum_all_printers_info_1_name(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
1829 DEBUG(4,("enum_all_printers_info_1_name\n"));
1831 fstrcpy(temp, "\\\\");
1832 fstrcat(temp, global_myname);
1834 if (!strcmp(name, temp)) {
1835 fstrcat(temp, "\\");
1836 return enum_all_printers_info_1(temp, PRINTER_ENUM_ICON8, buffer, offered, needed, returned);
1839 return ERROR_INVALID_NAME;
1842 /********************************************************************
1843 enum_all_printers_info_1_remote.
1844 *********************************************************************/
1845 static BOOL enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
1847 PRINTER_INFO_1 *printer;
1848 fstring printername;
1851 DEBUG(4,("enum_all_printers_info_1_remote\n"));
1853 /* JFM: currently it's more a place holder than anything else.
1854 * In the spooler world there is a notion of server registration.
1855 * the print servers are registring (sp ?) on the PDC (in the same domain)
1857 * We should have a TDB here. The registration is done thru an undocumented RPC call.
1860 printer=(PRINTER_INFO_1 *)malloc(sizeof(PRINTER_INFO_1));
1864 snprintf(printername, sizeof(printername)-1,"Windows NT Remote Printers!!\\\\%s", global_myname);
1865 snprintf(desc, sizeof(desc)-1,"%s", global_myname);
1866 snprintf(comment, sizeof(comment)-1, "Logged on Domain");
1868 init_unistr(&printer->description, desc);
1869 init_unistr(&printer->name, printername);
1870 init_unistr(&printer->comment, comment);
1871 printer->flags=PRINTER_ENUM_ICON3|PRINTER_ENUM_CONTAINER;
1873 /* check the required size. */
1874 *needed += spoolss_size_printer_info_1(printer);
1876 if (!alloc_buffer_size(buffer, *needed)) {
1878 return ERROR_INSUFFICIENT_BUFFER;
1881 /* fill the buffer with the structures */
1882 new_smb_io_printer_info_1("", buffer, printer, 0);
1887 if (*needed > offered) {
1889 return ERROR_INSUFFICIENT_BUFFER;
1892 return NT_STATUS_NO_PROBLEMO;
1895 /********************************************************************
1896 enum_all_printers_info_1_network.
1897 *********************************************************************/
1898 static BOOL enum_all_printers_info_1_network(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
1901 DEBUG(4,("enum_all_printers_info_1_network\n"));
1903 fstrcpy(temp, "\\\\");
1904 fstrcat(temp, global_myname);
1905 fstrcat(temp, "\\");
1906 return enum_all_printers_info_1(temp, PRINTER_ENUM_UNKNOWN_8, buffer, offered, needed, returned);
1909 /********************************************************************
1910 * api_spoolss_enumprinters
1912 * called from api_spoolss_enumprinters (see this to understand)
1913 ********************************************************************/
1914 static BOOL enum_all_printers_info_2(fstring servername, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
1918 int n_services=lp_numservices();
1919 PRINTER_INFO_2 *printers=NULL;
1920 PRINTER_INFO_2 current_prt;
1922 for (snum=0; snum<n_services; snum++) {
1923 if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
1924 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum));
1926 if (construct_printer_info_2(servername, ¤t_prt, snum)) {
1927 printers=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_2));
1928 DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_2\n", *returned));
1929 memcpy(&(printers[*returned]), ¤t_prt, sizeof(PRINTER_INFO_2));
1935 /* check the required size. */
1936 for (i=0; i<*returned; i++)
1937 (*needed) += spoolss_size_printer_info_2(&(printers[i]));
1939 if (!alloc_buffer_size(buffer, *needed))
1940 return ERROR_INSUFFICIENT_BUFFER;
1942 /* fill the buffer with the structures */
1943 for (i=0; i<*returned; i++)
1944 new_smb_io_printer_info_2("", buffer, &(printers[i]), 0);
1947 safe_free(printers);
1949 if (*needed > offered) {
1951 return ERROR_INSUFFICIENT_BUFFER;
1954 return NT_STATUS_NO_PROBLEMO;
1957 /********************************************************************
1958 * handle enumeration of printers at level 1
1959 ********************************************************************/
1960 static uint32 enumprinters_level1( uint32 flags, fstring name,
1961 NEW_BUFFER *buffer, uint32 offered,
1962 uint32 *needed, uint32 *returned)
1964 /* Not all the flags are equals */
1966 if (flags & PRINTER_ENUM_LOCAL)
1967 return enum_all_printers_info_1_local(name, buffer, offered, needed, returned);
1969 if (flags & PRINTER_ENUM_NAME)
1970 return enum_all_printers_info_1_name(name, buffer, offered, needed, returned);
1972 if (flags & PRINTER_ENUM_REMOTE)
1973 return enum_all_printers_info_1_remote(name, buffer, offered, needed, returned);
1975 if (flags & PRINTER_ENUM_NETWORK)
1976 return enum_all_printers_info_1_network(name, buffer, offered, needed, returned);
1978 return NT_STATUS_NO_PROBLEMO; /* NT4sp5 does that */
1981 /********************************************************************
1982 * handle enumeration of printers at level 2
1983 ********************************************************************/
1984 static uint32 enumprinters_level2( uint32 flags, fstring servername,
1985 NEW_BUFFER *buffer, uint32 offered,
1986 uint32 *needed, uint32 *returned)
1990 fstrcpy(temp, "\\\\");
1991 fstrcat(temp, global_myname);
1993 if (flags & PRINTER_ENUM_LOCAL) {
1994 if (!strcmp(servername, temp)) {
1995 fstrcat(temp, "\\");
1996 return enum_all_printers_info_2(temp, buffer, offered, needed, returned);
1999 return enum_all_printers_info_2("", buffer, offered, needed, returned);
2002 if (flags & PRINTER_ENUM_NAME) {
2003 if (!strcmp(servername, temp)) {
2004 fstrcat(temp, "\\");
2005 return enum_all_printers_info_2(temp, buffer, offered, needed, returned);
2008 return ERROR_INVALID_NAME;
2011 if (flags & PRINTER_ENUM_REMOTE)
2012 return ERROR_INVALID_LEVEL;
2014 return NT_STATUS_NO_PROBLEMO;
2017 /********************************************************************
2018 * handle enumeration of printers at level 5
2019 ********************************************************************/
2020 static uint32 enumprinters_level5( uint32 flags, fstring servername,
2021 NEW_BUFFER *buffer, uint32 offered,
2022 uint32 *needed, uint32 *returned)
2024 /* return enum_all_printers_info_5(buffer, offered, needed, returned);*/
2025 return NT_STATUS_NO_PROBLEMO;
2028 /********************************************************************
2029 * api_spoolss_enumprinters
2031 * called from api_spoolss_enumprinters (see this to understand)
2032 ********************************************************************/
2033 uint32 _spoolss_enumprinters( uint32 flags, const UNISTR2 *servername, uint32 level,
2034 NEW_BUFFER *buffer, uint32 offered,
2035 uint32 *needed, uint32 *returned)
2039 DEBUG(4,("_spoolss_enumprinters\n"));
2046 * flags==PRINTER_ENUM_NAME
2047 * if name=="" then enumerates all printers
2048 * if name!="" then enumerate the printer
2049 * flags==PRINTER_ENUM_REMOTE
2050 * name is NULL, enumerate printers
2051 * Level 2: name!="" enumerates printers, name can't be NULL
2052 * Level 3: doesn't exist
2053 * Level 4: does a local registry lookup
2054 * Level 5: same as Level 2
2057 unistr2_to_ascii(name, servername, sizeof(name)-1);
2061 return enumprinters_level1(flags, name, buffer, offered, needed, returned);
2064 return enumprinters_level2(flags, name, buffer, offered, needed, returned);
2067 return enumprinters_level5(flags, name, buffer, offered, needed, returned);
2072 return NT_STATUS_INVALID_LEVEL;
2077 /****************************************************************************
2078 ****************************************************************************/
2079 static uint32 getprinter_level_0(pstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2081 PRINTER_INFO_0 *printer=NULL;
2083 printer=(PRINTER_INFO_0*)malloc(sizeof(PRINTER_INFO_0));
2085 construct_printer_info_0(printer, snum, servername);
2087 /* check the required size. */
2088 *needed += spoolss_size_printer_info_0(printer);
2090 if (!alloc_buffer_size(buffer, *needed)) {
2092 return ERROR_INSUFFICIENT_BUFFER;
2095 /* fill the buffer with the structures */
2096 new_smb_io_printer_info_0("", buffer, printer, 0);
2101 if (*needed > offered) {
2102 return ERROR_INSUFFICIENT_BUFFER;
2105 return NT_STATUS_NO_PROBLEMO;
2108 /****************************************************************************
2109 ****************************************************************************/
2110 static uint32 getprinter_level_1(pstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2112 PRINTER_INFO_1 *printer=NULL;
2114 printer=(PRINTER_INFO_1*)malloc(sizeof(PRINTER_INFO_1));
2115 construct_printer_info_1(servername, PRINTER_ENUM_ICON8, printer, snum);
2117 /* check the required size. */
2118 *needed += spoolss_size_printer_info_1(printer);
2120 if (!alloc_buffer_size(buffer, *needed)) {
2122 return ERROR_INSUFFICIENT_BUFFER;
2125 /* fill the buffer with the structures */
2126 new_smb_io_printer_info_1("", buffer, printer, 0);
2131 if (*needed > offered) {
2132 return ERROR_INSUFFICIENT_BUFFER;
2135 return NT_STATUS_NO_PROBLEMO;
2138 /****************************************************************************
2139 ****************************************************************************/
2140 static uint32 getprinter_level_2(pstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2142 PRINTER_INFO_2 *printer=NULL;
2145 printer=(PRINTER_INFO_2*)malloc(sizeof(PRINTER_INFO_2));
2147 fstrcpy(temp, "\\\\");
2148 fstrcat(temp, servername);
2149 construct_printer_info_2(temp, printer, snum);
2151 /* check the required size. */
2152 *needed += spoolss_size_printer_info_2(printer);
2154 if (!alloc_buffer_size(buffer, *needed)) {
2156 return ERROR_INSUFFICIENT_BUFFER;
2159 /* fill the buffer with the structures */
2160 new_smb_io_printer_info_2("", buffer, printer, 0);
2165 if (*needed > offered) {
2166 return ERROR_INSUFFICIENT_BUFFER;
2169 return NT_STATUS_NO_PROBLEMO;
2172 /****************************************************************************
2173 ****************************************************************************/
2174 uint32 _spoolss_getprinter(POLICY_HND *handle, uint32 level,
2175 NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2182 pstrcpy(servername, global_myname);
2184 if (!get_printer_snum(handle, &snum))
2185 return NT_STATUS_INVALID_HANDLE;
2189 return getprinter_level_0(servername, snum, buffer, offered, needed);
2192 return getprinter_level_1(servername,snum, buffer, offered, needed);
2195 return getprinter_level_2(servername,snum, buffer, offered, needed);
2198 return ERROR_INVALID_LEVEL;
2203 /********************************************************************
2204 * construct_printer_driver_info_1
2205 * fill a construct_printer_driver_info_1 struct
2206 ********************************************************************/
2207 static void fill_printer_driver_info_1(DRIVER_INFO_1 *info,
2208 NT_PRINTER_DRIVER_INFO_LEVEL driver,
2209 pstring servername, fstring architecture)
2211 init_unistr( &(info->name), driver.info_3->name);
2214 static void construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum,
2215 pstring servername, fstring architecture)
2217 NT_PRINTER_INFO_LEVEL printer;
2218 NT_PRINTER_DRIVER_INFO_LEVEL driver;
2220 get_a_printer(&printer, 2, lp_servicename(snum) );
2221 get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture);
2223 fill_printer_driver_info_1(info, driver, servername, architecture);
2225 free_a_printer_driver(driver, 3);
2226 free_a_printer(printer, 2);
2229 /********************************************************************
2230 * construct_printer_driver_info_2
2231 * fill a printer_info_2 struct
2232 ********************************************************************/
2233 static void fill_printer_driver_info_2(DRIVER_INFO_2 *info,
2234 NT_PRINTER_DRIVER_INFO_LEVEL driver,
2235 pstring servername, fstring architecture)
2238 pstring temp_driverpath;
2239 pstring temp_datafile;
2240 pstring temp_configfile;
2241 fstring short_archi;
2243 get_short_archi(short_archi,architecture);
2245 snprintf(where,sizeof(where)-1,"\\\\%s\\print$\\%s\\", servername, short_archi);
2247 info->version=driver.info_3->cversion;
2249 init_unistr( &(info->name), driver.info_3->name );
2250 init_unistr( &(info->architecture), architecture );
2252 snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "%s%s", where,
2253 driver.info_3->driverpath);
2254 init_unistr( &(info->driverpath), temp_driverpath );
2256 snprintf(temp_datafile, sizeof(temp_datafile)-1, "%s%s", where,
2257 driver.info_3->datafile);
2258 init_unistr( &(info->datafile), temp_datafile );
2260 snprintf(temp_configfile, sizeof(temp_configfile)-1, "%s%s", where,
2261 driver.info_3->configfile);
2262 init_unistr( &(info->configfile), temp_configfile );
2265 /********************************************************************
2266 * construct_printer_driver_info_2
2267 * fill a printer_info_2 struct
2268 ********************************************************************/
2269 static void construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum,
2270 pstring servername, fstring architecture)
2272 NT_PRINTER_INFO_LEVEL printer;
2273 NT_PRINTER_DRIVER_INFO_LEVEL driver;
2275 get_a_printer(&printer, 2, lp_servicename(snum) );
2276 get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture);
2278 fill_printer_driver_info_2(info, driver, servername, architecture);
2280 free_a_printer_driver(driver, 3);
2281 free_a_printer(printer, 2);
2284 /********************************************************************
2285 * copy a strings array and convert to UNICODE
2286 ********************************************************************/
2287 static void init_unistr_array(UNISTR ***uni_array, char **char_array, char *where)
2293 DEBUG(6,("init_unistr_array\n"));
2295 for (v=char_array[i]; *v!='\0'; v=char_array[i])
2297 DEBUGADD(6,("i:%d:", i));
2298 DEBUGADD(6,("%s:%d:", v, strlen(v)));
2300 *uni_array=(UNISTR **)Realloc(*uni_array, sizeof(UNISTR *)*(i+1));
2301 DEBUGADD(7,("realloc:[%p],", *uni_array));
2303 (*uni_array)[i]=(UNISTR *)malloc( sizeof(UNISTR) );
2304 DEBUGADD(7,("alloc:[%p],", (*uni_array)[i]));
2306 snprintf(line, sizeof(line)-1, "%s%s", where, v);
2307 init_unistr( (*uni_array)[i], line );
2308 DEBUGADD(7,("copy\n"));
2312 DEBUGADD(7,("last one\n"));
2314 *uni_array=(UNISTR **)Realloc(*uni_array, sizeof(UNISTR *)*(i+1));
2315 (*uni_array)[i]=0x0000;
2316 DEBUGADD(6,("last one:done\n"));
2319 /********************************************************************
2320 * construct_printer_info_3
2321 * fill a printer_info_3 struct
2322 ********************************************************************/
2323 static void fill_printer_driver_info_3(DRIVER_INFO_3 *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 pstring temp_helpfile;
2332 fstring short_archi;
2334 get_short_archi(short_archi, architecture);
2336 snprintf(where,sizeof(where)-1,"\\\\%s\\print$\\%s\\", servername, short_archi);
2338 info->version=driver.info_3->cversion;
2340 init_unistr( &(info->name), driver.info_3->name );
2341 init_unistr( &(info->architecture), architecture );
2343 snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "%s%s", where, driver.info_3->driverpath);
2344 init_unistr( &(info->driverpath), temp_driverpath );
2346 snprintf(temp_datafile, sizeof(temp_datafile)-1, "%s%s", where, driver.info_3->datafile);
2347 init_unistr( &(info->datafile), temp_datafile );
2349 snprintf(temp_configfile, sizeof(temp_configfile)-1, "%s%s", where, driver.info_3->configfile);
2350 init_unistr( &(info->configfile), temp_configfile );
2352 snprintf(temp_helpfile, sizeof(temp_helpfile)-1, "%s%s", where, driver.info_3->helpfile);
2353 init_unistr( &(info->helpfile), temp_helpfile );
2355 init_unistr( &(info->monitorname), driver.info_3->monitorname );
2356 init_unistr( &(info->defaultdatatype), driver.info_3->defaultdatatype );
2358 info->dependentfiles=NULL;
2359 init_unistr_array(&(info->dependentfiles), driver.info_3->dependentfiles, where);
2362 /********************************************************************
2363 * construct_printer_info_3
2364 * fill a printer_info_3 struct
2365 ********************************************************************/
2366 static void construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum,
2367 pstring servername, fstring architecture)
2369 NT_PRINTER_INFO_LEVEL printer;
2370 NT_PRINTER_DRIVER_INFO_LEVEL driver;
2372 get_a_printer(&printer, 2, lp_servicename(snum) );
2373 get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture);
2375 fill_printer_driver_info_3(info, driver, servername, architecture);
2377 free_a_printer_driver(driver, 3);
2378 free_a_printer(printer, 2);
2381 /****************************************************************************
2382 ****************************************************************************/
2383 static uint32 getprinterdriver2_level1(pstring servername, pstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2385 DRIVER_INFO_1 *info=NULL;
2387 info=(DRIVER_INFO_1 *)malloc(sizeof(DRIVER_INFO_1));
2389 construct_printer_driver_info_1(info, snum, servername, architecture);
2391 /* check the required size. */
2392 *needed += spoolss_size_printer_driver_info_1(info);
2394 if (!alloc_buffer_size(buffer, *needed))
2395 return ERROR_INSUFFICIENT_BUFFER;
2397 /* fill the buffer with the structures */
2398 new_smb_io_printer_driver_info_1("", buffer, info, 0);
2403 if (*needed > offered) {
2404 return ERROR_INSUFFICIENT_BUFFER;
2407 return NT_STATUS_NO_PROBLEMO;
2410 /****************************************************************************
2411 ****************************************************************************/
2412 static uint32 getprinterdriver2_level2(pstring servername, pstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2414 DRIVER_INFO_2 *info=NULL;
2416 info=(DRIVER_INFO_2 *)malloc(sizeof(DRIVER_INFO_2));
2418 construct_printer_driver_info_2(info, snum, servername, architecture);
2420 /* check the required size. */
2421 *needed += spoolss_size_printer_driver_info_2(info);
2423 if (!alloc_buffer_size(buffer, *needed))
2424 return ERROR_INSUFFICIENT_BUFFER;
2426 /* fill the buffer with the structures */
2427 new_smb_io_printer_driver_info_2("", buffer, info, 0);
2432 if (*needed > offered) {
2433 return ERROR_INSUFFICIENT_BUFFER;
2436 return NT_STATUS_NO_PROBLEMO;
2439 /****************************************************************************
2440 ****************************************************************************/
2441 static uint32 getprinterdriver2_level3(pstring servername, pstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2443 DRIVER_INFO_3 *info=NULL;
2445 info=(DRIVER_INFO_3 *)malloc(sizeof(DRIVER_INFO_3));
2447 construct_printer_driver_info_3(info, snum, servername, architecture);
2449 /* check the required size. */
2450 *needed += spoolss_size_printer_driver_info_3(info);
2452 if (!alloc_buffer_size(buffer, *needed))
2453 return ERROR_INSUFFICIENT_BUFFER;
2455 /* fill the buffer with the structures */
2456 new_smb_io_printer_driver_info_3("", buffer, info, 0);
2461 if (*needed > offered) {
2462 return ERROR_INSUFFICIENT_BUFFER;
2465 return NT_STATUS_NO_PROBLEMO;
2468 /****************************************************************************
2469 ****************************************************************************/
2470 uint32 _spoolss_getprinterdriver2(const POLICY_HND *handle, const UNISTR2 *uni_arch, uint32 level, uint32 unknown,
2471 NEW_BUFFER *buffer, uint32 offered,
2472 uint32 *needed, uint32 *unknown0, uint32 *unknown1)
2475 fstring architecture;
2478 DEBUG(4,("_spoolss_getprinterdriver2\n"));
2484 pstrcpy(servername, global_myname);
2485 unistr2_to_ascii(architecture, uni_arch, sizeof(architecture)-1);
2487 if (!get_printer_snum(handle, &snum))
2489 return NT_STATUS_INVALID_HANDLE;
2494 return getprinterdriver2_level1(servername, architecture, snum, buffer, offered, needed);
2497 return getprinterdriver2_level2(servername, architecture, snum, buffer, offered, needed);
2500 return getprinterdriver2_level3(servername, architecture, snum, buffer, offered, needed);
2503 return NT_STATUS_INVALID_LEVEL;
2508 /****************************************************************************
2509 ****************************************************************************/
2510 uint32 _spoolss_startpageprinter(const POLICY_HND *handle)
2512 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2514 if (OPEN_HANDLE(Printer))
2516 Printer->page_started=True;
2520 DEBUG(3,("Error in startpageprinter printer handle\n"));
2521 return NT_STATUS_INVALID_HANDLE;
2524 /****************************************************************************
2525 ****************************************************************************/
2526 uint32 _spoolss_endpageprinter(const POLICY_HND *handle)
2528 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2530 if (!OPEN_HANDLE(Printer))
2532 DEBUG(3,("Error in endpageprinter printer handle\n"));
2533 return NT_STATUS_INVALID_HANDLE;
2536 Printer->page_started=False;
2538 return NT_STATUS_NO_PROBLEMO;
2542 /********************************************************************
2543 * api_spoolss_getprinter
2544 * called from the spoolss dispatcher
2546 ********************************************************************/
2547 uint32 _spoolss_startdocprinter( const POLICY_HND *handle, uint32 level,
2548 DOC_INFO *docinfo, uint32 *jobid)
2550 DOC_INFO_1 *info_1 = &docinfo->doc_info_1;
2557 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2559 if (!OPEN_HANDLE(Printer))
2561 return NT_STATUS_INVALID_HANDLE;
2565 * a nice thing with NT is it doesn't listen to what you tell it.
2566 * when asked to send _only_ RAW datas, it tries to send datas
2569 * So I add checks like in NT Server ...
2571 * lkclXXXX jean-francois, i love this kind of thing. oh, well,
2572 * there's a bug in NT client-side code, so we'll fix it in the
2573 * server-side code. *nnnnnggggh!*
2576 if (info_1->p_datatype != 0)
2578 unistr2_to_ascii(datatype, &(info_1->docname), sizeof(datatype));
2579 if (strcmp(datatype, "RAW") != 0)
2582 return ERROR_INVALID_DATATYPE;
2586 /* get the share number of the printer */
2587 if (!get_printer_snum(handle, &snum))
2589 return NT_STATUS_INVALID_HANDLE;
2592 /* Create a temporary file in the printer spool directory
2596 slprintf(tempname,sizeof(tempname)-1, "%s/smb_print.XXXXXX",lp_pathname(snum));
2597 pstrcpy(fname, (char *)mktemp(tempname));
2599 fd=open(fname, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, S_IRUSR|S_IWUSR );
2600 DEBUG(4,("Temp spool file created: [%s]\n", fname));
2602 Printer->current_jobid=fd;
2603 pstrcpy(Printer->document_name, fname);
2605 unistr2_to_ascii(Printer->job_name, &info_1->docname, sizeof(Printer->job_name));
2607 Printer->document_fd=fd;
2608 Printer->document_started=True;
2609 (*jobid) = Printer->current_jobid;
2614 /********************************************************************
2615 * api_spoolss_getprinter
2616 * called from the spoolss dispatcher
2618 ********************************************************************/
2619 uint32 _spoolss_enddocprinter(const POLICY_HND *handle)
2627 Printer_entry *Printer=find_printer_index_by_hnd(handle);
2631 if (!OPEN_HANDLE(Printer))
2633 DEBUG(3,("Error in enddocprinter handle\n"));
2634 return NT_STATUS_INVALID_HANDLE;
2637 Printer->document_started=False;
2638 close(Printer->document_fd);
2639 DEBUG(4,("Temp spool file closed, printing now ...\n"));
2641 pstrcpy(filename1, Printer->document_name);
2642 pstrcpy(job_name, Printer->job_name);
2644 if (!get_printer_snum(handle,&snum))
2646 return NT_STATUS_INVALID_HANDLE;
2649 /* copy the command into the buffer for extensive meddling. */
2650 StrnCpy(syscmd, lp_printcommand(snum), sizeof(pstring) - 1);
2652 /* look for "%s" in the string. If there is no %s, we cannot print. */
2653 if (!strstr(syscmd, "%s") && !strstr(syscmd, "%f"))
2655 DEBUG(2,("WARNING! No placeholder for the filename in the print command for service %s!\n", SERVICE(snum)));
2658 if (strstr(syscmd,"%s"))
2660 pstrcpy(filename,filename1);
2661 pstring_sub(syscmd, "%s", filename);
2664 pstring_sub(syscmd, "%f", filename1);
2666 /* Does the service have a printername? If not, make a fake and empty
2667 * printer name. That way a %p is treated sanely if no printer
2668 * name was specified to replace it. This eventuality is logged.
2671 tstr = lp_printername(snum);
2672 if (tstr == NULL || tstr[0] == '\0')
2674 DEBUG(3,( "No printer name - using %s.\n", SERVICE(snum)));
2675 tstr = SERVICE(snum);
2678 pstring_sub(syscmd, "%p", tstr);
2680 /* If the lpr command support the 'Job' option replace here */
2681 pstring_sub(syscmd, "%j", job_name);
2683 if ( *syscmd != '\0')
2685 int ret = smbrun(syscmd, NULL, False);
2686 DEBUG(3,("Running the command `%s' gave %d\n", syscmd, ret));
2690 return NT_STATUS_ACCESS_DENIED;
2695 DEBUG(0,("Null print command?\n"));
2697 return NT_STATUS_ACCESS_DENIED;
2705 /****************************************************************************
2706 ****************************************************************************/
2707 uint32 _spoolss_writeprinter( const POLICY_HND *handle,
2709 const uint8 *buffer,
2710 uint32 *buffer_written)
2713 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2715 if (!OPEN_HANDLE(Printer))
2717 DEBUG(3,("Error in writeprinter handle\n"));
2718 return NT_STATUS_INVALID_HANDLE;
2721 fd = Printer->document_fd;
2722 (*buffer_written) = write(fd, buffer, buffer_size);
2723 Printer->document_lastwritten = (*buffer_written);
2728 /********************************************************************
2729 * api_spoolss_getprinter
2730 * called from the spoolss dispatcher
2732 ********************************************************************/
2733 static uint32 control_printer(const POLICY_HND *handle, uint32 command)
2736 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2738 if (!OPEN_HANDLE(Printer))
2739 return NT_STATUS_INVALID_HANDLE;
2741 if (!get_printer_snum(handle, &snum) )
2742 return NT_STATUS_INVALID_HANDLE;
2745 case PRINTER_CONTROL_PAUSE:
2746 /* pause the printer here */
2747 status_printqueue(NULL, snum, LPSTAT_STOPPED);
2750 case PRINTER_CONTROL_RESUME:
2751 case PRINTER_CONTROL_UNPAUSE:
2752 /* UN-pause the printer here */
2753 status_printqueue(NULL, snum, LPSTAT_OK);
2756 case PRINTER_CONTROL_PURGE:
2758 * It's not handled by samba
2759 * we need a smb.conf param to do
2760 * lprm -P%p - on BSD
2761 * lprm -P%p all on LPRNG
2762 * I don't know on SysV
2763 * we could do it by looping in the job's list...
2768 return NT_STATUS_INVALID_INFO_CLASS;
2771 /********************************************************************
2772 * called by spoolss_api_setprinter
2773 * when updating a printer description
2774 ********************************************************************/
2775 static uint32 update_printer(const POLICY_HND *handle, uint32 level,
2776 const SPOOL_PRINTER_INFO_LEVEL *info,
2777 const DEVICEMODE *devmode)
2780 NT_PRINTER_INFO_LEVEL printer;
2781 NT_DEVICEMODE *nt_devmode;
2782 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2786 DEBUG(8,("update_printer\n"));
2789 DEBUG(0,("Send a mail to jfm@samba.org\n"));
2790 DEBUGADD(0,("with the following message: update_printer: level!=2\n"));
2791 return NT_STATUS_INVALID_INFO_CLASS;
2794 if (!OPEN_HANDLE(Printer))
2795 return NT_STATUS_INVALID_HANDLE;
2797 if (!get_printer_snum(handle, &snum) )
2798 return NT_STATUS_INVALID_HANDLE;
2800 get_a_printer(&printer, 2, lp_servicename(snum));
2802 DEBUGADD(8,("Converting info_2 struct\n"));
2803 convert_printer_info(info, &printer, level);
2805 if ((info->info_2)->devmode_ptr != 0) {
2806 /* we have a valid devmode
2807 convert it and link it*/
2809 /* the nt_devmode memory is already alloced
2810 * while doing the get_a_printer call
2811 * but the devmode private part is not
2812 * it's done by convert_devicemode
2814 DEBUGADD(8,("Converting the devicemode struct\n"));
2815 nt_devmode=printer.info_2->devmode;
2817 init_devicemode(nt_devmode);
2819 convert_devicemode(*devmode, nt_devmode);
2822 if (printer.info_2->devmode != NULL)
2823 free(printer.info_2->devmode);
2824 printer.info_2->devmode=NULL;
2827 if (add_a_printer(printer, 2)!=0) {
2828 free_a_printer(printer, 2);
2830 /* I don't really know what to return here !!! */
2831 return NT_STATUS_INVALID_INFO_CLASS;
2834 free_a_printer(printer, 2);
2836 return NT_STATUS_NO_PROBLEMO;
2839 /****************************************************************************
2840 ****************************************************************************/
2841 uint32 _spoolss_setprinter(const POLICY_HND *handle, uint32 level,
2842 const SPOOL_PRINTER_INFO_LEVEL *info,
2843 const DEVMODE_CTR devmode_ctr,
2846 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2848 if (!OPEN_HANDLE(Printer))
2849 return NT_STATUS_INVALID_HANDLE;
2851 /* check the level */
2854 return control_printer(handle, command);
2857 return update_printer(handle, level, info, devmode_ctr.devmode);
2861 return NT_STATUS_INVALID_INFO_CLASS;
2864 /****************************************************************************
2865 ****************************************************************************/
2866 uint32 _spoolss_fcpn(const POLICY_HND *handle)
2868 Printer_entry *Printer= find_printer_index_by_hnd(handle);
2870 if (!OPEN_HANDLE(Printer))
2871 return NT_STATUS_INVALID_HANDLE;
2873 Printer->notify.flags=0;
2874 Printer->notify.options=0;
2875 Printer->notify.localmachine[0]='\0';
2876 Printer->notify.printerlocal=0;
2877 safe_free(Printer->notify.option);
2878 Printer->notify.option=NULL;
2880 return NT_STATUS_NO_PROBLEMO;
2883 /****************************************************************************
2884 ****************************************************************************/
2885 uint32 _spoolss_addjob(const POLICY_HND *handle, uint32 level,
2886 NEW_BUFFER *buffer, uint32 offered)
2888 return NT_STATUS_NO_PROBLEMO;
2891 /****************************************************************************
2892 ****************************************************************************/
2893 static void fill_job_info_1(JOB_INFO_1 *job_info, print_queue_struct *queue,
2894 int position, int snum)
2899 time_t unixdate = time(NULL);
2901 t=gmtime(&unixdate);
2902 snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname);
2904 job_info->jobid=queue->job;
2905 init_unistr(&(job_info->printername), lp_servicename(snum));
2906 init_unistr(&(job_info->machinename), temp_name);
2907 init_unistr(&(job_info->username), queue->user);
2908 init_unistr(&(job_info->document), queue->file);
2909 init_unistr(&(job_info->datatype), "RAW");
2910 init_unistr(&(job_info->text_status), "");
2911 job_info->status=queue->status;
2912 job_info->priority=queue->priority;
2913 job_info->position=position;
2914 job_info->totalpages=0;
2915 job_info->pagesprinted=0;
2917 make_systemtime(&(job_info->submitted), t);
2920 /****************************************************************************
2921 ****************************************************************************/
2922 static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue,
2923 int position, int snum)
2926 DEVICEMODE *devmode;
2927 NT_PRINTER_INFO_LEVEL ntprinter;
2931 time_t unixdate = time(NULL);
2933 if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0 )
2938 t=gmtime(&unixdate);
2939 snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname);
2941 job_info->jobid=queue->job;
2943 snprintf(chaine, sizeof(chaine)-1, "\\\\%s\\%s", global_myname, ntprinter.info_2->printername);
2944 init_unistr(&(job_info->printername), chaine);
2946 init_unistr(&(job_info->machinename), temp_name);
2947 init_unistr(&(job_info->username), queue->user);
2948 init_unistr(&(job_info->document), queue->file);
2949 init_unistr(&(job_info->notifyname), queue->user);
2950 init_unistr(&(job_info->datatype), "RAW");
2951 init_unistr(&(job_info->printprocessor), "winprint");
2952 init_unistr(&(job_info->parameters), "");
2953 init_unistr(&(job_info->text_status), "");
2955 /* and here the security descriptor */
2957 job_info->status=queue->status;
2958 job_info->priority=queue->priority;
2959 job_info->position=position;
2960 job_info->starttime=0;
2961 job_info->untiltime=0;
2962 job_info->totalpages=0;
2963 job_info->size=queue->size;
2964 make_systemtime(&(job_info->submitted), t);
2965 job_info->timeelapsed=0;
2966 job_info->pagesprinted=0;
2968 devmode=(DEVICEMODE *)malloc(sizeof(DEVICEMODE));
2969 ZERO_STRUCTP(devmode);
2970 construct_dev_mode(devmode, snum, global_myname);
2971 job_info->devmode=devmode;
2973 free_a_printer(ntprinter, 2);
2977 /****************************************************************************
2978 Enumjobs at level 1.
2979 ****************************************************************************/
2980 static uint32 enumjobs_level1(print_queue_struct *queue, int snum,
2981 NEW_BUFFER *buffer, uint32 offered,
2982 uint32 *needed, uint32 *returned)
2987 info=(JOB_INFO_1 *)malloc(*returned*sizeof(JOB_INFO_1));
2989 for (i=0; i<*returned; i++)
2991 fill_job_info_1(&(info[i]), &(queue[i]), i, snum);
2994 /* check the required size. */
2995 for (i=0; i<*returned; i++)
2996 (*needed) += spoolss_size_job_info_1(&(info[i]));
2998 if (!alloc_buffer_size(buffer, *needed))
2999 return ERROR_INSUFFICIENT_BUFFER;
3001 /* fill the buffer with the structures */
3002 for (i=0; i<*returned; i++)
3003 new_smb_io_job_info_1("", buffer, &(info[i]), 0);
3009 if (*needed > offered) {
3011 return ERROR_INSUFFICIENT_BUFFER;
3014 return NT_STATUS_NO_PROBLEMO;
3017 /****************************************************************************
3018 Enumjobs at level 2.
3019 ****************************************************************************/
3020 static uint32 enumjobs_level2(print_queue_struct *queue, int snum,
3021 NEW_BUFFER *buffer, uint32 offered,
3022 uint32 *needed, uint32 *returned)
3027 info=(JOB_INFO_2 *)malloc(*returned*sizeof(JOB_INFO_2));
3029 for (i=0; i<*returned; i++)
3031 fill_job_info_2(&(info[i]), &(queue[i]), i, snum);
3034 /* check the required size. */
3035 for (i=0; i<*returned; i++)
3036 (*needed) += spoolss_size_job_info_2(&(info[i]));
3038 if (!alloc_buffer_size(buffer, *needed))
3039 return ERROR_INSUFFICIENT_BUFFER;
3041 /* fill the buffer with the structures */
3042 for (i=0; i<*returned; i++)
3043 new_smb_io_job_info_2("", buffer, &(info[i]), 0);
3049 if (*needed > offered) {
3051 return ERROR_INSUFFICIENT_BUFFER;
3054 return NT_STATUS_NO_PROBLEMO;
3057 /****************************************************************************
3059 ****************************************************************************/
3060 uint32 _spoolss_enumjobs( POLICY_HND *handle, uint32 firstjob, uint32 numofjobs, uint32 level,
3061 NEW_BUFFER *buffer, uint32 offered,
3062 uint32 *needed, uint32 *returned)
3065 print_queue_struct *queue=NULL;
3066 print_status_struct prt_status;
3068 DEBUG(4,("_spoolss_enumjobs\n"));
3070 ZERO_STRUCT(prt_status);
3075 if (!get_printer_snum(handle, &snum))
3077 return NT_STATUS_INVALID_HANDLE;
3080 *returned = get_printqueue(snum, NULL, &queue, &prt_status);
3081 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n", *returned, prt_status.status, prt_status.message));
3085 return enumjobs_level1(queue, snum, buffer, offered, needed, returned);
3088 return enumjobs_level2(queue, snum, buffer, offered, needed, returned);
3091 return NT_STATUS_INVALID_LEVEL;
3098 /****************************************************************************
3099 ****************************************************************************/
3100 uint32 _spoolss_schedulejob( const POLICY_HND *handle, uint32 jobid)
3105 /****************************************************************************
3106 ****************************************************************************/
3107 uint32 _spoolss_setjob( const POLICY_HND *handle,
3115 print_queue_struct *queue=NULL;
3116 print_status_struct prt_status;
3121 memset(&prt_status, 0, sizeof(prt_status));
3123 if (!get_printer_snum(handle, &snum))
3125 return NT_STATUS_INVALID_HANDLE;
3128 count=get_printqueue(snum, NULL, &queue, &prt_status);
3130 while ( (i<count) && found==False )
3132 if ( jobid == queue[i].job )
3143 case JOB_CONTROL_CANCEL:
3144 case JOB_CONTROL_DELETE:
3146 del_printqueue(NULL, snum, jobid);
3150 case JOB_CONTROL_PAUSE:
3152 status_printjob(NULL, snum, jobid, LPQ_PAUSED);
3156 case JOB_CONTROL_RESUME:
3158 status_printjob(NULL, snum, jobid, LPQ_QUEUED);
3165 return NT_STATUS_INVALID_INFO_CLASS;
3169 /****************************************************************************
3170 Enumerates all printer drivers at level 1.
3171 ****************************************************************************/
3172 static uint32 enumprinterdrivers_level1(fstring *list, fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3175 NT_PRINTER_DRIVER_INFO_LEVEL driver;
3176 DRIVER_INFO_1 *driver_info_1=NULL;
3177 driver_info_1=(DRIVER_INFO_1 *)malloc(*returned * sizeof(DRIVER_INFO_1));
3179 for (i=0; i<*returned; i++) {
3180 get_a_printer_driver(&driver, 3, list[i], architecture);
3181 fill_printer_driver_info_1(&(driver_info_1[i]), driver, servername, architecture );
3182 free_a_printer_driver(driver, 3);
3185 /* check the required size. */
3186 for (i=0; i<*returned; i++)
3188 DEBUGADD(6,("adding driver [%d]'s size\n",i));
3189 *needed += spoolss_size_printer_driver_info_1(&(driver_info_1[i]));
3192 if (!alloc_buffer_size(buffer, *needed))
3193 return ERROR_INSUFFICIENT_BUFFER;
3195 /* fill the buffer with the form structures */
3196 for (i=0; i<*returned; i++)
3198 DEBUGADD(6,("adding driver [%d] to buffer\n",i));
3199 new_smb_io_printer_driver_info_1("", buffer, &(driver_info_1[i]), 0);
3204 if (*needed > offered)
3205 return ERROR_INSUFFICIENT_BUFFER;
3207 return NT_STATUS_NO_PROBLEMO;
3210 /****************************************************************************
3211 Enumerates all printer drivers at level 2.
3212 ****************************************************************************/
3213 static uint32 enumprinterdrivers_level2(fstring *list, fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3216 NT_PRINTER_DRIVER_INFO_LEVEL driver;
3217 DRIVER_INFO_2 *driver_info_2=NULL;
3218 driver_info_2=(DRIVER_INFO_2 *)malloc(*returned * sizeof(DRIVER_INFO_2));
3220 for (i=0; i<*returned; i++) {
3221 get_a_printer_driver(&driver, 3, list[i], architecture);
3222 fill_printer_driver_info_2(&(driver_info_2[i]), driver, servername, architecture );
3223 free_a_printer_driver(driver, 3);
3226 /* check the required size. */
3227 for (i=0; i<*returned; i++)
3229 DEBUGADD(6,("adding driver [%d]'s size\n",i));
3230 *needed += spoolss_size_printer_driver_info_2(&(driver_info_2[i]));
3233 if (!alloc_buffer_size(buffer, *needed))
3234 return ERROR_INSUFFICIENT_BUFFER;
3236 /* fill the buffer with the form structures */
3237 for (i=0; i<*returned; i++)
3239 DEBUGADD(6,("adding driver [%d] to buffer\n",i));
3240 new_smb_io_printer_driver_info_2("", buffer, &(driver_info_2[i]), 0);
3245 if (*needed > offered)
3246 return ERROR_INSUFFICIENT_BUFFER;
3248 return NT_STATUS_NO_PROBLEMO;
3251 /****************************************************************************
3252 Enumerates all printer drivers at level 3.
3253 ****************************************************************************/
3254 static uint32 enumprinterdrivers_level3(fstring *list, fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3257 NT_PRINTER_DRIVER_INFO_LEVEL driver;
3258 DRIVER_INFO_3 *driver_info_3=NULL;
3259 driver_info_3=(DRIVER_INFO_3 *)malloc((*returned)*sizeof(DRIVER_INFO_3));
3261 for (i=0; i<*returned; i++) {
3262 get_a_printer_driver(&driver, 3, list[i], architecture);
3263 fill_printer_driver_info_3(&(driver_info_3[i]), driver, servername, architecture );
3264 free_a_printer_driver(driver, 3);
3267 /* check the required size. */
3268 for (i=0; i<*returned; i++)
3270 DEBUGADD(6,("adding driver [%d]'s size\n",i));
3271 *needed += spoolss_size_printer_driver_info_3(&(driver_info_3[i]));
3274 if (!alloc_buffer_size(buffer, *needed))
3275 return ERROR_INSUFFICIENT_BUFFER;
3277 /* fill the buffer with the form structures */
3278 for (i=0; i<*returned; i++)
3280 DEBUGADD(6,("adding form [%d] to buffer\n",i));
3281 new_smb_io_printer_driver_info_3("", buffer, &(driver_info_3[i]), 0);
3286 if (*needed > offered)
3287 return ERROR_INSUFFICIENT_BUFFER;
3289 return NT_STATUS_NO_PROBLEMO;
3292 /****************************************************************************
3293 Enumerates all printer drivers.
3294 ****************************************************************************/
3295 uint32 _spoolss_enumprinterdrivers( UNISTR2 *name, UNISTR2 *environment, uint32 level,
3296 NEW_BUFFER *buffer, uint32 offered,
3297 uint32 *needed, uint32 *returned)
3302 fstring architecture;
3304 DEBUG(4,("_spoolss_enumprinterdrivers\n"));
3305 fstrcpy(servername, global_myname);
3309 unistr2_to_ascii(architecture, environment, sizeof(architecture)-1);
3310 *returned=get_ntdrivers(&list, architecture);
3312 DEBUGADD(4,("we have: [%d] drivers in environment [%s]\n", *returned, architecture));
3313 for (i=0; i<*returned; i++)
3314 DEBUGADD(5,("driver: [%s]\n", list[i]));
3318 return enumprinterdrivers_level1(list, servername, architecture, buffer, offered, needed, returned);
3321 return enumprinterdrivers_level2(list, servername, architecture, buffer, offered, needed, returned);
3324 return enumprinterdrivers_level3(list, servername, architecture, buffer, offered, needed, returned);
3327 return NT_STATUS_INVALID_INFO_CLASS;
3332 /****************************************************************************
3333 ****************************************************************************/
3334 static void fill_form_1(FORM_1 *form, nt_forms_struct *list, int position)
3336 form->flag=list->flag;
3337 init_unistr(&(form->name), list->name);
3338 form->width=list->width;
3339 form->length=list->length;
3340 form->left=list->left;
3341 form->top=list->top;
3342 form->right=list->right;
3343 form->bottom=list->bottom;
3346 /****************************************************************************
3347 ****************************************************************************/
3348 uint32 _new_spoolss_enumforms( const POLICY_HND *handle, uint32 level,
3349 NEW_BUFFER *buffer, uint32 offered,
3350 uint32 *needed, uint32 *numofforms)
3352 nt_forms_struct *list=NULL;
3357 DEBUG(4,("_new_spoolss_enumforms\n"));
3358 DEBUGADD(5,("Offered buffer size [%d]\n", offered));
3359 DEBUGADD(5,("Info level [%d]\n", level));
3361 *numofforms = get_ntforms(&list);
3362 DEBUGADD(5,("Number of forms [%d]\n", *numofforms));
3366 forms_1=(FORM_1 *)malloc(*numofforms * sizeof(FORM_1));
3368 /* construct the list of form structures */
3369 for (i=0; i<*numofforms; i++)
3371 DEBUGADD(6,("Filling form number [%d]\n",i));
3372 fill_form_1(&(forms_1[i]), &(list[i]), i);
3375 /* check the required size. */
3376 for (i=0; i<*numofforms; i++)
3378 DEBUGADD(6,("adding form [%d]'s size\n",i));
3379 buffer_size += spoolss_size_form_1(&(forms_1[i]));
3382 *needed=buffer_size;
3384 if (!alloc_buffer_size(buffer, buffer_size))
3385 return ERROR_INSUFFICIENT_BUFFER;
3387 /* fill the buffer with the form structures */
3388 for (i=0; i<*numofforms; i++)
3390 DEBUGADD(6,("adding form [%d] to buffer\n",i));
3391 new_smb_io_form_1("", buffer, &(forms_1[i]), 0);
3396 if (*needed > offered)
3397 return ERROR_INSUFFICIENT_BUFFER;
3399 return NT_STATUS_NO_PROBLEMO;
3403 return NT_STATUS_INVALID_INFO_CLASS;
3408 /****************************************************************************
3409 ****************************************************************************/
3410 static void fill_port_1(PORT_INFO_1 *port, char *name)
3412 init_unistr(&(port->port_name), name);
3415 /****************************************************************************
3416 ****************************************************************************/
3417 static void fill_port_2(PORT_INFO_2 *port, char *name)
3419 init_unistr(&(port->port_name), name);
3420 init_unistr(&(port->monitor_name), "Moniteur Local");
3421 init_unistr(&(port->description), "Local Port");
3422 #define PORT_TYPE_WRITE 1
3423 port->port_type=PORT_TYPE_WRITE;
3427 /****************************************************************************
3429 ****************************************************************************/
3430 static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3432 int n_services=lp_numservices();
3436 PORT_INFO_1 *ports=NULL;
3438 for (snum=0; snum<n_services; snum++)
3439 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
3442 ports=(PORT_INFO_1 *)malloc( (*returned+1) * sizeof(PORT_INFO_1) );
3444 for (snum=0; snum<n_services; snum++)
3446 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
3447 DEBUGADD(6,("Filling port number [%d]\n", i));
3448 fill_port_1(&(ports[i]), lp_servicename(snum));
3453 /* check the required size. */
3454 for (i=0; i<*returned; i++)
3456 DEBUGADD(6,("adding port [%d]'s size\n", i));
3457 *needed += spoolss_size_port_info_1(&(ports[i]));
3460 if (!alloc_buffer_size(buffer, *needed))
3461 return ERROR_INSUFFICIENT_BUFFER;
3463 /* fill the buffer with the ports structures */
3464 for (i=0; i<*returned; i++)
3466 DEBUGADD(6,("adding port [%d] to buffer\n", i));
3467 new_smb_io_port_1("", buffer, &(ports[i]), 0);
3472 if (*needed > offered) {
3474 return ERROR_INSUFFICIENT_BUFFER;
3477 return NT_STATUS_NO_PROBLEMO;
3481 /****************************************************************************
3483 ****************************************************************************/
3484 static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3486 int n_services=lp_numservices();
3490 PORT_INFO_2 *ports=NULL;
3492 for (snum=0; snum<n_services; snum++)
3493 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
3496 ports=(PORT_INFO_2 *)malloc( (*returned+1) * sizeof(PORT_INFO_2) );
3498 for (snum=0; snum<n_services; snum++)
3500 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
3501 DEBUGADD(6,("Filling port number [%d]\n", i));
3502 fill_port_2(&(ports[i]), lp_servicename(snum));
3507 /* check the required size. */
3508 for (i=0; i<*returned; i++)
3510 DEBUGADD(6,("adding port [%d]'s size\n", i));
3511 *needed += spoolss_size_port_info_2(&(ports[i]));
3514 if (!alloc_buffer_size(buffer, *needed))
3515 return ERROR_INSUFFICIENT_BUFFER;
3517 /* fill the buffer with the ports structures */
3518 for (i=0; i<*returned; i++)
3520 DEBUGADD(6,("adding port [%d] to buffer\n", i));
3521 new_smb_io_port_2("", buffer, &(ports[i]), 0);
3526 if (*needed > offered) {
3528 return ERROR_INSUFFICIENT_BUFFER;
3531 return NT_STATUS_NO_PROBLEMO;
3534 /****************************************************************************
3536 ****************************************************************************/
3537 uint32 _spoolss_enumports( UNISTR2 *name, uint32 level,
3538 NEW_BUFFER *buffer, uint32 offered,
3539 uint32 *needed, uint32 *returned)
3541 DEBUG(4,("_spoolss_enumports\n"));
3548 return enumports_level_1(buffer, offered, needed, returned);
3551 return enumports_level_2(buffer, offered, needed, returned);
3554 return NT_STATUS_INVALID_INFO_CLASS;
3559 /****************************************************************************
3560 ****************************************************************************/
3561 uint32 _spoolss_addprinterex( const UNISTR2 *uni_srv_name, uint32 level,
3562 const SPOOL_PRINTER_INFO_LEVEL *info,
3563 uint32 unk0, uint32 unk1, uint32 unk2, uint32 unk3,
3564 uint32 user_switch, const SPOOL_USER_CTR *user,
3567 NT_PRINTER_INFO_LEVEL printer;
3571 clear_handle(handle);
3574 * FIX: JFM: we need to check the user here !!!!
3576 * as the code is running as root, anybody can add printers to the server
3578 /* NULLify info_2 here */
3579 /* don't put it in convert_printer_info as it's used also with non-NULL values */
3580 printer.info_2=NULL;
3582 /* convert from UNICODE to ASCII */
3583 convert_printer_info(info, &printer, level);
3585 unistr2_to_ascii(share_name, &((info->info_2)->portname), sizeof(share_name)-1);
3587 slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname, share_name);
3589 create_printer_hnd(handle);
3591 open_printer_hnd(handle);
3593 if (!set_printer_hnd_printertype(handle, name)) {
3594 close_printer_handle(handle);
3595 return NT_STATUS_ACCESS_DENIED;
3598 if (!set_printer_hnd_printername(handle, name)) {
3599 close_printer_handle(handle);
3600 return NT_STATUS_ACCESS_DENIED;
3603 /* write the ASCII on disk */
3604 if (add_a_printer(printer, level) != 0x0) {
3605 close_printer_handle(handle);
3606 return NT_STATUS_ACCESS_DENIED;
3609 return NT_STATUS_NO_PROBLEMO;
3612 /****************************************************************************
3613 ****************************************************************************/
3614 uint32 _spoolss_addprinterdriver( const UNISTR2 *server_name,
3616 const SPOOL_PRINTER_DRIVER_INFO_LEVEL *info)
3618 NT_PRINTER_DRIVER_INFO_LEVEL driver;
3620 convert_printer_driver_info(info, &driver, level);
3622 if (add_a_printer_driver(driver, level)!=0)
3623 return NT_STATUS_ACCESS_DENIED;
3625 return NT_STATUS_NO_PROBLEMO;
3628 /****************************************************************************
3629 ****************************************************************************/
3630 static void fill_driverdir_1(DRIVER_DIRECTORY_1 *info, char *name)
3632 init_unistr(&(info->name), name);
3635 /****************************************************************************
3636 ****************************************************************************/
3637 static uint32 getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environment, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
3641 pstring short_archi;
3642 DRIVER_DIRECTORY_1 *info=NULL;
3644 info=(DRIVER_DIRECTORY_1 *)malloc(sizeof(DRIVER_DIRECTORY_1));
3646 unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)-1);
3647 get_short_archi(short_archi, long_archi);
3649 slprintf(chaine, sizeof(chaine)-1, "\\\\%s\\print$\\%s", global_myname, short_archi);
3651 DEBUG(4,("printer driver directory: [%s]\n", chaine));
3653 fill_driverdir_1(info, chaine);
3655 *needed += spoolss_size_driverdir_info_1(info);
3657 if (!alloc_buffer_size(buffer, *needed))
3658 return ERROR_INSUFFICIENT_BUFFER;
3660 new_smb_io_driverdir_1("", buffer, info, 0);
3664 if (*needed > offered)
3665 return ERROR_INSUFFICIENT_BUFFER;
3667 return NT_STATUS_NO_PROBLEMO;
3670 /****************************************************************************
3671 ****************************************************************************/
3672 uint32 _spoolss_getprinterdriverdirectory(UNISTR2 *name, UNISTR2 *uni_environment, uint32 level,
3673 NEW_BUFFER *buffer, uint32 offered,
3676 DEBUG(4,("_spoolss_getprinterdriverdirectory\n"));
3682 return getprinterdriverdir_level_1(name, uni_environment, buffer, offered, needed);
3685 return NT_STATUS_INVALID_INFO_CLASS;
3690 /****************************************************************************
3691 ****************************************************************************/
3692 uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx,
3693 uint32 in_value_len, uint32 in_data_len,
3694 uint32 *out_max_value_len, uint16 **out_value, uint32 *out_value_len,
3696 uint32 *out_max_data_len, uint8 **data_out, uint32 *out_data_len)
3698 NT_PRINTER_INFO_LEVEL printer;
3703 uint32 biggest_valuesize;
3704 uint32 biggest_datasize;
3706 Printer_entry *Printer = find_printer_index_by_hnd(handle);
3711 ZERO_STRUCT(printer);
3713 *out_max_value_len=0;
3719 *out_max_data_len=0;
3723 DEBUG(5,("spoolss_enumprinterdata\n"));
3725 if (!OPEN_HANDLE(Printer))
3726 return NT_STATUS_INVALID_HANDLE;
3728 if (!get_printer_snum(handle, &snum))
3729 return NT_STATUS_INVALID_HANDLE;
3731 if (get_a_printer(&printer, 2, lp_servicename(snum)) != 0x0)
3732 return NT_STATUS_INVALID_HANDLE;
3735 * The NT machine wants to know the biggest size of value and data
3737 * cf: MSDN EnumPrinterData remark section
3739 if ( (in_value_len==0) && (in_data_len==0) ) {
3740 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
3743 biggest_valuesize=0;
3746 while (get_specific_param_by_index(printer, 2, param_index, value, &data, &type, &data_len)) {
3747 if (strlen(value) > biggest_valuesize) biggest_valuesize=strlen(value);
3748 if (data_len > biggest_datasize) biggest_datasize=data_len;
3750 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize, biggest_datasize));
3756 /* the value is an UNICODE string but realvaluesize is the length in bytes including the leading 0 */
3757 *out_value_len=2*(1+biggest_valuesize);
3758 *out_data_len=biggest_datasize;
3760 DEBUG(6,("final values: [%d], [%d]\n", *out_value_len, *out_data_len));
3762 free_a_printer(printer, 2);
3763 return NT_STATUS_NO_PROBLEMO;
3767 * the value len is wrong in NT sp3
3768 * that's the number of bytes not the number of unicode chars
3771 if (!get_specific_param_by_index(printer, 2, idx, value, &data, &type, &data_len)) {
3772 free_a_printer(printer, 2);
3773 return ERROR_NO_MORE_ITEMS;
3778 * - counted in bytes in the request
3779 * - counted in UNICODE chars in the max reply
3780 * - counted in bytes in the real size
3782 * take a pause *before* coding not *during* coding
3785 *out_max_value_len=in_value_len/2;
3786 *out_value=(uint16 *)malloc(in_value_len*sizeof(uint8));
3787 ascii_to_unistr(*out_value, value, *out_max_value_len);
3788 *out_value_len=2*(1+strlen(value));
3792 /* the data is counted in bytes */
3793 *out_max_data_len=in_data_len;
3794 *data_out=(uint8 *)malloc(in_data_len*sizeof(uint8));
3795 memcpy(*out_data, data, data_len);
3796 *out_data_len=data_len;
3800 free_a_printer(printer, 2);
3801 return NT_STATUS_NO_PROBLEMO;
3804 /****************************************************************************
3805 ****************************************************************************/
3806 uint32 _spoolss_setprinterdata( const POLICY_HND *handle,
3807 const UNISTR2 *value,
3812 uint32 numeric_data)
3814 NT_PRINTER_INFO_LEVEL printer;
3815 NT_PRINTER_PARAM *param = NULL;
3818 uint32 status = 0x0;
3819 Printer_entry *Printer=find_printer_index_by_hnd(handle);
3821 DEBUG(5,("spoolss_setprinterdata\n"));
3824 if (!OPEN_HANDLE(Printer))
3825 return NT_STATUS_INVALID_HANDLE;
3827 if (!get_printer_snum(handle, &snum))
3828 return NT_STATUS_INVALID_HANDLE;
3830 status = get_a_printer(&printer, 2, lp_servicename(snum));
3834 convert_specific_param(¶m, value , type, data, real_len);
3835 unlink_specific_param_if_exist(printer.info_2, param);
3837 if (!add_a_specific_param(printer.info_2, param))
3839 status = NT_STATUS_INVALID_PARAMETER;
3843 status = add_a_printer(printer, 2);
3845 free_a_printer(printer, 2);
3850 /****************************************************************************
3851 ****************************************************************************/
3852 uint32 _spoolss_addform( const POLICY_HND *handle,
3857 nt_forms_struct *list=NULL;
3858 Printer_entry *Printer = find_printer_index_by_hnd(handle);
3860 DEBUG(5,("spoolss_addform\n"));
3862 if (!OPEN_HANDLE(Printer))
3863 return NT_STATUS_INVALID_HANDLE;
3865 count=get_ntforms(&list);
3866 add_a_form(&list, form, &count);
3867 write_ntforms(&list, count);
3874 /****************************************************************************
3875 ****************************************************************************/
3876 uint32 _spoolss_setform( const POLICY_HND *handle,
3877 const UNISTR2 *uni_name,
3882 nt_forms_struct *list=NULL;
3883 Printer_entry *Printer = find_printer_index_by_hnd(handle);
3885 DEBUG(5,("spoolss_setform\n"));
3887 if (!OPEN_HANDLE(Printer))
3889 return NT_STATUS_INVALID_HANDLE;
3891 count=get_ntforms(&list);
3892 update_a_form(&list, form, count);
3893 write_ntforms(&list, count);
3900 /****************************************************************************
3901 enumprintprocessors level 1.
3902 ****************************************************************************/
3903 static uint32 enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3905 PRINTPROCESSOR_1 *info_1=NULL;
3907 info_1 = (PRINTPROCESSOR_1 *)malloc(sizeof(PRINTPROCESSOR_1));
3910 init_unistr(&(info_1->name), "winprint");
3912 *needed += spoolss_size_printprocessor_info_1(info_1);
3914 if (!alloc_buffer_size(buffer, *needed))
3915 return ERROR_INSUFFICIENT_BUFFER;
3917 smb_io_printprocessor_info_1("", buffer, info_1, 0);
3921 if (*needed > offered) {
3923 return ERROR_INSUFFICIENT_BUFFER;
3926 return NT_STATUS_NO_PROBLEMO;
3929 /****************************************************************************
3930 ****************************************************************************/
3931 uint32 _spoolss_enumprintprocessors(UNISTR2 *name, UNISTR2 *environment, uint32 level,
3932 NEW_BUFFER *buffer, uint32 offered,
3933 uint32 *needed, uint32 *returned)
3935 DEBUG(5,("spoolss_enumprintprocessors\n"));
3938 * Enumerate the print processors ...
3940 * Just reply with "winprint", to keep NT happy
3941 * and I can use my nice printer checker.
3949 return enumprintprocessors_level_1(buffer, offered, needed, returned);
3952 return NT_STATUS_INVALID_INFO_CLASS;
3957 /****************************************************************************
3958 enumprintprocdatatypes level 1.
3959 ****************************************************************************/
3960 static uint32 enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3962 PRINTPROCDATATYPE_1 *info_1=NULL;
3964 info_1 = (PRINTPROCDATATYPE_1 *)malloc(sizeof(PRINTPROCDATATYPE_1));
3967 init_unistr(&(info_1->name), "RAW");
3969 *needed += spoolss_size_printprocdatatype_info_1(info_1);
3971 if (!alloc_buffer_size(buffer, *needed))
3972 return ERROR_INSUFFICIENT_BUFFER;
3974 smb_io_printprocdatatype_info_1("", buffer, info_1, 0);
3978 if (*needed > offered) {
3980 return ERROR_INSUFFICIENT_BUFFER;
3983 return NT_STATUS_NO_PROBLEMO;
3986 /****************************************************************************
3987 ****************************************************************************/
3988 uint32 _spoolss_enumprintprocdatatypes(UNISTR2 *name, UNISTR2 *processor, uint32 level,
3989 NEW_BUFFER *buffer, uint32 offered,
3990 uint32 *needed, uint32 *returned)
3992 DEBUG(5,("_spoolss_enumprintprocdatatypes\n"));
3999 return enumprintprocdatatypes_level_1(buffer, offered, needed, returned);
4002 return NT_STATUS_INVALID_INFO_CLASS;
4007 /****************************************************************************
4008 enumprintmonitors level 1.
4009 ****************************************************************************/
4010 static uint32 enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4012 PRINTMONITOR_1 *info_1=NULL;
4014 info_1 = (PRINTMONITOR_1 *)malloc(sizeof(PRINTMONITOR_1));
4017 init_unistr(&(info_1->name), "Local Port");
4019 *needed += spoolss_size_printmonitor_info_1(info_1);
4021 if (!alloc_buffer_size(buffer, *needed))
4022 return ERROR_INSUFFICIENT_BUFFER;
4024 smb_io_printmonitor_info_1("", buffer, info_1, 0);
4028 if (*needed > offered) {
4030 return ERROR_INSUFFICIENT_BUFFER;
4033 return NT_STATUS_NO_PROBLEMO;
4036 /****************************************************************************
4037 enumprintmonitors level 2.
4038 ****************************************************************************/
4039 static uint32 enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4041 PRINTMONITOR_2 *info_2=NULL;
4043 info_2 = (PRINTMONITOR_2 *)malloc(sizeof(PRINTMONITOR_2));
4046 init_unistr(&(info_2->name), "Local Port");
4047 init_unistr(&(info_2->environment), "Windows NT X86");
4048 init_unistr(&(info_2->dll_name), "localmon.dll");
4050 *needed += spoolss_size_printmonitor_info_2(info_2);
4052 if (!alloc_buffer_size(buffer, *needed))
4053 return ERROR_INSUFFICIENT_BUFFER;
4055 smb_io_printmonitor_info_2("", buffer, info_2, 0);
4059 if (*needed > offered) {
4061 return ERROR_INSUFFICIENT_BUFFER;
4064 return NT_STATUS_NO_PROBLEMO;
4067 /****************************************************************************
4068 ****************************************************************************/
4069 uint32 _spoolss_enumprintmonitors(UNISTR2 *name,uint32 level,
4070 NEW_BUFFER *buffer, uint32 offered,
4071 uint32 *needed, uint32 *returned)
4073 DEBUG(5,("spoolss_enumprintmonitors\n"));
4076 * Enumerate the print monitors ...
4078 * Just reply with "Local Port", to keep NT happy
4079 * and I can use my nice printer checker.
4087 return enumprintmonitors_level_1(buffer, offered, needed, returned);
4090 return enumprintmonitors_level_2(buffer, offered, needed, returned);
4093 return NT_STATUS_INVALID_INFO_CLASS;
4098 /****************************************************************************
4099 ****************************************************************************/
4100 static uint32 getjob_level_1(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
4104 JOB_INFO_1 *info_1=NULL;
4105 info_1=(JOB_INFO_1 *)malloc(sizeof(JOB_INFO_1));
4107 if (info_1 == NULL) {
4109 return NT_STATUS_NO_MEMORY;
4112 for (i=0; i<count && found==False; i++) {
4113 if (queue[i].job==(int)jobid)
4119 /* I shoud reply something else ... I can't find the good one */
4120 return NT_STATUS_NO_PROBLEMO;
4123 fill_job_info_1(info_1, &(queue[i]), i, snum);
4125 *needed += spoolss_size_job_info_1(info_1);
4127 if (!alloc_buffer_size(buffer, *needed))
4128 return ERROR_INSUFFICIENT_BUFFER;
4130 new_smb_io_job_info_1("", buffer, info_1, 0);
4134 if (*needed > offered)
4135 return ERROR_INSUFFICIENT_BUFFER;
4137 return NT_STATUS_NO_PROBLEMO;
4141 /****************************************************************************
4142 ****************************************************************************/
4145 static uint32 getjob_level_2(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
4149 JOB_INFO_2 *info_2=NULL;
4150 info_2=(JOB_INFO_2 *)malloc(sizeof(JOB_INFO_2));
4152 if (info_2 == NULL) {
4154 return NT_STATUS_NO_MEMORY;
4157 for (i=0; i<count && found==False; i++) {
4158 if (queue[i].job==(int)jobid)
4164 /* I shoud reply something else ... I can't find the good one */
4165 return NT_STATUS_NO_PROBLEMO;
4168 fill_job_info_2(info_2, &(queue[i]), i, snum);
4170 *needed += spoolss_size_job_info_2(info_2);
4172 if (!alloc_buffer_size(buffer, *needed))
4173 return ERROR_INSUFFICIENT_BUFFER;
4175 new_smb_io_job_info_2("", buffer, info_2, 0);
4179 if (*needed > offered)
4180 return ERROR_INSUFFICIENT_BUFFER;
4182 return NT_STATUS_NO_PROBLEMO;
4186 /****************************************************************************
4187 ****************************************************************************/
4188 uint32 _spoolss_getjob( POLICY_HND *handle, uint32 jobid, uint32 level,
4189 NEW_BUFFER *buffer, uint32 offered,
4194 print_queue_struct *queue=NULL;
4195 print_status_struct prt_status;
4197 DEBUG(5,("spoolss_getjob\n"));
4199 memset(&prt_status, 0, sizeof(prt_status));
4203 if (!get_printer_snum(handle, &snum))
4205 return NT_STATUS_INVALID_HANDLE;
4208 count=get_printqueue(snum, NULL, &queue, &prt_status);
4210 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
4211 count, prt_status.status, prt_status.message));
4215 return getjob_level_1(queue, count, snum, jobid, buffer, offered, needed);
4218 return getjob_level_1(queue, count, snum, jobid, buffer, offered, needed);
4222 return NT_STATUS_INVALID_INFO_CLASS;