2 * Unix SMB/Netbios implementation.
4 * RPC Pipe client / server routines
5 * Copyright (C) Andrew Tridgell 1992-2000,
6 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
7 * Copyright (C) Jean François Micouleau 1998-2000.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 extern int DEBUGLEVEL;
29 extern pstring global_myname;
31 #ifndef MAX_OPEN_PRINTER_EXS
32 #define MAX_OPEN_PRINTER_EXS 50
35 #define PRINTER_HANDLE_IS_PRINTER 0
36 #define PRINTER_HANDLE_IS_PRINTSERVER 1
38 /* structure to store the printer handles */
39 /* and a reference to what it's pointing to */
40 /* and the notify info asked about */
41 /* that's the central struct */
42 typedef struct _Printer{
47 BOOL document_started;
49 int jobid; /* jobid in printing backend */
50 POLICY_HND printer_hnd;
54 fstring printerservername;
63 SPOOL_NOTIFY_OPTION *option;
71 typedef struct _counter_printer_0 {
79 static ubi_dlList Printer_list;
80 static ubi_dlList counter_list;
83 #define OPEN_HANDLE(pnum) ((pnum!=NULL) && (pnum->open!=False))
85 /* translate between internal status numbers and NT status numbers */
86 static int nt_printj_status(int v)
90 return PRINTER_STATUS_PAUSED;
99 static int nt_printq_status(int v)
103 return PRINTER_STATUS_ERROR;
112 /****************************************************************************
113 initialise printer handle states...
114 ****************************************************************************/
115 void init_printer_hnd(void)
117 ubi_dlInitList(&Printer_list);
118 ubi_dlInitList(&counter_list);
121 /****************************************************************************
122 create a unique printer handle
123 ****************************************************************************/
124 static void create_printer_hnd(POLICY_HND *hnd)
126 static uint32 prt_hnd_low = 0;
127 static uint32 prt_hnd_high = 0;
129 if (hnd == NULL) return;
131 /* i severely doubt that prt_hnd_high will ever be non-zero... */
133 if (prt_hnd_low == 0) prt_hnd_high++;
135 SIVAL(hnd->data, 0 , 0x0); /* first bit must be null */
136 SIVAL(hnd->data, 4 , prt_hnd_low ); /* second bit is incrementing */
137 SIVAL(hnd->data, 8 , prt_hnd_high); /* second bit is incrementing */
138 SIVAL(hnd->data, 12, time(NULL)); /* something random */
139 SIVAL(hnd->data, 16, getpid()); /* something more random */
142 /****************************************************************************
143 find printer index by handle
144 ****************************************************************************/
145 static Printer_entry *find_printer_index_by_hnd(const POLICY_HND *hnd)
147 Printer_entry *find_printer;
149 find_printer = (Printer_entry *)ubi_dlFirst(&Printer_list);
151 for(; find_printer; find_printer = (Printer_entry *)ubi_dlNext(find_printer)) {
153 if (memcmp(&(find_printer->printer_hnd), hnd, sizeof(*hnd)) == 0)
155 DEBUG(4,("Found printer handle \n"));
156 /*dump_data(4, hnd->data, sizeof(hnd->data));*/
161 DEBUG(3,("Whoops, Printer handle not found: "));
162 /*dump_data(4, hnd->data, sizeof(hnd->data));*/
166 /****************************************************************************
168 ****************************************************************************/
169 static void clear_handle(POLICY_HND *hnd)
171 memset(hnd->data, 0, POLICY_HND_SIZE);
174 /****************************************************************************
175 close printer index by handle
176 ****************************************************************************/
177 static BOOL close_printer_handle(POLICY_HND *hnd)
179 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
181 if (!OPEN_HANDLE(Printer))
183 DEBUG(3,("Error closing printer handle\n"));
188 Printer->notify.flags=0;
189 Printer->notify.options=0;
190 Printer->notify.localmachine[0]='\0';
191 Printer->notify.printerlocal=0;
192 safe_free(Printer->notify.option);
193 Printer->notify.option=NULL;
197 ubi_dlRemThis(&Printer_list, Printer);
204 /****************************************************************************
205 return the snum of a printer corresponding to an handle
206 ****************************************************************************/
207 static BOOL get_printer_snum(const POLICY_HND *hnd, int *number)
209 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
211 if (!OPEN_HANDLE(Printer)) {
212 DEBUG(3,("Error getting printer - take a nap quickly !\n"));
216 switch (Printer->printer_type) {
217 case PRINTER_HANDLE_IS_PRINTER:
218 DEBUG(4,("short name:%s\n", Printer->dev.printername));
219 *number = print_queue_snum(Printer->dev.printername);
220 return (*number != -1);
221 case PRINTER_HANDLE_IS_PRINTSERVER:
230 /****************************************************************************
231 find first available printer slot. creates a printer handle for you.
232 ****************************************************************************/
233 static BOOL open_printer_hnd(POLICY_HND *hnd)
235 Printer_entry *new_printer;
237 if((new_printer=(Printer_entry *)malloc(sizeof(Printer_entry))) == NULL)
240 ZERO_STRUCTP(new_printer);
242 new_printer->open = True;
243 new_printer->notify.option=NULL;
245 memcpy(&(new_printer->printer_hnd), hnd, sizeof(*hnd));
247 ubi_dlAddHead( &Printer_list, (ubi_dlNode *)new_printer);
252 /****************************************************************************
253 set printer handle type.
254 ****************************************************************************/
255 static BOOL set_printer_hnd_accesstype(POLICY_HND *hnd, uint32 access_required)
257 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
259 if (!OPEN_HANDLE(Printer)) {
260 DEBUG(4,("Error setting printer type=%x", access_required));
264 DEBUG(4,("Setting printer access=%x\n", access_required));
265 Printer->access = access_required;
269 /****************************************************************************
270 set printer handle type.
271 check if it's \\server or \\server\printer
272 ****************************************************************************/
273 static BOOL set_printer_hnd_printertype(POLICY_HND *hnd, char *printername)
275 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
277 if (!OPEN_HANDLE(Printer)) {
278 DEBUGADD(4,("Error setting printer name %s", printername));
282 DEBUG(3,("Setting printer type=%s\n", printername));
284 if ( strlen(printername) < 3 ) {
285 DEBUGADD(4,("A print server must have at least 1 char ! %s\n", printername));
289 /* it's a print server */
290 if (!strchr(printername+2, '\\')) {
291 DEBUGADD(4,("Printer is a print server\n"));
292 Printer->printer_type = PRINTER_HANDLE_IS_PRINTSERVER;
297 DEBUGADD(4,("Printer is a printer\n"));
298 Printer->printer_type = PRINTER_HANDLE_IS_PRINTER;
305 /****************************************************************************
306 set printer handle printername.
307 ****************************************************************************/
308 static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername)
310 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
311 NT_PRINTER_INFO_LEVEL printer;
313 int n_services=lp_numservices();
317 if (!OPEN_HANDLE(Printer)) {
318 DEBUG(0,("Error setting printer name=%s\n", printername));
322 DEBUG(4,("Setting printer name=%s (len=%d)\n", printername, strlen(printername)));
324 if (Printer->printer_type==PRINTER_HANDLE_IS_PRINTSERVER) {
325 ZERO_STRUCT(Printer->dev.printerservername);
326 strncpy(Printer->dev.printerservername, printername, strlen(printername));
330 if (Printer->printer_type!=PRINTER_HANDLE_IS_PRINTER)
333 aprinter=strchr(printername+2, '\\');
336 DEBUGADD(5,("searching for [%s] (len=%d)\n", aprinter, strlen(aprinter)));
339 * store the Samba share name in it
340 * in back we have the long printer name
341 * need to iterate all the snum and do a
342 * get_a_printer each time to find the printer
343 * faster to do it here than later.
346 for (snum=0;snum<n_services && found==False;snum++) {
348 if ( !(lp_snum_ok(snum) && lp_print_ok(snum) ) )
351 DEBUGADD(5,("share:%s\n",lp_servicename(snum)));
353 if (get_a_printer(&printer, 2, lp_servicename(snum))!=0)
356 DEBUG(10,("set_printer_hnd_printername: printername [%s], aprinter [%s]\n",
357 printer.info_2->printername, aprinter ));
359 if ( strlen(printer.info_2->printername) != strlen(aprinter) ) {
360 free_a_printer(printer, 2);
364 if ( strncasecmp(printer.info_2->printername, aprinter, strlen(aprinter))) {
365 free_a_printer(printer, 2);
373 * if we haven't found a printer with the given printername
374 * then it can be a share name as you can open both \\server\printer and
379 * we still check if the printer description file exists as NT won't be happy
380 * if we reply OK in the openprinter call and can't reply in the subsequent RPC calls
384 DEBUGADD(5,("Printer not found, checking for share now\n"));
386 for (snum=0;snum<n_services && found==False;snum++) {
388 if ( !(lp_snum_ok(snum) && lp_print_ok(snum) ) )
391 DEBUGADD(5,("share:%s\n",lp_servicename(snum)));
393 if (get_a_printer(&printer, 2, lp_servicename(snum))!=0)
396 DEBUG(10,("set_printer_hnd_printername: printername [%s], aprinter [%s]\n",
397 printer.info_2->printername, aprinter ));
399 if ( strlen(lp_servicename(snum)) != strlen(aprinter) ) {
400 free_a_printer(printer, 2);
404 if ( strncasecmp(lp_servicename(snum), aprinter, strlen(aprinter))) {
405 free_a_printer(printer, 2);
414 DEBUGADD(4,("Printer not found\n"));
419 DEBUGADD(4,("Printer found: %s -> %s[%x]\n",printer.info_2->printername, lp_servicename(snum),snum));
420 ZERO_STRUCT(Printer->dev.printername);
421 strncpy(Printer->dev.printername, lp_servicename(snum), strlen(lp_servicename(snum)));
422 free_a_printer(printer, 2);
427 /********************************************************************
428 Return True is the handle is a print server.
429 ********************************************************************/
430 static BOOL handle_is_printserver(const POLICY_HND *handle)
432 Printer_entry *Printer=find_printer_index_by_hnd(handle);
434 if (!OPEN_HANDLE(Printer))
437 if (Printer->printer_type != PRINTER_HANDLE_IS_PRINTSERVER)
443 /****************************************************************************
444 allocate more memory for a BUFFER.
445 ****************************************************************************/
446 static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size)
454 /* damn, I'm doing the reverse operation of prs_grow() :) */
455 if (buffer_size < prs_data_size(ps))
458 extra_space = buffer_size - prs_data_size(ps);
461 * save the offset and move to the end of the buffer
462 * prs_grow() checks the extra_space against the offset
464 old_offset=prs_offset(ps);
465 prs_set_offset(ps, prs_data_size(ps));
467 if (!prs_grow(ps, extra_space))
470 prs_set_offset(ps, old_offset);
472 buffer->string_at_end=prs_data_size(ps);
477 /********************************************************************
478 * spoolss_open_printer
480 * called from the spoolss dispatcher
481 ********************************************************************/
482 uint32 _spoolss_open_printer_ex( const UNISTR2 *printername,
483 const PRINTER_DEFAULT *printer_default,
484 uint32 user_switch, SPOOL_USER_CTR user_ctr,
489 clear_handle(handle);
491 if (printername == NULL)
492 return ERROR_INVALID_PRINTER_NAME;
494 /* some sanity check because you can open a printer or a print server */
495 /* aka: \\server\printer or \\server */
496 unistr2_to_ascii(name, printername, sizeof(name)-1);
498 DEBUGADD(3,("checking name: %s\n",name));
500 create_printer_hnd(handle);
502 open_printer_hnd(handle);
504 if (!set_printer_hnd_printertype(handle, name)) {
505 close_printer_handle(handle);
506 return ERROR_INVALID_PRINTER_NAME;
509 if (!set_printer_hnd_printername(handle, name)) {
510 close_printer_handle(handle);
511 return ERROR_INVALID_PRINTER_NAME;
515 if (printer_default->datatype_ptr != NULL)
517 unistr2_to_ascii(datatype, printer_default->datatype, sizeof(datatype)-1);
518 set_printer_hnd_datatype(handle, datatype);
521 set_printer_hnd_datatype(handle, "");
524 if (!set_printer_hnd_accesstype(handle, printer_default->access_required)) {
525 close_printer_handle(handle);
526 return ERROR_ACCESS_DENIED;
529 return NT_STATUS_NO_PROBLEMO;
532 /****************************************************************************
533 ****************************************************************************/
534 static BOOL convert_printer_info(const SPOOL_PRINTER_INFO_LEVEL *uni,
535 NT_PRINTER_INFO_LEVEL *printer, uint32 level)
539 uni_2_asc_printer_info_2(uni->info_2, &(printer->info_2));
548 static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL *uni,
549 NT_PRINTER_DRIVER_INFO_LEVEL *printer, uint32 level)
553 printer->info_3=NULL;
554 uni_2_asc_printer_driver_3(uni->info_3, &(printer->info_3));
563 static BOOL convert_devicemode(DEVICEMODE devmode, NT_DEVICEMODE *nt_devmode)
565 unistr_to_ascii(nt_devmode->devicename, devmode.devicename.buffer, 31);
566 unistr_to_ascii(nt_devmode->formname, devmode.formname.buffer, 31);
568 nt_devmode->specversion=devmode.specversion;
569 nt_devmode->driverversion=devmode.driverversion;
570 nt_devmode->size=devmode.size;
571 nt_devmode->driverextra=devmode.driverextra;
572 nt_devmode->fields=devmode.fields;
573 nt_devmode->orientation=devmode.orientation;
574 nt_devmode->papersize=devmode.papersize;
575 nt_devmode->paperlength=devmode.paperlength;
576 nt_devmode->paperwidth=devmode.paperwidth;
577 nt_devmode->scale=devmode.scale;
578 nt_devmode->copies=devmode.copies;
579 nt_devmode->defaultsource=devmode.defaultsource;
580 nt_devmode->printquality=devmode.printquality;
581 nt_devmode->color=devmode.color;
582 nt_devmode->duplex=devmode.duplex;
583 nt_devmode->yresolution=devmode.yresolution;
584 nt_devmode->ttoption=devmode.ttoption;
585 nt_devmode->collate=devmode.collate;
587 nt_devmode->logpixels=devmode.logpixels;
588 nt_devmode->bitsperpel=devmode.bitsperpel;
589 nt_devmode->pelswidth=devmode.pelswidth;
590 nt_devmode->pelsheight=devmode.pelsheight;
591 nt_devmode->displayflags=devmode.displayflags;
592 nt_devmode->displayfrequency=devmode.displayfrequency;
593 nt_devmode->icmmethod=devmode.icmmethod;
594 nt_devmode->icmintent=devmode.icmintent;
595 nt_devmode->mediatype=devmode.mediatype;
596 nt_devmode->dithertype=devmode.dithertype;
597 nt_devmode->reserved1=devmode.reserved1;
598 nt_devmode->reserved2=devmode.reserved2;
599 nt_devmode->panningwidth=devmode.panningwidth;
600 nt_devmode->panningheight=devmode.panningheight;
602 if (nt_devmode->driverextra != 0)
604 /* if we had a previous private delete it and make a new one */
605 if (nt_devmode->private != NULL)
606 free(nt_devmode->private);
607 if((nt_devmode->private=(uint8 *)malloc(nt_devmode->driverextra * sizeof(uint8))) == NULL)
609 memcpy(nt_devmode->private, devmode.private, nt_devmode->driverextra);
615 /********************************************************************
616 * api_spoolss_closeprinter
617 ********************************************************************/
618 uint32 _spoolss_closeprinter(POLICY_HND *handle)
620 if (!close_printer_handle(handle))
621 return ERROR_INVALID_HANDLE;
623 return NT_STATUS_NO_PROBLEMO;
626 /********************************************************************
627 GetPrinterData on a printer server Handle.
628 ********************************************************************/
629 static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **data, uint32 *needed, uint32 in_size)
633 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
635 if (!strcmp(value, "BeepEnabled"))
638 if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL)
640 SIVAL(*data, 0, 0x01);
645 if (!strcmp(value, "EventLog"))
648 if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL)
650 SIVAL(*data, 0, 0x1B);
655 if (!strcmp(value, "NetPopup"))
658 if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL)
660 SIVAL(*data, 0, 0x01);
665 if (!strcmp(value, "MajorVersion"))
668 if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL)
670 SIVAL(*data, 0, 0x02);
675 if (!strcmp(value, "DefaultSpoolDirectory"))
677 pstring string="You are using a Samba server";
679 *needed = 2*(strlen(string)+1);
680 if((*data = (uint8 *)malloc( ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL)
682 memset(*data, 0, (*needed > in_size) ? *needed:in_size);
684 /* it's done by hand ready to go on the wire */
685 for (i=0; i<strlen(string); i++)
687 (*data)[2*i]=string[i];
693 if (!strcmp(value, "Architecture"))
695 pstring string="Windows NT x86";
697 *needed = 2*(strlen(string)+1);
698 if((*data = (uint8 *)malloc( ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL)
700 memset(*data, 0, (*needed > in_size) ? *needed:in_size);
701 for (i=0; i<strlen(string); i++)
703 (*data)[2*i]=string[i];
712 /********************************************************************
713 GetPrinterData on a printer Handle.
714 ********************************************************************/
715 static BOOL getprinterdata_printer(const POLICY_HND *handle,
716 fstring value, uint32 *type,
717 uint8 **data, uint32 *needed, uint32 in_size )
719 NT_PRINTER_INFO_LEVEL printer;
723 Printer_entry *Printer = find_printer_index_by_hnd(handle);
725 DEBUG(5,("getprinterdata_printer\n"));
727 if (!OPEN_HANDLE(Printer))
730 if(!get_printer_snum(handle, &snum))
733 if(get_a_printer(&printer, 2, lp_servicename(snum)) != 0)
736 if (!get_specific_param(printer, 2, value, &idata, type, &len)) {
737 free_a_printer(printer, 2);
741 DEBUG(5,("getprinterdata_printer:allocating %d\n", in_size));
743 if((*data = (uint8 *)malloc( in_size *sizeof(uint8) )) == NULL) {
744 free_a_printer(printer, 2);
748 memset(*data, 0, in_size *sizeof(uint8));
749 /* copy the min(in_size, len) */
750 memcpy(*data, idata, (len>in_size)?in_size:len *sizeof(uint8));
754 DEBUG(5,("getprinterdata_printer:copy done\n"));
756 free_a_printer(printer, 2);
762 /********************************************************************
763 * spoolss_getprinterdata
764 ********************************************************************/
765 uint32 _spoolss_getprinterdata(const POLICY_HND *handle, UNISTR2 *valuename,
774 Printer_entry *Printer = find_printer_index_by_hnd(handle);
777 * Reminder: when it's a string, the length is in BYTES
778 * even if UNICODE is negociated.
785 /* in case of problem, return some default values */
789 DEBUG(4,("_spoolss_getprinterdata\n"));
791 if (!OPEN_HANDLE(Printer)) {
792 if((*data=(uint8 *)malloc(4*sizeof(uint8))) == NULL)
793 return ERROR_NOT_ENOUGH_MEMORY;
794 return ERROR_INVALID_HANDLE;
797 unistr2_to_ascii(value, valuename, sizeof(value)-1);
799 if (handle_is_printserver(handle))
800 found=getprinterdata_printer_server(value, type, data, needed, *out_size);
802 found=getprinterdata_printer(handle, value, type, data, needed, *out_size);
805 DEBUG(5, ("value not found, allocating %d\n", *out_size));
806 /* reply this param doesn't exist */
807 if((*data=(uint8 *)malloc(*out_size*sizeof(uint8))) == NULL)
808 return ERROR_NOT_ENOUGH_MEMORY;
809 memset(*data, 0x0, *out_size*sizeof(uint8));
810 return ERROR_INVALID_PARAMETER;
813 if (*needed > *out_size)
814 return ERROR_INSUFFICIENT_BUFFER;
816 return NT_STATUS_NO_PROBLEMO;
819 /********************************************************************
821 * ReplyFindFirstPrinterChangeNotifyEx
823 * jfmxxxx: before replying OK: status=0
824 * should do a rpc call to the workstation asking ReplyOpenPrinter
825 * have to code it, later.
827 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
828 * called from api_spoolss_rffpcnex
829 ********************************************************************/
830 uint32 _spoolss_rffpcnex(const POLICY_HND *handle, uint32 flags, uint32 options,
831 const UNISTR2 *localmachine, uint32 printerlocal,
832 SPOOL_NOTIFY_OPTION *option)
834 /* store the notify value in the printer struct */
836 Printer_entry *Printer=find_printer_index_by_hnd(handle);
838 if (!OPEN_HANDLE(Printer))
839 return ERROR_INVALID_HANDLE;
841 Printer->notify.flags=flags;
842 Printer->notify.options=options;
843 Printer->notify.printerlocal=printerlocal;
844 Printer->notify.option=option;
845 unistr2_to_ascii(Printer->notify.localmachine, localmachine, sizeof(Printer->notify.localmachine)-1);
847 return NT_STATUS_NO_PROBLEMO;
850 /*******************************************************************
851 * fill a notify_info_data with the servername
852 ********************************************************************/
853 static void spoolss_notify_server_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
857 snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname);
859 data->notify_data.data.length=strlen(temp_name);
860 ascii_to_unistr(data->notify_data.data.string, temp_name, sizeof(data->notify_data.data.string)-1);
863 /*******************************************************************
864 * fill a notify_info_data with the servicename
865 * jfmxxxx: it's incorrect should be long_printername
866 ********************************************************************/
867 static void spoolss_notify_printer_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
870 data->notify_data.data.length=strlen(lp_servicename(snum));
871 ascii_to_unistr(data->notify_data.data.string, lp_servicename(snum), sizeof(data->notify_data.data.string)-1);
873 data->notify_data.data.length=strlen(printer->info_2->printername);
874 ascii_to_unistr(data->notify_data.data.string,
875 printer->info_2->printername,
876 sizeof(data->notify_data.data.string)-1);
879 /*******************************************************************
880 * fill a notify_info_data with the servicename
881 ********************************************************************/
882 static void spoolss_notify_share_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
884 data->notify_data.data.length=strlen(lp_servicename(snum));
885 ascii_to_unistr(data->notify_data.data.string,
886 lp_servicename(snum),
887 sizeof(data->notify_data.data.string)-1);
890 /*******************************************************************
891 * fill a notify_info_data with the port name
892 ********************************************************************/
893 static void spoolss_notify_port_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
895 /* even if it's strange, that's consistant in all the code */
897 data->notify_data.data.length=strlen(lp_servicename(snum));
898 ascii_to_unistr(data->notify_data.data.string,
899 lp_servicename(snum),
900 sizeof(data->notify_data.data.string)-1);
903 /*******************************************************************
904 * fill a notify_info_data with the printername
905 * jfmxxxx: it's incorrect, should be lp_printerdrivername()
906 * but it doesn't exist, have to see what to do
907 ********************************************************************/
908 static void spoolss_notify_driver_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
910 data->notify_data.data.length=strlen(printer->info_2->drivername);
911 ascii_to_unistr(data->notify_data.data.string,
912 printer->info_2->drivername,
913 sizeof(data->notify_data.data.string)-1);
916 /*******************************************************************
917 * fill a notify_info_data with the comment
918 ********************************************************************/
919 static void spoolss_notify_comment(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
921 data->notify_data.data.length=strlen(lp_comment(snum));
922 ascii_to_unistr(data->notify_data.data.string,
924 sizeof(data->notify_data.data.string)-1);
927 /*******************************************************************
928 * fill a notify_info_data with the comment
929 * jfm:xxxx incorrect, have to create a new smb.conf option
930 * location = "Room 1, floor 2, building 3"
931 ********************************************************************/
932 static void spoolss_notify_location(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
934 data->notify_data.data.length=strlen(printer->info_2->location);
935 ascii_to_unistr(data->notify_data.data.string,
936 printer->info_2->location,
937 sizeof(data->notify_data.data.string)-1);
940 /*******************************************************************
941 * fill a notify_info_data with the device mode
942 * jfm:xxxx don't to it for know but that's a real problem !!!
943 ********************************************************************/
944 static void spoolss_notify_devmode(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
948 /*******************************************************************
949 * fill a notify_info_data with the separator file name
950 * jfm:xxxx just return no file could add an option to smb.conf
951 * separator file = "separator.txt"
952 ********************************************************************/
953 static void spoolss_notify_sepfile(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
955 data->notify_data.data.length=strlen(printer->info_2->sepfile);
956 ascii_to_unistr(data->notify_data.data.string,
957 printer->info_2->sepfile,
958 sizeof(data->notify_data.data.string)-1);
961 /*******************************************************************
962 * fill a notify_info_data with the print processor
963 * jfm:xxxx return always winprint to indicate we don't do anything to it
964 ********************************************************************/
965 static void spoolss_notify_print_processor(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
967 data->notify_data.data.length=strlen(printer->info_2->printprocessor);
968 ascii_to_unistr(data->notify_data.data.string,
969 printer->info_2->printprocessor,
970 sizeof(data->notify_data.data.string)-1);
973 /*******************************************************************
974 * fill a notify_info_data with the print processor options
975 * jfm:xxxx send an empty string
976 ********************************************************************/
977 static void spoolss_notify_parameters(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
979 data->notify_data.data.length=strlen(printer->info_2->parameters);
980 ascii_to_unistr(data->notify_data.data.string,
981 printer->info_2->parameters,
982 sizeof(data->notify_data.data.string)-1);
985 /*******************************************************************
986 * fill a notify_info_data with the data type
987 * jfm:xxxx always send RAW as data type
988 ********************************************************************/
989 static void spoolss_notify_datatype(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
991 data->notify_data.data.length=strlen(printer->info_2->datatype);
992 ascii_to_unistr(data->notify_data.data.string,
993 printer->info_2->datatype,
994 sizeof(data->notify_data.data.string)-1);
997 /*******************************************************************
998 * fill a notify_info_data with the security descriptor
999 * jfm:xxxx send an null pointer to say no security desc
1000 * have to implement security before !
1001 ********************************************************************/
1002 static void spoolss_notify_security_desc(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1004 data->notify_data.data.length=0;
1005 data->notify_data.data.string[0]=0x00;
1008 /*******************************************************************
1009 * fill a notify_info_data with the attributes
1010 * jfm:xxxx a samba printer is always shared
1011 ********************************************************************/
1012 static void spoolss_notify_attributes(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1014 data->notify_data.value[0] = PRINTER_ATTRIBUTE_SHARED \
1015 | PRINTER_ATTRIBUTE_NETWORK \
1016 | PRINTER_ATTRIBUTE_RAW_ONLY ;
1019 /*******************************************************************
1020 * fill a notify_info_data with the priority
1021 ********************************************************************/
1022 static void spoolss_notify_priority(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1024 data->notify_data.value[0] = printer->info_2->priority;
1027 /*******************************************************************
1028 * fill a notify_info_data with the default priority
1029 ********************************************************************/
1030 static void spoolss_notify_default_priority(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1032 data->notify_data.value[0] = printer->info_2->default_priority;
1035 /*******************************************************************
1036 * fill a notify_info_data with the start time
1037 ********************************************************************/
1038 static void spoolss_notify_start_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1040 data->notify_data.value[0] = printer->info_2->starttime;
1043 /*******************************************************************
1044 * fill a notify_info_data with the until time
1045 ********************************************************************/
1046 static void spoolss_notify_until_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1048 data->notify_data.value[0] = printer->info_2->untiltime;
1051 /*******************************************************************
1052 * fill a notify_info_data with the status
1053 ********************************************************************/
1054 static void spoolss_notify_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1057 print_queue_struct *q=NULL;
1058 print_status_struct status;
1060 memset(&status, 0, sizeof(status));
1061 count = print_queue_status(snum, &q, &status);
1062 data->notify_data.value[0]=(uint32) status.status;
1066 /*******************************************************************
1067 * fill a notify_info_data with the number of jobs queued
1068 ********************************************************************/
1069 static void spoolss_notify_cjobs(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1071 print_queue_struct *q=NULL;
1072 print_status_struct status;
1074 memset(&status, 0, sizeof(status));
1075 data->notify_data.value[0] = print_queue_status(snum, &q, &status);
1079 /*******************************************************************
1080 * fill a notify_info_data with the average ppm
1081 ********************************************************************/
1082 static void spoolss_notify_average_ppm(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1084 /* always respond 8 pages per minutes */
1085 /* a little hard ! */
1086 data->notify_data.value[0] = printer->info_2->averageppm;
1089 /*******************************************************************
1090 * fill a notify_info_data with
1091 ********************************************************************/
1092 static void spoolss_notify_username(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1094 data->notify_data.data.length=strlen(queue->user);
1095 ascii_to_unistr(data->notify_data.data.string, queue->user, sizeof(data->notify_data.data.string)-1);
1098 /*******************************************************************
1099 * fill a notify_info_data with
1100 ********************************************************************/
1101 static void spoolss_notify_job_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1103 data->notify_data.value[0]=nt_printj_status(queue->status);
1106 /*******************************************************************
1107 * fill a notify_info_data with
1108 ********************************************************************/
1109 static void spoolss_notify_job_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1111 data->notify_data.data.length=strlen(queue->file);
1112 ascii_to_unistr(data->notify_data.data.string, queue->file, sizeof(data->notify_data.data.string)-1);
1115 /*******************************************************************
1116 * fill a notify_info_data with
1117 ********************************************************************/
1118 static void spoolss_notify_job_status_string(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1120 char *p = "unknown";
1121 switch (queue->status) {
1135 data->notify_data.data.length=strlen(p);
1136 ascii_to_unistr(data->notify_data.data.string, p, sizeof(data->notify_data.data.string)-1);
1139 /*******************************************************************
1140 * fill a notify_info_data with
1141 ********************************************************************/
1142 static void spoolss_notify_job_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1144 data->notify_data.value[0]=0x0;
1147 /*******************************************************************
1148 * fill a notify_info_data with
1149 ********************************************************************/
1150 static void spoolss_notify_job_size(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1152 data->notify_data.value[0]=queue->size;
1155 /*******************************************************************
1156 * fill a notify_info_data with
1157 ********************************************************************/
1158 static void spoolss_notify_job_position(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1160 data->notify_data.value[0]=queue->job;
1165 struct s_notify_info_data_table notify_info_data_table[] =
1167 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SERVER_NAME, "PRINTER_NOTIFY_SERVER_NAME", POINTER, spoolss_notify_server_name },
1168 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINTER_NAME, "PRINTER_NOTIFY_PRINTER_NAME", POINTER, spoolss_notify_printer_name },
1169 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SHARE_NAME, "PRINTER_NOTIFY_SHARE_NAME", POINTER, spoolss_notify_share_name },
1170 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PORT_NAME, "PRINTER_NOTIFY_PORT_NAME", POINTER, spoolss_notify_port_name },
1171 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DRIVER_NAME, "PRINTER_NOTIFY_DRIVER_NAME", POINTER, spoolss_notify_driver_name },
1172 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_COMMENT, "PRINTER_NOTIFY_COMMENT", POINTER, spoolss_notify_comment },
1173 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_LOCATION, "PRINTER_NOTIFY_LOCATION", POINTER, spoolss_notify_location },
1174 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DEVMODE, "PRINTER_NOTIFY_DEVMODE", POINTER, spoolss_notify_devmode },
1175 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SEPFILE, "PRINTER_NOTIFY_SEPFILE", POINTER, spoolss_notify_sepfile },
1176 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINT_PROCESSOR, "PRINTER_NOTIFY_PRINT_PROCESSOR", POINTER, spoolss_notify_print_processor },
1177 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PARAMETERS, "PRINTER_NOTIFY_PARAMETERS", POINTER, spoolss_notify_parameters },
1178 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DATATYPE, "PRINTER_NOTIFY_DATATYPE", POINTER, spoolss_notify_datatype },
1179 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_SECURITY_DESCRIPTOR", POINTER, spoolss_notify_security_desc },
1180 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_ATTRIBUTES, "PRINTER_NOTIFY_ATTRIBUTES", ONE_VALUE, spoolss_notify_attributes },
1181 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRIORITY, "PRINTER_NOTIFY_PRIORITY", ONE_VALUE, spoolss_notify_priority },
1182 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DEFAULT_PRIORITY, "PRINTER_NOTIFY_DEFAULT_PRIORITY", ONE_VALUE, spoolss_notify_default_priority },
1183 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_START_TIME, "PRINTER_NOTIFY_START_TIME", ONE_VALUE, spoolss_notify_start_time },
1184 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_UNTIL_TIME, "PRINTER_NOTIFY_UNTIL_TIME", ONE_VALUE, spoolss_notify_until_time },
1185 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_STATUS, "PRINTER_NOTIFY_STATUS", ONE_VALUE, spoolss_notify_status },
1186 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_STATUS_STRING, "PRINTER_NOTIFY_STATUS_STRING", POINTER, NULL },
1187 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_CJOBS, "PRINTER_NOTIFY_CJOBS", ONE_VALUE, spoolss_notify_cjobs },
1188 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_AVERAGE_PPM, "PRINTER_NOTIFY_AVERAGE_PPM", ONE_VALUE, spoolss_notify_average_ppm },
1189 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_PAGES, "PRINTER_NOTIFY_TOTAL_PAGES", POINTER, NULL },
1190 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PAGES_PRINTED, "PRINTER_NOTIFY_PAGES_PRINTED", POINTER, NULL },
1191 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_BYTES, "PRINTER_NOTIFY_TOTAL_BYTES", POINTER, NULL },
1192 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_BYTES_PRINTED, "PRINTER_NOTIFY_BYTES_PRINTED", POINTER, NULL },
1193 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINTER_NAME, "JOB_NOTIFY_PRINTER_NAME", POINTER, spoolss_notify_printer_name },
1194 { JOB_NOTIFY_TYPE, JOB_NOTIFY_MACHINE_NAME, "JOB_NOTIFY_MACHINE_NAME", POINTER, spoolss_notify_server_name },
1195 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PORT_NAME, "JOB_NOTIFY_PORT_NAME", POINTER, spoolss_notify_port_name },
1196 { JOB_NOTIFY_TYPE, JOB_NOTIFY_USER_NAME, "JOB_NOTIFY_USER_NAME", POINTER, spoolss_notify_username },
1197 { JOB_NOTIFY_TYPE, JOB_NOTIFY_NOTIFY_NAME, "JOB_NOTIFY_NOTIFY_NAME", POINTER, spoolss_notify_username },
1198 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DATATYPE, "JOB_NOTIFY_DATATYPE", POINTER, spoolss_notify_datatype },
1199 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINT_PROCESSOR, "JOB_NOTIFY_PRINT_PROCESSOR", POINTER, spoolss_notify_print_processor },
1200 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PARAMETERS, "JOB_NOTIFY_PARAMETERS", POINTER, spoolss_notify_parameters },
1201 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DRIVER_NAME, "JOB_NOTIFY_DRIVER_NAME", POINTER, spoolss_notify_driver_name },
1202 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DEVMODE, "JOB_NOTIFY_DEVMODE", POINTER, spoolss_notify_devmode },
1203 { JOB_NOTIFY_TYPE, JOB_NOTIFY_STATUS, "JOB_NOTIFY_STATUS", ONE_VALUE, spoolss_notify_job_status },
1204 { JOB_NOTIFY_TYPE, JOB_NOTIFY_STATUS_STRING, "JOB_NOTIFY_STATUS_STRING", POINTER, spoolss_notify_job_status_string },
1205 { JOB_NOTIFY_TYPE, JOB_NOTIFY_SECURITY_DESCRIPTOR, "JOB_NOTIFY_SECURITY_DESCRIPTOR", POINTER, NULL },
1206 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DOCUMENT, "JOB_NOTIFY_DOCUMENT", POINTER, spoolss_notify_job_name },
1207 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRIORITY, "JOB_NOTIFY_PRIORITY", ONE_VALUE, spoolss_notify_priority },
1208 { JOB_NOTIFY_TYPE, JOB_NOTIFY_POSITION, "JOB_NOTIFY_POSITION", ONE_VALUE, spoolss_notify_job_position },
1209 { JOB_NOTIFY_TYPE, JOB_NOTIFY_SUBMITTED, "JOB_NOTIFY_SUBMITTED", POINTER, NULL },
1210 { JOB_NOTIFY_TYPE, JOB_NOTIFY_START_TIME, "JOB_NOTIFY_START_TIME", ONE_VALUE, spoolss_notify_start_time },
1211 { JOB_NOTIFY_TYPE, JOB_NOTIFY_UNTIL_TIME, "JOB_NOTIFY_UNTIL_TIME", ONE_VALUE, spoolss_notify_until_time },
1212 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TIME, "JOB_NOTIFY_TIME", ONE_VALUE, spoolss_notify_job_time },
1213 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_PAGES, "JOB_NOTIFY_TOTAL_PAGES", ONE_VALUE, NULL },
1214 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PAGES_PRINTED, "JOB_NOTIFY_PAGES_PRINTED", ONE_VALUE, NULL },
1215 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_BYTES, "JOB_NOTIFY_TOTAL_BYTES", ONE_VALUE, spoolss_notify_job_size },
1216 { JOB_NOTIFY_TYPE, JOB_NOTIFY_BYTES_PRINTED, "JOB_NOTIFY_BYTES_PRINTED", ONE_VALUE, NULL },
1217 { END, END, "", END, NULL }
1220 /*******************************************************************
1221 return the size of info_data structure
1222 ********************************************************************/
1223 static uint32 size_of_notify_info_data(uint16 type, uint16 field)
1227 while (notify_info_data_table[i].type != END)
1229 if ( (notify_info_data_table[i].type == type ) &&
1230 (notify_info_data_table[i].field == field ) )
1232 return (notify_info_data_table[i].size);
1240 /*******************************************************************
1241 return the type of notify_info_data
1242 ********************************************************************/
1243 static BOOL type_of_notify_info_data(uint16 type, uint16 field)
1247 while (notify_info_data_table[i].type != END)
1249 if ( (notify_info_data_table[i].type == type ) &&
1250 (notify_info_data_table[i].field == field ) )
1252 if (notify_info_data_table[i].size == POINTER)
1267 /****************************************************************************
1268 ****************************************************************************/
1269 static int search_notify(uint16 type, uint16 field, int *value)
1274 for (j=0, found=False; found==False && notify_info_data_table[j].type != END ; j++)
1276 if ( (notify_info_data_table[j].type == type ) &&
1277 (notify_info_data_table[j].field == field ) )
1282 if ( found && (notify_info_data_table[j].fn != NULL) )
1288 /****************************************************************************
1289 ****************************************************************************/
1290 static void construct_info_data(SPOOL_NOTIFY_INFO_DATA *info_data, uint16 type, uint16 field, int id)
1292 info_data->type = type;
1293 info_data->field = field;
1294 info_data->reserved = 0;
1296 info_data->size = size_of_notify_info_data(type, field);
1297 info_data->enc_type = type_of_notify_info_data(type, field);
1301 /*******************************************************************
1303 * fill a notify_info struct with info asked
1305 ********************************************************************/
1306 static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPOOL_NOTIFY_OPTION_TYPE *option_type, uint32 id)
1312 SPOOL_NOTIFY_INFO_DATA *current_data;
1313 NT_PRINTER_INFO_LEVEL printer;
1314 print_queue_struct *queue=NULL;
1316 DEBUG(4,("construct_notify_printer_info\n"));
1318 type=option_type->type;
1320 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
1321 (option_type->type==PRINTER_NOTIFY_TYPE?"PRINTER_NOTIFY_TYPE":"JOB_NOTIFY_TYPE"),
1322 option_type->count, lp_servicename(snum)));
1324 if (get_a_printer(&printer, 2, lp_servicename(snum))!=0)
1329 for(field_num=0; field_num<option_type->count; field_num++)
1331 field = option_type->fields[field_num];
1332 DEBUGADD(4,("notify [%d]: type [%x], field [%x]\n", field_num, type, field));
1334 if (!search_notify(type, field, &j) )
1337 if((info->data=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) {
1338 free_a_printer(printer, 2);
1341 current_data=&(info->data[info->count]);
1343 construct_info_data(current_data, type, field, id);
1344 notify_info_data_table[j].fn(snum, current_data, queue, &printer);
1349 free_a_printer(printer, 2);
1353 /*******************************************************************
1355 * fill a notify_info struct with info asked
1357 ********************************************************************/
1358 static BOOL construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_INFO *info, int snum, SPOOL_NOTIFY_OPTION_TYPE *option_type, uint32 id)
1364 SPOOL_NOTIFY_INFO_DATA *current_data;
1365 NT_PRINTER_INFO_LEVEL printer;
1367 DEBUG(4,("construct_notify_jobs_info\n"));
1369 type = option_type->type;
1371 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
1372 (option_type->type==PRINTER_NOTIFY_TYPE?"PRINTER_NOTIFY_TYPE":"JOB_NOTIFY_TYPE"),
1373 option_type->count));
1375 if (get_a_printer(&printer, 2, lp_servicename(snum))!=0)
1380 for(field_num=0; field_num<option_type->count; field_num++)
1382 field = option_type->fields[field_num];
1384 if (!search_notify(type, field, &j) )
1387 if((info->data=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) {
1388 free_a_printer(printer, 2);
1392 current_data=&(info->data[info->count]);
1394 construct_info_data(current_data, type, field, id);
1395 notify_info_data_table[j].fn(snum, current_data, queue, &printer);
1399 free_a_printer(printer, 2);
1405 * JFM: The enumeration is not that simple, it's even non obvious.
1407 * let's take an example: I want to monitor the PRINTER SERVER for
1408 * the printer's name and the number of jobs currently queued.
1409 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
1410 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
1412 * I have 3 printers on the back of my server.
1414 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
1417 * 1 printer 1 name 1
1418 * 2 printer 1 cjob 1
1419 * 3 printer 2 name 2
1420 * 4 printer 2 cjob 2
1421 * 5 printer 3 name 3
1422 * 6 printer 3 name 3
1424 * that's the print server case, the printer case is even worse.
1429 /*******************************************************************
1431 * enumerate all printers on the printserver
1432 * fill a notify_info struct with info asked
1434 ********************************************************************/
1435 static uint32 printserver_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info)
1438 Printer_entry *Printer=find_printer_index_by_hnd(hnd);
1439 int n_services=lp_numservices();
1442 SPOOL_NOTIFY_OPTION *option;
1443 SPOOL_NOTIFY_OPTION_TYPE *option_type;
1445 DEBUG(4,("printserver_notify_info\n"));
1447 option=Printer->notify.option;
1453 for (i=0; i<option->count; i++)
1455 option_type=&(option->ctr.type[i]);
1457 if (option_type->type!=PRINTER_NOTIFY_TYPE)
1460 for (snum=0; snum<n_services; snum++)
1461 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
1462 if (construct_notify_printer_info(info, snum, option_type, id))
1467 * Debugging information, don't delete.
1470 DEBUG(1,("dumping the NOTIFY_INFO\n"));
1471 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
1472 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
1474 for (i=0; i<info->count; i++)
1476 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
1477 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
1478 info->data[i].id, info->data[i].size, info->data[i].enc_type));
1482 return NT_STATUS_NO_PROBLEMO;
1485 /*******************************************************************
1487 * fill a notify_info struct with info asked
1489 ********************************************************************/
1490 static uint32 printer_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info)
1493 Printer_entry *Printer=find_printer_index_by_hnd(hnd);
1496 SPOOL_NOTIFY_OPTION *option;
1497 SPOOL_NOTIFY_OPTION_TYPE *option_type;
1499 print_queue_struct *queue=NULL;
1500 print_status_struct status;
1502 DEBUG(4,("printer_notify_info\n"));
1504 option=Printer->notify.option;
1510 get_printer_snum(hnd, &snum);
1512 for (i=0; i<option->count; i++)
1514 option_type=&(option->ctr.type[i]);
1516 switch ( option_type->type ) {
1517 case PRINTER_NOTIFY_TYPE:
1518 if(construct_notify_printer_info(info, snum, option_type, id))
1522 case JOB_NOTIFY_TYPE:
1523 memset(&status, 0, sizeof(status));
1524 count = print_queue_status(snum, &queue, &status);
1525 for (j=0; j<count; j++)
1526 construct_notify_jobs_info(&(queue[j]), info, snum, option_type, queue[j].job);
1533 * Debugging information, don't delete.
1536 DEBUG(1,("dumping the NOTIFY_INFO\n"));
1537 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
1538 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
1540 for (i=0; i<info->count; i++)
1542 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
1543 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
1544 info->data[i].id, info->data[i].size, info->data[i].enc_type));
1547 return NT_STATUS_NO_PROBLEMO;
1550 /********************************************************************
1552 ********************************************************************/
1553 uint32 _spoolss_rfnpcnex( const POLICY_HND *handle, uint32 change,
1554 SPOOL_NOTIFY_OPTION *option, SPOOL_NOTIFY_INFO *info)
1556 Printer_entry *Printer=find_printer_index_by_hnd(handle);
1558 if (!OPEN_HANDLE(Printer))
1559 return ERROR_INVALID_HANDLE;
1561 DEBUG(4,("Printer type %x\n",Printer->printer_type));
1563 /* jfm: the change value isn't used right now.
1564 * we will honour it when
1565 * a) we'll be able to send notification to the client
1566 * b) we'll have a way to communicate between the spoolss process.
1568 * same thing for option->flags
1569 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
1570 * I don't have a global notification system, I'm sending back all the
1571 * informations even when _NOTHING_ has changed.
1574 /* just discard the SPOOL_NOTIFY_OPTION */
1576 safe_free(option->ctr.type);
1578 switch (Printer->printer_type) {
1579 case PRINTER_HANDLE_IS_PRINTSERVER:
1580 return printserver_notify_info(handle, info);
1582 case PRINTER_HANDLE_IS_PRINTER:
1583 return printer_notify_info(handle, info);
1587 return ERROR_INVALID_HANDLE;
1590 /********************************************************************
1591 * construct_printer_info_0
1592 * fill a printer_info_1 struct
1593 ********************************************************************/
1594 static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, pstring servername)
1598 NT_PRINTER_INFO_LEVEL ntprinter;
1599 counter_printer_0 *session_counter;
1600 uint32 global_counter;
1603 print_queue_struct *queue=NULL;
1604 print_status_struct status;
1606 memset(&status, 0, sizeof(status));
1608 if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) != 0)
1611 count = print_queue_status(snum, &queue, &status);
1613 /* check if we already have a counter for this printer */
1614 session_counter = (counter_printer_0 *)ubi_dlFirst(&counter_list);
1616 for(; session_counter; session_counter = (counter_printer_0 *)ubi_dlNext(session_counter)) {
1617 if (session_counter->snum == snum)
1621 /* it's the first time, add it to the list */
1622 if (session_counter==NULL) {
1623 if((session_counter=(counter_printer_0 *)malloc(sizeof(counter_printer_0))) == NULL)
1625 ZERO_STRUCTP(session_counter);
1626 session_counter->snum=snum;
1627 session_counter->counter=0;
1628 ubi_dlAddHead( &counter_list, (ubi_dlNode *)session_counter);
1632 session_counter->counter++;
1635 * the global_counter should be stored in a TDB as it's common to all the clients
1636 * and should be zeroed on samba startup
1638 global_counter=session_counter->counter;
1640 /* the description and the name are of the form \\server\share */
1641 slprintf(chaine,sizeof(chaine)-1,"\\\\%s\\%s",servername, ntprinter.info_2->printername);
1643 init_unistr(&(printer->printername), chaine);
1645 slprintf(chaine,sizeof(chaine)-1,"\\\\%s", servername);
1646 init_unistr(&(printer->servername), chaine);
1648 printer->cjobs = count;
1649 printer->total_jobs = 0;
1650 printer->total_bytes = 0;
1652 t=gmtime(&ntprinter.info_2->setuptime);
1654 printer->year = t->tm_year+1900;
1655 printer->month = t->tm_mon+1;
1656 printer->dayofweek = t->tm_wday;
1657 printer->day = t->tm_mday;
1658 printer->hour = t->tm_hour;
1659 printer->minute = t->tm_min;
1660 printer->second = t->tm_sec;
1661 printer->milliseconds = 0;
1663 printer->global_counter = global_counter;
1664 printer->total_pages = 0;
1665 printer->major_version = 0x0004; /* NT 4 */
1666 printer->build_version = 0x0565; /* build 1381 */
1667 printer->unknown7 = 0x1;
1668 printer->unknown8 = 0x0;
1669 printer->unknown9 = 0x0;
1670 printer->session_counter = session_counter->counter;
1671 printer->unknown11 = 0x0;
1672 printer->printer_errors = 0x0; /* number of print failure */
1673 printer->unknown13 = 0x0;
1674 printer->unknown14 = 0x1;
1675 printer->unknown15 = 0x024a; /* 586 Pentium ? */
1676 printer->unknown16 = 0x0;
1677 printer->change_id = ntprinter.info_2->changeid; /* ChangeID in milliseconds*/
1678 printer->unknown18 = 0x0;
1679 printer->status = nt_printq_status(status.status);
1680 printer->unknown20 = 0x0;
1681 printer->c_setprinter = ntprinter.info_2->c_setprinter; /* how many times setprinter has been called */
1682 printer->unknown22 = 0x0;
1683 printer->unknown23 = 0x6; /* 6 ???*/
1684 printer->unknown24 = 0; /* unknown 24 to 26 are always 0 */
1685 printer->unknown25 = 0;
1686 printer->unknown26 = 0;
1687 printer->unknown27 = 0;
1688 printer->unknown28 = 0;
1689 printer->unknown29 = 0;
1693 free_a_printer(ntprinter, 2);
1697 /********************************************************************
1698 * construct_printer_info_1
1699 * fill a printer_info_1 struct
1700 ********************************************************************/
1701 static BOOL construct_printer_info_1(fstring server, uint32 flags, PRINTER_INFO_1 *printer, int snum)
1705 NT_PRINTER_INFO_LEVEL ntprinter;
1707 if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) != 0)
1710 printer->flags=flags;
1712 snprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",server, ntprinter.info_2->printername,
1713 ntprinter.info_2->drivername, lp_comment(snum));
1715 snprintf(chaine2,sizeof(chaine)-1,"%s%s", server, ntprinter.info_2->printername);
1717 init_unistr(&printer->description, chaine);
1718 init_unistr(&printer->name, chaine2);
1719 init_unistr(&printer->comment, lp_comment(snum));
1721 free_a_printer(ntprinter, 2);
1726 /****************************************************************************
1727 ****************************************************************************/
1728 static BOOL construct_dev_mode(DEVICEMODE *devmode, int snum, char *servername)
1732 NT_PRINTER_INFO_LEVEL printer;
1733 NT_DEVICEMODE *ntdevmode;
1735 DEBUG(7,("construct_dev_mode\n"));
1737 memset(&(devmode->devicename), 0, 2*sizeof(adevice));
1738 memset(&(devmode->formname), 0, 2*sizeof(aform));
1740 DEBUGADD(8,("getting printer characteristics\n"));
1742 get_a_printer(&printer, 2, lp_servicename(snum));
1743 ntdevmode=(printer.info_2)->devmode;
1745 DEBUGADD(8,("loading DEVICEMODE\n"));
1746 snprintf(adevice, sizeof(adevice), "\\\\%s\\%s", global_myname,
1747 printer.info_2->printername);
1748 init_unistr(&(devmode->devicename), adevice);
1750 snprintf(aform, sizeof(aform), ntdevmode->formname);
1751 init_unistr(&(devmode->formname), aform);
1753 devmode->specversion = ntdevmode->specversion;
1754 devmode->driverversion = ntdevmode->driverversion;
1755 devmode->size = ntdevmode->size;
1756 devmode->driverextra = ntdevmode->driverextra;
1757 devmode->fields = ntdevmode->fields;
1759 devmode->orientation = ntdevmode->orientation;
1760 devmode->papersize = ntdevmode->papersize;
1761 devmode->paperlength = ntdevmode->paperlength;
1762 devmode->paperwidth = ntdevmode->paperwidth;
1763 devmode->scale = ntdevmode->scale;
1764 devmode->copies = ntdevmode->copies;
1765 devmode->defaultsource = ntdevmode->defaultsource;
1766 devmode->printquality = ntdevmode->printquality;
1767 devmode->color = ntdevmode->color;
1768 devmode->duplex = ntdevmode->duplex;
1769 devmode->yresolution = ntdevmode->yresolution;
1770 devmode->ttoption = ntdevmode->ttoption;
1771 devmode->collate = ntdevmode->collate;
1772 devmode->icmmethod = ntdevmode->icmmethod;
1773 devmode->icmintent = ntdevmode->icmintent;
1774 devmode->mediatype = ntdevmode->mediatype;
1775 devmode->dithertype = ntdevmode->dithertype;
1777 if (ntdevmode->private != NULL)
1779 if((devmode->private=(uint8 *)malloc(devmode->driverextra*sizeof(uint8))) == NULL) {
1780 free_a_printer(printer, 2);
1783 memcpy(devmode->private, ntdevmode->private, devmode->driverextra);
1786 free_a_printer(printer, 2);
1791 /********************************************************************
1792 * construct_printer_info_2
1793 * fill a printer_info_2 struct
1794 ********************************************************************/
1795 static BOOL construct_printer_info_2(fstring servername, PRINTER_INFO_2 *printer, int snum)
1801 DEVICEMODE *devmode;
1802 NT_PRINTER_INFO_LEVEL ntprinter;
1804 print_queue_struct *queue=NULL;
1805 print_status_struct status;
1806 memset(&status, 0, sizeof(status));
1808 if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0 )
1811 memset(&status, 0, sizeof(status));
1812 count = print_queue_status(snum, &queue, &status);
1814 snprintf(chaine, sizeof(chaine)-1, "%s", servername);
1816 if (strlen(servername)!=0)
1821 snprintf(chaine2, sizeof(chaine)-1, "%s%s%s", servername, sl, ntprinter.info_2->printername);
1823 init_unistr(&printer->servername, chaine); /* servername*/
1824 init_unistr(&printer->printername, chaine2); /* printername*/
1825 init_unistr(&printer->sharename, lp_servicename(snum)); /* sharename */
1826 init_unistr(&printer->portname, lp_servicename(snum)); /* port */
1827 init_unistr(&printer->drivername, ntprinter.info_2->drivername); /* drivername */
1828 init_unistr(&printer->comment, lp_comment(snum)); /* comment */
1829 init_unistr(&printer->location, ntprinter.info_2->location); /* location */
1830 init_unistr(&printer->sepfile, ntprinter.info_2->sepfile); /* separator file */
1831 init_unistr(&printer->printprocessor, ntprinter.info_2->printprocessor);/* print processor */
1832 init_unistr(&printer->datatype, ntprinter.info_2->datatype); /* datatype */
1833 init_unistr(&printer->parameters, ntprinter.info_2->parameters); /* parameters (of print processor) */
1835 printer->attributes = PRINTER_ATTRIBUTE_SHARED \
1836 | PRINTER_ATTRIBUTE_LOCAL \
1837 | PRINTER_ATTRIBUTE_RAW_ONLY ; /* attributes */
1839 printer->priority = ntprinter.info_2->priority; /* priority */
1840 printer->defaultpriority = ntprinter.info_2->default_priority; /* default priority */
1841 printer->starttime = ntprinter.info_2->starttime; /* starttime */
1842 printer->untiltime = ntprinter.info_2->untiltime; /* untiltime */
1843 printer->status = nt_printq_status(status.status); /* status */
1844 printer->cjobs = count; /* jobs */
1845 printer->averageppm = ntprinter.info_2->averageppm; /* average pages per minute */
1847 if((devmode=(DEVICEMODE *)malloc(sizeof(DEVICEMODE))) == NULL)
1850 ZERO_STRUCTP(devmode);
1852 if(!construct_dev_mode(devmode, snum, servername))
1855 printer->devmode=devmode;
1858 free_a_printer(ntprinter, 2);
1864 free_a_printer(ntprinter, 2);
1868 /********************************************************************
1869 Spoolss_enumprinters.
1870 ********************************************************************/
1871 static BOOL enum_all_printers_info_1(fstring server, uint32 flags, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
1875 int n_services=lp_numservices();
1876 PRINTER_INFO_1 *printers=NULL;
1877 PRINTER_INFO_1 current_prt;
1879 DEBUG(4,("enum_all_printers_info_1\n"));
1881 for (snum=0; snum<n_services; snum++) {
1882 if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
1883 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum));
1885 if (construct_printer_info_1(server, flags, ¤t_prt, snum)) {
1886 if((printers=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_1))) == NULL) {
1888 return ERROR_NOT_ENOUGH_MEMORY;
1890 DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_1\n", *returned));
1891 memcpy(&(printers[*returned]), ¤t_prt, sizeof(PRINTER_INFO_1));
1897 /* check the required size. */
1898 for (i=0; i<*returned; i++)
1899 (*needed) += spoolss_size_printer_info_1(&(printers[i]));
1901 if (!alloc_buffer_size(buffer, *needed))
1902 return ERROR_INSUFFICIENT_BUFFER;
1904 /* fill the buffer with the structures */
1905 for (i=0; i<*returned; i++)
1906 new_smb_io_printer_info_1("", buffer, &(printers[i]), 0);
1909 safe_free(printers);
1911 if (*needed > offered) {
1913 return ERROR_INSUFFICIENT_BUFFER;
1916 return NT_STATUS_NO_PROBLEMO;
1919 /********************************************************************
1920 enum_all_printers_info_1_local.
1921 *********************************************************************/
1922 static BOOL enum_all_printers_info_1_local(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
1925 DEBUG(4,("enum_all_printers_info_1_local\n"));
1927 fstrcpy(temp, "\\\\");
1928 fstrcat(temp, global_myname);
1930 if (!strcmp(name, temp)) {
1931 fstrcat(temp, "\\");
1932 return enum_all_printers_info_1(temp, PRINTER_ENUM_ICON8, buffer, offered, needed, returned);
1935 return enum_all_printers_info_1("", PRINTER_ENUM_ICON8, buffer, offered, needed, returned);
1938 /********************************************************************
1939 enum_all_printers_info_1_name.
1940 *********************************************************************/
1941 static BOOL enum_all_printers_info_1_name(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
1944 DEBUG(4,("enum_all_printers_info_1_name\n"));
1946 fstrcpy(temp, "\\\\");
1947 fstrcat(temp, global_myname);
1949 if (!strcmp(name, temp)) {
1950 fstrcat(temp, "\\");
1951 return enum_all_printers_info_1(temp, PRINTER_ENUM_ICON8, buffer, offered, needed, returned);
1954 return ERROR_INVALID_NAME;
1957 /********************************************************************
1958 enum_all_printers_info_1_remote.
1959 *********************************************************************/
1960 static BOOL enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
1962 PRINTER_INFO_1 *printer;
1963 fstring printername;
1966 DEBUG(4,("enum_all_printers_info_1_remote\n"));
1968 /* JFM: currently it's more a place holder than anything else.
1969 * In the spooler world there is a notion of server registration.
1970 * the print servers are registring (sp ?) on the PDC (in the same domain)
1972 * We should have a TDB here. The registration is done thru an undocumented RPC call.
1975 if((printer=(PRINTER_INFO_1 *)malloc(sizeof(PRINTER_INFO_1))) == NULL)
1976 return ERROR_NOT_ENOUGH_MEMORY;
1980 snprintf(printername, sizeof(printername)-1,"Windows NT Remote Printers!!\\\\%s", global_myname);
1981 snprintf(desc, sizeof(desc)-1,"%s", global_myname);
1982 snprintf(comment, sizeof(comment)-1, "Logged on Domain");
1984 init_unistr(&printer->description, desc);
1985 init_unistr(&printer->name, printername);
1986 init_unistr(&printer->comment, comment);
1987 printer->flags=PRINTER_ENUM_ICON3|PRINTER_ENUM_CONTAINER;
1989 /* check the required size. */
1990 *needed += spoolss_size_printer_info_1(printer);
1992 if (!alloc_buffer_size(buffer, *needed)) {
1994 return ERROR_INSUFFICIENT_BUFFER;
1997 /* fill the buffer with the structures */
1998 new_smb_io_printer_info_1("", buffer, printer, 0);
2003 if (*needed > offered) {
2005 return ERROR_INSUFFICIENT_BUFFER;
2008 return NT_STATUS_NO_PROBLEMO;
2011 /********************************************************************
2012 enum_all_printers_info_1_network.
2013 *********************************************************************/
2014 static BOOL enum_all_printers_info_1_network(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
2017 DEBUG(4,("enum_all_printers_info_1_network\n"));
2019 fstrcpy(temp, "\\\\");
2020 fstrcat(temp, global_myname);
2021 fstrcat(temp, "\\");
2022 return enum_all_printers_info_1(temp, PRINTER_ENUM_UNKNOWN_8, buffer, offered, needed, returned);
2025 /********************************************************************
2026 * api_spoolss_enumprinters
2028 * called from api_spoolss_enumprinters (see this to understand)
2029 ********************************************************************/
2030 static BOOL enum_all_printers_info_2(fstring servername, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
2034 int n_services=lp_numservices();
2035 PRINTER_INFO_2 *printers=NULL;
2036 PRINTER_INFO_2 current_prt;
2038 for (snum=0; snum<n_services; snum++) {
2039 if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
2040 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum));
2042 if (construct_printer_info_2(servername, ¤t_prt, snum)) {
2043 if((printers=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_2))) == NULL)
2044 return ERROR_NOT_ENOUGH_MEMORY;
2045 DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_2\n", *returned));
2046 memcpy(&(printers[*returned]), ¤t_prt, sizeof(PRINTER_INFO_2));
2052 /* check the required size. */
2053 for (i=0; i<*returned; i++)
2054 (*needed) += spoolss_size_printer_info_2(&(printers[i]));
2056 if (!alloc_buffer_size(buffer, *needed)) {
2057 for (i=0; i<*returned; i++) {
2058 safe_free(printers[i].devmode->private);
2059 safe_free(printers[i].devmode);
2061 safe_free(printers);
2062 return ERROR_INSUFFICIENT_BUFFER;
2065 /* fill the buffer with the structures */
2066 for (i=0; i<*returned; i++)
2067 new_smb_io_printer_info_2("", buffer, &(printers[i]), 0);
2070 for (i=0; i<*returned; i++) {
2071 safe_free(printers[i].devmode->private);
2072 safe_free(printers[i].devmode);
2074 safe_free(printers);
2076 if (*needed > offered) {
2078 return ERROR_INSUFFICIENT_BUFFER;
2081 return NT_STATUS_NO_PROBLEMO;
2084 /********************************************************************
2085 * handle enumeration of printers at level 1
2086 ********************************************************************/
2087 static uint32 enumprinters_level1( uint32 flags, fstring name,
2088 NEW_BUFFER *buffer, uint32 offered,
2089 uint32 *needed, uint32 *returned)
2091 /* Not all the flags are equals */
2093 if (flags & PRINTER_ENUM_LOCAL)
2094 return enum_all_printers_info_1_local(name, buffer, offered, needed, returned);
2096 if (flags & PRINTER_ENUM_NAME)
2097 return enum_all_printers_info_1_name(name, buffer, offered, needed, returned);
2099 if (flags & PRINTER_ENUM_REMOTE)
2100 return enum_all_printers_info_1_remote(name, buffer, offered, needed, returned);
2102 if (flags & PRINTER_ENUM_NETWORK)
2103 return enum_all_printers_info_1_network(name, buffer, offered, needed, returned);
2105 return NT_STATUS_NO_PROBLEMO; /* NT4sp5 does that */
2108 /********************************************************************
2109 * handle enumeration of printers at level 2
2110 ********************************************************************/
2111 static uint32 enumprinters_level2( uint32 flags, fstring servername,
2112 NEW_BUFFER *buffer, uint32 offered,
2113 uint32 *needed, uint32 *returned)
2117 fstrcpy(temp, "\\\\");
2118 fstrcat(temp, global_myname);
2120 if (flags & PRINTER_ENUM_LOCAL) {
2121 if (!strcmp(servername, temp))
2122 return enum_all_printers_info_2(temp, buffer, offered, needed, returned);
2124 return enum_all_printers_info_2("", buffer, offered, needed, returned);
2127 if (flags & PRINTER_ENUM_NAME) {
2128 if (!strcmp(servername, temp))
2129 return enum_all_printers_info_2(temp, buffer, offered, needed, returned);
2131 return ERROR_INVALID_NAME;
2134 if (flags & PRINTER_ENUM_REMOTE)
2135 return ERROR_INVALID_LEVEL;
2137 return NT_STATUS_NO_PROBLEMO;
2140 /********************************************************************
2141 * handle enumeration of printers at level 5
2142 ********************************************************************/
2143 static uint32 enumprinters_level5( uint32 flags, fstring servername,
2144 NEW_BUFFER *buffer, uint32 offered,
2145 uint32 *needed, uint32 *returned)
2147 /* return enum_all_printers_info_5(buffer, offered, needed, returned);*/
2148 return NT_STATUS_NO_PROBLEMO;
2151 /********************************************************************
2152 * api_spoolss_enumprinters
2154 * called from api_spoolss_enumprinters (see this to understand)
2155 ********************************************************************/
2156 uint32 _spoolss_enumprinters( uint32 flags, const UNISTR2 *servername, uint32 level,
2157 NEW_BUFFER *buffer, uint32 offered,
2158 uint32 *needed, uint32 *returned)
2162 DEBUG(4,("_spoolss_enumprinters\n"));
2169 * flags==PRINTER_ENUM_NAME
2170 * if name=="" then enumerates all printers
2171 * if name!="" then enumerate the printer
2172 * flags==PRINTER_ENUM_REMOTE
2173 * name is NULL, enumerate printers
2174 * Level 2: name!="" enumerates printers, name can't be NULL
2175 * Level 3: doesn't exist
2176 * Level 4: does a local registry lookup
2177 * Level 5: same as Level 2
2180 unistr2_to_ascii(name, servername, sizeof(name)-1);
2185 return enumprinters_level1(flags, name, buffer, offered, needed, returned);
2188 return enumprinters_level2(flags, name, buffer, offered, needed, returned);
2191 return enumprinters_level5(flags, name, buffer, offered, needed, returned);
2196 return ERROR_INVALID_LEVEL;
2201 /****************************************************************************
2202 ****************************************************************************/
2203 static uint32 getprinter_level_0(pstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2205 PRINTER_INFO_0 *printer=NULL;
2207 if((printer=(PRINTER_INFO_0*)malloc(sizeof(PRINTER_INFO_0))) == NULL)
2208 return ERROR_NOT_ENOUGH_MEMORY;
2210 construct_printer_info_0(printer, snum, servername);
2212 /* check the required size. */
2213 *needed += spoolss_size_printer_info_0(printer);
2215 if (!alloc_buffer_size(buffer, *needed)) {
2217 return ERROR_INSUFFICIENT_BUFFER;
2220 /* fill the buffer with the structures */
2221 new_smb_io_printer_info_0("", buffer, printer, 0);
2226 if (*needed > offered) {
2227 return ERROR_INSUFFICIENT_BUFFER;
2230 return NT_STATUS_NO_PROBLEMO;
2233 /****************************************************************************
2234 ****************************************************************************/
2235 static uint32 getprinter_level_1(pstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2237 PRINTER_INFO_1 *printer=NULL;
2239 if((printer=(PRINTER_INFO_1*)malloc(sizeof(PRINTER_INFO_1))) == NULL)
2240 return ERROR_NOT_ENOUGH_MEMORY;
2242 construct_printer_info_1(servername, PRINTER_ENUM_ICON8, printer, snum);
2244 /* check the required size. */
2245 *needed += spoolss_size_printer_info_1(printer);
2247 if (!alloc_buffer_size(buffer, *needed)) {
2249 return ERROR_INSUFFICIENT_BUFFER;
2252 /* fill the buffer with the structures */
2253 new_smb_io_printer_info_1("", buffer, printer, 0);
2258 if (*needed > offered) {
2259 return ERROR_INSUFFICIENT_BUFFER;
2262 return NT_STATUS_NO_PROBLEMO;
2265 /****************************************************************************
2266 ****************************************************************************/
2267 static uint32 getprinter_level_2(pstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2269 PRINTER_INFO_2 *printer=NULL;
2272 if((printer=(PRINTER_INFO_2*)malloc(sizeof(PRINTER_INFO_2)))==NULL)
2273 return ERROR_NOT_ENOUGH_MEMORY;
2275 fstrcpy(temp, "\\\\");
2276 fstrcat(temp, servername);
2277 construct_printer_info_2(temp, printer, snum);
2279 /* check the required size. */
2280 *needed += spoolss_size_printer_info_2(printer);
2282 if (!alloc_buffer_size(buffer, *needed)) {
2284 return ERROR_INSUFFICIENT_BUFFER;
2287 /* fill the buffer with the structures */
2288 new_smb_io_printer_info_2("", buffer, printer, 0);
2291 safe_free(printer->devmode->private);
2292 safe_free(printer->devmode);
2295 if (*needed > offered) {
2296 return ERROR_INSUFFICIENT_BUFFER;
2299 return NT_STATUS_NO_PROBLEMO;
2302 /****************************************************************************
2303 ****************************************************************************/
2304 uint32 _spoolss_getprinter(POLICY_HND *handle, uint32 level,
2305 NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2312 pstrcpy(servername, global_myname);
2314 if (!get_printer_snum(handle, &snum))
2315 return ERROR_INVALID_HANDLE;
2319 return getprinter_level_0(servername, snum, buffer, offered, needed);
2322 return getprinter_level_1(servername,snum, buffer, offered, needed);
2325 return getprinter_level_2(servername,snum, buffer, offered, needed);
2328 return ERROR_INVALID_LEVEL;
2333 /********************************************************************
2334 * construct_printer_driver_info_1
2335 * fill a construct_printer_driver_info_1 struct
2336 ********************************************************************/
2337 static void fill_printer_driver_info_1(DRIVER_INFO_1 *info,
2338 NT_PRINTER_DRIVER_INFO_LEVEL driver,
2339 pstring servername, fstring architecture)
2341 init_unistr( &(info->name), driver.info_3->name);
2344 static void construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum,
2345 pstring servername, fstring architecture)
2347 NT_PRINTER_INFO_LEVEL printer;
2348 NT_PRINTER_DRIVER_INFO_LEVEL driver;
2350 get_a_printer(&printer, 2, lp_servicename(snum) );
2351 get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture);
2353 fill_printer_driver_info_1(info, driver, servername, architecture);
2355 free_a_printer_driver(driver, 3);
2356 free_a_printer(printer, 2);
2359 /********************************************************************
2360 * construct_printer_driver_info_2
2361 * fill a printer_info_2 struct
2362 ********************************************************************/
2363 static void fill_printer_driver_info_2(DRIVER_INFO_2 *info,
2364 NT_PRINTER_DRIVER_INFO_LEVEL driver,
2365 pstring servername, fstring architecture)
2368 pstring temp_driverpath;
2369 pstring temp_datafile;
2370 pstring temp_configfile;
2371 fstring short_archi;
2373 get_short_archi(short_archi,architecture);
2375 snprintf(where,sizeof(where)-1,"\\\\%s\\print$\\%s\\", servername, short_archi);
2377 info->version=driver.info_3->cversion;
2379 init_unistr( &(info->name), driver.info_3->name );
2380 init_unistr( &(info->architecture), architecture );
2382 snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "%s%s", where,
2383 driver.info_3->driverpath);
2384 init_unistr( &(info->driverpath), temp_driverpath );
2386 snprintf(temp_datafile, sizeof(temp_datafile)-1, "%s%s", where,
2387 driver.info_3->datafile);
2388 init_unistr( &(info->datafile), temp_datafile );
2390 snprintf(temp_configfile, sizeof(temp_configfile)-1, "%s%s", where,
2391 driver.info_3->configfile);
2392 init_unistr( &(info->configfile), temp_configfile );
2395 /********************************************************************
2396 * construct_printer_driver_info_2
2397 * fill a printer_info_2 struct
2398 ********************************************************************/
2399 static void construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, pstring servername, fstring architecture)
2401 NT_PRINTER_INFO_LEVEL printer;
2402 NT_PRINTER_DRIVER_INFO_LEVEL driver;
2404 get_a_printer(&printer, 2, lp_servicename(snum) );
2405 get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture);
2407 fill_printer_driver_info_2(info, driver, servername, architecture);
2409 free_a_printer_driver(driver, 3);
2410 free_a_printer(printer, 2);
2413 /********************************************************************
2414 * copy a strings array and convert to UNICODE
2416 * convert an array of ascii string to a UNICODE string
2417 ********************************************************************/
2418 static void init_unistr_array(uint16 **uni_array, char **char_array, char *where)
2425 DEBUG(6,("init_unistr_array\n"));
2428 for (v=char_array[i]; *v!='\0'; v=char_array[i]) {
2429 snprintf(line, sizeof(line)-1, "%s%s", where, v);
2430 DEBUGADD(6,("%d:%s:%d\n", i, line, strlen(line)));
2431 if((*uni_array=Realloc(*uni_array, (j+strlen(line)+2)*sizeof(uint16))) == NULL) {
2432 DEBUG(0,("init_unistr_array: Realloc error\n" ));
2435 ascii_to_unistr( *uni_array+j, line , strlen(line));
2440 (*uni_array)[j]=0x0000;
2442 DEBUGADD(6,("last one:done\n"));
2445 /********************************************************************
2446 * construct_printer_info_3
2447 * fill a printer_info_3 struct
2448 ********************************************************************/
2449 static void fill_printer_driver_info_3(DRIVER_INFO_3 *info,
2450 NT_PRINTER_DRIVER_INFO_LEVEL driver,
2451 pstring servername, fstring architecture)
2454 pstring temp_driverpath;
2455 pstring temp_datafile;
2456 pstring temp_configfile;
2457 pstring temp_helpfile;
2458 fstring short_archi;
2460 get_short_archi(short_archi, architecture);
2462 snprintf(where,sizeof(where)-1,"\\\\%s\\print$\\%s\\", servername, short_archi);
2464 info->version=driver.info_3->cversion;
2466 init_unistr( &(info->name), driver.info_3->name );
2467 init_unistr( &(info->architecture), architecture );
2469 snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "%s%s", where, driver.info_3->driverpath);
2470 init_unistr( &(info->driverpath), temp_driverpath );
2472 snprintf(temp_datafile, sizeof(temp_datafile)-1, "%s%s", where, driver.info_3->datafile);
2473 init_unistr( &(info->datafile), temp_datafile );
2475 snprintf(temp_configfile, sizeof(temp_configfile)-1, "%s%s", where, driver.info_3->configfile);
2476 init_unistr( &(info->configfile), temp_configfile );
2478 snprintf(temp_helpfile, sizeof(temp_helpfile)-1, "%s%s", where, driver.info_3->helpfile);
2479 init_unistr( &(info->helpfile), temp_helpfile );
2481 init_unistr( &(info->monitorname), driver.info_3->monitorname );
2482 init_unistr( &(info->defaultdatatype), driver.info_3->defaultdatatype );
2484 info->dependentfiles=NULL;
2485 init_unistr_array(&(info->dependentfiles), driver.info_3->dependentfiles, where);
2488 /********************************************************************
2489 * construct_printer_info_3
2490 * fill a printer_info_3 struct
2491 ********************************************************************/
2492 static void construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum,
2493 pstring servername, fstring architecture)
2495 NT_PRINTER_INFO_LEVEL printer;
2496 NT_PRINTER_DRIVER_INFO_LEVEL driver;
2498 get_a_printer(&printer, 2, lp_servicename(snum) );
2499 get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture);
2501 fill_printer_driver_info_3(info, driver, servername, architecture);
2503 free_a_printer_driver(driver, 3);
2504 free_a_printer(printer, 2);
2507 /****************************************************************************
2508 ****************************************************************************/
2509 static uint32 getprinterdriver2_level1(pstring servername, pstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2511 DRIVER_INFO_1 *info=NULL;
2513 if((info=(DRIVER_INFO_1 *)malloc(sizeof(DRIVER_INFO_1))) == NULL)
2514 return ERROR_NOT_ENOUGH_MEMORY;
2516 construct_printer_driver_info_1(info, snum, servername, architecture);
2518 /* check the required size. */
2519 *needed += spoolss_size_printer_driver_info_1(info);
2521 if (!alloc_buffer_size(buffer, *needed)) {
2523 return ERROR_INSUFFICIENT_BUFFER;
2526 /* fill the buffer with the structures */
2527 new_smb_io_printer_driver_info_1("", buffer, info, 0);
2532 if (*needed > offered)
2533 return ERROR_INSUFFICIENT_BUFFER;
2535 return NT_STATUS_NO_PROBLEMO;
2538 /****************************************************************************
2539 ****************************************************************************/
2540 static uint32 getprinterdriver2_level2(pstring servername, pstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2542 DRIVER_INFO_2 *info=NULL;
2544 if((info=(DRIVER_INFO_2 *)malloc(sizeof(DRIVER_INFO_2))) == NULL)
2545 return ERROR_NOT_ENOUGH_MEMORY;
2547 construct_printer_driver_info_2(info, snum, servername, architecture);
2549 /* check the required size. */
2550 *needed += spoolss_size_printer_driver_info_2(info);
2552 if (!alloc_buffer_size(buffer, *needed)) {
2554 return ERROR_INSUFFICIENT_BUFFER;
2557 /* fill the buffer with the structures */
2558 new_smb_io_printer_driver_info_2("", buffer, info, 0);
2563 if (*needed > offered)
2564 return ERROR_INSUFFICIENT_BUFFER;
2566 return NT_STATUS_NO_PROBLEMO;
2569 /****************************************************************************
2570 ****************************************************************************/
2571 static uint32 getprinterdriver2_level3(pstring servername, pstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2573 DRIVER_INFO_3 *info=NULL;
2575 if((info=(DRIVER_INFO_3 *)malloc(sizeof(DRIVER_INFO_3)))==NULL)
2576 return ERROR_NOT_ENOUGH_MEMORY;
2578 construct_printer_driver_info_3(info, snum, servername, architecture);
2580 /* check the required size. */
2581 *needed += spoolss_size_printer_driver_info_3(info);
2583 if (!alloc_buffer_size(buffer, *needed)) {
2585 return ERROR_INSUFFICIENT_BUFFER;
2588 /* fill the buffer with the structures */
2589 new_smb_io_printer_driver_info_3("", buffer, info, 0);
2592 safe_free(info->dependentfiles);
2595 if (*needed > offered)
2596 return ERROR_INSUFFICIENT_BUFFER;
2598 return NT_STATUS_NO_PROBLEMO;
2601 /****************************************************************************
2602 ****************************************************************************/
2603 uint32 _spoolss_getprinterdriver2(const POLICY_HND *handle, const UNISTR2 *uni_arch, uint32 level,
2604 uint32 clientmajorversion, uint32 clientminorversion,
2605 NEW_BUFFER *buffer, uint32 offered,
2606 uint32 *needed, uint32 *servermajorversion, uint32 *serverminorversion)
2609 fstring architecture;
2612 DEBUG(4,("_spoolss_getprinterdriver2\n"));
2615 *servermajorversion=0;
2616 *serverminorversion=0;
2618 pstrcpy(servername, global_myname);
2619 unistr2_to_ascii(architecture, uni_arch, sizeof(architecture)-1);
2621 if (!get_printer_snum(handle, &snum))
2622 return ERROR_INVALID_HANDLE;
2626 return getprinterdriver2_level1(servername, architecture, snum, buffer, offered, needed);
2629 return getprinterdriver2_level2(servername, architecture, snum, buffer, offered, needed);
2632 return getprinterdriver2_level3(servername, architecture, snum, buffer, offered, needed);
2635 return ERROR_INVALID_LEVEL;
2640 /****************************************************************************
2641 ****************************************************************************/
2642 uint32 _spoolss_startpageprinter(const POLICY_HND *handle)
2644 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2646 if (OPEN_HANDLE(Printer))
2648 Printer->page_started=True;
2652 DEBUG(3,("Error in startpageprinter printer handle\n"));
2653 return ERROR_INVALID_HANDLE;
2656 /****************************************************************************
2657 ****************************************************************************/
2658 uint32 _spoolss_endpageprinter(const POLICY_HND *handle)
2660 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2662 if (!OPEN_HANDLE(Printer))
2664 DEBUG(3,("Error in endpageprinter printer handle\n"));
2665 return ERROR_INVALID_HANDLE;
2668 Printer->page_started=False;
2670 return NT_STATUS_NO_PROBLEMO;
2674 /********************************************************************
2675 * api_spoolss_getprinter
2676 * called from the spoolss dispatcher
2678 ********************************************************************/
2679 uint32 _spoolss_startdocprinter( const POLICY_HND *handle, uint32 level,
2680 DOC_INFO *docinfo, uint32 *jobid)
2682 DOC_INFO_1 *info_1 = &docinfo->doc_info_1;
2686 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2688 if (!OPEN_HANDLE(Printer))
2690 return ERROR_INVALID_HANDLE;
2694 * a nice thing with NT is it doesn't listen to what you tell it.
2695 * when asked to send _only_ RAW datas, it tries to send datas
2698 * So I add checks like in NT Server ...
2700 * lkclXXXX jean-francois, i love this kind of thing. oh, well,
2701 * there's a bug in NT client-side code, so we'll fix it in the
2702 * server-side code. *nnnnnggggh!*
2705 if (info_1->p_datatype != 0)
2707 unistr2_to_ascii(datatype, &(info_1->docname), sizeof(datatype));
2708 if (strcmp(datatype, "RAW") != 0)
2711 return ERROR_INVALID_DATATYPE;
2715 /* get the share number of the printer */
2716 if (!get_printer_snum(handle, &snum))
2718 return ERROR_INVALID_HANDLE;
2721 unistr2_to_ascii(jobname, &info_1->docname, sizeof(jobname));
2723 Printer->jobid = print_job_start(snum, jobname);
2725 /* need to map error codes properly - for now give out of
2726 memory as I don't know the correct codes (tridge) */
2727 if (Printer->jobid == -1) {
2728 return ERROR_NOT_ENOUGH_MEMORY;
2731 Printer->document_started=True;
2732 (*jobid) = Printer->jobid;
2737 /********************************************************************
2738 * api_spoolss_getprinter
2739 * called from the spoolss dispatcher
2741 ********************************************************************/
2742 uint32 _spoolss_enddocprinter(const POLICY_HND *handle)
2744 Printer_entry *Printer=find_printer_index_by_hnd(handle);
2746 if (!OPEN_HANDLE(Printer))
2748 DEBUG(3,("Error in enddocprinter handle\n"));
2749 return ERROR_INVALID_HANDLE;
2752 Printer->document_started=False;
2753 print_job_end(Printer->jobid);
2754 /* error codes unhandled so far ... */
2759 /****************************************************************************
2760 ****************************************************************************/
2761 uint32 _spoolss_writeprinter( const POLICY_HND *handle,
2763 const uint8 *buffer,
2764 uint32 *buffer_written)
2766 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2768 if (!OPEN_HANDLE(Printer))
2770 DEBUG(3,("Error in writeprinter handle\n"));
2771 return ERROR_INVALID_HANDLE;
2774 (*buffer_written) = print_job_write(Printer->jobid, buffer, buffer_size);
2779 /********************************************************************
2780 * api_spoolss_getprinter
2781 * called from the spoolss dispatcher
2783 ********************************************************************/
2784 static uint32 control_printer(const POLICY_HND *handle, uint32 command)
2787 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2789 if (!OPEN_HANDLE(Printer))
2790 return ERROR_INVALID_HANDLE;
2792 if (!get_printer_snum(handle, &snum) )
2793 return ERROR_INVALID_HANDLE;
2796 case PRINTER_CONTROL_PAUSE:
2797 if (print_queue_pause(snum)) {
2801 case PRINTER_CONTROL_RESUME:
2802 case PRINTER_CONTROL_UNPAUSE:
2803 if (print_queue_resume(snum)) {
2807 case PRINTER_CONTROL_PURGE:
2808 if (print_queue_purge(snum)) {
2814 return ERROR_INVALID_FUNCTION;
2817 /********************************************************************
2818 * called by spoolss_api_setprinter
2819 * when updating a printer description
2820 ********************************************************************/
2821 static uint32 update_printer(const POLICY_HND *handle, uint32 level,
2822 const SPOOL_PRINTER_INFO_LEVEL *info,
2823 const DEVICEMODE *devmode)
2826 NT_PRINTER_INFO_LEVEL printer;
2827 NT_DEVICEMODE *nt_devmode;
2828 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2832 DEBUG(8,("update_printer\n"));
2835 DEBUG(0,("Send a mail to jfm@samba.org\n"));
2836 DEBUGADD(0,("with the following message: update_printer: level!=2\n"));
2837 return ERROR_INVALID_LEVEL;
2840 if (!OPEN_HANDLE(Printer))
2841 return ERROR_INVALID_HANDLE;
2843 if (!get_printer_snum(handle, &snum) )
2844 return ERROR_INVALID_HANDLE;
2846 get_a_printer(&printer, 2, lp_servicename(snum));
2848 DEBUGADD(8,("Converting info_2 struct\n"));
2849 convert_printer_info(info, &printer, level);
2851 if ((info->info_2)->devmode_ptr != 0) {
2852 /* we have a valid devmode
2853 convert it and link it*/
2855 /* the nt_devmode memory is already alloced
2856 * while doing the get_a_printer call
2857 * but the devmode private part is not
2858 * it's done by convert_devicemode
2860 DEBUGADD(8,("Converting the devicemode struct\n"));
2861 nt_devmode=printer.info_2->devmode;
2863 init_devicemode(nt_devmode);
2865 convert_devicemode(*devmode, nt_devmode);
2868 if (printer.info_2->devmode != NULL)
2869 free(printer.info_2->devmode);
2870 printer.info_2->devmode=NULL;
2873 if (add_a_printer(printer, 2)!=0) {
2874 free_a_printer(printer, 2);
2876 /* I don't really know what to return here !!! */
2877 return ERROR_ACCESS_DENIED;
2880 free_a_printer(printer, 2);
2882 return NT_STATUS_NO_PROBLEMO;
2885 /****************************************************************************
2886 ****************************************************************************/
2887 uint32 _spoolss_setprinter(const POLICY_HND *handle, uint32 level,
2888 const SPOOL_PRINTER_INFO_LEVEL *info,
2889 const DEVMODE_CTR devmode_ctr,
2892 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2894 if (!OPEN_HANDLE(Printer))
2895 return ERROR_INVALID_HANDLE;
2897 /* check the level */
2900 return control_printer(handle, command);
2903 return update_printer(handle, level, info, devmode_ctr.devmode);
2906 return ERROR_INVALID_LEVEL;
2911 /****************************************************************************
2912 ****************************************************************************/
2913 uint32 _spoolss_fcpn(const POLICY_HND *handle)
2915 Printer_entry *Printer= find_printer_index_by_hnd(handle);
2917 if (!OPEN_HANDLE(Printer))
2918 return ERROR_INVALID_HANDLE;
2920 Printer->notify.flags=0;
2921 Printer->notify.options=0;
2922 Printer->notify.localmachine[0]='\0';
2923 Printer->notify.printerlocal=0;
2924 safe_free(Printer->notify.option);
2925 Printer->notify.option=NULL;
2927 return NT_STATUS_NO_PROBLEMO;
2930 /****************************************************************************
2931 ****************************************************************************/
2932 uint32 _spoolss_addjob(const POLICY_HND *handle, uint32 level,
2933 NEW_BUFFER *buffer, uint32 offered)
2935 return NT_STATUS_NO_PROBLEMO;
2938 /****************************************************************************
2939 ****************************************************************************/
2940 static void fill_job_info_1(JOB_INFO_1 *job_info, print_queue_struct *queue,
2941 int position, int snum)
2946 time_t unixdate = time(NULL);
2948 t=gmtime(&unixdate);
2949 snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname);
2951 job_info->jobid=queue->job;
2952 init_unistr(&(job_info->printername), lp_servicename(snum));
2953 init_unistr(&(job_info->machinename), temp_name);
2954 init_unistr(&(job_info->username), queue->user);
2955 init_unistr(&(job_info->document), queue->file);
2956 init_unistr(&(job_info->datatype), "RAW");
2957 init_unistr(&(job_info->text_status), "");
2958 job_info->status=nt_printj_status(queue->status);
2959 job_info->priority=queue->priority;
2960 job_info->position=position;
2961 job_info->totalpages=0;
2962 job_info->pagesprinted=0;
2964 make_systemtime(&(job_info->submitted), t);
2967 /****************************************************************************
2968 ****************************************************************************/
2969 static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue,
2970 int position, int snum)
2973 DEVICEMODE *devmode;
2974 NT_PRINTER_INFO_LEVEL ntprinter;
2978 time_t unixdate = time(NULL);
2980 if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0 )
2983 t=gmtime(&unixdate);
2984 snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname);
2986 job_info->jobid=queue->job;
2988 snprintf(chaine, sizeof(chaine)-1, "\\\\%s\\%s", global_myname, ntprinter.info_2->printername);
2989 init_unistr(&(job_info->printername), chaine);
2991 init_unistr(&(job_info->machinename), temp_name);
2992 init_unistr(&(job_info->username), queue->user);
2993 init_unistr(&(job_info->document), queue->file);
2994 init_unistr(&(job_info->notifyname), queue->user);
2995 init_unistr(&(job_info->datatype), "RAW");
2996 init_unistr(&(job_info->printprocessor), "winprint");
2997 init_unistr(&(job_info->parameters), "");
2998 init_unistr(&(job_info->text_status), "");
3000 /* and here the security descriptor */
3002 job_info->status=nt_printj_status(queue->status);
3003 job_info->priority=queue->priority;
3004 job_info->position=position;
3005 job_info->starttime=0;
3006 job_info->untiltime=0;
3007 job_info->totalpages=0;
3008 job_info->size=queue->size;
3009 make_systemtime(&(job_info->submitted), t);
3010 job_info->timeelapsed=0;
3011 job_info->pagesprinted=0;
3013 if((devmode=(DEVICEMODE *)malloc(sizeof(DEVICEMODE))) == NULL) {
3014 free_a_printer(ntprinter, 2);
3018 ZERO_STRUCTP(devmode);
3019 if(!construct_dev_mode(devmode, snum, global_myname)) {
3020 free_a_printer(ntprinter, 2);
3023 job_info->devmode=devmode;
3025 free_a_printer(ntprinter, 2);
3029 /****************************************************************************
3030 Enumjobs at level 1.
3031 ****************************************************************************/
3032 static uint32 enumjobs_level1(print_queue_struct *queue, int snum,
3033 NEW_BUFFER *buffer, uint32 offered,
3034 uint32 *needed, uint32 *returned)
3039 info=(JOB_INFO_1 *)malloc(*returned*sizeof(JOB_INFO_1));
3043 return ERROR_NOT_ENOUGH_MEMORY;
3046 for (i=0; i<*returned; i++)
3047 fill_job_info_1(&(info[i]), &(queue[i]), i, snum);
3051 /* check the required size. */
3052 for (i=0; i<*returned; i++)
3053 (*needed) += spoolss_size_job_info_1(&(info[i]));
3055 if (!alloc_buffer_size(buffer, *needed)) {
3057 return ERROR_INSUFFICIENT_BUFFER;
3060 /* fill the buffer with the structures */
3061 for (i=0; i<*returned; i++)
3062 new_smb_io_job_info_1("", buffer, &(info[i]), 0);
3067 if (*needed > offered) {
3069 return ERROR_INSUFFICIENT_BUFFER;
3072 return NT_STATUS_NO_PROBLEMO;
3075 /****************************************************************************
3076 Enumjobs at level 2.
3077 ****************************************************************************/
3078 static uint32 enumjobs_level2(print_queue_struct *queue, int snum,
3079 NEW_BUFFER *buffer, uint32 offered,
3080 uint32 *needed, uint32 *returned)
3085 info=(JOB_INFO_2 *)malloc(*returned*sizeof(JOB_INFO_2));
3089 return ERROR_NOT_ENOUGH_MEMORY;
3092 for (i=0; i<*returned; i++)
3093 fill_job_info_2(&(info[i]), &(queue[i]), i, snum);
3097 /* check the required size. */
3098 for (i=0; i<*returned; i++)
3099 (*needed) += spoolss_size_job_info_2(&(info[i]));
3101 if (!alloc_buffer_size(buffer, *needed)) {
3103 return ERROR_INSUFFICIENT_BUFFER;
3106 /* fill the buffer with the structures */
3107 for (i=0; i<*returned; i++)
3108 new_smb_io_job_info_2("", buffer, &(info[i]), 0);
3113 if (*needed > offered) {
3115 return ERROR_INSUFFICIENT_BUFFER;
3118 return NT_STATUS_NO_PROBLEMO;
3121 /****************************************************************************
3123 ****************************************************************************/
3124 uint32 _spoolss_enumjobs( POLICY_HND *handle, uint32 firstjob, uint32 numofjobs, uint32 level,
3125 NEW_BUFFER *buffer, uint32 offered,
3126 uint32 *needed, uint32 *returned)
3129 print_queue_struct *queue=NULL;
3130 print_status_struct prt_status;
3132 DEBUG(4,("_spoolss_enumjobs\n"));
3134 ZERO_STRUCT(prt_status);
3139 if (!get_printer_snum(handle, &snum))
3140 return ERROR_INVALID_HANDLE;
3142 *returned = print_queue_status(snum, &queue, &prt_status);
3143 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n", *returned, prt_status.status, prt_status.message));
3147 return enumjobs_level1(queue, snum, buffer, offered, needed, returned);
3150 return enumjobs_level2(queue, snum, buffer, offered, needed, returned);
3155 return ERROR_INVALID_LEVEL;
3161 /****************************************************************************
3162 ****************************************************************************/
3163 uint32 _spoolss_schedulejob( const POLICY_HND *handle, uint32 jobid)
3168 /****************************************************************************
3169 ****************************************************************************/
3170 uint32 _spoolss_setjob( const POLICY_HND *handle,
3178 print_status_struct prt_status;
3180 memset(&prt_status, 0, sizeof(prt_status));
3182 if (!get_printer_snum(handle, &snum)) {
3183 return ERROR_INVALID_HANDLE;
3186 if (!print_job_exists(jobid)) {
3187 return ERROR_INVALID_PRINTER_NAME;
3191 case JOB_CONTROL_CANCEL:
3192 case JOB_CONTROL_DELETE:
3193 if (print_job_delete(jobid)) return 0x0;
3195 case JOB_CONTROL_PAUSE:
3196 if (print_job_pause(jobid)) return 0x0;
3198 case JOB_CONTROL_RESUME:
3199 if (print_job_resume(jobid)) return 0x0;
3202 return ERROR_INVALID_LEVEL;
3205 return ERROR_INVALID_HANDLE;
3208 /****************************************************************************
3209 Enumerates all printer drivers at level 1.
3210 ****************************************************************************/
3211 static uint32 enumprinterdrivers_level1(fstring *list, fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3214 NT_PRINTER_DRIVER_INFO_LEVEL driver;
3215 DRIVER_INFO_1 *driver_info_1=NULL;
3217 if((driver_info_1=(DRIVER_INFO_1 *)malloc(*returned * sizeof(DRIVER_INFO_1))) == NULL)
3218 return ERROR_NOT_ENOUGH_MEMORY;
3220 for (i=0; i<*returned; i++) {
3221 get_a_printer_driver(&driver, 3, list[i], architecture);
3222 fill_printer_driver_info_1(&(driver_info_1[i]), driver, servername, architecture );
3223 free_a_printer_driver(driver, 3);
3228 /* check the required size. */
3229 for (i=0; i<*returned; i++) {
3230 DEBUGADD(6,("adding driver [%d]'s size\n",i));
3231 *needed += spoolss_size_printer_driver_info_1(&(driver_info_1[i]));
3234 if (!alloc_buffer_size(buffer, *needed)) {
3235 safe_free(driver_info_1);
3236 return ERROR_INSUFFICIENT_BUFFER;
3239 /* fill the buffer with the form structures */
3240 for (i=0; i<*returned; i++) {
3241 DEBUGADD(6,("adding driver [%d] to buffer\n",i));
3242 new_smb_io_printer_driver_info_1("", buffer, &(driver_info_1[i]), 0);
3245 safe_free(driver_info_1);
3247 if (*needed > offered) {
3249 return ERROR_INSUFFICIENT_BUFFER;
3252 return NT_STATUS_NO_PROBLEMO;
3255 /****************************************************************************
3256 Enumerates all printer drivers at level 2.
3257 ****************************************************************************/
3258 static uint32 enumprinterdrivers_level2(fstring *list, fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3261 NT_PRINTER_DRIVER_INFO_LEVEL driver;
3262 DRIVER_INFO_2 *driver_info_2=NULL;
3264 if((driver_info_2=(DRIVER_INFO_2 *)malloc(*returned * sizeof(DRIVER_INFO_2))) == NULL)
3265 return ERROR_NOT_ENOUGH_MEMORY;
3267 for (i=0; i<*returned; i++) {
3268 get_a_printer_driver(&driver, 3, list[i], architecture);
3269 fill_printer_driver_info_2(&(driver_info_2[i]), driver, servername, architecture );
3270 free_a_printer_driver(driver, 3);
3275 /* check the required size. */
3276 for (i=0; i<*returned; i++) {
3277 DEBUGADD(6,("adding driver [%d]'s size\n",i));
3278 *needed += spoolss_size_printer_driver_info_2(&(driver_info_2[i]));
3281 if (!alloc_buffer_size(buffer, *needed)) {
3282 safe_free(driver_info_2);
3283 return ERROR_INSUFFICIENT_BUFFER;
3286 /* fill the buffer with the form structures */
3287 for (i=0; i<*returned; i++) {
3288 DEBUGADD(6,("adding driver [%d] to buffer\n",i));
3289 new_smb_io_printer_driver_info_2("", buffer, &(driver_info_2[i]), 0);
3292 safe_free(driver_info_2);
3294 if (*needed > offered) {
3296 return ERROR_INSUFFICIENT_BUFFER;
3299 return NT_STATUS_NO_PROBLEMO;
3302 /****************************************************************************
3303 Enumerates all printer drivers at level 3.
3304 ****************************************************************************/
3305 static uint32 enumprinterdrivers_level3(fstring *list, fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3308 NT_PRINTER_DRIVER_INFO_LEVEL driver;
3309 DRIVER_INFO_3 *driver_info_3=NULL;
3311 if((driver_info_3=(DRIVER_INFO_3 *)malloc((*returned)*sizeof(DRIVER_INFO_3))) == NULL)
3312 return ERROR_NOT_ENOUGH_MEMORY;
3314 for (i=0; i<*returned; i++) {
3315 get_a_printer_driver(&driver, 3, list[i], architecture);
3316 fill_printer_driver_info_3(&(driver_info_3[i]), driver, servername, architecture );
3317 free_a_printer_driver(driver, 3);
3322 /* check the required size. */
3323 for (i=0; i<*returned; i++) {
3324 DEBUGADD(6,("adding driver [%d]'s size\n",i));
3325 *needed += spoolss_size_printer_driver_info_3(&(driver_info_3[i]));
3328 if (!alloc_buffer_size(buffer, *needed)) {
3329 safe_free(driver_info_3);
3330 return ERROR_INSUFFICIENT_BUFFER;
3333 /* fill the buffer with the form structures */
3334 for (i=0; i<*returned; i++) {
3335 DEBUGADD(6,("adding form [%d] to buffer\n",i));
3336 new_smb_io_printer_driver_info_3("", buffer, &(driver_info_3[i]), 0);
3339 for (i=0; i<*returned; i++)
3340 safe_free(driver_info_3[i].dependentfiles);
3342 safe_free(driver_info_3);
3344 if (*needed > offered) {
3346 return ERROR_INSUFFICIENT_BUFFER;
3349 return NT_STATUS_NO_PROBLEMO;
3352 /****************************************************************************
3353 Enumerates all printer drivers.
3354 ****************************************************************************/
3355 uint32 _spoolss_enumprinterdrivers( UNISTR2 *name, UNISTR2 *environment, uint32 level,
3356 NEW_BUFFER *buffer, uint32 offered,
3357 uint32 *needed, uint32 *returned)
3362 fstring architecture;
3364 DEBUG(4,("_spoolss_enumprinterdrivers\n"));
3365 fstrcpy(servername, global_myname);
3369 unistr2_to_ascii(architecture, environment, sizeof(architecture)-1);
3370 *returned=get_ntdrivers(&list, architecture);
3372 DEBUGADD(4,("we have: [%d] drivers in environment [%s]\n", *returned, architecture));
3374 return ERROR_NOT_ENOUGH_MEMORY;
3376 for (i=0; i<*returned; i++)
3377 DEBUGADD(5,("driver: [%s]\n", list[i]));
3381 return enumprinterdrivers_level1(list, servername, architecture, buffer, offered, needed, returned);
3384 return enumprinterdrivers_level2(list, servername, architecture, buffer, offered, needed, returned);
3387 return enumprinterdrivers_level3(list, servername, architecture, buffer, offered, needed, returned);
3390 return ERROR_INVALID_LEVEL;
3395 /****************************************************************************
3396 ****************************************************************************/
3397 static void fill_form_1(FORM_1 *form, nt_forms_struct *list, int position)
3399 form->flag=list->flag;
3400 init_unistr(&(form->name), list->name);
3401 form->width=list->width;
3402 form->length=list->length;
3403 form->left=list->left;
3404 form->top=list->top;
3405 form->right=list->right;
3406 form->bottom=list->bottom;
3409 /****************************************************************************
3410 ****************************************************************************/
3411 uint32 _new_spoolss_enumforms( const POLICY_HND *handle, uint32 level,
3412 NEW_BUFFER *buffer, uint32 offered,
3413 uint32 *needed, uint32 *numofforms)
3415 nt_forms_struct *list=NULL;
3420 DEBUG(4,("_new_spoolss_enumforms\n"));
3421 DEBUGADD(5,("Offered buffer size [%d]\n", offered));
3422 DEBUGADD(5,("Info level [%d]\n", level));
3424 *numofforms = get_ntforms(&list);
3425 DEBUGADD(5,("Number of forms [%d]\n", *numofforms));
3429 if((forms_1=(FORM_1 *)malloc(*numofforms * sizeof(FORM_1))) == NULL) {
3431 return ERROR_NOT_ENOUGH_MEMORY;
3434 /* construct the list of form structures */
3435 for (i=0; i<*numofforms; i++) {
3436 DEBUGADD(6,("Filling form number [%d]\n",i));
3437 fill_form_1(&(forms_1[i]), &(list[i]), i);
3442 /* check the required size. */
3443 for (i=0; i<*numofforms; i++) {
3444 DEBUGADD(6,("adding form [%d]'s size\n",i));
3445 buffer_size += spoolss_size_form_1(&(forms_1[i]));
3448 *needed=buffer_size;
3450 if (!alloc_buffer_size(buffer, buffer_size)){
3452 return ERROR_INSUFFICIENT_BUFFER;
3455 /* fill the buffer with the form structures */
3456 for (i=0; i<*numofforms; i++) {
3457 DEBUGADD(6,("adding form [%d] to buffer\n",i));
3458 new_smb_io_form_1("", buffer, &(forms_1[i]), 0);
3463 if (*needed > offered) {
3465 return ERROR_INSUFFICIENT_BUFFER;
3468 return NT_STATUS_NO_PROBLEMO;
3472 return ERROR_INVALID_LEVEL;
3477 /****************************************************************************
3478 ****************************************************************************/
3479 static void fill_port_1(PORT_INFO_1 *port, char *name)
3481 init_unistr(&(port->port_name), name);
3484 /****************************************************************************
3485 ****************************************************************************/
3486 static void fill_port_2(PORT_INFO_2 *port, char *name)
3488 init_unistr(&(port->port_name), name);
3489 init_unistr(&(port->monitor_name), "Moniteur Local");
3490 init_unistr(&(port->description), "Local Port");
3491 #define PORT_TYPE_WRITE 1
3492 port->port_type=PORT_TYPE_WRITE;
3496 /****************************************************************************
3498 ****************************************************************************/
3499 static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3501 int n_services=lp_numservices();
3505 PORT_INFO_1 *ports=NULL;
3507 for (snum=0; snum<n_services; snum++)
3508 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
3511 if((ports=(PORT_INFO_1 *)malloc( (*returned+1) * sizeof(PORT_INFO_1) )) == NULL)
3512 return ERROR_NOT_ENOUGH_MEMORY;
3514 for (snum=0; snum<n_services; snum++) {
3515 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
3516 DEBUGADD(6,("Filling port number [%d]\n", i));
3517 fill_port_1(&(ports[i]), lp_servicename(snum));
3522 /* check the required size. */
3523 for (i=0; i<*returned; i++) {
3524 DEBUGADD(6,("adding port [%d]'s size\n", i));
3525 *needed += spoolss_size_port_info_1(&(ports[i]));
3528 if (!alloc_buffer_size(buffer, *needed)) {
3530 return ERROR_INSUFFICIENT_BUFFER;
3533 /* fill the buffer with the ports structures */
3534 for (i=0; i<*returned; i++) {
3535 DEBUGADD(6,("adding port [%d] to buffer\n", i));
3536 new_smb_io_port_1("", buffer, &(ports[i]), 0);
3541 if (*needed > offered) {
3543 return ERROR_INSUFFICIENT_BUFFER;
3546 return NT_STATUS_NO_PROBLEMO;
3550 /****************************************************************************
3552 ****************************************************************************/
3553 static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3555 int n_services=lp_numservices();
3559 PORT_INFO_2 *ports=NULL;
3561 for (snum=0; snum<n_services; snum++)
3562 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
3565 if((ports=(PORT_INFO_2 *)malloc( (*returned+1) * sizeof(PORT_INFO_2) )) == NULL)
3566 return ERROR_NOT_ENOUGH_MEMORY;
3568 for (snum=0; snum<n_services; snum++) {
3569 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
3570 DEBUGADD(6,("Filling port number [%d]\n", i));
3571 fill_port_2(&(ports[i]), lp_servicename(snum));
3576 /* check the required size. */
3577 for (i=0; i<*returned; i++) {
3578 DEBUGADD(6,("adding port [%d]'s size\n", i));
3579 *needed += spoolss_size_port_info_2(&(ports[i]));
3582 if (!alloc_buffer_size(buffer, *needed)) {
3584 return ERROR_INSUFFICIENT_BUFFER;
3587 /* fill the buffer with the ports structures */
3588 for (i=0; i<*returned; i++) {
3589 DEBUGADD(6,("adding port [%d] to buffer\n", i));
3590 new_smb_io_port_2("", buffer, &(ports[i]), 0);
3595 if (*needed > offered) {
3597 return ERROR_INSUFFICIENT_BUFFER;
3600 return NT_STATUS_NO_PROBLEMO;
3603 /****************************************************************************
3605 ****************************************************************************/
3606 uint32 _spoolss_enumports( UNISTR2 *name, uint32 level,
3607 NEW_BUFFER *buffer, uint32 offered,
3608 uint32 *needed, uint32 *returned)
3610 DEBUG(4,("_spoolss_enumports\n"));
3617 return enumports_level_1(buffer, offered, needed, returned);
3620 return enumports_level_2(buffer, offered, needed, returned);
3623 return ERROR_INVALID_LEVEL;
3628 /****************************************************************************
3629 ****************************************************************************/
3630 static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name,
3631 const SPOOL_PRINTER_INFO_LEVEL *info,
3632 uint32 unk0, uint32 unk1, uint32 unk2, uint32 unk3,
3633 uint32 user_switch, const SPOOL_USER_CTR *user,
3636 NT_PRINTER_INFO_LEVEL printer;
3640 clear_handle(handle);
3642 /* NULLify info_2 here */
3643 /* don't put it in convert_printer_info as it's used also with non-NULL values */
3644 printer.info_2=NULL;
3646 /* convert from UNICODE to ASCII */
3647 convert_printer_info(info, &printer, 2);
3649 unistr2_to_ascii(share_name, &((info->info_2)->printername), sizeof(share_name)-1);
3651 slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname, share_name);
3653 /* write the ASCII on disk */
3654 if (add_a_printer(printer, 2) != 0x0)
3655 return ERROR_ACCESS_DENIED;
3657 create_printer_hnd(handle);
3659 open_printer_hnd(handle);
3661 if (!set_printer_hnd_printertype(handle, name)) {
3662 close_printer_handle(handle);
3663 return ERROR_ACCESS_DENIED;
3666 if (!set_printer_hnd_printername(handle, name)) {
3667 close_printer_handle(handle);
3668 return ERROR_ACCESS_DENIED;
3671 return NT_STATUS_NO_PROBLEMO;
3674 /****************************************************************************
3675 ****************************************************************************/
3676 uint32 _spoolss_addprinterex( const UNISTR2 *uni_srv_name, uint32 level,
3677 const SPOOL_PRINTER_INFO_LEVEL *info,
3678 uint32 unk0, uint32 unk1, uint32 unk2, uint32 unk3,
3679 uint32 user_switch, const SPOOL_USER_CTR *user,
3684 /* we don't handle yet */
3685 /* but I know what to do ... */
3686 return ERROR_INVALID_LEVEL;
3689 return spoolss_addprinterex_level_2(uni_srv_name, info,
3690 unk0, unk1, unk2, unk3,
3691 user_switch, user, handle);
3694 return ERROR_INVALID_LEVEL;
3700 /****************************************************************************
3701 ****************************************************************************/
3702 uint32 _spoolss_addprinterdriver( const UNISTR2 *server_name,
3704 const SPOOL_PRINTER_DRIVER_INFO_LEVEL *info)
3706 NT_PRINTER_DRIVER_INFO_LEVEL driver;
3708 convert_printer_driver_info(info, &driver, level);
3710 if (add_a_printer_driver(driver, level)!=0)
3711 return ERROR_ACCESS_DENIED;
3713 return NT_STATUS_NO_PROBLEMO;
3716 /****************************************************************************
3717 ****************************************************************************/
3718 static void fill_driverdir_1(DRIVER_DIRECTORY_1 *info, char *name)
3720 init_unistr(&(info->name), name);
3723 /****************************************************************************
3724 ****************************************************************************/
3725 static uint32 getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environment, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
3729 pstring short_archi;
3730 DRIVER_DIRECTORY_1 *info=NULL;
3732 if((info=(DRIVER_DIRECTORY_1 *)malloc(sizeof(DRIVER_DIRECTORY_1))) == NULL)
3733 return ERROR_NOT_ENOUGH_MEMORY;
3735 unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)-1);
3736 get_short_archi(short_archi, long_archi);
3738 slprintf(chaine, sizeof(chaine)-1, "\\\\%s\\print$\\%s", global_myname, short_archi);
3740 DEBUG(4,("printer driver directory: [%s]\n", chaine));
3742 fill_driverdir_1(info, chaine);
3744 *needed += spoolss_size_driverdir_info_1(info);
3746 if (!alloc_buffer_size(buffer, *needed)) {
3748 return ERROR_INSUFFICIENT_BUFFER;
3751 new_smb_io_driverdir_1("", buffer, info, 0);
3755 if (*needed > offered)
3756 return ERROR_INSUFFICIENT_BUFFER;
3758 return NT_STATUS_NO_PROBLEMO;
3761 /****************************************************************************
3762 ****************************************************************************/
3763 uint32 _spoolss_getprinterdriverdirectory(UNISTR2 *name, UNISTR2 *uni_environment, uint32 level,
3764 NEW_BUFFER *buffer, uint32 offered,
3767 DEBUG(4,("_spoolss_getprinterdriverdirectory\n"));
3773 return getprinterdriverdir_level_1(name, uni_environment, buffer, offered, needed);
3776 return ERROR_INVALID_LEVEL;
3781 /****************************************************************************
3782 ****************************************************************************/
3783 uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx,
3784 uint32 in_value_len, uint32 in_data_len,
3785 uint32 *out_max_value_len, uint16 **out_value, uint32 *out_value_len,
3787 uint32 *out_max_data_len, uint8 **data_out, uint32 *out_data_len)
3789 NT_PRINTER_INFO_LEVEL printer;
3794 uint32 biggest_valuesize;
3795 uint32 biggest_datasize;
3797 Printer_entry *Printer = find_printer_index_by_hnd(handle);
3802 ZERO_STRUCT(printer);
3804 *out_max_value_len=0;
3810 *out_max_data_len=0;
3814 DEBUG(5,("spoolss_enumprinterdata\n"));
3816 if (!OPEN_HANDLE(Printer))
3817 return ERROR_INVALID_HANDLE;
3819 if (!get_printer_snum(handle, &snum))
3820 return ERROR_INVALID_HANDLE;
3822 if (get_a_printer(&printer, 2, lp_servicename(snum)) != 0x0)
3823 return ERROR_INVALID_HANDLE;
3826 * The NT machine wants to know the biggest size of value and data
3828 * cf: MSDN EnumPrinterData remark section
3830 if ( (in_value_len==0) && (in_data_len==0) ) {
3831 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
3834 biggest_valuesize=0;
3837 while (get_specific_param_by_index(printer, 2, param_index, value, &data, &type, &data_len)) {
3838 if (strlen(value) > biggest_valuesize) biggest_valuesize=strlen(value);
3839 if (data_len > biggest_datasize) biggest_datasize=data_len;
3841 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize, biggest_datasize));
3847 /* the value is an UNICODE string but realvaluesize is the length in bytes including the leading 0 */
3848 *out_value_len=2*(1+biggest_valuesize);
3849 *out_data_len=biggest_datasize;
3851 DEBUG(6,("final values: [%d], [%d]\n", *out_value_len, *out_data_len));
3853 free_a_printer(printer, 2);
3854 return NT_STATUS_NO_PROBLEMO;
3858 * the value len is wrong in NT sp3
3859 * that's the number of bytes not the number of unicode chars
3862 if (!get_specific_param_by_index(printer, 2, idx, value, &data, &type, &data_len)) {
3863 free_a_printer(printer, 2);
3865 return ERROR_NO_MORE_ITEMS;
3870 * - counted in bytes in the request
3871 * - counted in UNICODE chars in the max reply
3872 * - counted in bytes in the real size
3874 * take a pause *before* coding not *during* coding
3877 *out_max_value_len=in_value_len/2;
3878 if((*out_value=(uint16 *)malloc(in_value_len*sizeof(uint8))) == NULL) {
3879 free_a_printer(printer, 2);
3881 return ERROR_NOT_ENOUGH_MEMORY;
3883 ascii_to_unistr(*out_value, value, *out_max_value_len);
3884 *out_value_len=2*(1+strlen(value));
3888 /* the data is counted in bytes */
3889 *out_max_data_len=in_data_len;
3890 if((*data_out=(uint8 *)malloc(in_data_len*sizeof(uint8))) == NULL) {
3891 free_a_printer(printer, 2);
3893 return ERROR_NOT_ENOUGH_MEMORY;
3895 memcpy(*data_out, data, data_len);
3896 *out_data_len=data_len;
3900 free_a_printer(printer, 2);
3901 return NT_STATUS_NO_PROBLEMO;
3904 /****************************************************************************
3905 ****************************************************************************/
3906 uint32 _spoolss_setprinterdata( const POLICY_HND *handle,
3907 const UNISTR2 *value,
3912 uint32 numeric_data)
3914 NT_PRINTER_INFO_LEVEL printer;
3915 NT_PRINTER_PARAM *param = NULL;
3918 uint32 status = 0x0;
3919 Printer_entry *Printer=find_printer_index_by_hnd(handle);
3921 DEBUG(5,("spoolss_setprinterdata\n"));
3924 if (!OPEN_HANDLE(Printer))
3925 return ERROR_INVALID_HANDLE;
3927 if (!get_printer_snum(handle, &snum))
3928 return ERROR_INVALID_HANDLE;
3930 status = get_a_printer(&printer, 2, lp_servicename(snum));
3932 return ERROR_INVALID_NAME;
3934 convert_specific_param(¶m, value , type, data, real_len);
3935 unlink_specific_param_if_exist(printer.info_2, param);
3937 if (!add_a_specific_param(printer.info_2, param))
3938 status = ERROR_INVALID_PARAMETER;
3940 status = add_a_printer(printer, 2);
3942 free_a_printer(printer, 2);
3947 /****************************************************************************
3948 ****************************************************************************/
3949 uint32 _spoolss_addform( const POLICY_HND *handle,
3954 nt_forms_struct *list=NULL;
3955 Printer_entry *Printer = find_printer_index_by_hnd(handle);
3957 DEBUG(5,("spoolss_addform\n"));
3959 if (!OPEN_HANDLE(Printer))
3960 return ERROR_INVALID_HANDLE;
3962 count=get_ntforms(&list);
3963 if(!add_a_form(&list, form, &count))
3964 return ERROR_NOT_ENOUGH_MEMORY;
3965 write_ntforms(&list, count);
3972 /****************************************************************************
3973 ****************************************************************************/
3974 uint32 _spoolss_setform( const POLICY_HND *handle,
3975 const UNISTR2 *uni_name,
3980 nt_forms_struct *list=NULL;
3981 Printer_entry *Printer = find_printer_index_by_hnd(handle);
3983 DEBUG(5,("spoolss_setform\n"));
3985 if (!OPEN_HANDLE(Printer))
3987 return ERROR_INVALID_HANDLE;
3989 count=get_ntforms(&list);
3990 update_a_form(&list, form, count);
3991 write_ntforms(&list, count);
3998 /****************************************************************************
3999 enumprintprocessors level 1.
4000 ****************************************************************************/
4001 static uint32 enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4003 PRINTPROCESSOR_1 *info_1=NULL;
4005 if((info_1 = (PRINTPROCESSOR_1 *)malloc(sizeof(PRINTPROCESSOR_1))) == NULL)
4006 return ERROR_NOT_ENOUGH_MEMORY;
4010 init_unistr(&(info_1->name), "winprint");
4012 *needed += spoolss_size_printprocessor_info_1(info_1);
4014 if (!alloc_buffer_size(buffer, *needed))
4015 return ERROR_INSUFFICIENT_BUFFER;
4017 smb_io_printprocessor_info_1("", buffer, info_1, 0);
4021 if (*needed > offered) {
4023 return ERROR_INSUFFICIENT_BUFFER;
4026 return NT_STATUS_NO_PROBLEMO;
4029 /****************************************************************************
4030 ****************************************************************************/
4031 uint32 _spoolss_enumprintprocessors(UNISTR2 *name, UNISTR2 *environment, uint32 level,
4032 NEW_BUFFER *buffer, uint32 offered,
4033 uint32 *needed, uint32 *returned)
4035 DEBUG(5,("spoolss_enumprintprocessors\n"));
4038 * Enumerate the print processors ...
4040 * Just reply with "winprint", to keep NT happy
4041 * and I can use my nice printer checker.
4049 return enumprintprocessors_level_1(buffer, offered, needed, returned);
4052 return ERROR_INVALID_LEVEL;
4057 /****************************************************************************
4058 enumprintprocdatatypes level 1.
4059 ****************************************************************************/
4060 static uint32 enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4062 PRINTPROCDATATYPE_1 *info_1=NULL;
4064 if((info_1 = (PRINTPROCDATATYPE_1 *)malloc(sizeof(PRINTPROCDATATYPE_1))) == NULL)
4065 return ERROR_NOT_ENOUGH_MEMORY;
4069 init_unistr(&(info_1->name), "RAW");
4071 *needed += spoolss_size_printprocdatatype_info_1(info_1);
4073 if (!alloc_buffer_size(buffer, *needed))
4074 return ERROR_INSUFFICIENT_BUFFER;
4076 smb_io_printprocdatatype_info_1("", buffer, info_1, 0);
4080 if (*needed > offered) {
4082 return ERROR_INSUFFICIENT_BUFFER;
4085 return NT_STATUS_NO_PROBLEMO;
4088 /****************************************************************************
4089 ****************************************************************************/
4090 uint32 _spoolss_enumprintprocdatatypes(UNISTR2 *name, UNISTR2 *processor, uint32 level,
4091 NEW_BUFFER *buffer, uint32 offered,
4092 uint32 *needed, uint32 *returned)
4094 DEBUG(5,("_spoolss_enumprintprocdatatypes\n"));
4101 return enumprintprocdatatypes_level_1(buffer, offered, needed, returned);
4104 return ERROR_INVALID_LEVEL;
4109 /****************************************************************************
4110 enumprintmonitors level 1.
4111 ****************************************************************************/
4112 static uint32 enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4114 PRINTMONITOR_1 *info_1=NULL;
4116 if((info_1 = (PRINTMONITOR_1 *)malloc(sizeof(PRINTMONITOR_1))) == NULL)
4117 return ERROR_NOT_ENOUGH_MEMORY;
4121 init_unistr(&(info_1->name), "Local Port");
4123 *needed += spoolss_size_printmonitor_info_1(info_1);
4125 if (!alloc_buffer_size(buffer, *needed))
4126 return ERROR_INSUFFICIENT_BUFFER;
4128 smb_io_printmonitor_info_1("", buffer, info_1, 0);
4132 if (*needed > offered) {
4134 return ERROR_INSUFFICIENT_BUFFER;
4137 return NT_STATUS_NO_PROBLEMO;
4140 /****************************************************************************
4141 enumprintmonitors level 2.
4142 ****************************************************************************/
4143 static uint32 enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4145 PRINTMONITOR_2 *info_2=NULL;
4147 if((info_2 = (PRINTMONITOR_2 *)malloc(sizeof(PRINTMONITOR_2))) == NULL)
4148 return ERROR_NOT_ENOUGH_MEMORY;
4152 init_unistr(&(info_2->name), "Local Port");
4153 init_unistr(&(info_2->environment), "Windows NT X86");
4154 init_unistr(&(info_2->dll_name), "localmon.dll");
4156 *needed += spoolss_size_printmonitor_info_2(info_2);
4158 if (!alloc_buffer_size(buffer, *needed))
4159 return ERROR_INSUFFICIENT_BUFFER;
4161 smb_io_printmonitor_info_2("", buffer, info_2, 0);
4165 if (*needed > offered) {
4167 return ERROR_INSUFFICIENT_BUFFER;
4170 return NT_STATUS_NO_PROBLEMO;
4173 /****************************************************************************
4174 ****************************************************************************/
4175 uint32 _spoolss_enumprintmonitors(UNISTR2 *name,uint32 level,
4176 NEW_BUFFER *buffer, uint32 offered,
4177 uint32 *needed, uint32 *returned)
4179 DEBUG(5,("spoolss_enumprintmonitors\n"));
4182 * Enumerate the print monitors ...
4184 * Just reply with "Local Port", to keep NT happy
4185 * and I can use my nice printer checker.
4193 return enumprintmonitors_level_1(buffer, offered, needed, returned);
4196 return enumprintmonitors_level_2(buffer, offered, needed, returned);
4199 return ERROR_INVALID_LEVEL;
4204 /****************************************************************************
4205 ****************************************************************************/
4206 static uint32 getjob_level_1(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
4210 JOB_INFO_1 *info_1=NULL;
4212 info_1=(JOB_INFO_1 *)malloc(sizeof(JOB_INFO_1));
4214 if (info_1 == NULL) {
4216 return ERROR_NOT_ENOUGH_MEMORY;
4219 for (i=0; i<count && found==False; i++) {
4220 if (queue[i].job==(int)jobid)
4227 /* I shoud reply something else ... I can't find the good one */
4228 return NT_STATUS_NO_PROBLEMO;
4231 fill_job_info_1(info_1, &(queue[i-1]), i, snum);
4235 *needed += spoolss_size_job_info_1(info_1);
4237 if (!alloc_buffer_size(buffer, *needed)) {
4239 return ERROR_INSUFFICIENT_BUFFER;
4242 new_smb_io_job_info_1("", buffer, info_1, 0);
4246 if (*needed > offered)
4247 return ERROR_INSUFFICIENT_BUFFER;
4249 return NT_STATUS_NO_PROBLEMO;
4253 /****************************************************************************
4254 ****************************************************************************/
4255 static uint32 getjob_level_2(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
4259 JOB_INFO_2 *info_2=NULL;
4260 info_2=(JOB_INFO_2 *)malloc(sizeof(JOB_INFO_2));
4262 if (info_2 == NULL) {
4264 return ERROR_NOT_ENOUGH_MEMORY;
4267 for (i=0; i<count && found==False; i++) {
4268 if (queue[i].job==(int)jobid)
4275 /* I shoud reply something else ... I can't find the good one */
4276 return NT_STATUS_NO_PROBLEMO;
4279 fill_job_info_2(info_2, &(queue[i-1]), i, snum);
4283 *needed += spoolss_size_job_info_2(info_2);
4285 if (!alloc_buffer_size(buffer, *needed)) {
4287 return ERROR_INSUFFICIENT_BUFFER;
4290 new_smb_io_job_info_2("", buffer, info_2, 0);
4294 if (*needed > offered)
4295 return ERROR_INSUFFICIENT_BUFFER;
4297 return NT_STATUS_NO_PROBLEMO;
4300 /****************************************************************************
4301 ****************************************************************************/
4302 uint32 _spoolss_getjob( POLICY_HND *handle, uint32 jobid, uint32 level,
4303 NEW_BUFFER *buffer, uint32 offered,
4308 print_queue_struct *queue=NULL;
4309 print_status_struct prt_status;
4311 DEBUG(5,("spoolss_getjob\n"));
4313 memset(&prt_status, 0, sizeof(prt_status));
4317 if (!get_printer_snum(handle, &snum))
4318 return ERROR_INVALID_HANDLE;
4320 count = print_queue_status(snum, &queue, &prt_status);
4322 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
4323 count, prt_status.status, prt_status.message));
4327 return getjob_level_1(queue, count, snum, jobid, buffer, offered, needed);
4330 return getjob_level_2(queue, count, snum, jobid, buffer, offered, needed);
4334 return ERROR_INVALID_LEVEL;