3 * Unix SMB/Netbios implementation.
5 * RPC Pipe client / server routines
6 * Copyright (C) Andrew Tridgell 1992-2000,
7 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
8 * Copyright (C) Jean François Micouleau 1998-2000.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #ifndef MANGLE_DRIVER_PATH
29 #define MANGLE_DRIVER_PATH 0
32 extern int DEBUGLEVEL;
33 extern pstring global_myname;
35 #ifndef MAX_OPEN_PRINTER_EXS
36 #define MAX_OPEN_PRINTER_EXS 50
39 #define PRINTER_HANDLE_IS_PRINTER 0
40 #define PRINTER_HANDLE_IS_PRINTSERVER 1
42 /* structure to store the printer handles */
43 /* and a reference to what it's pointing to */
44 /* and the notify info asked about */
45 /* that's the central struct */
46 typedef struct _Printer{
51 BOOL document_started;
53 int jobid; /* jobid in printing backend */
54 POLICY_HND printer_hnd;
58 fstring printerservername;
67 SPOOL_NOTIFY_OPTION *option;
75 typedef struct _counter_printer_0 {
83 static ubi_dlList Printer_list;
84 static ubi_dlList counter_list;
87 #define OPEN_HANDLE(pnum) ((pnum!=NULL) && (pnum->open!=False))
89 /* translate between internal status numbers and NT status numbers */
90 static int nt_printj_status(int v)
94 return PRINTER_STATUS_PAUSED;
103 static int nt_printq_status(int v)
107 return PRINTER_STATUS_ERROR;
116 /****************************************************************************
117 initialise printer handle states...
118 ****************************************************************************/
119 void init_printer_hnd(void)
121 ubi_dlInitList(&Printer_list);
122 ubi_dlInitList(&counter_list);
125 /****************************************************************************
126 create a unique printer handle
127 ****************************************************************************/
128 static void create_printer_hnd(POLICY_HND *hnd)
130 static uint32 prt_hnd_low = 0;
131 static uint32 prt_hnd_high = 0;
133 if (hnd == NULL) return;
135 /* i severely doubt that prt_hnd_high will ever be non-zero... */
137 if (prt_hnd_low == 0) prt_hnd_high++;
139 SIVAL(hnd->data, 0 , 0x0); /* first bit must be null */
140 SIVAL(hnd->data, 4 , prt_hnd_low ); /* second bit is incrementing */
141 SIVAL(hnd->data, 8 , prt_hnd_high); /* second bit is incrementing */
142 SIVAL(hnd->data, 12, time(NULL)); /* something random */
143 SIVAL(hnd->data, 16, sys_getpid()); /* something more random */
146 /****************************************************************************
147 find printer index by handle
148 ****************************************************************************/
149 static Printer_entry *find_printer_index_by_hnd(const POLICY_HND *hnd)
151 Printer_entry *find_printer;
153 find_printer = (Printer_entry *)ubi_dlFirst(&Printer_list);
155 for(; find_printer; find_printer = (Printer_entry *)ubi_dlNext(find_printer)) {
157 if (memcmp(&(find_printer->printer_hnd), hnd, sizeof(*hnd)) == 0) {
158 DEBUG(4,("Found printer handle \n"));
159 /*dump_data(4, hnd->data, sizeof(hnd->data));*/
164 DEBUG(3,("Whoops, Printer handle not found: "));
165 /*dump_data(4, hnd->data, sizeof(hnd->data));*/
169 /****************************************************************************
171 ****************************************************************************/
172 static void clear_handle(POLICY_HND *hnd)
177 /****************************************************************************
178 close printer index by handle
179 ****************************************************************************/
180 static BOOL close_printer_handle(POLICY_HND *hnd)
182 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
184 if (!OPEN_HANDLE(Printer)) {
185 DEBUG(3,("Error closing printer handle\n"));
190 Printer->notify.flags=0;
191 Printer->notify.options=0;
192 Printer->notify.localmachine[0]='\0';
193 Printer->notify.printerlocal=0;
194 safe_free(Printer->notify.option);
195 Printer->notify.option=NULL;
199 ubi_dlRemThis(&Printer_list, Printer);
206 /****************************************************************************
207 delete a printer given a handle
208 ****************************************************************************/
209 static BOOL delete_printer_handle(POLICY_HND *hnd)
211 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
213 if (!OPEN_HANDLE(Printer)) {
214 DEBUG(3,("Error closing printer handle\n"));
218 if (del_a_printer(Printer->dev.printername) != 0) {
219 DEBUG(3,("Error deleting printer %s\n", Printer->dev.printername));
226 /****************************************************************************
227 return the snum of a printer corresponding to an handle
228 ****************************************************************************/
229 static BOOL get_printer_snum(const POLICY_HND *hnd, int *number)
231 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
233 if (!OPEN_HANDLE(Printer)) {
234 DEBUG(3,("Error getting printer - take a nap quickly !\n"));
238 switch (Printer->printer_type) {
239 case PRINTER_HANDLE_IS_PRINTER:
240 DEBUG(4,("short name:%s\n", Printer->dev.printername));
241 *number = print_queue_snum(Printer->dev.printername);
242 return (*number != -1);
243 case PRINTER_HANDLE_IS_PRINTSERVER:
252 /****************************************************************************
253 find first available printer slot. creates a printer handle for you.
254 ****************************************************************************/
255 static BOOL open_printer_hnd(POLICY_HND *hnd)
257 Printer_entry *new_printer;
259 if((new_printer=(Printer_entry *)malloc(sizeof(Printer_entry))) == NULL)
262 ZERO_STRUCTP(new_printer);
264 new_printer->open = True;
265 new_printer->notify.option=NULL;
267 memcpy(&new_printer->printer_hnd, hnd, sizeof(*hnd));
269 ubi_dlAddHead( &Printer_list, (ubi_dlNode *)new_printer);
274 /****************************************************************************
275 set printer handle type.
276 ****************************************************************************/
277 static BOOL set_printer_hnd_accesstype(POLICY_HND *hnd, uint32 access_required)
279 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
281 if (!OPEN_HANDLE(Printer)) {
282 DEBUG(4,("Error setting printer type=%x", access_required));
286 DEBUG(4,("Setting printer access=%x\n", access_required));
287 Printer->access = access_required;
291 /****************************************************************************
292 set printer handle type.
293 check if it's \\server or \\server\printer
294 ****************************************************************************/
295 static BOOL set_printer_hnd_printertype(POLICY_HND *hnd, char *printername)
297 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
299 if (!OPEN_HANDLE(Printer)) {
300 DEBUGADD(4,("Error setting printer name %s", printername));
304 DEBUG(3,("Setting printer type=%s\n", printername));
306 if ( strlen(printername) < 3 ) {
307 DEBUGADD(4,("A print server must have at least 1 char ! %s\n", printername));
311 /* it's a print server */
312 if (!strchr(printername+2, '\\')) {
313 DEBUGADD(4,("Printer is a print server\n"));
314 Printer->printer_type = PRINTER_HANDLE_IS_PRINTSERVER;
319 DEBUGADD(4,("Printer is a printer\n"));
320 Printer->printer_type = PRINTER_HANDLE_IS_PRINTER;
327 /****************************************************************************
328 set printer handle printername.
329 ****************************************************************************/
330 static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername)
332 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
333 NT_PRINTER_INFO_LEVEL *printer = NULL;
335 int n_services=lp_numservices();
339 if (!OPEN_HANDLE(Printer)) {
340 DEBUG(0,("Error setting printer name=%s\n", printername));
344 DEBUG(4,("Setting printer name=%s (len=%d)\n", printername, strlen(printername)));
346 if (Printer->printer_type==PRINTER_HANDLE_IS_PRINTSERVER) {
347 ZERO_STRUCT(Printer->dev.printerservername);
348 strncpy(Printer->dev.printerservername, printername, strlen(printername));
352 if (Printer->printer_type!=PRINTER_HANDLE_IS_PRINTER)
355 aprinter=strchr(printername+2, '\\');
358 DEBUGADD(5,("searching for [%s] (len=%d)\n", aprinter, strlen(aprinter)));
361 * store the Samba share name in it
362 * in back we have the long printer name
363 * need to iterate all the snum and do a
364 * get_a_printer each time to find the printer
365 * faster to do it here than later.
368 for (snum=0;snum<n_services && found==False;snum++) {
370 if ( !(lp_snum_ok(snum) && lp_print_ok(snum) ) )
373 DEBUGADD(5,("share:%s\n",lp_servicename(snum)));
375 if (get_a_printer(&printer, 2, lp_servicename(snum))!=0)
378 DEBUG(10,("set_printer_hnd_printername: printername [%s], aprinter [%s]\n",
379 printer->info_2->printername, aprinter ));
381 if ( strlen(printer->info_2->printername) != strlen(aprinter) ) {
382 free_a_printer(&printer, 2);
386 if ( strncasecmp(printer->info_2->printername, aprinter, strlen(aprinter))) {
387 free_a_printer(&printer, 2);
395 * if we haven't found a printer with the given printername
396 * then it can be a share name as you can open both \\server\printer and
401 * we still check if the printer description file exists as NT won't be happy
402 * if we reply OK in the openprinter call and can't reply in the subsequent RPC calls
406 DEBUGADD(5,("Printer not found, checking for share now\n"));
408 for (snum=0;snum<n_services && found==False;snum++) {
410 if ( !(lp_snum_ok(snum) && lp_print_ok(snum) ) )
413 DEBUGADD(5,("set_printer_hnd_printername: share:%s\n",lp_servicename(snum)));
415 if (get_a_printer(&printer, 2, lp_servicename(snum))!=0)
418 DEBUG(10,("set_printer_hnd_printername: printername [%s], aprinter [%s]\n",
419 printer->info_2->printername, aprinter ));
421 if ( strlen(lp_servicename(snum)) != strlen(aprinter) ) {
422 free_a_printer(&printer, 2);
426 if ( strncasecmp(lp_servicename(snum), aprinter, strlen(aprinter))) {
427 free_a_printer(&printer, 2);
436 DEBUGADD(4,("Printer not found\n"));
441 DEBUGADD(4,("set_printer_hnd_printername: Printer found: %s -> %s[%x]\n",
442 printer->info_2->printername, lp_servicename(snum),snum));
444 ZERO_STRUCT(Printer->dev.printername);
445 strncpy(Printer->dev.printername, lp_servicename(snum), strlen(lp_servicename(snum)));
447 free_a_printer(&printer, 2);
452 /********************************************************************
453 Return True is the handle is a print server.
454 ********************************************************************/
455 static BOOL handle_is_printserver(const POLICY_HND *handle)
457 Printer_entry *Printer=find_printer_index_by_hnd(handle);
459 if (!OPEN_HANDLE(Printer))
462 if (Printer->printer_type != PRINTER_HANDLE_IS_PRINTSERVER)
468 /****************************************************************************
469 allocate more memory for a BUFFER.
470 ****************************************************************************/
471 static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size)
479 /* damn, I'm doing the reverse operation of prs_grow() :) */
480 if (buffer_size < prs_data_size(ps))
483 extra_space = buffer_size - prs_data_size(ps);
486 * save the offset and move to the end of the buffer
487 * prs_grow() checks the extra_space against the offset
489 old_offset=prs_offset(ps);
490 prs_set_offset(ps, prs_data_size(ps));
492 if (!prs_grow(ps, extra_space))
495 prs_set_offset(ps, old_offset);
497 buffer->string_at_end=prs_data_size(ps);
502 /********************************************************************
503 * spoolss_open_printer
505 * called from the spoolss dispatcher
506 ********************************************************************/
507 uint32 _spoolss_open_printer_ex( const UNISTR2 *printername,
508 const PRINTER_DEFAULT *printer_default,
509 uint32 user_switch, SPOOL_USER_CTR user_ctr,
514 clear_handle(handle);
516 if (printername == NULL)
517 return ERROR_INVALID_PRINTER_NAME;
519 /* some sanity check because you can open a printer or a print server */
520 /* aka: \\server\printer or \\server */
521 unistr2_to_ascii(name, printername, sizeof(name)-1);
523 DEBUGADD(3,("checking name: %s\n",name));
525 create_printer_hnd(handle);
527 open_printer_hnd(handle);
529 if (!set_printer_hnd_printertype(handle, name)) {
530 close_printer_handle(handle);
531 return ERROR_INVALID_PRINTER_NAME;
534 if (!set_printer_hnd_printername(handle, name)) {
535 close_printer_handle(handle);
536 return ERROR_INVALID_PRINTER_NAME;
540 if (printer_default->datatype_ptr != NULL)
542 unistr2_to_ascii(datatype, printer_default->datatype, sizeof(datatype)-1);
543 set_printer_hnd_datatype(handle, datatype);
546 set_printer_hnd_datatype(handle, "");
549 if (!set_printer_hnd_accesstype(handle, printer_default->access_required)) {
550 close_printer_handle(handle);
551 return ERROR_ACCESS_DENIED;
554 return NT_STATUS_NO_PROBLEMO;
557 /****************************************************************************
558 ****************************************************************************/
559 static BOOL convert_printer_info(const SPOOL_PRINTER_INFO_LEVEL *uni,
560 NT_PRINTER_INFO_LEVEL *printer, uint32 level)
564 uni_2_asc_printer_info_2(uni->info_2, &printer->info_2);
573 static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL *uni,
574 NT_PRINTER_DRIVER_INFO_LEVEL *printer, uint32 level)
578 printer->info_3=NULL;
579 uni_2_asc_printer_driver_3(uni->info_3, &printer->info_3);
582 printer->info_6=NULL;
583 uni_2_asc_printer_driver_6(uni->info_6, &printer->info_6);
592 static BOOL convert_devicemode(const DEVICEMODE *devmode, NT_DEVICEMODE *nt_devmode)
594 unistr_to_dos(nt_devmode->devicename, (const char *)devmode->devicename.buffer, 31);
595 unistr_to_dos(nt_devmode->formname, (const char *)devmode->formname.buffer, 31);
597 nt_devmode->specversion=devmode->specversion;
598 nt_devmode->driverversion=devmode->driverversion;
599 nt_devmode->size=devmode->size;
600 nt_devmode->driverextra=devmode->driverextra;
601 nt_devmode->fields=devmode->fields;
602 nt_devmode->orientation=devmode->orientation;
603 nt_devmode->papersize=devmode->papersize;
604 nt_devmode->paperlength=devmode->paperlength;
605 nt_devmode->paperwidth=devmode->paperwidth;
606 nt_devmode->scale=devmode->scale;
607 nt_devmode->copies=devmode->copies;
608 nt_devmode->defaultsource=devmode->defaultsource;
609 nt_devmode->printquality=devmode->printquality;
610 nt_devmode->color=devmode->color;
611 nt_devmode->duplex=devmode->duplex;
612 nt_devmode->yresolution=devmode->yresolution;
613 nt_devmode->ttoption=devmode->ttoption;
614 nt_devmode->collate=devmode->collate;
616 nt_devmode->logpixels=devmode->logpixels;
617 nt_devmode->bitsperpel=devmode->bitsperpel;
618 nt_devmode->pelswidth=devmode->pelswidth;
619 nt_devmode->pelsheight=devmode->pelsheight;
620 nt_devmode->displayflags=devmode->displayflags;
621 nt_devmode->displayfrequency=devmode->displayfrequency;
622 nt_devmode->icmmethod=devmode->icmmethod;
623 nt_devmode->icmintent=devmode->icmintent;
624 nt_devmode->mediatype=devmode->mediatype;
625 nt_devmode->dithertype=devmode->dithertype;
626 nt_devmode->reserved1=devmode->reserved1;
627 nt_devmode->reserved2=devmode->reserved2;
628 nt_devmode->panningwidth=devmode->panningwidth;
629 nt_devmode->panningheight=devmode->panningheight;
631 if (nt_devmode->driverextra != 0) {
632 /* if we had a previous private delete it and make a new one */
633 safe_free(nt_devmode->private);
634 if((nt_devmode->private=(uint8 *)malloc(nt_devmode->driverextra * sizeof(uint8))) == NULL)
636 memcpy(nt_devmode->private, devmode->private, nt_devmode->driverextra);
642 /********************************************************************
643 * api_spoolss_closeprinter
644 ********************************************************************/
645 uint32 _spoolss_closeprinter(POLICY_HND *handle)
647 if (!close_printer_handle(handle))
648 return ERROR_INVALID_HANDLE;
650 return NT_STATUS_NO_PROBLEMO;
653 /********************************************************************
654 * api_spoolss_deleteprinter
655 ********************************************************************/
656 uint32 _spoolss_deleteprinter(POLICY_HND *handle)
658 if (!delete_printer_handle(handle))
659 return ERROR_INVALID_HANDLE;
661 return NT_STATUS_NO_PROBLEMO;
664 /********************************************************************
665 GetPrinterData on a printer server Handle.
666 ********************************************************************/
667 static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **data, uint32 *needed, uint32 in_size)
671 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
673 if (!strcmp(value, "BeepEnabled")) {
675 if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL)
677 SIVAL(*data, 0, 0x01);
682 if (!strcmp(value, "EventLog")) {
684 if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL)
686 SIVAL(*data, 0, 0x1B);
691 if (!strcmp(value, "NetPopup")) {
693 if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL)
695 SIVAL(*data, 0, 0x01);
700 if (!strcmp(value, "MajorVersion")) {
702 if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL)
704 SIVAL(*data, 0, 0x02);
709 if (!strcmp(value, "DefaultSpoolDirectory")) {
710 pstring string="You are using a Samba server";
712 *needed = 2*(strlen(string)+1);
713 if((*data = (uint8 *)malloc( ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL)
715 memset(*data, 0, (*needed > in_size) ? *needed:in_size);
717 /* it's done by hand ready to go on the wire */
718 for (i=0; i<strlen(string); i++) {
719 (*data)[2*i]=string[i];
725 if (!strcmp(value, "Architecture")) {
726 pstring string="Windows NT x86";
728 *needed = 2*(strlen(string)+1);
729 if((*data = (uint8 *)malloc( ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL)
731 memset(*data, 0, (*needed > in_size) ? *needed:in_size);
732 for (i=0; i<strlen(string); i++) {
733 (*data)[2*i]=string[i];
742 /********************************************************************
743 GetPrinterData on a printer Handle.
744 ********************************************************************/
745 static BOOL getprinterdata_printer(const POLICY_HND *handle,
746 fstring value, uint32 *type,
747 uint8 **data, uint32 *needed, uint32 in_size )
749 NT_PRINTER_INFO_LEVEL *printer = NULL;
753 Printer_entry *Printer = find_printer_index_by_hnd(handle);
755 DEBUG(5,("getprinterdata_printer\n"));
757 if (!OPEN_HANDLE(Printer))
760 if(!get_printer_snum(handle, &snum))
763 if(get_a_printer(&printer, 2, lp_servicename(snum)) != 0)
766 if (!get_specific_param(*printer, 2, value, &idata, type, &len)) {
767 free_a_printer(&printer, 2);
771 free_a_printer(&printer, 2);
773 DEBUG(5,("getprinterdata_printer:allocating %d\n", in_size));
776 if((*data = (uint8 *)malloc( in_size *sizeof(uint8) )) == NULL) {
780 memset(*data, 0, in_size *sizeof(uint8));
781 /* copy the min(in_size, len) */
782 memcpy(*data, idata, (len>in_size)?in_size:len *sizeof(uint8));
789 DEBUG(5,("getprinterdata_printer:copy done\n"));
796 /********************************************************************
797 * spoolss_getprinterdata
798 ********************************************************************/
799 uint32 _spoolss_getprinterdata(const POLICY_HND *handle, UNISTR2 *valuename,
808 Printer_entry *Printer = find_printer_index_by_hnd(handle);
811 * Reminder: when it's a string, the length is in BYTES
812 * even if UNICODE is negociated.
819 /* in case of problem, return some default values */
823 DEBUG(4,("_spoolss_getprinterdata\n"));
825 if (!OPEN_HANDLE(Printer)) {
826 if((*data=(uint8 *)malloc(4*sizeof(uint8))) == NULL)
827 return ERROR_NOT_ENOUGH_MEMORY;
828 return ERROR_INVALID_HANDLE;
831 unistr2_to_ascii(value, valuename, sizeof(value)-1);
833 if (handle_is_printserver(handle))
834 found=getprinterdata_printer_server(value, type, data, needed, *out_size);
836 found=getprinterdata_printer(handle, value, type, data, needed, *out_size);
839 DEBUG(5, ("value not found, allocating %d\n", *out_size));
840 /* reply this param doesn't exist */
842 if((*data=(uint8 *)malloc(*out_size*sizeof(uint8))) == NULL)
843 return ERROR_NOT_ENOUGH_MEMORY;
844 memset(*data, '\0', *out_size*sizeof(uint8));
849 return ERROR_INVALID_PARAMETER;
852 if (*needed > *out_size)
853 return ERROR_INSUFFICIENT_BUFFER;
855 return NT_STATUS_NO_PROBLEMO;
858 /********************************************************************
860 * ReplyFindFirstPrinterChangeNotifyEx
862 * jfmxxxx: before replying OK: status=0
863 * should do a rpc call to the workstation asking ReplyOpenPrinter
864 * have to code it, later.
866 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
867 * called from api_spoolss_rffpcnex
868 ********************************************************************/
869 uint32 _spoolss_rffpcnex(const POLICY_HND *handle, uint32 flags, uint32 options,
870 const UNISTR2 *localmachine, uint32 printerlocal,
871 SPOOL_NOTIFY_OPTION *option)
873 /* store the notify value in the printer struct */
875 Printer_entry *Printer=find_printer_index_by_hnd(handle);
877 if (!OPEN_HANDLE(Printer))
878 return ERROR_INVALID_HANDLE;
880 Printer->notify.flags=flags;
881 Printer->notify.options=options;
882 Printer->notify.printerlocal=printerlocal;
883 Printer->notify.option=option;
884 unistr2_to_ascii(Printer->notify.localmachine, localmachine, sizeof(Printer->notify.localmachine)-1);
886 return NT_STATUS_NO_PROBLEMO;
889 /*******************************************************************
890 * fill a notify_info_data with the servername
891 ********************************************************************/
892 static void spoolss_notify_server_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue,
893 NT_PRINTER_INFO_LEVEL *printer)
897 snprintf(temp_name, sizeof(temp_name)-1, "\\\\%s", global_myname);
899 data->notify_data.data.length= (uint32)((dos_PutUniCode((char *)data->notify_data.data.string,
900 temp_name, sizeof(data->notify_data.data.string), True) - sizeof(uint16))/sizeof(uint16));
903 /*******************************************************************
904 * fill a notify_info_data with the servicename
905 * jfmxxxx: it's incorrect should be long_printername
906 ********************************************************************/
907 static void spoolss_notify_printer_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue,
908 NT_PRINTER_INFO_LEVEL *printer)
911 data->notify_data.data.length=strlen(lp_servicename(snum));
912 dos_PutUniCode(data->notify_data.data.string, lp_servicename(snum), sizeof(data->notify_data.data.string), True);
914 data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string,
915 printer->info_2->printername, sizeof(data->notify_data.data.string), True) - sizeof(uint16))/sizeof(uint16));
918 /*******************************************************************
919 * fill a notify_info_data with the servicename
920 ********************************************************************/
921 static void spoolss_notify_share_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
923 data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string,
924 lp_servicename(snum), sizeof(data->notify_data.data.string),True) - sizeof(uint16))/sizeof(uint16));
927 /*******************************************************************
928 * fill a notify_info_data with the port name
929 ********************************************************************/
930 static void spoolss_notify_port_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
932 /* even if it's strange, that's consistant in all the code */
934 data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string,
935 lp_servicename(snum), sizeof(data->notify_data.data.string), True) - sizeof(uint16))/sizeof(uint16));
938 /*******************************************************************
939 * fill a notify_info_data with the printername
940 * jfmxxxx: it's incorrect, should be lp_printerdrivername()
941 * but it doesn't exist, have to see what to do
942 ********************************************************************/
943 static void spoolss_notify_driver_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
945 data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string,
946 printer->info_2->drivername, sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16));
949 /*******************************************************************
950 * fill a notify_info_data with the comment
951 ********************************************************************/
952 static void spoolss_notify_comment(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
954 data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string,
955 lp_comment(snum), sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16));
958 /*******************************************************************
959 * fill a notify_info_data with the comment
960 * jfm:xxxx incorrect, have to create a new smb.conf option
961 * location = "Room 1, floor 2, building 3"
962 ********************************************************************/
963 static void spoolss_notify_location(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
965 data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string,
966 printer->info_2->location, sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16));
969 /*******************************************************************
970 * fill a notify_info_data with the device mode
971 * jfm:xxxx don't to it for know but that's a real problem !!!
972 ********************************************************************/
973 static void spoolss_notify_devmode(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
977 /*******************************************************************
978 * fill a notify_info_data with the separator file name
979 * jfm:xxxx just return no file could add an option to smb.conf
980 * separator file = "separator.txt"
981 ********************************************************************/
982 static void spoolss_notify_sepfile(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
984 data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string,
985 printer->info_2->sepfile, sizeof(data->notify_data.data.string)-1,True) - sizeof(uint16))/sizeof(uint16));
988 /*******************************************************************
989 * fill a notify_info_data with the print processor
990 * jfm:xxxx return always winprint to indicate we don't do anything to it
991 ********************************************************************/
992 static void spoolss_notify_print_processor(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
994 data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string,
995 printer->info_2->printprocessor, sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16));
998 /*******************************************************************
999 * fill a notify_info_data with the print processor options
1000 * jfm:xxxx send an empty string
1001 ********************************************************************/
1002 static void spoolss_notify_parameters(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1004 data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string,
1005 printer->info_2->parameters, sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16));
1008 /*******************************************************************
1009 * fill a notify_info_data with the data type
1010 * jfm:xxxx always send RAW as data type
1011 ********************************************************************/
1012 static void spoolss_notify_datatype(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1014 data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string,
1015 printer->info_2->datatype, sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16));
1018 /*******************************************************************
1019 * fill a notify_info_data with the security descriptor
1020 * jfm:xxxx send an null pointer to say no security desc
1021 * have to implement security before !
1022 ********************************************************************/
1023 static void spoolss_notify_security_desc(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1025 data->notify_data.data.length=0;
1026 data->notify_data.data.string[0]=0x00;
1029 /*******************************************************************
1030 * fill a notify_info_data with the attributes
1031 * jfm:xxxx a samba printer is always shared
1032 ********************************************************************/
1033 static void spoolss_notify_attributes(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1035 data->notify_data.value[0] = PRINTER_ATTRIBUTE_SHARED \
1036 | PRINTER_ATTRIBUTE_LOCAL \
1037 | PRINTER_ATTRIBUTE_RAW_ONLY ;
1040 /*******************************************************************
1041 * fill a notify_info_data with the priority
1042 ********************************************************************/
1043 static void spoolss_notify_priority(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1045 data->notify_data.value[0] = printer->info_2->priority;
1048 /*******************************************************************
1049 * fill a notify_info_data with the default priority
1050 ********************************************************************/
1051 static void spoolss_notify_default_priority(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1053 data->notify_data.value[0] = printer->info_2->default_priority;
1056 /*******************************************************************
1057 * fill a notify_info_data with the start time
1058 ********************************************************************/
1059 static void spoolss_notify_start_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1061 data->notify_data.value[0] = printer->info_2->starttime;
1064 /*******************************************************************
1065 * fill a notify_info_data with the until time
1066 ********************************************************************/
1067 static void spoolss_notify_until_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1069 data->notify_data.value[0] = printer->info_2->untiltime;
1072 /*******************************************************************
1073 * fill a notify_info_data with the status
1074 ********************************************************************/
1075 static void spoolss_notify_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1078 print_queue_struct *q=NULL;
1079 print_status_struct status;
1081 memset(&status, 0, sizeof(status));
1082 count = print_queue_status(snum, &q, &status);
1083 data->notify_data.value[0]=(uint32) status.status;
1087 /*******************************************************************
1088 * fill a notify_info_data with the number of jobs queued
1089 ********************************************************************/
1090 static void spoolss_notify_cjobs(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1092 print_queue_struct *q=NULL;
1093 print_status_struct status;
1095 memset(&status, 0, sizeof(status));
1096 data->notify_data.value[0] = print_queue_status(snum, &q, &status);
1100 /*******************************************************************
1101 * fill a notify_info_data with the average ppm
1102 ********************************************************************/
1103 static void spoolss_notify_average_ppm(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1105 /* always respond 8 pages per minutes */
1106 /* a little hard ! */
1107 data->notify_data.value[0] = printer->info_2->averageppm;
1110 /*******************************************************************
1111 * fill a notify_info_data with
1112 ********************************************************************/
1113 static void spoolss_notify_username(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1115 data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string,
1116 queue->user, sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16));
1119 /*******************************************************************
1120 * fill a notify_info_data with
1121 ********************************************************************/
1122 static void spoolss_notify_job_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1124 data->notify_data.value[0]=nt_printj_status(queue->status);
1127 /*******************************************************************
1128 * fill a notify_info_data with
1129 ********************************************************************/
1130 static void spoolss_notify_job_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1132 data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string,
1133 queue->file, sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16));
1136 /*******************************************************************
1137 * fill a notify_info_data with
1138 ********************************************************************/
1139 static void spoolss_notify_job_status_string(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1141 char *p = "unknown";
1142 switch (queue->status) {
1156 data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string,
1157 p, sizeof(data->notify_data.data.string)-1, True) - sizeof(uint16))/sizeof(uint16));
1160 /*******************************************************************
1161 * fill a notify_info_data with
1162 ********************************************************************/
1163 static void spoolss_notify_job_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1165 data->notify_data.value[0]=0x0;
1168 /*******************************************************************
1169 * fill a notify_info_data with
1170 ********************************************************************/
1171 static void spoolss_notify_job_size(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1173 data->notify_data.value[0]=queue->size;
1176 /*******************************************************************
1177 * fill a notify_info_data with
1178 ********************************************************************/
1179 static void spoolss_notify_job_position(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1181 data->notify_data.value[0]=queue->job;
1186 struct s_notify_info_data_table
1192 void (*fn) (int snum, SPOOL_NOTIFY_INFO_DATA *data,
1193 print_queue_struct *queue,
1194 NT_PRINTER_INFO_LEVEL *printer);
1197 struct s_notify_info_data_table notify_info_data_table[] =
1199 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SERVER_NAME, "PRINTER_NOTIFY_SERVER_NAME", POINTER, spoolss_notify_server_name },
1200 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINTER_NAME, "PRINTER_NOTIFY_PRINTER_NAME", POINTER, spoolss_notify_printer_name },
1201 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SHARE_NAME, "PRINTER_NOTIFY_SHARE_NAME", POINTER, spoolss_notify_share_name },
1202 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PORT_NAME, "PRINTER_NOTIFY_PORT_NAME", POINTER, spoolss_notify_port_name },
1203 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DRIVER_NAME, "PRINTER_NOTIFY_DRIVER_NAME", POINTER, spoolss_notify_driver_name },
1204 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_COMMENT, "PRINTER_NOTIFY_COMMENT", POINTER, spoolss_notify_comment },
1205 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_LOCATION, "PRINTER_NOTIFY_LOCATION", POINTER, spoolss_notify_location },
1206 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DEVMODE, "PRINTER_NOTIFY_DEVMODE", POINTER, spoolss_notify_devmode },
1207 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SEPFILE, "PRINTER_NOTIFY_SEPFILE", POINTER, spoolss_notify_sepfile },
1208 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINT_PROCESSOR, "PRINTER_NOTIFY_PRINT_PROCESSOR", POINTER, spoolss_notify_print_processor },
1209 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PARAMETERS, "PRINTER_NOTIFY_PARAMETERS", POINTER, spoolss_notify_parameters },
1210 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DATATYPE, "PRINTER_NOTIFY_DATATYPE", POINTER, spoolss_notify_datatype },
1211 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_SECURITY_DESCRIPTOR", POINTER, spoolss_notify_security_desc },
1212 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_ATTRIBUTES, "PRINTER_NOTIFY_ATTRIBUTES", ONE_VALUE, spoolss_notify_attributes },
1213 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRIORITY, "PRINTER_NOTIFY_PRIORITY", ONE_VALUE, spoolss_notify_priority },
1214 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DEFAULT_PRIORITY, "PRINTER_NOTIFY_DEFAULT_PRIORITY", ONE_VALUE, spoolss_notify_default_priority },
1215 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_START_TIME, "PRINTER_NOTIFY_START_TIME", ONE_VALUE, spoolss_notify_start_time },
1216 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_UNTIL_TIME, "PRINTER_NOTIFY_UNTIL_TIME", ONE_VALUE, spoolss_notify_until_time },
1217 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_STATUS, "PRINTER_NOTIFY_STATUS", ONE_VALUE, spoolss_notify_status },
1218 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_STATUS_STRING, "PRINTER_NOTIFY_STATUS_STRING", POINTER, NULL },
1219 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_CJOBS, "PRINTER_NOTIFY_CJOBS", ONE_VALUE, spoolss_notify_cjobs },
1220 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_AVERAGE_PPM, "PRINTER_NOTIFY_AVERAGE_PPM", ONE_VALUE, spoolss_notify_average_ppm },
1221 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_PAGES, "PRINTER_NOTIFY_TOTAL_PAGES", POINTER, NULL },
1222 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PAGES_PRINTED, "PRINTER_NOTIFY_PAGES_PRINTED", POINTER, NULL },
1223 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_BYTES, "PRINTER_NOTIFY_TOTAL_BYTES", POINTER, NULL },
1224 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_BYTES_PRINTED, "PRINTER_NOTIFY_BYTES_PRINTED", POINTER, NULL },
1225 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINTER_NAME, "JOB_NOTIFY_PRINTER_NAME", POINTER, spoolss_notify_printer_name },
1226 { JOB_NOTIFY_TYPE, JOB_NOTIFY_MACHINE_NAME, "JOB_NOTIFY_MACHINE_NAME", POINTER, spoolss_notify_server_name },
1227 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PORT_NAME, "JOB_NOTIFY_PORT_NAME", POINTER, spoolss_notify_port_name },
1228 { JOB_NOTIFY_TYPE, JOB_NOTIFY_USER_NAME, "JOB_NOTIFY_USER_NAME", POINTER, spoolss_notify_username },
1229 { JOB_NOTIFY_TYPE, JOB_NOTIFY_NOTIFY_NAME, "JOB_NOTIFY_NOTIFY_NAME", POINTER, spoolss_notify_username },
1230 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DATATYPE, "JOB_NOTIFY_DATATYPE", POINTER, spoolss_notify_datatype },
1231 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINT_PROCESSOR, "JOB_NOTIFY_PRINT_PROCESSOR", POINTER, spoolss_notify_print_processor },
1232 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PARAMETERS, "JOB_NOTIFY_PARAMETERS", POINTER, spoolss_notify_parameters },
1233 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DRIVER_NAME, "JOB_NOTIFY_DRIVER_NAME", POINTER, spoolss_notify_driver_name },
1234 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DEVMODE, "JOB_NOTIFY_DEVMODE", POINTER, spoolss_notify_devmode },
1235 { JOB_NOTIFY_TYPE, JOB_NOTIFY_STATUS, "JOB_NOTIFY_STATUS", ONE_VALUE, spoolss_notify_job_status },
1236 { JOB_NOTIFY_TYPE, JOB_NOTIFY_STATUS_STRING, "JOB_NOTIFY_STATUS_STRING", POINTER, spoolss_notify_job_status_string },
1237 { JOB_NOTIFY_TYPE, JOB_NOTIFY_SECURITY_DESCRIPTOR, "JOB_NOTIFY_SECURITY_DESCRIPTOR", POINTER, NULL },
1238 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DOCUMENT, "JOB_NOTIFY_DOCUMENT", POINTER, spoolss_notify_job_name },
1239 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRIORITY, "JOB_NOTIFY_PRIORITY", ONE_VALUE, spoolss_notify_priority },
1240 { JOB_NOTIFY_TYPE, JOB_NOTIFY_POSITION, "JOB_NOTIFY_POSITION", ONE_VALUE, spoolss_notify_job_position },
1241 { JOB_NOTIFY_TYPE, JOB_NOTIFY_SUBMITTED, "JOB_NOTIFY_SUBMITTED", POINTER, NULL },
1242 { JOB_NOTIFY_TYPE, JOB_NOTIFY_START_TIME, "JOB_NOTIFY_START_TIME", ONE_VALUE, spoolss_notify_start_time },
1243 { JOB_NOTIFY_TYPE, JOB_NOTIFY_UNTIL_TIME, "JOB_NOTIFY_UNTIL_TIME", ONE_VALUE, spoolss_notify_until_time },
1244 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TIME, "JOB_NOTIFY_TIME", ONE_VALUE, spoolss_notify_job_time },
1245 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_PAGES, "JOB_NOTIFY_TOTAL_PAGES", ONE_VALUE, NULL },
1246 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PAGES_PRINTED, "JOB_NOTIFY_PAGES_PRINTED", ONE_VALUE, NULL },
1247 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_BYTES, "JOB_NOTIFY_TOTAL_BYTES", ONE_VALUE, spoolss_notify_job_size },
1248 { JOB_NOTIFY_TYPE, JOB_NOTIFY_BYTES_PRINTED, "JOB_NOTIFY_BYTES_PRINTED", ONE_VALUE, NULL },
1249 { END, END, "", END, NULL }
1252 /*******************************************************************
1253 return the size of info_data structure
1254 ********************************************************************/
1255 static uint32 size_of_notify_info_data(uint16 type, uint16 field)
1259 while (notify_info_data_table[i].type != END)
1261 if ( (notify_info_data_table[i].type == type ) &&
1262 (notify_info_data_table[i].field == field ) )
1264 return (notify_info_data_table[i].size);
1272 /*******************************************************************
1273 return the type of notify_info_data
1274 ********************************************************************/
1275 static BOOL type_of_notify_info_data(uint16 type, uint16 field)
1279 while (notify_info_data_table[i].type != END)
1281 if ( (notify_info_data_table[i].type == type ) &&
1282 (notify_info_data_table[i].field == field ) )
1284 if (notify_info_data_table[i].size == POINTER)
1299 /****************************************************************************
1300 ****************************************************************************/
1301 static int search_notify(uint16 type, uint16 field, int *value)
1306 for (j=0, found=False; found==False && notify_info_data_table[j].type != END ; j++)
1308 if ( (notify_info_data_table[j].type == type ) &&
1309 (notify_info_data_table[j].field == field ) )
1314 if ( found && (notify_info_data_table[j].fn != NULL) )
1320 /****************************************************************************
1321 ****************************************************************************/
1322 static void construct_info_data(SPOOL_NOTIFY_INFO_DATA *info_data, uint16 type, uint16 field, int id)
1324 info_data->type = type;
1325 info_data->field = field;
1326 info_data->reserved = 0;
1328 info_data->size = size_of_notify_info_data(type, field);
1329 info_data->enc_type = type_of_notify_info_data(type, field);
1333 /*******************************************************************
1335 * fill a notify_info struct with info asked
1337 ********************************************************************/
1338 static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPOOL_NOTIFY_OPTION_TYPE *option_type, uint32 id)
1344 SPOOL_NOTIFY_INFO_DATA *current_data;
1345 NT_PRINTER_INFO_LEVEL *printer = NULL;
1346 print_queue_struct *queue=NULL;
1348 DEBUG(4,("construct_notify_printer_info\n"));
1350 type=option_type->type;
1352 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
1353 (option_type->type==PRINTER_NOTIFY_TYPE?"PRINTER_NOTIFY_TYPE":"JOB_NOTIFY_TYPE"),
1354 option_type->count, lp_servicename(snum)));
1356 if (get_a_printer(&printer, 2, lp_servicename(snum))!=0)
1359 for(field_num=0; field_num<option_type->count; field_num++) {
1360 field = option_type->fields[field_num];
1361 DEBUGADD(4,("notify [%d]: type [%x], field [%x]\n", field_num, type, field));
1363 if (!search_notify(type, field, &j) )
1366 if((info->data=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) {
1369 current_data=&info->data[info->count];
1371 construct_info_data(current_data, type, field, id);
1372 notify_info_data_table[j].fn(snum, current_data, queue, printer);
1377 free_a_printer(&printer, 2);
1381 /*******************************************************************
1383 * fill a notify_info struct with info asked
1385 ********************************************************************/
1386 static BOOL construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_INFO *info, int snum, SPOOL_NOTIFY_OPTION_TYPE *option_type, uint32 id)
1392 SPOOL_NOTIFY_INFO_DATA *current_data;
1393 NT_PRINTER_INFO_LEVEL *printer = NULL;
1395 DEBUG(4,("construct_notify_jobs_info\n"));
1397 type = option_type->type;
1399 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
1400 (option_type->type==PRINTER_NOTIFY_TYPE?"PRINTER_NOTIFY_TYPE":"JOB_NOTIFY_TYPE"),
1401 option_type->count));
1403 if (get_a_printer(&printer, 2, lp_servicename(snum))!=0)
1406 for(field_num=0; field_num<option_type->count; field_num++) {
1407 field = option_type->fields[field_num];
1409 if (!search_notify(type, field, &j) )
1412 if((info->data=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) {
1416 current_data=&(info->data[info->count]);
1418 construct_info_data(current_data, type, field, id);
1419 notify_info_data_table[j].fn(snum, current_data, queue, printer);
1423 free_a_printer(&printer, 2);
1428 * JFM: The enumeration is not that simple, it's even non obvious.
1430 * let's take an example: I want to monitor the PRINTER SERVER for
1431 * the printer's name and the number of jobs currently queued.
1432 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
1433 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
1435 * I have 3 printers on the back of my server.
1437 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
1440 * 1 printer 1 name 1
1441 * 2 printer 1 cjob 1
1442 * 3 printer 2 name 2
1443 * 4 printer 2 cjob 2
1444 * 5 printer 3 name 3
1445 * 6 printer 3 name 3
1447 * that's the print server case, the printer case is even worse.
1452 /*******************************************************************
1454 * enumerate all printers on the printserver
1455 * fill a notify_info struct with info asked
1457 ********************************************************************/
1458 static uint32 printserver_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info)
1461 Printer_entry *Printer=find_printer_index_by_hnd(hnd);
1462 int n_services=lp_numservices();
1465 SPOOL_NOTIFY_OPTION *option;
1466 SPOOL_NOTIFY_OPTION_TYPE *option_type;
1468 DEBUG(4,("printserver_notify_info\n"));
1470 option=Printer->notify.option;
1476 for (i=0; i<option->count; i++) {
1477 option_type=&(option->ctr.type[i]);
1479 if (option_type->type!=PRINTER_NOTIFY_TYPE)
1482 for (snum=0; snum<n_services; snum++)
1483 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
1484 if (construct_notify_printer_info(info, snum, option_type, id))
1489 * Debugging information, don't delete.
1492 DEBUG(1,("dumping the NOTIFY_INFO\n"));
1493 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
1494 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
1496 for (i=0; i<info->count; i++) {
1497 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
1498 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
1499 info->data[i].id, info->data[i].size, info->data[i].enc_type));
1503 return NT_STATUS_NO_PROBLEMO;
1506 /*******************************************************************
1508 * fill a notify_info struct with info asked
1510 ********************************************************************/
1511 static uint32 printer_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info)
1514 Printer_entry *Printer=find_printer_index_by_hnd(hnd);
1517 SPOOL_NOTIFY_OPTION *option;
1518 SPOOL_NOTIFY_OPTION_TYPE *option_type;
1520 print_queue_struct *queue=NULL;
1521 print_status_struct status;
1523 DEBUG(4,("printer_notify_info\n"));
1525 option=Printer->notify.option;
1531 get_printer_snum(hnd, &snum);
1533 for (i=0; i<option->count; i++) {
1534 option_type=&option->ctr.type[i];
1536 switch ( option_type->type ) {
1537 case PRINTER_NOTIFY_TYPE:
1538 if(construct_notify_printer_info(info, snum, option_type, id))
1542 case JOB_NOTIFY_TYPE:
1543 memset(&status, 0, sizeof(status));
1544 count = print_queue_status(snum, &queue, &status);
1545 for (j=0; j<count; j++)
1546 construct_notify_jobs_info(&queue[j], info, snum, option_type, queue[j].job);
1553 * Debugging information, don't delete.
1556 DEBUG(1,("dumping the NOTIFY_INFO\n"));
1557 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
1558 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
1560 for (i=0; i<info->count; i++) {
1561 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
1562 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
1563 info->data[i].id, info->data[i].size, info->data[i].enc_type));
1566 return NT_STATUS_NO_PROBLEMO;
1569 /********************************************************************
1571 ********************************************************************/
1572 uint32 _spoolss_rfnpcnex( const POLICY_HND *handle, uint32 change,
1573 SPOOL_NOTIFY_OPTION *option, SPOOL_NOTIFY_INFO *info)
1575 Printer_entry *Printer=find_printer_index_by_hnd(handle);
1577 if (!OPEN_HANDLE(Printer))
1578 return ERROR_INVALID_HANDLE;
1580 DEBUG(4,("Printer type %x\n",Printer->printer_type));
1582 /* jfm: the change value isn't used right now.
1583 * we will honour it when
1584 * a) we'll be able to send notification to the client
1585 * b) we'll have a way to communicate between the spoolss process.
1587 * same thing for option->flags
1588 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
1589 * I don't have a global notification system, I'm sending back all the
1590 * informations even when _NOTHING_ has changed.
1593 /* just discard the SPOOL_NOTIFY_OPTION */
1595 safe_free(option->ctr.type);
1597 switch (Printer->printer_type) {
1598 case PRINTER_HANDLE_IS_PRINTSERVER:
1599 return printserver_notify_info(handle, info);
1601 case PRINTER_HANDLE_IS_PRINTER:
1602 return printer_notify_info(handle, info);
1606 return ERROR_INVALID_HANDLE;
1609 /********************************************************************
1610 * construct_printer_info_0
1611 * fill a printer_info_1 struct
1612 ********************************************************************/
1613 static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, fstring servername)
1617 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
1618 counter_printer_0 *session_counter;
1619 uint32 global_counter;
1621 time_t setup_time = time(NULL);
1623 print_queue_struct *queue=NULL;
1624 print_status_struct status;
1626 memset(&status, 0, sizeof(status));
1628 if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) != 0)
1631 count = print_queue_status(snum, &queue, &status);
1633 /* check if we already have a counter for this printer */
1634 session_counter = (counter_printer_0 *)ubi_dlFirst(&counter_list);
1636 for(; session_counter; session_counter = (counter_printer_0 *)ubi_dlNext(session_counter)) {
1637 if (session_counter->snum == snum)
1641 /* it's the first time, add it to the list */
1642 if (session_counter==NULL) {
1643 if((session_counter=(counter_printer_0 *)malloc(sizeof(counter_printer_0))) == NULL) {
1644 free_a_printer(&ntprinter, 2);
1647 ZERO_STRUCTP(session_counter);
1648 session_counter->snum=snum;
1649 session_counter->counter=0;
1650 ubi_dlAddHead( &counter_list, (ubi_dlNode *)session_counter);
1654 session_counter->counter++;
1657 * the global_counter should be stored in a TDB as it's common to all the clients
1658 * and should be zeroed on samba startup
1660 global_counter=session_counter->counter;
1662 /* the description and the name are of the form \\server\share */
1663 slprintf(chaine,sizeof(chaine)-1,"\\\\%s\\%s",servername, ntprinter->info_2->printername);
1665 init_unistr(&printer->printername, chaine);
1667 slprintf(chaine,sizeof(chaine)-1,"\\\\%s", servername);
1668 init_unistr(&printer->servername, chaine);
1670 printer->cjobs = count;
1671 printer->total_jobs = 0;
1672 printer->total_bytes = 0;
1674 t=gmtime(&setup_time);
1675 ntprinter->info_2->setuptime = (uint32)setup_time; /* FIXME !! */
1677 printer->year = t->tm_year+1900;
1678 printer->month = t->tm_mon+1;
1679 printer->dayofweek = t->tm_wday;
1680 printer->day = t->tm_mday;
1681 printer->hour = t->tm_hour;
1682 printer->minute = t->tm_min;
1683 printer->second = t->tm_sec;
1684 printer->milliseconds = 0;
1686 printer->global_counter = global_counter;
1687 printer->total_pages = 0;
1688 printer->major_version = 0x0004; /* NT 4 */
1689 printer->build_version = 0x0565; /* build 1381 */
1690 printer->unknown7 = 0x1;
1691 printer->unknown8 = 0x0;
1692 printer->unknown9 = 0x0;
1693 printer->session_counter = session_counter->counter;
1694 printer->unknown11 = 0x0;
1695 printer->printer_errors = 0x0; /* number of print failure */
1696 printer->unknown13 = 0x0;
1697 printer->unknown14 = 0x1;
1698 printer->unknown15 = 0x024a; /* 586 Pentium ? */
1699 printer->unknown16 = 0x0;
1700 printer->change_id = ntprinter->info_2->changeid; /* ChangeID in milliseconds*/
1701 printer->unknown18 = 0x0;
1702 printer->status = nt_printq_status(status.status);
1703 printer->unknown20 = 0x0;
1704 printer->c_setprinter = ntprinter->info_2->c_setprinter; /* how many times setprinter has been called */
1705 printer->unknown22 = 0x0;
1706 printer->unknown23 = 0x6; /* 6 ???*/
1707 printer->unknown24 = 0; /* unknown 24 to 26 are always 0 */
1708 printer->unknown25 = 0;
1709 printer->unknown26 = 0;
1710 printer->unknown27 = 0;
1711 printer->unknown28 = 0;
1712 printer->unknown29 = 0;
1715 free_a_printer(&ntprinter,2);
1719 /********************************************************************
1720 * construct_printer_info_1
1721 * fill a printer_info_1 struct
1722 ********************************************************************/
1723 static BOOL construct_printer_info_1(fstring server, uint32 flags, PRINTER_INFO_1 *printer, int snum)
1727 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
1729 if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) != 0)
1732 printer->flags=flags;
1734 snprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",server, ntprinter->info_2->printername,
1735 ntprinter->info_2->drivername, lp_comment(snum));
1737 snprintf(chaine2,sizeof(chaine)-1,"%s%s", server, ntprinter->info_2->printername);
1739 init_unistr(&printer->description, chaine);
1740 init_unistr(&printer->name, chaine2);
1741 init_unistr(&printer->comment, lp_comment(snum));
1743 free_a_printer(&ntprinter,2);
1748 /****************************************************************************
1749 Free a DEVMODE struct.
1750 ****************************************************************************/
1752 static void free_dev_mode(DEVICEMODE *dev)
1758 safe_free(dev->private);
1763 /****************************************************************************
1764 Create a DEVMODE struct. Returns malloced memory.
1765 ****************************************************************************/
1767 static DEVICEMODE *construct_dev_mode(int snum, char *servername)
1771 NT_PRINTER_INFO_LEVEL *printer = NULL;
1772 NT_DEVICEMODE *ntdevmode = NULL;
1773 DEVICEMODE *devmode = NULL;
1775 DEBUG(7,("construct_dev_mode\n"));
1777 DEBUGADD(8,("getting printer characteristics\n"));
1779 if ((devmode = (DEVICEMODE *)malloc(sizeof(DEVICEMODE))) == NULL) {
1780 DEBUG(0,("construct_dev_mode: malloc fail.\n"));
1784 ZERO_STRUCTP(devmode);
1786 if(get_a_printer(&printer, 2, lp_servicename(snum)) != 0)
1789 if (printer->info_2->devmode)
1790 ntdevmode = dup_nt_devicemode(printer->info_2->devmode);
1792 ntdevmode = construct_nt_devicemode(printer->info_2->printername);
1794 if (ntdevmode == NULL)
1797 DEBUGADD(8,("loading DEVICEMODE\n"));
1800 snprintf(adevice, sizeof(adevice), "\\\\%s\\%s", global_myname, ntdevmode->devicename);
1802 snprintf(adevice, sizeof(adevice), "\\\\%s\\%s", global_myname, printer->info_2->printername);
1803 #endif /* JRATEST */
1804 init_unistr(&devmode->devicename, adevice);
1806 snprintf(aform, sizeof(aform), ntdevmode->formname);
1807 init_unistr(&devmode->formname, aform);
1809 devmode->specversion = ntdevmode->specversion;
1810 devmode->driverversion = ntdevmode->driverversion;
1811 devmode->size = ntdevmode->size;
1812 devmode->driverextra = ntdevmode->driverextra;
1813 devmode->fields = ntdevmode->fields;
1815 devmode->orientation = ntdevmode->orientation;
1816 devmode->papersize = ntdevmode->papersize;
1817 devmode->paperlength = ntdevmode->paperlength;
1818 devmode->paperwidth = ntdevmode->paperwidth;
1819 devmode->scale = ntdevmode->scale;
1820 devmode->copies = ntdevmode->copies;
1821 devmode->defaultsource = ntdevmode->defaultsource;
1822 devmode->printquality = ntdevmode->printquality;
1823 devmode->color = ntdevmode->color;
1824 devmode->duplex = ntdevmode->duplex;
1825 devmode->yresolution = ntdevmode->yresolution;
1826 devmode->ttoption = ntdevmode->ttoption;
1827 devmode->collate = ntdevmode->collate;
1828 devmode->icmmethod = ntdevmode->icmmethod;
1829 devmode->icmintent = ntdevmode->icmintent;
1830 devmode->mediatype = ntdevmode->mediatype;
1831 devmode->dithertype = ntdevmode->dithertype;
1833 if (ntdevmode->private != NULL) {
1834 if ((devmode->private=(uint8 *)memdup(ntdevmode->private, ntdevmode->driverextra)) == NULL)
1838 free_nt_devicemode(&ntdevmode);
1839 free_a_printer(&printer,2);
1846 free_nt_devicemode(&ntdevmode);
1848 free_a_printer(&printer,2);
1849 free_dev_mode(devmode);
1854 /********************************************************************
1855 * construct_printer_info_2
1856 * fill a printer_info_2 struct
1857 ********************************************************************/
1859 static BOOL construct_printer_info_2(fstring servername, PRINTER_INFO_2 *printer, int snum)
1865 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
1867 print_queue_struct *queue=NULL;
1868 print_status_struct status;
1869 memset(&status, 0, sizeof(status));
1871 if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0 )
1874 memset(&status, 0, sizeof(status));
1875 count = print_queue_status(snum, &queue, &status);
1877 snprintf(chaine, sizeof(chaine)-1, "%s", servername);
1879 if (strlen(servername)!=0)
1884 snprintf(chaine2, sizeof(chaine)-1, "%s%s%s", servername, sl, ntprinter->info_2->printername);
1886 init_unistr(&printer->servername, chaine); /* servername*/
1887 init_unistr(&printer->printername, chaine2); /* printername*/
1888 init_unistr(&printer->sharename, lp_servicename(snum)); /* sharename */
1889 init_unistr(&printer->portname, lp_servicename(snum)); /* port */
1890 init_unistr(&printer->drivername, ntprinter->info_2->drivername); /* drivername */
1891 init_unistr(&printer->comment, lp_comment(snum)); /* comment */
1892 init_unistr(&printer->location, ntprinter->info_2->location); /* location */
1893 init_unistr(&printer->sepfile, ntprinter->info_2->sepfile); /* separator file */
1894 init_unistr(&printer->printprocessor, ntprinter->info_2->printprocessor);/* print processor */
1895 init_unistr(&printer->datatype, ntprinter->info_2->datatype); /* datatype */
1896 init_unistr(&printer->parameters, ntprinter->info_2->parameters); /* parameters (of print processor) */
1898 printer->attributes = ntprinter->info_2->attributes;
1900 printer->priority = ntprinter->info_2->priority; /* priority */
1901 printer->defaultpriority = ntprinter->info_2->default_priority; /* default priority */
1902 printer->starttime = ntprinter->info_2->starttime; /* starttime */
1903 printer->untiltime = ntprinter->info_2->untiltime; /* untiltime */
1904 printer->status = nt_printq_status(status.status); /* status */
1905 printer->cjobs = count; /* jobs */
1906 printer->averageppm = ntprinter->info_2->averageppm; /* average pages per minute */
1908 if((printer->devmode = construct_dev_mode(snum, servername)) == NULL)
1911 if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->len != 0) {
1912 /* steal the printer info sec_desc structure. [badly done]. */
1913 printer->secdesc = ntprinter->info_2->secdesc_buf->sec;
1914 ntprinter->info_2->secdesc_buf->sec = NULL; /* Stolen memory. */
1915 ntprinter->info_2->secdesc_buf->len = 0; /* Stolen memory. */
1916 ntprinter->info_2->secdesc_buf->max_len = 0; /* Stolen memory. */
1919 printer->secdesc = NULL;
1922 free_a_printer(&ntprinter, 2);
1929 free_a_printer(&ntprinter, 2);
1934 /********************************************************************
1935 * construct_printer_info_3
1936 * fill a printer_info_3 struct
1937 ********************************************************************/
1938 static BOOL construct_printer_info_3(fstring servername,
1939 PRINTER_INFO_3 **pp_printer, int snum)
1941 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
1942 PRINTER_INFO_3 *printer = NULL;
1944 if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0 )
1948 if ((printer = (PRINTER_INFO_3 *)malloc(sizeof(PRINTER_INFO_3))) == NULL) {
1949 DEBUG(0,("construct_printer_info_3: malloc fail.\n"));
1953 ZERO_STRUCTP(printer);
1955 printer->flags = 4; /* This is the offset to the SEC_DESC. */
1956 if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->len != 0) {
1957 /* steal the printer info sec_desc structure. [badly done]. */
1958 printer->secdesc = ntprinter->info_2->secdesc_buf->sec;
1959 ntprinter->info_2->secdesc_buf->sec = NULL; /* Stolen the malloced memory. */
1960 ntprinter->info_2->secdesc_buf->len = 0; /* Stolen the malloced memory. */
1961 ntprinter->info_2->secdesc_buf->max_len = 0; /* Stolen the malloced memory. */
1964 free_a_printer(&ntprinter, 2);
1966 *pp_printer = printer;
1970 /********************************************************************
1971 Spoolss_enumprinters.
1972 ********************************************************************/
1973 static BOOL enum_all_printers_info_1(fstring server, uint32 flags, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
1977 int n_services=lp_numservices();
1978 PRINTER_INFO_1 *printers=NULL;
1979 PRINTER_INFO_1 current_prt;
1981 DEBUG(4,("enum_all_printers_info_1\n"));
1983 for (snum=0; snum<n_services; snum++) {
1984 if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
1985 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum));
1987 if (construct_printer_info_1(server, flags, ¤t_prt, snum)) {
1988 if((printers=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_1))) == NULL) {
1990 return ERROR_NOT_ENOUGH_MEMORY;
1992 DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_1\n", *returned));
1993 memcpy(&(printers[*returned]), ¤t_prt, sizeof(PRINTER_INFO_1));
1999 /* check the required size. */
2000 for (i=0; i<*returned; i++)
2001 (*needed) += spoolss_size_printer_info_1(&(printers[i]));
2003 if (!alloc_buffer_size(buffer, *needed))
2004 return ERROR_INSUFFICIENT_BUFFER;
2006 /* fill the buffer with the structures */
2007 for (i=0; i<*returned; i++)
2008 new_smb_io_printer_info_1("", buffer, &(printers[i]), 0);
2011 safe_free(printers);
2013 if (*needed > offered) {
2015 return ERROR_INSUFFICIENT_BUFFER;
2018 return NT_STATUS_NO_PROBLEMO;
2021 /********************************************************************
2022 enum_all_printers_info_1_local.
2023 *********************************************************************/
2024 static BOOL enum_all_printers_info_1_local(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
2027 DEBUG(4,("enum_all_printers_info_1_local\n"));
2029 fstrcpy(temp, "\\\\");
2030 fstrcat(temp, global_myname);
2032 if (!strcmp(name, temp)) {
2033 fstrcat(temp, "\\");
2034 return enum_all_printers_info_1(temp, PRINTER_ENUM_ICON8, buffer, offered, needed, returned);
2037 return enum_all_printers_info_1("", PRINTER_ENUM_ICON8, buffer, offered, needed, returned);
2040 /********************************************************************
2041 enum_all_printers_info_1_name.
2042 *********************************************************************/
2043 static BOOL enum_all_printers_info_1_name(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
2046 DEBUG(4,("enum_all_printers_info_1_name\n"));
2048 fstrcpy(temp, "\\\\");
2049 fstrcat(temp, global_myname);
2051 if (!strcmp(name, temp)) {
2052 fstrcat(temp, "\\");
2053 return enum_all_printers_info_1(temp, PRINTER_ENUM_ICON8, buffer, offered, needed, returned);
2056 return ERROR_INVALID_NAME;
2059 /********************************************************************
2060 enum_all_printers_info_1_remote.
2061 *********************************************************************/
2062 static BOOL enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
2064 PRINTER_INFO_1 *printer;
2065 fstring printername;
2068 DEBUG(4,("enum_all_printers_info_1_remote\n"));
2070 /* JFM: currently it's more a place holder than anything else.
2071 * In the spooler world there is a notion of server registration.
2072 * the print servers are registring (sp ?) on the PDC (in the same domain)
2074 * We should have a TDB here. The registration is done thru an undocumented RPC call.
2077 if((printer=(PRINTER_INFO_1 *)malloc(sizeof(PRINTER_INFO_1))) == NULL)
2078 return ERROR_NOT_ENOUGH_MEMORY;
2082 snprintf(printername, sizeof(printername)-1,"Windows NT Remote Printers!!\\\\%s", global_myname);
2083 snprintf(desc, sizeof(desc)-1,"%s", global_myname);
2084 snprintf(comment, sizeof(comment)-1, "Logged on Domain");
2086 init_unistr(&printer->description, desc);
2087 init_unistr(&printer->name, printername);
2088 init_unistr(&printer->comment, comment);
2089 printer->flags=PRINTER_ENUM_ICON3|PRINTER_ENUM_CONTAINER;
2091 /* check the required size. */
2092 *needed += spoolss_size_printer_info_1(printer);
2094 if (!alloc_buffer_size(buffer, *needed)) {
2096 return ERROR_INSUFFICIENT_BUFFER;
2099 /* fill the buffer with the structures */
2100 new_smb_io_printer_info_1("", buffer, printer, 0);
2105 if (*needed > offered) {
2107 return ERROR_INSUFFICIENT_BUFFER;
2110 return NT_STATUS_NO_PROBLEMO;
2113 /********************************************************************
2114 enum_all_printers_info_1_network.
2115 *********************************************************************/
2116 static BOOL enum_all_printers_info_1_network(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
2119 DEBUG(4,("enum_all_printers_info_1_network\n"));
2121 fstrcpy(temp, "\\\\");
2122 fstrcat(temp, global_myname);
2123 fstrcat(temp, "\\");
2124 return enum_all_printers_info_1(temp, PRINTER_ENUM_UNKNOWN_8, buffer, offered, needed, returned);
2127 /********************************************************************
2128 * api_spoolss_enumprinters
2130 * called from api_spoolss_enumprinters (see this to understand)
2131 ********************************************************************/
2132 static BOOL enum_all_printers_info_2(fstring servername, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
2136 int n_services=lp_numservices();
2137 PRINTER_INFO_2 *printers=NULL;
2138 PRINTER_INFO_2 current_prt;
2140 for (snum=0; snum<n_services; snum++) {
2141 if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
2142 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum));
2144 if (construct_printer_info_2(servername, ¤t_prt, snum)) {
2145 if((printers=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_2))) == NULL)
2146 return ERROR_NOT_ENOUGH_MEMORY;
2147 DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_2\n", *returned));
2148 memcpy(&printers[*returned], ¤t_prt, sizeof(PRINTER_INFO_2));
2154 /* check the required size. */
2155 for (i=0; i<*returned; i++)
2156 (*needed) += spoolss_size_printer_info_2(&printers[i]);
2158 if (!alloc_buffer_size(buffer, *needed)) {
2159 for (i=0; i<*returned; i++) {
2160 free_devmode(printers[i].devmode);
2161 free_sec_desc(&printers[i].secdesc);
2163 safe_free(printers);
2164 return ERROR_INSUFFICIENT_BUFFER;
2167 /* fill the buffer with the structures */
2168 for (i=0; i<*returned; i++)
2169 new_smb_io_printer_info_2("", buffer, &(printers[i]), 0);
2172 for (i=0; i<*returned; i++) {
2173 free_devmode(printers[i].devmode);
2174 free_sec_desc(&printers[i].secdesc);
2176 safe_free(printers);
2178 if (*needed > offered) {
2180 return ERROR_INSUFFICIENT_BUFFER;
2183 return NT_STATUS_NO_PROBLEMO;
2186 /********************************************************************
2187 * handle enumeration of printers at level 1
2188 ********************************************************************/
2189 static uint32 enumprinters_level1( uint32 flags, fstring name,
2190 NEW_BUFFER *buffer, uint32 offered,
2191 uint32 *needed, uint32 *returned)
2193 /* Not all the flags are equals */
2195 if (flags & PRINTER_ENUM_LOCAL)
2196 return enum_all_printers_info_1_local(name, buffer, offered, needed, returned);
2198 if (flags & PRINTER_ENUM_NAME)
2199 return enum_all_printers_info_1_name(name, buffer, offered, needed, returned);
2201 if (flags & PRINTER_ENUM_REMOTE)
2202 return enum_all_printers_info_1_remote(name, buffer, offered, needed, returned);
2204 if (flags & PRINTER_ENUM_NETWORK)
2205 return enum_all_printers_info_1_network(name, buffer, offered, needed, returned);
2207 return NT_STATUS_NO_PROBLEMO; /* NT4sp5 does that */
2210 /********************************************************************
2211 * handle enumeration of printers at level 2
2212 ********************************************************************/
2213 static uint32 enumprinters_level2( uint32 flags, fstring servername,
2214 NEW_BUFFER *buffer, uint32 offered,
2215 uint32 *needed, uint32 *returned)
2219 fstrcpy(temp, "\\\\");
2220 fstrcat(temp, global_myname);
2222 if (flags & PRINTER_ENUM_LOCAL) {
2223 if (!strcmp(servername, temp))
2224 return enum_all_printers_info_2(temp, buffer, offered, needed, returned);
2226 return enum_all_printers_info_2("", buffer, offered, needed, returned);
2229 if (flags & PRINTER_ENUM_NAME) {
2230 if (!strcmp(servername, temp))
2231 return enum_all_printers_info_2(temp, buffer, offered, needed, returned);
2233 return ERROR_INVALID_NAME;
2236 if (flags & PRINTER_ENUM_REMOTE)
2237 return ERROR_INVALID_LEVEL;
2239 return NT_STATUS_NO_PROBLEMO;
2242 /********************************************************************
2243 * handle enumeration of printers at level 5
2244 ********************************************************************/
2245 static uint32 enumprinters_level5( uint32 flags, fstring servername,
2246 NEW_BUFFER *buffer, uint32 offered,
2247 uint32 *needed, uint32 *returned)
2249 /* return enum_all_printers_info_5(buffer, offered, needed, returned);*/
2250 return NT_STATUS_NO_PROBLEMO;
2253 /********************************************************************
2254 * api_spoolss_enumprinters
2256 * called from api_spoolss_enumprinters (see this to understand)
2257 ********************************************************************/
2258 uint32 _spoolss_enumprinters( uint32 flags, const UNISTR2 *servername, uint32 level,
2259 NEW_BUFFER *buffer, uint32 offered,
2260 uint32 *needed, uint32 *returned)
2264 DEBUG(4,("_spoolss_enumprinters\n"));
2271 * flags==PRINTER_ENUM_NAME
2272 * if name=="" then enumerates all printers
2273 * if name!="" then enumerate the printer
2274 * flags==PRINTER_ENUM_REMOTE
2275 * name is NULL, enumerate printers
2276 * Level 2: name!="" enumerates printers, name can't be NULL
2277 * Level 3: doesn't exist
2278 * Level 4: does a local registry lookup
2279 * Level 5: same as Level 2
2282 unistr2_to_ascii(name, servername, sizeof(name)-1);
2287 return enumprinters_level1(flags, name, buffer, offered, needed, returned);
2290 return enumprinters_level2(flags, name, buffer, offered, needed, returned);
2293 return enumprinters_level5(flags, name, buffer, offered, needed, returned);
2298 return ERROR_INVALID_LEVEL;
2303 /****************************************************************************
2304 ****************************************************************************/
2305 static uint32 getprinter_level_0(fstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2307 PRINTER_INFO_0 *printer=NULL;
2309 if((printer=(PRINTER_INFO_0*)malloc(sizeof(PRINTER_INFO_0))) == NULL)
2310 return ERROR_NOT_ENOUGH_MEMORY;
2312 construct_printer_info_0(printer, snum, servername);
2314 /* check the required size. */
2315 *needed += spoolss_size_printer_info_0(printer);
2317 if (!alloc_buffer_size(buffer, *needed)) {
2319 return ERROR_INSUFFICIENT_BUFFER;
2322 /* fill the buffer with the structures */
2323 new_smb_io_printer_info_0("", buffer, printer, 0);
2328 if (*needed > offered) {
2329 return ERROR_INSUFFICIENT_BUFFER;
2332 return NT_STATUS_NO_PROBLEMO;
2335 /****************************************************************************
2336 ****************************************************************************/
2337 static uint32 getprinter_level_1(fstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2339 PRINTER_INFO_1 *printer=NULL;
2341 if((printer=(PRINTER_INFO_1*)malloc(sizeof(PRINTER_INFO_1))) == NULL)
2342 return ERROR_NOT_ENOUGH_MEMORY;
2344 construct_printer_info_1(servername, PRINTER_ENUM_ICON8, printer, snum);
2346 /* check the required size. */
2347 *needed += spoolss_size_printer_info_1(printer);
2349 if (!alloc_buffer_size(buffer, *needed)) {
2351 return ERROR_INSUFFICIENT_BUFFER;
2354 /* fill the buffer with the structures */
2355 new_smb_io_printer_info_1("", buffer, printer, 0);
2360 if (*needed > offered) {
2361 return ERROR_INSUFFICIENT_BUFFER;
2364 return NT_STATUS_NO_PROBLEMO;
2367 /****************************************************************************
2368 ****************************************************************************/
2369 static uint32 getprinter_level_2(fstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2371 PRINTER_INFO_2 *printer=NULL;
2374 if((printer=(PRINTER_INFO_2*)malloc(sizeof(PRINTER_INFO_2)))==NULL)
2375 return ERROR_NOT_ENOUGH_MEMORY;
2377 fstrcpy(temp, "\\\\");
2378 fstrcat(temp, servername);
2379 construct_printer_info_2(temp, printer, snum);
2381 /* check the required size. */
2382 *needed += spoolss_size_printer_info_2(printer);
2384 if (!alloc_buffer_size(buffer, *needed)) {
2385 free_printer_info_2(printer);
2386 return ERROR_INSUFFICIENT_BUFFER;
2389 /* fill the buffer with the structures */
2390 if (!new_smb_io_printer_info_2("", buffer, printer, 0)) {
2391 free_printer_info_2(printer);
2392 return ERROR_NOT_ENOUGH_MEMORY;
2396 free_printer_info_2(printer);
2398 if (*needed > offered) {
2399 return ERROR_INSUFFICIENT_BUFFER;
2402 return NT_STATUS_NO_PROBLEMO;
2405 /****************************************************************************
2406 ****************************************************************************/
2407 static uint32 getprinter_level_3(fstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2409 PRINTER_INFO_3 *printer=NULL;
2412 fstrcpy(temp, "\\\\");
2413 fstrcat(temp, servername);
2414 if (!construct_printer_info_3(temp, &printer, snum))
2415 return ERROR_NOT_ENOUGH_MEMORY;
2417 /* check the required size. */
2418 *needed += spoolss_size_printer_info_3(printer);
2420 if (!alloc_buffer_size(buffer, *needed)) {
2421 free_printer_info_3(printer);
2422 return ERROR_INSUFFICIENT_BUFFER;
2425 /* fill the buffer with the structures */
2426 new_smb_io_printer_info_3("", buffer, printer, 0);
2429 free_printer_info_3(printer);
2431 if (*needed > offered) {
2432 return ERROR_INSUFFICIENT_BUFFER;
2435 return NT_STATUS_NO_PROBLEMO;
2438 /****************************************************************************
2439 ****************************************************************************/
2440 uint32 _spoolss_getprinter(POLICY_HND *handle, uint32 level,
2441 NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2448 pstrcpy(servername, global_myname);
2450 if (!get_printer_snum(handle, &snum))
2451 return ERROR_INVALID_HANDLE;
2455 return getprinter_level_0(servername, snum, buffer, offered, needed);
2457 return getprinter_level_1(servername,snum, buffer, offered, needed);
2459 return getprinter_level_2(servername,snum, buffer, offered, needed);
2461 return getprinter_level_3(servername,snum, buffer, offered, needed);
2463 return ERROR_INVALID_LEVEL;
2468 /********************************************************************
2469 * construct_printer_driver_info_1
2470 * fill a construct_printer_driver_info_1 struct
2471 ********************************************************************/
2472 static void fill_printer_driver_info_1(DRIVER_INFO_1 *info,
2473 NT_PRINTER_DRIVER_INFO_LEVEL driver,
2474 fstring servername, fstring architecture)
2476 init_unistr( &(info->name), driver.info_3->name);
2479 static void construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum,
2480 fstring servername, fstring architecture)
2482 NT_PRINTER_INFO_LEVEL *printer = NULL;
2483 NT_PRINTER_DRIVER_INFO_LEVEL driver;
2485 ZERO_STRUCT(driver);
2487 get_a_printer(&printer, 2, lp_servicename(snum) );
2488 get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture);
2490 fill_printer_driver_info_1(info, driver, servername, architecture);
2492 free_a_printer(&printer,2);
2495 /********************************************************************
2496 * construct_printer_driver_info_2
2497 * fill a printer_info_2 struct
2498 ********************************************************************/
2499 static void fill_printer_driver_info_2(DRIVER_INFO_2 *info,
2500 NT_PRINTER_DRIVER_INFO_LEVEL driver,
2501 fstring servername, fstring architecture)
2504 pstring temp_driverpath;
2505 pstring temp_datafile;
2506 pstring temp_configfile;
2507 fstring short_archi;
2509 get_short_archi(short_archi,architecture);
2511 snprintf(where,sizeof(where)-1,"\\\\%s\\print$\\%s\\%s\\", servername, short_archi, driver.info_3->name);
2513 info->version=driver.info_3->cversion;
2515 init_unistr( &(info->name), driver.info_3->name );
2516 init_unistr( &(info->architecture), architecture );
2518 snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "%s%s", where,
2519 driver.info_3->driverpath);
2520 init_unistr( &(info->driverpath), temp_driverpath );
2522 snprintf(temp_datafile, sizeof(temp_datafile)-1, "%s%s", where,
2523 driver.info_3->datafile);
2524 init_unistr( &(info->datafile), temp_datafile );
2526 snprintf(temp_configfile, sizeof(temp_configfile)-1, "%s%s", where,
2527 driver.info_3->configfile);
2528 init_unistr( &(info->configfile), temp_configfile );
2531 /********************************************************************
2532 * construct_printer_driver_info_2
2533 * fill a printer_info_2 struct
2534 ********************************************************************/
2535 static void construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fstring servername, fstring architecture)
2537 NT_PRINTER_INFO_LEVEL *printer = NULL;
2538 NT_PRINTER_DRIVER_INFO_LEVEL driver;
2540 ZERO_STRUCT(printer);
2541 ZERO_STRUCT(driver);
2543 get_a_printer(&printer, 2, lp_servicename(snum) );
2544 get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture);
2546 fill_printer_driver_info_2(info, driver, servername, architecture);
2548 free_a_printer(&printer,2);
2551 /********************************************************************
2552 * copy a strings array and convert to UNICODE
2554 * convert an array of ascii string to a UNICODE string
2555 ********************************************************************/
2556 static void init_unistr_array(uint16 **uni_array, fstring *char_array, char *where)
2563 DEBUG(6,("init_unistr_array\n"));
2567 if (char_array == NULL)
2571 if (!v) v = ""; /* hack to handle null lists */
2573 if (strlen(v) == 0) break;
2574 snprintf(line, sizeof(line)-1, "%s%s", where, v);
2575 DEBUGADD(6,("%d:%s:%d\n", i, line, strlen(line)));
2576 if((*uni_array=Realloc(*uni_array, (j+strlen(line)+2)*sizeof(uint16))) == NULL) {
2577 DEBUG(0,("init_unistr_array: Realloc error\n" ));
2580 j += (dos_PutUniCode((char *)(*uni_array+j), line , sizeof(uint16)*strlen(line), True) / sizeof(uint16) );
2585 (*uni_array)[j]=0x0000;
2588 DEBUGADD(6,("last one:done\n"));
2591 /********************************************************************
2592 * construct_printer_info_3
2593 * fill a printer_info_3 struct
2594 ********************************************************************/
2595 static void fill_printer_driver_info_3(DRIVER_INFO_3 *info,
2596 NT_PRINTER_DRIVER_INFO_LEVEL driver,
2597 fstring servername, fstring architecture)
2600 pstring temp_driverpath;
2601 pstring temp_datafile;
2602 pstring temp_configfile;
2603 pstring temp_helpfile;
2604 fstring short_archi;
2606 get_short_archi(short_archi, architecture);
2608 #if MANGLE_DRIVER_PATH
2609 snprintf(where,sizeof(where)-1,"\\\\%s\\print$\\%s\\%s\\", servername, short_archi, driver.info_3->name);
2611 snprintf(where,sizeof(where)-1,"\\\\%s\\print$\\%s\\", servername, short_archi);
2614 info->version=driver.info_3->cversion;
2616 init_unistr( &info->name, driver.info_3->name );
2617 init_unistr( &info->architecture, architecture );
2619 snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "%s%s", where, driver.info_3->driverpath);
2620 init_unistr( &info->driverpath, temp_driverpath );
2622 snprintf(temp_datafile, sizeof(temp_datafile)-1, "%s%s", where, driver.info_3->datafile);
2623 init_unistr( &info->datafile, temp_datafile );
2625 snprintf(temp_configfile, sizeof(temp_configfile)-1, "%s%s", where, driver.info_3->configfile);
2626 init_unistr( &info->configfile, temp_configfile );
2628 snprintf(temp_helpfile, sizeof(temp_helpfile)-1, "%s%s", where, driver.info_3->helpfile);
2629 init_unistr( &info->helpfile, temp_helpfile );
2631 init_unistr( &info->monitorname, driver.info_3->monitorname );
2632 init_unistr( &info->defaultdatatype, driver.info_3->defaultdatatype );
2634 info->dependentfiles=NULL;
2635 init_unistr_array(&info->dependentfiles, driver.info_3->dependentfiles, where);
2638 /********************************************************************
2639 * construct_printer_info_3
2640 * fill a printer_info_3 struct
2641 ********************************************************************/
2642 static void construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum,
2643 fstring servername, fstring architecture)
2645 NT_PRINTER_INFO_LEVEL *printer = NULL;
2646 NT_PRINTER_DRIVER_INFO_LEVEL driver;
2648 ZERO_STRUCT(driver);
2650 get_a_printer(&printer, 2, lp_servicename(snum) );
2651 get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture);
2653 fill_printer_driver_info_3(info, driver, servername, architecture);
2655 free_a_printer(&printer,2);
2658 /****************************************************************************
2659 ****************************************************************************/
2661 static void free_printer_driver_info_3(DRIVER_INFO_3 *info)
2663 safe_free(info->dependentfiles);
2666 /****************************************************************************
2667 ****************************************************************************/
2668 static uint32 getprinterdriver2_level1(fstring servername, fstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2670 DRIVER_INFO_1 *info=NULL;
2672 if((info=(DRIVER_INFO_1 *)malloc(sizeof(DRIVER_INFO_1))) == NULL)
2673 return ERROR_NOT_ENOUGH_MEMORY;
2675 construct_printer_driver_info_1(info, snum, servername, architecture);
2677 /* check the required size. */
2678 *needed += spoolss_size_printer_driver_info_1(info);
2680 if (!alloc_buffer_size(buffer, *needed)) {
2682 return ERROR_INSUFFICIENT_BUFFER;
2685 /* fill the buffer with the structures */
2686 new_smb_io_printer_driver_info_1("", buffer, info, 0);
2691 if (*needed > offered)
2692 return ERROR_INSUFFICIENT_BUFFER;
2694 return NT_STATUS_NO_PROBLEMO;
2697 /****************************************************************************
2698 ****************************************************************************/
2699 static uint32 getprinterdriver2_level2(fstring servername, fstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2701 DRIVER_INFO_2 *info=NULL;
2703 if((info=(DRIVER_INFO_2 *)malloc(sizeof(DRIVER_INFO_2))) == NULL)
2704 return ERROR_NOT_ENOUGH_MEMORY;
2706 construct_printer_driver_info_2(info, snum, servername, architecture);
2708 /* check the required size. */
2709 *needed += spoolss_size_printer_driver_info_2(info);
2711 if (!alloc_buffer_size(buffer, *needed)) {
2713 return ERROR_INSUFFICIENT_BUFFER;
2716 /* fill the buffer with the structures */
2717 new_smb_io_printer_driver_info_2("", buffer, info, 0);
2722 if (*needed > offered)
2723 return ERROR_INSUFFICIENT_BUFFER;
2725 return NT_STATUS_NO_PROBLEMO;
2728 /****************************************************************************
2729 ****************************************************************************/
2730 static uint32 getprinterdriver2_level3(fstring servername, fstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2736 construct_printer_driver_info_3(&info, snum, servername, architecture);
2738 /* check the required size. */
2739 *needed += spoolss_size_printer_driver_info_3(&info);
2741 if (!alloc_buffer_size(buffer, *needed)) {
2742 free_printer_driver_info_3(&info);
2743 return ERROR_INSUFFICIENT_BUFFER;
2746 /* fill the buffer with the structures */
2747 new_smb_io_printer_driver_info_3("", buffer, &info, 0);
2749 free_printer_driver_info_3(&info);
2751 if (*needed > offered)
2752 return ERROR_INSUFFICIENT_BUFFER;
2754 return NT_STATUS_NO_PROBLEMO;
2757 /****************************************************************************
2758 ****************************************************************************/
2759 uint32 _spoolss_getprinterdriver2(const POLICY_HND *handle, const UNISTR2 *uni_arch, uint32 level,
2760 uint32 clientmajorversion, uint32 clientminorversion,
2761 NEW_BUFFER *buffer, uint32 offered,
2762 uint32 *needed, uint32 *servermajorversion, uint32 *serverminorversion)
2765 fstring architecture;
2768 DEBUG(4,("_spoolss_getprinterdriver2\n"));
2771 *servermajorversion=0;
2772 *serverminorversion=0;
2774 pstrcpy(servername, global_myname);
2775 unistr2_to_ascii(architecture, uni_arch, sizeof(architecture)-1);
2777 if (!get_printer_snum(handle, &snum))
2778 return ERROR_INVALID_HANDLE;
2782 return getprinterdriver2_level1(servername, architecture, snum, buffer, offered, needed);
2785 return getprinterdriver2_level2(servername, architecture, snum, buffer, offered, needed);
2788 return getprinterdriver2_level3(servername, architecture, snum, buffer, offered, needed);
2791 return ERROR_INVALID_LEVEL;
2796 /****************************************************************************
2797 ****************************************************************************/
2798 uint32 _spoolss_startpageprinter(const POLICY_HND *handle)
2800 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2802 if (OPEN_HANDLE(Printer))
2804 Printer->page_started=True;
2808 DEBUG(3,("Error in startpageprinter printer handle\n"));
2809 return ERROR_INVALID_HANDLE;
2812 /****************************************************************************
2813 ****************************************************************************/
2814 uint32 _spoolss_endpageprinter(const POLICY_HND *handle)
2816 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2818 if (!OPEN_HANDLE(Printer))
2820 DEBUG(3,("Error in endpageprinter printer handle\n"));
2821 return ERROR_INVALID_HANDLE;
2824 Printer->page_started=False;
2826 return NT_STATUS_NO_PROBLEMO;
2830 /********************************************************************
2831 * api_spoolss_getprinter
2832 * called from the spoolss dispatcher
2834 ********************************************************************/
2835 uint32 _spoolss_startdocprinter(const POLICY_HND *handle, uint32 level,
2836 pipes_struct *p, DOC_INFO *docinfo,
2839 DOC_INFO_1 *info_1 = &docinfo->doc_info_1;
2843 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2844 struct current_user user;
2846 if (!OPEN_HANDLE(Printer))
2848 return ERROR_INVALID_HANDLE;
2851 if (p->ntlmssp_auth_validated) {
2852 memcpy(&user, &p->pipe_user, sizeof(user));
2854 extern struct current_user current_user;
2855 memcpy(&user, ¤t_user, sizeof(user));
2859 * a nice thing with NT is it doesn't listen to what you tell it.
2860 * when asked to send _only_ RAW datas, it tries to send datas
2863 * So I add checks like in NT Server ...
2865 * lkclXXXX jean-francois, i love this kind of thing. oh, well,
2866 * there's a bug in NT client-side code, so we'll fix it in the
2867 * server-side code. *nnnnnggggh!*
2870 if (info_1->p_datatype != 0)
2872 unistr2_to_ascii(datatype, &(info_1->docname), sizeof(datatype));
2873 if (strcmp(datatype, "RAW") != 0)
2876 return ERROR_INVALID_DATATYPE;
2880 /* get the share number of the printer */
2881 if (!get_printer_snum(handle, &snum))
2883 return ERROR_INVALID_HANDLE;
2886 unistr2_to_ascii(jobname, &info_1->docname, sizeof(jobname));
2888 Printer->jobid = print_job_start(&user, snum, jobname);
2890 /* need to map error codes properly - for now give out of
2891 memory as I don't know the correct codes (tridge) */
2892 if (Printer->jobid == -1) {
2893 return ERROR_NOT_ENOUGH_MEMORY;
2896 Printer->document_started=True;
2897 (*jobid) = Printer->jobid;
2902 /********************************************************************
2903 * api_spoolss_getprinter
2904 * called from the spoolss dispatcher
2906 ********************************************************************/
2907 uint32 _spoolss_enddocprinter(const POLICY_HND *handle)
2909 Printer_entry *Printer=find_printer_index_by_hnd(handle);
2911 if (!OPEN_HANDLE(Printer))
2913 DEBUG(3,("Error in enddocprinter handle\n"));
2914 return ERROR_INVALID_HANDLE;
2917 Printer->document_started=False;
2918 print_job_end(Printer->jobid);
2919 /* error codes unhandled so far ... */
2924 /****************************************************************************
2925 ****************************************************************************/
2926 uint32 _spoolss_writeprinter( const POLICY_HND *handle,
2928 const uint8 *buffer,
2929 uint32 *buffer_written)
2931 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2933 if (!OPEN_HANDLE(Printer))
2935 DEBUG(3,("Error in writeprinter handle\n"));
2936 return ERROR_INVALID_HANDLE;
2939 (*buffer_written) = print_job_write(Printer->jobid, buffer, buffer_size);
2944 /********************************************************************
2945 * api_spoolss_getprinter
2946 * called from the spoolss dispatcher
2948 ********************************************************************/
2949 static uint32 control_printer(const POLICY_HND *handle, uint32 command,
2952 struct current_user user;
2954 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2956 if (p->ntlmssp_auth_validated) {
2957 memcpy(&user, &p->pipe_user, sizeof(user));
2959 extern struct current_user current_user;
2960 memcpy(&user, ¤t_user, sizeof(user));
2963 if (!OPEN_HANDLE(Printer))
2964 return ERROR_INVALID_HANDLE;
2966 if (!get_printer_snum(handle, &snum) )
2967 return ERROR_INVALID_HANDLE;
2970 case PRINTER_CONTROL_PAUSE:
2971 if (print_queue_pause(&user, snum)) {
2975 case PRINTER_CONTROL_RESUME:
2976 case PRINTER_CONTROL_UNPAUSE:
2977 if (print_queue_resume(&user, snum)) {
2981 case PRINTER_CONTROL_PURGE:
2982 if (print_queue_purge(&user, snum)) {
2988 return ERROR_INVALID_FUNCTION;
2991 /********************************************************************
2992 * called by spoolss_api_setprinter
2993 * when updating a printer description
2994 ********************************************************************/
2995 static uint32 update_printer_sec(const POLICY_HND *handle, uint32 level,
2996 const SPOOL_PRINTER_INFO_LEVEL *info,
2997 SEC_DESC_BUF *secdesc_ctr)
2999 Printer_entry *Printer = find_printer_index_by_hnd(handle);
3001 if (!OPEN_HANDLE(Printer))
3002 return ERROR_INVALID_HANDLE;
3004 return nt_printing_setsec(Printer->dev.printername, secdesc_ctr);
3007 /********************************************************************
3008 * called by spoolss_api_setprinter
3009 * when updating a printer description
3010 ********************************************************************/
3012 static uint32 update_printer(const POLICY_HND *handle, uint32 level,
3013 const SPOOL_PRINTER_INFO_LEVEL *info,
3014 DEVICEMODE *devmode)
3017 NT_PRINTER_INFO_LEVEL *printer = NULL;
3018 Printer_entry *Printer = find_printer_index_by_hnd(handle);
3020 DEBUG(8,("update_printer\n"));
3023 DEBUG(0,("Send a mail to samba@samba.org\n"));
3024 DEBUGADD(0,("with the following message: update_printer: level!=2\n"));
3025 return ERROR_INVALID_LEVEL;
3028 if (!OPEN_HANDLE(Printer))
3029 return ERROR_INVALID_HANDLE;
3031 if (!get_printer_snum(handle, &snum) )
3032 return ERROR_INVALID_HANDLE;
3034 if(get_a_printer(&printer, 2, lp_servicename(snum)) != 0)
3035 return ERROR_INVALID_HANDLE;
3037 DEBUGADD(8,("Converting info_2 struct\n"));
3040 * convert_printer_info converts the incoming
3041 * info from the client and overwrites the info
3042 * just read from the tdb in the pointer 'printer'.
3045 convert_printer_info(info, printer, level);
3047 if (info->info_2->devmode_ptr != 0) {
3048 /* we have a valid devmode
3049 convert it and link it*/
3052 * Ensure printer->info_2->devmode is a valid pointer
3053 * as we will be overwriting it in convert_devicemode().
3056 if (printer->info_2->devmode == NULL)
3057 printer->info_2->devmode = construct_nt_devicemode(printer->info_2->printername);
3059 DEBUGADD(8,("Converting the devicemode struct\n"));
3060 convert_devicemode(devmode, printer->info_2->devmode);
3063 if (printer->info_2->devmode != NULL)
3064 free_nt_devicemode(&printer->info_2->devmode);
3065 printer->info_2->devmode=NULL;
3068 if (add_a_printer(*printer, 2)!=0) {
3069 /* I don't really know what to return here !!! */
3070 free_a_printer(&printer, 2);
3071 return ERROR_ACCESS_DENIED;
3074 free_a_printer(&printer, 2);
3076 return NT_STATUS_NO_PROBLEMO;
3079 /****************************************************************************
3080 ****************************************************************************/
3081 uint32 _spoolss_setprinter(const POLICY_HND *handle, uint32 level,
3082 const SPOOL_PRINTER_INFO_LEVEL *info,
3083 DEVMODE_CTR devmode_ctr,
3084 SEC_DESC_BUF *secdesc_ctr,
3085 uint32 command, pipes_struct *p)
3087 Printer_entry *Printer = find_printer_index_by_hnd(handle);
3089 if (!OPEN_HANDLE(Printer))
3090 return ERROR_INVALID_HANDLE;
3092 /* check the level */
3095 return control_printer(handle, command, p);
3098 return update_printer(handle, level, info, devmode_ctr.devmode);
3101 return update_printer_sec(handle, level, info, secdesc_ctr);
3104 return ERROR_INVALID_LEVEL;
3109 /****************************************************************************
3110 ****************************************************************************/
3111 uint32 _spoolss_fcpn(const POLICY_HND *handle)
3113 Printer_entry *Printer= find_printer_index_by_hnd(handle);
3115 if (!OPEN_HANDLE(Printer))
3116 return ERROR_INVALID_HANDLE;
3118 Printer->notify.flags=0;
3119 Printer->notify.options=0;
3120 Printer->notify.localmachine[0]='\0';
3121 Printer->notify.printerlocal=0;
3122 if (Printer->notify.option)
3123 safe_free(Printer->notify.option->ctr.type);
3124 safe_free(Printer->notify.option);
3125 Printer->notify.option=NULL;
3127 return NT_STATUS_NO_PROBLEMO;
3130 /****************************************************************************
3131 ****************************************************************************/
3132 uint32 _spoolss_addjob(const POLICY_HND *handle, uint32 level,
3133 NEW_BUFFER *buffer, uint32 offered)
3135 return NT_STATUS_NO_PROBLEMO;
3138 /****************************************************************************
3139 ****************************************************************************/
3140 static void fill_job_info_1(JOB_INFO_1 *job_info, print_queue_struct *queue,
3141 int position, int snum)
3146 time_t unixdate = time(NULL);
3148 t=gmtime(&unixdate);
3149 snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname);
3151 job_info->jobid=queue->job;
3152 init_unistr(&(job_info->printername), lp_servicename(snum));
3153 init_unistr(&(job_info->machinename), temp_name);
3154 init_unistr(&(job_info->username), queue->user);
3155 init_unistr(&(job_info->document), queue->file);
3156 init_unistr(&(job_info->datatype), "RAW");
3157 init_unistr(&(job_info->text_status), "");
3158 job_info->status=nt_printj_status(queue->status);
3159 job_info->priority=queue->priority;
3160 job_info->position=position;
3161 job_info->totalpages=0;
3162 job_info->pagesprinted=0;
3164 make_systemtime(&(job_info->submitted), t);
3167 /****************************************************************************
3168 ****************************************************************************/
3169 static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue,
3170 int position, int snum)
3173 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
3177 time_t unixdate = time(NULL);
3179 if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0 )
3182 t=gmtime(&unixdate);
3183 snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname);
3185 job_info->jobid=queue->job;
3187 snprintf(chaine, sizeof(chaine)-1, "\\\\%s\\%s", global_myname, ntprinter->info_2->printername);
3189 init_unistr(&(job_info->printername), chaine);
3191 init_unistr(&(job_info->machinename), temp_name);
3192 init_unistr(&(job_info->username), queue->user);
3193 init_unistr(&(job_info->document), queue->file);
3194 init_unistr(&(job_info->notifyname), queue->user);
3195 init_unistr(&(job_info->datatype), "RAW");
3196 init_unistr(&(job_info->printprocessor), "winprint");
3197 init_unistr(&(job_info->parameters), "");
3198 init_unistr(&(job_info->text_status), "");
3200 /* and here the security descriptor */
3202 job_info->status=nt_printj_status(queue->status);
3203 job_info->priority=queue->priority;
3204 job_info->position=position;
3205 job_info->starttime=0;
3206 job_info->untiltime=0;
3207 job_info->totalpages=0;
3208 job_info->size=queue->size;
3209 make_systemtime(&(job_info->submitted), t);
3210 job_info->timeelapsed=0;
3211 job_info->pagesprinted=0;
3213 if((job_info->devmode = construct_dev_mode(snum, global_myname)) == NULL) {
3214 free_a_printer(&ntprinter, 2);
3218 free_a_printer(&ntprinter, 2);
3222 /****************************************************************************
3223 Enumjobs at level 1.
3224 ****************************************************************************/
3225 static uint32 enumjobs_level1(print_queue_struct *queue, int snum,
3226 NEW_BUFFER *buffer, uint32 offered,
3227 uint32 *needed, uint32 *returned)
3232 info=(JOB_INFO_1 *)malloc(*returned*sizeof(JOB_INFO_1));
3236 return ERROR_NOT_ENOUGH_MEMORY;
3239 for (i=0; i<*returned; i++)
3240 fill_job_info_1(&(info[i]), &(queue[i]), i, snum);
3244 /* check the required size. */
3245 for (i=0; i<*returned; i++)
3246 (*needed) += spoolss_size_job_info_1(&(info[i]));
3248 if (!alloc_buffer_size(buffer, *needed)) {
3250 return ERROR_INSUFFICIENT_BUFFER;
3253 /* fill the buffer with the structures */
3254 for (i=0; i<*returned; i++)
3255 new_smb_io_job_info_1("", buffer, &(info[i]), 0);
3260 if (*needed > offered) {
3262 return ERROR_INSUFFICIENT_BUFFER;
3265 return NT_STATUS_NO_PROBLEMO;
3268 /****************************************************************************
3269 Enumjobs at level 2.
3270 ****************************************************************************/
3271 static uint32 enumjobs_level2(print_queue_struct *queue, int snum,
3272 NEW_BUFFER *buffer, uint32 offered,
3273 uint32 *needed, uint32 *returned)
3278 info=(JOB_INFO_2 *)malloc(*returned*sizeof(JOB_INFO_2));
3282 return ERROR_NOT_ENOUGH_MEMORY;
3285 for (i=0; i<*returned; i++)
3286 fill_job_info_2(&(info[i]), &(queue[i]), i, snum);
3290 /* check the required size. */
3291 for (i=0; i<*returned; i++)
3292 (*needed) += spoolss_size_job_info_2(&(info[i]));
3294 if (!alloc_buffer_size(buffer, *needed)) {
3296 return ERROR_INSUFFICIENT_BUFFER;
3299 /* fill the buffer with the structures */
3300 for (i=0; i<*returned; i++)
3301 new_smb_io_job_info_2("", buffer, &(info[i]), 0);
3306 if (*needed > offered) {
3308 return ERROR_INSUFFICIENT_BUFFER;
3311 return NT_STATUS_NO_PROBLEMO;
3314 /****************************************************************************
3316 ****************************************************************************/
3317 uint32 _spoolss_enumjobs( POLICY_HND *handle, uint32 firstjob, uint32 numofjobs, uint32 level,
3318 NEW_BUFFER *buffer, uint32 offered,
3319 uint32 *needed, uint32 *returned)
3322 print_queue_struct *queue=NULL;
3323 print_status_struct prt_status;
3325 DEBUG(4,("_spoolss_enumjobs\n"));
3327 ZERO_STRUCT(prt_status);
3332 if (!get_printer_snum(handle, &snum))
3333 return ERROR_INVALID_HANDLE;
3335 *returned = print_queue_status(snum, &queue, &prt_status);
3336 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n", *returned, prt_status.status, prt_status.message));
3340 return enumjobs_level1(queue, snum, buffer, offered, needed, returned);
3343 return enumjobs_level2(queue, snum, buffer, offered, needed, returned);
3348 return ERROR_INVALID_LEVEL;
3354 /****************************************************************************
3355 ****************************************************************************/
3356 uint32 _spoolss_schedulejob( const POLICY_HND *handle, uint32 jobid)
3361 /****************************************************************************
3362 ****************************************************************************/
3363 uint32 _spoolss_setjob( const POLICY_HND *handle,
3371 struct current_user user;
3373 print_status_struct prt_status;
3375 memset(&prt_status, 0, sizeof(prt_status));
3377 if (!get_printer_snum(handle, &snum)) {
3378 return ERROR_INVALID_HANDLE;
3381 if (!print_job_exists(jobid)) {
3382 return ERROR_INVALID_PRINTER_NAME;
3385 if (p->ntlmssp_auth_validated) {
3386 memcpy(&user, &p->pipe_user, sizeof(user));
3388 extern struct current_user current_user;
3389 memcpy(&user, ¤t_user, sizeof(user));
3393 case JOB_CONTROL_CANCEL:
3394 case JOB_CONTROL_DELETE:
3395 if (print_job_delete(&user, jobid)) return 0x0;
3397 case JOB_CONTROL_PAUSE:
3398 if (print_job_pause(&user, jobid)) return 0x0;
3400 case JOB_CONTROL_RESUME:
3401 if (print_job_resume(&user, jobid)) return 0x0;
3404 return ERROR_INVALID_LEVEL;
3407 return ERROR_INVALID_HANDLE;
3410 /****************************************************************************
3411 Enumerates all printer drivers at level 1.
3412 ****************************************************************************/
3413 static uint32 enumprinterdrivers_level1(fstring *list, fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3416 NT_PRINTER_DRIVER_INFO_LEVEL driver;
3417 DRIVER_INFO_1 *driver_info_1=NULL;
3419 ZERO_STRUCT(driver);
3421 if((driver_info_1=(DRIVER_INFO_1 *)malloc(*returned * sizeof(DRIVER_INFO_1))) == NULL)
3422 return ERROR_NOT_ENOUGH_MEMORY;
3424 for (i=0; i<*returned; i++) {
3425 get_a_printer_driver(&driver, 3, list[i], architecture);
3426 fill_printer_driver_info_1(&(driver_info_1[i]), driver, servername, architecture );
3431 /* check the required size. */
3432 for (i=0; i<*returned; i++) {
3433 DEBUGADD(6,("adding driver [%d]'s size\n",i));
3434 *needed += spoolss_size_printer_driver_info_1(&(driver_info_1[i]));
3437 if (!alloc_buffer_size(buffer, *needed)) {
3438 safe_free(driver_info_1);
3439 return ERROR_INSUFFICIENT_BUFFER;
3442 /* fill the buffer with the form structures */
3443 for (i=0; i<*returned; i++) {
3444 DEBUGADD(6,("adding driver [%d] to buffer\n",i));
3445 new_smb_io_printer_driver_info_1("", buffer, &(driver_info_1[i]), 0);
3448 safe_free(driver_info_1);
3450 if (*needed > offered) {
3452 return ERROR_INSUFFICIENT_BUFFER;
3455 return NT_STATUS_NO_PROBLEMO;
3458 /****************************************************************************
3459 Enumerates all printer drivers at level 2.
3460 ****************************************************************************/
3461 static uint32 enumprinterdrivers_level2(fstring *list, fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3464 DRIVER_INFO_2 *driver_info_2=NULL;
3466 if (*returned > 0 &&
3467 !(driver_info_2=(DRIVER_INFO_2 *)malloc(*returned * sizeof(DRIVER_INFO_2))))
3468 return ERROR_NOT_ENOUGH_MEMORY;
3470 for (i=0; i<*returned; i++) {
3471 NT_PRINTER_DRIVER_INFO_LEVEL driver;
3472 ZERO_STRUCT(driver);
3473 if (get_a_printer_driver(&driver, 3, list[i], architecture)
3478 fill_printer_driver_info_2(&(driver_info_2[i]), driver, servername, architecture );
3483 /* check the required size. */
3484 for (i=0; i<*returned; i++) {
3485 DEBUGADD(6,("adding driver [%d]'s size\n",i));
3486 *needed += spoolss_size_printer_driver_info_2(&(driver_info_2[i]));
3489 if (!alloc_buffer_size(buffer, *needed)) {
3490 safe_free(driver_info_2);
3491 return ERROR_INSUFFICIENT_BUFFER;
3494 /* fill the buffer with the form structures */
3495 for (i=0; i<*returned; i++) {
3496 DEBUGADD(6,("adding driver [%d] to buffer\n",i));
3497 new_smb_io_printer_driver_info_2("", buffer, &(driver_info_2[i]), 0);
3500 safe_free(driver_info_2);
3502 if (*needed > offered) {
3504 return ERROR_INSUFFICIENT_BUFFER;
3507 return NT_STATUS_NO_PROBLEMO;
3510 /****************************************************************************
3511 Enumerates all printer drivers at level 3.
3512 ****************************************************************************/
3513 static uint32 enumprinterdrivers_level3(fstring *list, fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3516 NT_PRINTER_DRIVER_INFO_LEVEL driver;
3517 DRIVER_INFO_3 *driver_info_3=NULL;
3519 ZERO_STRUCT(driver);
3521 if((driver_info_3=(DRIVER_INFO_3 *)malloc((*returned)*sizeof(DRIVER_INFO_3))) == NULL)
3522 return ERROR_NOT_ENOUGH_MEMORY;
3524 for (i=0; i<*returned; i++) {
3525 get_a_printer_driver(&driver, 3, list[i], architecture);
3526 fill_printer_driver_info_3(&(driver_info_3[i]), driver, servername, architecture );
3531 /* check the required size. */
3532 for (i=0; i<*returned; i++) {
3533 DEBUGADD(6,("adding driver [%d]'s size\n",i));
3534 *needed += spoolss_size_printer_driver_info_3(&driver_info_3[i]);
3537 if (!alloc_buffer_size(buffer, *needed)) {
3538 safe_free(driver_info_3);
3539 return ERROR_INSUFFICIENT_BUFFER;
3542 /* fill the buffer with the form structures */
3543 for (i=0; i<*returned; i++) {
3544 DEBUGADD(6,("adding form [%d] to buffer\n",i));
3545 new_smb_io_printer_driver_info_3("", buffer, &driver_info_3[i], 0);
3548 for (i=0; i<*returned; i++)
3549 safe_free(driver_info_3[i].dependentfiles);
3551 safe_free(driver_info_3);
3553 if (*needed > offered) {
3555 return ERROR_INSUFFICIENT_BUFFER;
3558 return NT_STATUS_NO_PROBLEMO;
3561 /****************************************************************************
3562 Enumerates all printer drivers.
3563 ****************************************************************************/
3564 uint32 _spoolss_enumprinterdrivers( UNISTR2 *name, UNISTR2 *environment, uint32 level,
3565 NEW_BUFFER *buffer, uint32 offered,
3566 uint32 *needed, uint32 *returned)
3569 fstring *list = NULL;
3571 fstring architecture;
3573 DEBUG(4,("_spoolss_enumprinterdrivers\n"));
3574 fstrcpy(servername, global_myname);
3578 unistr2_to_ascii(architecture, environment, sizeof(architecture)-1);
3579 *returned=get_ntdrivers(&list, architecture);
3581 DEBUGADD(4,("we have: [%d] drivers in environment [%s]\n", *returned, architecture));
3583 return ERROR_NOT_ENOUGH_MEMORY;
3585 for (i=0; i<*returned; i++)
3586 DEBUGADD(5,("driver: [%s]\n", list[i]));
3590 return enumprinterdrivers_level1(list, servername, architecture, buffer, offered, needed, returned);
3593 return enumprinterdrivers_level2(list, servername, architecture, buffer, offered, needed, returned);
3596 return enumprinterdrivers_level3(list, servername, architecture, buffer, offered, needed, returned);
3599 return ERROR_INVALID_LEVEL;
3604 /****************************************************************************
3605 ****************************************************************************/
3606 static void fill_form_1(FORM_1 *form, nt_forms_struct *list, int position)
3608 form->flag=list->flag;
3609 init_unistr(&(form->name), list->name);
3610 form->width=list->width;
3611 form->length=list->length;
3612 form->left=list->left;
3613 form->top=list->top;
3614 form->right=list->right;
3615 form->bottom=list->bottom;
3618 /****************************************************************************
3619 ****************************************************************************/
3620 uint32 _new_spoolss_enumforms( const POLICY_HND *handle, uint32 level,
3621 NEW_BUFFER *buffer, uint32 offered,
3622 uint32 *needed, uint32 *numofforms)
3624 nt_forms_struct *list=NULL;
3629 DEBUG(4,("_new_spoolss_enumforms\n"));
3630 DEBUGADD(5,("Offered buffer size [%d]\n", offered));
3631 DEBUGADD(5,("Info level [%d]\n", level));
3633 *numofforms = get_ntforms(&list);
3634 DEBUGADD(5,("Number of forms [%d]\n", *numofforms));
3636 if (*numofforms == 0) return ERROR_NO_MORE_ITEMS;
3640 if ((forms_1=(FORM_1 *)malloc(*numofforms * sizeof(FORM_1))) == NULL) {
3642 return ERROR_NOT_ENOUGH_MEMORY;
3645 /* construct the list of form structures */
3646 for (i=0; i<*numofforms; i++) {
3647 DEBUGADD(6,("Filling form number [%d]\n",i));
3648 fill_form_1(&(forms_1[i]), &(list[i]), i);
3653 /* check the required size. */
3654 for (i=0; i<*numofforms; i++) {
3655 DEBUGADD(6,("adding form [%d]'s size\n",i));
3656 buffer_size += spoolss_size_form_1(&(forms_1[i]));
3659 *needed=buffer_size;
3661 if (!alloc_buffer_size(buffer, buffer_size)){
3663 return ERROR_INSUFFICIENT_BUFFER;
3666 /* fill the buffer with the form structures */
3667 for (i=0; i<*numofforms; i++) {
3668 DEBUGADD(6,("adding form [%d] to buffer\n",i));
3669 new_smb_io_form_1("", buffer, &(forms_1[i]), 0);
3674 if (*needed > offered) {
3676 return ERROR_INSUFFICIENT_BUFFER;
3679 return NT_STATUS_NO_PROBLEMO;
3683 return ERROR_INVALID_LEVEL;
3688 /****************************************************************************
3689 ****************************************************************************/
3690 static void fill_port_1(PORT_INFO_1 *port, char *name)
3692 init_unistr(&port->port_name, name);
3695 /****************************************************************************
3696 ****************************************************************************/
3697 static void fill_port_2(PORT_INFO_2 *port, char *name)
3699 init_unistr(&port->port_name, name);
3700 init_unistr(&port->monitor_name, "Local Monitor");
3701 init_unistr(&port->description, "Local Port");
3702 #define PORT_TYPE_WRITE 1
3703 port->port_type=PORT_TYPE_WRITE;
3707 /****************************************************************************
3709 ****************************************************************************/
3710 static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3712 int n_services=lp_numservices();
3716 PORT_INFO_1 *ports=NULL;
3718 for (snum=0; snum<n_services; snum++)
3719 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
3722 if((ports=(PORT_INFO_1 *)malloc( (*returned+1) * sizeof(PORT_INFO_1) )) == NULL)
3723 return ERROR_NOT_ENOUGH_MEMORY;
3725 for (snum=0; snum<n_services; snum++) {
3726 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
3728 * Ensure this port name is unique.
3732 DEBUG(10,("enumports_level_1: port name %s\n", PRINTERNAME(snum)));
3734 for(j = 0; j < i; j++) {
3736 unistr_to_dos(port_name, (const char *)&ports[j].port_name.buffer[0], sizeof(port_name));
3738 if (strequal(port_name, PRINTERNAME(snum)))
3745 DEBUGADD(6,("Filling port number [%d]\n", i));
3746 fill_port_1(&ports[i], PRINTERNAME(snum));
3753 /* check the required size. */
3754 for (i=0; i<*returned; i++) {
3755 DEBUGADD(6,("adding port [%d]'s size\n", i));
3756 *needed += spoolss_size_port_info_1(&ports[i]);
3759 if (!alloc_buffer_size(buffer, *needed)) {
3761 return ERROR_INSUFFICIENT_BUFFER;
3764 /* fill the buffer with the ports structures */
3765 for (i=0; i<*returned; i++) {
3766 DEBUGADD(6,("adding port [%d] to buffer\n", i));
3767 new_smb_io_port_1("", buffer, &ports[i], 0);
3772 if (*needed > offered) {
3774 return ERROR_INSUFFICIENT_BUFFER;
3777 return NT_STATUS_NO_PROBLEMO;
3780 /****************************************************************************
3782 ****************************************************************************/
3784 static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3786 int n_services=lp_numservices();
3790 PORT_INFO_2 *ports=NULL;
3792 for (snum=0; snum<n_services; snum++)
3793 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
3796 if((ports=(PORT_INFO_2 *)malloc( (*returned+1) * sizeof(PORT_INFO_2) )) == NULL)
3797 return ERROR_NOT_ENOUGH_MEMORY;
3799 for (snum=0; snum<n_services; snum++) {
3800 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
3802 * Ensure this port name is unique.
3806 DEBUG(10,("enumports_level_2: port name %s\n", PRINTERNAME(snum)));
3808 for(j = 0; j < i; j++) {
3810 unistr_to_dos(port_name, (const char *)&ports[j].port_name.buffer[0], sizeof(port_name));
3812 if (strequal(port_name, PRINTERNAME(snum)))
3819 DEBUGADD(6,("Filling port number [%d]\n", i));
3820 fill_port_2(&ports[i], PRINTERNAME(snum));
3827 /* check the required size. */
3828 for (i=0; i<*returned; i++) {
3829 DEBUGADD(6,("adding port [%d]'s size\n", i));
3830 *needed += spoolss_size_port_info_2(&ports[i]);
3833 if (!alloc_buffer_size(buffer, *needed)) {
3835 return ERROR_INSUFFICIENT_BUFFER;
3838 /* fill the buffer with the ports structures */
3839 for (i=0; i<*returned; i++) {
3840 DEBUGADD(6,("adding port [%d] to buffer\n", i));
3841 new_smb_io_port_2("", buffer, &ports[i], 0);
3846 if (*needed > offered) {
3848 return ERROR_INSUFFICIENT_BUFFER;
3851 return NT_STATUS_NO_PROBLEMO;
3854 /****************************************************************************
3856 ****************************************************************************/
3857 uint32 _spoolss_enumports( UNISTR2 *name, uint32 level,
3858 NEW_BUFFER *buffer, uint32 offered,
3859 uint32 *needed, uint32 *returned)
3861 DEBUG(4,("_spoolss_enumports\n"));
3868 return enumports_level_1(buffer, offered, needed, returned);
3871 return enumports_level_2(buffer, offered, needed, returned);
3874 return ERROR_INVALID_LEVEL;
3879 /****************************************************************************
3880 ****************************************************************************/
3881 static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name,
3882 const SPOOL_PRINTER_INFO_LEVEL *info,
3883 uint32 unk0, uint32 unk1, uint32 unk2, uint32 unk3,
3884 uint32 user_switch, const SPOOL_USER_CTR *user,
3887 NT_PRINTER_INFO_LEVEL *printer = NULL;
3891 if ((printer = (NT_PRINTER_INFO_LEVEL *)malloc(sizeof(NT_PRINTER_INFO_LEVEL))) == NULL) {
3892 DEBUG(0,("spoolss_addprinterex_level_2: malloc fail.\n"));
3893 return ERROR_NOT_ENOUGH_MEMORY;
3896 ZERO_STRUCTP(printer);
3898 clear_handle(handle);
3900 /* convert from UNICODE to ASCII - this allocates the info_2 struct inside *printer.*/
3901 convert_printer_info(info, printer, 2);
3903 unistr2_to_ascii(share_name, &info->info_2->printername, sizeof(share_name)-1);
3905 slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname, share_name);
3907 /* write the ASCII on disk */
3908 if (add_a_printer(*printer, 2) != 0) {
3909 free_a_printer(&printer,2);
3910 return ERROR_ACCESS_DENIED;
3913 create_printer_hnd(handle);
3915 open_printer_hnd(handle);
3917 if (!set_printer_hnd_printertype(handle, name)) {
3918 free_a_printer(&printer,2);
3919 close_printer_handle(handle);
3920 return ERROR_ACCESS_DENIED;
3923 if (!set_printer_hnd_printername(handle, name)) {
3924 free_a_printer(&printer,2);
3925 close_printer_handle(handle);
3926 return ERROR_ACCESS_DENIED;
3929 free_a_printer(&printer,2);
3930 return NT_STATUS_NO_PROBLEMO;
3933 /****************************************************************************
3934 ****************************************************************************/
3935 uint32 _spoolss_addprinterex( const UNISTR2 *uni_srv_name, uint32 level,
3936 const SPOOL_PRINTER_INFO_LEVEL *info,
3937 uint32 unk0, uint32 unk1, uint32 unk2, uint32 unk3,
3938 uint32 user_switch, const SPOOL_USER_CTR *user,
3943 /* we don't handle yet */
3944 /* but I know what to do ... */
3945 return ERROR_INVALID_LEVEL;
3948 return spoolss_addprinterex_level_2(uni_srv_name, info,
3949 unk0, unk1, unk2, unk3,
3950 user_switch, user, handle);
3953 return ERROR_INVALID_LEVEL;
3958 /****************************************************************************
3959 Modify internal driver heirarchy.
3960 ****************************************************************************/
3962 #if MANGLE_DRIVER_PATH
3963 static uint32 modify_driver_heirarchy(NT_PRINTER_DRIVER_INFO_LEVEL *driver, uint32 level)
3967 pstring short_archi;
3970 /* find_service is an smbd-specific function call */
3971 int snum = find_service("print$");
3974 *short_archi = '\0';
3977 get_short_archi(short_archi, driver->info_3->environment);
3978 model = driver->info_3->name;
3981 get_short_archi(short_archi, driver->info_6->environment);
3982 model = driver->info_6->name;
3985 DEBUG(0,("modify_driver_heirarchy: unknown info level (%d)\n", level));
3986 return ERROR_INVALID_LEVEL;
3990 slprintf(path_old, sizeof(path_old)-1, "%s/%s/TMP_%s", lp_pathname(snum), short_archi,
3993 /* Clean up any '/' and other characters in the model name. */
3994 alpha_strcpy(model_name, model, sizeof(pstring));
3996 slprintf(path_new, sizeof(path_new)-1, "%s/%s/%s", lp_pathname(snum), short_archi, model_name);
3998 DEBUG(10,("modify_driver_heirarchy: old_path=%s, new_path=%s\n",
3999 path_old, path_new ));
4000 if (dos_rename(path_old, path_new) == -1) {
4001 DEBUG(0,("modify_driver_heirarchy: rename from %s to %s failed (%s)\n",
4002 path_old, path_new, strerror(errno) ));
4003 /* We need to clean up here.... - how ? */
4004 return ERROR_ACCESS_DENIED; /* We need a generic mapping from NT errors here... */
4007 return NT_STATUS_NO_PROBLEMO;
4011 /****************************************************************************
4012 ****************************************************************************/
4013 uint32 _spoolss_addprinterdriver( const UNISTR2 *server_name,
4015 const SPOOL_PRINTER_DRIVER_INFO_LEVEL *info)
4017 uint32 err = NT_STATUS_NO_PROBLEMO;
4018 NT_PRINTER_DRIVER_INFO_LEVEL driver;
4019 ZERO_STRUCT(driver);
4021 convert_printer_driver_info(info, &driver, level);
4023 if (add_a_printer_driver(driver, level)!=0)
4024 return ERROR_ACCESS_DENIED;
4026 #if MANGLE_DRIVER_PATH
4027 err = modify_driver_heirarchy(&driver, level);
4030 free_a_printer_driver(driver, level);
4035 /****************************************************************************
4036 ****************************************************************************/
4037 static void fill_driverdir_1(DRIVER_DIRECTORY_1 *info, char *name)
4039 init_unistr(&(info->name), name);
4042 /****************************************************************************
4043 ****************************************************************************/
4044 static uint32 getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environment, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
4048 pstring short_archi;
4049 DRIVER_DIRECTORY_1 *info=NULL;
4051 if((info=(DRIVER_DIRECTORY_1 *)malloc(sizeof(DRIVER_DIRECTORY_1))) == NULL)
4052 return ERROR_NOT_ENOUGH_MEMORY;
4054 unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)-1);
4055 get_short_archi(short_archi, long_archi);
4057 #if MANGLE_DRIVER_PATH
4058 slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s\\TMP_%s", global_myname, short_archi,
4061 slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s",
4062 global_myname, short_archi);
4064 DEBUG(4,("printer driver directory: [%s]\n", path));
4066 fill_driverdir_1(info, path);
4068 *needed += spoolss_size_driverdir_info_1(info);
4070 if (!alloc_buffer_size(buffer, *needed)) {
4072 return ERROR_INSUFFICIENT_BUFFER;
4075 new_smb_io_driverdir_1("", buffer, info, 0);
4079 if (*needed > offered)
4080 return ERROR_INSUFFICIENT_BUFFER;
4082 return NT_STATUS_NO_PROBLEMO;
4085 /****************************************************************************
4086 ****************************************************************************/
4087 uint32 _spoolss_getprinterdriverdirectory(UNISTR2 *name, UNISTR2 *uni_environment, uint32 level,
4088 NEW_BUFFER *buffer, uint32 offered,
4091 DEBUG(4,("_spoolss_getprinterdriverdirectory\n"));
4097 return getprinterdriverdir_level_1(name, uni_environment, buffer, offered, needed);
4100 return ERROR_INVALID_LEVEL;
4105 /****************************************************************************
4106 ****************************************************************************/
4107 uint32 _spoolss_enumprinterdata(const POLICY_HND *handle, uint32 idx,
4108 uint32 in_value_len, uint32 in_data_len,
4109 uint32 *out_max_value_len, uint16 **out_value, uint32 *out_value_len,
4111 uint32 *out_max_data_len, uint8 **data_out, uint32 *out_data_len)
4113 NT_PRINTER_INFO_LEVEL *printer = NULL;
4118 uint32 biggest_valuesize;
4119 uint32 biggest_datasize;
4121 Printer_entry *Printer = find_printer_index_by_hnd(handle);
4126 ZERO_STRUCT(printer);
4128 *out_max_value_len=0;
4134 *out_max_data_len=0;
4138 DEBUG(5,("spoolss_enumprinterdata\n"));
4140 if (!OPEN_HANDLE(Printer))
4141 return ERROR_INVALID_HANDLE;
4143 if (!get_printer_snum(handle, &snum))
4144 return ERROR_INVALID_HANDLE;
4146 if (get_a_printer(&printer, 2, lp_servicename(snum)) != 0)
4147 return ERROR_INVALID_HANDLE;
4150 * The NT machine wants to know the biggest size of value and data
4152 * cf: MSDN EnumPrinterData remark section
4154 if ( (in_value_len==0) && (in_data_len==0) ) {
4155 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
4158 biggest_valuesize=0;
4161 while (get_specific_param_by_index(*printer, 2, param_index, value, &data, &type, &data_len)) {
4162 if (strlen(value) > biggest_valuesize) biggest_valuesize=strlen(value);
4163 if (data_len > biggest_datasize) biggest_datasize=data_len;
4165 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize, biggest_datasize));
4171 /* the value is an UNICODE string but realvaluesize is the length in bytes including the leading 0 */
4172 *out_value_len=2*(1+biggest_valuesize);
4173 *out_data_len=biggest_datasize;
4175 DEBUG(6,("final values: [%d], [%d]\n", *out_value_len, *out_data_len));
4177 free_a_printer(&printer, 2);
4178 return NT_STATUS_NO_PROBLEMO;
4182 * the value len is wrong in NT sp3
4183 * that's the number of bytes not the number of unicode chars
4186 if (!get_specific_param_by_index(*printer, 2, idx, value, &data, &type, &data_len)) {
4188 free_a_printer(&printer, 2);
4189 return ERROR_NO_MORE_ITEMS;
4192 free_a_printer(&printer, 2);
4196 * - counted in bytes in the request
4197 * - counted in UNICODE chars in the max reply
4198 * - counted in bytes in the real size
4200 * take a pause *before* coding not *during* coding
4203 *out_max_value_len=(in_value_len/sizeof(uint16));
4204 if((*out_value=(uint16 *)malloc(in_value_len*sizeof(uint8))) == NULL) {
4206 return ERROR_NOT_ENOUGH_MEMORY;
4208 *out_value_len = (uint32)dos_PutUniCode((char *)*out_value, value, in_value_len, True);
4210 *out_max_value_len=(*out_value_len/sizeof(uint16));
4211 #endif /* JRATEST */
4215 /* the data is counted in bytes */
4216 *out_max_data_len=in_data_len;
4217 if((*data_out=(uint8 *)malloc(in_data_len*sizeof(uint8))) == NULL) {
4219 return ERROR_NOT_ENOUGH_MEMORY;
4221 memcpy(*data_out, data, (size_t)data_len);
4222 *out_data_len=data_len;
4224 *out_max_data_len=data_len;
4225 #endif /* JRATEST */
4229 return NT_STATUS_NO_PROBLEMO;
4232 /****************************************************************************
4233 ****************************************************************************/
4234 uint32 _spoolss_setprinterdata( const POLICY_HND *handle,
4235 const UNISTR2 *value,
4240 uint32 numeric_data)
4242 NT_PRINTER_INFO_LEVEL *printer = NULL;
4243 NT_PRINTER_PARAM *param = NULL;
4246 uint32 status = 0x0;
4247 Printer_entry *Printer=find_printer_index_by_hnd(handle);
4249 DEBUG(5,("spoolss_setprinterdata\n"));
4252 if (!OPEN_HANDLE(Printer))
4253 return ERROR_INVALID_HANDLE;
4255 if (!get_printer_snum(handle, &snum))
4256 return ERROR_INVALID_HANDLE;
4258 status = get_a_printer(&printer, 2, lp_servicename(snum));
4260 return ERROR_INVALID_NAME;
4262 convert_specific_param(¶m, value , type, data, real_len);
4263 unlink_specific_param_if_exist(printer->info_2, param);
4265 if (!add_a_specific_param(printer->info_2, param))
4266 status = ERROR_INVALID_PARAMETER;
4268 status = add_a_printer(*printer, 2);
4270 free_a_printer(&printer, 2);
4274 /****************************************************************************
4275 ****************************************************************************/
4276 uint32 _spoolss_addform( const POLICY_HND *handle,
4281 nt_forms_struct *list=NULL;
4282 Printer_entry *Printer = find_printer_index_by_hnd(handle);
4284 DEBUG(5,("spoolss_addform\n"));
4286 if (!OPEN_HANDLE(Printer))
4287 return ERROR_INVALID_HANDLE;
4289 count=get_ntforms(&list);
4290 if(!add_a_form(&list, form, &count))
4291 return ERROR_NOT_ENOUGH_MEMORY;
4292 write_ntforms(&list, count);
4299 /****************************************************************************
4300 ****************************************************************************/
4301 uint32 _spoolss_setform( const POLICY_HND *handle,
4302 const UNISTR2 *uni_name,
4307 nt_forms_struct *list=NULL;
4308 Printer_entry *Printer = find_printer_index_by_hnd(handle);
4310 DEBUG(5,("spoolss_setform\n"));
4312 if (!OPEN_HANDLE(Printer))
4314 return ERROR_INVALID_HANDLE;
4316 count=get_ntforms(&list);
4317 update_a_form(&list, form, count);
4318 write_ntforms(&list, count);
4325 /****************************************************************************
4326 enumprintprocessors level 1.
4327 ****************************************************************************/
4328 static uint32 enumprintprocessors_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4330 PRINTPROCESSOR_1 *info_1=NULL;
4332 if((info_1 = (PRINTPROCESSOR_1 *)malloc(sizeof(PRINTPROCESSOR_1))) == NULL)
4333 return ERROR_NOT_ENOUGH_MEMORY;
4337 init_unistr(&(info_1->name), "winprint");
4339 *needed += spoolss_size_printprocessor_info_1(info_1);
4341 if (!alloc_buffer_size(buffer, *needed))
4342 return ERROR_INSUFFICIENT_BUFFER;
4344 smb_io_printprocessor_info_1("", buffer, info_1, 0);
4348 if (*needed > offered) {
4350 return ERROR_INSUFFICIENT_BUFFER;
4353 return NT_STATUS_NO_PROBLEMO;
4356 /****************************************************************************
4357 ****************************************************************************/
4358 uint32 _spoolss_enumprintprocessors(UNISTR2 *name, UNISTR2 *environment, uint32 level,
4359 NEW_BUFFER *buffer, uint32 offered,
4360 uint32 *needed, uint32 *returned)
4362 DEBUG(5,("spoolss_enumprintprocessors\n"));
4365 * Enumerate the print processors ...
4367 * Just reply with "winprint", to keep NT happy
4368 * and I can use my nice printer checker.
4376 return enumprintprocessors_level_1(buffer, offered, needed, returned);
4379 return ERROR_INVALID_LEVEL;
4384 /****************************************************************************
4385 enumprintprocdatatypes level 1.
4386 ****************************************************************************/
4387 static uint32 enumprintprocdatatypes_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4389 PRINTPROCDATATYPE_1 *info_1=NULL;
4391 if((info_1 = (PRINTPROCDATATYPE_1 *)malloc(sizeof(PRINTPROCDATATYPE_1))) == NULL)
4392 return ERROR_NOT_ENOUGH_MEMORY;
4396 init_unistr(&(info_1->name), "RAW");
4398 *needed += spoolss_size_printprocdatatype_info_1(info_1);
4400 if (!alloc_buffer_size(buffer, *needed))
4401 return ERROR_INSUFFICIENT_BUFFER;
4403 smb_io_printprocdatatype_info_1("", buffer, info_1, 0);
4407 if (*needed > offered) {
4409 return ERROR_INSUFFICIENT_BUFFER;
4412 return NT_STATUS_NO_PROBLEMO;
4415 /****************************************************************************
4416 ****************************************************************************/
4417 uint32 _spoolss_enumprintprocdatatypes(UNISTR2 *name, UNISTR2 *processor, uint32 level,
4418 NEW_BUFFER *buffer, uint32 offered,
4419 uint32 *needed, uint32 *returned)
4421 DEBUG(5,("_spoolss_enumprintprocdatatypes\n"));
4428 return enumprintprocdatatypes_level_1(buffer, offered, needed, returned);
4431 return ERROR_INVALID_LEVEL;
4436 /****************************************************************************
4437 enumprintmonitors level 1.
4438 ****************************************************************************/
4439 static uint32 enumprintmonitors_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4441 PRINTMONITOR_1 *info_1=NULL;
4443 if((info_1 = (PRINTMONITOR_1 *)malloc(sizeof(PRINTMONITOR_1))) == NULL)
4444 return ERROR_NOT_ENOUGH_MEMORY;
4448 init_unistr(&(info_1->name), "Local Port");
4450 *needed += spoolss_size_printmonitor_info_1(info_1);
4452 if (!alloc_buffer_size(buffer, *needed))
4453 return ERROR_INSUFFICIENT_BUFFER;
4455 smb_io_printmonitor_info_1("", buffer, info_1, 0);
4459 if (*needed > offered) {
4461 return ERROR_INSUFFICIENT_BUFFER;
4464 return NT_STATUS_NO_PROBLEMO;
4467 /****************************************************************************
4468 enumprintmonitors level 2.
4469 ****************************************************************************/
4470 static uint32 enumprintmonitors_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4472 PRINTMONITOR_2 *info_2=NULL;
4474 if((info_2 = (PRINTMONITOR_2 *)malloc(sizeof(PRINTMONITOR_2))) == NULL)
4475 return ERROR_NOT_ENOUGH_MEMORY;
4479 init_unistr(&(info_2->name), "Local Port");
4480 init_unistr(&(info_2->environment), "Windows NT X86");
4481 init_unistr(&(info_2->dll_name), "localmon.dll");
4483 *needed += spoolss_size_printmonitor_info_2(info_2);
4485 if (!alloc_buffer_size(buffer, *needed))
4486 return ERROR_INSUFFICIENT_BUFFER;
4488 smb_io_printmonitor_info_2("", buffer, info_2, 0);
4492 if (*needed > offered) {
4494 return ERROR_INSUFFICIENT_BUFFER;
4497 return NT_STATUS_NO_PROBLEMO;
4500 /****************************************************************************
4501 ****************************************************************************/
4502 uint32 _spoolss_enumprintmonitors(UNISTR2 *name,uint32 level,
4503 NEW_BUFFER *buffer, uint32 offered,
4504 uint32 *needed, uint32 *returned)
4506 DEBUG(5,("spoolss_enumprintmonitors\n"));
4509 * Enumerate the print monitors ...
4511 * Just reply with "Local Port", to keep NT happy
4512 * and I can use my nice printer checker.
4520 return enumprintmonitors_level_1(buffer, offered, needed, returned);
4523 return enumprintmonitors_level_2(buffer, offered, needed, returned);
4526 return ERROR_INVALID_LEVEL;
4531 /****************************************************************************
4532 ****************************************************************************/
4533 static uint32 getjob_level_1(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
4537 JOB_INFO_1 *info_1=NULL;
4539 info_1=(JOB_INFO_1 *)malloc(sizeof(JOB_INFO_1));
4541 if (info_1 == NULL) {
4543 return ERROR_NOT_ENOUGH_MEMORY;
4546 for (i=0; i<count && found==False; i++) {
4547 if (queue[i].job==(int)jobid)
4554 /* I shoud reply something else ... I can't find the good one */
4555 return NT_STATUS_NO_PROBLEMO;
4558 fill_job_info_1(info_1, &(queue[i-1]), i, snum);
4562 *needed += spoolss_size_job_info_1(info_1);
4564 if (!alloc_buffer_size(buffer, *needed)) {
4566 return ERROR_INSUFFICIENT_BUFFER;
4569 new_smb_io_job_info_1("", buffer, info_1, 0);
4573 if (*needed > offered)
4574 return ERROR_INSUFFICIENT_BUFFER;
4576 return NT_STATUS_NO_PROBLEMO;
4580 /****************************************************************************
4581 ****************************************************************************/
4582 static uint32 getjob_level_2(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
4587 info_2=(JOB_INFO_2 *)malloc(sizeof(JOB_INFO_2));
4589 ZERO_STRUCTP(info_2);
4591 if (info_2 == NULL) {
4593 return ERROR_NOT_ENOUGH_MEMORY;
4596 for (i=0; i<count && found==False; i++) {
4597 if (queue[i].job==(int)jobid)
4604 /* I shoud reply something else ... I can't find the good one */
4605 return NT_STATUS_NO_PROBLEMO;
4608 fill_job_info_2(info_2, &(queue[i-1]), i, snum);
4612 *needed += spoolss_size_job_info_2(info_2);
4614 if (!alloc_buffer_size(buffer, *needed)) {
4616 return ERROR_INSUFFICIENT_BUFFER;
4619 new_smb_io_job_info_2("", buffer, info_2, 0);
4621 free_dev_mode(info_2->devmode);
4624 if (*needed > offered)
4625 return ERROR_INSUFFICIENT_BUFFER;
4627 return NT_STATUS_NO_PROBLEMO;
4630 /****************************************************************************
4631 ****************************************************************************/
4632 uint32 _spoolss_getjob( POLICY_HND *handle, uint32 jobid, uint32 level,
4633 NEW_BUFFER *buffer, uint32 offered,
4638 print_queue_struct *queue=NULL;
4639 print_status_struct prt_status;
4641 DEBUG(5,("spoolss_getjob\n"));
4643 memset(&prt_status, 0, sizeof(prt_status));
4647 if (!get_printer_snum(handle, &snum))
4648 return ERROR_INVALID_HANDLE;
4650 count = print_queue_status(snum, &queue, &prt_status);
4652 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
4653 count, prt_status.status, prt_status.message));
4657 return getjob_level_1(queue, count, snum, jobid, buffer, offered, needed);
4660 return getjob_level_2(queue, count, snum, jobid, buffer, offered, needed);
4664 return ERROR_INVALID_LEVEL;