2 * Unix SMB/Netbios implementation.
4 * RPC Pipe client / server routines
5 * Copyright (C) Andrew Tridgell 1992-2000,
6 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
7 * Copyright (C) Jean François Micouleau 1998-2000.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 extern int DEBUGLEVEL;
28 extern pstring global_myname;
30 #ifndef MAX_OPEN_PRINTER_EXS
31 #define MAX_OPEN_PRINTER_EXS 50
34 #define PRINTER_HANDLE_IS_PRINTER 0
35 #define PRINTER_HANDLE_IS_PRINTSERVER 1
37 /* structure to store the printer handles */
38 /* and a reference to what it's pointing to */
39 /* and the notify info asked about */
40 /* that's the central struct */
41 typedef struct _Printer{
46 BOOL document_started;
48 int jobid; /* jobid in printing backend */
49 POLICY_HND printer_hnd;
53 fstring printerservername;
62 SPOOL_NOTIFY_OPTION *option;
70 typedef struct _counter_printer_0 {
78 static ubi_dlList Printer_list;
79 static ubi_dlList counter_list;
82 #define OPEN_HANDLE(pnum) ((pnum!=NULL) && (pnum->open!=False))
84 /* translate between internal status numbers and NT status numbers */
85 static int nt_printj_status(int v)
89 return PRINTER_STATUS_PAUSED;
98 static int nt_printq_status(int v)
102 return PRINTER_STATUS_ERROR;
111 /****************************************************************************
112 initialise printer handle states...
113 ****************************************************************************/
114 void init_printer_hnd(void)
116 ubi_dlInitList(&Printer_list);
117 ubi_dlInitList(&counter_list);
120 /****************************************************************************
121 create a unique printer handle
122 ****************************************************************************/
123 static void create_printer_hnd(POLICY_HND *hnd)
125 static uint32 prt_hnd_low = 0;
126 static uint32 prt_hnd_high = 0;
128 if (hnd == NULL) return;
130 /* i severely doubt that prt_hnd_high will ever be non-zero... */
132 if (prt_hnd_low == 0) prt_hnd_high++;
134 SIVAL(hnd->data, 0 , 0x0); /* first bit must be null */
135 SIVAL(hnd->data, 4 , prt_hnd_low ); /* second bit is incrementing */
136 SIVAL(hnd->data, 8 , prt_hnd_high); /* second bit is incrementing */
137 SIVAL(hnd->data, 12, time(NULL)); /* something random */
138 SIVAL(hnd->data, 16, sys_getpid()); /* something more random */
141 /****************************************************************************
142 find printer index by handle
143 ****************************************************************************/
144 static Printer_entry *find_printer_index_by_hnd(const POLICY_HND *hnd)
146 Printer_entry *find_printer;
148 find_printer = (Printer_entry *)ubi_dlFirst(&Printer_list);
150 for(; find_printer; find_printer = (Printer_entry *)ubi_dlNext(find_printer)) {
152 if (memcmp(&(find_printer->printer_hnd), hnd, sizeof(*hnd)) == 0)
154 DEBUG(4,("Found printer handle \n"));
155 /*dump_data(4, hnd->data, sizeof(hnd->data));*/
160 DEBUG(3,("Whoops, Printer handle not found: "));
161 /*dump_data(4, hnd->data, sizeof(hnd->data));*/
165 /****************************************************************************
167 ****************************************************************************/
168 static void clear_handle(POLICY_HND *hnd)
170 memset(hnd->data, 0, POLICY_HND_SIZE);
173 /****************************************************************************
174 close printer index by handle
175 ****************************************************************************/
176 static BOOL close_printer_handle(POLICY_HND *hnd)
178 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
180 if (!OPEN_HANDLE(Printer))
182 DEBUG(3,("Error closing printer handle\n"));
187 Printer->notify.flags=0;
188 Printer->notify.options=0;
189 Printer->notify.localmachine[0]='\0';
190 Printer->notify.printerlocal=0;
191 safe_free(Printer->notify.option);
192 Printer->notify.option=NULL;
196 ubi_dlRemThis(&Printer_list, Printer);
203 /****************************************************************************
204 return the snum of a printer corresponding to an handle
205 ****************************************************************************/
206 static BOOL get_printer_snum(const POLICY_HND *hnd, int *number)
208 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
210 if (!OPEN_HANDLE(Printer)) {
211 DEBUG(3,("Error getting printer - take a nap quickly !\n"));
215 switch (Printer->printer_type) {
216 case PRINTER_HANDLE_IS_PRINTER:
217 DEBUG(4,("short name:%s\n", Printer->dev.printername));
218 *number = print_queue_snum(Printer->dev.printername);
219 return (*number != -1);
220 case PRINTER_HANDLE_IS_PRINTSERVER:
229 /****************************************************************************
230 find first available printer slot. creates a printer handle for you.
231 ****************************************************************************/
232 static BOOL open_printer_hnd(POLICY_HND *hnd)
234 Printer_entry *new_printer;
236 if((new_printer=(Printer_entry *)malloc(sizeof(Printer_entry))) == NULL)
239 ZERO_STRUCTP(new_printer);
241 new_printer->open = True;
242 new_printer->notify.option=NULL;
244 memcpy(&(new_printer->printer_hnd), hnd, sizeof(*hnd));
246 ubi_dlAddHead( &Printer_list, (ubi_dlNode *)new_printer);
251 /****************************************************************************
252 set printer handle type.
253 ****************************************************************************/
254 static BOOL set_printer_hnd_accesstype(POLICY_HND *hnd, uint32 access_required)
256 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
258 if (!OPEN_HANDLE(Printer)) {
259 DEBUG(4,("Error setting printer type=%x", access_required));
263 DEBUG(4,("Setting printer access=%x\n", access_required));
264 Printer->access = access_required;
268 /****************************************************************************
269 set printer handle type.
270 check if it's \\server or \\server\printer
271 ****************************************************************************/
272 static BOOL set_printer_hnd_printertype(POLICY_HND *hnd, char *printername)
274 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
276 if (!OPEN_HANDLE(Printer)) {
277 DEBUGADD(4,("Error setting printer name %s", printername));
281 DEBUG(3,("Setting printer type=%s\n", printername));
283 if ( strlen(printername) < 3 ) {
284 DEBUGADD(4,("A print server must have at least 1 char ! %s\n", printername));
288 /* it's a print server */
289 if (!strchr(printername+2, '\\')) {
290 DEBUGADD(4,("Printer is a print server\n"));
291 Printer->printer_type = PRINTER_HANDLE_IS_PRINTSERVER;
296 DEBUGADD(4,("Printer is a printer\n"));
297 Printer->printer_type = PRINTER_HANDLE_IS_PRINTER;
304 /****************************************************************************
305 set printer handle printername.
306 ****************************************************************************/
307 static BOOL set_printer_hnd_printername(POLICY_HND *hnd, char *printername)
309 Printer_entry *Printer = find_printer_index_by_hnd(hnd);
310 NT_PRINTER_INFO_LEVEL printer;
312 int n_services=lp_numservices();
316 if (!OPEN_HANDLE(Printer)) {
317 DEBUG(0,("Error setting printer name=%s\n", printername));
321 DEBUG(4,("Setting printer name=%s (len=%d)\n", printername, strlen(printername)));
323 if (Printer->printer_type==PRINTER_HANDLE_IS_PRINTSERVER) {
324 ZERO_STRUCT(Printer->dev.printerservername);
325 strncpy(Printer->dev.printerservername, printername, strlen(printername));
329 if (Printer->printer_type!=PRINTER_HANDLE_IS_PRINTER)
332 aprinter=strchr(printername+2, '\\');
335 DEBUGADD(5,("searching for [%s] (len=%d)\n", aprinter, strlen(aprinter)));
338 * store the Samba share name in it
339 * in back we have the long printer name
340 * need to iterate all the snum and do a
341 * get_a_printer each time to find the printer
342 * faster to do it here than later.
345 for (snum=0;snum<n_services && found==False;snum++) {
347 if ( !(lp_snum_ok(snum) && lp_print_ok(snum) ) )
350 DEBUGADD(5,("share:%s\n",lp_servicename(snum)));
352 if (get_a_printer(&printer, 2, lp_servicename(snum))!=0)
355 DEBUG(10,("set_printer_hnd_printername: printername [%s], aprinter [%s]\n",
356 printer.info_2->printername, aprinter ));
358 if ( strlen(printer.info_2->printername) != strlen(aprinter) ) {
359 free_a_printer(printer, 2);
363 if ( strncasecmp(printer.info_2->printername, aprinter, strlen(aprinter))) {
364 free_a_printer(printer, 2);
372 * if we haven't found a printer with the given printername
373 * then it can be a share name as you can open both \\server\printer and
378 * we still check if the printer description file exists as NT won't be happy
379 * if we reply OK in the openprinter call and can't reply in the subsequent RPC calls
383 DEBUGADD(5,("Printer not found, checking for share now\n"));
385 for (snum=0;snum<n_services && found==False;snum++) {
387 if ( !(lp_snum_ok(snum) && lp_print_ok(snum) ) )
390 DEBUGADD(5,("share:%s\n",lp_servicename(snum)));
392 if (get_a_printer(&printer, 2, lp_servicename(snum))!=0)
395 DEBUG(10,("set_printer_hnd_printername: printername [%s], aprinter [%s]\n",
396 printer.info_2->printername, aprinter ));
398 if ( strlen(lp_servicename(snum)) != strlen(aprinter) ) {
399 free_a_printer(printer, 2);
403 if ( strncasecmp(lp_servicename(snum), aprinter, strlen(aprinter))) {
404 free_a_printer(printer, 2);
413 DEBUGADD(4,("Printer not found\n"));
418 DEBUGADD(4,("Printer found: %s -> %s[%x]\n",printer.info_2->printername, lp_servicename(snum),snum));
419 ZERO_STRUCT(Printer->dev.printername);
420 strncpy(Printer->dev.printername, lp_servicename(snum), strlen(lp_servicename(snum)));
421 free_a_printer(printer, 2);
426 /********************************************************************
427 Return True is the handle is a print server.
428 ********************************************************************/
429 static BOOL handle_is_printserver(const POLICY_HND *handle)
431 Printer_entry *Printer=find_printer_index_by_hnd(handle);
433 if (!OPEN_HANDLE(Printer))
436 if (Printer->printer_type != PRINTER_HANDLE_IS_PRINTSERVER)
442 /****************************************************************************
443 allocate more memory for a BUFFER.
444 ****************************************************************************/
445 static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size)
453 /* damn, I'm doing the reverse operation of prs_grow() :) */
454 if (buffer_size < prs_data_size(ps))
457 extra_space = buffer_size - prs_data_size(ps);
460 * save the offset and move to the end of the buffer
461 * prs_grow() checks the extra_space against the offset
463 old_offset=prs_offset(ps);
464 prs_set_offset(ps, prs_data_size(ps));
466 if (!prs_grow(ps, extra_space))
469 prs_set_offset(ps, old_offset);
471 buffer->string_at_end=prs_data_size(ps);
476 /********************************************************************
477 * spoolss_open_printer
479 * called from the spoolss dispatcher
480 ********************************************************************/
481 uint32 _spoolss_open_printer_ex( const UNISTR2 *printername,
482 const PRINTER_DEFAULT *printer_default,
483 uint32 user_switch, SPOOL_USER_CTR user_ctr,
488 clear_handle(handle);
490 if (printername == NULL)
491 return ERROR_INVALID_PRINTER_NAME;
493 /* some sanity check because you can open a printer or a print server */
494 /* aka: \\server\printer or \\server */
495 unistr2_to_ascii(name, printername, sizeof(name)-1);
497 DEBUGADD(3,("checking name: %s\n",name));
499 create_printer_hnd(handle);
501 open_printer_hnd(handle);
503 if (!set_printer_hnd_printertype(handle, name)) {
504 close_printer_handle(handle);
505 return ERROR_INVALID_PRINTER_NAME;
508 if (!set_printer_hnd_printername(handle, name)) {
509 close_printer_handle(handle);
510 return ERROR_INVALID_PRINTER_NAME;
514 if (printer_default->datatype_ptr != NULL)
516 unistr2_to_ascii(datatype, printer_default->datatype, sizeof(datatype)-1);
517 set_printer_hnd_datatype(handle, datatype);
520 set_printer_hnd_datatype(handle, "");
523 if (!set_printer_hnd_accesstype(handle, printer_default->access_required)) {
524 close_printer_handle(handle);
525 return ERROR_ACCESS_DENIED;
528 return NT_STATUS_NO_PROBLEMO;
531 /****************************************************************************
532 ****************************************************************************/
533 static BOOL convert_printer_info(const SPOOL_PRINTER_INFO_LEVEL *uni,
534 NT_PRINTER_INFO_LEVEL *printer, uint32 level)
538 uni_2_asc_printer_info_2(uni->info_2, &(printer->info_2));
547 static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL *uni,
548 NT_PRINTER_DRIVER_INFO_LEVEL *printer, uint32 level)
552 printer->info_3=NULL;
553 uni_2_asc_printer_driver_3(uni->info_3, &(printer->info_3));
562 static BOOL convert_devicemode(DEVICEMODE devmode, NT_DEVICEMODE *nt_devmode)
564 unistr_to_ascii(nt_devmode->devicename, (char *)devmode.devicename.buffer, 31);
565 unistr_to_ascii(nt_devmode->formname, (char *)devmode.formname.buffer, 31);
567 nt_devmode->specversion=devmode.specversion;
568 nt_devmode->driverversion=devmode.driverversion;
569 nt_devmode->size=devmode.size;
570 nt_devmode->driverextra=devmode.driverextra;
571 nt_devmode->fields=devmode.fields;
572 nt_devmode->orientation=devmode.orientation;
573 nt_devmode->papersize=devmode.papersize;
574 nt_devmode->paperlength=devmode.paperlength;
575 nt_devmode->paperwidth=devmode.paperwidth;
576 nt_devmode->scale=devmode.scale;
577 nt_devmode->copies=devmode.copies;
578 nt_devmode->defaultsource=devmode.defaultsource;
579 nt_devmode->printquality=devmode.printquality;
580 nt_devmode->color=devmode.color;
581 nt_devmode->duplex=devmode.duplex;
582 nt_devmode->yresolution=devmode.yresolution;
583 nt_devmode->ttoption=devmode.ttoption;
584 nt_devmode->collate=devmode.collate;
586 nt_devmode->logpixels=devmode.logpixels;
587 nt_devmode->bitsperpel=devmode.bitsperpel;
588 nt_devmode->pelswidth=devmode.pelswidth;
589 nt_devmode->pelsheight=devmode.pelsheight;
590 nt_devmode->displayflags=devmode.displayflags;
591 nt_devmode->displayfrequency=devmode.displayfrequency;
592 nt_devmode->icmmethod=devmode.icmmethod;
593 nt_devmode->icmintent=devmode.icmintent;
594 nt_devmode->mediatype=devmode.mediatype;
595 nt_devmode->dithertype=devmode.dithertype;
596 nt_devmode->reserved1=devmode.reserved1;
597 nt_devmode->reserved2=devmode.reserved2;
598 nt_devmode->panningwidth=devmode.panningwidth;
599 nt_devmode->panningheight=devmode.panningheight;
601 if (nt_devmode->driverextra != 0)
603 /* if we had a previous private delete it and make a new one */
604 if (nt_devmode->private != NULL)
605 free(nt_devmode->private);
606 if((nt_devmode->private=(uint8 *)malloc(nt_devmode->driverextra * sizeof(uint8))) == NULL)
608 memcpy(nt_devmode->private, devmode.private, nt_devmode->driverextra);
614 /********************************************************************
615 * api_spoolss_closeprinter
616 ********************************************************************/
617 uint32 _spoolss_closeprinter(POLICY_HND *handle)
619 if (!close_printer_handle(handle))
620 return ERROR_INVALID_HANDLE;
622 return NT_STATUS_NO_PROBLEMO;
625 /********************************************************************
626 GetPrinterData on a printer server Handle.
627 ********************************************************************/
628 static BOOL getprinterdata_printer_server(fstring value, uint32 *type, uint8 **data, uint32 *needed, uint32 in_size)
632 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
634 if (!strcmp(value, "BeepEnabled"))
637 if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL)
639 SIVAL(*data, 0, 0x01);
644 if (!strcmp(value, "EventLog"))
647 if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL)
649 SIVAL(*data, 0, 0x1B);
654 if (!strcmp(value, "NetPopup"))
657 if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL)
659 SIVAL(*data, 0, 0x01);
664 if (!strcmp(value, "MajorVersion"))
667 if((*data = (uint8 *)malloc( 4*sizeof(uint8) )) == NULL)
669 SIVAL(*data, 0, 0x02);
674 if (!strcmp(value, "DefaultSpoolDirectory"))
676 pstring string="You are using a Samba server";
678 *needed = 2*(strlen(string)+1);
679 if((*data = (uint8 *)malloc( ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL)
681 memset(*data, 0, (*needed > in_size) ? *needed:in_size);
683 /* it's done by hand ready to go on the wire */
684 for (i=0; i<strlen(string); i++)
686 (*data)[2*i]=string[i];
692 if (!strcmp(value, "Architecture"))
694 pstring string="Windows NT x86";
696 *needed = 2*(strlen(string)+1);
697 if((*data = (uint8 *)malloc( ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL)
699 memset(*data, 0, (*needed > in_size) ? *needed:in_size);
700 for (i=0; i<strlen(string); i++)
702 (*data)[2*i]=string[i];
711 /********************************************************************
712 GetPrinterData on a printer Handle.
713 ********************************************************************/
714 static BOOL getprinterdata_printer(const POLICY_HND *handle,
715 fstring value, uint32 *type,
716 uint8 **data, uint32 *needed, uint32 in_size )
718 NT_PRINTER_INFO_LEVEL printer;
722 Printer_entry *Printer = find_printer_index_by_hnd(handle);
724 DEBUG(5,("getprinterdata_printer\n"));
726 if (!OPEN_HANDLE(Printer))
729 if(!get_printer_snum(handle, &snum))
732 if(get_a_printer(&printer, 2, lp_servicename(snum)) != 0)
735 if (!get_specific_param(printer, 2, value, &idata, type, &len)) {
736 free_a_printer(printer, 2);
740 DEBUG(5,("getprinterdata_printer:allocating %d\n", in_size));
742 if((*data = (uint8 *)malloc( in_size *sizeof(uint8) )) == NULL) {
743 free_a_printer(printer, 2);
747 memset(*data, 0, in_size *sizeof(uint8));
748 /* copy the min(in_size, len) */
749 memcpy(*data, idata, (len>in_size)?in_size:len *sizeof(uint8));
753 DEBUG(5,("getprinterdata_printer:copy done\n"));
755 free_a_printer(printer, 2);
761 /********************************************************************
762 * spoolss_getprinterdata
763 ********************************************************************/
764 uint32 _spoolss_getprinterdata(const POLICY_HND *handle, UNISTR2 *valuename,
773 Printer_entry *Printer = find_printer_index_by_hnd(handle);
776 * Reminder: when it's a string, the length is in BYTES
777 * even if UNICODE is negociated.
784 /* in case of problem, return some default values */
788 DEBUG(4,("_spoolss_getprinterdata\n"));
790 if (!OPEN_HANDLE(Printer)) {
791 if((*data=(uint8 *)malloc(4*sizeof(uint8))) == NULL)
792 return ERROR_NOT_ENOUGH_MEMORY;
793 return ERROR_INVALID_HANDLE;
796 unistr2_to_ascii(value, valuename, sizeof(value)-1);
798 if (handle_is_printserver(handle))
799 found=getprinterdata_printer_server(value, type, data, needed, *out_size);
801 found=getprinterdata_printer(handle, value, type, data, needed, *out_size);
804 DEBUG(5, ("value not found, allocating %d\n", *out_size));
805 /* reply this param doesn't exist */
806 if((*data=(uint8 *)malloc(*out_size*sizeof(uint8))) == NULL)
807 return ERROR_NOT_ENOUGH_MEMORY;
808 memset(*data, 0x0, *out_size*sizeof(uint8));
809 return ERROR_INVALID_PARAMETER;
812 if (*needed > *out_size)
813 return ERROR_INSUFFICIENT_BUFFER;
815 return NT_STATUS_NO_PROBLEMO;
818 /********************************************************************
820 * ReplyFindFirstPrinterChangeNotifyEx
822 * jfmxxxx: before replying OK: status=0
823 * should do a rpc call to the workstation asking ReplyOpenPrinter
824 * have to code it, later.
826 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
827 * called from api_spoolss_rffpcnex
828 ********************************************************************/
829 uint32 _spoolss_rffpcnex(const POLICY_HND *handle, uint32 flags, uint32 options,
830 const UNISTR2 *localmachine, uint32 printerlocal,
831 SPOOL_NOTIFY_OPTION *option)
833 /* store the notify value in the printer struct */
835 Printer_entry *Printer=find_printer_index_by_hnd(handle);
837 if (!OPEN_HANDLE(Printer))
838 return ERROR_INVALID_HANDLE;
840 Printer->notify.flags=flags;
841 Printer->notify.options=options;
842 Printer->notify.printerlocal=printerlocal;
843 Printer->notify.option=option;
844 unistr2_to_ascii(Printer->notify.localmachine, localmachine, sizeof(Printer->notify.localmachine)-1);
846 return NT_STATUS_NO_PROBLEMO;
849 /*******************************************************************
850 * fill a notify_info_data with the servername
851 ********************************************************************/
852 static void spoolss_notify_server_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
856 snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname);
858 data->notify_data.data.length=strlen(temp_name);
859 ascii_to_unistr((char *)data->notify_data.data.string, temp_name, sizeof(data->notify_data.data.string)-1);
862 /*******************************************************************
863 * fill a notify_info_data with the servicename
864 * jfmxxxx: it's incorrect should be long_printername
865 ********************************************************************/
866 static void spoolss_notify_printer_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
869 data->notify_data.data.length=strlen(lp_servicename(snum));
870 ascii_to_unistr(data->notify_data.data.string, lp_servicename(snum), sizeof(data->notify_data.data.string)-1);
872 data->notify_data.data.length=strlen(printer->info_2->printername);
873 ascii_to_unistr((char *)data->notify_data.data.string,
874 printer->info_2->printername,
875 sizeof(data->notify_data.data.string)-1);
878 /*******************************************************************
879 * fill a notify_info_data with the servicename
880 ********************************************************************/
881 static void spoolss_notify_share_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
883 data->notify_data.data.length=strlen(lp_servicename(snum));
884 ascii_to_unistr((char *)data->notify_data.data.string,
885 lp_servicename(snum),
886 sizeof(data->notify_data.data.string)-1);
889 /*******************************************************************
890 * fill a notify_info_data with the port name
891 ********************************************************************/
892 static void spoolss_notify_port_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
894 /* even if it's strange, that's consistant in all the code */
896 data->notify_data.data.length=strlen(lp_servicename(snum));
897 ascii_to_unistr((char *)data->notify_data.data.string,
898 lp_servicename(snum),
899 sizeof(data->notify_data.data.string)-1);
902 /*******************************************************************
903 * fill a notify_info_data with the printername
904 * jfmxxxx: it's incorrect, should be lp_printerdrivername()
905 * but it doesn't exist, have to see what to do
906 ********************************************************************/
907 static void spoolss_notify_driver_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
909 data->notify_data.data.length=strlen(printer->info_2->drivername);
910 ascii_to_unistr((char *)data->notify_data.data.string,
911 printer->info_2->drivername,
912 sizeof(data->notify_data.data.string)-1);
915 /*******************************************************************
916 * fill a notify_info_data with the comment
917 ********************************************************************/
918 static void spoolss_notify_comment(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
920 data->notify_data.data.length=strlen(lp_comment(snum));
921 ascii_to_unistr((char *)data->notify_data.data.string,
923 sizeof(data->notify_data.data.string)-1);
926 /*******************************************************************
927 * fill a notify_info_data with the comment
928 * jfm:xxxx incorrect, have to create a new smb.conf option
929 * location = "Room 1, floor 2, building 3"
930 ********************************************************************/
931 static void spoolss_notify_location(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
933 data->notify_data.data.length=strlen(printer->info_2->location);
934 ascii_to_unistr((char *)data->notify_data.data.string,
935 printer->info_2->location,
936 sizeof(data->notify_data.data.string)-1);
939 /*******************************************************************
940 * fill a notify_info_data with the device mode
941 * jfm:xxxx don't to it for know but that's a real problem !!!
942 ********************************************************************/
943 static void spoolss_notify_devmode(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
947 /*******************************************************************
948 * fill a notify_info_data with the separator file name
949 * jfm:xxxx just return no file could add an option to smb.conf
950 * separator file = "separator.txt"
951 ********************************************************************/
952 static void spoolss_notify_sepfile(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
954 data->notify_data.data.length=strlen(printer->info_2->sepfile);
955 ascii_to_unistr((char *)data->notify_data.data.string,
956 printer->info_2->sepfile,
957 sizeof(data->notify_data.data.string)-1);
960 /*******************************************************************
961 * fill a notify_info_data with the print processor
962 * jfm:xxxx return always winprint to indicate we don't do anything to it
963 ********************************************************************/
964 static void spoolss_notify_print_processor(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
966 data->notify_data.data.length=strlen(printer->info_2->printprocessor);
967 ascii_to_unistr((char *)data->notify_data.data.string,
968 printer->info_2->printprocessor,
969 sizeof(data->notify_data.data.string)-1);
972 /*******************************************************************
973 * fill a notify_info_data with the print processor options
974 * jfm:xxxx send an empty string
975 ********************************************************************/
976 static void spoolss_notify_parameters(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
978 data->notify_data.data.length=strlen(printer->info_2->parameters);
979 ascii_to_unistr((char *)data->notify_data.data.string,
980 printer->info_2->parameters,
981 sizeof(data->notify_data.data.string)-1);
984 /*******************************************************************
985 * fill a notify_info_data with the data type
986 * jfm:xxxx always send RAW as data type
987 ********************************************************************/
988 static void spoolss_notify_datatype(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
990 data->notify_data.data.length=strlen(printer->info_2->datatype);
991 ascii_to_unistr((char *)data->notify_data.data.string,
992 printer->info_2->datatype,
993 sizeof(data->notify_data.data.string)-1);
996 /*******************************************************************
997 * fill a notify_info_data with the security descriptor
998 * jfm:xxxx send an null pointer to say no security desc
999 * have to implement security before !
1000 ********************************************************************/
1001 static void spoolss_notify_security_desc(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1003 data->notify_data.data.length=0;
1004 data->notify_data.data.string[0]=0x00;
1007 /*******************************************************************
1008 * fill a notify_info_data with the attributes
1009 * jfm:xxxx a samba printer is always shared
1010 ********************************************************************/
1011 static void spoolss_notify_attributes(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1013 data->notify_data.value[0] = PRINTER_ATTRIBUTE_SHARED \
1014 | PRINTER_ATTRIBUTE_NETWORK \
1015 | PRINTER_ATTRIBUTE_RAW_ONLY ;
1018 /*******************************************************************
1019 * fill a notify_info_data with the priority
1020 ********************************************************************/
1021 static void spoolss_notify_priority(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1023 data->notify_data.value[0] = printer->info_2->priority;
1026 /*******************************************************************
1027 * fill a notify_info_data with the default priority
1028 ********************************************************************/
1029 static void spoolss_notify_default_priority(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1031 data->notify_data.value[0] = printer->info_2->default_priority;
1034 /*******************************************************************
1035 * fill a notify_info_data with the start time
1036 ********************************************************************/
1037 static void spoolss_notify_start_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1039 data->notify_data.value[0] = printer->info_2->starttime;
1042 /*******************************************************************
1043 * fill a notify_info_data with the until time
1044 ********************************************************************/
1045 static void spoolss_notify_until_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1047 data->notify_data.value[0] = printer->info_2->untiltime;
1050 /*******************************************************************
1051 * fill a notify_info_data with the status
1052 ********************************************************************/
1053 static void spoolss_notify_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1056 print_queue_struct *q=NULL;
1057 print_status_struct status;
1059 memset(&status, 0, sizeof(status));
1060 count = print_queue_status(snum, &q, &status);
1061 data->notify_data.value[0]=(uint32) status.status;
1065 /*******************************************************************
1066 * fill a notify_info_data with the number of jobs queued
1067 ********************************************************************/
1068 static void spoolss_notify_cjobs(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1070 print_queue_struct *q=NULL;
1071 print_status_struct status;
1073 memset(&status, 0, sizeof(status));
1074 data->notify_data.value[0] = print_queue_status(snum, &q, &status);
1078 /*******************************************************************
1079 * fill a notify_info_data with the average ppm
1080 ********************************************************************/
1081 static void spoolss_notify_average_ppm(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1083 /* always respond 8 pages per minutes */
1084 /* a little hard ! */
1085 data->notify_data.value[0] = printer->info_2->averageppm;
1088 /*******************************************************************
1089 * fill a notify_info_data with
1090 ********************************************************************/
1091 static void spoolss_notify_username(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1093 data->notify_data.data.length=strlen(queue->user);
1094 ascii_to_unistr((char *)data->notify_data.data.string, queue->user, sizeof(data->notify_data.data.string)-1);
1097 /*******************************************************************
1098 * fill a notify_info_data with
1099 ********************************************************************/
1100 static void spoolss_notify_job_status(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1102 data->notify_data.value[0]=nt_printj_status(queue->status);
1105 /*******************************************************************
1106 * fill a notify_info_data with
1107 ********************************************************************/
1108 static void spoolss_notify_job_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1110 data->notify_data.data.length=strlen(queue->file);
1111 ascii_to_unistr((char *)data->notify_data.data.string, queue->file, sizeof(data->notify_data.data.string)-1);
1114 /*******************************************************************
1115 * fill a notify_info_data with
1116 ********************************************************************/
1117 static void spoolss_notify_job_status_string(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1119 char *p = "unknown";
1120 switch (queue->status) {
1134 data->notify_data.data.length=strlen(p);
1135 ascii_to_unistr((char *)data->notify_data.data.string, p, sizeof(data->notify_data.data.string)-1);
1138 /*******************************************************************
1139 * fill a notify_info_data with
1140 ********************************************************************/
1141 static void spoolss_notify_job_time(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1143 data->notify_data.value[0]=0x0;
1146 /*******************************************************************
1147 * fill a notify_info_data with
1148 ********************************************************************/
1149 static void spoolss_notify_job_size(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1151 data->notify_data.value[0]=queue->size;
1154 /*******************************************************************
1155 * fill a notify_info_data with
1156 ********************************************************************/
1157 static void spoolss_notify_job_position(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue, NT_PRINTER_INFO_LEVEL *printer)
1159 data->notify_data.value[0]=queue->job;
1164 struct s_notify_info_data_table notify_info_data_table[] =
1166 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SERVER_NAME, "PRINTER_NOTIFY_SERVER_NAME", POINTER, spoolss_notify_server_name },
1167 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINTER_NAME, "PRINTER_NOTIFY_PRINTER_NAME", POINTER, spoolss_notify_printer_name },
1168 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SHARE_NAME, "PRINTER_NOTIFY_SHARE_NAME", POINTER, spoolss_notify_share_name },
1169 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PORT_NAME, "PRINTER_NOTIFY_PORT_NAME", POINTER, spoolss_notify_port_name },
1170 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DRIVER_NAME, "PRINTER_NOTIFY_DRIVER_NAME", POINTER, spoolss_notify_driver_name },
1171 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_COMMENT, "PRINTER_NOTIFY_COMMENT", POINTER, spoolss_notify_comment },
1172 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_LOCATION, "PRINTER_NOTIFY_LOCATION", POINTER, spoolss_notify_location },
1173 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DEVMODE, "PRINTER_NOTIFY_DEVMODE", POINTER, spoolss_notify_devmode },
1174 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SEPFILE, "PRINTER_NOTIFY_SEPFILE", POINTER, spoolss_notify_sepfile },
1175 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINT_PROCESSOR, "PRINTER_NOTIFY_PRINT_PROCESSOR", POINTER, spoolss_notify_print_processor },
1176 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PARAMETERS, "PRINTER_NOTIFY_PARAMETERS", POINTER, spoolss_notify_parameters },
1177 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DATATYPE, "PRINTER_NOTIFY_DATATYPE", POINTER, spoolss_notify_datatype },
1178 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_SECURITY_DESCRIPTOR", POINTER, spoolss_notify_security_desc },
1179 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_ATTRIBUTES, "PRINTER_NOTIFY_ATTRIBUTES", ONE_VALUE, spoolss_notify_attributes },
1180 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRIORITY, "PRINTER_NOTIFY_PRIORITY", ONE_VALUE, spoolss_notify_priority },
1181 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DEFAULT_PRIORITY, "PRINTER_NOTIFY_DEFAULT_PRIORITY", ONE_VALUE, spoolss_notify_default_priority },
1182 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_START_TIME, "PRINTER_NOTIFY_START_TIME", ONE_VALUE, spoolss_notify_start_time },
1183 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_UNTIL_TIME, "PRINTER_NOTIFY_UNTIL_TIME", ONE_VALUE, spoolss_notify_until_time },
1184 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_STATUS, "PRINTER_NOTIFY_STATUS", ONE_VALUE, spoolss_notify_status },
1185 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_STATUS_STRING, "PRINTER_NOTIFY_STATUS_STRING", POINTER, NULL },
1186 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_CJOBS, "PRINTER_NOTIFY_CJOBS", ONE_VALUE, spoolss_notify_cjobs },
1187 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_AVERAGE_PPM, "PRINTER_NOTIFY_AVERAGE_PPM", ONE_VALUE, spoolss_notify_average_ppm },
1188 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_PAGES, "PRINTER_NOTIFY_TOTAL_PAGES", POINTER, NULL },
1189 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PAGES_PRINTED, "PRINTER_NOTIFY_PAGES_PRINTED", POINTER, NULL },
1190 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_BYTES, "PRINTER_NOTIFY_TOTAL_BYTES", POINTER, NULL },
1191 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_BYTES_PRINTED, "PRINTER_NOTIFY_BYTES_PRINTED", POINTER, NULL },
1192 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINTER_NAME, "JOB_NOTIFY_PRINTER_NAME", POINTER, spoolss_notify_printer_name },
1193 { JOB_NOTIFY_TYPE, JOB_NOTIFY_MACHINE_NAME, "JOB_NOTIFY_MACHINE_NAME", POINTER, spoolss_notify_server_name },
1194 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PORT_NAME, "JOB_NOTIFY_PORT_NAME", POINTER, spoolss_notify_port_name },
1195 { JOB_NOTIFY_TYPE, JOB_NOTIFY_USER_NAME, "JOB_NOTIFY_USER_NAME", POINTER, spoolss_notify_username },
1196 { JOB_NOTIFY_TYPE, JOB_NOTIFY_NOTIFY_NAME, "JOB_NOTIFY_NOTIFY_NAME", POINTER, spoolss_notify_username },
1197 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DATATYPE, "JOB_NOTIFY_DATATYPE", POINTER, spoolss_notify_datatype },
1198 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINT_PROCESSOR, "JOB_NOTIFY_PRINT_PROCESSOR", POINTER, spoolss_notify_print_processor },
1199 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PARAMETERS, "JOB_NOTIFY_PARAMETERS", POINTER, spoolss_notify_parameters },
1200 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DRIVER_NAME, "JOB_NOTIFY_DRIVER_NAME", POINTER, spoolss_notify_driver_name },
1201 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DEVMODE, "JOB_NOTIFY_DEVMODE", POINTER, spoolss_notify_devmode },
1202 { JOB_NOTIFY_TYPE, JOB_NOTIFY_STATUS, "JOB_NOTIFY_STATUS", ONE_VALUE, spoolss_notify_job_status },
1203 { JOB_NOTIFY_TYPE, JOB_NOTIFY_STATUS_STRING, "JOB_NOTIFY_STATUS_STRING", POINTER, spoolss_notify_job_status_string },
1204 { JOB_NOTIFY_TYPE, JOB_NOTIFY_SECURITY_DESCRIPTOR, "JOB_NOTIFY_SECURITY_DESCRIPTOR", POINTER, NULL },
1205 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DOCUMENT, "JOB_NOTIFY_DOCUMENT", POINTER, spoolss_notify_job_name },
1206 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRIORITY, "JOB_NOTIFY_PRIORITY", ONE_VALUE, spoolss_notify_priority },
1207 { JOB_NOTIFY_TYPE, JOB_NOTIFY_POSITION, "JOB_NOTIFY_POSITION", ONE_VALUE, spoolss_notify_job_position },
1208 { JOB_NOTIFY_TYPE, JOB_NOTIFY_SUBMITTED, "JOB_NOTIFY_SUBMITTED", POINTER, NULL },
1209 { JOB_NOTIFY_TYPE, JOB_NOTIFY_START_TIME, "JOB_NOTIFY_START_TIME", ONE_VALUE, spoolss_notify_start_time },
1210 { JOB_NOTIFY_TYPE, JOB_NOTIFY_UNTIL_TIME, "JOB_NOTIFY_UNTIL_TIME", ONE_VALUE, spoolss_notify_until_time },
1211 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TIME, "JOB_NOTIFY_TIME", ONE_VALUE, spoolss_notify_job_time },
1212 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_PAGES, "JOB_NOTIFY_TOTAL_PAGES", ONE_VALUE, NULL },
1213 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PAGES_PRINTED, "JOB_NOTIFY_PAGES_PRINTED", ONE_VALUE, NULL },
1214 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_BYTES, "JOB_NOTIFY_TOTAL_BYTES", ONE_VALUE, spoolss_notify_job_size },
1215 { JOB_NOTIFY_TYPE, JOB_NOTIFY_BYTES_PRINTED, "JOB_NOTIFY_BYTES_PRINTED", ONE_VALUE, NULL },
1216 { END, END, "", END, NULL }
1219 /*******************************************************************
1220 return the size of info_data structure
1221 ********************************************************************/
1222 static uint32 size_of_notify_info_data(uint16 type, uint16 field)
1226 while (notify_info_data_table[i].type != END)
1228 if ( (notify_info_data_table[i].type == type ) &&
1229 (notify_info_data_table[i].field == field ) )
1231 return (notify_info_data_table[i].size);
1239 /*******************************************************************
1240 return the type of notify_info_data
1241 ********************************************************************/
1242 static BOOL type_of_notify_info_data(uint16 type, uint16 field)
1246 while (notify_info_data_table[i].type != END)
1248 if ( (notify_info_data_table[i].type == type ) &&
1249 (notify_info_data_table[i].field == field ) )
1251 if (notify_info_data_table[i].size == POINTER)
1266 /****************************************************************************
1267 ****************************************************************************/
1268 static int search_notify(uint16 type, uint16 field, int *value)
1273 for (j=0, found=False; found==False && notify_info_data_table[j].type != END ; j++)
1275 if ( (notify_info_data_table[j].type == type ) &&
1276 (notify_info_data_table[j].field == field ) )
1281 if ( found && (notify_info_data_table[j].fn != NULL) )
1287 /****************************************************************************
1288 ****************************************************************************/
1289 static void construct_info_data(SPOOL_NOTIFY_INFO_DATA *info_data, uint16 type, uint16 field, int id)
1291 info_data->type = type;
1292 info_data->field = field;
1293 info_data->reserved = 0;
1295 info_data->size = size_of_notify_info_data(type, field);
1296 info_data->enc_type = type_of_notify_info_data(type, field);
1300 /*******************************************************************
1302 * fill a notify_info struct with info asked
1304 ********************************************************************/
1305 static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int snum, SPOOL_NOTIFY_OPTION_TYPE *option_type, uint32 id)
1311 SPOOL_NOTIFY_INFO_DATA *current_data;
1312 NT_PRINTER_INFO_LEVEL printer;
1313 print_queue_struct *queue=NULL;
1315 DEBUG(4,("construct_notify_printer_info\n"));
1317 type=option_type->type;
1319 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
1320 (option_type->type==PRINTER_NOTIFY_TYPE?"PRINTER_NOTIFY_TYPE":"JOB_NOTIFY_TYPE"),
1321 option_type->count, lp_servicename(snum)));
1323 if (get_a_printer(&printer, 2, lp_servicename(snum))!=0)
1328 for(field_num=0; field_num<option_type->count; field_num++)
1330 field = option_type->fields[field_num];
1331 DEBUGADD(4,("notify [%d]: type [%x], field [%x]\n", field_num, type, field));
1333 if (!search_notify(type, field, &j) )
1336 if((info->data=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) {
1337 free_a_printer(printer, 2);
1340 current_data=&(info->data[info->count]);
1342 construct_info_data(current_data, type, field, id);
1343 notify_info_data_table[j].fn(snum, current_data, queue, &printer);
1348 free_a_printer(printer, 2);
1352 /*******************************************************************
1354 * fill a notify_info struct with info asked
1356 ********************************************************************/
1357 static BOOL construct_notify_jobs_info(print_queue_struct *queue, SPOOL_NOTIFY_INFO *info, int snum, SPOOL_NOTIFY_OPTION_TYPE *option_type, uint32 id)
1363 SPOOL_NOTIFY_INFO_DATA *current_data;
1364 NT_PRINTER_INFO_LEVEL printer;
1366 DEBUG(4,("construct_notify_jobs_info\n"));
1368 type = option_type->type;
1370 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
1371 (option_type->type==PRINTER_NOTIFY_TYPE?"PRINTER_NOTIFY_TYPE":"JOB_NOTIFY_TYPE"),
1372 option_type->count));
1374 if (get_a_printer(&printer, 2, lp_servicename(snum))!=0)
1379 for(field_num=0; field_num<option_type->count; field_num++)
1381 field = option_type->fields[field_num];
1383 if (!search_notify(type, field, &j) )
1386 if((info->data=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) {
1387 free_a_printer(printer, 2);
1391 current_data=&(info->data[info->count]);
1393 construct_info_data(current_data, type, field, id);
1394 notify_info_data_table[j].fn(snum, current_data, queue, &printer);
1398 free_a_printer(printer, 2);
1404 * JFM: The enumeration is not that simple, it's even non obvious.
1406 * let's take an example: I want to monitor the PRINTER SERVER for
1407 * the printer's name and the number of jobs currently queued.
1408 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
1409 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
1411 * I have 3 printers on the back of my server.
1413 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
1416 * 1 printer 1 name 1
1417 * 2 printer 1 cjob 1
1418 * 3 printer 2 name 2
1419 * 4 printer 2 cjob 2
1420 * 5 printer 3 name 3
1421 * 6 printer 3 name 3
1423 * that's the print server case, the printer case is even worse.
1428 /*******************************************************************
1430 * enumerate all printers on the printserver
1431 * fill a notify_info struct with info asked
1433 ********************************************************************/
1434 static uint32 printserver_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info)
1437 Printer_entry *Printer=find_printer_index_by_hnd(hnd);
1438 int n_services=lp_numservices();
1441 SPOOL_NOTIFY_OPTION *option;
1442 SPOOL_NOTIFY_OPTION_TYPE *option_type;
1444 DEBUG(4,("printserver_notify_info\n"));
1446 option=Printer->notify.option;
1452 for (i=0; i<option->count; i++)
1454 option_type=&(option->ctr.type[i]);
1456 if (option_type->type!=PRINTER_NOTIFY_TYPE)
1459 for (snum=0; snum<n_services; snum++)
1460 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
1461 if (construct_notify_printer_info(info, snum, option_type, id))
1466 * Debugging information, don't delete.
1469 DEBUG(1,("dumping the NOTIFY_INFO\n"));
1470 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
1471 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
1473 for (i=0; i<info->count; i++)
1475 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
1476 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
1477 info->data[i].id, info->data[i].size, info->data[i].enc_type));
1481 return NT_STATUS_NO_PROBLEMO;
1484 /*******************************************************************
1486 * fill a notify_info struct with info asked
1488 ********************************************************************/
1489 static uint32 printer_notify_info(const POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info)
1492 Printer_entry *Printer=find_printer_index_by_hnd(hnd);
1495 SPOOL_NOTIFY_OPTION *option;
1496 SPOOL_NOTIFY_OPTION_TYPE *option_type;
1498 print_queue_struct *queue=NULL;
1499 print_status_struct status;
1501 DEBUG(4,("printer_notify_info\n"));
1503 option=Printer->notify.option;
1509 get_printer_snum(hnd, &snum);
1511 for (i=0; i<option->count; i++)
1513 option_type=&(option->ctr.type[i]);
1515 switch ( option_type->type ) {
1516 case PRINTER_NOTIFY_TYPE:
1517 if(construct_notify_printer_info(info, snum, option_type, id))
1521 case JOB_NOTIFY_TYPE:
1522 memset(&status, 0, sizeof(status));
1523 count = print_queue_status(snum, &queue, &status);
1524 for (j=0; j<count; j++)
1525 construct_notify_jobs_info(&(queue[j]), info, snum, option_type, queue[j].job);
1532 * Debugging information, don't delete.
1535 DEBUG(1,("dumping the NOTIFY_INFO\n"));
1536 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
1537 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
1539 for (i=0; i<info->count; i++)
1541 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
1542 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
1543 info->data[i].id, info->data[i].size, info->data[i].enc_type));
1546 return NT_STATUS_NO_PROBLEMO;
1549 /********************************************************************
1551 ********************************************************************/
1552 uint32 _spoolss_rfnpcnex( const POLICY_HND *handle, uint32 change,
1553 SPOOL_NOTIFY_OPTION *option, SPOOL_NOTIFY_INFO *info)
1555 Printer_entry *Printer=find_printer_index_by_hnd(handle);
1557 if (!OPEN_HANDLE(Printer))
1558 return ERROR_INVALID_HANDLE;
1560 DEBUG(4,("Printer type %x\n",Printer->printer_type));
1562 /* jfm: the change value isn't used right now.
1563 * we will honour it when
1564 * a) we'll be able to send notification to the client
1565 * b) we'll have a way to communicate between the spoolss process.
1567 * same thing for option->flags
1568 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
1569 * I don't have a global notification system, I'm sending back all the
1570 * informations even when _NOTHING_ has changed.
1573 /* just discard the SPOOL_NOTIFY_OPTION */
1575 safe_free(option->ctr.type);
1577 switch (Printer->printer_type) {
1578 case PRINTER_HANDLE_IS_PRINTSERVER:
1579 return printserver_notify_info(handle, info);
1581 case PRINTER_HANDLE_IS_PRINTER:
1582 return printer_notify_info(handle, info);
1586 return ERROR_INVALID_HANDLE;
1589 /********************************************************************
1590 * construct_printer_info_0
1591 * fill a printer_info_1 struct
1592 ********************************************************************/
1593 static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, fstring servername)
1597 NT_PRINTER_INFO_LEVEL ntprinter;
1598 counter_printer_0 *session_counter;
1599 uint32 global_counter;
1602 print_queue_struct *queue=NULL;
1603 print_status_struct status;
1605 memset(&status, 0, sizeof(status));
1607 if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) != 0)
1610 count = print_queue_status(snum, &queue, &status);
1612 /* check if we already have a counter for this printer */
1613 session_counter = (counter_printer_0 *)ubi_dlFirst(&counter_list);
1615 for(; session_counter; session_counter = (counter_printer_0 *)ubi_dlNext(session_counter)) {
1616 if (session_counter->snum == snum)
1620 /* it's the first time, add it to the list */
1621 if (session_counter==NULL) {
1622 if((session_counter=(counter_printer_0 *)malloc(sizeof(counter_printer_0))) == NULL)
1624 ZERO_STRUCTP(session_counter);
1625 session_counter->snum=snum;
1626 session_counter->counter=0;
1627 ubi_dlAddHead( &counter_list, (ubi_dlNode *)session_counter);
1631 session_counter->counter++;
1634 * the global_counter should be stored in a TDB as it's common to all the clients
1635 * and should be zeroed on samba startup
1637 global_counter=session_counter->counter;
1639 /* the description and the name are of the form \\server\share */
1640 slprintf(chaine,sizeof(chaine)-1,"\\\\%s\\%s",servername, ntprinter.info_2->printername);
1642 init_unistr(&(printer->printername), chaine);
1644 slprintf(chaine,sizeof(chaine)-1,"\\\\%s", servername);
1645 init_unistr(&(printer->servername), chaine);
1647 printer->cjobs = count;
1648 printer->total_jobs = 0;
1649 printer->total_bytes = 0;
1651 t=gmtime(&ntprinter.info_2->setuptime);
1653 printer->year = t->tm_year+1900;
1654 printer->month = t->tm_mon+1;
1655 printer->dayofweek = t->tm_wday;
1656 printer->day = t->tm_mday;
1657 printer->hour = t->tm_hour;
1658 printer->minute = t->tm_min;
1659 printer->second = t->tm_sec;
1660 printer->milliseconds = 0;
1662 printer->global_counter = global_counter;
1663 printer->total_pages = 0;
1664 printer->major_version = 0x0004; /* NT 4 */
1665 printer->build_version = 0x0565; /* build 1381 */
1666 printer->unknown7 = 0x1;
1667 printer->unknown8 = 0x0;
1668 printer->unknown9 = 0x0;
1669 printer->session_counter = session_counter->counter;
1670 printer->unknown11 = 0x0;
1671 printer->printer_errors = 0x0; /* number of print failure */
1672 printer->unknown13 = 0x0;
1673 printer->unknown14 = 0x1;
1674 printer->unknown15 = 0x024a; /* 586 Pentium ? */
1675 printer->unknown16 = 0x0;
1676 printer->change_id = ntprinter.info_2->changeid; /* ChangeID in milliseconds*/
1677 printer->unknown18 = 0x0;
1678 printer->status = nt_printq_status(status.status);
1679 printer->unknown20 = 0x0;
1680 printer->c_setprinter = ntprinter.info_2->c_setprinter; /* how many times setprinter has been called */
1681 printer->unknown22 = 0x0;
1682 printer->unknown23 = 0x6; /* 6 ???*/
1683 printer->unknown24 = 0; /* unknown 24 to 26 are always 0 */
1684 printer->unknown25 = 0;
1685 printer->unknown26 = 0;
1686 printer->unknown27 = 0;
1687 printer->unknown28 = 0;
1688 printer->unknown29 = 0;
1692 free_a_printer(ntprinter, 2);
1696 /********************************************************************
1697 * construct_printer_info_1
1698 * fill a printer_info_1 struct
1699 ********************************************************************/
1700 static BOOL construct_printer_info_1(fstring server, uint32 flags, PRINTER_INFO_1 *printer, int snum)
1704 NT_PRINTER_INFO_LEVEL ntprinter;
1706 if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) != 0)
1709 printer->flags=flags;
1711 snprintf(chaine,sizeof(chaine)-1,"%s%s,%s,%s",server, ntprinter.info_2->printername,
1712 ntprinter.info_2->drivername, lp_comment(snum));
1714 snprintf(chaine2,sizeof(chaine)-1,"%s%s", server, ntprinter.info_2->printername);
1716 init_unistr(&printer->description, chaine);
1717 init_unistr(&printer->name, chaine2);
1718 init_unistr(&printer->comment, lp_comment(snum));
1720 free_a_printer(ntprinter, 2);
1725 /****************************************************************************
1726 ****************************************************************************/
1727 static BOOL construct_dev_mode(DEVICEMODE *devmode, int snum, char *servername)
1731 NT_PRINTER_INFO_LEVEL printer;
1732 NT_DEVICEMODE *ntdevmode;
1734 DEBUG(7,("construct_dev_mode\n"));
1736 memset(&(devmode->devicename), 0, 2*sizeof(adevice));
1737 memset(&(devmode->formname), 0, 2*sizeof(aform));
1739 DEBUGADD(8,("getting printer characteristics\n"));
1741 get_a_printer(&printer, 2, lp_servicename(snum));
1742 ntdevmode=(printer.info_2)->devmode;
1744 DEBUGADD(8,("loading DEVICEMODE\n"));
1745 snprintf(adevice, sizeof(adevice), "\\\\%s\\%s", global_myname,
1746 printer.info_2->printername);
1747 init_unistr(&(devmode->devicename), adevice);
1749 snprintf(aform, sizeof(aform), ntdevmode->formname);
1750 init_unistr(&(devmode->formname), aform);
1752 devmode->specversion = ntdevmode->specversion;
1753 devmode->driverversion = ntdevmode->driverversion;
1754 devmode->size = ntdevmode->size;
1755 devmode->driverextra = ntdevmode->driverextra;
1756 devmode->fields = ntdevmode->fields;
1758 devmode->orientation = ntdevmode->orientation;
1759 devmode->papersize = ntdevmode->papersize;
1760 devmode->paperlength = ntdevmode->paperlength;
1761 devmode->paperwidth = ntdevmode->paperwidth;
1762 devmode->scale = ntdevmode->scale;
1763 devmode->copies = ntdevmode->copies;
1764 devmode->defaultsource = ntdevmode->defaultsource;
1765 devmode->printquality = ntdevmode->printquality;
1766 devmode->color = ntdevmode->color;
1767 devmode->duplex = ntdevmode->duplex;
1768 devmode->yresolution = ntdevmode->yresolution;
1769 devmode->ttoption = ntdevmode->ttoption;
1770 devmode->collate = ntdevmode->collate;
1771 devmode->icmmethod = ntdevmode->icmmethod;
1772 devmode->icmintent = ntdevmode->icmintent;
1773 devmode->mediatype = ntdevmode->mediatype;
1774 devmode->dithertype = ntdevmode->dithertype;
1776 if (ntdevmode->private != NULL)
1778 if((devmode->private=(uint8 *)malloc(devmode->driverextra*sizeof(uint8))) == NULL) {
1779 free_a_printer(printer, 2);
1782 memcpy(devmode->private, ntdevmode->private, devmode->driverextra);
1785 free_a_printer(printer, 2);
1790 /********************************************************************
1791 * construct_printer_info_2
1792 * fill a printer_info_2 struct
1793 ********************************************************************/
1794 static BOOL construct_printer_info_2(fstring servername, PRINTER_INFO_2 *printer, int snum)
1800 DEVICEMODE *devmode;
1801 NT_PRINTER_INFO_LEVEL ntprinter;
1803 print_queue_struct *queue=NULL;
1804 print_status_struct status;
1805 memset(&status, 0, sizeof(status));
1807 if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0 )
1810 memset(&status, 0, sizeof(status));
1811 count = print_queue_status(snum, &queue, &status);
1813 snprintf(chaine, sizeof(chaine)-1, "%s", servername);
1815 if (strlen(servername)!=0)
1820 snprintf(chaine2, sizeof(chaine)-1, "%s%s%s", servername, sl, ntprinter.info_2->printername);
1822 init_unistr(&printer->servername, chaine); /* servername*/
1823 init_unistr(&printer->printername, chaine2); /* printername*/
1824 init_unistr(&printer->sharename, lp_servicename(snum)); /* sharename */
1825 init_unistr(&printer->portname, lp_servicename(snum)); /* port */
1826 init_unistr(&printer->drivername, ntprinter.info_2->drivername); /* drivername */
1827 init_unistr(&printer->comment, lp_comment(snum)); /* comment */
1828 init_unistr(&printer->location, ntprinter.info_2->location); /* location */
1829 init_unistr(&printer->sepfile, ntprinter.info_2->sepfile); /* separator file */
1830 init_unistr(&printer->printprocessor, ntprinter.info_2->printprocessor);/* print processor */
1831 init_unistr(&printer->datatype, ntprinter.info_2->datatype); /* datatype */
1832 init_unistr(&printer->parameters, ntprinter.info_2->parameters); /* parameters (of print processor) */
1834 printer->attributes = PRINTER_ATTRIBUTE_SHARED \
1835 | PRINTER_ATTRIBUTE_LOCAL \
1836 | PRINTER_ATTRIBUTE_RAW_ONLY ; /* attributes */
1838 printer->priority = ntprinter.info_2->priority; /* priority */
1839 printer->defaultpriority = ntprinter.info_2->default_priority; /* default priority */
1840 printer->starttime = ntprinter.info_2->starttime; /* starttime */
1841 printer->untiltime = ntprinter.info_2->untiltime; /* untiltime */
1842 printer->status = nt_printq_status(status.status); /* status */
1843 printer->cjobs = count; /* jobs */
1844 printer->averageppm = ntprinter.info_2->averageppm; /* average pages per minute */
1846 if((devmode=(DEVICEMODE *)malloc(sizeof(DEVICEMODE))) == NULL)
1849 ZERO_STRUCTP(devmode);
1851 if(!construct_dev_mode(devmode, snum, servername))
1854 printer->devmode=devmode;
1857 free_a_printer(ntprinter, 2);
1863 free_a_printer(ntprinter, 2);
1867 /********************************************************************
1868 Spoolss_enumprinters.
1869 ********************************************************************/
1870 static BOOL enum_all_printers_info_1(fstring server, uint32 flags, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
1874 int n_services=lp_numservices();
1875 PRINTER_INFO_1 *printers=NULL;
1876 PRINTER_INFO_1 current_prt;
1878 DEBUG(4,("enum_all_printers_info_1\n"));
1880 for (snum=0; snum<n_services; snum++) {
1881 if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
1882 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum));
1884 if (construct_printer_info_1(server, flags, ¤t_prt, snum)) {
1885 if((printers=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_1))) == NULL) {
1887 return ERROR_NOT_ENOUGH_MEMORY;
1889 DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_1\n", *returned));
1890 memcpy(&(printers[*returned]), ¤t_prt, sizeof(PRINTER_INFO_1));
1896 /* check the required size. */
1897 for (i=0; i<*returned; i++)
1898 (*needed) += spoolss_size_printer_info_1(&(printers[i]));
1900 if (!alloc_buffer_size(buffer, *needed))
1901 return ERROR_INSUFFICIENT_BUFFER;
1903 /* fill the buffer with the structures */
1904 for (i=0; i<*returned; i++)
1905 new_smb_io_printer_info_1("", buffer, &(printers[i]), 0);
1908 safe_free(printers);
1910 if (*needed > offered) {
1912 return ERROR_INSUFFICIENT_BUFFER;
1915 return NT_STATUS_NO_PROBLEMO;
1918 /********************************************************************
1919 enum_all_printers_info_1_local.
1920 *********************************************************************/
1921 static BOOL enum_all_printers_info_1_local(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
1924 DEBUG(4,("enum_all_printers_info_1_local\n"));
1926 fstrcpy(temp, "\\\\");
1927 fstrcat(temp, global_myname);
1929 if (!strcmp(name, temp)) {
1930 fstrcat(temp, "\\");
1931 return enum_all_printers_info_1(temp, PRINTER_ENUM_ICON8, buffer, offered, needed, returned);
1934 return enum_all_printers_info_1("", PRINTER_ENUM_ICON8, buffer, offered, needed, returned);
1937 /********************************************************************
1938 enum_all_printers_info_1_name.
1939 *********************************************************************/
1940 static BOOL enum_all_printers_info_1_name(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
1943 DEBUG(4,("enum_all_printers_info_1_name\n"));
1945 fstrcpy(temp, "\\\\");
1946 fstrcat(temp, global_myname);
1948 if (!strcmp(name, temp)) {
1949 fstrcat(temp, "\\");
1950 return enum_all_printers_info_1(temp, PRINTER_ENUM_ICON8, buffer, offered, needed, returned);
1953 return ERROR_INVALID_NAME;
1956 /********************************************************************
1957 enum_all_printers_info_1_remote.
1958 *********************************************************************/
1959 static BOOL enum_all_printers_info_1_remote(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
1961 PRINTER_INFO_1 *printer;
1962 fstring printername;
1965 DEBUG(4,("enum_all_printers_info_1_remote\n"));
1967 /* JFM: currently it's more a place holder than anything else.
1968 * In the spooler world there is a notion of server registration.
1969 * the print servers are registring (sp ?) on the PDC (in the same domain)
1971 * We should have a TDB here. The registration is done thru an undocumented RPC call.
1974 if((printer=(PRINTER_INFO_1 *)malloc(sizeof(PRINTER_INFO_1))) == NULL)
1975 return ERROR_NOT_ENOUGH_MEMORY;
1979 snprintf(printername, sizeof(printername)-1,"Windows NT Remote Printers!!\\\\%s", global_myname);
1980 snprintf(desc, sizeof(desc)-1,"%s", global_myname);
1981 snprintf(comment, sizeof(comment)-1, "Logged on Domain");
1983 init_unistr(&printer->description, desc);
1984 init_unistr(&printer->name, printername);
1985 init_unistr(&printer->comment, comment);
1986 printer->flags=PRINTER_ENUM_ICON3|PRINTER_ENUM_CONTAINER;
1988 /* check the required size. */
1989 *needed += spoolss_size_printer_info_1(printer);
1991 if (!alloc_buffer_size(buffer, *needed)) {
1993 return ERROR_INSUFFICIENT_BUFFER;
1996 /* fill the buffer with the structures */
1997 new_smb_io_printer_info_1("", buffer, printer, 0);
2002 if (*needed > offered) {
2004 return ERROR_INSUFFICIENT_BUFFER;
2007 return NT_STATUS_NO_PROBLEMO;
2010 /********************************************************************
2011 enum_all_printers_info_1_network.
2012 *********************************************************************/
2013 static BOOL enum_all_printers_info_1_network(fstring name, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
2016 DEBUG(4,("enum_all_printers_info_1_network\n"));
2018 fstrcpy(temp, "\\\\");
2019 fstrcat(temp, global_myname);
2020 fstrcat(temp, "\\");
2021 return enum_all_printers_info_1(temp, PRINTER_ENUM_UNKNOWN_8, buffer, offered, needed, returned);
2024 /********************************************************************
2025 * api_spoolss_enumprinters
2027 * called from api_spoolss_enumprinters (see this to understand)
2028 ********************************************************************/
2029 static BOOL enum_all_printers_info_2(fstring servername, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
2033 int n_services=lp_numservices();
2034 PRINTER_INFO_2 *printers=NULL;
2035 PRINTER_INFO_2 current_prt;
2037 for (snum=0; snum<n_services; snum++) {
2038 if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
2039 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum));
2041 if (construct_printer_info_2(servername, ¤t_prt, snum)) {
2042 if((printers=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_2))) == NULL)
2043 return ERROR_NOT_ENOUGH_MEMORY;
2044 DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_2\n", *returned));
2045 memcpy(&(printers[*returned]), ¤t_prt, sizeof(PRINTER_INFO_2));
2051 /* check the required size. */
2052 for (i=0; i<*returned; i++)
2053 (*needed) += spoolss_size_printer_info_2(&(printers[i]));
2055 if (!alloc_buffer_size(buffer, *needed)) {
2056 for (i=0; i<*returned; i++) {
2057 safe_free(printers[i].devmode->private);
2058 safe_free(printers[i].devmode);
2060 safe_free(printers);
2061 return ERROR_INSUFFICIENT_BUFFER;
2064 /* fill the buffer with the structures */
2065 for (i=0; i<*returned; i++)
2066 new_smb_io_printer_info_2("", buffer, &(printers[i]), 0);
2069 for (i=0; i<*returned; i++) {
2070 safe_free(printers[i].devmode->private);
2071 safe_free(printers[i].devmode);
2073 safe_free(printers);
2075 if (*needed > offered) {
2077 return ERROR_INSUFFICIENT_BUFFER;
2080 return NT_STATUS_NO_PROBLEMO;
2083 /********************************************************************
2084 * handle enumeration of printers at level 1
2085 ********************************************************************/
2086 static uint32 enumprinters_level1( uint32 flags, fstring name,
2087 NEW_BUFFER *buffer, uint32 offered,
2088 uint32 *needed, uint32 *returned)
2090 /* Not all the flags are equals */
2092 if (flags & PRINTER_ENUM_LOCAL)
2093 return enum_all_printers_info_1_local(name, buffer, offered, needed, returned);
2095 if (flags & PRINTER_ENUM_NAME)
2096 return enum_all_printers_info_1_name(name, buffer, offered, needed, returned);
2098 if (flags & PRINTER_ENUM_REMOTE)
2099 return enum_all_printers_info_1_remote(name, buffer, offered, needed, returned);
2101 if (flags & PRINTER_ENUM_NETWORK)
2102 return enum_all_printers_info_1_network(name, buffer, offered, needed, returned);
2104 return NT_STATUS_NO_PROBLEMO; /* NT4sp5 does that */
2107 /********************************************************************
2108 * handle enumeration of printers at level 2
2109 ********************************************************************/
2110 static uint32 enumprinters_level2( uint32 flags, fstring servername,
2111 NEW_BUFFER *buffer, uint32 offered,
2112 uint32 *needed, uint32 *returned)
2116 fstrcpy(temp, "\\\\");
2117 fstrcat(temp, global_myname);
2119 if (flags & PRINTER_ENUM_LOCAL) {
2120 if (!strcmp(servername, temp))
2121 return enum_all_printers_info_2(temp, buffer, offered, needed, returned);
2123 return enum_all_printers_info_2("", buffer, offered, needed, returned);
2126 if (flags & PRINTER_ENUM_NAME) {
2127 if (!strcmp(servername, temp))
2128 return enum_all_printers_info_2(temp, buffer, offered, needed, returned);
2130 return ERROR_INVALID_NAME;
2133 if (flags & PRINTER_ENUM_REMOTE)
2134 return ERROR_INVALID_LEVEL;
2136 return NT_STATUS_NO_PROBLEMO;
2139 /********************************************************************
2140 * handle enumeration of printers at level 5
2141 ********************************************************************/
2142 static uint32 enumprinters_level5( uint32 flags, fstring servername,
2143 NEW_BUFFER *buffer, uint32 offered,
2144 uint32 *needed, uint32 *returned)
2146 /* return enum_all_printers_info_5(buffer, offered, needed, returned);*/
2147 return NT_STATUS_NO_PROBLEMO;
2150 /********************************************************************
2151 * api_spoolss_enumprinters
2153 * called from api_spoolss_enumprinters (see this to understand)
2154 ********************************************************************/
2155 uint32 _spoolss_enumprinters( uint32 flags, const UNISTR2 *servername, uint32 level,
2156 NEW_BUFFER *buffer, uint32 offered,
2157 uint32 *needed, uint32 *returned)
2161 DEBUG(4,("_spoolss_enumprinters\n"));
2168 * flags==PRINTER_ENUM_NAME
2169 * if name=="" then enumerates all printers
2170 * if name!="" then enumerate the printer
2171 * flags==PRINTER_ENUM_REMOTE
2172 * name is NULL, enumerate printers
2173 * Level 2: name!="" enumerates printers, name can't be NULL
2174 * Level 3: doesn't exist
2175 * Level 4: does a local registry lookup
2176 * Level 5: same as Level 2
2179 unistr2_to_ascii(name, servername, sizeof(name)-1);
2184 return enumprinters_level1(flags, name, buffer, offered, needed, returned);
2187 return enumprinters_level2(flags, name, buffer, offered, needed, returned);
2190 return enumprinters_level5(flags, name, buffer, offered, needed, returned);
2195 return ERROR_INVALID_LEVEL;
2200 /****************************************************************************
2201 ****************************************************************************/
2202 static uint32 getprinter_level_0(fstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2204 PRINTER_INFO_0 *printer=NULL;
2206 if((printer=(PRINTER_INFO_0*)malloc(sizeof(PRINTER_INFO_0))) == NULL)
2207 return ERROR_NOT_ENOUGH_MEMORY;
2209 construct_printer_info_0(printer, snum, servername);
2211 /* check the required size. */
2212 *needed += spoolss_size_printer_info_0(printer);
2214 if (!alloc_buffer_size(buffer, *needed)) {
2216 return ERROR_INSUFFICIENT_BUFFER;
2219 /* fill the buffer with the structures */
2220 new_smb_io_printer_info_0("", buffer, printer, 0);
2225 if (*needed > offered) {
2226 return ERROR_INSUFFICIENT_BUFFER;
2229 return NT_STATUS_NO_PROBLEMO;
2232 /****************************************************************************
2233 ****************************************************************************/
2234 static uint32 getprinter_level_1(fstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2236 PRINTER_INFO_1 *printer=NULL;
2238 if((printer=(PRINTER_INFO_1*)malloc(sizeof(PRINTER_INFO_1))) == NULL)
2239 return ERROR_NOT_ENOUGH_MEMORY;
2241 construct_printer_info_1(servername, PRINTER_ENUM_ICON8, printer, snum);
2243 /* check the required size. */
2244 *needed += spoolss_size_printer_info_1(printer);
2246 if (!alloc_buffer_size(buffer, *needed)) {
2248 return ERROR_INSUFFICIENT_BUFFER;
2251 /* fill the buffer with the structures */
2252 new_smb_io_printer_info_1("", buffer, printer, 0);
2257 if (*needed > offered) {
2258 return ERROR_INSUFFICIENT_BUFFER;
2261 return NT_STATUS_NO_PROBLEMO;
2264 /****************************************************************************
2265 ****************************************************************************/
2266 static uint32 getprinter_level_2(fstring servername, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2268 PRINTER_INFO_2 *printer=NULL;
2271 if((printer=(PRINTER_INFO_2*)malloc(sizeof(PRINTER_INFO_2)))==NULL)
2272 return ERROR_NOT_ENOUGH_MEMORY;
2274 fstrcpy(temp, "\\\\");
2275 fstrcat(temp, servername);
2276 construct_printer_info_2(temp, printer, snum);
2278 /* check the required size. */
2279 *needed += spoolss_size_printer_info_2(printer);
2281 if (!alloc_buffer_size(buffer, *needed)) {
2283 return ERROR_INSUFFICIENT_BUFFER;
2286 /* fill the buffer with the structures */
2287 new_smb_io_printer_info_2("", buffer, printer, 0);
2290 safe_free(printer->devmode->private);
2291 safe_free(printer->devmode);
2294 if (*needed > offered) {
2295 return ERROR_INSUFFICIENT_BUFFER;
2298 return NT_STATUS_NO_PROBLEMO;
2301 /****************************************************************************
2302 ****************************************************************************/
2303 uint32 _spoolss_getprinter(POLICY_HND *handle, uint32 level,
2304 NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2311 pstrcpy(servername, global_myname);
2313 if (!get_printer_snum(handle, &snum))
2314 return ERROR_INVALID_HANDLE;
2318 return getprinter_level_0(servername, snum, buffer, offered, needed);
2321 return getprinter_level_1(servername,snum, buffer, offered, needed);
2324 return getprinter_level_2(servername,snum, buffer, offered, needed);
2327 return ERROR_INVALID_LEVEL;
2332 /********************************************************************
2333 * construct_printer_driver_info_1
2334 * fill a construct_printer_driver_info_1 struct
2335 ********************************************************************/
2336 static void fill_printer_driver_info_1(DRIVER_INFO_1 *info,
2337 NT_PRINTER_DRIVER_INFO_LEVEL driver,
2338 fstring servername, fstring architecture)
2340 init_unistr( &(info->name), driver.info_3->name);
2343 static void construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum,
2344 fstring servername, fstring architecture)
2346 NT_PRINTER_INFO_LEVEL printer;
2347 NT_PRINTER_DRIVER_INFO_LEVEL driver;
2349 get_a_printer(&printer, 2, lp_servicename(snum) );
2350 get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture);
2352 fill_printer_driver_info_1(info, driver, servername, architecture);
2354 free_a_printer_driver(driver, 3);
2355 free_a_printer(printer, 2);
2358 /********************************************************************
2359 * construct_printer_driver_info_2
2360 * fill a printer_info_2 struct
2361 ********************************************************************/
2362 static void fill_printer_driver_info_2(DRIVER_INFO_2 *info,
2363 NT_PRINTER_DRIVER_INFO_LEVEL driver,
2364 fstring servername, fstring architecture)
2367 pstring temp_driverpath;
2368 pstring temp_datafile;
2369 pstring temp_configfile;
2370 fstring short_archi;
2372 get_short_archi(short_archi,architecture);
2374 snprintf(where,sizeof(where)-1,"\\\\%s\\print$\\%s\\", servername, short_archi);
2376 info->version=driver.info_3->cversion;
2378 init_unistr( &(info->name), driver.info_3->name );
2379 init_unistr( &(info->architecture), architecture );
2381 snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "%s%s", where,
2382 driver.info_3->driverpath);
2383 init_unistr( &(info->driverpath), temp_driverpath );
2385 snprintf(temp_datafile, sizeof(temp_datafile)-1, "%s%s", where,
2386 driver.info_3->datafile);
2387 init_unistr( &(info->datafile), temp_datafile );
2389 snprintf(temp_configfile, sizeof(temp_configfile)-1, "%s%s", where,
2390 driver.info_3->configfile);
2391 init_unistr( &(info->configfile), temp_configfile );
2394 /********************************************************************
2395 * construct_printer_driver_info_2
2396 * fill a printer_info_2 struct
2397 ********************************************************************/
2398 static void construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fstring servername, fstring architecture)
2400 NT_PRINTER_INFO_LEVEL printer;
2401 NT_PRINTER_DRIVER_INFO_LEVEL driver;
2403 get_a_printer(&printer, 2, lp_servicename(snum) );
2404 get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture);
2406 fill_printer_driver_info_2(info, driver, servername, architecture);
2408 free_a_printer_driver(driver, 3);
2409 free_a_printer(printer, 2);
2412 /********************************************************************
2413 * copy a strings array and convert to UNICODE
2415 * convert an array of ascii string to a UNICODE string
2416 ********************************************************************/
2417 static void init_unistr_array(uint16 **uni_array, char **char_array, char *where)
2424 DEBUG(6,("init_unistr_array\n"));
2427 for (v=char_array[i]; *v!='\0'; v=char_array[i]) {
2428 snprintf(line, sizeof(line)-1, "%s%s", where, v);
2429 DEBUGADD(6,("%d:%s:%d\n", i, line, strlen(line)));
2430 if((*uni_array=Realloc(*uni_array, (j+strlen(line)+2)*sizeof(uint16))) == NULL) {
2431 DEBUG(0,("init_unistr_array: Realloc error\n" ));
2434 ascii_to_unistr((char *)(*uni_array+j), line , 2*strlen(line));
2439 (*uni_array)[j]=0x0000;
2441 DEBUGADD(6,("last one:done\n"));
2444 /********************************************************************
2445 * construct_printer_info_3
2446 * fill a printer_info_3 struct
2447 ********************************************************************/
2448 static void fill_printer_driver_info_3(DRIVER_INFO_3 *info,
2449 NT_PRINTER_DRIVER_INFO_LEVEL driver,
2450 fstring servername, fstring architecture)
2453 pstring temp_driverpath;
2454 pstring temp_datafile;
2455 pstring temp_configfile;
2456 pstring temp_helpfile;
2457 fstring short_archi;
2459 get_short_archi(short_archi, architecture);
2461 snprintf(where,sizeof(where)-1,"\\\\%s\\print$\\%s\\", servername, short_archi);
2463 info->version=driver.info_3->cversion;
2465 init_unistr( &(info->name), driver.info_3->name );
2466 init_unistr( &(info->architecture), architecture );
2468 snprintf(temp_driverpath, sizeof(temp_driverpath)-1, "%s%s", where, driver.info_3->driverpath);
2469 init_unistr( &(info->driverpath), temp_driverpath );
2471 snprintf(temp_datafile, sizeof(temp_datafile)-1, "%s%s", where, driver.info_3->datafile);
2472 init_unistr( &(info->datafile), temp_datafile );
2474 snprintf(temp_configfile, sizeof(temp_configfile)-1, "%s%s", where, driver.info_3->configfile);
2475 init_unistr( &(info->configfile), temp_configfile );
2477 snprintf(temp_helpfile, sizeof(temp_helpfile)-1, "%s%s", where, driver.info_3->helpfile);
2478 init_unistr( &(info->helpfile), temp_helpfile );
2480 init_unistr( &(info->monitorname), driver.info_3->monitorname );
2481 init_unistr( &(info->defaultdatatype), driver.info_3->defaultdatatype );
2483 info->dependentfiles=NULL;
2484 init_unistr_array(&(info->dependentfiles), driver.info_3->dependentfiles, where);
2487 /********************************************************************
2488 * construct_printer_info_3
2489 * fill a printer_info_3 struct
2490 ********************************************************************/
2491 static void construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum,
2492 fstring servername, fstring architecture)
2494 NT_PRINTER_INFO_LEVEL printer;
2495 NT_PRINTER_DRIVER_INFO_LEVEL driver;
2497 get_a_printer(&printer, 2, lp_servicename(snum) );
2498 get_a_printer_driver(&driver, 3, printer.info_2->drivername, architecture);
2500 fill_printer_driver_info_3(info, driver, servername, architecture);
2502 free_a_printer_driver(driver, 3);
2503 free_a_printer(printer, 2);
2506 /****************************************************************************
2507 ****************************************************************************/
2508 static uint32 getprinterdriver2_level1(fstring servername, fstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2510 DRIVER_INFO_1 *info=NULL;
2512 if((info=(DRIVER_INFO_1 *)malloc(sizeof(DRIVER_INFO_1))) == NULL)
2513 return ERROR_NOT_ENOUGH_MEMORY;
2515 construct_printer_driver_info_1(info, snum, servername, architecture);
2517 /* check the required size. */
2518 *needed += spoolss_size_printer_driver_info_1(info);
2520 if (!alloc_buffer_size(buffer, *needed)) {
2522 return ERROR_INSUFFICIENT_BUFFER;
2525 /* fill the buffer with the structures */
2526 new_smb_io_printer_driver_info_1("", buffer, info, 0);
2531 if (*needed > offered)
2532 return ERROR_INSUFFICIENT_BUFFER;
2534 return NT_STATUS_NO_PROBLEMO;
2537 /****************************************************************************
2538 ****************************************************************************/
2539 static uint32 getprinterdriver2_level2(fstring servername, fstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2541 DRIVER_INFO_2 *info=NULL;
2543 if((info=(DRIVER_INFO_2 *)malloc(sizeof(DRIVER_INFO_2))) == NULL)
2544 return ERROR_NOT_ENOUGH_MEMORY;
2546 construct_printer_driver_info_2(info, snum, servername, architecture);
2548 /* check the required size. */
2549 *needed += spoolss_size_printer_driver_info_2(info);
2551 if (!alloc_buffer_size(buffer, *needed)) {
2553 return ERROR_INSUFFICIENT_BUFFER;
2556 /* fill the buffer with the structures */
2557 new_smb_io_printer_driver_info_2("", buffer, info, 0);
2562 if (*needed > offered)
2563 return ERROR_INSUFFICIENT_BUFFER;
2565 return NT_STATUS_NO_PROBLEMO;
2568 /****************************************************************************
2569 ****************************************************************************/
2570 static uint32 getprinterdriver2_level3(fstring servername, fstring architecture, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
2572 DRIVER_INFO_3 *info=NULL;
2574 if((info=(DRIVER_INFO_3 *)malloc(sizeof(DRIVER_INFO_3)))==NULL)
2575 return ERROR_NOT_ENOUGH_MEMORY;
2577 construct_printer_driver_info_3(info, snum, servername, architecture);
2579 /* check the required size. */
2580 *needed += spoolss_size_printer_driver_info_3(info);
2582 if (!alloc_buffer_size(buffer, *needed)) {
2584 return ERROR_INSUFFICIENT_BUFFER;
2587 /* fill the buffer with the structures */
2588 new_smb_io_printer_driver_info_3("", buffer, info, 0);
2591 safe_free(info->dependentfiles);
2594 if (*needed > offered)
2595 return ERROR_INSUFFICIENT_BUFFER;
2597 return NT_STATUS_NO_PROBLEMO;
2600 /****************************************************************************
2601 ****************************************************************************/
2602 uint32 _spoolss_getprinterdriver2(const POLICY_HND *handle, const UNISTR2 *uni_arch, uint32 level,
2603 uint32 clientmajorversion, uint32 clientminorversion,
2604 NEW_BUFFER *buffer, uint32 offered,
2605 uint32 *needed, uint32 *servermajorversion, uint32 *serverminorversion)
2608 fstring architecture;
2611 DEBUG(4,("_spoolss_getprinterdriver2\n"));
2614 *servermajorversion=0;
2615 *serverminorversion=0;
2617 pstrcpy(servername, global_myname);
2618 unistr2_to_ascii(architecture, uni_arch, sizeof(architecture)-1);
2620 if (!get_printer_snum(handle, &snum))
2621 return ERROR_INVALID_HANDLE;
2625 return getprinterdriver2_level1(servername, architecture, snum, buffer, offered, needed);
2628 return getprinterdriver2_level2(servername, architecture, snum, buffer, offered, needed);
2631 return getprinterdriver2_level3(servername, architecture, snum, buffer, offered, needed);
2634 return ERROR_INVALID_LEVEL;
2639 /****************************************************************************
2640 ****************************************************************************/
2641 uint32 _spoolss_startpageprinter(const POLICY_HND *handle)
2643 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2645 if (OPEN_HANDLE(Printer))
2647 Printer->page_started=True;
2651 DEBUG(3,("Error in startpageprinter printer handle\n"));
2652 return ERROR_INVALID_HANDLE;
2655 /****************************************************************************
2656 ****************************************************************************/
2657 uint32 _spoolss_endpageprinter(const POLICY_HND *handle)
2659 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2661 if (!OPEN_HANDLE(Printer))
2663 DEBUG(3,("Error in endpageprinter printer handle\n"));
2664 return ERROR_INVALID_HANDLE;
2667 Printer->page_started=False;
2669 return NT_STATUS_NO_PROBLEMO;
2673 /********************************************************************
2674 * api_spoolss_getprinter
2675 * called from the spoolss dispatcher
2677 ********************************************************************/
2678 uint32 _spoolss_startdocprinter( const POLICY_HND *handle, uint32 level,
2679 DOC_INFO *docinfo, uint32 *jobid)
2681 DOC_INFO_1 *info_1 = &docinfo->doc_info_1;
2685 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2687 if (!OPEN_HANDLE(Printer))
2689 return ERROR_INVALID_HANDLE;
2693 * a nice thing with NT is it doesn't listen to what you tell it.
2694 * when asked to send _only_ RAW datas, it tries to send datas
2697 * So I add checks like in NT Server ...
2699 * lkclXXXX jean-francois, i love this kind of thing. oh, well,
2700 * there's a bug in NT client-side code, so we'll fix it in the
2701 * server-side code. *nnnnnggggh!*
2704 if (info_1->p_datatype != 0)
2706 unistr2_to_ascii(datatype, &(info_1->docname), sizeof(datatype));
2707 if (strcmp(datatype, "RAW") != 0)
2710 return ERROR_INVALID_DATATYPE;
2714 /* get the share number of the printer */
2715 if (!get_printer_snum(handle, &snum))
2717 return ERROR_INVALID_HANDLE;
2720 unistr2_to_ascii(jobname, &info_1->docname, sizeof(jobname));
2722 Printer->jobid = print_job_start(snum, jobname);
2724 /* need to map error codes properly - for now give out of
2725 memory as I don't know the correct codes (tridge) */
2726 if (Printer->jobid == -1) {
2727 return ERROR_NOT_ENOUGH_MEMORY;
2730 Printer->document_started=True;
2731 (*jobid) = Printer->jobid;
2736 /********************************************************************
2737 * api_spoolss_getprinter
2738 * called from the spoolss dispatcher
2740 ********************************************************************/
2741 uint32 _spoolss_enddocprinter(const POLICY_HND *handle)
2743 Printer_entry *Printer=find_printer_index_by_hnd(handle);
2745 if (!OPEN_HANDLE(Printer))
2747 DEBUG(3,("Error in enddocprinter handle\n"));
2748 return ERROR_INVALID_HANDLE;
2751 Printer->document_started=False;
2752 print_job_end(Printer->jobid);
2753 /* error codes unhandled so far ... */
2758 /****************************************************************************
2759 ****************************************************************************/
2760 uint32 _spoolss_writeprinter( const POLICY_HND *handle,
2762 const uint8 *buffer,
2763 uint32 *buffer_written)
2765 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2767 if (!OPEN_HANDLE(Printer))
2769 DEBUG(3,("Error in writeprinter handle\n"));
2770 return ERROR_INVALID_HANDLE;
2773 (*buffer_written) = print_job_write(Printer->jobid, buffer, buffer_size);
2778 /********************************************************************
2779 * api_spoolss_getprinter
2780 * called from the spoolss dispatcher
2782 ********************************************************************/
2783 static uint32 control_printer(const POLICY_HND *handle, uint32 command)
2786 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2788 if (!OPEN_HANDLE(Printer))
2789 return ERROR_INVALID_HANDLE;
2791 if (!get_printer_snum(handle, &snum) )
2792 return ERROR_INVALID_HANDLE;
2795 case PRINTER_CONTROL_PAUSE:
2796 if (print_queue_pause(snum)) {
2800 case PRINTER_CONTROL_RESUME:
2801 case PRINTER_CONTROL_UNPAUSE:
2802 if (print_queue_resume(snum)) {
2806 case PRINTER_CONTROL_PURGE:
2807 if (print_queue_purge(snum)) {
2813 return ERROR_INVALID_FUNCTION;
2816 /********************************************************************
2817 * called by spoolss_api_setprinter
2818 * when updating a printer description
2819 ********************************************************************/
2820 static uint32 update_printer(const POLICY_HND *handle, uint32 level,
2821 const SPOOL_PRINTER_INFO_LEVEL *info,
2822 const DEVICEMODE *devmode)
2825 NT_PRINTER_INFO_LEVEL printer;
2826 NT_DEVICEMODE *nt_devmode;
2827 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2831 DEBUG(8,("update_printer\n"));
2834 DEBUG(0,("Send a mail to jfm@samba.org\n"));
2835 DEBUGADD(0,("with the following message: update_printer: level!=2\n"));
2836 return ERROR_INVALID_LEVEL;
2839 if (!OPEN_HANDLE(Printer))
2840 return ERROR_INVALID_HANDLE;
2842 if (!get_printer_snum(handle, &snum) )
2843 return ERROR_INVALID_HANDLE;
2845 get_a_printer(&printer, 2, lp_servicename(snum));
2847 DEBUGADD(8,("Converting info_2 struct\n"));
2848 convert_printer_info(info, &printer, level);
2850 if ((info->info_2)->devmode_ptr != 0) {
2851 /* we have a valid devmode
2852 convert it and link it*/
2854 /* the nt_devmode memory is already alloced
2855 * while doing the get_a_printer call
2856 * but the devmode private part is not
2857 * it's done by convert_devicemode
2859 DEBUGADD(8,("Converting the devicemode struct\n"));
2860 nt_devmode=printer.info_2->devmode;
2862 init_devicemode(nt_devmode);
2864 convert_devicemode(*devmode, nt_devmode);
2867 if (printer.info_2->devmode != NULL)
2868 free(printer.info_2->devmode);
2869 printer.info_2->devmode=NULL;
2872 if (add_a_printer(printer, 2)!=0) {
2873 free_a_printer(printer, 2);
2875 /* I don't really know what to return here !!! */
2876 return ERROR_ACCESS_DENIED;
2879 free_a_printer(printer, 2);
2881 return NT_STATUS_NO_PROBLEMO;
2884 /****************************************************************************
2885 ****************************************************************************/
2886 uint32 _spoolss_setprinter(const POLICY_HND *handle, uint32 level,
2887 const SPOOL_PRINTER_INFO_LEVEL *info,
2888 const DEVMODE_CTR devmode_ctr,
2891 Printer_entry *Printer = find_printer_index_by_hnd(handle);
2893 if (!OPEN_HANDLE(Printer))
2894 return ERROR_INVALID_HANDLE;
2896 /* check the level */
2899 return control_printer(handle, command);
2902 return update_printer(handle, level, info, devmode_ctr.devmode);
2905 return ERROR_INVALID_LEVEL;
2910 /****************************************************************************
2911 ****************************************************************************/
2912 uint32 _spoolss_fcpn(const POLICY_HND *handle)
2914 Printer_entry *Printer= find_printer_index_by_hnd(handle);
2916 if (!OPEN_HANDLE(Printer))
2917 return ERROR_INVALID_HANDLE;
2919 Printer->notify.flags=0;
2920 Printer->notify.options=0;
2921 Printer->notify.localmachine[0]='\0';
2922 Printer->notify.printerlocal=0;
2923 safe_free(Printer->notify.option);
2924 Printer->notify.option=NULL;
2926 return NT_STATUS_NO_PROBLEMO;
2929 /****************************************************************************
2930 ****************************************************************************/
2931 uint32 _spoolss_addjob(const POLICY_HND *handle, uint32 level,
2932 NEW_BUFFER *buffer, uint32 offered)
2934 return NT_STATUS_NO_PROBLEMO;
2937 /****************************************************************************
2938 ****************************************************************************/
2939 static void fill_job_info_1(JOB_INFO_1 *job_info, print_queue_struct *queue,
2940 int position, int snum)
2945 time_t unixdate = time(NULL);
2947 t=gmtime(&unixdate);
2948 snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname);
2950 job_info->jobid=queue->job;
2951 init_unistr(&(job_info->printername), lp_servicename(snum));
2952 init_unistr(&(job_info->machinename), temp_name);
2953 init_unistr(&(job_info->username), queue->user);
2954 init_unistr(&(job_info->document), queue->file);
2955 init_unistr(&(job_info->datatype), "RAW");
2956 init_unistr(&(job_info->text_status), "");
2957 job_info->status=nt_printj_status(queue->status);
2958 job_info->priority=queue->priority;
2959 job_info->position=position;
2960 job_info->totalpages=0;
2961 job_info->pagesprinted=0;
2963 make_systemtime(&(job_info->submitted), t);
2966 /****************************************************************************
2967 ****************************************************************************/
2968 static BOOL fill_job_info_2(JOB_INFO_2 *job_info, print_queue_struct *queue,
2969 int position, int snum)
2972 DEVICEMODE *devmode;
2973 NT_PRINTER_INFO_LEVEL ntprinter;
2977 time_t unixdate = time(NULL);
2979 if (get_a_printer(&ntprinter, 2, lp_servicename(snum)) !=0 )
2982 t=gmtime(&unixdate);
2983 snprintf(temp_name, sizeof(temp_name), "\\\\%s", global_myname);
2985 job_info->jobid=queue->job;
2987 snprintf(chaine, sizeof(chaine)-1, "\\\\%s\\%s", global_myname, ntprinter.info_2->printername);
2988 init_unistr(&(job_info->printername), chaine);
2990 init_unistr(&(job_info->machinename), temp_name);
2991 init_unistr(&(job_info->username), queue->user);
2992 init_unistr(&(job_info->document), queue->file);
2993 init_unistr(&(job_info->notifyname), queue->user);
2994 init_unistr(&(job_info->datatype), "RAW");
2995 init_unistr(&(job_info->printprocessor), "winprint");
2996 init_unistr(&(job_info->parameters), "");
2997 init_unistr(&(job_info->text_status), "");
2999 /* and here the security descriptor */
3001 job_info->status=nt_printj_status(queue->status);
3002 job_info->priority=queue->priority;
3003 job_info->position=position;
3004 job_info->starttime=0;
3005 job_info->untiltime=0;
3006 job_info->totalpages=0;
3007 job_info->size=queue->size;
3008 make_systemtime(&(job_info->submitted), t);
3009 job_info->timeelapsed=0;
3010 job_info->pagesprinted=0;
3012 if((devmode=(DEVICEMODE *)malloc(sizeof(DEVICEMODE))) == NULL) {
3013 free_a_printer(ntprinter, 2);
3017 ZERO_STRUCTP(devmode);
3018 if(!construct_dev_mode(devmode, snum, global_myname)) {
3019 free_a_printer(ntprinter, 2);
3022 job_info->devmode=devmode;
3024 free_a_printer(ntprinter, 2);
3028 /****************************************************************************
3029 Enumjobs at level 1.
3030 ****************************************************************************/
3031 static uint32 enumjobs_level1(print_queue_struct *queue, int snum,
3032 NEW_BUFFER *buffer, uint32 offered,
3033 uint32 *needed, uint32 *returned)
3038 info=(JOB_INFO_1 *)malloc(*returned*sizeof(JOB_INFO_1));
3042 return ERROR_NOT_ENOUGH_MEMORY;
3045 for (i=0; i<*returned; i++)
3046 fill_job_info_1(&(info[i]), &(queue[i]), i, snum);
3050 /* check the required size. */
3051 for (i=0; i<*returned; i++)
3052 (*needed) += spoolss_size_job_info_1(&(info[i]));
3054 if (!alloc_buffer_size(buffer, *needed)) {
3056 return ERROR_INSUFFICIENT_BUFFER;
3059 /* fill the buffer with the structures */
3060 for (i=0; i<*returned; i++)
3061 new_smb_io_job_info_1("", buffer, &(info[i]), 0);
3066 if (*needed > offered) {
3068 return ERROR_INSUFFICIENT_BUFFER;
3071 return NT_STATUS_NO_PROBLEMO;
3074 /****************************************************************************
3075 Enumjobs at level 2.
3076 ****************************************************************************/
3077 static uint32 enumjobs_level2(print_queue_struct *queue, int snum,
3078 NEW_BUFFER *buffer, uint32 offered,
3079 uint32 *needed, uint32 *returned)
3084 info=(JOB_INFO_2 *)malloc(*returned*sizeof(JOB_INFO_2));
3088 return ERROR_NOT_ENOUGH_MEMORY;
3091 for (i=0; i<*returned; i++)
3092 fill_job_info_2(&(info[i]), &(queue[i]), i, snum);
3096 /* check the required size. */
3097 for (i=0; i<*returned; i++)
3098 (*needed) += spoolss_size_job_info_2(&(info[i]));
3100 if (!alloc_buffer_size(buffer, *needed)) {
3102 return ERROR_INSUFFICIENT_BUFFER;
3105 /* fill the buffer with the structures */
3106 for (i=0; i<*returned; i++)
3107 new_smb_io_job_info_2("", buffer, &(info[i]), 0);
3112 if (*needed > offered) {
3114 return ERROR_INSUFFICIENT_BUFFER;
3117 return NT_STATUS_NO_PROBLEMO;
3120 /****************************************************************************
3122 ****************************************************************************/
3123 uint32 _spoolss_enumjobs( POLICY_HND *handle, uint32 firstjob, uint32 numofjobs, uint32 level,
3124 NEW_BUFFER *buffer, uint32 offered,
3125 uint32 *needed, uint32 *returned)
3128 print_queue_struct *queue=NULL;
3129 print_status_struct prt_status;
3131 DEBUG(4,("_spoolss_enumjobs\n"));
3133 ZERO_STRUCT(prt_status);
3138 if (!get_printer_snum(handle, &snum))
3139 return ERROR_INVALID_HANDLE;
3141 *returned = print_queue_status(snum, &queue, &prt_status);
3142 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n", *returned, prt_status.status, prt_status.message));
3146 return enumjobs_level1(queue, snum, buffer, offered, needed, returned);
3149 return enumjobs_level2(queue, snum, buffer, offered, needed, returned);
3154 return ERROR_INVALID_LEVEL;
3160 /****************************************************************************
3161 ****************************************************************************/
3162 uint32 _spoolss_schedulejob( const POLICY_HND *handle, uint32 jobid)
3167 /****************************************************************************
3168 ****************************************************************************/
3169 uint32 _spoolss_setjob( const POLICY_HND *handle,
3177 print_status_struct prt_status;
3179 memset(&prt_status, 0, sizeof(prt_status));
3181 if (!get_printer_snum(handle, &snum)) {
3182 return ERROR_INVALID_HANDLE;
3185 if (!print_job_exists(jobid)) {
3186 return ERROR_INVALID_PRINTER_NAME;
3190 case JOB_CONTROL_CANCEL:
3191 case JOB_CONTROL_DELETE:
3192 if (print_job_delete(jobid)) return 0x0;
3194 case JOB_CONTROL_PAUSE:
3195 if (print_job_pause(jobid)) return 0x0;
3197 case JOB_CONTROL_RESUME:
3198 if (print_job_resume(jobid)) return 0x0;
3201 return ERROR_INVALID_LEVEL;
3204 return ERROR_INVALID_HANDLE;
3207 /****************************************************************************
3208 Enumerates all printer drivers at level 1.
3209 ****************************************************************************/
3210 static uint32 enumprinterdrivers_level1(fstring *list, fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3213 NT_PRINTER_DRIVER_INFO_LEVEL driver;
3214 DRIVER_INFO_1 *driver_info_1=NULL;
3216 if((driver_info_1=(DRIVER_INFO_1 *)malloc(*returned * sizeof(DRIVER_INFO_1))) == NULL)
3217 return ERROR_NOT_ENOUGH_MEMORY;
3219 for (i=0; i<*returned; i++) {
3220 get_a_printer_driver(&driver, 3, list[i], architecture);
3221 fill_printer_driver_info_1(&(driver_info_1[i]), driver, servername, architecture );
3222 free_a_printer_driver(driver, 3);
3227 /* check the required size. */
3228 for (i=0; i<*returned; i++) {
3229 DEBUGADD(6,("adding driver [%d]'s size\n",i));
3230 *needed += spoolss_size_printer_driver_info_1(&(driver_info_1[i]));
3233 if (!alloc_buffer_size(buffer, *needed)) {
3234 safe_free(driver_info_1);
3235 return ERROR_INSUFFICIENT_BUFFER;
3238 /* fill the buffer with the form structures */
3239 for (i=0; i<*returned; i++) {
3240 DEBUGADD(6,("adding driver [%d] to buffer\n",i));
3241 new_smb_io_printer_driver_info_1("", buffer, &(driver_info_1[i]), 0);
3244 safe_free(driver_info_1);
3246 if (*needed > offered) {
3248 return ERROR_INSUFFICIENT_BUFFER;
3251 return NT_STATUS_NO_PROBLEMO;
3254 /****************************************************************************
3255 Enumerates all printer drivers at level 2.
3256 ****************************************************************************/
3257 static uint32 enumprinterdrivers_level2(fstring *list, fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3260 NT_PRINTER_DRIVER_INFO_LEVEL driver;
3261 DRIVER_INFO_2 *driver_info_2=NULL;
3263 if (*returned > 0 &&
3264 !(driver_info_2=(DRIVER_INFO_2 *)malloc(*returned * sizeof(DRIVER_INFO_2))))
3265 return ERROR_NOT_ENOUGH_MEMORY;
3267 for (i=0; i<*returned; i++) {
3268 get_a_printer_driver(&driver, 3, list[i], architecture);
3269 fill_printer_driver_info_2(&(driver_info_2[i]), driver, servername, architecture );
3270 free_a_printer_driver(driver, 3);
3275 /* check the required size. */
3276 for (i=0; i<*returned; i++) {
3277 DEBUGADD(6,("adding driver [%d]'s size\n",i));
3278 *needed += spoolss_size_printer_driver_info_2(&(driver_info_2[i]));
3281 if (!alloc_buffer_size(buffer, *needed)) {
3282 safe_free(driver_info_2);
3283 return ERROR_INSUFFICIENT_BUFFER;
3286 /* fill the buffer with the form structures */
3287 for (i=0; i<*returned; i++) {
3288 DEBUGADD(6,("adding driver [%d] to buffer\n",i));
3289 new_smb_io_printer_driver_info_2("", buffer, &(driver_info_2[i]), 0);
3292 safe_free(driver_info_2);
3294 if (*needed > offered) {
3296 return ERROR_INSUFFICIENT_BUFFER;
3299 return NT_STATUS_NO_PROBLEMO;
3302 /****************************************************************************
3303 Enumerates all printer drivers at level 3.
3304 ****************************************************************************/
3305 static uint32 enumprinterdrivers_level3(fstring *list, fstring servername, fstring architecture, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3308 NT_PRINTER_DRIVER_INFO_LEVEL driver;
3309 DRIVER_INFO_3 *driver_info_3=NULL;
3311 if((driver_info_3=(DRIVER_INFO_3 *)malloc((*returned)*sizeof(DRIVER_INFO_3))) == NULL)
3312 return ERROR_NOT_ENOUGH_MEMORY;
3314 for (i=0; i<*returned; i++) {
3315 get_a_printer_driver(&driver, 3, list[i], architecture);
3316 fill_printer_driver_info_3(&(driver_info_3[i]), driver, servername, architecture );
3317 free_a_printer_driver(driver, 3);
3322 /* check the required size. */
3323 for (i=0; i<*returned; i++) {
3324 DEBUGADD(6,("adding driver [%d]'s size\n",i));
3325 *needed += spoolss_size_printer_driver_info_3(&(driver_info_3[i]));
3328 if (!alloc_buffer_size(buffer, *needed)) {
3329 safe_free(driver_info_3);
3330 return ERROR_INSUFFICIENT_BUFFER;
3333 /* fill the buffer with the form structures */
3334 for (i=0; i<*returned; i++) {
3335 DEBUGADD(6,("adding form [%d] to buffer\n",i));
3336 new_smb_io_printer_driver_info_3("", buffer, &(driver_info_3[i]), 0);
3339 for (i=0; i<*returned; i++)
3340 safe_free(driver_info_3[i].dependentfiles);
3342 safe_free(driver_info_3);
3344 if (*needed > offered) {
3346 return ERROR_INSUFFICIENT_BUFFER;
3349 return NT_STATUS_NO_PROBLEMO;
3352 /****************************************************************************
3353 Enumerates all printer drivers.
3354 ****************************************************************************/
3355 uint32 _spoolss_enumprinterdrivers( UNISTR2 *name, UNISTR2 *environment, uint32 level,
3356 NEW_BUFFER *buffer, uint32 offered,
3357 uint32 *needed, uint32 *returned)
3362 fstring architecture;
3364 DEBUG(4,("_spoolss_enumprinterdrivers\n"));
3365 fstrcpy(servername, global_myname);
3369 unistr2_to_ascii(architecture, environment, sizeof(architecture)-1);
3370 *returned=get_ntdrivers(&list, architecture);
3372 DEBUGADD(4,("we have: [%d] drivers in environment [%s]\n", *returned, architecture));
3374 return ERROR_NOT_ENOUGH_MEMORY;
3376 for (i=0; i<*returned; i++)
3377 DEBUGADD(5,("driver: [%s]\n", list[i]));
3381 return enumprinterdrivers_level1(list, servername, architecture, buffer, offered, needed, returned);
3384 return enumprinterdrivers_level2(list, servername, architecture, buffer, offered, needed, returned);
3387 return enumprinterdrivers_level3(list, servername, architecture, buffer, offered, needed, returned);
3390 return ERROR_INVALID_LEVEL;
3395 /****************************************************************************
3396 ****************************************************************************/
3397 static void fill_form_1(FORM_1 *form, nt_forms_struct *list, int position)
3399 form->flag=list->flag;
3400 init_unistr(&(form->name), list->name);
3401 form->width=list->width;
3402 form->length=list->length;
3403 form->left=list->left;
3404 form->top=list->top;
3405 form->right=list->right;
3406 form->bottom=list->bottom;
3409 /****************************************************************************
3410 ****************************************************************************/
3411 uint32 _new_spoolss_enumforms( const POLICY_HND *handle, uint32 level,
3412 NEW_BUFFER *buffer, uint32 offered,
3413 uint32 *needed, uint32 *numofforms)
3415 nt_forms_struct *list=NULL;
3420 DEBUG(4,("_new_spoolss_enumforms\n"));
3421 DEBUGADD(5,("Offered buffer size [%d]\n", offered));
3422 DEBUGADD(5,("Info level [%d]\n", level));
3424 *numofforms = get_ntforms(&list);
3425 DEBUGADD(5,("Number of forms [%d]\n", *numofforms));
3429 if((forms_1=(FORM_1 *)malloc(*numofforms * sizeof(FORM_1))) == NULL) {
3431 return ERROR_NOT_ENOUGH_MEMORY;
3434 /* construct the list of form structures */
3435 for (i=0; i<*numofforms; i++) {
3436 DEBUGADD(6,("Filling form number [%d]\n",i));
3437 fill_form_1(&(forms_1[i]), &(list[i]), i);
3442 /* check the required size. */
3443 for (i=0; i<*numofforms; i++) {
3444 DEBUGADD(6,("adding form [%d]'s size\n",i));
3445 buffer_size += spoolss_size_form_1(&(forms_1[i]));
3448 *needed=buffer_size;
3450 if (!alloc_buffer_size(buffer, buffer_size)){
3452 return ERROR_INSUFFICIENT_BUFFER;
3455 /* fill the buffer with the form structures */
3456 for (i=0; i<*numofforms; i++) {
3457 DEBUGADD(6,("adding form [%d] to buffer\n",i));
3458 new_smb_io_form_1("", buffer, &(forms_1[i]), 0);
3463 if (*needed > offered) {
3465 return ERROR_INSUFFICIENT_BUFFER;
3468 return NT_STATUS_NO_PROBLEMO;
3472 return ERROR_INVALID_LEVEL;
3477 /****************************************************************************
3478 ****************************************************************************/
3479 static void fill_port_1(PORT_INFO_1 *port, char *name)
3481 init_unistr(&(port->port_name), name);
3484 /****************************************************************************
3485 ****************************************************************************/
3486 static void fill_port_2(PORT_INFO_2 *port, char *name)
3488 init_unistr(&(port->port_name), name);
3489 init_unistr(&(port->monitor_name), "Moniteur Local");
3490 init_unistr(&(port->description), "Local Port");
3491 #define PORT_TYPE_WRITE 1
3492 port->port_type=PORT_TYPE_WRITE;
3496 /****************************************************************************
3498 ****************************************************************************/
3499 static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3501 int n_services=lp_numservices();
3505 PORT_INFO_1 *ports=NULL;
3507 for (snum=0; snum<n_services; snum++)
3508 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
3511 if((ports=(PORT_INFO_1 *)malloc( (*returned+1) * sizeof(PORT_INFO_1) )) == NULL)
3512 return ERROR_NOT_ENOUGH_MEMORY;
3514 for (snum=0; snum<n_services; snum++) {
3515 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
3516 DEBUGADD(6,("Filling port number [%d]\n", i));
3517 fill_port_1(&(ports[i]), lp_servicename(snum));
3522 /* check the required size. */
3523 for (i=0; i<*returned; i++) {
3524 DEBUGADD(6,("adding port [%d]'s size\n", i));
3525 *needed += spoolss_size_port_info_1(&(ports[i]));
3528 if (!alloc_buffer_size(buffer, *needed)) {
3530 return ERROR_INSUFFICIENT_BUFFER;
3533 /* fill the buffer with the ports structures */
3534 for (i=0; i<*returned; i++) {
3535 DEBUGADD(6,("adding port [%d] to buffer\n", i));
3536 new_smb_io_port_1("", buffer, &(ports[i]), 0);
3541 if (*needed > offered) {
3543 return ERROR_INSUFFICIENT_BUFFER;
3546 return NT_STATUS_NO_PROBLEMO;
3550 /****************************************************************************
3552 ****************************************************************************/
3553 static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
3555 int n_services=lp_numservices();
3559 PORT_INFO_2 *ports=NULL;
3561 for (snum=0; snum<n_services; snum++)
3562 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
3565 if((ports=(PORT_INFO_2 *)malloc( (*returned+1) * sizeof(PORT_INFO_2) )) == NULL)
3566 return ERROR_NOT_ENOUGH_MEMORY;
3568 for (snum=0; snum<n_services; snum++) {
3569 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
3570 DEBUGADD(6,("Filling port number [%d]\n", i));
3571 fill_port_2(&(ports[i]), lp_servicename(snum));
3576 /* check the required size. */
3577 for (i=0; i<*returned; i++) {
3578 DEBUGADD(6,("adding port [%d]'s size\n", i));
3579 *needed += spoolss_size_port_info_2(&(ports[i]));
3582 if (!alloc_buffer_size(buffer, *needed)) {
3584 return ERROR_INSUFFICIENT_BUFFER;
3587 /* fill the buffer with the ports structures */
3588 for (i=0; i<*returned; i++) {
3589 DEBUGADD(6,("adding port [%d] to buffer\n", i));
3590 new_smb_io_port_2("", buffer, &(ports[i]), 0);
3595 if (*needed > offered) {
3597 return ERROR_INSUFFICIENT_BUFFER;
3600 return NT_STATUS_NO_PROBLEMO;
3603 /****************************************************************************
3605 ****************************************************************************/
3606 uint32 _spoolss_enumports( UNISTR2 *name, uint32 level,
3607 NEW_BUFFER *buffer, uint32 offered,
3608 uint32 *needed, uint32 *returned)
3610 DEBUG(4,("_spoolss_enumports\n"));
3617 return enumports_level_1(buffer, offered, needed, returned);
3620 return enumports_level_2(buffer, offered, needed, returned);
3623 return ERROR_INVALID_LEVEL;
3628 /****************************************************************************
3629 ****************************************************************************/
3630 static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name,
3631 const SPOOL_PRINTER_INFO_LEVEL *info,
3632 uint32 unk0, uint32 unk1, uint32 unk2, uint32 unk3,
3633 uint32 user_switch, const SPOOL_USER_CTR *user,
3636 NT_PRINTER_INFO_LEVEL printer;
3640 clear_handle(handle);
3642 /* NULLify info_2 here */
3643 /* don't put it in convert_printer_info as it's used also with non-NULL values */
3644 printer.info_2=NULL;
3646 /* convert from UNICODE to ASCII */
3647 convert_printer_info(info, &printer, 2);
3649 unistr2_to_ascii(share_name, &((info->info_2)->printername), sizeof(share_name)-1);
3651 slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname, share_name);
3653 /* write the ASCII on disk */
3654 if (add_a_printer(printer, 2) != 0x0)
3655 return ERROR_ACCESS_DENIED;
3657 create_printer_hnd(handle);
3659 open_printer_hnd(handle);
3661 if (!set_printer_hnd_printertype(handle, name)) {
3662 close_printer_handle(handle);
3663 return ERROR_ACCESS_DENIED;
3666 if (!set_printer_hnd_printername(handle, name)) {
3667 close_printer_handle(handle);
3668 return ERROR_ACCESS_DENIED;
3671 return NT_STATUS_NO_PROBLEMO;
3674 /****************************************************************************
3675 ****************************************************************************/
3676 uint32 _spoolss_addprinterex( const UNISTR2 *uni_srv_name, uint32 level,
3677 const SPOOL_PRINTER_INFO_LEVEL *info,
3678 uint32 unk0, uint32 unk1, uint32 unk2, uint32 unk3,
3679 uint32 user_switch, const SPOOL_USER_CTR *user,
3684 /* we don't handle yet */
3685 /* but I know what to do ... */
3686 return ERROR_INVALID_LEVEL;
3689 return spoolss_addprinterex_level_2(uni_srv_name, info,
3690 unk0, unk1, unk2, unk3,
3691 user_switch, user, handle);
3694 return ERROR_INVALID_LEVEL;
3700 /****************************************************************************
3701 ****************************************************************************/
3702 uint32 _spoolss_addprinterdriver( const UNISTR2 *server_name,
3704 const SPOOL_PRINTER_DRIVER_INFO_LEVEL *info)
3706 NT_PRINTER_DRIVER_INFO_LEVEL driver;
3708 convert_printer_driver_info(info, &driver, level);
3710 if (add_a_printer_driver(driver, level)!=0)
3711 return ERROR_ACCESS_DENIED;
3713 safe_free(driver.info_3);
3715 return NT_STATUS_NO_PROBLEMO;
3718 /****************************************************************************
3719 ****************************************************************************/
3720 static void fill_driverdir_1(DRIVER_DIRECTORY_1 *info, char *name)
3722 init_unistr(&(info->name), name);