2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-2000,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
6 * Copyright (C) Jean François Micouleau 1998-2000,
7 * Copyright (C) Jeremy Allison 2001-2002,
8 * Copyright (C) Gerald Carter 2000-2004,
9 * Copyright (C) Tim Potter 2001-2002.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <http://www.gnu.org/licenses/>.
25 /* Since the SPOOLSS rpc routines are basically DOS 16-bit calls wrapped
26 up, all the errors returned are DOS errors, not NT status codes. */
30 /* macros stolen from s4 spoolss server */
31 #define SPOOLSS_BUFFER_UNION(fn,ic,info,level) \
32 ((info)?ndr_size_##fn(info, level, ic, 0):0)
34 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,ic,info,level,count) \
35 ((info)?ndr_size_##fn##_info(mem_ctx, ic, level, count, info):0)
37 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
40 extern userdom_struct current_user_info;
43 #define DBGC_CLASS DBGC_RPC_SRV
45 #ifndef MAX_OPEN_PRINTER_EXS
46 #define MAX_OPEN_PRINTER_EXS 50
49 #define MAGIC_DISPLAY_FREQUENCY 0xfade2bad
50 #define PHANTOM_DEVMODE_KEY "_p_f_a_n_t_0_m_"
53 const char *long_archi;
54 const char *short_archi;
58 static Printer_entry *printers_list;
60 typedef struct _counter_printer_0 {
61 struct _counter_printer_0 *next;
62 struct _counter_printer_0 *prev;
68 static counter_printer_0 *counter_list;
70 static struct rpc_pipe_client *notify_cli_pipe; /* print notify back-channel pipe handle*/
71 static uint32 smb_connections=0;
74 /* in printing/nt_printing.c */
76 extern struct standard_mapping printer_std_mapping, printserver_std_mapping;
78 /* API table for Xcv Monitor functions */
80 struct xcv_api_table {
82 WERROR(*fn) (TALLOC_CTX *mem_ctx, NT_USER_TOKEN *token, DATA_BLOB *in, DATA_BLOB *out, uint32_t *needed);
85 /********************************************************************
86 * Canonicalize servername.
87 ********************************************************************/
89 static const char *canon_servername(const char *servername)
91 const char *pservername = servername;
92 while (*pservername == '\\') {
98 /* translate between internal status numbers and NT status numbers */
99 static int nt_printj_status(int v)
105 return JOB_STATUS_PAUSED;
107 return JOB_STATUS_SPOOLING;
109 return JOB_STATUS_PRINTING;
111 return JOB_STATUS_ERROR;
113 return JOB_STATUS_DELETING;
115 return JOB_STATUS_OFFLINE;
117 return JOB_STATUS_PAPEROUT;
119 return JOB_STATUS_PRINTED;
121 return JOB_STATUS_DELETED;
123 return JOB_STATUS_BLOCKED_DEVQ;
124 case LPQ_USER_INTERVENTION:
125 return JOB_STATUS_USER_INTERVENTION;
130 static int nt_printq_status(int v)
134 return PRINTER_STATUS_PAUSED;
143 /***************************************************************************
144 Disconnect from the client
145 ****************************************************************************/
147 static void srv_spoolss_replycloseprinter(int snum, POLICY_HND *handle)
153 * Tell the specific printing tdb we no longer want messages for this printer
154 * by deregistering our PID.
157 if (!print_notify_deregister_pid(snum))
158 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", lp_const_servicename(snum) ));
160 /* weird if the test succeds !!! */
161 if (smb_connections==0) {
162 DEBUG(0,("srv_spoolss_replycloseprinter:Trying to close non-existant notify backchannel !\n"));
166 status = rpccli_spoolss_ReplyClosePrinter(notify_cli_pipe, talloc_tos(),
169 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
170 DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed [%s].\n",
171 win_errstr(result)));
173 /* if it's the last connection, deconnect the IPC$ share */
174 if (smb_connections==1) {
176 cli_shutdown( rpc_pipe_np_smb_conn(notify_cli_pipe) );
177 notify_cli_pipe = NULL; /* The above call shuts downn the pipe also. */
179 messaging_deregister(smbd_messaging_context(),
180 MSG_PRINTER_NOTIFY2, NULL);
182 /* Tell the connections db we're no longer interested in
183 * printer notify messages. */
185 register_message_flags( False, FLAG_MSG_PRINT_NOTIFY );
191 /****************************************************************************
192 Functions to free a printer entry datastruct.
193 ****************************************************************************/
195 static int printer_entry_destructor(Printer_entry *Printer)
197 if (Printer->notify.client_connected==True) {
200 if ( Printer->printer_type == SPLHND_SERVER) {
202 srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
203 } else if (Printer->printer_type == SPLHND_PRINTER) {
204 snum = print_queue_snum(Printer->sharename);
206 srv_spoolss_replycloseprinter(snum,
207 &Printer->notify.client_hnd);
211 Printer->notify.flags=0;
212 Printer->notify.options=0;
213 Printer->notify.localmachine[0]='\0';
214 Printer->notify.printerlocal=0;
215 TALLOC_FREE(Printer->notify.option);
216 Printer->notify.client_connected=False;
218 free_nt_devicemode( &Printer->nt_devmode );
219 free_a_printer( &Printer->printer_info, 2 );
221 /* Remove from the internal list. */
222 DLIST_REMOVE(printers_list, Printer);
226 /****************************************************************************
227 find printer index by handle
228 ****************************************************************************/
230 static Printer_entry *find_printer_index_by_hnd(pipes_struct *p, POLICY_HND *hnd)
232 Printer_entry *find_printer = NULL;
234 if(!find_policy_by_hnd(p,hnd,(void **)(void *)&find_printer)) {
235 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
242 /****************************************************************************
243 Close printer index by handle.
244 ****************************************************************************/
246 static bool close_printer_handle(pipes_struct *p, POLICY_HND *hnd)
248 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
251 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(hnd)));
255 close_policy_hnd(p, hnd);
260 /****************************************************************************
261 Delete a printer given a handle.
262 ****************************************************************************/
264 WERROR delete_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *sharename )
266 char *cmd = lp_deleteprinter_cmd();
267 char *command = NULL;
269 SE_PRIV se_printop = SE_PRINT_OPERATOR;
270 bool is_print_op = False;
272 /* can't fail if we don't try */
277 command = talloc_asprintf(ctx,
284 is_print_op = user_has_privileges( token, &se_printop );
286 DEBUG(10,("Running [%s]\n", command));
288 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
293 if ( (ret = smbrun(command, NULL)) == 0 ) {
294 /* Tell everyone we updated smb.conf. */
295 message_send_all(smbd_messaging_context(),
296 MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
302 /********** END SePrintOperatorPrivlege BLOCK **********/
304 DEBUGADD(10,("returned [%d]\n", ret));
306 TALLOC_FREE(command);
309 return WERR_BADFID; /* What to return here? */
311 /* go ahead and re-read the services immediately */
312 reload_services( False );
314 if ( lp_servicenumber( sharename ) < 0 )
315 return WERR_ACCESS_DENIED;
320 /****************************************************************************
321 Delete a printer given a handle.
322 ****************************************************************************/
324 static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd)
326 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
329 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(hnd)));
334 * It turns out that Windows allows delete printer on a handle
335 * opened by an admin user, then used on a pipe handle created
336 * by an anonymous user..... but they're working on security.... riiight !
340 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
341 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
342 return WERR_ACCESS_DENIED;
345 /* this does not need a become root since the access check has been
346 done on the handle already */
348 if (del_a_printer( Printer->sharename ) != 0) {
349 DEBUG(3,("Error deleting printer %s\n", Printer->sharename));
353 return delete_printer_hook(p->mem_ctx, p->server_info->ptok,
354 Printer->sharename );
357 /****************************************************************************
358 Return the snum of a printer corresponding to an handle.
359 ****************************************************************************/
361 static bool get_printer_snum(pipes_struct *p, POLICY_HND *hnd, int *number,
362 struct share_params **params)
364 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
367 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(hnd)));
371 switch (Printer->printer_type) {
373 DEBUG(4,("short name:%s\n", Printer->sharename));
374 *number = print_queue_snum(Printer->sharename);
375 return (*number != -1);
383 /****************************************************************************
384 Set printer handle type.
385 Check if it's \\server or \\server\printer
386 ****************************************************************************/
388 static bool set_printer_hnd_printertype(Printer_entry *Printer, char *handlename)
390 DEBUG(3,("Setting printer type=%s\n", handlename));
392 if ( strlen(handlename) < 3 ) {
393 DEBUGADD(4,("A print server must have at least 1 char ! %s\n", handlename));
397 /* it's a print server */
398 if (*handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) {
399 DEBUGADD(4,("Printer is a print server\n"));
400 Printer->printer_type = SPLHND_SERVER;
402 /* it's a printer (set_printer_hnd_name() will handle port monitors */
404 DEBUGADD(4,("Printer is a printer\n"));
405 Printer->printer_type = SPLHND_PRINTER;
411 /****************************************************************************
412 Set printer handle name.. Accept names like \\server, \\server\printer,
413 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
414 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
415 XcvDataPort() interface.
416 ****************************************************************************/
418 static bool set_printer_hnd_name(Printer_entry *Printer, char *handlename)
421 int n_services=lp_numservices();
422 char *aprinter, *printername;
423 const char *servername;
426 NT_PRINTER_INFO_LEVEL *printer = NULL;
429 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename, (unsigned long)strlen(handlename)));
431 aprinter = handlename;
432 if ( *handlename == '\\' ) {
433 servername = canon_servername(handlename);
434 if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
442 /* save the servername to fill in replies on this handle */
444 if ( !is_myname_or_ipaddr( servername ) )
447 fstrcpy( Printer->servername, servername );
449 if ( Printer->printer_type == SPLHND_SERVER )
452 if ( Printer->printer_type != SPLHND_PRINTER )
455 DEBUGADD(5, ("searching for [%s]\n", aprinter ));
457 /* check for the Port Monitor Interface */
459 if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
460 Printer->printer_type = SPLHND_PORTMON_TCP;
461 fstrcpy(sname, SPL_XCV_MONITOR_TCPMON);
464 else if ( strequal( aprinter, SPL_XCV_MONITOR_LOCALMON ) ) {
465 Printer->printer_type = SPLHND_PORTMON_LOCAL;
466 fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON);
470 /* Search all sharenames first as this is easier than pulling
471 the printer_info_2 off of disk. Don't use find_service() since
472 that calls out to map_username() */
474 /* do another loop to look for printernames */
476 for (snum=0; !found && snum<n_services; snum++) {
478 /* no point going on if this is not a printer */
480 if ( !(lp_snum_ok(snum) && lp_print_ok(snum)) )
483 fstrcpy(sname, lp_servicename(snum));
484 if ( strequal( aprinter, sname ) ) {
489 /* no point looking up the printer object if
490 we aren't allowing printername != sharename */
492 if ( lp_force_printername(snum) )
495 fstrcpy(sname, lp_servicename(snum));
499 /* This call doesn't fill in the location or comment from
500 * a CUPS server for efficiency with large numbers of printers.
504 result = get_a_printer_search( NULL, &printer, 2, sname );
505 if ( !W_ERROR_IS_OK(result) ) {
506 DEBUG(0,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
507 sname, win_errstr(result)));
511 /* printername is always returned as \\server\printername */
512 if ( !(printername = strchr_m(&printer->info_2->printername[2], '\\')) ) {
513 DEBUG(0,("set_printer_hnd_name: info2->printername in wrong format! [%s]\n",
514 printer->info_2->printername));
515 free_a_printer( &printer, 2);
521 if ( strequal(printername, aprinter) ) {
522 free_a_printer( &printer, 2);
527 DEBUGADD(10, ("printername: %s\n", printername));
529 free_a_printer( &printer, 2);
532 free_a_printer( &printer, 2);
535 DEBUGADD(4,("Printer not found\n"));
539 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));
541 fstrcpy(Printer->sharename, sname);
546 /****************************************************************************
547 Find first available printer slot. creates a printer handle for you.
548 ****************************************************************************/
550 static bool open_printer_hnd(pipes_struct *p, POLICY_HND *hnd, char *name, uint32 access_granted)
552 Printer_entry *new_printer;
554 DEBUG(10,("open_printer_hnd: name [%s]\n", name));
556 new_printer = TALLOC_ZERO_P(NULL, Printer_entry);
557 if (new_printer == NULL) {
560 talloc_set_destructor(new_printer, printer_entry_destructor);
562 if (!create_policy_hnd(p, hnd, new_printer)) {
563 TALLOC_FREE(new_printer);
567 /* Add to the internal list. */
568 DLIST_ADD(printers_list, new_printer);
570 new_printer->notify.option=NULL;
572 if (!set_printer_hnd_printertype(new_printer, name)) {
573 close_printer_handle(p, hnd);
577 if (!set_printer_hnd_name(new_printer, name)) {
578 close_printer_handle(p, hnd);
582 new_printer->access_granted = access_granted;
584 DEBUG(5, ("%d printer handles active\n", (int)p->pipe_handles->count ));
589 /***************************************************************************
590 check to see if the client motify handle is monitoring the notification
591 given by (notify_type, notify_field).
592 **************************************************************************/
594 static bool is_monitoring_event_flags(uint32 flags, uint16 notify_type,
600 static bool is_monitoring_event(Printer_entry *p, uint16 notify_type,
603 struct spoolss_NotifyOption *option = p->notify.option;
607 * Flags should always be zero when the change notify
608 * is registered by the client's spooler. A user Win32 app
609 * might use the flags though instead of the NOTIFY_OPTION_INFO
618 return is_monitoring_event_flags(
619 p->notify.flags, notify_type, notify_field);
621 for (i = 0; i < option->count; i++) {
623 /* Check match for notify_type */
625 if (option->types[i].type != notify_type)
628 /* Check match for field */
630 for (j = 0; j < option->types[i].count; j++) {
631 if (option->types[i].fields[j] == notify_field) {
637 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
638 p->servername, p->sharename, notify_type, notify_field));
643 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
644 _data->data.integer[0] = _integer; \
645 _data->data.integer[1] = 0;
648 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
649 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
650 if (!_data->data.string.string) {\
651 _data->data.string.size = 0; \
653 _data->data.string.size = strlen_m_term(_p) * 2;
655 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
656 _data->data.devmode.devmode = _devmode;
658 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _size, _sd) \
659 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
660 if (!_data->data.sd.sd) { \
661 _data->data.sd.sd_size = 0; \
663 _data->data.sd.sd_size = _size;
665 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
670 struct spoolss_Time st;
674 if (!init_systemtime(&st, t)) {
678 p = talloc_array(mem_ctx, char, len);
684 * Systemtime must be linearized as a set of UINT16's.
685 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
688 SSVAL(p, 0, st.year);
689 SSVAL(p, 2, st.month);
690 SSVAL(p, 4, st.day_of_week);
692 SSVAL(p, 8, st.hour);
693 SSVAL(p, 10, st.minute);
694 SSVAL(p, 12, st.second);
695 SSVAL(p, 14, st.millisecond);
701 /* Convert a notification message to a struct spoolss_Notify */
703 static void notify_one_value(struct spoolss_notify_msg *msg,
704 struct spoolss_Notify *data,
707 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, msg->notify.value[0]);
710 static void notify_string(struct spoolss_notify_msg *msg,
711 struct spoolss_Notify *data,
714 /* The length of the message includes the trailing \0 */
716 data->data.string.size = msg->len * 2;
717 data->data.string.string = talloc_strdup(mem_ctx, msg->notify.data);
718 if (!data->data.string.string) {
719 data->data.string.size = 0;
724 static void notify_system_time(struct spoolss_notify_msg *msg,
725 struct spoolss_Notify *data,
728 data->data.string.string = NULL;
729 data->data.string.size = 0;
731 if (msg->len != sizeof(time_t)) {
732 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
737 init_systemtime_buffer(mem_ctx, gmtime((time_t *)msg->notify.data),
738 &data->data.string.string,
739 &data->data.string.size);
742 struct notify2_message_table {
744 void (*fn)(struct spoolss_notify_msg *msg,
745 struct spoolss_Notify *data, TALLOC_CTX *mem_ctx);
748 static struct notify2_message_table printer_notify_table[] = {
749 /* 0x00 */ { "PRINTER_NOTIFY_SERVER_NAME", notify_string },
750 /* 0x01 */ { "PRINTER_NOTIFY_PRINTER_NAME", notify_string },
751 /* 0x02 */ { "PRINTER_NOTIFY_SHARE_NAME", notify_string },
752 /* 0x03 */ { "PRINTER_NOTIFY_PORT_NAME", notify_string },
753 /* 0x04 */ { "PRINTER_NOTIFY_DRIVER_NAME", notify_string },
754 /* 0x05 */ { "PRINTER_NOTIFY_COMMENT", notify_string },
755 /* 0x06 */ { "PRINTER_NOTIFY_LOCATION", notify_string },
756 /* 0x07 */ { "PRINTER_NOTIFY_DEVMODE", NULL },
757 /* 0x08 */ { "PRINTER_NOTIFY_SEPFILE", notify_string },
758 /* 0x09 */ { "PRINTER_NOTIFY_PRINT_PROCESSOR", notify_string },
759 /* 0x0a */ { "PRINTER_NOTIFY_PARAMETERS", NULL },
760 /* 0x0b */ { "PRINTER_NOTIFY_DATATYPE", notify_string },
761 /* 0x0c */ { "PRINTER_NOTIFY_SECURITY_DESCRIPTOR", NULL },
762 /* 0x0d */ { "PRINTER_NOTIFY_ATTRIBUTES", notify_one_value },
763 /* 0x0e */ { "PRINTER_NOTIFY_PRIORITY", notify_one_value },
764 /* 0x0f */ { "PRINTER_NOTIFY_DEFAULT_PRIORITY", NULL },
765 /* 0x10 */ { "PRINTER_NOTIFY_START_TIME", NULL },
766 /* 0x11 */ { "PRINTER_NOTIFY_UNTIL_TIME", NULL },
767 /* 0x12 */ { "PRINTER_NOTIFY_STATUS", notify_one_value },
770 static struct notify2_message_table job_notify_table[] = {
771 /* 0x00 */ { "JOB_NOTIFY_PRINTER_NAME", NULL },
772 /* 0x01 */ { "JOB_NOTIFY_MACHINE_NAME", NULL },
773 /* 0x02 */ { "JOB_NOTIFY_PORT_NAME", NULL },
774 /* 0x03 */ { "JOB_NOTIFY_USER_NAME", notify_string },
775 /* 0x04 */ { "JOB_NOTIFY_NOTIFY_NAME", NULL },
776 /* 0x05 */ { "JOB_NOTIFY_DATATYPE", NULL },
777 /* 0x06 */ { "JOB_NOTIFY_PRINT_PROCESSOR", NULL },
778 /* 0x07 */ { "JOB_NOTIFY_PARAMETERS", NULL },
779 /* 0x08 */ { "JOB_NOTIFY_DRIVER_NAME", NULL },
780 /* 0x09 */ { "JOB_NOTIFY_DEVMODE", NULL },
781 /* 0x0a */ { "JOB_NOTIFY_STATUS", notify_one_value },
782 /* 0x0b */ { "JOB_NOTIFY_STATUS_STRING", NULL },
783 /* 0x0c */ { "JOB_NOTIFY_SECURITY_DESCRIPTOR", NULL },
784 /* 0x0d */ { "JOB_NOTIFY_DOCUMENT", notify_string },
785 /* 0x0e */ { "JOB_NOTIFY_PRIORITY", NULL },
786 /* 0x0f */ { "JOB_NOTIFY_POSITION", NULL },
787 /* 0x10 */ { "JOB_NOTIFY_SUBMITTED", notify_system_time },
788 /* 0x11 */ { "JOB_NOTIFY_START_TIME", NULL },
789 /* 0x12 */ { "JOB_NOTIFY_UNTIL_TIME", NULL },
790 /* 0x13 */ { "JOB_NOTIFY_TIME", NULL },
791 /* 0x14 */ { "JOB_NOTIFY_TOTAL_PAGES", notify_one_value },
792 /* 0x15 */ { "JOB_NOTIFY_PAGES_PRINTED", NULL },
793 /* 0x16 */ { "JOB_NOTIFY_TOTAL_BYTES", notify_one_value },
794 /* 0x17 */ { "JOB_NOTIFY_BYTES_PRINTED", NULL },
798 /***********************************************************************
799 Allocate talloc context for container object
800 **********************************************************************/
802 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
807 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
812 /***********************************************************************
813 release all allocated memory and zero out structure
814 **********************************************************************/
816 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
822 talloc_destroy(ctr->ctx);
829 /***********************************************************************
830 **********************************************************************/
832 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
840 /***********************************************************************
841 **********************************************************************/
843 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx )
845 if ( !ctr || !ctr->msg_groups )
848 if ( idx >= ctr->num_groups )
851 return &ctr->msg_groups[idx];
855 /***********************************************************************
856 How many groups of change messages do we have ?
857 **********************************************************************/
859 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
864 return ctr->num_groups;
867 /***********************************************************************
868 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
869 **********************************************************************/
871 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
873 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
874 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
875 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
881 /* loop over all groups looking for a matching printer name */
883 for ( i=0; i<ctr->num_groups; i++ ) {
884 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
888 /* add a new group? */
890 if ( i == ctr->num_groups ) {
893 if ( !(groups = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
894 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
897 ctr->msg_groups = groups;
899 /* clear the new entry and set the printer name */
901 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
902 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
905 /* add the change messages; 'i' is the correct index now regardless */
907 msg_grp = &ctr->msg_groups[i];
911 if ( !(msg_list = TALLOC_REALLOC_ARRAY( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
912 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
915 msg_grp->msgs = msg_list;
917 new_slot = msg_grp->num_msgs-1;
918 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
920 /* need to allocate own copy of data */
923 msg_grp->msgs[new_slot].notify.data = (char *)
924 TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len );
926 return ctr->num_groups;
929 /***********************************************************************
930 Send a change notication message on all handles which have a call
932 **********************************************************************/
934 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx )
937 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
938 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
939 SPOOLSS_NOTIFY_MSG *messages;
940 int sending_msg_count;
943 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
947 messages = msg_group->msgs;
950 DEBUG(5,("send_notify2_changes() called with no messages!\n"));
954 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
956 /* loop over all printers */
958 for (p = printers_list; p; p = p->next) {
959 struct spoolss_Notify *notifies;
964 /* Is there notification on this handle? */
966 if ( !p->notify.client_connected )
969 DEBUG(10,("Client connected! [\\\\%s\\%s]\n", p->servername, p->sharename));
971 /* For this printer? Print servers always receive
974 if ( ( p->printer_type == SPLHND_PRINTER ) &&
975 ( !strequal(msg_group->printername, p->sharename) ) )
978 DEBUG(10,("Our printer\n"));
980 /* allocate the max entries possible */
982 notifies = TALLOC_ZERO_ARRAY(mem_ctx, struct spoolss_Notify, msg_group->num_msgs);
987 /* build the array of change notifications */
989 sending_msg_count = 0;
991 for ( i=0; i<msg_group->num_msgs; i++ ) {
992 SPOOLSS_NOTIFY_MSG *msg = &messages[i];
994 /* Are we monitoring this event? */
996 if (!is_monitoring_event(p, msg->type, msg->field))
1002 DEBUG(10,("process_notify2_message: Sending message type [0x%x] field [0x%2x] for printer [%s]\n",
1003 msg->type, msg->field, p->sharename));
1006 * if the is a printer notification handle and not a job notification
1007 * type, then set the id to 0. Other wise just use what was specified
1010 * When registering change notification on a print server handle
1011 * we always need to send back the id (snum) matching the printer
1012 * for which the change took place. For change notify registered
1013 * on a printer handle, this does not matter and the id should be 0.
1018 if ( ( p->printer_type == SPLHND_PRINTER ) && ( msg->type == PRINTER_NOTIFY_TYPE ) )
1024 /* Convert unix jobid to smb jobid */
1026 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1027 id = sysjob_to_jobid(msg->id);
1030 DEBUG(3, ("no such unix jobid %d\n", msg->id));
1035 construct_info_data( ¬ifies[count], msg->type, msg->field, id );
1038 case PRINTER_NOTIFY_TYPE:
1039 if ( printer_notify_table[msg->field].fn )
1040 printer_notify_table[msg->field].fn(msg, ¬ifies[count], mem_ctx);
1043 case JOB_NOTIFY_TYPE:
1044 if ( job_notify_table[msg->field].fn )
1045 job_notify_table[msg->field].fn(msg, ¬ifies[count], mem_ctx);
1049 DEBUG(5, ("Unknown notification type %d\n", msg->type));
1056 if ( sending_msg_count ) {
1059 union spoolss_ReplyPrinterInfo info;
1060 struct spoolss_NotifyInfo info0;
1061 uint32_t reply_result;
1063 info0.version = 0x2;
1064 info0.flags = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
1065 info0.count = count;
1066 info0.notifies = notifies;
1068 info.info0 = &info0;
1070 status = rpccli_spoolss_RouterReplyPrinterEx(notify_cli_pipe, mem_ctx,
1071 &p->notify.client_hnd,
1072 p->notify.change, /* color */
1075 0, /* reply_type, must be 0 */
1078 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) {
1079 DEBUG(1,("RouterReplyPrinterEx to client: %s failed: %s\n",
1080 notify_cli_pipe->srv_name_slash,
1083 switch (reply_result) {
1086 case PRINTER_NOTIFY_INFO_DISCARDED:
1087 case PRINTER_NOTIFY_INFO_DISCARDNOTED:
1088 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
1097 DEBUG(8,("send_notify2_changes: Exit...\n"));
1101 /***********************************************************************
1102 **********************************************************************/
1104 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1107 uint32 tv_sec, tv_usec;
1110 /* Unpack message */
1112 offset += tdb_unpack((uint8 *)buf + offset, len - offset, "f",
1115 offset += tdb_unpack((uint8 *)buf + offset, len - offset, "ddddddd",
1117 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1120 tdb_unpack((uint8 *)buf + offset, len - offset, "dd",
1121 &msg->notify.value[0], &msg->notify.value[1]);
1123 tdb_unpack((uint8 *)buf + offset, len - offset, "B",
1124 &msg->len, &msg->notify.data);
1126 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1127 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1129 tv->tv_sec = tv_sec;
1130 tv->tv_usec = tv_usec;
1133 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1134 msg->notify.value[1]));
1136 dump_data(3, (uint8 *)msg->notify.data, msg->len);
1141 /********************************************************************
1142 Receive a notify2 message list
1143 ********************************************************************/
1145 static void receive_notify2_message_list(struct messaging_context *msg,
1148 struct server_id server_id,
1151 size_t msg_count, i;
1152 char *buf = (char *)data->data;
1155 SPOOLSS_NOTIFY_MSG notify;
1156 SPOOLSS_NOTIFY_MSG_CTR messages;
1159 if (data->length < 4) {
1160 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1164 msg_count = IVAL(buf, 0);
1167 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1169 if (msg_count == 0) {
1170 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1174 /* initialize the container */
1176 ZERO_STRUCT( messages );
1177 notify_msg_ctr_init( &messages );
1180 * build message groups for each printer identified
1181 * in a change_notify msg. Remember that a PCN message
1182 * includes the handle returned for the srv_spoolss_replyopenprinter()
1183 * call. Therefore messages are grouped according to printer handle.
1186 for ( i=0; i<msg_count; i++ ) {
1187 struct timeval msg_tv;
1189 if (msg_ptr + 4 - buf > data->length) {
1190 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1194 msg_len = IVAL(msg_ptr,0);
1197 if (msg_ptr + msg_len - buf > data->length) {
1198 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1202 /* unpack messages */
1204 ZERO_STRUCT( notify );
1205 notify2_unpack_msg( ¬ify, &msg_tv, msg_ptr, msg_len );
1208 /* add to correct list in container */
1210 notify_msg_ctr_addmsg( &messages, ¬ify );
1212 /* free memory that might have been allocated by notify2_unpack_msg() */
1214 if ( notify.len != 0 )
1215 SAFE_FREE( notify.notify.data );
1218 /* process each group of messages */
1220 num_groups = notify_msg_ctr_numgroups( &messages );
1221 for ( i=0; i<num_groups; i++ )
1222 send_notify2_changes( &messages, i );
1227 DEBUG(10,("receive_notify2_message_list: processed %u messages\n", (uint32)msg_count ));
1229 notify_msg_ctr_destroy( &messages );
1234 /********************************************************************
1235 Send a message to ourself about new driver being installed
1236 so we can upgrade the information for each printer bound to this
1238 ********************************************************************/
1240 static bool srv_spoolss_drv_upgrade_printer(char* drivername)
1242 int len = strlen(drivername);
1247 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1250 messaging_send_buf(smbd_messaging_context(), procid_self(),
1251 MSG_PRINTER_DRVUPGRADE,
1252 (uint8 *)drivername, len+1);
1257 /**********************************************************************
1258 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1259 over all printers, upgrading ones as necessary
1260 **********************************************************************/
1262 void do_drv_upgrade_printer(struct messaging_context *msg,
1265 struct server_id server_id,
1270 int n_services = lp_numservices();
1273 len = MIN(data->length,sizeof(drivername)-1);
1274 strncpy(drivername, (const char *)data->data, len);
1276 DEBUG(10,("do_drv_upgrade_printer: Got message for new driver [%s]\n", drivername ));
1278 /* Iterate the printer list */
1280 for (snum=0; snum<n_services; snum++)
1282 if (lp_snum_ok(snum) && lp_print_ok(snum) )
1285 NT_PRINTER_INFO_LEVEL *printer = NULL;
1287 result = get_a_printer(NULL, &printer, 2, lp_const_servicename(snum));
1288 if (!W_ERROR_IS_OK(result))
1291 if (printer && printer->info_2 && !strcmp(drivername, printer->info_2->drivername))
1293 DEBUG(6,("Updating printer [%s]\n", printer->info_2->printername));
1295 /* all we care about currently is the change_id */
1297 result = mod_a_printer(printer, 2);
1298 if (!W_ERROR_IS_OK(result)) {
1299 DEBUG(3,("do_drv_upgrade_printer: mod_a_printer() failed with status [%s]\n",
1300 win_errstr(result)));
1304 free_a_printer(&printer, 2);
1311 /********************************************************************
1312 Update the cache for all printq's with a registered client
1314 ********************************************************************/
1316 void update_monitored_printq_cache( void )
1318 Printer_entry *printer = printers_list;
1321 /* loop through all printers and update the cache where
1322 client_connected == True */
1325 if ( (printer->printer_type == SPLHND_PRINTER)
1326 && printer->notify.client_connected )
1328 snum = print_queue_snum(printer->sharename);
1329 print_queue_status( snum, NULL, NULL );
1332 printer = printer->next;
1337 /********************************************************************
1338 Send a message to ourself about new driver being installed
1339 so we can upgrade the information for each printer bound to this
1341 ********************************************************************/
1343 static bool srv_spoolss_reset_printerdata(char* drivername)
1345 int len = strlen(drivername);
1350 DEBUG(10,("srv_spoolss_reset_printerdata: Sending message about resetting printerdata [%s]\n",
1353 messaging_send_buf(smbd_messaging_context(), procid_self(),
1354 MSG_PRINTERDATA_INIT_RESET,
1355 (uint8 *)drivername, len+1);
1360 /**********************************************************************
1361 callback to receive a MSG_PRINTERDATA_INIT_RESET message and interate
1362 over all printers, resetting printer data as neessary
1363 **********************************************************************/
1365 void reset_all_printerdata(struct messaging_context *msg,
1368 struct server_id server_id,
1373 int n_services = lp_numservices();
1376 len = MIN( data->length, sizeof(drivername)-1 );
1377 strncpy( drivername, (const char *)data->data, len );
1379 DEBUG(10,("reset_all_printerdata: Got message for new driver [%s]\n", drivername ));
1381 /* Iterate the printer list */
1383 for ( snum=0; snum<n_services; snum++ )
1385 if ( lp_snum_ok(snum) && lp_print_ok(snum) )
1388 NT_PRINTER_INFO_LEVEL *printer = NULL;
1390 result = get_a_printer( NULL, &printer, 2, lp_const_servicename(snum) );
1391 if ( !W_ERROR_IS_OK(result) )
1395 * if the printer is bound to the driver,
1396 * then reset to the new driver initdata
1399 if ( printer && printer->info_2 && !strcmp(drivername, printer->info_2->drivername) )
1401 DEBUG(6,("reset_all_printerdata: Updating printer [%s]\n", printer->info_2->printername));
1403 if ( !set_driver_init(printer, 2) ) {
1404 DEBUG(5,("reset_all_printerdata: Error resetting printer data for printer [%s], driver [%s]!\n",
1405 printer->info_2->printername, printer->info_2->drivername));
1408 result = mod_a_printer( printer, 2 );
1409 if ( !W_ERROR_IS_OK(result) ) {
1410 DEBUG(3,("reset_all_printerdata: mod_a_printer() failed! (%s)\n",
1411 get_dos_error_msg(result)));
1415 free_a_printer( &printer, 2 );
1424 /****************************************************************
1425 _spoolss_OpenPrinter
1426 ****************************************************************/
1428 WERROR _spoolss_OpenPrinter(pipes_struct *p,
1429 struct spoolss_OpenPrinter *r)
1431 struct spoolss_OpenPrinterEx e;
1434 ZERO_STRUCT(e.in.userlevel);
1436 e.in.printername = r->in.printername;
1437 e.in.datatype = r->in.datatype;
1438 e.in.devmode_ctr = r->in.devmode_ctr;
1439 e.in.access_mask = r->in.access_mask;
1442 e.out.handle = r->out.handle;
1444 werr = _spoolss_OpenPrinterEx(p, &e);
1446 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1447 /* OpenPrinterEx returns this for a bad
1448 * printer name. We must return WERR_INVALID_PRINTER_NAME
1451 werr = WERR_INVALID_PRINTER_NAME;
1457 /********************************************************************
1458 FIXME: temporary convert_devicemode_new function
1459 ********************************************************************/
1461 static bool convert_devicemode_new(const char *printername,
1462 struct spoolss_DeviceMode *devmode,
1463 NT_DEVICEMODE **pp_nt_devmode)
1465 NT_DEVICEMODE *nt_devmode = *pp_nt_devmode;
1468 * Ensure nt_devmode is a valid pointer
1469 * as we will be overwriting it.
1472 if (nt_devmode == NULL) {
1473 DEBUG(5, ("convert_devicemode_new: allocating a generic devmode\n"));
1474 if ((nt_devmode = construct_nt_devicemode(printername)) == NULL)
1478 rpcstr_push(nt_devmode->devicename, devmode->devicename, 31, 0);
1479 rpcstr_push(nt_devmode->formname, devmode->formname, 31, 0);
1481 nt_devmode->specversion = devmode->specversion;
1482 nt_devmode->driverversion = devmode->driverversion;
1483 nt_devmode->size = devmode->size;
1484 nt_devmode->fields = devmode->fields;
1485 nt_devmode->orientation = devmode->orientation;
1486 nt_devmode->papersize = devmode->papersize;
1487 nt_devmode->paperlength = devmode->paperlength;
1488 nt_devmode->paperwidth = devmode->paperwidth;
1489 nt_devmode->scale = devmode->scale;
1490 nt_devmode->copies = devmode->copies;
1491 nt_devmode->defaultsource = devmode->defaultsource;
1492 nt_devmode->printquality = devmode->printquality;
1493 nt_devmode->color = devmode->color;
1494 nt_devmode->duplex = devmode->duplex;
1495 nt_devmode->yresolution = devmode->yresolution;
1496 nt_devmode->ttoption = devmode->ttoption;
1497 nt_devmode->collate = devmode->collate;
1499 nt_devmode->logpixels = devmode->logpixels;
1500 nt_devmode->bitsperpel = devmode->bitsperpel;
1501 nt_devmode->pelswidth = devmode->pelswidth;
1502 nt_devmode->pelsheight = devmode->pelsheight;
1503 nt_devmode->displayflags = devmode->displayflags;
1504 nt_devmode->displayfrequency = devmode->displayfrequency;
1505 nt_devmode->icmmethod = devmode->icmmethod;
1506 nt_devmode->icmintent = devmode->icmintent;
1507 nt_devmode->mediatype = devmode->mediatype;
1508 nt_devmode->dithertype = devmode->dithertype;
1509 nt_devmode->reserved1 = devmode->reserved1;
1510 nt_devmode->reserved2 = devmode->reserved2;
1511 nt_devmode->panningwidth = devmode->panningwidth;
1512 nt_devmode->panningheight = devmode->panningheight;
1515 * Only change private and driverextra if the incoming devmode
1516 * has a new one. JRA.
1519 if ((devmode->__driverextra_length != 0) && (devmode->driverextra_data.data != NULL)) {
1520 SAFE_FREE(nt_devmode->nt_dev_private);
1521 nt_devmode->driverextra = devmode->__driverextra_length;
1522 if((nt_devmode->nt_dev_private=SMB_MALLOC_ARRAY(uint8, nt_devmode->driverextra)) == NULL)
1524 memcpy(nt_devmode->nt_dev_private, devmode->driverextra_data.data, nt_devmode->driverextra);
1527 *pp_nt_devmode = nt_devmode;
1532 /****************************************************************
1533 _spoolss_OpenPrinterEx
1534 ****************************************************************/
1536 WERROR _spoolss_OpenPrinterEx(pipes_struct *p,
1537 struct spoolss_OpenPrinterEx *r)
1539 POLICY_HND *handle = r->out.handle;
1540 char *name = CONST_DISCARD(char *, r->in.printername);
1542 Printer_entry *Printer=NULL;
1545 return WERR_INVALID_PARAM;
1548 /* some sanity check because you can open a printer or a print server */
1549 /* aka: \\server\printer or \\server */
1551 DEBUGADD(3,("checking name: %s\n",name));
1553 if (!open_printer_hnd(p, handle, name, 0)) {
1554 ZERO_STRUCTP(r->out.handle);
1555 return WERR_INVALID_PARAM;
1558 Printer=find_printer_index_by_hnd(p, handle);
1560 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1561 "handle we created for printer %s\n", name ));
1562 close_printer_handle(p,handle);
1563 ZERO_STRUCTP(r->out.handle);
1564 return WERR_INVALID_PARAM;
1568 * First case: the user is opening the print server:
1570 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1571 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1573 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1574 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1575 * or if the user is listed in the smb.conf printer admin parameter.
1577 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1578 * client view printer folder, but does not show the MSAPW.
1580 * Note: this test needs code to check access rights here too. Jeremy
1581 * could you look at this?
1583 * Second case: the user is opening a printer:
1584 * NT doesn't let us connect to a printer if the connecting user
1585 * doesn't have print permission.
1587 * Third case: user is opening a Port Monitor
1588 * access checks same as opening a handle to the print server.
1591 switch (Printer->printer_type )
1594 case SPLHND_PORTMON_TCP:
1595 case SPLHND_PORTMON_LOCAL:
1596 /* Printserver handles use global struct... */
1600 /* Map standard access rights to object specific access rights */
1602 se_map_standard(&r->in.access_mask,
1603 &printserver_std_mapping);
1605 /* Deny any object specific bits that don't apply to print
1606 servers (i.e printer and job specific bits) */
1608 r->in.access_mask &= SPECIFIC_RIGHTS_MASK;
1610 if (r->in.access_mask &
1611 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1612 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1613 close_printer_handle(p, handle);
1614 ZERO_STRUCTP(r->out.handle);
1615 return WERR_ACCESS_DENIED;
1618 /* Allow admin access */
1620 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1622 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1624 if (!lp_ms_add_printer_wizard()) {
1625 close_printer_handle(p, handle);
1626 ZERO_STRUCTP(r->out.handle);
1627 return WERR_ACCESS_DENIED;
1630 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1631 and not a printer admin, then fail */
1633 if ((p->server_info->utok.uid != 0) &&
1634 !user_has_privileges(p->server_info->ptok,
1636 !token_contains_name_in_list(
1637 uidtoname(p->server_info->utok.uid),
1639 p->server_info->ptok,
1640 lp_printer_admin(snum))) {
1641 close_printer_handle(p, handle);
1642 ZERO_STRUCTP(r->out.handle);
1643 return WERR_ACCESS_DENIED;
1646 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1650 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1653 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1654 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1656 /* We fall through to return WERR_OK */
1659 case SPLHND_PRINTER:
1660 /* NT doesn't let us connect to a printer if the connecting user
1661 doesn't have print permission. */
1663 if (!get_printer_snum(p, handle, &snum, NULL)) {
1664 close_printer_handle(p, handle);
1665 ZERO_STRUCTP(r->out.handle);
1669 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1671 /* map an empty access mask to the minimum access mask */
1672 if (r->in.access_mask == 0x0)
1673 r->in.access_mask = PRINTER_ACCESS_USE;
1676 * If we are not serving the printer driver for this printer,
1677 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1678 * will keep NT clients happy --jerry
1681 if (lp_use_client_driver(snum)
1682 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1684 r->in.access_mask = PRINTER_ACCESS_USE;
1687 /* check smb.conf parameters and the the sec_desc */
1689 if ( !check_access(get_client_fd(), lp_hostsallow(snum), lp_hostsdeny(snum)) ) {
1690 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1691 ZERO_STRUCTP(r->out.handle);
1692 return WERR_ACCESS_DENIED;
1695 if (!user_ok_token(uidtoname(p->server_info->utok.uid), NULL,
1696 p->server_info->ptok, snum) ||
1697 !print_access_check(p->server_info, snum,
1698 r->in.access_mask)) {
1699 DEBUG(3, ("access DENIED for printer open\n"));
1700 close_printer_handle(p, handle);
1701 ZERO_STRUCTP(r->out.handle);
1702 return WERR_ACCESS_DENIED;
1705 if ((r->in.access_mask & SPECIFIC_RIGHTS_MASK)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1706 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1707 close_printer_handle(p, handle);
1708 ZERO_STRUCTP(r->out.handle);
1709 return WERR_ACCESS_DENIED;
1712 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1713 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1715 r->in.access_mask = PRINTER_ACCESS_USE;
1717 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1718 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1723 /* sanity check to prevent programmer error */
1724 ZERO_STRUCTP(r->out.handle);
1728 Printer->access_granted = r->in.access_mask;
1731 * If the client sent a devmode in the OpenPrinter() call, then
1732 * save it here in case we get a job submission on this handle
1735 if ( (Printer->printer_type != SPLHND_SERVER)
1736 && r->in.devmode_ctr.devmode )
1738 convert_devicemode_new(Printer->sharename,
1739 r->in.devmode_ctr.devmode,
1740 &Printer->nt_devmode);
1743 #if 0 /* JERRY -- I'm doubtful this is really effective */
1744 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1745 optimization in Windows 2000 clients --jerry */
1747 if ( (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1748 && (RA_WIN2K == get_remote_arch()) )
1750 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1751 sys_usleep( 500000 );
1758 /****************************************************************************
1759 ****************************************************************************/
1761 static bool printer_info2_to_nt_printer_info2(struct spoolss_SetPrinterInfo2 *r,
1762 NT_PRINTER_INFO_LEVEL_2 *d)
1764 DEBUG(7,("printer_info2_to_nt_printer_info2\n"));
1770 d->attributes = r->attributes;
1771 d->priority = r->priority;
1772 d->default_priority = r->defaultpriority;
1773 d->starttime = r->starttime;
1774 d->untiltime = r->untiltime;
1775 d->status = r->status;
1776 d->cjobs = r->cjobs;
1778 fstrcpy(d->servername, r->servername);
1779 fstrcpy(d->printername, r->printername);
1780 fstrcpy(d->sharename, r->sharename);
1781 fstrcpy(d->portname, r->portname);
1782 fstrcpy(d->drivername, r->drivername);
1783 slprintf(d->comment, sizeof(d->comment)-1, "%s", r->comment);
1784 fstrcpy(d->location, r->location);
1785 fstrcpy(d->sepfile, r->sepfile);
1786 fstrcpy(d->printprocessor, r->printprocessor);
1787 fstrcpy(d->datatype, r->datatype);
1788 fstrcpy(d->parameters, r->parameters);
1793 /****************************************************************************
1794 ****************************************************************************/
1796 static bool convert_printer_info_new(struct spoolss_SetPrinterInfoCtr *info_ctr,
1797 NT_PRINTER_INFO_LEVEL *printer)
1801 switch (info_ctr->level) {
1803 /* allocate memory if needed. Messy because
1804 convert_printer_info is used to update an existing
1805 printer or build a new one */
1807 if (!printer->info_2) {
1808 printer->info_2 = TALLOC_ZERO_P(printer, NT_PRINTER_INFO_LEVEL_2);
1809 if (!printer->info_2) {
1810 DEBUG(0,("convert_printer_info_new: "
1811 "talloc() failed!\n"));
1816 ret = printer_info2_to_nt_printer_info2(info_ctr->info.info2,
1818 printer->info_2->setuptime = time(NULL);
1825 /*******************************************************************
1826 ********************************************************************/
1828 static bool string_array_to_fstring_array(const char **sarray, fstring **farray)
1837 *farray = SMB_MALLOC_ARRAY(fstring, 1);
1842 for (i=0; sarray[i] != NULL; i++) {
1843 *farray = SMB_REALLOC_ARRAY(*farray, fstring, i+2);
1847 fstrcpy((*farray)[i], sarray[i]);
1850 fstrcpy((*farray)[i], "");
1855 /*******************************************************************
1856 ********************************************************************/
1858 static bool driver_info3_to_nt_driver_info3(struct spoolss_AddDriverInfo3 *r,
1859 NT_PRINTER_DRIVER_INFO_LEVEL_3 **p)
1861 NT_PRINTER_DRIVER_INFO_LEVEL_3 *d;
1863 DEBUG(7,("driver_info3_to_nt_driver_info3: Converting from UNICODE to ASCII\n"));
1866 *p = SMB_MALLOC_P(NT_PRINTER_DRIVER_INFO_LEVEL_3);
1875 d->cversion = r->version;
1877 fstrcpy(d->name, r->driver_name);
1878 fstrcpy(d->environment, r->architecture);
1879 fstrcpy(d->driverpath, r->driver_path);
1880 fstrcpy(d->datafile, r->data_file);
1881 fstrcpy(d->configfile, r->config_file);
1882 fstrcpy(d->helpfile, r->help_file);
1883 fstrcpy(d->monitorname, r->monitor_name);
1884 fstrcpy(d->defaultdatatype, r->default_datatype);
1886 DEBUGADD(8,( "version: %d\n", d->cversion));
1887 DEBUGADD(8,( "name: %s\n", d->name));
1888 DEBUGADD(8,( "environment: %s\n", d->environment));
1889 DEBUGADD(8,( "driverpath: %s\n", d->driverpath));
1890 DEBUGADD(8,( "datafile: %s\n", d->datafile));
1891 DEBUGADD(8,( "configfile: %s\n", d->configfile));
1892 DEBUGADD(8,( "helpfile: %s\n", d->helpfile));
1893 DEBUGADD(8,( "monitorname: %s\n", d->monitorname));
1894 DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
1896 if (r->dependent_files) {
1897 if (!string_array_to_fstring_array(r->dependent_files->string,
1898 &d->dependentfiles)) {
1907 /*******************************************************************
1908 ********************************************************************/
1910 static bool driver_info6_to_nt_driver_info6(struct spoolss_AddDriverInfo6 *r,
1911 NT_PRINTER_DRIVER_INFO_LEVEL_6 **p)
1913 NT_PRINTER_DRIVER_INFO_LEVEL_6 *d;
1915 DEBUG(7,("driver_info6_to_nt_driver_info6: Converting from UNICODE to ASCII\n"));
1918 *p = SMB_MALLOC_P(NT_PRINTER_DRIVER_INFO_LEVEL_6);
1927 d->version = r->version;
1929 fstrcpy(d->name, r->driver_name);
1930 fstrcpy(d->environment, r->architecture);
1931 fstrcpy(d->driverpath, r->driver_path);
1932 fstrcpy(d->datafile, r->data_file);
1933 fstrcpy(d->configfile, r->config_file);
1934 fstrcpy(d->helpfile, r->help_file);
1935 fstrcpy(d->monitorname, r->monitor_name);
1936 fstrcpy(d->defaultdatatype, r->default_datatype);
1938 DEBUGADD(8,( "version: %d\n", d->version));
1939 DEBUGADD(8,( "name: %s\n", d->name));
1940 DEBUGADD(8,( "environment: %s\n", d->environment));
1941 DEBUGADD(8,( "driverpath: %s\n", d->driverpath));
1942 DEBUGADD(8,( "datafile: %s\n", d->datafile));
1943 DEBUGADD(8,( "configfile: %s\n", d->configfile));
1944 DEBUGADD(8,( "helpfile: %s\n", d->helpfile));
1945 DEBUGADD(8,( "monitorname: %s\n", d->monitorname));
1946 DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
1948 if (r->dependent_files) {
1949 if (!string_array_to_fstring_array(r->dependent_files->string,
1950 &d->dependentfiles)) {
1955 if (r->previous_names) {
1956 if (!string_array_to_fstring_array(r->previous_names->string,
1957 &d->previousnames)) {
1969 /********************************************************************
1970 ********************************************************************/
1972 static bool convert_printer_driver_info(const struct spoolss_AddDriverInfoCtr *r,
1973 NT_PRINTER_DRIVER_INFO_LEVEL *printer,
1978 printer->info_3 = NULL;
1979 if (!driver_info3_to_nt_driver_info3(r->info.info3, &printer->info_3)) {
1984 printer->info_6 = NULL;
1985 if (!driver_info6_to_nt_driver_info6(r->info.info6, &printer->info_6)) {
1996 bool convert_devicemode(const char *printername, const DEVICEMODE *devmode,
1997 NT_DEVICEMODE **pp_nt_devmode)
1999 NT_DEVICEMODE *nt_devmode = *pp_nt_devmode;
2002 * Ensure nt_devmode is a valid pointer
2003 * as we will be overwriting it.
2006 if (nt_devmode == NULL) {
2007 DEBUG(5, ("convert_devicemode: allocating a generic devmode\n"));
2008 if ((nt_devmode = construct_nt_devicemode(printername)) == NULL)
2012 rpcstr_pull(nt_devmode->devicename,devmode->devicename.buffer, 31, -1, 0);
2013 rpcstr_pull(nt_devmode->formname,devmode->formname.buffer, 31, -1, 0);
2015 nt_devmode->specversion=devmode->specversion;
2016 nt_devmode->driverversion=devmode->driverversion;
2017 nt_devmode->size=devmode->size;
2018 nt_devmode->fields=devmode->fields;
2019 nt_devmode->orientation=devmode->orientation;
2020 nt_devmode->papersize=devmode->papersize;
2021 nt_devmode->paperlength=devmode->paperlength;
2022 nt_devmode->paperwidth=devmode->paperwidth;
2023 nt_devmode->scale=devmode->scale;
2024 nt_devmode->copies=devmode->copies;
2025 nt_devmode->defaultsource=devmode->defaultsource;
2026 nt_devmode->printquality=devmode->printquality;
2027 nt_devmode->color=devmode->color;
2028 nt_devmode->duplex=devmode->duplex;
2029 nt_devmode->yresolution=devmode->yresolution;
2030 nt_devmode->ttoption=devmode->ttoption;
2031 nt_devmode->collate=devmode->collate;
2033 nt_devmode->logpixels=devmode->logpixels;
2034 nt_devmode->bitsperpel=devmode->bitsperpel;
2035 nt_devmode->pelswidth=devmode->pelswidth;
2036 nt_devmode->pelsheight=devmode->pelsheight;
2037 nt_devmode->displayflags=devmode->displayflags;
2038 nt_devmode->displayfrequency=devmode->displayfrequency;
2039 nt_devmode->icmmethod=devmode->icmmethod;
2040 nt_devmode->icmintent=devmode->icmintent;
2041 nt_devmode->mediatype=devmode->mediatype;
2042 nt_devmode->dithertype=devmode->dithertype;
2043 nt_devmode->reserved1=devmode->reserved1;
2044 nt_devmode->reserved2=devmode->reserved2;
2045 nt_devmode->panningwidth=devmode->panningwidth;
2046 nt_devmode->panningheight=devmode->panningheight;
2049 * Only change private and driverextra if the incoming devmode
2050 * has a new one. JRA.
2053 if ((devmode->driverextra != 0) && (devmode->dev_private != NULL)) {
2054 SAFE_FREE(nt_devmode->nt_dev_private);
2055 nt_devmode->driverextra=devmode->driverextra;
2056 if((nt_devmode->nt_dev_private=SMB_MALLOC_ARRAY(uint8, nt_devmode->driverextra)) == NULL)
2058 memcpy(nt_devmode->nt_dev_private, devmode->dev_private, nt_devmode->driverextra);
2061 *pp_nt_devmode = nt_devmode;
2066 /********************************************************************
2067 * _spoolss_enddocprinter_internal.
2068 ********************************************************************/
2070 static WERROR _spoolss_enddocprinter_internal(pipes_struct *p, POLICY_HND *handle)
2072 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
2076 DEBUG(2,("_spoolss_enddocprinter_internal: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle)));
2080 if (!get_printer_snum(p, handle, &snum, NULL))
2083 Printer->document_started=False;
2084 print_job_end(snum, Printer->jobid,NORMAL_CLOSE);
2085 /* error codes unhandled so far ... */
2090 /****************************************************************
2091 _spoolss_ClosePrinter
2092 ****************************************************************/
2094 WERROR _spoolss_ClosePrinter(pipes_struct *p,
2095 struct spoolss_ClosePrinter *r)
2097 POLICY_HND *handle = r->in.handle;
2099 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
2101 if (Printer && Printer->document_started)
2102 _spoolss_enddocprinter_internal(p, handle); /* print job was not closed */
2104 if (!close_printer_handle(p, handle))
2107 /* clear the returned printer handle. Observed behavior
2108 from Win2k server. Don't think this really matters.
2109 Previous code just copied the value of the closed
2112 ZERO_STRUCTP(r->out.handle);
2117 /****************************************************************
2118 _spoolss_DeletePrinter
2119 ****************************************************************/
2121 WERROR _spoolss_DeletePrinter(pipes_struct *p,
2122 struct spoolss_DeletePrinter *r)
2124 POLICY_HND *handle = r->in.handle;
2125 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
2128 if (Printer && Printer->document_started)
2129 _spoolss_enddocprinter_internal(p, handle); /* print job was not closed */
2131 result = delete_printer_handle(p, handle);
2133 update_c_setprinter(False);
2138 /*******************************************************************
2139 * static function to lookup the version id corresponding to an
2140 * long architecture string
2141 ******************************************************************/
2143 static int get_version_id (char * arch)
2146 struct table_node archi_table[]= {
2148 {"Windows 4.0", "WIN40", 0 },
2149 {"Windows NT x86", "W32X86", 2 },
2150 {"Windows NT R4000", "W32MIPS", 2 },
2151 {"Windows NT Alpha_AXP", "W32ALPHA", 2 },
2152 {"Windows NT PowerPC", "W32PPC", 2 },
2153 {"Windows IA64", "IA64", 3 },
2154 {"Windows x64", "x64", 3 },
2158 for (i=0; archi_table[i].long_archi != NULL; i++)
2160 if (strcmp(arch, archi_table[i].long_archi) == 0)
2161 return (archi_table[i].version);
2167 /****************************************************************
2168 _spoolss_DeletePrinterDriver
2169 ****************************************************************/
2171 WERROR _spoolss_DeletePrinterDriver(pipes_struct *p,
2172 struct spoolss_DeletePrinterDriver *r)
2176 NT_PRINTER_DRIVER_INFO_LEVEL info;
2177 NT_PRINTER_DRIVER_INFO_LEVEL info_win2k;
2180 WERROR status_win2k = WERR_ACCESS_DENIED;
2181 SE_PRIV se_printop = SE_PRINT_OPERATOR;
2183 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2184 and not a printer admin, then fail */
2186 if ( (p->server_info->utok.uid != 0)
2187 && !user_has_privileges(p->server_info->ptok, &se_printop )
2188 && !token_contains_name_in_list(
2189 uidtoname(p->server_info->utok.uid), NULL,
2190 NULL, p->server_info->ptok,
2191 lp_printer_admin(-1)) )
2193 return WERR_ACCESS_DENIED;
2196 driver = CONST_DISCARD(char *, r->in.driver);
2197 arch = CONST_DISCARD(char *, r->in.architecture);
2199 /* check that we have a valid driver name first */
2201 if ((version=get_version_id(arch)) == -1)
2202 return WERR_INVALID_ENVIRONMENT;
2205 ZERO_STRUCT(info_win2k);
2207 if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, driver, arch, version)))
2209 /* try for Win2k driver if "Windows NT x86" */
2211 if ( version == 2 ) {
2213 if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, driver, arch, version))) {
2214 status = WERR_UNKNOWN_PRINTER_DRIVER;
2218 /* otherwise it was a failure */
2220 status = WERR_UNKNOWN_PRINTER_DRIVER;
2226 if (printer_driver_in_use(info.info_3)) {
2227 status = WERR_PRINTER_DRIVER_IN_USE;
2233 if (W_ERROR_IS_OK(get_a_printer_driver(&info_win2k, 3, driver, arch, 3)))
2235 /* if we get to here, we now have 2 driver info structures to remove */
2236 /* remove the Win2k driver first*/
2238 status_win2k = delete_printer_driver(
2239 p, info_win2k.info_3, 3, False );
2240 free_a_printer_driver( info_win2k, 3 );
2242 /* this should not have failed---if it did, report to client */
2243 if ( !W_ERROR_IS_OK(status_win2k) )
2245 status = status_win2k;
2251 status = delete_printer_driver(p, info.info_3, version, False);
2253 /* if at least one of the deletes succeeded return OK */
2255 if ( W_ERROR_IS_OK(status) || W_ERROR_IS_OK(status_win2k) )
2259 free_a_printer_driver( info, 3 );
2264 /****************************************************************
2265 _spoolss_DeletePrinterDriverEx
2266 ****************************************************************/
2268 WERROR _spoolss_DeletePrinterDriverEx(pipes_struct *p,
2269 struct spoolss_DeletePrinterDriverEx *r)
2273 NT_PRINTER_DRIVER_INFO_LEVEL info;
2274 NT_PRINTER_DRIVER_INFO_LEVEL info_win2k;
2276 uint32_t flags = r->in.delete_flags;
2279 WERROR status_win2k = WERR_ACCESS_DENIED;
2280 SE_PRIV se_printop = SE_PRINT_OPERATOR;
2282 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2283 and not a printer admin, then fail */
2285 if ( (p->server_info->utok.uid != 0)
2286 && !user_has_privileges(p->server_info->ptok, &se_printop )
2287 && !token_contains_name_in_list(
2288 uidtoname(p->server_info->utok.uid), NULL, NULL,
2289 p->server_info->ptok, lp_printer_admin(-1)) )
2291 return WERR_ACCESS_DENIED;
2294 driver = CONST_DISCARD(char *, r->in.driver);
2295 arch = CONST_DISCARD(char *, r->in.architecture);
2297 /* check that we have a valid driver name first */
2298 if ((version=get_version_id(arch)) == -1) {
2299 /* this is what NT returns */
2300 return WERR_INVALID_ENVIRONMENT;
2303 if ( flags & DPD_DELETE_SPECIFIC_VERSION )
2304 version = r->in.version;
2307 ZERO_STRUCT(info_win2k);
2309 status = get_a_printer_driver(&info, 3, driver, arch, version);
2311 if ( !W_ERROR_IS_OK(status) )
2314 * if the client asked for a specific version,
2315 * or this is something other than Windows NT x86,
2319 if ( (flags&DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
2322 /* try for Win2k driver if "Windows NT x86" */
2325 if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, driver, arch, version))) {
2326 status = WERR_UNKNOWN_PRINTER_DRIVER;
2331 if ( printer_driver_in_use(info.info_3) ) {
2332 status = WERR_PRINTER_DRIVER_IN_USE;
2337 * we have a couple of cases to consider.
2338 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
2339 * then the delete should fail if **any** files overlap with
2341 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
2342 * non-overlapping files
2343 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
2344 * is set, the do not delete any files
2345 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2348 delete_files = flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
2350 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
2352 if ( delete_files && printer_driver_files_in_use(info.info_3) & (flags&DPD_DELETE_ALL_FILES) ) {
2353 /* no idea of the correct error here */
2354 status = WERR_ACCESS_DENIED;
2359 /* also check for W32X86/3 if necessary; maybe we already have? */
2361 if ( (version == 2) && ((flags&DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
2362 if (W_ERROR_IS_OK(get_a_printer_driver(&info_win2k, 3, driver, arch, 3)))
2365 if ( delete_files && printer_driver_files_in_use(info_win2k.info_3) & (flags&DPD_DELETE_ALL_FILES) ) {
2366 /* no idea of the correct error here */
2367 free_a_printer_driver( info_win2k, 3 );
2368 status = WERR_ACCESS_DENIED;
2372 /* if we get to here, we now have 2 driver info structures to remove */
2373 /* remove the Win2k driver first*/
2375 status_win2k = delete_printer_driver(
2376 p, info_win2k.info_3, 3, delete_files);
2377 free_a_printer_driver( info_win2k, 3 );
2379 /* this should not have failed---if it did, report to client */
2381 if ( !W_ERROR_IS_OK(status_win2k) )
2386 status = delete_printer_driver(p, info.info_3, version, delete_files);
2388 if ( W_ERROR_IS_OK(status) || W_ERROR_IS_OK(status_win2k) )
2391 free_a_printer_driver( info, 3 );
2397 /****************************************************************************
2398 Internal routine for retreiving printerdata
2399 ***************************************************************************/
2401 static WERROR get_printer_dataex( TALLOC_CTX *ctx, NT_PRINTER_INFO_LEVEL *printer,
2402 const char *key, const char *value, uint32 *type, uint8 **data,
2403 uint32 *needed, uint32 in_size )
2405 REGISTRY_VALUE *val;
2409 if ( !(val = get_printer_data( printer->info_2, key, value)) )
2410 return WERR_BADFILE;
2412 *type = regval_type( val );
2414 DEBUG(5,("get_printer_dataex: allocating %d\n", in_size));
2416 size = regval_size( val );
2418 /* copy the min(in_size, len) */
2421 data_len = (size > in_size) ? in_size : size*sizeof(uint8);
2423 /* special case for 0 length values */
2425 if ( (*data = (uint8 *)TALLOC_MEMDUP(ctx, regval_data_p(val), data_len)) == NULL )
2429 if ( (*data = (uint8 *)TALLOC_ZERO(ctx, in_size)) == NULL )
2438 DEBUG(5,("get_printer_dataex: copy done\n"));
2443 /****************************************************************************
2444 Internal routine for removing printerdata
2445 ***************************************************************************/
2447 static WERROR delete_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char *key, const char *value )
2449 return delete_printer_data( printer->info_2, key, value );
2452 /****************************************************************************
2453 Internal routine for storing printerdata
2454 ***************************************************************************/
2456 WERROR set_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char *key, const char *value,
2457 uint32 type, uint8 *data, int real_len )
2459 /* the registry objects enforce uniqueness based on value name */
2461 return add_printer_data( printer->info_2, key, value, type, data, real_len );
2464 /********************************************************************
2465 GetPrinterData on a printer server Handle.
2466 ********************************************************************/
2468 static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint32 *type, uint8 **data, uint32 *needed, uint32 in_size)
2472 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2474 if (!StrCaseCmp(value, "W3SvcInstalled")) {
2476 if ( !(*data = TALLOC_ARRAY(ctx, uint8, sizeof(uint32) )) )
2478 SIVAL(*data, 0, 0x00);
2483 if (!StrCaseCmp(value, "BeepEnabled")) {
2485 if ( !(*data = TALLOC_ARRAY(ctx, uint8, sizeof(uint32) )) )
2487 SIVAL(*data, 0, 0x00);
2492 if (!StrCaseCmp(value, "EventLog")) {
2494 if ( !(*data = TALLOC_ARRAY(ctx, uint8, sizeof(uint32) )) )
2496 /* formally was 0x1b */
2497 SIVAL(*data, 0, 0x0);
2502 if (!StrCaseCmp(value, "NetPopup")) {
2504 if ( !(*data = TALLOC_ARRAY(ctx, uint8, sizeof(uint32) )) )
2506 SIVAL(*data, 0, 0x00);
2511 if (!StrCaseCmp(value, "MajorVersion")) {
2513 if ( !(*data = TALLOC_ARRAY(ctx, uint8, sizeof(uint32) )) )
2516 /* Windows NT 4.0 seems to not allow uploading of drivers
2517 to a server that reports 0x3 as the MajorVersion.
2518 need to investigate more how Win2k gets around this .
2521 if ( RA_WINNT == get_remote_arch() )
2530 if (!StrCaseCmp(value, "MinorVersion")) {
2532 if ( !(*data = TALLOC_ARRAY(ctx, uint8, sizeof(uint32) )) )
2540 * uint32 size = 0x114
2542 * uint32 minor = [0|1]
2543 * uint32 build = [2195|2600]
2544 * extra unicode string = e.g. "Service Pack 3"
2546 if (!StrCaseCmp(value, "OSVersion")) {
2550 if ( !(*data = TALLOC_ZERO_ARRAY(ctx, uint8, (*needed > in_size) ? *needed:in_size )) )
2553 SIVAL(*data, 0, *needed); /* size */
2554 SIVAL(*data, 4, 5); /* Windows 2000 == 5.0 */
2556 SIVAL(*data, 12, 2195); /* build */
2558 /* leave extra string empty */
2564 if (!StrCaseCmp(value, "DefaultSpoolDirectory")) {
2565 const char *string="C:\\PRINTERS";
2567 *needed = 2*(strlen(string)+1);
2568 if((*data = (uint8 *)TALLOC(ctx, (*needed > in_size) ? *needed:in_size )) == NULL)
2570 memset(*data, 0, (*needed > in_size) ? *needed:in_size);
2572 /* it's done by hand ready to go on the wire */
2573 for (i=0; i<strlen(string); i++) {
2574 (*data)[2*i]=string[i];
2575 (*data)[2*i+1]='\0';
2580 if (!StrCaseCmp(value, "Architecture")) {
2581 const char *string="Windows NT x86";
2583 *needed = 2*(strlen(string)+1);
2584 if((*data = (uint8 *)TALLOC(ctx, (*needed > in_size) ? *needed:in_size )) == NULL)
2586 memset(*data, 0, (*needed > in_size) ? *needed:in_size);
2587 for (i=0; i<strlen(string); i++) {
2588 (*data)[2*i]=string[i];
2589 (*data)[2*i+1]='\0';
2594 if (!StrCaseCmp(value, "DsPresent")) {
2596 if ( !(*data = TALLOC_ARRAY(ctx, uint8, sizeof(uint32) )) )
2599 /* only show the publish check box if we are a
2600 memeber of a AD domain */
2602 if ( lp_security() == SEC_ADS )
2603 SIVAL(*data, 0, 0x01);
2605 SIVAL(*data, 0, 0x00);
2611 if (!StrCaseCmp(value, "DNSMachineName")) {
2612 const char *hostname = get_mydnsfullname();
2615 return WERR_BADFILE;
2617 *needed = 2*(strlen(hostname)+1);
2618 if((*data = (uint8 *)TALLOC(ctx, (*needed > in_size) ? *needed:in_size )) == NULL)
2620 memset(*data, 0, (*needed > in_size) ? *needed:in_size);
2621 for (i=0; i<strlen(hostname); i++) {
2622 (*data)[2*i]=hostname[i];
2623 (*data)[2*i+1]='\0';
2629 return WERR_BADFILE;
2632 /********************************************************************
2633 * spoolss_getprinterdata
2634 ********************************************************************/
2636 WERROR _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPOOL_R_GETPRINTERDATA *r_u)
2638 POLICY_HND *handle = &q_u->handle;
2639 UNISTR2 *valuename = &q_u->valuename;
2640 uint32 in_size = q_u->size;
2641 uint32 *type = &r_u->type;
2642 uint32 *out_size = &r_u->size;
2643 uint8 **data = &r_u->data;
2644 uint32 *needed = &r_u->needed;
2647 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
2648 NT_PRINTER_INFO_LEVEL *printer = NULL;
2652 * Reminder: when it's a string, the length is in BYTES
2653 * even if UNICODE is negociated.
2658 *out_size = in_size;
2660 /* in case of problem, return some default values */
2665 DEBUG(4,("_spoolss_getprinterdata\n"));
2668 DEBUG(2,("_spoolss_getprinterdata: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
2669 status = WERR_BADFID;
2673 unistr2_to_ascii(value, valuename, sizeof(value));
2675 if ( Printer->printer_type == SPLHND_SERVER )
2676 status = getprinterdata_printer_server( p->mem_ctx, value, type, data, needed, *out_size );
2679 if ( !get_printer_snum(p,handle, &snum, NULL) ) {
2680 status = WERR_BADFID;
2684 status = get_a_printer(Printer, &printer, 2, lp_servicename(snum));
2685 if ( !W_ERROR_IS_OK(status) )
2688 /* XP sends this and wants to change id value from the PRINTER_INFO_0 */
2690 if ( strequal(value, "ChangeId") ) {
2692 *needed = sizeof(uint32);
2693 if ( (*data = (uint8*)TALLOC(p->mem_ctx, sizeof(uint32))) == NULL) {
2694 status = WERR_NOMEM;
2697 SIVAL( *data, 0, printer->info_2->changeid );
2701 status = get_printer_dataex( p->mem_ctx, printer, SPOOL_PRINTERDATA_KEY, value, type, data, needed, *out_size );
2704 if (*needed > *out_size)
2705 status = WERR_MORE_DATA;
2708 if ( !W_ERROR_IS_OK(status) )
2710 DEBUG(5, ("error %d: allocating %d\n", W_ERROR_V(status),*out_size));
2712 /* reply this param doesn't exist */
2715 if((*data=(uint8 *)TALLOC_ZERO_ARRAY(p->mem_ctx, uint8, *out_size)) == NULL) {
2717 free_a_printer( &printer, 2 );
2725 /* cleanup & exit */
2728 free_a_printer( &printer, 2 );
2733 /*********************************************************
2734 Connect to the client machine.
2735 **********************************************************/
2737 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2738 struct sockaddr_storage *client_ss, const char *remote_machine)
2741 struct cli_state *the_cli;
2742 struct sockaddr_storage rm_addr;
2744 if ( is_zero_addr((struct sockaddr *)client_ss) ) {
2745 if ( !resolve_name( remote_machine, &rm_addr, 0x20) ) {
2746 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2750 if (ismyaddr((struct sockaddr *)&rm_addr)) {
2751 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n", remote_machine));
2755 char addr[INET6_ADDRSTRLEN];
2756 rm_addr = *client_ss;
2757 print_sockaddr(addr, sizeof(addr), &rm_addr);
2758 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2762 /* setup the connection */
2764 ret = cli_full_connection( &the_cli, global_myname(), remote_machine,
2765 &rm_addr, 0, "IPC$", "IPC",
2769 0, lp_client_signing(), NULL );
2771 if ( !NT_STATUS_IS_OK( ret ) ) {
2772 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2777 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2778 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2779 cli_shutdown(the_cli);
2784 * Ok - we have an anonymous connection to the IPC$ share.
2785 * Now start the NT Domain stuff :-).
2788 ret = cli_rpc_pipe_open_noauth(the_cli, &syntax_spoolss, pp_pipe);
2789 if (!NT_STATUS_IS_OK(ret)) {
2790 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2791 remote_machine, nt_errstr(ret)));
2792 cli_shutdown(the_cli);
2799 /***************************************************************************
2800 Connect to the client.
2801 ****************************************************************************/
2803 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2804 uint32 localprinter, uint32 type,
2805 POLICY_HND *handle, struct sockaddr_storage *client_ss)
2811 * If it's the first connection, contact the client
2812 * and connect to the IPC$ share anonymously
2814 if (smb_connections==0) {
2815 fstring unix_printer;
2817 fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */
2819 if ( !spoolss_connect_to_client( ¬ify_cli_pipe, client_ss, unix_printer ))
2822 messaging_register(smbd_messaging_context(), NULL,
2823 MSG_PRINTER_NOTIFY2,
2824 receive_notify2_message_list);
2825 /* Tell the connections db we're now interested in printer
2826 * notify messages. */
2827 register_message_flags( True, FLAG_MSG_PRINT_NOTIFY );
2831 * Tell the specific printing tdb we want messages for this printer
2832 * by registering our PID.
2835 if (!print_notify_register_pid(snum))
2836 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", printer ));
2840 status = rpccli_spoolss_ReplyOpenPrinter(notify_cli_pipe, talloc_tos(),
2848 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
2849 DEBUG(5,("srv_spoolss_reply_open_printer: Client RPC returned [%s]\n",
2850 win_errstr(result)));
2852 return (W_ERROR_IS_OK(result));
2855 /****************************************************************
2856 ****************************************************************/
2858 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2859 const struct spoolss_NotifyOption *r)
2861 struct spoolss_NotifyOption *option;
2868 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2875 if (!option->count) {
2879 option->types = talloc_zero_array(option,
2880 struct spoolss_NotifyOptionType, option->count);
2881 if (!option->types) {
2882 talloc_free(option);
2886 for (i=0; i < option->count; i++) {
2887 option->types[i] = r->types[i];
2889 if (option->types[i].count) {
2890 option->types[i].fields = talloc_zero_array(option,
2891 enum spoolss_Field, option->types[i].count);
2892 if (!option->types[i].fields) {
2893 talloc_free(option);
2896 for (k=0; k<option->types[i].count; k++) {
2897 option->types[i].fields[k] =
2898 r->types[i].fields[k];
2906 /****************************************************************
2907 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2909 * before replying OK: status=0 a rpc call is made to the workstation
2910 * asking ReplyOpenPrinter
2912 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2913 * called from api_spoolss_rffpcnex
2914 ****************************************************************/
2916 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(pipes_struct *p,
2917 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2919 POLICY_HND *handle = r->in.handle;
2921 struct spoolss_NotifyOption *option = r->in.notify_options;
2922 struct sockaddr_storage client_ss;
2924 /* store the notify value in the printer struct */
2926 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
2929 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2930 "Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
2934 Printer->notify.flags = r->in.flags;
2935 Printer->notify.options = r->in.options;
2936 Printer->notify.printerlocal = r->in.printer_local;
2938 TALLOC_FREE(Printer->notify.option);
2939 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2941 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2943 /* Connect to the client machine and send a ReplyOpenPrinter */
2945 if ( Printer->printer_type == SPLHND_SERVER)
2947 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2948 !get_printer_snum(p, handle, &snum, NULL) )
2951 if (!interpret_string_addr(&client_ss, p->client_address,
2953 return WERR_SERVER_UNAVAILABLE;
2956 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2957 Printer->notify.printerlocal, 1,
2958 &Printer->notify.client_hnd, &client_ss))
2959 return WERR_SERVER_UNAVAILABLE;
2961 Printer->notify.client_connected=True;
2966 /*******************************************************************
2967 * fill a notify_info_data with the servername
2968 ********************************************************************/
2970 void spoolss_notify_server_name(int snum,
2971 struct spoolss_Notify *data,
2972 print_queue_struct *queue,
2973 NT_PRINTER_INFO_LEVEL *printer,
2974 TALLOC_CTX *mem_ctx)
2976 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->servername);
2979 /*******************************************************************
2980 * fill a notify_info_data with the printername (not including the servername).
2981 ********************************************************************/
2983 void spoolss_notify_printer_name(int snum,
2984 struct spoolss_Notify *data,
2985 print_queue_struct *queue,
2986 NT_PRINTER_INFO_LEVEL *printer,
2987 TALLOC_CTX *mem_ctx)
2989 /* the notify name should not contain the \\server\ part */
2990 char *p = strrchr(printer->info_2->printername, '\\');
2993 p = printer->info_2->printername;
2998 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
3001 /*******************************************************************
3002 * fill a notify_info_data with the servicename
3003 ********************************************************************/
3005 void spoolss_notify_share_name(int snum,
3006 struct spoolss_Notify *data,
3007 print_queue_struct *queue,
3008 NT_PRINTER_INFO_LEVEL *printer,
3009 TALLOC_CTX *mem_ctx)
3011 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
3014 /*******************************************************************
3015 * fill a notify_info_data with the port name
3016 ********************************************************************/
3018 void spoolss_notify_port_name(int snum,
3019 struct spoolss_Notify *data,
3020 print_queue_struct *queue,
3021 NT_PRINTER_INFO_LEVEL *printer,
3022 TALLOC_CTX *mem_ctx)
3024 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->portname);
3027 /*******************************************************************
3028 * fill a notify_info_data with the printername
3029 * but it doesn't exist, have to see what to do
3030 ********************************************************************/
3032 void spoolss_notify_driver_name(int snum,
3033 struct spoolss_Notify *data,
3034 print_queue_struct *queue,
3035 NT_PRINTER_INFO_LEVEL *printer,
3036 TALLOC_CTX *mem_ctx)
3038 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->drivername);
3041 /*******************************************************************
3042 * fill a notify_info_data with the comment
3043 ********************************************************************/
3045 void spoolss_notify_comment(int snum,
3046 struct spoolss_Notify *data,
3047 print_queue_struct *queue,
3048 NT_PRINTER_INFO_LEVEL *printer,
3049 TALLOC_CTX *mem_ctx)
3053 if (*printer->info_2->comment == '\0') {
3054 p = lp_comment(snum);
3056 p = printer->info_2->comment;
3059 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->comment);
3062 /*******************************************************************
3063 * fill a notify_info_data with the comment
3064 * location = "Room 1, floor 2, building 3"
3065 ********************************************************************/
3067 void spoolss_notify_location(int snum,
3068 struct spoolss_Notify *data,
3069 print_queue_struct *queue,
3070 NT_PRINTER_INFO_LEVEL *printer,
3071 TALLOC_CTX *mem_ctx)
3073 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->location);
3076 /*******************************************************************
3077 * fill a notify_info_data with the device mode
3078 * jfm:xxxx don't to it for know but that's a real problem !!!
3079 ********************************************************************/
3081 static void spoolss_notify_devmode(int snum,
3082 struct spoolss_Notify *data,
3083 print_queue_struct *queue,
3084 NT_PRINTER_INFO_LEVEL *printer,
3085 TALLOC_CTX *mem_ctx)
3087 /* for a dummy implementation we have to zero the fields */
3088 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
3091 /*******************************************************************
3092 * fill a notify_info_data with the separator file name
3093 ********************************************************************/
3095 void spoolss_notify_sepfile(int snum,
3096 struct spoolss_Notify *data,
3097 print_queue_struct *queue,
3098 NT_PRINTER_INFO_LEVEL *printer,
3099 TALLOC_CTX *mem_ctx)
3101 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->sepfile);
3104 /*******************************************************************
3105 * fill a notify_info_data with the print processor
3106 * jfm:xxxx return always winprint to indicate we don't do anything to it
3107 ********************************************************************/
3109 void spoolss_notify_print_processor(int snum,
3110 struct spoolss_Notify *data,
3111 print_queue_struct *queue,
3112 NT_PRINTER_INFO_LEVEL *printer,
3113 TALLOC_CTX *mem_ctx)
3115 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->printprocessor);
3118 /*******************************************************************
3119 * fill a notify_info_data with the print processor options
3120 * jfm:xxxx send an empty string
3121 ********************************************************************/
3123 void spoolss_notify_parameters(int snum,
3124 struct spoolss_Notify *data,
3125 print_queue_struct *queue,
3126 NT_PRINTER_INFO_LEVEL *printer,
3127 TALLOC_CTX *mem_ctx)
3129 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->parameters);
3132 /*******************************************************************
3133 * fill a notify_info_data with the data type
3134 * jfm:xxxx always send RAW as data type
3135 ********************************************************************/
3137 void spoolss_notify_datatype(int snum,
3138 struct spoolss_Notify *data,
3139 print_queue_struct *queue,
3140 NT_PRINTER_INFO_LEVEL *printer,
3141 TALLOC_CTX *mem_ctx)
3143 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->datatype);
3146 /*******************************************************************
3147 * fill a notify_info_data with the security descriptor
3148 * jfm:xxxx send an null pointer to say no security desc
3149 * have to implement security before !
3150 ********************************************************************/
3152 static void spoolss_notify_security_desc(int snum,
3153 struct spoolss_Notify *data,
3154 print_queue_struct *queue,
3155 NT_PRINTER_INFO_LEVEL *printer,
3156 TALLOC_CTX *mem_ctx)
3158 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data,
3159 printer->info_2->secdesc_buf->sd_size,
3160 printer->info_2->secdesc_buf->sd);
3163 /*******************************************************************
3164 * fill a notify_info_data with the attributes
3165 * jfm:xxxx a samba printer is always shared
3166 ********************************************************************/
3168 void spoolss_notify_attributes(int snum,
3169 struct spoolss_Notify *data,
3170 print_queue_struct *queue,
3171 NT_PRINTER_INFO_LEVEL *printer,
3172 TALLOC_CTX *mem_ctx)
3174 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->attributes);
3177 /*******************************************************************
3178 * fill a notify_info_data with the priority
3179 ********************************************************************/
3181 static void spoolss_notify_priority(int snum,
3182 struct spoolss_Notify *data,
3183 print_queue_struct *queue,
3184 NT_PRINTER_INFO_LEVEL *printer,
3185 TALLOC_CTX *mem_ctx)
3187 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->priority);
3190 /*******************************************************************
3191 * fill a notify_info_data with the default priority
3192 ********************************************************************/
3194 static void spoolss_notify_default_priority(int snum,
3195 struct spoolss_Notify *data,
3196 print_queue_struct *queue,
3197 NT_PRINTER_INFO_LEVEL *printer,
3198 TALLOC_CTX *mem_ctx)
3200 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->default_priority);
3203 /*******************************************************************
3204 * fill a notify_info_data with the start time
3205 ********************************************************************/
3207 static void spoolss_notify_start_time(int snum,
3208 struct spoolss_Notify *data,
3209 print_queue_struct *queue,
3210 NT_PRINTER_INFO_LEVEL *printer,
3211 TALLOC_CTX *mem_ctx)
3213 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->starttime);
3216 /*******************************************************************
3217 * fill a notify_info_data with the until time
3218 ********************************************************************/
3220 static void spoolss_notify_until_time(int snum,
3221 struct spoolss_Notify *data,
3222 print_queue_struct *queue,
3223 NT_PRINTER_INFO_LEVEL *printer,
3224 TALLOC_CTX *mem_ctx)
3226 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->untiltime);
3229 /*******************************************************************
3230 * fill a notify_info_data with the status
3231 ********************************************************************/
3233 static void spoolss_notify_status(int snum,
3234 struct spoolss_Notify *data,
3235 print_queue_struct *queue,
3236 NT_PRINTER_INFO_LEVEL *printer,
3237 TALLOC_CTX *mem_ctx)
3239 print_status_struct status;
3241 print_queue_length(snum, &status);
3242 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
3245 /*******************************************************************
3246 * fill a notify_info_data with the number of jobs queued
3247 ********************************************************************/
3249 void spoolss_notify_cjobs(int snum,
3250 struct spoolss_Notify *data,
3251 print_queue_struct *queue,
3252 NT_PRINTER_INFO_LEVEL *printer,
3253 TALLOC_CTX *mem_ctx)
3255 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, print_queue_length(snum, NULL));
3258 /*******************************************************************
3259 * fill a notify_info_data with the average ppm
3260 ********************************************************************/
3262 static void spoolss_notify_average_ppm(int snum,
3263 struct spoolss_Notify *data,
3264 print_queue_struct *queue,
3265 NT_PRINTER_INFO_LEVEL *printer,
3266 TALLOC_CTX *mem_ctx)
3268 /* always respond 8 pages per minutes */
3269 /* a little hard ! */
3270 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->averageppm);
3273 /*******************************************************************
3274 * fill a notify_info_data with username
3275 ********************************************************************/
3277 static void spoolss_notify_username(int snum,
3278 struct spoolss_Notify *data,
3279 print_queue_struct *queue,
3280 NT_PRINTER_INFO_LEVEL *printer,
3281 TALLOC_CTX *mem_ctx)
3283 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
3286 /*******************************************************************
3287 * fill a notify_info_data with job status
3288 ********************************************************************/
3290 static void spoolss_notify_job_status(int snum,
3291 struct spoolss_Notify *data,
3292 print_queue_struct *queue,
3293 NT_PRINTER_INFO_LEVEL *printer,
3294 TALLOC_CTX *mem_ctx)
3296 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
3299 /*******************************************************************
3300 * fill a notify_info_data with job name
3301 ********************************************************************/
3303 static void spoolss_notify_job_name(int snum,
3304 struct spoolss_Notify *data,
3305 print_queue_struct *queue,
3306 NT_PRINTER_INFO_LEVEL *printer,
3307 TALLOC_CTX *mem_ctx)
3309 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
3312 /*******************************************************************
3313 * fill a notify_info_data with job status
3314 ********************************************************************/
3316 static void spoolss_notify_job_status_string(int snum,
3317 struct spoolss_Notify *data,
3318 print_queue_struct *queue,
3319 NT_PRINTER_INFO_LEVEL *printer,
3320 TALLOC_CTX *mem_ctx)
3323 * Now we're returning job status codes we just return a "" here. JRA.
3328 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3331 switch (queue->status) {
3336 p = ""; /* NT provides the paused string */
3345 #endif /* NO LONGER NEEDED. */
3347 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
3350 /*******************************************************************
3351 * fill a notify_info_data with job time
3352 ********************************************************************/
3354 static void spoolss_notify_job_time(int snum,
3355 struct spoolss_Notify *data,
3356 print_queue_struct *queue,
3357 NT_PRINTER_INFO_LEVEL *printer,
3358 TALLOC_CTX *mem_ctx)
3360 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3363 /*******************************************************************
3364 * fill a notify_info_data with job size
3365 ********************************************************************/
3367 static void spoolss_notify_job_size(int snum,
3368 struct spoolss_Notify *data,
3369 print_queue_struct *queue,
3370 NT_PRINTER_INFO_LEVEL *printer,
3371 TALLOC_CTX *mem_ctx)
3373 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
3376 /*******************************************************************
3377 * fill a notify_info_data with page info
3378 ********************************************************************/
3379 static void spoolss_notify_total_pages(int snum,
3380 struct spoolss_Notify *data,
3381 print_queue_struct *queue,
3382 NT_PRINTER_INFO_LEVEL *printer,
3383 TALLOC_CTX *mem_ctx)
3385 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
3388 /*******************************************************************
3389 * fill a notify_info_data with pages printed info.
3390 ********************************************************************/
3391 static void spoolss_notify_pages_printed(int snum,
3392 struct spoolss_Notify *data,
3393 print_queue_struct *queue,
3394 NT_PRINTER_INFO_LEVEL *printer,
3395 TALLOC_CTX *mem_ctx)
3397 /* Add code when back-end tracks this */
3398 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3401 /*******************************************************************
3402 Fill a notify_info_data with job position.
3403 ********************************************************************/
3405 static void spoolss_notify_job_position(int snum,
3406 struct spoolss_Notify *data,
3407 print_queue_struct *queue,
3408 NT_PRINTER_INFO_LEVEL *printer,
3409 TALLOC_CTX *mem_ctx)
3411 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
3414 /*******************************************************************
3415 Fill a notify_info_data with submitted time.
3416 ********************************************************************/
3418 static void spoolss_notify_submitted_time(int snum,
3419 struct spoolss_Notify *data,
3420 print_queue_struct *queue,
3421 NT_PRINTER_INFO_LEVEL *printer,
3422 TALLOC_CTX *mem_ctx)
3424 data->data.string.string = NULL;
3425 data->data.string.size = 0;
3427 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
3428 &data->data.string.string,
3429 &data->data.string.size);
3433 struct s_notify_info_data_table
3435 enum spoolss_NotifyType type;
3436 enum spoolss_Field field;
3438 enum spoolss_NotifyTable variable_type;
3439 void (*fn) (int snum, struct spoolss_Notify *data,
3440 print_queue_struct *queue,
3441 NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx);
3444 /* A table describing the various print notification constants and
3445 whether the notification data is a pointer to a variable sized
3446 buffer, a one value uint32 or a two value uint32. */
3448 static const struct s_notify_info_data_table notify_info_data_table[] =
3450 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SERVER_NAME, "PRINTER_NOTIFY_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3451 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINTER_NAME, "PRINTER_NOTIFY_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3452 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SHARE_NAME, "PRINTER_NOTIFY_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
3453 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PORT_NAME, "PRINTER_NOTIFY_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3454 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DRIVER_NAME, "PRINTER_NOTIFY_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3455 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_COMMENT, "PRINTER_NOTIFY_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
3456 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_LOCATION, "PRINTER_NOTIFY_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
3457 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DEVMODE, "PRINTER_NOTIFY_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3458 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SEPFILE, "PRINTER_NOTIFY_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
3459 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINT_PROCESSOR, "PRINTER_NOTIFY_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3460 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PARAMETERS, "PRINTER_NOTIFY_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3461 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DATATYPE, "PRINTER_NOTIFY_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3462 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
3463 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_ATTRIBUTES, "PRINTER_NOTIFY_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
3464 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRIORITY, "PRINTER_NOTIFY_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3465 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DEFAULT_PRIORITY, "PRINTER_NOTIFY_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
3466 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_START_TIME, "PRINTER_NOTIFY_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3467 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_UNTIL_TIME, "PRINTER_NOTIFY_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3468 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_STATUS, "PRINTER_NOTIFY_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
3469 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_STATUS_STRING, "PRINTER_NOTIFY_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
3470 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_CJOBS, "PRINTER_NOTIFY_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
3471 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_AVERAGE_PPM, "PRINTER_NOTIFY_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
3472 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_PAGES, "PRINTER_NOTIFY_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
3473 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PAGES_PRINTED, "PRINTER_NOTIFY_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3474 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_BYTES, "PRINTER_NOTIFY_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
3475 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_BYTES_PRINTED, "PRINTER_NOTIFY_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3476 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINTER_NAME, "JOB_NOTIFY_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3477 { JOB_NOTIFY_TYPE, JOB_NOTIFY_MACHINE_NAME, "JOB_NOTIFY_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3478 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PORT_NAME, "JOB_NOTIFY_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3479 { JOB_NOTIFY_TYPE, JOB_NOTIFY_USER_NAME, "JOB_NOTIFY_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3480 { JOB_NOTIFY_TYPE, JOB_NOTIFY_NOTIFY_NAME, "JOB_NOTIFY_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3481 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DATATYPE, "JOB_NOTIFY_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3482 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINT_PROCESSOR, "JOB_NOTIFY_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3483 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PARAMETERS, "JOB_NOTIFY_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3484 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DRIVER_NAME, "JOB_NOTIFY_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3485 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DEVMODE, "JOB_NOTIFY_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3486 { JOB_NOTIFY_TYPE, JOB_NOTIFY_STATUS, "JOB_NOTIFY_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
3487 { JOB_NOTIFY_TYPE, JOB_NOTIFY_STATUS_STRING, "JOB_NOTIFY_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
3488 { JOB_NOTIFY_TYPE, JOB_NOTIFY_SECURITY_DESCRIPTOR, "JOB_NOTIFY_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
3489 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DOCUMENT, "JOB_NOTIFY_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
3490 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRIORITY, "JOB_NOTIFY_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3491 { JOB_NOTIFY_TYPE, JOB_NOTIFY_POSITION, "JOB_NOTIFY_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
3492 { JOB_NOTIFY_TYPE, JOB_NOTIFY_SUBMITTED, "JOB_NOTIFY_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
3493 { JOB_NOTIFY_TYPE, JOB_NOTIFY_START_TIME, "JOB_NOTIFY_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3494 { JOB_NOTIFY_TYPE, JOB_NOTIFY_UNTIL_TIME, "JOB_NOTIFY_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3495 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TIME, "JOB_NOTIFY_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
3496 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_PAGES, "JOB_NOTIFY_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
3497 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PAGES_PRINTED, "JOB_NOTIFY_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
3498 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_BYTES, "JOB_NOTIFY_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
3501 /*******************************************************************
3502 Return the variable_type of info_data structure.
3503 ********************************************************************/
3505 static uint32_t variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3506 enum spoolss_Field field)
3510 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3511 if ( (notify_info_data_table[i].type == type) &&
3512 (notify_info_data_table[i].field == field) ) {
3513 return notify_info_data_table[i].variable_type;
3517 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3522 /****************************************************************************
3523 ****************************************************************************/
3525 static bool search_notify(enum spoolss_NotifyType type,
3526 enum spoolss_Field field,
3531 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3532 if (notify_info_data_table[i].type == type &&
3533 notify_info_data_table[i].field == field &&
3534 notify_info_data_table[i].fn != NULL) {
3543 /****************************************************************************
3544 ****************************************************************************/
3546 void construct_info_data(struct spoolss_Notify *info_data,
3547 enum spoolss_NotifyType type,
3548 enum spoolss_Field field,
3551 info_data->type = type;
3552 info_data->field = field;
3553 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3554 info_data->job_id = id;
3557 /*******************************************************************
3559 * fill a notify_info struct with info asked
3561 ********************************************************************/
3563 static bool construct_notify_printer_info(Printer_entry *print_hnd,
3564 struct spoolss_NotifyInfo *info,
3566 const struct spoolss_NotifyOptionType *option_type,
3568 TALLOC_CTX *mem_ctx)
3571 enum spoolss_NotifyType type;
3572 enum spoolss_Field field;
3574 struct spoolss_Notify *current_data;
3575 NT_PRINTER_INFO_LEVEL *printer = NULL;
3576 print_queue_struct *queue=NULL;
3578 type = option_type->type;
3580 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3581 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3582 option_type->count, lp_servicename(snum)));
3584 if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &printer, 2, lp_const_servicename(snum))))
3587 for(field_num=0; field_num < option_type->count; field_num++) {
3588 field = option_type->fields[field_num];
3590 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3592 if (!search_notify(type, field, &j) )
3595 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3596 struct spoolss_Notify,
3598 if (info->notifies == NULL) {
3599 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3600 free_a_printer(&printer, 2);
3604 current_data = &info->notifies[info->count];
3606 construct_info_data(current_data, type, field, id);
3608 DEBUG(10,("construct_notify_printer_info: calling [%s] snum=%d printername=[%s])\n",
3609 notify_info_data_table[j].name, snum, printer->info_2->printername ));
3611 notify_info_data_table[j].fn(snum, current_data, queue,
3617 free_a_printer(&printer, 2);
3621 /*******************************************************************
3623 * fill a notify_info struct with info asked
3625 ********************************************************************/
3627 static bool construct_notify_jobs_info(print_queue_struct *queue,
3628 struct spoolss_NotifyInfo *info,
3629 NT_PRINTER_INFO_LEVEL *printer,
3631 const struct spoolss_NotifyOptionType *option_type,
3633 TALLOC_CTX *mem_ctx)
3636 enum spoolss_NotifyType type;
3637 enum spoolss_Field field;
3638 struct spoolss_Notify *current_data;
3640 DEBUG(4,("construct_notify_jobs_info\n"));
3642 type = option_type->type;
3644 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3645 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3646 option_type->count));
3648 for(field_num=0; field_num<option_type->count; field_num++) {
3649 field = option_type->fields[field_num];
3651 if (!search_notify(type, field, &j) )
3654 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3655 struct spoolss_Notify,
3657 if (info->notifies == NULL) {
3658 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3662 current_data=&(info->notifies[info->count]);
3664 construct_info_data(current_data, type, field, id);
3665 notify_info_data_table[j].fn(snum, current_data, queue,
3674 * JFM: The enumeration is not that simple, it's even non obvious.
3676 * let's take an example: I want to monitor the PRINTER SERVER for
3677 * the printer's name and the number of jobs currently queued.
3678 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3679 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3681 * I have 3 printers on the back of my server.
3683 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3686 * 1 printer 1 name 1
3687 * 2 printer 1 cjob 1
3688 * 3 printer 2 name 2
3689 * 4 printer 2 cjob 2
3690 * 5 printer 3 name 3
3691 * 6 printer 3 name 3
3693 * that's the print server case, the printer case is even worse.
3696 /*******************************************************************
3698 * enumerate all printers on the printserver
3699 * fill a notify_info struct with info asked
3701 ********************************************************************/
3703 static WERROR printserver_notify_info(pipes_struct *p, POLICY_HND *hnd,
3704 struct spoolss_NotifyInfo *info,
3705 TALLOC_CTX *mem_ctx)
3708 Printer_entry *Printer=find_printer_index_by_hnd(p, hnd);
3709 int n_services=lp_numservices();
3711 struct spoolss_NotifyOption *option;
3712 struct spoolss_NotifyOptionType option_type;
3714 DEBUG(4,("printserver_notify_info\n"));
3719 option = Printer->notify.option;
3722 info->notifies = NULL;
3725 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3726 sending a ffpcn() request first */
3731 for (i=0; i<option->count; i++) {
3732 option_type = option->types[i];
3734 if (option_type.type != PRINTER_NOTIFY_TYPE)
3737 for (snum=0; snum<n_services; snum++)
3739 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
3740 construct_notify_printer_info ( Printer, info, snum, &option_type, snum, mem_ctx );
3746 * Debugging information, don't delete.
3749 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3750 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3751 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3753 for (i=0; i<info->count; i++) {
3754 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3755 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3756 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3763 /*******************************************************************
3765 * fill a notify_info struct with info asked
3767 ********************************************************************/
3769 static WERROR printer_notify_info(pipes_struct *p, POLICY_HND *hnd, struct spoolss_NotifyInfo *info,
3770 TALLOC_CTX *mem_ctx)
3773 Printer_entry *Printer=find_printer_index_by_hnd(p, hnd);
3776 struct spoolss_NotifyOption *option;
3777 struct spoolss_NotifyOptionType option_type;
3779 print_queue_struct *queue=NULL;
3780 print_status_struct status;
3782 DEBUG(4,("printer_notify_info\n"));
3787 option = Printer->notify.option;
3791 info->notifies = NULL;
3794 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3795 sending a ffpcn() request first */
3800 get_printer_snum(p, hnd, &snum, NULL);
3802 for (i=0; i<option->count; i++) {
3803 option_type = option->types[i];
3805 switch (option_type.type) {
3806 case PRINTER_NOTIFY_TYPE:
3807 if(construct_notify_printer_info(Printer, info, snum,
3813 case JOB_NOTIFY_TYPE: {
3814 NT_PRINTER_INFO_LEVEL *printer = NULL;
3816 count = print_queue_status(snum, &queue, &status);
3818 if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum))))
3821 for (j=0; j<count; j++) {
3822 construct_notify_jobs_info(&queue[j], info,
3829 free_a_printer(&printer, 2);
3839 * Debugging information, don't delete.
3842 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3843 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3844 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3846 for (i=0; i<info->count; i++) {
3847 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3848 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3849 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3855 /****************************************************************
3856 _spoolss_RouterRefreshPrinterChangeNotify
3857 ****************************************************************/
3859 WERROR _spoolss_RouterRefreshPrinterChangeNotify(pipes_struct *p,
3860 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3862 POLICY_HND *handle = r->in.handle;
3863 struct spoolss_NotifyInfo *info;
3865 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
3866 WERROR result = WERR_BADFID;
3868 /* we always have a spoolss_NotifyInfo struct */
3869 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3871 result = WERR_NOMEM;
3875 *r->out.info = info;
3878 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3879 "Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
3883 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3886 * We are now using the change value, and
3887 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3888 * I don't have a global notification system, I'm sending back all the
3889 * informations even when _NOTHING_ has changed.
3892 /* We need to keep track of the change value to send back in
3893 RRPCN replies otherwise our updates are ignored. */
3895 Printer->notify.fnpcn = True;
3897 if (Printer->notify.client_connected) {
3898 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3899 "Saving change value in request [%x]\n",
3901 Printer->notify.change = r->in.change_low;
3904 /* just ignore the spoolss_NotifyOption */
3906 switch (Printer->printer_type) {
3908 result = printserver_notify_info(p, handle, info, p->mem_ctx);
3911 case SPLHND_PRINTER:
3912 result = printer_notify_info(p, handle, info, p->mem_ctx);
3916 Printer->notify.fnpcn = False;
3922 /********************************************************************
3923 * construct_printer_info_0
3924 * fill a printer_info_0 struct
3925 ********************************************************************/
3927 static bool construct_printer_info_0(Printer_entry *print_hnd, PRINTER_INFO_0 *printer, int snum)
3929 char *chaine = NULL;
3931 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
3932 counter_printer_0 *session_counter;
3933 uint32 global_counter;
3936 print_status_struct status;
3937 TALLOC_CTX *ctx = talloc_tos();
3939 if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum))))
3942 init_unistr(&printer->printername, ntprinter->info_2->printername);
3944 chaine = talloc_asprintf(ctx, "\\\\%s", get_server_name(print_hnd));
3946 free_a_printer(&ntprinter,2);
3950 count = print_queue_length(snum, &status);
3952 /* check if we already have a counter for this printer */
3953 for(session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3954 if (session_counter->snum == snum)
3958 init_unistr(&printer->servername, chaine);
3960 /* it's the first time, add it to the list */
3961 if (session_counter==NULL) {
3962 if((session_counter=SMB_MALLOC_P(counter_printer_0)) == NULL) {
3963 free_a_printer(&ntprinter, 2);
3966 ZERO_STRUCTP(session_counter);
3967 session_counter->snum=snum;
3968 session_counter->counter=0;
3969 DLIST_ADD(counter_list, session_counter);
3973 session_counter->counter++;
3976 * the global_counter should be stored in a TDB as it's common to all the clients
3977 * and should be zeroed on samba startup
3979 global_counter=session_counter->counter;
3980 printer->cjobs = count;
3981 printer->total_jobs = 0;
3982 printer->total_bytes = 0;
3984 setuptime = (time_t)ntprinter->info_2->setuptime;
3985 t=gmtime(&setuptime);
3987 printer->year = t->tm_year+1900;
3988 printer->month = t->tm_mon+1;
3989 printer->dayofweek = t->tm_wday;
3990 printer->day = t->tm_mday;
3991 printer->hour = t->tm_hour;
3992 printer->minute = t->tm_min;
3993 printer->second = t->tm_sec;
3994 printer->milliseconds = 0;
3996 printer->global_counter = global_counter;
3997 printer->total_pages = 0;
3999 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
4000 printer->major_version = 0x0005; /* NT 5 */
4001 printer->build_version = 0x0893; /* build 2195 */
4003 printer->unknown7 = 0x1;
4004 printer->unknown8 = 0x0;
4005 printer->unknown9 = 0x0;
4006 printer->session_counter = session_counter->counter;
4007 printer->unknown11 = 0x0;
4008 printer->printer_errors = 0x0; /* number of print failure */
4009 printer->unknown13 = 0x0;
4010 printer->unknown14 = 0x1;
4011 printer->unknown15 = 0x024a; /* 586 Pentium ? */
4012 printer->unknown16 = 0x0;
4013 printer->change_id = ntprinter->info_2->changeid; /* ChangeID in milliseconds*/
4014 printer->unknown18 = 0x0;
4015 printer->status = nt_printq_status(status.status);
4016 printer->unknown20 = 0x0;
4017 printer->c_setprinter = get_c_setprinter(); /* monotonically increasing sum of delta printer counts */
4018 printer->unknown22 = 0x0;
4019 printer->unknown23 = 0x6; /* 6 ???*/
4020 printer->unknown24 = 0; /* unknown 24 to 26 are always 0 */
4021 printer->unknown25 = 0;
4022 printer->unknown26 = 0;
4023 printer->unknown27 = 0;
4024 printer->unknown28 = 0;
4025 printer->unknown29 = 0;
4027 free_a_printer(&ntprinter,2);
4031 /********************************************************************
4032 * construct_printer_info_1
4033 * fill a printer_info_1 struct
4034 ********************************************************************/
4035 static bool construct_printer_info_1(Printer_entry *print_hnd, uint32 flags, PRINTER_INFO_1 *printer, int snum)
4037 char *chaine = NULL;
4038 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
4039 TALLOC_CTX *ctx = talloc_tos();
4041 if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum))))
4044 printer->flags=flags;
4046 if (*ntprinter->info_2->comment == '\0') {
4047 init_unistr(&printer->comment, lp_comment(snum));
4048 chaine = talloc_asprintf(ctx,
4049 "%s,%s,%s", ntprinter->info_2->printername,
4050 ntprinter->info_2->drivername, lp_comment(snum));
4053 init_unistr(&printer->comment, ntprinter->info_2->comment); /* saved comment. */
4054 chaine = talloc_asprintf(ctx,
4055 "%s,%s,%s", ntprinter->info_2->printername,
4056 ntprinter->info_2->drivername, ntprinter->info_2->comment);
4060 free_a_printer(&ntprinter,2);
4064 init_unistr(&printer->description, chaine);
4065 init_unistr(&printer->name, ntprinter->info_2->printername);
4067 free_a_printer(&ntprinter,2);
4072 /****************************************************************************
4073 Free a DEVMODE struct.
4074 ****************************************************************************/
4076 static void free_dev_mode(DEVICEMODE *dev)
4081 SAFE_FREE(dev->dev_private);
4085 /****************************************************************************
4086 Convert an NT_DEVICEMODE to a spoolss_DeviceMode structure. Both pointers
4087 should be valid upon entry
4088 ****************************************************************************/
4090 static WERROR convert_nt_devicemode_new(TALLOC_CTX *mem_ctx,
4091 struct spoolss_DeviceMode *r,
4092 const NT_DEVICEMODE *ntdevmode)
4094 if (!r || !ntdevmode) {
4095 return WERR_INVALID_PARAM;
4098 r->devicename = talloc_strdup(mem_ctx, ntdevmode->devicename);
4099 W_ERROR_HAVE_NO_MEMORY(r->devicename);
4101 r->specversion = ntdevmode->specversion;
4102 r->driverversion = ntdevmode->driverversion;
4103 r->size = ntdevmode->size;
4104 r->__driverextra_length = ntdevmode->driverextra;
4105 r->fields = ntdevmode->fields;
4107 r->orientation = ntdevmode->orientation;
4108 r->papersize = ntdevmode->papersize;
4109 r->paperlength = ntdevmode->paperlength;
4110 r->paperwidth = ntdevmode->paperwidth;
4111 r->scale = ntdevmode->scale;
4112 r->copies = ntdevmode->copies;
4113 r->defaultsource = ntdevmode->defaultsource;
4114 r->printquality = ntdevmode->printquality;
4115 r->color = ntdevmode->color;
4116 r->duplex = ntdevmode->duplex;
4117 r->yresolution = ntdevmode->yresolution;
4118 r->ttoption = ntdevmode->ttoption;
4119 r->collate = ntdevmode->collate;
4121 r->formname = talloc_strdup(mem_ctx, ntdevmode->formname);
4122 W_ERROR_HAVE_NO_MEMORY(r->formname);
4124 /* all 0 below are values that have not been set in the old parsing/copy
4125 * function, maybe they should... - gd */
4131 r->displayflags = 0;
4132 r->displayfrequency = 0;
4133 r->icmmethod = ntdevmode->icmmethod;
4134 r->icmintent = ntdevmode->icmintent;
4135 r->mediatype = ntdevmode->mediatype;
4136 r->dithertype = ntdevmode->dithertype;
4139 r->panningwidth = 0;
4140 r->panningheight = 0;
4142 if (ntdevmode->nt_dev_private != NULL) {
4143 r->driverextra_data = data_blob_talloc(mem_ctx,
4144 ntdevmode->nt_dev_private,
4145 ntdevmode->driverextra);
4146 W_ERROR_HAVE_NO_MEMORY(r->driverextra_data.data);
4153 /****************************************************************************
4154 Convert an NT_DEVICEMODE to a DEVICEMODE structure. Both pointers
4155 should be valid upon entry
4156 ****************************************************************************/
4158 static bool convert_nt_devicemode( DEVICEMODE *devmode, NT_DEVICEMODE *ntdevmode )
4160 if ( !devmode || !ntdevmode )
4163 init_unistr(&devmode->devicename, ntdevmode->devicename);
4165 init_unistr(&devmode->formname, ntdevmode->formname);
4167 devmode->specversion = ntdevmode->specversion;
4168 devmode->driverversion = ntdevmode->driverversion;
4169 devmode->size = ntdevmode->size;
4170 devmode->driverextra = ntdevmode->driverextra;
4171 devmode->fields = ntdevmode->fields;
4173 devmode->orientation = ntdevmode->orientation;
4174 devmode->papersize = ntdevmode->papersize;
4175 devmode->paperlength = ntdevmode->paperlength;
4176 devmode->paperwidth = ntdevmode->paperwidth;
4177 devmode->scale = ntdevmode->scale;
4178 devmode->copies = ntdevmode->copies;
4179 devmode->defaultsource = ntdevmode->defaultsource;
4180 devmode->printquality = ntdevmode->printquality;
4181 devmode->color = ntdevmode->color;
4182 devmode->duplex = ntdevmode->duplex;
4183 devmode->yresolution = ntdevmode->yresolution;
4184 devmode->ttoption = ntdevmode->ttoption;
4185 devmode->collate = ntdevmode->collate;
4186 devmode->icmmethod = ntdevmode->icmmethod;
4187 devmode->icmintent = ntdevmode->icmintent;
4188 devmode->mediatype = ntdevmode->mediatype;
4189 devmode->dithertype = ntdevmode->dithertype;
4191 if (ntdevmode->nt_dev_private != NULL) {
4192 if ((devmode->dev_private=(uint8 *)memdup(ntdevmode->nt_dev_private, ntdevmode->driverextra)) == NULL)
4199 /****************************************************************************
4200 Create a spoolss_DeviceMode struct. Returns talloced memory.
4201 ****************************************************************************/
4203 struct spoolss_DeviceMode *construct_dev_mode_new(TALLOC_CTX *mem_ctx,
4204 const char *servicename)
4207 NT_PRINTER_INFO_LEVEL *printer = NULL;
4208 struct spoolss_DeviceMode *devmode = NULL;
4210 DEBUG(7,("construct_dev_mode_new\n"));
4212 DEBUGADD(8,("getting printer characteristics\n"));
4214 if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, servicename)))
4217 if (!printer->info_2->devmode) {
4218 DEBUG(5, ("BONG! There was no device mode!\n"));
4222 devmode = TALLOC_ZERO_P(mem_ctx, struct spoolss_DeviceMode);
4224 DEBUG(2,("construct_dev_mode_new: talloc fail.\n"));
4228 DEBUGADD(8,("loading DEVICEMODE\n"));
4230 result = convert_nt_devicemode_new(mem_ctx, devmode, printer->info_2->devmode);
4231 if (!W_ERROR_IS_OK(result)) {
4232 TALLOC_FREE(devmode);
4236 free_a_printer(&printer,2);
4241 /****************************************************************************
4242 Create a DEVMODE struct. Returns malloced memory.
4243 ****************************************************************************/
4245 DEVICEMODE *construct_dev_mode(const char *servicename)
4247 NT_PRINTER_INFO_LEVEL *printer = NULL;
4248 DEVICEMODE *devmode = NULL;
4250 DEBUG(7,("construct_dev_mode\n"));
4252 DEBUGADD(8,("getting printer characteristics\n"));
4254 if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, servicename)))
4257 if ( !printer->info_2->devmode ) {
4258 DEBUG(5, ("BONG! There was no device mode!\n"));
4262 if ((devmode = SMB_MALLOC_P(DEVICEMODE)) == NULL) {
4263 DEBUG(2,("construct_dev_mode: malloc fail.\n"));
4267 ZERO_STRUCTP(devmode);
4269 DEBUGADD(8,("loading DEVICEMODE\n"));
4271 if ( !convert_nt_devicemode( devmode, printer->info_2->devmode ) ) {
4272 free_dev_mode( devmode );
4277 free_a_printer(&printer,2);
4282 /********************************************************************
4283 * construct_printer_info_2
4284 * fill a printer_info_2 struct
4285 ********************************************************************/
4287 static bool construct_printer_info_2(Printer_entry *print_hnd, PRINTER_INFO_2 *printer, int snum)
4290 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
4292 print_status_struct status;
4294 if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum))))
4297 count = print_queue_length(snum, &status);
4299 init_unistr(&printer->servername, ntprinter->info_2->servername); /* servername*/
4300 init_unistr(&printer->printername, ntprinter->info_2->printername); /* printername*/
4301 init_unistr(&printer->sharename, lp_servicename(snum)); /* sharename */
4302 init_unistr(&printer->portname, ntprinter->info_2->portname); /* port */
4303 init_unistr(&printer->drivername, ntprinter->info_2->drivername); /* drivername */
4305 if (*ntprinter->info_2->comment == '\0')
4306 init_unistr(&printer->comment, lp_comment(snum)); /* comment */
4308 init_unistr(&printer->comment, ntprinter->info_2->comment); /* saved comment. */
4310 init_unistr(&printer->location, ntprinter->info_2->location); /* location */
4311 init_unistr(&printer->sepfile, ntprinter->info_2->sepfile); /* separator file */
4312 init_unistr(&printer->printprocessor, ntprinter->info_2->printprocessor);/* print processor */
4313 init_unistr(&printer->datatype, ntprinter->info_2->datatype); /* datatype */
4314 init_unistr(&printer->parameters, ntprinter->info_2->parameters); /* parameters (of print processor) */
4316 printer->attributes = ntprinter->info_2->attributes;
4318 printer->priority = ntprinter->info_2->priority; /* priority */
4319 printer->defaultpriority = ntprinter->info_2->default_priority; /* default priority */
4320 printer->starttime = ntprinter->info_2->starttime; /* starttime */
4321 printer->untiltime = ntprinter->info_2->untiltime; /* untiltime */
4322 printer->status = nt_printq_status(status.status); /* status */
4323 printer->cjobs = count; /* jobs */
4324 printer->averageppm = ntprinter->info_2->averageppm; /* average pages per minute */
4326 if ( !(printer->devmode = construct_dev_mode(
4327 lp_const_servicename(snum))) )
4328 DEBUG(8, ("Returning NULL Devicemode!\n"));
4330 printer->secdesc = NULL;
4332 if ( ntprinter->info_2->secdesc_buf
4333 && ntprinter->info_2->secdesc_buf->sd_size != 0 )
4335 /* don't use talloc_steal() here unless you do a deep steal of all
4336 the SEC_DESC members */
4338 printer->secdesc = dup_sec_desc( talloc_tos(),
4339 ntprinter->info_2->secdesc_buf->sd );
4342 free_a_printer(&ntprinter, 2);
4347 /********************************************************************
4348 * construct_printer_info_3
4349 * fill a printer_info_3 struct
4350 ********************************************************************/
4352 static bool construct_printer_info_3(Printer_entry *print_hnd, PRINTER_INFO_3 **pp_printer, int snum)
4354 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
4355 PRINTER_INFO_3 *printer = NULL;
4357 if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum))))
4361 if ((printer = SMB_MALLOC_P(PRINTER_INFO_3)) == NULL) {
4362 DEBUG(2,("construct_printer_info_3: malloc fail.\n"));
4363 free_a_printer(&ntprinter, 2);
4367 ZERO_STRUCTP(printer);
4369 /* These are the components of the SD we are returning. */
4371 if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->sd_size != 0) {
4372 /* don't use talloc_steal() here unless you do a deep steal of all
4373 the SEC_DESC members */
4375 printer->secdesc = dup_sec_desc( talloc_tos(),
4376 ntprinter->info_2->secdesc_buf->sd );
4379 free_a_printer(&ntprinter, 2);
4381 *pp_printer = printer;
4385 /********************************************************************
4386 * construct_printer_info_4
4387 * fill a printer_info_4 struct
4388 ********************************************************************/
4390 static bool construct_printer_info_4(Printer_entry *print_hnd, PRINTER_INFO_4 *printer, int snum)
4392 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
4394 if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum))))
4397 init_unistr(&printer->printername, ntprinter->info_2->printername); /* printername*/
4398 init_unistr(&printer->servername, ntprinter->info_2->servername); /* servername*/
4399 printer->attributes = ntprinter->info_2->attributes;
4401 free_a_printer(&ntprinter, 2);
4405 /********************************************************************
4406 * construct_printer_info_5
4407 * fill a printer_info_5 struct
4408 ********************************************************************/
4410 static bool construct_printer_info_5(Printer_entry *print_hnd, PRINTER_INFO_5 *printer, int snum)
4412 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
4414 if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum))))
4417 init_unistr(&printer->printername, ntprinter->info_2->printername);
4418 init_unistr(&printer->portname, ntprinter->info_2->portname);
4419 printer->attributes = ntprinter->info_2->attributes;
4421 /* these two are not used by NT+ according to MSDN */
4423 printer->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
4424 printer->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
4426 free_a_printer(&ntprinter, 2);
4431 /********************************************************************
4432 * construct_printer_info_6
4433 * fill a printer_info_6 struct
4434 ********************************************************************/
4436 static bool construct_printer_info_6(Printer_entry *print_hnd,
4437 PRINTER_INFO_6 *printer,
4440 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
4442 print_status_struct status;
4444 if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2,
4445 lp_const_servicename(snum))))
4448 count = print_queue_length(snum, &status);
4450 printer->status = nt_printq_status(status.status);
4452 free_a_printer(&ntprinter, 2);
4457 /********************************************************************
4458 * construct_printer_info_7
4459 * fill a printer_info_7 struct
4460 ********************************************************************/
4462 static bool construct_printer_info_7(Printer_entry *print_hnd, PRINTER_INFO_7 *printer, int snum)
4464 char *guid_str = NULL;
4467 if (is_printer_published(print_hnd, snum, &guid)) {
4468 if (asprintf(&guid_str, "{%s}",
4469 GUID_string(talloc_tos(), &guid)) == -1) {
4472 strupper_m(guid_str);
4473 init_unistr(&printer->guid, guid_str);
4474 SAFE_FREE(guid_str);
4475 printer->action = DSPRINT_PUBLISH;
4477 init_unistr(&printer->guid, "");
4478 printer->action = DSPRINT_UNPUBLISH;
4484 /********************************************************************
4485 Spoolss_enumprinters.
4486 ********************************************************************/
4488 static WERROR enum_all_printers_info_1(uint32 flags, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4492 int n_services=lp_numservices();
4493 PRINTER_INFO_1 *printers=NULL;
4494 PRINTER_INFO_1 current_prt;
4495 WERROR result = WERR_OK;
4497 DEBUG(4,("enum_all_printers_info_1\n"));
4499 for (snum=0; snum<n_services; snum++) {
4500 if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
4501 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum));
4503 if (construct_printer_info_1(NULL, flags, ¤t_prt, snum)) {
4504 if((printers=SMB_REALLOC_ARRAY(printers, PRINTER_INFO_1, *returned +1)) == NULL) {
4505 DEBUG(2,("enum_all_printers_info_1: failed to enlarge printers buffer!\n"));
4509 DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_1\n", *returned));
4511 memcpy(&printers[*returned], ¤t_prt, sizeof(PRINTER_INFO_1));
4517 /* check the required size. */
4518 for (i=0; i<*returned; i++)
4519 (*needed) += spoolss_size_printer_info_1(&printers[i]);
4521 if (*needed > offered) {
4522 result = WERR_INSUFFICIENT_BUFFER;
4526 if (!rpcbuf_alloc_size(buffer, *needed)) {
4527 result = WERR_NOMEM;
4531 /* fill the buffer with the structures */
4532 for (i=0; i<*returned; i++)
4533 smb_io_printer_info_1("", buffer, &printers[i], 0);
4538 SAFE_FREE(printers);
4540 if ( !W_ERROR_IS_OK(result) )
4546 /********************************************************************
4547 enum_all_printers_info_1_local.
4548 *********************************************************************/
4550 static WERROR enum_all_printers_info_1_local(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4552 DEBUG(4,("enum_all_printers_info_1_local\n"));
4554 return enum_all_printers_info_1(PRINTER_ENUM_ICON8, buffer, offered, needed, returned);
4557 /********************************************************************
4558 enum_all_printers_info_1_name.
4559 *********************************************************************/
4561 static WERROR enum_all_printers_info_1_name(fstring name, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4565 DEBUG(4,("enum_all_printers_info_1_name\n"));
4567 if ((name[0] == '\\') && (name[1] == '\\'))
4570 if (is_myname_or_ipaddr(s)) {
4571 return enum_all_printers_info_1(PRINTER_ENUM_ICON8, buffer, offered, needed, returned);
4574 return WERR_INVALID_NAME;
4577 #if 0 /* JERRY -- disabled for now. Don't think this is used, tested, or correct */
4578 /********************************************************************
4579 enum_all_printers_info_1_remote.
4580 *********************************************************************/
4582 static WERROR enum_all_printers_info_1_remote(fstring name, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4584 PRINTER_INFO_1 *printer;
4585 fstring printername;
4588 DEBUG(4,("enum_all_printers_info_1_remote\n"));
4589 WERROR result = WERR_OK;
4591 /* JFM: currently it's more a place holder than anything else.
4592 * In the spooler world there is a notion of server registration.
4593 * the print servers are registered on the PDC (in the same domain)
4595 * We should have a TDB here. The registration is done thru an
4596 * undocumented RPC call.
4599 if((printer=SMB_MALLOC_P(PRINTER_INFO_1)) == NULL)
4604 slprintf(printername, sizeof(printername)-1,"Windows NT Remote Printers!!\\\\%s", name);
4605 slprintf(desc, sizeof(desc)-1,"%s", name);
4606 slprintf(comment, sizeof(comment)-1, "Logged on Domain");
4608 init_unistr(&printer->description, desc);
4609 init_unistr(&printer->name, printername);
4610 init_unistr(&printer->comment, comment);
4611 printer->flags=PRINTER_ENUM_ICON3|PRINTER_ENUM_CONTAINER;
4613 /* check the required size. */
4614 *needed += spoolss_size_printer_info_1(printer);
4616 if (*needed > offered) {
4617 result = WERR_INSUFFICIENT_BUFFER;
4621 if (!rpcbuf_alloc_size(buffer, *needed)) {
4622 result = WERR_NOMEM;
4626 /* fill the buffer with the structures */
4627 smb_io_printer_info_1("", buffer, printer, 0);
4633 if ( !W_ERROR_IS_OK(result) )
4641 /********************************************************************
4642 enum_all_printers_info_1_network.
4643 *********************************************************************/
4645 static WERROR enum_all_printers_info_1_network(fstring name, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4649 DEBUG(4,("enum_all_printers_info_1_network\n"));
4651 /* If we respond to a enum_printers level 1 on our name with flags
4652 set to PRINTER_ENUM_REMOTE with a list of printers then these
4653 printers incorrectly appear in the APW browse list.
4654 Specifically the printers for the server appear at the workgroup
4655 level where all the other servers in the domain are
4656 listed. Windows responds to this call with a
4657 WERR_CAN_NOT_COMPLETE so we should do the same. */
4659 if (name[0] == '\\' && name[1] == '\\')
4662 if (is_myname_or_ipaddr(s))
4663 return WERR_CAN_NOT_COMPLETE;
4665 return enum_all_printers_info_1(PRINTER_ENUM_NAME, buffer, offered, needed, returned);
4668 /********************************************************************
4669 * api_spoolss_enumprinters
4671 * called from api_spoolss_enumprinters (see this to understand)
4672 ********************************************************************/
4674 static WERROR enum_all_printers_info_2(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4678 int n_services=lp_numservices();
4679 PRINTER_INFO_2 *printers=NULL;
4680 PRINTER_INFO_2 current_prt;
4681 WERROR result = WERR_OK;
4685 for (snum=0; snum<n_services; snum++) {
4686 if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
4687 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum));
4689 if (construct_printer_info_2(NULL, ¤t_prt, snum)) {
4690 if ( !(printers=SMB_REALLOC_ARRAY(printers, PRINTER_INFO_2, *returned +1)) ) {
4691 DEBUG(2,("enum_all_printers_info_2: failed to enlarge printers buffer!\n"));
4696 DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_2\n", *returned + 1));
4698 memcpy(&printers[*returned], ¤t_prt, sizeof(PRINTER_INFO_2));
4705 /* check the required size. */
4706 for (i=0; i<*returned; i++)
4707 (*needed) += spoolss_size_printer_info_2(&printers[i]);
4709 if (*needed > offered) {
4710 result = WERR_INSUFFICIENT_BUFFER;
4714 if (!rpcbuf_alloc_size(buffer, *needed)) {
4715 result = WERR_NOMEM;
4719 /* fill the buffer with the structures */
4720 for (i=0; i<*returned; i++)
4721 smb_io_printer_info_2("", buffer, &(printers[i]), 0);
4726 for (i=0; i<*returned; i++)
4727 free_devmode(printers[i].devmode);
4729 SAFE_FREE(printers);
4731 if ( !W_ERROR_IS_OK(result) )
4737 /********************************************************************
4738 * handle enumeration of printers at level 1
4739 ********************************************************************/
4741 static WERROR enumprinters_level1( uint32 flags, fstring name,
4742 RPC_BUFFER *buffer, uint32 offered,
4743 uint32 *needed, uint32 *returned)
4745 /* Not all the flags are equals */
4747 if (flags & PRINTER_ENUM_LOCAL)
4748 return enum_all_printers_info_1_local(buffer, offered, needed, returned);
4750 if (flags & PRINTER_ENUM_NAME)
4751 return enum_all_printers_info_1_name(name, buffer, offered, needed, returned);
4753 #if 0 /* JERRY - disabled for now */
4754 if (flags & PRINTER_ENUM_REMOTE)
4755 return enum_all_printers_info_1_remote(name, buffer, offered, needed, returned);
4758 if (flags & PRINTER_ENUM_NETWORK)
4759 return enum_all_printers_info_1_network(name, buffer, offered, needed, returned);
4761 return WERR_OK; /* NT4sp5 does that */
4764 /********************************************************************
4765 * handle enumeration of printers at level 2
4766 ********************************************************************/
4768 static WERROR enumprinters_level2( uint32 flags, const char *servername,
4769 RPC_BUFFER *buffer, uint32 offered,
4770 uint32 *needed, uint32 *returned)
4772 if (flags & PRINTER_ENUM_LOCAL) {
4773 return enum_all_printers_info_2(buffer, offered, needed, returned);
4776 if (flags & PRINTER_ENUM_NAME) {
4777 if (is_myname_or_ipaddr(canon_servername(servername)))
4778 return enum_all_printers_info_2(buffer, offered, needed, returned);
4780 return WERR_INVALID_NAME;
4783 if (flags & PRINTER_ENUM_REMOTE)
4784 return WERR_UNKNOWN_LEVEL;
4789 /********************************************************************
4790 * handle enumeration of printers at level 5
4791 ********************************************************************/
4793 static WERROR enumprinters_level5( uint32 flags, const char *servername,
4794 RPC_BUFFER *buffer, uint32 offered,
4795 uint32 *needed, uint32 *returned)
4797 /* return enum_all_printers_info_5(buffer, offered, needed, returned);*/
4801 /********************************************************************
4802 * api_spoolss_enumprinters
4804 * called from api_spoolss_enumprinters (see this to understand)
4805 ********************************************************************/
4807 WERROR _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOOL_R_ENUMPRINTERS *r_u)
4809 uint32 flags = q_u->flags;
4810 UNISTR2 *servername = &q_u->servername;
4811 uint32 level = q_u->level;
4812 RPC_BUFFER *buffer = NULL;
4813 uint32 offered = q_u->offered;
4814 uint32 *needed = &r_u->needed;
4815 uint32 *returned = &r_u->returned;
4819 /* that's an [in out] buffer */
4821 if (!q_u->buffer && (offered!=0)) {
4822 return WERR_INVALID_PARAM;
4825 if (offered > MAX_RPC_DATA_SIZE) {
4826 return WERR_INVALID_PARAM;
4829 rpcbuf_move(q_u->buffer, &r_u->buffer);
4830 buffer = r_u->buffer;
4832 DEBUG(4,("_spoolss_enumprinters\n"));
4839 * flags==PRINTER_ENUM_NAME
4840 * if name=="" then enumerates all printers
4841 * if name!="" then enumerate the printer
4842 * flags==PRINTER_ENUM_REMOTE
4843 * name is NULL, enumerate printers
4844 * Level 2: name!="" enumerates printers, name can't be NULL
4845 * Level 3: doesn't exist
4846 * Level 4: does a local registry lookup
4847 * Level 5: same as Level 2
4850 unistr2_to_ascii(name, servername, sizeof(name));
4855 return enumprinters_level1(flags, name, buffer, offered, needed, returned);
4857 return enumprinters_level2(flags, name, buffer, offered, needed, returned);
4859 return enumprinters_level5(flags, name, buffer, offered, needed, returned);
4864 return WERR_UNKNOWN_LEVEL;
4867 /****************************************************************************
4868 ****************************************************************************/
4870 static WERROR getprinter_level_0(Printer_entry *print_hnd, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed)
4872 PRINTER_INFO_0 *printer=NULL;
4873 WERROR result = WERR_OK;
4875 if((printer=SMB_MALLOC_P(PRINTER_INFO_0)) == NULL)
4878 construct_printer_info_0(print_hnd, printer, snum);
4880 /* check the required size. */
4881 *needed += spoolss_size_printer_info_0(printer);
4883 if (*needed > offered) {
4884 result = WERR_INSUFFICIENT_BUFFER;
4888 if (!rpcbuf_alloc_size(buffer, *needed)) {
4889 result = WERR_NOMEM;
4893 /* fill the buffer with the structures */
4894 smb_io_printer_info_0("", buffer, printer, 0);
4904 /****************************************************************************
4905 ****************************************************************************/
4907 static WERROR getprinter_level_1(Printer_entry *print_hnd, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed)
4909 PRINTER_INFO_1 *printer=NULL;
4910 WERROR result = WERR_OK;
4912 if((printer=SMB_MALLOC_P(PRINTER_INFO_1)) == NULL)
4915 construct_printer_info_1(print_hnd, PRINTER_ENUM_ICON8, printer, snum);
4917 /* check the required size. */
4918 *needed += spoolss_size_printer_info_1(printer);
4920 if (*needed > offered) {
4921 result = WERR_INSUFFICIENT_BUFFER;
4925 if (!rpcbuf_alloc_size(buffer, *needed)) {
4926 result = WERR_NOMEM;
4930 /* fill the buffer with the structures */
4931 smb_io_printer_info_1("", buffer, printer, 0);
4940 /****************************************************************************
4941 ****************************************************************************/
4943 static WERROR getprinter_level_2(Printer_entry *print_hnd, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed)
4945 PRINTER_INFO_2 *printer=NULL;
4946 WERROR result = WERR_OK;
4948 if((printer=SMB_MALLOC_P(PRINTER_INFO_2))==NULL)
4951 construct_printer_info_2(print_hnd, printer, snum);
4953 /* check the required size. */
4954 *needed += spoolss_size_printer_info_2(printer);
4956 if (*needed > offered) {
4957 result = WERR_INSUFFICIENT_BUFFER;
4961 if (!rpcbuf_alloc_size(buffer, *needed)) {
4962 result = WERR_NOMEM;
4966 /* fill the buffer with the structures */
4967 if (!smb_io_printer_info_2("", buffer, printer, 0))
4968 result = WERR_NOMEM;
4972 free_printer_info_2(printer);
4977 /****************************************************************************
4978 ****************************************************************************/
4980 static WERROR getprinter_level_3(Printer_entry *print_hnd, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed)
4982 PRINTER_INFO_3 *printer=NULL;
4983 WERROR result = WERR_OK;
4985 if (!construct_printer_info_3(print_hnd, &printer, snum))
4988 /* check the required size. */
4989 *needed += spoolss_size_printer_info_3(printer);
4991 if (*needed > offered) {
4992 result = WERR_INSUFFICIENT_BUFFER;
4996 if (!rpcbuf_alloc_size(buffer, *needed)) {
4997 result = WERR_NOMEM;
5001 /* fill the buffer with the structures */
5002 smb_io_printer_info_3("", buffer, printer, 0);
5006 free_printer_info_3(printer);
5011 /****************************************************************************
5012 ****************************************************************************/
5014 static WERROR getprinter_level_4(Printer_entry *print_hnd, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed)
5016 PRINTER_INFO_4 *printer=NULL;
5017 WERROR result = WERR_OK;
5019 if((printer=SMB_MALLOC_P(PRINTER_INFO_4))==NULL)
5022 if (!construct_printer_info_4(print_hnd, printer, snum)) {
5027 /* check the required size. */
5028 *needed += spoolss_size_printer_info_4(printer);
5030 if (*needed > offered) {
5031 result = WERR_INSUFFICIENT_BUFFER;
5035 if (!rpcbuf_alloc_size(buffer, *needed)) {
5036 result = WERR_NOMEM;
5040 /* fill the buffer with the structures */
5041 smb_io_printer_info_4("", buffer, printer, 0);
5045 free_printer_info_4(printer);
5050 /****************************************************************************
5051 ****************************************************************************/
5053 static WERROR getprinter_level_5(Printer_entry *print_hnd, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed)
5055 PRINTER_INFO_5 *printer=NULL;
5056 WERROR result = WERR_OK;
5058 if((printer=SMB_MALLOC_P(PRINTER_INFO_5))==NULL)
5061 if (!construct_printer_info_5(print_hnd, printer, snum)) {
5062 free_printer_info_5(printer);
5066 /* check the required size. */
5067 *needed += spoolss_size_printer_info_5(printer);
5069 if (*needed > offered) {
5070 result = WERR_INSUFFICIENT_BUFFER;
5074 if (!rpcbuf_alloc_size(buffer, *needed)) {
5075 result = WERR_NOMEM;
5079 /* fill the buffer with the structures */
5080 smb_io_printer_info_5("", buffer, printer, 0);
5084 free_printer_info_5(printer);
5089 static WERROR getprinter_level_6(Printer_entry *print_hnd,
5091 RPC_BUFFER *buffer, uint32 offered,
5094 PRINTER_INFO_6 *printer;
5095 WERROR result = WERR_OK;
5097 if ((printer = SMB_MALLOC_P(PRINTER_INFO_6)) == NULL) {
5101 if (!construct_printer_info_6(print_hnd, printer, snum)) {
5102 free_printer_info_6(printer);
5106 /* check the required size. */
5107 *needed += spoolss_size_printer_info_6(printer);
5109 if (*needed > offered) {
5110 result = WERR_INSUFFICIENT_BUFFER;
5114 if (!rpcbuf_alloc_size(buffer, *needed)) {
5115 result = WERR_NOMEM;
5119 /* fill the buffer with the structures */
5120 smb_io_printer_info_6("", buffer, printer, 0);
5124 free_printer_info_6(printer);
5129 static WERROR getprinter_level_7(Printer_entry *print_hnd, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed)
5131 PRINTER_INFO_7 *printer=NULL;
5132 WERROR result = WERR_OK;
5134 if((printer=SMB_MALLOC_P(PRINTER_INFO_7))==NULL)
5137 if (!construct_printer_info_7(print_hnd, printer, snum)) {
5138 result = WERR_NOMEM;
5142 /* check the required size. */
5143 *needed += spoolss_size_printer_info_7(printer);
5145 if (*needed > offered) {
5146 result = WERR_INSUFFICIENT_BUFFER;
5150 if (!rpcbuf_alloc_size(buffer, *needed)) {
5151 result = WERR_NOMEM;
5156 /* fill the buffer with the structures */
5157 smb_io_printer_info_7("", buffer, printer, 0);
5161 free_printer_info_7(printer);
5166 /****************************************************************************
5167 ****************************************************************************/
5169 WERROR _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GETPRINTER *r_u)
5171 POLICY_HND *handle = &q_u->handle;
5172 uint32 level = q_u->level;
5173 RPC_BUFFER *buffer = NULL;
5174 uint32 offered = q_u->offered;
5175 uint32 *needed = &r_u->needed;
5176 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
5180 /* that's an [in out] buffer */
5182 if (!q_u->buffer && (offered!=0)) {
5183 return WERR_INVALID_PARAM;
5186 if (offered > MAX_RPC_DATA_SIZE) {
5187 return WERR_INVALID_PARAM;
5190 rpcbuf_move(q_u->buffer, &r_u->buffer);
5191 buffer = r_u->buffer;
5195 if (!get_printer_snum(p, handle, &snum, NULL))
5200 return getprinter_level_0(Printer, snum, buffer, offered, needed);
5202 return getprinter_level_1(Printer, snum, buffer, offered, needed);
5204 return getprinter_level_2(Printer, snum, buffer, offered, needed);
5206 return getprinter_level_3(Printer, snum, buffer, offered, needed);
5208 return getprinter_level_4(Printer, snum, buffer, offered, needed);
5210 return getprinter_level_5(Printer, snum, buffer, offered, needed);
5212 return getprinter_level_6(Printer, snum, buffer, offered, needed);
5214 return getprinter_level_7(Printer, snum, buffer, offered, needed);
5216 return WERR_UNKNOWN_LEVEL;
5219 /********************************************************************
5220 * fill a DRIVER_INFO_1 struct
5221 ********************************************************************/
5223 static void fill_printer_driver_info_1(DRIVER_INFO_1 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, const char *servername, fstring architecture)
5225 init_unistr( &info->name, driver.info_3->name);
5228 /********************************************************************
5229 * construct_printer_driver_info_1
5230 ********************************************************************/
5232 static WERROR construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, const char *servername, fstring architecture, uint32 version)
5234 NT_PRINTER_INFO_LEVEL *printer = NULL;
5235 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5237 ZERO_STRUCT(driver);
5239 if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, lp_const_servicename(snum))))
5240 return WERR_INVALID_PRINTER_NAME;
5242 if (!W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version))) {
5243 free_a_printer(&printer, 2);
5244 return WERR_UNKNOWN_PRINTER_DRIVER;
5247 fill_printer_driver_info_1(info, driver, servername, architecture);
5249 free_a_printer(&printer,2);
5254 /********************************************************************
5255 * construct_printer_driver_info_2
5256 * fill a printer_info_2 struct
5257 ********************************************************************/
5259 static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, const char *servername)
5261 TALLOC_CTX *ctx = talloc_tos();
5263 const char *cservername = canon_servername(servername);
5265 info->version=driver.info_3->cversion;
5267 init_unistr( &info->name, driver.info_3->name );
5268 init_unistr( &info->architecture, driver.info_3->environment );
5270 if (strlen(driver.info_3->driverpath)) {
5271 temp = talloc_asprintf(ctx,
5274 driver.info_3->driverpath);
5275 init_unistr( &info->driverpath, temp );
5277 init_unistr( &info->driverpath, "" );
5281 if (strlen(driver.info_3->datafile)) {
5282 temp = talloc_asprintf(ctx,
5285 driver.info_3->datafile);
5286 init_unistr( &info->datafile, temp );
5288 init_unistr( &info->datafile, "" );
5291 if (strlen(driver.info_3->configfile)) {
5292 temp = talloc_asprintf(ctx,
5295 driver.info_3->configfile);
5296 init_unistr( &info->configfile, temp );
5298 init_unistr( &info->configfile, "" );
5301 /********************************************************************
5302 * construct_printer_driver_info_2
5303 * fill a printer_info_2 struct
5304 ********************************************************************/
5306 static WERROR construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, const char *servername, fstring architecture, uint32 version)
5308 NT_PRINTER_INFO_LEVEL *printer = NULL;
5309 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5311 ZERO_STRUCT(printer);
5312 ZERO_STRUCT(driver);
5314 if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, lp_const_servicename(snum))))
5315 return WERR_INVALID_PRINTER_NAME;
5317 if (!W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version))) {
5318 free_a_printer(&printer, 2);
5319 return WERR_UNKNOWN_PRINTER_DRIVER;
5322 fill_printer_driver_info_2(info, driver, servername);
5324 free_a_printer(&printer,2);
5329 /********************************************************************
5330 * copy a strings array and convert to UNICODE
5332 * convert an array of ascii string to a UNICODE string
5333 ********************************************************************/
5335 static uint32 init_unistr_array(uint16 **uni_array, fstring *char_array, const char *servername)
5341 TALLOC_CTX *ctx = talloc_tos();
5343 DEBUG(6,("init_unistr_array\n"));
5347 if ( !char_array ) {
5352 v = ""; /* hack to handle null lists */
5355 /* hack to allow this to be used in places other than when generating
5356 the list of dependent files */
5360 line = talloc_asprintf(ctx,
5362 canon_servername(servername),
5365 line = talloc_strdup(ctx, v);
5369 SAFE_FREE(*uni_array);
5372 DEBUGADD(6,("%d:%s:%lu\n", i, line, (unsigned long)strlen(line)));
5374 /* add one extra unit16 for the second terminating NULL */
5376 if ( (*uni_array=SMB_REALLOC_ARRAY(*uni_array, uint16, j+1+strlen(line)+2)) == NULL ) {
5377 DEBUG(2,("init_unistr_array: Realloc error\n" ));
5384 j += (rpcstr_push((*uni_array+j), line, sizeof(uint16)*strlen(line)+2, STR_TERMINATE) / sizeof(uint16));
5389 /* special case for ""; we need to add both NULL's here */
5391 (*uni_array)[j++]=0x0000;
5392 (*uni_array)[j]=0x0000;
5395 DEBUGADD(6,("last one:done\n"));
5397 /* return size of array in uint16's */
5402 /********************************************************************
5403 * construct_printer_info_3
5404 * fill a printer_info_3 struct
5405 ********************************************************************/
5407 static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, const char *servername)
5410 TALLOC_CTX *ctx = talloc_tos();
5411 const char *cservername = canon_servername(servername);
5415 info->version=driver.info_3->cversion;
5417 init_unistr( &info->name, driver.info_3->name );
5418 init_unistr( &info->architecture, driver.info_3->environment );
5420 if (strlen(driver.info_3->driverpath)) {
5421 temp = talloc_asprintf(ctx,
5424 driver.info_3->driverpath);
5425 init_unistr( &info->driverpath, temp );
5427 init_unistr( &info->driverpath, "" );
5430 if (strlen(driver.info_3->datafile)) {
5431 temp = talloc_asprintf(ctx,
5434 driver.info_3->datafile);
5435 init_unistr( &info->datafile, temp );
5437 init_unistr( &info->datafile, "" );
5440 if (strlen(driver.info_3->configfile)) {
5441 temp = talloc_asprintf(ctx,
5444 driver.info_3->configfile);
5445 init_unistr( &info->configfile, temp );
5447 init_unistr( &info->configfile, "" );
5450 if (strlen(driver.info_3->helpfile)) {
5451 temp = talloc_asprintf(ctx,
5454 driver.info_3->helpfile);
5455 init_unistr( &info->helpfile, temp );
5457 init_unistr( &info->helpfile, "" );
5460 init_unistr( &info->monitorname, driver.info_3->monitorname );
5461 init_unistr( &info->defaultdatatype, driver.info_3->defaultdatatype );
5463 info->dependentfiles=NULL;
5464 init_unistr_array(&info->dependentfiles, driver.info_3->dependentfiles, cservername);
5467 /********************************************************************
5468 * construct_printer_info_3
5469 * fill a printer_info_3 struct
5470 ********************************************************************/
5472 static WERROR construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, const char *servername, fstring architecture, uint32 version)
5474 NT_PRINTER_INFO_LEVEL *printer = NULL;
5475 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5477 ZERO_STRUCT(driver);
5479 status=get_a_printer(NULL, &printer, 2, lp_const_servicename(snum) );
5480 DEBUG(8,("construct_printer_driver_info_3: status: %s\n", win_errstr(status)));
5481 if (!W_ERROR_IS_OK(status))
5482 return WERR_INVALID_PRINTER_NAME;
5484 status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version);
5485 DEBUG(8,("construct_printer_driver_info_3: status: %s\n", win_errstr(status)));
5490 * I put this code in during testing. Helpful when commenting out the
5491 * support for DRIVER_INFO_6 in regards to win2k. Not needed in general
5492 * as win2k always queries the driver using an infor level of 6.
5493 * I've left it in (but ifdef'd out) because I'll probably
5494 * use it in experimentation again in the future. --jerry 22/01/2002
5497 if (!W_ERROR_IS_OK(status)) {
5499 * Is this a W2k client ?
5502 /* Yes - try again with a WinNT driver. */
5504 status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version);
5505 DEBUG(8,("construct_printer_driver_info_3: status: %s\n", win_errstr(status)));
5509 if (!W_ERROR_IS_OK(status)) {
5510 free_a_printer(&printer,2);
5511 return WERR_UNKNOWN_PRINTER_DRIVER;
5519 fill_printer_driver_info_3(info, driver, servername);
5521 free_a_printer(&printer,2);
5526 /********************************************************************
5527 * construct_printer_info_6
5528 * fill a printer_info_6 struct - we know that driver is really level 3. This sucks. JRA.
5529 ********************************************************************/
5531 static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, const char *servername)
5535 TALLOC_CTX *ctx = talloc_tos();
5536 const char *cservername = canon_servername(servername);
5539 memset(&nullstr, '\0', sizeof(fstring));
5541 info->version=driver.info_3->cversion;
5543 init_unistr( &info->name, driver.info_3->name );
5544 init_unistr( &info->architecture, driver.info_3->environment );
5546 if (strlen(driver.info_3->driverpath)) {
5547 temp = talloc_asprintf(ctx,
5550 driver.info_3->driverpath);
5551 init_unistr( &info->driverpath, temp );
5553 init_unistr( &info->driverpath, "" );
5556 if (strlen(driver.info_3->datafile)) {
5557 temp = talloc_asprintf(ctx,
5560 driver.info_3->datafile);
5561 init_unistr( &info->datafile, temp );
5563 init_unistr( &info->datafile, "" );
5566 if (strlen(driver.info_3->configfile)) {
5567 temp = talloc_asprintf(ctx,
5570 driver.info_3->configfile);
5571 init_unistr( &info->configfile, temp );
5573 init_unistr( &info->configfile, "" );
5576 if (strlen(driver.info_3->helpfile)) {
5577 temp = talloc_asprintf(ctx,
5580 driver.info_3->helpfile);
5581 init_unistr( &info->helpfile, temp );
5583 init_unistr( &info->helpfile, "" );
5586 init_unistr( &info->monitorname, driver.info_3->monitorname );
5587 init_unistr( &info->defaultdatatype, driver.info_3->defaultdatatype );
5589 info->dependentfiles = NULL;
5590 init_unistr_array( &info->dependentfiles, driver.info_3->dependentfiles, servername );
5592 info->previousdrivernames=NULL;
5593 init_unistr_array(&info->previousdrivernames, &nullstr, servername);
5595 info->driver_date=0;
5598 info->driver_version_low=0;
5599 info->driver_version_high=0;
5601 init_unistr( &info->mfgname, "");
5602 init_unistr( &info->oem_url, "");
5603 init_unistr( &info->hardware_id, "");
5604 init_unistr( &info->provider, "");
5607 /********************************************************************
5608 * construct_printer_info_6
5609 * fill a printer_info_6 struct
5610 ********************************************************************/
5612 static WERROR construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum,
5613 const char *servername, fstring architecture, uint32 version)
5615 NT_PRINTER_INFO_LEVEL *printer = NULL;
5616 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5619 ZERO_STRUCT(driver);
5621 status=get_a_printer(NULL, &printer, 2, lp_const_servicename(snum) );
5623 DEBUG(8,("construct_printer_driver_info_6: status: %s\n", win_errstr(status)));
5625 if (!W_ERROR_IS_OK(status))
5626 return WERR_INVALID_PRINTER_NAME;
5628 status = get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version);
5630 DEBUG(8,("construct_printer_driver_info_6: status: %s\n", win_errstr(status)));
5632 if (!W_ERROR_IS_OK(status))
5635 * Is this a W2k client ?
5639 free_a_printer(&printer,2);
5640 return WERR_UNKNOWN_PRINTER_DRIVER;
5643 /* Yes - try again with a WinNT driver. */
5645 status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version);
5646 DEBUG(8,("construct_printer_driver_info_6: status: %s\n", win_errstr(status)));
5647 if (!W_ERROR_IS_OK(status)) {
5648 free_a_printer(&printer,2);
5649 return WERR_UNKNOWN_PRINTER_DRIVER;
5653 fill_printer_driver_info_6(info, driver, servername);
5655 free_a_printer(&printer,2);
5656 free_a_printer_driver(driver, 3);
5661 /****************************************************************************
5662 ****************************************************************************/
5664 static void free_printer_driver_info_3(DRIVER_INFO_3 *info)
5666 SAFE_FREE(info->dependentfiles);
5669 /****************************************************************************
5670 ****************************************************************************/
5672 static void free_printer_driver_info_6(DRIVER_INFO_6 *info)
5674 SAFE_FREE(info->dependentfiles);
5677 /****************************************************************************
5678 ****************************************************************************/
5680 static WERROR getprinterdriver2_level1(const char *servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed)
5682 DRIVER_INFO_1 *info=NULL;
5685 if((info=SMB_MALLOC_P(DRIVER_INFO_1)) == NULL)
5688 result = construct_printer_driver_info_1(info, snum, servername, architecture, version);
5689 if (!W_ERROR_IS_OK(result))
5692 /* check the required size. */
5693 *needed += spoolss_size_printer_driver_info_1(info);
5695 if (*needed > offered) {
5696 result = WERR_INSUFFICIENT_BUFFER;
5700 if (!rpcbuf_alloc_size(buffer, *needed)) {
5701 result = WERR_NOMEM;
5705 /* fill the buffer with the structures */
5706 smb_io_printer_driver_info_1("", buffer, info, 0);
5715 /****************************************************************************
5716 ****************************************************************************/
5718 static WERROR getprinterdriver2_level2(const char *servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed)
5720 DRIVER_INFO_2 *info=NULL;
5723 if((info=SMB_MALLOC_P(DRIVER_INFO_2)) == NULL)
5726 result = construct_printer_driver_info_2(info, snum, servername, architecture, version);
5727 if (!W_ERROR_IS_OK(result))
5730 /* check the required size. */
5731 *needed += spoolss_size_printer_driver_info_2(info);
5733 if (*needed > offered) {
5734 result = WERR_INSUFFICIENT_BUFFER;
5738 if (!rpcbuf_alloc_size(buffer, *needed)) {
5739 result = WERR_NOMEM;
5743 /* fill the buffer with the structures */
5744 smb_io_printer_driver_info_2("", buffer, info, 0);
5753 /****************************************************************************
5754 ****************************************************************************/
5756 static WERROR getprinterdriver2_level3(const char *servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed)
5763 result = construct_printer_driver_info_3(&info, snum, servername, architecture, version);
5764 if (!W_ERROR_IS_OK(result))
5767 /* check the required size. */
5768 *needed += spoolss_size_printer_driver_info_3(&info);
5770 if (*needed > offered) {
5771 result = WERR_INSUFFICIENT_BUFFER;
5775 if (!rpcbuf_alloc_size(buffer, *needed)) {
5776 result = WERR_NOMEM;
5780 /* fill the buffer with the structures */
5781 smb_io_printer_driver_info_3("", buffer, &info, 0);
5784 free_printer_driver_info_3(&info);
5789 /****************************************************************************
5790 ****************************************************************************/
5792 static WERROR getprinterdriver2_level6(const char *servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed)
5799 result = construct_printer_driver_info_6(&info, snum, servername, architecture, version);
5800 if (!W_ERROR_IS_OK(result))
5803 /* check the required size. */
5804 *needed += spoolss_size_printer_driver_info_6(&info);
5806 if (*needed > offered) {
5807 result = WERR_INSUFFICIENT_BUFFER;
5811 if (!rpcbuf_alloc_size(buffer, *needed)) {
5812 result = WERR_NOMEM;
5816 /* fill the buffer with the structures */
5817 smb_io_printer_driver_info_6("", buffer, &info, 0);
5820 free_printer_driver_info_6(&info);
5825 /****************************************************************************
5826 ****************************************************************************/
5828 WERROR _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_u, SPOOL_R_GETPRINTERDRIVER2 *r_u)
5830 POLICY_HND *handle = &q_u->handle;
5831 UNISTR2 *uni_arch = &q_u->architecture;
5832 uint32 level = q_u->level;
5833 uint32 clientmajorversion = q_u->clientmajorversion;
5834 RPC_BUFFER *buffer = NULL;
5835 uint32 offered = q_u->offered;
5836 uint32 *needed = &r_u->needed;
5837 uint32 *servermajorversion = &r_u->servermajorversion;
5838 uint32 *serverminorversion = &r_u->serverminorversion;
5839 Printer_entry *printer;
5842 fstring architecture;
5845 /* that's an [in out] buffer */
5847 if (!q_u->buffer && (offered!=0)) {
5848 return WERR_INVALID_PARAM;
5851 if (offered > MAX_RPC_DATA_SIZE) {
5852 return WERR_INVALID_PARAM;
5855 rpcbuf_move(q_u->buffer, &r_u->buffer);
5856 buffer = r_u->buffer;
5858 DEBUG(4,("_spoolss_getprinterdriver2\n"));
5860 if ( !(printer = find_printer_index_by_hnd( p, handle )) ) {
5861 DEBUG(0,("_spoolss_getprinterdriver2: invalid printer handle!\n"));
5862 return WERR_INVALID_PRINTER_NAME;
5866 *servermajorversion = 0;
5867 *serverminorversion = 0;
5869 fstrcpy(servername, get_server_name( printer ));
5870 unistr2_to_ascii(architecture, uni_arch, sizeof(architecture));
5872 if (!get_printer_snum(p, handle, &snum, NULL))
5877 return getprinterdriver2_level1(servername, architecture, clientmajorversion, snum, buffer, offered, needed);
5879 return getprinterdriver2_level2(servername, architecture, clientmajorversion, snum, buffer, offered, needed);
5881 return getprinterdriver2_level3(servername, architecture, clientmajorversion, snum, buffer, offered, needed);
5883 return getprinterdriver2_level6(servername, architecture, clientmajorversion, snum, buffer, offered, needed);
5886 /* apparently this call is the equivalent of
5887 EnumPrinterDataEx() for the DsDriver key */
5892 return WERR_UNKNOWN_LEVEL;
5896 /****************************************************************
5897 _spoolss_StartPagePrinter
5898 ****************************************************************/
5900 WERROR _spoolss_StartPagePrinter(pipes_struct *p,
5901 struct spoolss_StartPagePrinter *r)
5903 POLICY_HND *handle = r->in.handle;
5905 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5908 DEBUG(3,("_spoolss_StartPagePrinter: "
5909 "Error in startpageprinter printer handle\n"));
5913 Printer->page_started=True;
5917 /****************************************************************
5918 _spoolss_EndPagePrinter
5919 ****************************************************************/
5921 WERROR _spoolss_EndPagePrinter(pipes_struct *p,
5922 struct spoolss_EndPagePrinter *r)
5924 POLICY_HND *handle = r->in.handle;
5927 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5930 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5931 OUR_HANDLE(handle)));
5935 if (!get_printer_snum(p, handle, &snum, NULL))
5938 Printer->page_started=False;
5939 print_job_endpage(snum, Printer->jobid);
5944 /****************************************************************
5945 _spoolss_StartDocPrinter
5946 ****************************************************************/
5948 WERROR _spoolss_StartDocPrinter(pipes_struct *p,
5949 struct spoolss_StartDocPrinter *r)
5951 POLICY_HND *handle = r->in.handle;
5952 uint32_t *jobid = r->out.job_id;
5953 struct spoolss_DocumentInfo1 *info_1;
5955 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5958 DEBUG(2,("_spoolss_StartDocPrinter: "
5959 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle)));
5963 if (r->in.level != 1) {
5964 return WERR_UNKNOWN_LEVEL;
5967 info_1 = r->in.info.info1;
5970 * a nice thing with NT is it doesn't listen to what you tell it.
5971 * when asked to send _only_ RAW datas, it tries to send datas
5974 * So I add checks like in NT Server ...
5977 if (info_1->datatype) {
5978 if (strcmp(info_1->datatype, "RAW") != 0) {
5980 return WERR_INVALID_DATATYPE;
5984 /* get the share number of the printer */
5985 if (!get_printer_snum(p, handle, &snum, NULL)) {
5989 Printer->jobid = print_job_start(p->server_info, snum,
5990 info_1->document_name,
5991 Printer->nt_devmode);
5993 /* An error occured in print_job_start() so return an appropriate
5996 if (Printer->jobid == -1) {
5997 return map_werror_from_unix(errno);
6000 Printer->document_started=True;
6001 (*jobid) = Printer->jobid;
6006 /****************************************************************
6007 _spoolss_EndDocPrinter
6008 ****************************************************************/
6010 WERROR _spoolss_EndDocPrinter(pipes_struct *p,
6011 struct spoolss_EndDocPrinter *r)
6013 POLICY_HND *handle = r->in.handle;
6015 return _spoolss_enddocprinter_internal(p, handle);
6018 /****************************************************************
6019 _spoolss_WritePrinter
6020 ****************************************************************/
6022 WERROR _spoolss_WritePrinter(pipes_struct *p,
6023 struct spoolss_WritePrinter *r)
6025 POLICY_HND *handle = r->in.handle;
6026 uint32 buffer_size = r->in._data_size;
6027 uint8 *buffer = r->in.data.data;
6028 uint32 *buffer_written = &r->in._data_size;
6030 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
6033 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
6034 OUR_HANDLE(handle)));
6035 *r->out.num_written = r->in._data_size;
6039 if (!get_printer_snum(p, handle, &snum, NULL))
6042 (*buffer_written) = (uint32)print_job_write(snum, Printer->jobid, (const char *)buffer,
6043 (SMB_OFF_T)-1, (size_t)buffer_size);
6044 if (*buffer_written == (uint32)-1) {
6045 *r->out.num_written = 0;
6046 if (errno == ENOSPC)
6047 return WERR_NO_SPOOL_SPACE;
6049 return WERR_ACCESS_DENIED;
6052 *r->out.num_written = r->in._data_size;
6057 /********************************************************************
6058 * api_spoolss_getprinter
6059 * called from the spoolss dispatcher
6061 ********************************************************************/
6063 static WERROR control_printer(POLICY_HND *handle, uint32 command,
6067 WERROR errcode = WERR_BADFUNC;
6068 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
6071 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle)));
6075 if (!get_printer_snum(p, handle, &snum, NULL))
6079 case SPOOLSS_PRINTER_CONTROL_PAUSE:
6080 if (print_queue_pause(p->server_info, snum, &errcode)) {
6084 case SPOOLSS_PRINTER_CONTROL_RESUME:
6085 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
6086 if (print_queue_resume(p->server_info, snum, &errcode)) {
6090 case SPOOLSS_PRINTER_CONTROL_PURGE:
6091 if (print_queue_purge(p->server_info, snum, &errcode)) {
6096 return WERR_UNKNOWN_LEVEL;
6103 /****************************************************************
6104 _spoolss_AbortPrinter
6105 * From MSDN: "Deletes printer's spool file if printer is configured
6107 ****************************************************************/
6109 WERROR _spoolss_AbortPrinter(pipes_struct *p,
6110 struct spoolss_AbortPrinter *r)
6112 POLICY_HND *handle = r->in.handle;
6113 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
6115 WERROR errcode = WERR_OK;
6118 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
6119 OUR_HANDLE(handle)));
6123 if (!get_printer_snum(p, handle, &snum, NULL))
6126 print_job_delete(p->server_info, snum, Printer->jobid, &errcode );
6131 /********************************************************************
6132 * called by spoolss_api_setprinter
6133 * when updating a printer description
6134 ********************************************************************/
6136 static WERROR update_printer_sec(POLICY_HND *handle,
6137 pipes_struct *p, SEC_DESC_BUF *secdesc_ctr)
6139 SEC_DESC_BUF *new_secdesc_ctr = NULL, *old_secdesc_ctr = NULL;
6143 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
6145 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
6146 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
6147 OUR_HANDLE(handle)));
6149 result = WERR_BADFID;
6154 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
6155 result = WERR_INVALID_PARAM;
6159 /* Check the user has permissions to change the security
6160 descriptor. By experimentation with two NT machines, the user
6161 requires Full Access to the printer to change security
6164 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
6165 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
6166 result = WERR_ACCESS_DENIED;
6170 /* NT seems to like setting the security descriptor even though
6171 nothing may have actually changed. */
6173 if ( !nt_printing_getsec(p->mem_ctx, Printer->sharename, &old_secdesc_ctr)) {
6174 DEBUG(2,("update_printer_sec: nt_printing_getsec() failed\n"));
6175 result = WERR_BADFID;
6179 if (DEBUGLEVEL >= 10) {
6183 the_acl = old_secdesc_ctr->sd->dacl;
6184 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
6185 PRINTERNAME(snum), the_acl->num_aces));
6187 for (i = 0; i < the_acl->num_aces; i++) {
6188 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
6189 &the_acl->aces[i].trustee),
6190 the_acl->aces[i].access_mask));
6193 the_acl = secdesc_ctr->sd->dacl;
6196 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
6197 PRINTERNAME(snum), the_acl->num_aces));
6199 for (i = 0; i < the_acl->num_aces; i++) {
6200 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
6201 &the_acl->aces[i].trustee),
6202 the_acl->aces[i].access_mask));
6205 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
6209 new_secdesc_ctr = sec_desc_merge(p->mem_ctx, secdesc_ctr, old_secdesc_ctr);
6210 if (!new_secdesc_ctr) {
6211 result = WERR_NOMEM;
6215 if (sec_desc_equal(new_secdesc_ctr->sd, old_secdesc_ctr->sd)) {
6220 result = nt_printing_setsec(Printer->sharename, new_secdesc_ctr);
6227 /********************************************************************
6228 Canonicalize printer info from a client
6230 ATTN: It does not matter what we set the servername to hear
6231 since we do the necessary work in get_a_printer() to set it to
6232 the correct value based on what the client sent in the
6233 _spoolss_open_printer_ex().
6234 ********************************************************************/
6236 static bool check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum)
6238 fstring printername;
6241 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
6242 "portname=%s drivername=%s comment=%s location=%s\n",
6243 info->servername, info->printername, info->sharename,
6244 info->portname, info->drivername, info->comment, info->location));
6246 /* we force some elements to "correct" values */
6247 slprintf(info->servername, sizeof(info->servername)-1, "\\\\%s", global_myname());
6248 fstrcpy(info->sharename, lp_servicename(snum));
6250 /* check to see if we allow printername != sharename */
6252 if ( lp_force_printername(snum) ) {
6253 slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s",
6254 global_myname(), info->sharename );
6257 /* make sure printername is in \\server\printername format */
6259 fstrcpy( printername, info->printername );
6261 if ( printername[0] == '\\' && printername[1] == '\\' ) {
6262 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
6266 slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s",
6267 global_myname(), p );
6270 info->attributes |= PRINTER_ATTRIBUTE_SAMBA;
6271 info->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
6278 /****************************************************************************
6279 ****************************************************************************/
6281 WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *portname, const char *uri )
6283 char *cmd = lp_addport_cmd();
6284 char *command = NULL;
6286 SE_PRIV se_printop = SE_PRINT_OPERATOR;
6287 bool is_print_op = False;
6290 return WERR_ACCESS_DENIED;
6293 command = talloc_asprintf(ctx,
6294 "%s \"%s\" \"%s\"", cmd, portname, uri );
6300 is_print_op = user_has_privileges( token, &se_printop );
6302 DEBUG(10,("Running [%s]\n", command));
6304 /********* BEGIN SePrintOperatorPrivilege **********/
6309 ret = smbrun(command, NULL);
6314 /********* END SePrintOperatorPrivilege **********/
6316 DEBUGADD(10,("returned [%d]\n", ret));
6318 TALLOC_FREE(command);
6321 return WERR_ACCESS_DENIED;
6327 /****************************************************************************
6328 ****************************************************************************/
6330 bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer)
6332 char *cmd = lp_addprinter_cmd();
6334 char *command = NULL;
6338 SE_PRIV se_printop = SE_PRINT_OPERATOR;
6339 bool is_print_op = False;
6340 char *remote_machine = talloc_strdup(ctx, "%m");
6342 if (!remote_machine) {
6345 remote_machine = talloc_sub_basic(ctx,
6346 current_user_info.smb_name,
6347 current_user_info.domain,
6349 if (!remote_machine) {
6353 command = talloc_asprintf(ctx,
6354 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
6355 cmd, printer->info_2->printername, printer->info_2->sharename,
6356 printer->info_2->portname, printer->info_2->drivername,
6357 printer->info_2->location, printer->info_2->comment, remote_machine);
6363 is_print_op = user_has_privileges( token, &se_printop );
6365 DEBUG(10,("Running [%s]\n", command));
6367 /********* BEGIN SePrintOperatorPrivilege **********/
6372 if ( (ret = smbrun(command, &fd)) == 0 ) {
6373 /* Tell everyone we updated smb.conf. */
6374 message_send_all(smbd_messaging_context(),
6375 MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
6381 /********* END SePrintOperatorPrivilege **********/
6383 DEBUGADD(10,("returned [%d]\n", ret));
6385 TALLOC_FREE(command);
6386 TALLOC_FREE(remote_machine);
6394 /* reload our services immediately */
6395 reload_services( False );
6398 /* Get lines and convert them back to dos-codepage */
6399 qlines = fd_lines_load(fd, &numlines, 0, NULL);
6400 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
6403 /* Set the portname to what the script says the portname should be. */
6404 /* but don't require anything to be return from the script exit a good error code */
6407 /* Set the portname to what the script says the portname should be. */
6408 strncpy(printer->info_2->portname, qlines[0], sizeof(printer->info_2->portname));
6409 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
6412 TALLOC_FREE(qlines);
6417 /********************************************************************
6418 * Called by spoolss_api_setprinter
6419 * when updating a printer description.
6420 ********************************************************************/
6422 static WERROR update_printer(pipes_struct *p, POLICY_HND *handle,
6423 struct spoolss_SetPrinterInfoCtr *info_ctr,
6424 struct spoolss_DeviceMode *devmode)
6427 NT_PRINTER_INFO_LEVEL *printer = NULL, *old_printer = NULL;
6428 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
6433 DEBUG(8,("update_printer\n"));
6438 result = WERR_BADFID;
6442 if (!get_printer_snum(p, handle, &snum, NULL)) {
6443 result = WERR_BADFID;
6447 if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum))) ||
6448 (!W_ERROR_IS_OK(get_a_printer(Printer, &old_printer, 2, lp_const_servicename(snum))))) {
6449 result = WERR_BADFID;
6453 DEBUGADD(8,("Converting info_2 struct\n"));
6456 * convert_printer_info converts the incoming
6457 * info from the client and overwrites the info
6458 * just read from the tdb in the pointer 'printer'.
6461 if (!convert_printer_info_new(info_ctr, printer)) {
6462 result = WERR_NOMEM;
6467 /* we have a valid devmode
6468 convert it and link it*/
6470 DEBUGADD(8,("update_printer: Converting the devicemode struct\n"));
6471 if (!convert_devicemode_new(printer->info_2->printername,
6473 &printer->info_2->devmode)) {
6474 result = WERR_NOMEM;
6479 /* Do sanity check on the requested changes for Samba */
6481 if (!check_printer_ok(printer->info_2, snum)) {
6482 result = WERR_INVALID_PARAM;
6486 /* FIXME!!! If the driver has changed we really should verify that
6487 it is installed before doing much else --jerry */
6489 /* Check calling user has permission to update printer description */
6491 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6492 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6493 result = WERR_ACCESS_DENIED;
6497 /* Call addprinter hook */
6498 /* Check changes to see if this is really needed */
6500 if ( *lp_addprinter_cmd()
6501 && (!strequal(printer->info_2->drivername, old_printer->info_2->drivername)
6502 || !strequal(printer->info_2->comment, old_printer->info_2->comment)
6503 || !strequal(printer->info_2->portname, old_printer->info_2->portname)
6504 || !strequal(printer->info_2->location, old_printer->info_2->location)) )
6506 /* add_printer_hook() will call reload_services() */
6508 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
6510 result = WERR_ACCESS_DENIED;
6516 * When a *new* driver is bound to a printer, the drivername is used to
6517 * lookup previously saved driver initialization info, which is then
6518 * bound to the printer, simulating what happens in the Windows arch.
6520 if (!strequal(printer->info_2->drivername, old_printer->info_2->drivername))
6522 if (!set_driver_init(printer, 2))
6524 DEBUG(5,("update_printer: Error restoring driver initialization data for driver [%s]!\n",
6525 printer->info_2->drivername));
6528 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6529 printer->info_2->drivername));
6531 notify_printer_driver(snum, printer->info_2->drivername);
6535 * flag which changes actually occured. This is a small subset of
6536 * all the possible changes. We also have to update things in the
6540 if (!strequal(printer->info_2->comment, old_printer->info_2->comment)) {
6541 init_unistr2( &buffer, printer->info_2->comment, UNI_STR_TERMINATE);
6542 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "description",
6543 REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 );
6545 notify_printer_comment(snum, printer->info_2->comment);
6548 if (!strequal(printer->info_2->sharename, old_printer->info_2->sharename)) {
6549 init_unistr2( &buffer, printer->info_2->sharename, UNI_STR_TERMINATE);
6550 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "shareName",
6551 REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 );
6553 notify_printer_sharename(snum, printer->info_2->sharename);
6556 if (!strequal(printer->info_2->printername, old_printer->info_2->printername)) {
6559 if ( (pname = strchr_m( printer->info_2->printername+2, '\\' )) != NULL )
6562 pname = printer->info_2->printername;
6565 init_unistr2( &buffer, pname, UNI_STR_TERMINATE);
6566 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "printerName",
6567 REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 );
6569 notify_printer_printername( snum, pname );
6572 if (!strequal(printer->info_2->portname, old_printer->info_2->portname)) {
6573 init_unistr2( &buffer, printer->info_2->portname, UNI_STR_TERMINATE);
6574 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "portName",
6575 REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 );
6577 notify_printer_port(snum, printer->info_2->portname);
6580 if (!strequal(printer->info_2->location, old_printer->info_2->location)) {
6581 init_unistr2( &buffer, printer->info_2->location, UNI_STR_TERMINATE);
6582 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "location",
6583 REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 );
6585 notify_printer_location(snum, printer->info_2->location);
6588 /* here we need to update some more DsSpooler keys */
6589 /* uNCName, serverName, shortServerName */
6591 init_unistr2( &buffer, global_myname(), UNI_STR_TERMINATE);
6592 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "serverName",
6593 REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 );
6594 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "shortServerName",
6595 REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 );
6597 slprintf( asc_buffer, sizeof(asc_buffer)-1, "\\\\%s\\%s",
6598 global_myname(), printer->info_2->sharename );
6599 init_unistr2( &buffer, asc_buffer, UNI_STR_TERMINATE);
6600 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "uNCName",
6601 REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 );
6603 /* Update printer info */
6604 result = mod_a_printer(printer, 2);
6607 free_a_printer(&printer, 2);
6608 free_a_printer(&old_printer, 2);
6614 /****************************************************************************
6615 ****************************************************************************/
6616 static WERROR publish_or_unpublish_printer(pipes_struct *p, POLICY_HND *handle,
6617 struct spoolss_SetPrinterInfo7 *info7)
6621 Printer_entry *Printer;
6623 if ( lp_security() != SEC_ADS ) {
6624 return WERR_UNKNOWN_LEVEL;
6627 Printer = find_printer_index_by_hnd(p, handle);
6629 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6634 if (!get_printer_snum(p, handle, &snum, NULL))
6637 nt_printer_publish(Printer, snum, info7->action);
6641 return WERR_UNKNOWN_LEVEL;
6645 /****************************************************************
6647 ****************************************************************/
6649 WERROR _spoolss_SetPrinter(pipes_struct *p,
6650 struct spoolss_SetPrinter *r)
6652 POLICY_HND *handle = r->in.handle;
6655 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
6658 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6659 OUR_HANDLE(handle)));
6663 /* check the level */
6664 switch (r->in.info_ctr->level) {
6666 return control_printer(handle, r->in.command, p);
6668 result = update_printer(p, handle,
6670 r->in.devmode_ctr->devmode);
6671 if (!W_ERROR_IS_OK(result))
6673 if (r->in.secdesc_ctr->sd)
6674 result = update_printer_sec(handle, p,
6678 return update_printer_sec(handle, p,
6681 return publish_or_unpublish_printer(p, handle,
6682 r->in.info_ctr->info.info7);
6684 return WERR_UNKNOWN_LEVEL;
6688 /****************************************************************
6689 _spoolss_FindClosePrinterNotify
6690 ****************************************************************/
6692 WERROR _spoolss_FindClosePrinterNotify(pipes_struct *p,
6693 struct spoolss_FindClosePrinterNotify *r)
6695 POLICY_HND *handle = r->in.handle;
6696 Printer_entry *Printer= find_printer_index_by_hnd(p, handle);
6699 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6700 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle)));
6704 if (Printer->notify.client_connected==True) {
6707 if ( Printer->printer_type == SPLHND_SERVER)
6709 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
6710 !get_printer_snum(p, handle, &snum, NULL) )
6713 srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
6716 Printer->notify.flags=0;
6717 Printer->notify.options=0;
6718 Printer->notify.localmachine[0]='\0';
6719 Printer->notify.printerlocal=0;
6720 TALLOC_FREE(Printer->notify.option);
6721 Printer->notify.client_connected=False;
6726 /****************************************************************
6728 ****************************************************************/
6730 WERROR _spoolss_AddJob(pipes_struct *p,
6731 struct spoolss_AddJob *r)
6733 if (!r->in.buffer && (r->in.offered != 0)) {
6734 return WERR_INVALID_PARAM;
6737 /* this is what a NT server returns for AddJob. AddJob must fail on
6738 * non-local printers */
6740 if (r->in.level != 1) {
6741 return WERR_UNKNOWN_LEVEL;
6744 return WERR_INVALID_PARAM;
6747 /****************************************************************************
6748 ****************************************************************************/
6750 static void fill_job_info_1(JOB_INFO_1 *job_info, const print_queue_struct *queue,
6751 int position, int snum,
6752 const NT_PRINTER_INFO_LEVEL *ntprinter)
6756 t=gmtime(&queue->time);
6758 job_info->jobid=queue->job;
6759 init_unistr(&job_info->printername, lp_servicename(snum));
6760 init_unistr(&job_info->machinename, ntprinter->info_2->servername);
6761 init_unistr(&job_info->username, queue->fs_user);
6762 init_unistr(&job_info->document, queue->fs_file);
6763 init_unistr(&job_info->datatype, "RAW");
6764 init_unistr(&job_info->text_status, "");
6765 job_info->status=nt_printj_status(queue->status);
6766 job_info->priority=queue->priority;
6767 job_info->position=position;
6768 job_info->totalpages=queue->page_count;
6769 job_info->pagesprinted=0;
6771 make_systemtime(&job_info->submitted, t);
6774 /****************************************************************************
6775 ****************************************************************************/
6777 static bool fill_job_info_2(JOB_INFO_2 *job_info, const print_queue_struct *queue,
6778 int position, int snum,
6779 const NT_PRINTER_INFO_LEVEL *ntprinter,
6780 DEVICEMODE *devmode)
6784 t=gmtime(&queue->time);
6786 job_info->jobid=queue->job;
6788 init_unistr(&job_info->printername, ntprinter->info_2->printername);
6790 init_unistr(&job_info->machinename, ntprinter->info_2->servername);
6791 init_unistr(&job_info->username, queue->fs_user);
6792 init_unistr(&job_info->document, queue->fs_file);
6793 init_unistr(&job_info->notifyname, queue->fs_user);
6794 init_unistr(&job_info->datatype, "RAW");
6795 init_unistr(&job_info->printprocessor, "winprint");
6796 init_unistr(&job_info->parameters, "");
6797 init_unistr(&job_info->drivername, ntprinter->info_2->drivername);
6798 init_unistr(&job_info->text_status, "");
6800 /* and here the security descriptor */
6802 job_info->status=nt_printj_status(queue->status);
6803 job_info->priority=queue->priority;
6804 job_info->position=position;
6805 job_info->starttime=0;
6806 job_info->untiltime=0;
6807 job_info->totalpages=queue->page_count;
6808 job_info->size=queue->size;
6809 make_systemtime(&(job_info->submitted), t);
6810 job_info->timeelapsed=0;
6811 job_info->pagesprinted=0;
6813 job_info->devmode = devmode;
6818 /****************************************************************************
6819 Enumjobs at level 1.
6820 ****************************************************************************/
6822 static WERROR enumjobs_level1(const print_queue_struct *queue, int snum,
6823 const NT_PRINTER_INFO_LEVEL *ntprinter,
6824 RPC_BUFFER *buffer, uint32 offered,
6825 uint32 *needed, uint32 *returned)
6829 WERROR result = WERR_OK;
6831 info=SMB_MALLOC_ARRAY(JOB_INFO_1,*returned);
6837 for (i=0; i<*returned; i++)
6838 fill_job_info_1( &info[i], &queue[i], i, snum, ntprinter );
6840 /* check the required size. */
6841 for (i=0; i<*returned; i++)
6842 (*needed) += spoolss_size_job_info_1(&info[i]);
6844 if (*needed > offered) {
6845 result = WERR_INSUFFICIENT_BUFFER;
6849 if (!rpcbuf_alloc_size(buffer, *needed)) {
6850 result = WERR_NOMEM;
6854 /* fill the buffer with the structures */
6855 for (i=0; i<*returned; i++)
6856 smb_io_job_info_1("", buffer, &info[i], 0);
6862 if ( !W_ERROR_IS_OK(result) )
6868 /****************************************************************************
6869 Enumjobs at level 2.
6870 ****************************************************************************/
6872 static WERROR enumjobs_level2(const print_queue_struct *queue, int snum,
6873 const NT_PRINTER_INFO_LEVEL *ntprinter,
6874 RPC_BUFFER *buffer, uint32 offered,
6875 uint32 *needed, uint32 *returned)
6877 JOB_INFO_2 *info = NULL;
6879 WERROR result = WERR_OK;
6880 DEVICEMODE *devmode = NULL;
6882 if ( !(info = SMB_MALLOC_ARRAY(JOB_INFO_2,*returned)) ) {
6887 /* this should not be a failure condition if the devmode is NULL */
6889 devmode = construct_dev_mode(lp_const_servicename(snum));
6891 for (i=0; i<*returned; i++)
6892 fill_job_info_2(&(info[i]), &queue[i], i, snum, ntprinter, devmode);
6894 /* check the required size. */
6895 for (i=0; i<*returned; i++)
6896 (*needed) += spoolss_size_job_info_2(&info[i]);
6898 if (*needed > offered) {
6899 result = WERR_INSUFFICIENT_BUFFER;
6903 if (!rpcbuf_alloc_size(buffer, *needed)) {
6904 result = WERR_NOMEM;
6908 /* fill the buffer with the structures */
6909 for (i=0; i<*returned; i++)
6910 smb_io_job_info_2("", buffer, &info[i], 0);
6913 free_devmode(devmode);
6916 if ( !W_ERROR_IS_OK(result) )
6923 /****************************************************************************
6925 ****************************************************************************/
6927 WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJOBS *r_u)
6929 POLICY_HND *handle = &q_u->handle;
6930 uint32 level = q_u->level;
6931 RPC_BUFFER *buffer = NULL;
6932 uint32 offered = q_u->offered;
6933 uint32 *needed = &r_u->needed;
6934 uint32 *returned = &r_u->returned;
6936 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
6938 print_status_struct prt_status;
6939 print_queue_struct *queue=NULL;
6941 /* that's an [in out] buffer */
6943 if (!q_u->buffer && (offered!=0)) {
6944 return WERR_INVALID_PARAM;
6947 if (offered > MAX_RPC_DATA_SIZE) {
6948 return WERR_INVALID_PARAM;
6951 rpcbuf_move(q_u->buffer, &r_u->buffer);
6952 buffer = r_u->buffer;
6954 DEBUG(4,("_spoolss_enumjobs\n"));
6959 /* lookup the printer snum and tdb entry */
6961 if (!get_printer_snum(p, handle, &snum, NULL))
6964 wret = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum));
6965 if ( !W_ERROR_IS_OK(wret) )
6968 *returned = print_queue_status(snum, &queue, &prt_status);
6969 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n", *returned, prt_status.status, prt_status.message));
6971 if (*returned == 0) {
6973 free_a_printer(&ntprinter, 2);
6979 wret = enumjobs_level1(queue, snum, ntprinter, buffer, offered, needed, returned);
6982 wret = enumjobs_level2(queue, snum, ntprinter, buffer, offered, needed, returned);
6986 wret = WERR_UNKNOWN_LEVEL;
6991 free_a_printer( &ntprinter, 2 );
6995 /****************************************************************
6996 _spoolss_ScheduleJob
6997 ****************************************************************/
6999 WERROR _spoolss_ScheduleJob(pipes_struct *p,
7000 struct spoolss_ScheduleJob *r)
7005 /****************************************************************
7007 ****************************************************************/
7009 WERROR _spoolss_SetJob(pipes_struct *p,
7010 struct spoolss_SetJob *r)
7012 POLICY_HND *handle = r->in.handle;
7013 uint32 jobid = r->in.job_id;
7014 uint32 command = r->in.command;
7017 WERROR errcode = WERR_BADFUNC;
7019 if (!get_printer_snum(p, handle, &snum, NULL)) {
7023 if (!print_job_exists(lp_const_servicename(snum), jobid)) {
7024 return WERR_INVALID_PRINTER_NAME;
7028 case SPOOLSS_JOB_CONTROL_CANCEL:
7029 case SPOOLSS_JOB_CONTROL_DELETE:
7030 if (print_job_delete(p->server_info, snum, jobid, &errcode)) {
7034 case SPOOLSS_JOB_CONTROL_PAUSE:
7035 if (print_job_pause(p->server_info, snum, jobid, &errcode)) {
7039 case SPOOLSS_JOB_CONTROL_RESTART:
7040 case SPOOLSS_JOB_CONTROL_RESUME:
7041 if (print_job_resume(p->server_info, snum, jobid, &errcode)) {
7046 return WERR_UNKNOWN_LEVEL;
7052 /****************************************************************************
7053 Enumerates all printer drivers at level 1.
7054 ****************************************************************************/
7056 static WERROR enumprinterdrivers_level1(const char *servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
7061 fstring *list = NULL;
7062 NT_PRINTER_DRIVER_INFO_LEVEL driver;
7063 DRIVER_INFO_1 *driver_info_1=NULL;
7064 WERROR result = WERR_OK;
7068 for (version=0; version<DRIVER_MAX_VERSION; version++) {
7070 ndrivers=get_ntdrivers(&list, architecture, version);
7071 DEBUGADD(4,("we have:[%d] drivers in environment [%s] and version [%d]\n", ndrivers, architecture, version));
7073 if(ndrivers == -1) {
7074 SAFE_FREE(driver_info_1);
7079 if((driver_info_1=SMB_REALLOC_ARRAY(driver_info_1, DRIVER_INFO_1, *returned+ndrivers )) == NULL) {
7080 DEBUG(0,("enumprinterdrivers_level1: failed to enlarge driver info buffer!\n"));
7086 for (i=0; i<ndrivers; i++) {
7088 DEBUGADD(5,("\tdriver: [%s]\n", list[i]));
7089 ZERO_STRUCT(driver);
7090 status = get_a_printer_driver(&driver, 3, list[i],
7091 architecture, version);
7092 if (!W_ERROR_IS_OK(status)) {
7094 SAFE_FREE(driver_info_1);
7097 fill_printer_driver_info_1(&driver_info_1[*returned+i], driver, servername, architecture );
7098 free_a_printer_driver(driver, 3);
7101 *returned+=ndrivers;
7105 /* check the required size. */
7106 for (i=0; i<*returned; i++) {
7107 DEBUGADD(6,("adding driver [%d]'s size\n",i));
7108 *needed += spoolss_size_printer_driver_info_1(&driver_info_1[i]);
7111 if (*needed > offered) {
7112 result = WERR_INSUFFICIENT_BUFFER;
7116 if (!rpcbuf_alloc_size(buffer, *needed)) {
7117 result = WERR_NOMEM;
7121 /* fill the buffer with the driver structures */
7122 for (i=0; i<*returned; i++) {
7123 DEBUGADD(6,("adding driver [%d] to buffer\n",i));
7124 smb_io_printer_driver_info_1("", buffer, &driver_info_1[i], 0);
7128 SAFE_FREE(driver_info_1);
7130 if ( !W_ERROR_IS_OK(result) )
7136 /****************************************************************************
7137 Enumerates all printer drivers at level 2.
7138 ****************************************************************************/
7140 static WERROR enumprinterdrivers_level2(const char *servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
7145 fstring *list = NULL;
7146 NT_PRINTER_DRIVER_INFO_LEVEL driver;
7147 DRIVER_INFO_2 *driver_info_2=NULL;
7148 WERROR result = WERR_OK;
7152 for (version=0; version<DRIVER_MAX_VERSION; version++) {
7154 ndrivers=get_ntdrivers(&list, architecture, version);
7155 DEBUGADD(4,("we have:[%d] drivers in environment [%s] and version [%d]\n", ndrivers, architecture, version));
7157 if(ndrivers == -1) {
7158 SAFE_FREE(driver_info_2);
7163 if((driver_info_2=SMB_REALLOC_ARRAY(driver_info_2, DRIVER_INFO_2, *returned+ndrivers )) == NULL) {
7164 DEBUG(0,("enumprinterdrivers_level2: failed to enlarge driver info buffer!\n"));
7170 for (i=0; i<ndrivers; i++) {
7173 DEBUGADD(5,("\tdriver: [%s]\n", list[i]));
7174 ZERO_STRUCT(driver);
7175 status = get_a_printer_driver(&driver, 3, list[i],
7176 architecture, version);
7177 if (!W_ERROR_IS_OK(status)) {
7179 SAFE_FREE(driver_info_2);
7182 fill_printer_driver_info_2(&driver_info_2[*returned+i], driver, servername);
7183 free_a_printer_driver(driver, 3);
7186 *returned+=ndrivers;
7190 /* check the required size. */
7191 for (i=0; i<*returned; i++) {
7192 DEBUGADD(6,("adding driver [%d]'s size\n",i));
7193 *needed += spoolss_size_printer_driver_info_2(&(driver_info_2[i]));
7196 if (*needed > offered) {
7197 result = WERR_INSUFFICIENT_BUFFER;
7201 if (!rpcbuf_alloc_size(buffer, *needed)) {
7202 result = WERR_NOMEM;
7206 /* fill the buffer with the form structures */
7207 for (i=0; i<*returned; i++) {
7208 DEBUGADD(6,("adding driver [%d] to buffer\n",i));
7209 smb_io_printer_driver_info_2("", buffer, &(driver_info_2[i]), 0);
7213 SAFE_FREE(driver_info_2);
7215 if ( !W_ERROR_IS_OK(result) )
7221 /****************************************************************************
7222 Enumerates all printer drivers at level 3.
7223 ****************************************************************************/
7225 static WERROR enumprinterdrivers_level3(const char *servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
7230 fstring *list = NULL;
7231 DRIVER_INFO_3 *driver_info_3=NULL;
7232 NT_PRINTER_DRIVER_INFO_LEVEL driver;
7233 WERROR result = WERR_OK;
7237 for (version=0; version<DRIVER_MAX_VERSION; version++) {
7239 ndrivers=get_ntdrivers(&list, architecture, version);
7240 DEBUGADD(4,("we have:[%d] drivers in environment [%s] and version [%d]\n", ndrivers, architecture, version));
7242 if(ndrivers == -1) {
7243 SAFE_FREE(driver_info_3);
7248 if((driver_info_3=SMB_REALLOC_ARRAY(driver_info_3, DRIVER_INFO_3, *returned+ndrivers )) == NULL) {
7249 DEBUG(0,("enumprinterdrivers_level3: failed to enlarge driver info buffer!\n"));
7255 for (i=0; i<ndrivers; i++) {
7258 DEBUGADD(5,("\tdriver: [%s]\n", list[i]));
7259 ZERO_STRUCT(driver);
7260 status = get_a_printer_driver(&driver, 3, list[i],
7261 architecture, version);
7262 if (!W_ERROR_IS_OK(status)) {
7264 SAFE_FREE(driver_info_3);
7267 fill_printer_driver_info_3(&driver_info_3[*returned+i], driver, servername);
7268 free_a_printer_driver(driver, 3);
7271 *returned+=ndrivers;
7275 /* check the required size. */
7276 for (i=0; i<*returned; i++) {
7277 DEBUGADD(6,("adding driver [%d]'s size\n",i));
7278 *needed += spoolss_size_printer_driver_info_3(&driver_info_3[i]);
7281 if (*needed > offered) {
7282 result = WERR_INSUFFICIENT_BUFFER;
7286 if (!rpcbuf_alloc_size(buffer, *needed)) {
7287 result = WERR_NOMEM;
7291 /* fill the buffer with the driver structures */
7292 for (i=0; i<*returned; i++) {
7293 DEBUGADD(6,("adding driver [%d] to buffer\n",i));
7294 smb_io_printer_driver_info_3("", buffer, &driver_info_3[i], 0);
7298 for (i=0; i<*returned; i++) {
7299 SAFE_FREE(driver_info_3[i].dependentfiles);
7302 SAFE_FREE(driver_info_3);
7304 if ( !W_ERROR_IS_OK(result) )
7310 /****************************************************************************
7311 Enumerates all printer drivers.
7312 ****************************************************************************/
7314 WERROR _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS *q_u, SPOOL_R_ENUMPRINTERDRIVERS *r_u)
7316 uint32 level = q_u->level;
7317 RPC_BUFFER *buffer = NULL;
7318 uint32 offered = q_u->offered;
7319 uint32 *needed = &r_u->needed;
7320 uint32 *returned = &r_u->returned;
7321 const char *cservername;
7323 fstring architecture;
7325 /* that's an [in out] buffer */
7327 if (!q_u->buffer && (offered!=0)) {
7328 return WERR_INVALID_PARAM;
7331 if (offered > MAX_RPC_DATA_SIZE) {
7332 return WERR_INVALID_PARAM;
7335 rpcbuf_move(q_u->buffer, &r_u->buffer);
7336 buffer = r_u->buffer;
7338 DEBUG(4,("_spoolss_enumprinterdrivers\n"));
7343 unistr2_to_ascii(architecture, &q_u->environment, sizeof(architecture));
7344 unistr2_to_ascii(servername, &q_u->name, sizeof(servername));
7346 cservername = canon_servername(servername);
7348 if (!is_myname_or_ipaddr(cservername))
7349 return WERR_UNKNOWN_PRINTER_DRIVER;
7353 return enumprinterdrivers_level1(cservername, architecture, buffer, offered, needed, returned);
7355 return enumprinterdrivers_level2(cservername, architecture, buffer, offered, needed, returned);
7357 return enumprinterdrivers_level3(cservername, architecture, buffer, offered, needed, returned);
7359 return WERR_UNKNOWN_LEVEL;
7363 /****************************************************************************
7364 ****************************************************************************/
7366 static WERROR fill_form_info_1(TALLOC_CTX *mem_ctx,
7367 struct spoolss_FormInfo1 *r,
7368 const nt_forms_struct *form)
7370 r->form_name = talloc_strdup(mem_ctx, form->name);
7371 W_ERROR_HAVE_NO_MEMORY(r->form_name);
7373 r->flags = form->flag;
7374 r->size.width = form->width;
7375 r->size.height = form->length;
7376 r->area.left = form->left;
7377 r->area.top = form->top;
7378 r->area.right = form->right;
7379 r->area.bottom = form->bottom;
7384 /****************************************************************
7385 spoolss_enumforms_level1
7386 ****************************************************************/
7388 static WERROR spoolss_enumforms_level1(TALLOC_CTX *mem_ctx,
7389 const nt_forms_struct *builtin_forms,
7390 uint32_t num_builtin_forms,
7391 const nt_forms_struct *user_forms,
7392 uint32_t num_user_forms,
7393 union spoolss_FormInfo **info_p,
7396 union spoolss_FormInfo *info;
7397 WERROR result = WERR_OK;
7400 *count = num_builtin_forms + num_user_forms;
7402 info = TALLOC_ARRAY(mem_ctx, union spoolss_FormInfo, *count);
7403 W_ERROR_HAVE_NO_MEMORY(info);
7405 /* construct the list of form structures */
7406 for (i=0; i<num_builtin_forms; i++) {
7407 DEBUGADD(6,("Filling form number [%d]\n",i));
7408 result = fill_form_info_1(info, &info[i].info1,
7410 if (!W_ERROR_IS_OK(result)) {
7415 for (; i<num_user_forms; i++) {
7416 DEBUGADD(6,("Filling form number [%d]\n",i));
7417 result = fill_form_info_1(info, &info[i].info1,
7418 &user_forms[i-num_builtin_forms]);
7419 if (!W_ERROR_IS_OK(result)) {
7425 if (!W_ERROR_IS_OK(result)) {
7436 /****************************************************************
7438 ****************************************************************/
7440 WERROR _spoolss_EnumForms(pipes_struct *p,
7441 struct spoolss_EnumForms *r)
7444 nt_forms_struct *user_forms = NULL;
7445 nt_forms_struct *builtin_forms = NULL;
7446 uint32_t num_user_forms;
7447 uint32_t num_builtin_forms;
7451 *r->out.info = NULL;
7453 /* that's an [in out] buffer */
7455 if (!r->in.buffer && (r->in.offered != 0) ) {
7456 return WERR_INVALID_PARAM;
7459 DEBUG(4,("_spoolss_EnumForms\n"));
7460 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7461 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7463 num_builtin_forms = get_builtin_ntforms(&builtin_forms);
7464 DEBUGADD(5,("Number of builtin forms [%d]\n", num_builtin_forms));
7465 num_user_forms = get_ntforms(&user_forms);
7466 DEBUGADD(5,("Number of user forms [%d]\n", num_user_forms));
7468 if (num_user_forms + num_builtin_forms == 0) {
7469 SAFE_FREE(builtin_forms);
7470 SAFE_FREE(user_forms);
7471 return WERR_NO_MORE_ITEMS;
7474 switch (r->in.level) {
7476 result = spoolss_enumforms_level1(p->mem_ctx,
7485 result = WERR_UNKNOWN_LEVEL;
7489 SAFE_FREE(user_forms);
7490 SAFE_FREE(builtin_forms);
7492 if (!W_ERROR_IS_OK(result)) {
7496 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7497 spoolss_EnumForms, NULL,
7498 *r->out.info, r->in.level,
7500 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7501 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7503 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7506 /****************************************************************
7507 ****************************************************************/
7509 static WERROR find_form_byname(const char *name,
7510 nt_forms_struct *form)
7512 nt_forms_struct *list = NULL;
7513 int num_forms = 0, i = 0;
7515 if (get_a_builtin_ntform_by_string(name, form)) {
7519 num_forms = get_ntforms(&list);
7520 DEBUGADD(5,("Number of forms [%d]\n", num_forms));
7522 if (num_forms == 0) {
7526 /* Check if the requested name is in the list of form structures */
7527 for (i = 0; i < num_forms; i++) {
7529 DEBUG(4,("checking form %s (want %s)\n", list[i].name, name));
7531 if (strequal(name, list[i].name)) {
7532 DEBUGADD(6,("Found form %s number [%d]\n", name, i));
7544 /****************************************************************
7546 ****************************************************************/
7548 WERROR _spoolss_GetForm(pipes_struct *p,
7549 struct spoolss_GetForm *r)
7552 nt_forms_struct form;
7554 /* that's an [in out] buffer */
7556 if (!r->in.buffer && (r->in.offered != 0)) {
7557 return WERR_INVALID_PARAM;
7560 DEBUG(4,("_spoolss_GetForm\n"));
7561 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7562 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7564 result = find_form_byname(r->in.form_name, &form);
7565 if (!W_ERROR_IS_OK(result)) {
7566 TALLOC_FREE(r->out.info);
7570 switch (r->in.level) {
7572 result = fill_form_info_1(p->mem_ctx,
7573 &r->out.info->info1,
7578 result = WERR_UNKNOWN_LEVEL;
7582 if (!W_ERROR_IS_OK(result)) {
7583 TALLOC_FREE(r->out.info);
7587 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo, NULL,
7588 r->out.info, r->in.level);
7589 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7591 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7594 /****************************************************************************
7595 ****************************************************************************/
7597 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
7598 struct spoolss_PortInfo1 *r,
7601 r->port_name = talloc_strdup(mem_ctx, name);
7602 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7607 /****************************************************************************
7608 TODO: This probably needs distinguish between TCP/IP and Local ports
7610 ****************************************************************************/
7612 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
7613 struct spoolss_PortInfo2 *r,
7616 r->port_name = talloc_strdup(mem_ctx, name);
7617 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7619 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
7620 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
7622 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT); /* FIXME */
7623 W_ERROR_HAVE_NO_MEMORY(r->description);
7625 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
7632 /****************************************************************************
7633 wrapper around the enumer ports command
7634 ****************************************************************************/
7636 WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines )
7638 char *cmd = lp_enumports_cmd();
7639 char **qlines = NULL;
7640 char *command = NULL;
7648 /* if no hook then just fill in the default port */
7651 if (!(qlines = TALLOC_ARRAY( NULL, char*, 2 ))) {
7654 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7655 TALLOC_FREE(qlines);
7662 /* we have a valid enumport command */
7664 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7669 DEBUG(10,("Running [%s]\n", command));
7670 ret = smbrun(command, &fd);
7671 DEBUG(10,("Returned [%d]\n", ret));
7672 TALLOC_FREE(command);
7677 return WERR_ACCESS_DENIED;
7681 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7682 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7692 /****************************************************************************
7694 ****************************************************************************/
7696 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7697 union spoolss_PortInfo **info_p,
7700 union spoolss_PortInfo *info = NULL;
7702 WERROR result = WERR_OK;
7703 char **qlines = NULL;
7706 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7707 if (!W_ERROR_IS_OK(result)) {
7712 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7714 DEBUG(10,("Returning WERR_NOMEM\n"));
7715 result = WERR_NOMEM;
7719 for (i=0; i<numlines; i++) {
7720 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7721 result = fill_port_1(info, &info[i].info1, qlines[i]);
7722 if (!W_ERROR_IS_OK(result)) {
7727 TALLOC_FREE(qlines);
7730 if (!W_ERROR_IS_OK(result)) {
7732 TALLOC_FREE(qlines);
7744 /****************************************************************************
7746 ****************************************************************************/
7748 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7749 union spoolss_PortInfo **info_p,
7752 union spoolss_PortInfo *info = NULL;
7754 WERROR result = WERR_OK;
7755 char **qlines = NULL;
7758 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7759 if (!W_ERROR_IS_OK(result)) {
7764 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7766 DEBUG(10,("Returning WERR_NOMEM\n"));
7767 result = WERR_NOMEM;
7771 for (i=0; i<numlines; i++) {
7772 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7773 result = fill_port_2(info, &info[i].info2, qlines[i]);
7774 if (!W_ERROR_IS_OK(result)) {
7779 TALLOC_FREE(qlines);
7782 if (!W_ERROR_IS_OK(result)) {
7784 TALLOC_FREE(qlines);
7796 /****************************************************************
7798 ****************************************************************/
7800 WERROR _spoolss_EnumPorts(pipes_struct *p,
7801 struct spoolss_EnumPorts *r)
7805 /* that's an [in out] buffer */
7807 if (!r->in.buffer && (r->in.offered != 0)) {
7808 return WERR_INVALID_PARAM;
7811 DEBUG(4,("_spoolss_EnumPorts\n"));
7815 *r->out.info = NULL;
7817 switch (r->in.level) {
7819 result = enumports_level_1(p->mem_ctx, r->out.info,
7823 result = enumports_level_2(p->mem_ctx, r->out.info,
7827 return WERR_UNKNOWN_LEVEL;
7830 if (!W_ERROR_IS_OK(result)) {
7834 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7835 spoolss_EnumPorts, NULL,
7836 *r->out.info, r->in.level,
7838 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7839 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7841 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7844 /****************************************************************************
7845 ****************************************************************************/
7847 static WERROR spoolss_addprinterex_level_2(pipes_struct *p,
7849 struct spoolss_SetPrinterInfoCtr *info_ctr,
7850 struct spoolss_DeviceMode *devmode,
7851 struct security_descriptor *sec_desc,
7852 struct spoolss_UserLevelCtr *user_ctr,
7855 NT_PRINTER_INFO_LEVEL *printer = NULL;
7858 WERROR err = WERR_OK;
7860 if ( !(printer = TALLOC_ZERO_P(NULL, NT_PRINTER_INFO_LEVEL)) ) {
7861 DEBUG(0,("spoolss_addprinterex_level_2: malloc fail.\n"));
7865 /* convert from UNICODE to ASCII - this allocates the info_2 struct inside *printer.*/
7866 if (!convert_printer_info_new(info_ctr, printer)) {
7867 free_a_printer(&printer, 2);
7871 /* check to see if the printer already exists */
7873 if ((snum = print_queue_snum(printer->info_2->sharename)) != -1) {
7874 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7875 printer->info_2->sharename));
7876 free_a_printer(&printer, 2);
7877 return WERR_PRINTER_ALREADY_EXISTS;
7880 /* FIXME!!! smbd should check to see if the driver is installed before
7881 trying to add a printer like this --jerry */
7883 if (*lp_addprinter_cmd() ) {
7884 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
7886 free_a_printer(&printer,2);
7887 return WERR_ACCESS_DENIED;
7890 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
7891 "smb.conf parameter \"addprinter command\" is defined. This"
7892 "parameter must exist for this call to succeed\n",
7893 printer->info_2->sharename ));
7896 /* use our primary netbios name since get_a_printer() will convert
7897 it to what the client expects on a case by case basis */
7899 slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname(),
7900 printer->info_2->sharename);
7903 if ((snum = print_queue_snum(printer->info_2->sharename)) == -1) {
7904 free_a_printer(&printer,2);
7905 return WERR_ACCESS_DENIED;
7908 /* you must be a printer admin to add a new printer */
7909 if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) {
7910 free_a_printer(&printer,2);
7911 return WERR_ACCESS_DENIED;
7915 * Do sanity check on the requested changes for Samba.
7918 if (!check_printer_ok(printer->info_2, snum)) {
7919 free_a_printer(&printer,2);
7920 return WERR_INVALID_PARAM;
7924 * When a printer is created, the drivername bound to the printer is used
7925 * to lookup previously saved driver initialization info, which is then
7926 * bound to the new printer, simulating what happens in the Windows arch.
7931 set_driver_init(printer, 2);
7935 /* A valid devmode was included, convert and link it
7937 DEBUGADD(10, ("spoolss_addprinterex_level_2: devmode included, converting\n"));
7939 if (!convert_devicemode_new(printer->info_2->printername,
7941 &printer->info_2->devmode))
7945 /* write the ASCII on disk */
7946 err = mod_a_printer(printer, 2);
7947 if (!W_ERROR_IS_OK(err)) {
7948 free_a_printer(&printer,2);
7952 if (!open_printer_hnd(p, handle, name, PRINTER_ACCESS_ADMINISTER)) {
7953 /* Handle open failed - remove addition. */
7954 del_a_printer(printer->info_2->sharename);
7955 free_a_printer(&printer,2);
7956 ZERO_STRUCTP(handle);
7957 return WERR_ACCESS_DENIED;
7960 update_c_setprinter(False);
7961 free_a_printer(&printer,2);
7966 /****************************************************************
7967 _spoolss_AddPrinterEx
7968 ****************************************************************/
7970 WERROR _spoolss_AddPrinterEx(pipes_struct *p,
7971 struct spoolss_AddPrinterEx *r)
7973 switch (r->in.info_ctr->level) {
7975 /* we don't handle yet */
7976 /* but I know what to do ... */
7977 return WERR_UNKNOWN_LEVEL;
7979 return spoolss_addprinterex_level_2(p, r->in.server,
7981 r->in.devmode_ctr->devmode,
7982 r->in.secdesc_ctr->sd,
7983 r->in.userlevel_ctr,
7986 return WERR_UNKNOWN_LEVEL;
7990 /****************************************************************
7991 _spoolss_AddPrinterDriver
7992 ****************************************************************/
7994 WERROR _spoolss_AddPrinterDriver(pipes_struct *p,
7995 struct spoolss_AddPrinterDriver *r)
7997 uint32_t level = r->in.info_ctr->level;
7998 struct spoolss_AddDriverInfoCtr *info = r->in.info_ctr;
7999 WERROR err = WERR_OK;
8000 NT_PRINTER_DRIVER_INFO_LEVEL driver;
8001 fstring driver_name;
8005 switch (p->hdr_req.opnum) {
8006 case NDR_SPOOLSS_ADDPRINTERDRIVER:
8007 fn = "_spoolss_AddPrinterDriver";
8009 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
8010 fn = "_spoolss_AddPrinterDriverEx";
8013 return WERR_INVALID_PARAM;
8018 if (level != 3 && level != 6) {
8019 /* Clever hack from Martin Zielinski <mz@seh.de>
8020 * to allow downgrade from level 8 (Vista).
8022 DEBUG(0,("%s: level %d not yet implemented\n", fn, level));
8023 return WERR_UNKNOWN_LEVEL;
8026 ZERO_STRUCT(driver);
8028 if (!convert_printer_driver_info(info, &driver, level)) {
8033 DEBUG(5,("Cleaning driver's information\n"));
8034 err = clean_up_driver_struct(p, driver, level);
8035 if (!W_ERROR_IS_OK(err))
8038 DEBUG(5,("Moving driver to final destination\n"));
8039 if( !W_ERROR_IS_OK(err = move_driver_to_download_area(p, driver, level,
8044 if (add_a_printer_driver(driver, level)!=0) {
8045 err = WERR_ACCESS_DENIED;
8051 fstrcpy(driver_name,
8052 driver.info_3->name ? driver.info_3->name : "");
8055 fstrcpy(driver_name,
8056 driver.info_6->name ? driver.info_6->name : "");
8061 * I think this is where he DrvUpgradePrinter() hook would be
8062 * be called in a driver's interface DLL on a Windows NT 4.0/2k
8063 * server. Right now, we just need to send ourselves a message
8064 * to update each printer bound to this driver. --jerry
8067 if (!srv_spoolss_drv_upgrade_printer(driver_name)) {
8068 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
8073 * Based on the version (e.g. driver destination dir: 0=9x,2=Nt/2k,3=2k/Xp),
8074 * decide if the driver init data should be deleted. The rules are:
8075 * 1) never delete init data if it is a 9x driver, they don't use it anyway
8076 * 2) delete init data only if there is no 2k/Xp driver
8077 * 3) always delete init data
8078 * The generalized rule is always use init data from the highest order driver.
8079 * It is necessary to follow the driver install by an initialization step to
8080 * finish off this process.
8083 version = driver.info_3->cversion;
8084 else if (level == 6)
8085 version = driver.info_6->version;
8090 * 9x printer driver - never delete init data
8093 DEBUG(10,("%s: init data not deleted for 9x driver [%s]\n",
8098 * Nt or 2k (compatiblity mode) printer driver - only delete init data if
8099 * there is no 2k/Xp driver init data for this driver name.
8103 NT_PRINTER_DRIVER_INFO_LEVEL driver1;
8105 if (!W_ERROR_IS_OK(get_a_printer_driver(&driver1, 3, driver_name, "Windows NT x86", 3))) {
8107 * No 2k/Xp driver found, delete init data (if any) for the new Nt driver.
8109 if (!del_driver_init(driver_name))
8110 DEBUG(6,("%s: del_driver_init(%s) Nt failed!\n",
8114 * a 2k/Xp driver was found, don't delete init data because Nt driver will use it.
8116 free_a_printer_driver(driver1,3);
8117 DEBUG(10,("%s: init data not deleted for Nt driver [%s]\n",
8124 * 2k or Xp printer driver - always delete init data
8127 if (!del_driver_init(driver_name))
8128 DEBUG(6,("%s: del_driver_init(%s) 2k/Xp failed!\n",
8133 DEBUG(0,("%s: invalid level=%d\n", fn, level));
8139 free_a_printer_driver(driver, level);
8143 /****************************************************************
8144 _spoolss_AddPrinterDriverEx
8145 ****************************************************************/
8147 WERROR _spoolss_AddPrinterDriverEx(pipes_struct *p,
8148 struct spoolss_AddPrinterDriverEx *r)
8150 struct spoolss_AddPrinterDriver a;
8153 * we only support the semantics of AddPrinterDriver()
8154 * i.e. only copy files that are newer than existing ones
8157 if (r->in.flags != APD_COPY_NEW_FILES) {
8158 return WERR_ACCESS_DENIED;
8161 a.in.servername = r->in.servername;
8162 a.in.info_ctr = r->in.info_ctr;
8164 return _spoolss_AddPrinterDriver(p, &a);
8167 /****************************************************************************
8168 ****************************************************************************/
8170 struct _spoolss_paths {
8176 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
8178 static const struct _spoolss_paths spoolss_paths[]= {
8179 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
8180 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
8183 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
8184 const char *servername,
8185 const char *environment,
8189 const char *pservername = NULL;
8190 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
8191 const char *short_archi;
8195 /* environment may be empty */
8196 if (environment && strlen(environment)) {
8197 long_archi = environment;
8200 /* servername may be empty */
8201 if (servername && strlen(servername)) {
8202 pservername = canon_servername(servername);
8204 if (!is_myname_or_ipaddr(pservername)) {
8205 return WERR_INVALID_PARAM;
8209 if (!(short_archi = get_short_archi(long_archi))) {
8210 return WERR_INVALID_ENVIRONMENT;
8213 switch (component) {
8214 case SPOOLSS_PRTPROCS_PATH:
8215 case SPOOLSS_DRIVER_PATH:
8217 *path = talloc_asprintf(mem_ctx,
8220 spoolss_paths[component].share,
8223 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
8224 SPOOLSS_DEFAULT_SERVER_PATH,
8225 spoolss_paths[component].dir,
8230 return WERR_INVALID_PARAM;
8240 /****************************************************************************
8241 ****************************************************************************/
8243 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
8244 const char *servername,
8245 const char *environment,
8246 struct spoolss_DriverDirectoryInfo1 *r)
8251 werr = compose_spoolss_server_path(mem_ctx,
8254 SPOOLSS_DRIVER_PATH,
8256 if (!W_ERROR_IS_OK(werr)) {
8260 DEBUG(4,("printer driver directory: [%s]\n", path));
8262 r->directory_name = path;
8267 /****************************************************************
8268 _spoolss_GetPrinterDriverDirectory
8269 ****************************************************************/
8271 WERROR _spoolss_GetPrinterDriverDirectory(pipes_struct *p,
8272 struct spoolss_GetPrinterDriverDirectory *r)
8276 /* that's an [in out] buffer */
8278 if (!r->in.buffer && (r->in.offered != 0)) {
8279 return WERR_INVALID_PARAM;
8282 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
8287 /* r->in.level is ignored */
8289 werror = getprinterdriverdir_level_1(p->mem_ctx,
8292 &r->out.info->info1);
8293 if (!W_ERROR_IS_OK(werror)) {
8294 TALLOC_FREE(r->out.info);
8298 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo, NULL,
8299 r->out.info, r->in.level);
8300 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8302 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8305 /****************************************************************************
8306 ****************************************************************************/
8308 WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, SPOOL_R_ENUMPRINTERDATA *r_u)
8310 POLICY_HND *handle = &q_u->handle;
8311 uint32 idx = q_u->index;
8312 uint32 in_value_len = q_u->valuesize;
8313 uint32 in_data_len = q_u->datasize;
8314 uint32 *out_max_value_len = &r_u->valuesize;
8315 uint16 **out_value = &r_u->value;
8316 uint32 *out_value_len = &r_u->realvaluesize;
8317 uint32 *out_type = &r_u->type;
8318 uint32 *out_max_data_len = &r_u->datasize;
8319 uint8 **data_out = &r_u->data;
8320 uint32 *out_data_len = &r_u->realdatasize;
8322 NT_PRINTER_INFO_LEVEL *printer = NULL;
8324 uint32 biggest_valuesize;
8325 uint32 biggest_datasize;
8327 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
8330 REGISTRY_VALUE *val = NULL;
8331 NT_PRINTER_DATA *p_data;
8332 int i, key_index, num_values;
8337 *out_max_data_len = 0;
8341 DEBUG(5,("spoolss_enumprinterdata\n"));
8344 DEBUG(2,("_spoolss_enumprinterdata: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
8348 if (!get_printer_snum(p,handle, &snum, NULL))
8351 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8352 if (!W_ERROR_IS_OK(result))
8355 p_data = printer->info_2->data;
8356 key_index = lookup_printerkey( p_data, SPOOL_PRINTERDATA_KEY );
8361 * The NT machine wants to know the biggest size of value and data
8363 * cf: MSDN EnumPrinterData remark section
8366 if ( !in_value_len && !in_data_len && (key_index != -1) )
8368 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
8370 biggest_valuesize = 0;
8371 biggest_datasize = 0;
8373 num_values = regval_ctr_numvals( p_data->keys[key_index].values );
8375 for ( i=0; i<num_values; i++ )
8377 val = regval_ctr_specific_value( p_data->keys[key_index].values, i );
8379 name_length = strlen(val->valuename);
8380 if ( strlen(val->valuename) > biggest_valuesize )
8381 biggest_valuesize = name_length;
8383 if ( val->size > biggest_datasize )
8384 biggest_datasize = val->size;
8386 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
8390 /* the value is an UNICODE string but real_value_size is the length
8391 in bytes including the trailing 0 */
8393 *out_value_len = 2 * (1+biggest_valuesize);
8394 *out_data_len = biggest_datasize;
8396 DEBUG(6,("final values: [%d], [%d]\n", *out_value_len, *out_data_len));
8402 * the value len is wrong in NT sp3
8403 * that's the number of bytes not the number of unicode chars
8406 if ( key_index != -1 )
8407 val = regval_ctr_specific_value( p_data->keys[key_index].values, idx );
8412 /* out_value should default to "" or else NT4 has
8413 problems unmarshalling the response */
8415 *out_max_value_len=(in_value_len/sizeof(uint16));
8418 if((*out_value=(uint16 *)TALLOC_ZERO(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL)
8420 result = WERR_NOMEM;
8423 *out_value_len = (uint32)rpcstr_push((char *)*out_value, "", in_value_len, 0);
8429 /* the data is counted in bytes */
8431 *out_max_data_len = in_data_len;
8432 *out_data_len = in_data_len;
8434 /* only allocate when given a non-zero data_len */
8436 if ( in_data_len && ((*data_out=(uint8 *)TALLOC_ZERO(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) )
8438 result = WERR_NOMEM;
8442 result = WERR_NO_MORE_ITEMS;
8448 * - counted in bytes in the request
8449 * - counted in UNICODE chars in the max reply
8450 * - counted in bytes in the real size
8452 * take a pause *before* coding not *during* coding
8456 *out_max_value_len=(in_value_len/sizeof(uint16));
8458 if ( (*out_value = (uint16 *)TALLOC_ZERO(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL )
8460 result = WERR_NOMEM;
8464 *out_value_len = (uint32)rpcstr_push((char *)*out_value, regval_name(val), (size_t)in_value_len, 0);
8472 *out_type = regval_type( val );
8474 /* data - counted in bytes */
8476 *out_max_data_len = in_data_len;
8477 if ( in_data_len && (*data_out = (uint8 *)TALLOC_ZERO(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL)
8479 result = WERR_NOMEM;
8482 data_len = regval_size(val);
8483 if ( *data_out && data_len )
8484 memcpy( *data_out, regval_data_p(val), data_len );
8485 *out_data_len = data_len;
8489 free_a_printer(&printer, 2);
8493 /****************************************************************************
8494 ****************************************************************************/
8496 WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SPOOL_R_SETPRINTERDATA *r_u)
8498 POLICY_HND *handle = &q_u->handle;
8499 UNISTR2 *value = &q_u->value;
8500 uint32 type = q_u->type;
8501 uint8 *data = q_u->data;
8502 uint32 real_len = q_u->real_len;
8504 NT_PRINTER_INFO_LEVEL *printer = NULL;
8506 WERROR status = WERR_OK;
8507 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
8510 DEBUG(5,("spoolss_setprinterdata\n"));
8513 DEBUG(2,("_spoolss_setprinterdata: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
8517 if ( Printer->printer_type == SPLHND_SERVER ) {
8518 DEBUG(10,("_spoolss_setprinterdata: Not implemented for server handles yet\n"));
8519 return WERR_INVALID_PARAM;
8522 if (!get_printer_snum(p,handle, &snum, NULL))
8526 * Access check : NT returns "access denied" if you make a
8527 * SetPrinterData call without the necessary privildge.
8528 * we were originally returning OK if nothing changed
8529 * which made Win2k issue **a lot** of SetPrinterData
8530 * when connecting to a printer --jerry
8533 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER)
8535 DEBUG(3, ("_spoolss_setprinterdata: change denied by handle access permissions\n"));
8536 status = WERR_ACCESS_DENIED;
8540 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8541 if (!W_ERROR_IS_OK(status))
8544 unistr2_to_ascii(valuename, value, sizeof(valuename));
8547 * When client side code sets a magic printer data key, detect it and save
8548 * the current printer data and the magic key's data (its the DEVMODE) for
8549 * future printer/driver initializations.
8551 if ( (type == REG_BINARY) && strequal( valuename, PHANTOM_DEVMODE_KEY))
8553 /* Set devmode and printer initialization info */
8554 status = save_driver_init( printer, 2, data, real_len );
8556 srv_spoolss_reset_printerdata( printer->info_2->drivername );
8560 status = set_printer_dataex( printer, SPOOL_PRINTERDATA_KEY, valuename,
8561 type, data, real_len );
8562 if ( W_ERROR_IS_OK(status) )
8563 status = mod_a_printer(printer, 2);
8567 free_a_printer(&printer, 2);
8572 /****************************************************************
8573 _spoolss_ResetPrinter
8574 ****************************************************************/
8576 WERROR _spoolss_ResetPrinter(pipes_struct *p,
8577 struct spoolss_ResetPrinter *r)
8579 POLICY_HND *handle = r->in.handle;
8580 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
8583 DEBUG(5,("_spoolss_ResetPrinter\n"));
8586 * All we do is to check to see if the handle and queue is valid.
8587 * This call really doesn't mean anything to us because we only
8588 * support RAW printing. --jerry
8592 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8593 OUR_HANDLE(handle)));
8597 if (!get_printer_snum(p,handle, &snum, NULL))
8601 /* blindly return success */
8605 /****************************************************************
8606 _spoolss_DeletePrinterData
8607 ****************************************************************/
8609 WERROR _spoolss_DeletePrinterData(pipes_struct *p,
8610 struct spoolss_DeletePrinterData *r)
8612 POLICY_HND *handle = r->in.handle;
8613 NT_PRINTER_INFO_LEVEL *printer = NULL;
8615 WERROR status = WERR_OK;
8616 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
8618 DEBUG(5,("_spoolss_DeletePrinterData\n"));
8621 DEBUG(2,("_spoolss_DeletePrinterData: Invalid handle (%s:%u:%u).\n",
8622 OUR_HANDLE(handle)));
8626 if (!get_printer_snum(p, handle, &snum, NULL))
8629 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8630 DEBUG(3, ("_spoolss_DeletePrinterData: "
8631 "printer properties change denied by handle\n"));
8632 return WERR_ACCESS_DENIED;
8635 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8636 if (!W_ERROR_IS_OK(status))
8639 if (!r->in.value_name) {
8640 free_a_printer(&printer, 2);
8644 status = delete_printer_dataex( printer, SPOOL_PRINTERDATA_KEY,
8647 if ( W_ERROR_IS_OK(status) )
8648 mod_a_printer( printer, 2 );
8650 free_a_printer(&printer, 2);
8655 /****************************************************************
8657 ****************************************************************/
8659 WERROR _spoolss_AddForm(pipes_struct *p,
8660 struct spoolss_AddForm *r)
8662 POLICY_HND *handle = r->in.handle;
8663 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8664 nt_forms_struct tmpForm;
8666 WERROR status = WERR_OK;
8667 NT_PRINTER_INFO_LEVEL *printer = NULL;
8670 nt_forms_struct *list=NULL;
8671 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
8673 DEBUG(5,("_spoolss_AddForm\n"));
8676 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8677 OUR_HANDLE(handle)));
8682 /* forms can be added on printer of on the print server handle */
8684 if ( Printer->printer_type == SPLHND_PRINTER )
8686 if (!get_printer_snum(p,handle, &snum, NULL))
8689 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8690 if (!W_ERROR_IS_OK(status))
8694 if ( !(Printer->access_granted & (PRINTER_ACCESS_ADMINISTER|SERVER_ACCESS_ADMINISTER)) ) {
8695 DEBUG(2,("_spoolss_addform: denied by handle permissions.\n"));
8696 status = WERR_ACCESS_DENIED;
8700 /* can't add if builtin */
8702 if (get_a_builtin_ntform_by_string(form->form_name, &tmpForm)) {
8703 status = WERR_FILE_EXISTS;
8707 count = get_ntforms(&list);
8709 if(!add_a_form(&list, form, &count)) {
8710 status = WERR_NOMEM;
8714 write_ntforms(&list, count);
8717 * ChangeID must always be set if this is a printer
8720 if ( Printer->printer_type == SPLHND_PRINTER )
8721 status = mod_a_printer(printer, 2);
8725 free_a_printer(&printer, 2);
8731 /****************************************************************
8733 ****************************************************************/
8735 WERROR _spoolss_DeleteForm(pipes_struct *p,
8736 struct spoolss_DeleteForm *r)
8738 POLICY_HND *handle = r->in.handle;
8739 const char *form_name = r->in.form_name;
8740 nt_forms_struct tmpForm;
8742 nt_forms_struct *list=NULL;
8743 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
8745 WERROR status = WERR_OK;
8746 NT_PRINTER_INFO_LEVEL *printer = NULL;
8748 DEBUG(5,("_spoolss_DeleteForm\n"));
8751 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8752 OUR_HANDLE(handle)));
8756 /* forms can be deleted on printer of on the print server handle */
8758 if ( Printer->printer_type == SPLHND_PRINTER )
8760 if (!get_printer_snum(p,handle, &snum, NULL))
8763 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8764 if (!W_ERROR_IS_OK(status))
8768 if ( !(Printer->access_granted & (PRINTER_ACCESS_ADMINISTER|SERVER_ACCESS_ADMINISTER)) ) {
8769 DEBUG(2,("_spoolss_DeleteForm: denied by handle permissions.\n"));
8770 status = WERR_ACCESS_DENIED;
8774 /* can't delete if builtin */
8776 if (get_a_builtin_ntform_by_string(form_name,&tmpForm)) {
8777 status = WERR_INVALID_PARAM;
8781 count = get_ntforms(&list);
8783 if ( !delete_a_form(&list, form_name, &count, &status ))
8787 * ChangeID must always be set if this is a printer
8790 if ( Printer->printer_type == SPLHND_PRINTER )
8791 status = mod_a_printer(printer, 2);
8795 free_a_printer(&printer, 2);
8801 /****************************************************************
8803 ****************************************************************/
8805 WERROR _spoolss_SetForm(pipes_struct *p,
8806 struct spoolss_SetForm *r)
8808 POLICY_HND *handle = r->in.handle;
8809 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8810 nt_forms_struct tmpForm;
8812 WERROR status = WERR_OK;
8813 NT_PRINTER_INFO_LEVEL *printer = NULL;
8816 nt_forms_struct *list=NULL;
8817 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
8819 DEBUG(5,("_spoolss_SetForm\n"));
8822 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8823 OUR_HANDLE(handle)));
8827 /* forms can be modified on printer of on the print server handle */
8829 if ( Printer->printer_type == SPLHND_PRINTER )
8831 if (!get_printer_snum(p,handle, &snum, NULL))
8834 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8835 if (!W_ERROR_IS_OK(status))
8839 if ( !(Printer->access_granted & (PRINTER_ACCESS_ADMINISTER|SERVER_ACCESS_ADMINISTER)) ) {
8840 DEBUG(2,("_spoolss_SetForm: denied by handle permissions\n"));
8841 status = WERR_ACCESS_DENIED;
8845 /* can't set if builtin */
8846 if (get_a_builtin_ntform_by_string(form->form_name, &tmpForm)) {
8847 status = WERR_INVALID_PARAM;
8851 count = get_ntforms(&list);
8852 update_a_form(&list, form, count);
8853 write_ntforms(&list, count);
8856 * ChangeID must always be set if this is a printer
8859 if ( Printer->printer_type == SPLHND_PRINTER )
8860 status = mod_a_printer(printer, 2);
8865 free_a_printer(&printer, 2);
8871 /****************************************************************************
8872 fill_print_processor1
8873 ****************************************************************************/
8875 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8876 struct spoolss_PrintProcessorInfo1 *r,
8877 const char *print_processor_name)
8879 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8880 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8885 /****************************************************************************
8886 enumprintprocessors level 1.
8887 ****************************************************************************/
8889 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8890 union spoolss_PrintProcessorInfo **info_p,
8893 union spoolss_PrintProcessorInfo *info;
8896 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8897 W_ERROR_HAVE_NO_MEMORY(info);
8901 result = fill_print_processor1(info, &info[0].info1, "winprint");
8902 if (!W_ERROR_IS_OK(result)) {
8907 if (!W_ERROR_IS_OK(result)) {
8918 /****************************************************************
8919 _spoolss_EnumPrintProcessors
8920 ****************************************************************/
8922 WERROR _spoolss_EnumPrintProcessors(pipes_struct *p,
8923 struct spoolss_EnumPrintProcessors *r)
8927 /* that's an [in out] buffer */
8929 if (!r->in.buffer && (r->in.offered != 0)) {
8930 return WERR_INVALID_PARAM;
8933 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8936 * Enumerate the print processors ...
8938 * Just reply with "winprint", to keep NT happy
8939 * and I can use my nice printer checker.
8944 *r->out.info = NULL;
8946 switch (r->in.level) {
8948 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8952 return WERR_UNKNOWN_LEVEL;
8955 if (!W_ERROR_IS_OK(result)) {
8959 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8960 spoolss_EnumPrintProcessors, NULL,
8961 *r->out.info, r->in.level,
8963 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8964 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8966 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8969 /****************************************************************************
8970 fill_printprocdatatype1
8971 ****************************************************************************/
8973 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8974 struct spoolss_PrintProcDataTypesInfo1 *r,
8975 const char *name_array)
8977 r->name_array = talloc_strdup(mem_ctx, name_array);
8978 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8983 /****************************************************************************
8984 enumprintprocdatatypes level 1.
8985 ****************************************************************************/
8987 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8988 union spoolss_PrintProcDataTypesInfo **info_p,
8992 union spoolss_PrintProcDataTypesInfo *info;
8994 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8995 W_ERROR_HAVE_NO_MEMORY(info);
8999 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
9000 if (!W_ERROR_IS_OK(result)) {
9005 if (!W_ERROR_IS_OK(result)) {
9016 /****************************************************************
9017 _spoolss_EnumPrintProcDataTypes
9018 ****************************************************************/
9020 WERROR _spoolss_EnumPrintProcDataTypes(pipes_struct *p,
9021 struct spoolss_EnumPrintProcDataTypes *r)
9025 /* that's an [in out] buffer */
9027 if (!r->in.buffer && (r->in.offered != 0)) {
9028 return WERR_INVALID_PARAM;
9031 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
9035 *r->out.info = NULL;
9037 switch (r->in.level) {
9039 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
9043 return WERR_UNKNOWN_LEVEL;
9046 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
9047 spoolss_EnumPrintProcDataTypes, NULL,
9048 *r->out.info, r->in.level,
9050 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9051 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
9053 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9056 /****************************************************************************
9058 ****************************************************************************/
9060 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
9061 struct spoolss_MonitorInfo1 *r,
9062 const char *monitor_name)
9064 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
9065 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
9070 /****************************************************************************
9072 ****************************************************************************/
9074 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
9075 struct spoolss_MonitorInfo2 *r,
9076 const char *monitor_name,
9077 const char *environment,
9078 const char *dll_name)
9080 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
9081 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
9082 r->environment = talloc_strdup(mem_ctx, environment);
9083 W_ERROR_HAVE_NO_MEMORY(r->environment);
9084 r->dll_name = talloc_strdup(mem_ctx, dll_name);
9085 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
9090 /****************************************************************************
9091 enumprintmonitors level 1.
9092 ****************************************************************************/
9094 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
9095 union spoolss_MonitorInfo **info_p,
9098 union spoolss_MonitorInfo *info;
9099 WERROR result = WERR_OK;
9101 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
9102 W_ERROR_HAVE_NO_MEMORY(info);
9106 result = fill_monitor_1(info, &info[0].info1,
9107 SPL_LOCAL_PORT /* FIXME */);
9108 if (!W_ERROR_IS_OK(result)) {
9112 result = fill_monitor_1(info, &info[1].info1,
9113 SPL_TCPIP_PORT /* FIXME */);
9114 if (!W_ERROR_IS_OK(result)) {
9119 if (!W_ERROR_IS_OK(result)) {
9130 /****************************************************************************
9131 enumprintmonitors level 2.
9132 ****************************************************************************/
9134 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
9135 union spoolss_MonitorInfo **info_p,
9138 union spoolss_MonitorInfo *info;
9139 WERROR result = WERR_OK;
9141 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
9142 W_ERROR_HAVE_NO_MEMORY(info);
9146 result = fill_monitor_2(info, &info[0].info2,
9147 SPL_LOCAL_PORT, /* FIXME */
9148 "Windows NT X86", /* FIXME */
9150 if (!W_ERROR_IS_OK(result)) {
9154 result = fill_monitor_2(info, &info[1].info2,
9155 SPL_TCPIP_PORT, /* FIXME */
9156 "Windows NT X86", /* FIXME */
9158 if (!W_ERROR_IS_OK(result)) {
9163 if (!W_ERROR_IS_OK(result)) {
9174 /****************************************************************
9175 _spoolss_EnumMonitors
9176 ****************************************************************/
9178 WERROR _spoolss_EnumMonitors(pipes_struct *p,
9179 struct spoolss_EnumMonitors *r)
9183 /* that's an [in out] buffer */
9185 if (!r->in.buffer && (r->in.offered != 0)) {
9186 return WERR_INVALID_PARAM;
9189 DEBUG(5,("_spoolss_EnumMonitors\n"));
9192 * Enumerate the print monitors ...
9194 * Just reply with "Local Port", to keep NT happy
9195 * and I can use my nice printer checker.
9200 *r->out.info = NULL;
9202 switch (r->in.level) {
9204 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
9208 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
9212 return WERR_UNKNOWN_LEVEL;
9215 if (!W_ERROR_IS_OK(result)) {
9219 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
9220 spoolss_EnumMonitors, NULL,
9221 *r->out.info, r->in.level,
9223 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9224 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
9226 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9229 /****************************************************************************
9230 ****************************************************************************/
9232 static WERROR getjob_level_1(print_queue_struct **queue, int count, int snum,
9233 NT_PRINTER_INFO_LEVEL *ntprinter,
9234 uint32 jobid, RPC_BUFFER *buffer, uint32 offered,
9239 JOB_INFO_1 *info_1=NULL;
9240 WERROR result = WERR_OK;
9242 info_1=SMB_MALLOC_P(JOB_INFO_1);
9244 if (info_1 == NULL) {
9248 for (i=0; i<count && found==False; i++) {
9249 if ((*queue)[i].job==(int)jobid)
9255 /* NT treats not found as bad param... yet another bad choice */
9256 return WERR_INVALID_PARAM;
9259 fill_job_info_1( info_1, &((*queue)[i-1]), i, snum, ntprinter );
9261 *needed += spoolss_size_job_info_1(info_1);
9263 if (*needed > offered) {
9264 result = WERR_INSUFFICIENT_BUFFER;
9268 if (!rpcbuf_alloc_size(buffer, *needed)) {
9269 result = WERR_NOMEM;
9273 smb_io_job_info_1("", buffer, info_1, 0);
9281 /****************************************************************************
9282 ****************************************************************************/
9284 static WERROR getjob_level_2(print_queue_struct **queue, int count, int snum,
9285 NT_PRINTER_INFO_LEVEL *ntprinter,
9286 uint32 jobid, RPC_BUFFER *buffer, uint32 offered,
9293 DEVICEMODE *devmode = NULL;
9294 NT_DEVICEMODE *nt_devmode = NULL;
9296 if ( !(info_2=SMB_MALLOC_P(JOB_INFO_2)) )
9299 ZERO_STRUCTP(info_2);
9301 for ( i=0; i<count && found==False; i++ )
9303 if ((*queue)[i].job == (int)jobid)
9308 /* NT treats not found as bad param... yet another bad
9310 result = WERR_INVALID_PARAM;
9315 * if the print job does not have a DEVMODE associated with it,
9316 * just use the one for the printer. A NULL devicemode is not
9317 * a failure condition
9320 if ( !(nt_devmode=print_job_devmode( lp_const_servicename(snum), jobid )) )
9321 devmode = construct_dev_mode(lp_const_servicename(snum));
9323 if ((devmode = SMB_MALLOC_P(DEVICEMODE)) != NULL) {
9324 ZERO_STRUCTP( devmode );
9325 convert_nt_devicemode( devmode, nt_devmode );
9329 fill_job_info_2(info_2, &((*queue)[i-1]), i, snum, ntprinter, devmode);
9331 *needed += spoolss_size_job_info_2(info_2);
9333 if (*needed > offered) {
9334 result = WERR_INSUFFICIENT_BUFFER;
9338 if (!rpcbuf_alloc_size(buffer, *needed)) {
9339 result = WERR_NOMEM;
9343 smb_io_job_info_2("", buffer, info_2, 0);
9348 /* Cleanup allocated memory */
9350 free_job_info_2(info_2); /* Also frees devmode */
9356 /****************************************************************************
9357 ****************************************************************************/
9359 WERROR _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_u)
9361 POLICY_HND *handle = &q_u->handle;
9362 uint32 jobid = q_u->jobid;
9363 uint32 level = q_u->level;
9364 RPC_BUFFER *buffer = NULL;
9365 uint32 offered = q_u->offered;
9366 uint32 *needed = &r_u->needed;
9367 WERROR wstatus = WERR_OK;
9368 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
9371 print_queue_struct *queue = NULL;
9372 print_status_struct prt_status;
9374 /* that's an [in out] buffer */
9376 if (!q_u->buffer && (offered!=0)) {
9377 return WERR_INVALID_PARAM;
9380 if (offered > MAX_RPC_DATA_SIZE) {
9381 return WERR_INVALID_PARAM;
9384 rpcbuf_move(q_u->buffer, &r_u->buffer);
9385 buffer = r_u->buffer;
9387 DEBUG(5,("spoolss_getjob\n"));
9391 if (!get_printer_snum(p, handle, &snum, NULL))
9394 wstatus = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum));
9395 if ( !W_ERROR_IS_OK(wstatus) )
9398 count = print_queue_status(snum, &queue, &prt_status);
9400 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
9401 count, prt_status.status, prt_status.message));
9405 wstatus = getjob_level_1(&queue, count, snum, ntprinter, jobid,
9406 buffer, offered, needed);
9409 wstatus = getjob_level_2(&queue, count, snum, ntprinter, jobid,
9410 buffer, offered, needed);
9413 wstatus = WERR_UNKNOWN_LEVEL;
9418 free_a_printer( &ntprinter, 2 );
9423 /****************************************************************
9424 _spoolss_GetPrinterDataEx
9426 From MSDN documentation of GetPrinterDataEx: pass request
9427 to GetPrinterData if key is "PrinterDriverData".
9428 ****************************************************************/
9430 WERROR _spoolss_GetPrinterDataEx(pipes_struct *p,
9431 struct spoolss_GetPrinterDataEx *r)
9433 POLICY_HND *handle = r->in.handle;
9435 const char *keyname = r->in.key_name;
9436 const char *valuename = r->in.value_name;
9438 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
9440 NT_PRINTER_INFO_LEVEL *printer = NULL;
9442 WERROR status = WERR_OK;
9444 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
9446 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
9447 keyname, valuename));
9449 /* in case of problem, return some default values */
9455 DEBUG(2,("_spoolss_GetPrinterDataEx: "
9456 "Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
9457 status = WERR_BADFID;
9461 /* Is the handle to a printer or to the server? */
9463 if (Printer->printer_type == SPLHND_SERVER) {
9464 DEBUG(10,("_spoolss_GetPrinterDataEx: "
9465 "Not implemented for server handles yet\n"));
9466 status = WERR_INVALID_PARAM;
9470 if ( !get_printer_snum(p,handle, &snum, NULL) )
9473 status = get_a_printer(Printer, &printer, 2, lp_servicename(snum));
9474 if ( !W_ERROR_IS_OK(status) )
9477 /* check to see if the keyname is valid */
9478 if ( !strlen(keyname) ) {
9479 status = WERR_INVALID_PARAM;
9483 if ( lookup_printerkey( printer->info_2->data, keyname ) == -1 ) {
9484 DEBUG(4,("_spoolss_GetPrinterDataEx: "
9485 "Invalid keyname [%s]\n", keyname ));
9486 free_a_printer( &printer, 2 );
9487 status = WERR_BADFILE;
9491 /* When given a new keyname, we should just create it */
9493 status = get_printer_dataex( p->mem_ctx, printer, keyname, valuename,
9494 r->out.type, &data, r->out.needed,
9497 if (*r->out.needed > r->in.offered) {
9498 status = WERR_MORE_DATA;
9501 if (W_ERROR_IS_OK(status)) {
9502 memcpy(r->out.buffer, data, r->in.offered);
9507 free_a_printer( &printer, 2 );
9512 /****************************************************************
9513 _spoolss_SetPrinterDataEx
9514 ****************************************************************/
9516 WERROR _spoolss_SetPrinterDataEx(pipes_struct *p,
9517 struct spoolss_SetPrinterDataEx *r)
9519 POLICY_HND *handle = r->in.handle;
9520 NT_PRINTER_INFO_LEVEL *printer = NULL;
9522 WERROR status = WERR_OK;
9523 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
9526 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
9528 /* From MSDN documentation of SetPrinterDataEx: pass request to
9529 SetPrinterData if key is "PrinterDriverData" */
9532 DEBUG(2,("_spoolss_SetPrinterDataEx: "
9533 "Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
9537 if ( Printer->printer_type == SPLHND_SERVER ) {
9538 DEBUG(10,("_spoolss_SetPrinterDataEx: "
9539 "Not implemented for server handles yet\n"));
9540 return WERR_INVALID_PARAM;
9543 if ( !get_printer_snum(p,handle, &snum, NULL) )
9547 * Access check : NT returns "access denied" if you make a
9548 * SetPrinterData call without the necessary privildge.
9549 * we were originally returning OK if nothing changed
9550 * which made Win2k issue **a lot** of SetPrinterData
9551 * when connecting to a printer --jerry
9554 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER)
9556 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
9557 "change denied by handle access permissions\n"));
9558 return WERR_ACCESS_DENIED;
9561 status = get_a_printer(Printer, &printer, 2, lp_servicename(snum));
9562 if (!W_ERROR_IS_OK(status))
9565 /* check for OID in valuename */
9567 if ( (oid_string = strchr( r->in.value_name, ',' )) != NULL )
9573 /* save the registry data */
9575 status = set_printer_dataex( printer, r->in.key_name, r->in.value_name,
9576 r->in.type, r->in.buffer, r->in.offered );
9578 if ( W_ERROR_IS_OK(status) )
9580 /* save the OID if one was specified */
9582 char *str = talloc_asprintf(p->mem_ctx, "%s\\%s",
9583 r->in.key_name, SPOOL_OID_KEY);
9589 * I'm not checking the status here on purpose. Don't know
9590 * if this is right, but I'm returning the status from the
9591 * previous set_printer_dataex() call. I have no idea if
9592 * this is right. --jerry
9595 set_printer_dataex( printer, str, r->in.value_name,
9596 REG_SZ, (uint8 *)oid_string,
9597 strlen(oid_string)+1 );
9600 status = mod_a_printer(printer, 2);
9603 free_a_printer(&printer, 2);
9608 /****************************************************************
9609 _spoolss_DeletePrinterDataEx
9610 ****************************************************************/
9612 WERROR _spoolss_DeletePrinterDataEx(pipes_struct *p,
9613 struct spoolss_DeletePrinterDataEx *r)
9615 POLICY_HND *handle = r->in.handle;
9616 NT_PRINTER_INFO_LEVEL *printer = NULL;
9618 WERROR status = WERR_OK;
9619 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
9621 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9624 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9625 "Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
9629 if (!get_printer_snum(p, handle, &snum, NULL))
9632 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9633 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9634 "printer properties change denied by handle\n"));
9635 return WERR_ACCESS_DENIED;
9638 if (!r->in.value_name || !r->in.key_name) {
9642 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9643 if (!W_ERROR_IS_OK(status))
9646 status = delete_printer_dataex( printer, r->in.key_name, r->in.value_name );
9648 if ( W_ERROR_IS_OK(status) )
9649 mod_a_printer( printer, 2 );
9651 free_a_printer(&printer, 2);
9656 /********************************************************************
9657 * spoolss_enumprinterkey
9658 ********************************************************************/
9661 WERROR _spoolss_enumprinterkey(pipes_struct *p, SPOOL_Q_ENUMPRINTERKEY *q_u, SPOOL_R_ENUMPRINTERKEY *r_u)
9664 fstring *keynames = NULL;
9665 uint16 *enumkeys = NULL;
9668 POLICY_HND *handle = &q_u->handle;
9669 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
9670 NT_PRINTER_DATA *data;
9671 NT_PRINTER_INFO_LEVEL *printer = NULL;
9673 WERROR status = WERR_BADFILE;
9676 DEBUG(4,("_spoolss_enumprinterkey\n"));
9679 DEBUG(2,("_spoolss_enumprinterkey: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
9683 if ( !get_printer_snum(p,handle, &snum, NULL) )
9686 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9687 if (!W_ERROR_IS_OK(status))
9690 /* get the list of subkey names */
9692 unistr2_to_ascii(key, &q_u->key, sizeof(key));
9693 data = printer->info_2->data;
9695 num_keys = get_printer_subkeys( data, key, &keynames );
9697 if ( num_keys == -1 ) {
9698 status = WERR_BADFILE;
9702 printerkey_len = init_unistr_array( &enumkeys, keynames, NULL );
9704 r_u->needed = printerkey_len*2;
9706 if ( q_u->size < r_u->needed ) {
9707 status = WERR_MORE_DATA;
9711 if (!make_spoolss_buffer5(p->mem_ctx, &r_u->keys, printerkey_len, enumkeys)) {
9712 status = WERR_NOMEM;
9718 if ( q_u->size < r_u->needed )
9719 status = WERR_MORE_DATA;
9722 free_a_printer( &printer, 2 );
9723 SAFE_FREE( keynames );
9728 /****************************************************************
9729 _spoolss_DeletePrinterKey
9730 ****************************************************************/
9732 WERROR _spoolss_DeletePrinterKey(pipes_struct *p,
9733 struct spoolss_DeletePrinterKey *r)
9735 POLICY_HND *handle = r->in.handle;
9736 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
9737 NT_PRINTER_INFO_LEVEL *printer = NULL;
9741 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9744 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9745 OUR_HANDLE(handle)));
9749 /* if keyname == NULL, return error */
9751 if ( !r->in.key_name )
9752 return WERR_INVALID_PARAM;
9754 if (!get_printer_snum(p, handle, &snum, NULL))
9757 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9758 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9759 "printer properties change denied by handle\n"));
9760 return WERR_ACCESS_DENIED;
9763 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9764 if (!W_ERROR_IS_OK(status))
9767 /* delete the key and all subneys */
9769 status = delete_all_printer_data( printer->info_2, r->in.key_name );
9771 if ( W_ERROR_IS_OK(status) )
9772 status = mod_a_printer(printer, 2);
9774 free_a_printer( &printer, 2 );
9780 /********************************************************************
9781 * spoolss_enumprinterdataex
9782 ********************************************************************/
9784 WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_u, SPOOL_R_ENUMPRINTERDATAEX *r_u)
9786 POLICY_HND *handle = &q_u->handle;
9787 uint32 in_size = q_u->size;
9790 NT_PRINTER_INFO_LEVEL *printer = NULL;
9791 PRINTER_ENUM_VALUES *enum_values = NULL;
9792 NT_PRINTER_DATA *p_data;
9794 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
9799 REGISTRY_VALUE *val;
9804 DEBUG(4,("_spoolss_enumprinterdataex\n"));
9807 DEBUG(2,("_spoolss_enumprinterdataex: Invalid handle (%s:%u:%u1<).\n", OUR_HANDLE(handle)));
9812 * first check for a keyname of NULL or "". Win2k seems to send
9813 * this a lot and we should send back WERR_INVALID_PARAM
9814 * no need to spend time looking up the printer in this case.
9818 unistr2_to_ascii(key, &q_u->key, sizeof(key));
9819 if ( !strlen(key) ) {
9820 result = WERR_INVALID_PARAM;
9824 /* get the printer off of disk */
9826 if (!get_printer_snum(p,handle, &snum, NULL))
9829 ZERO_STRUCT(printer);
9830 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9831 if (!W_ERROR_IS_OK(result))
9834 /* now look for a match on the key name */
9836 p_data = printer->info_2->data;
9838 unistr2_to_ascii(key, &q_u->key, sizeof(key));
9839 if ( (key_index = lookup_printerkey( p_data, key)) == -1 )
9841 DEBUG(10,("_spoolss_enumprinterdataex: Unknown keyname [%s]\n", key));
9842 result = WERR_INVALID_PARAM;
9849 /* allocate the memory for the array of pointers -- if necessary */
9851 num_entries = regval_ctr_numvals( p_data->keys[key_index].values );
9854 if ( (enum_values=TALLOC_ARRAY(p->mem_ctx, PRINTER_ENUM_VALUES, num_entries)) == NULL )
9856 DEBUG(0,("_spoolss_enumprinterdataex: talloc() failed to allocate memory for [%lu] bytes!\n",
9857 (unsigned long)num_entries*sizeof(PRINTER_ENUM_VALUES)));
9858 result = WERR_NOMEM;
9862 memset( enum_values, 0x0, num_entries*sizeof(PRINTER_ENUM_VALUES) );
9866 * loop through all params and build the array to pass
9867 * back to the client
9870 for ( i=0; i<num_entries; i++ )
9872 /* lookup the registry value */
9874 val = regval_ctr_specific_value( p_data->keys[key_index].values, i );
9875 DEBUG(10,("retrieved value number [%d] [%s]\n", i, regval_name(val) ));
9879 value_name = regval_name( val );
9880 init_unistr( &enum_values[i].valuename, value_name );
9881 enum_values[i].value_len = (strlen(value_name)+1) * 2;
9882 enum_values[i].type = regval_type( val );
9884 data_len = regval_size( val );
9886 if ( !(enum_values[i].data = (uint8 *)TALLOC_MEMDUP(p->mem_ctx, regval_data_p(val), data_len)) )
9888 DEBUG(0,("TALLOC_MEMDUP failed to allocate memory [data_len=%d] for data!\n",
9890 result = WERR_NOMEM;
9894 enum_values[i].data_len = data_len;
9896 /* keep track of the size of the array in bytes */
9898 needed += spoolss_size_printer_enum_values(&enum_values[i]);
9901 /* housekeeping information in the reply */
9903 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9904 * the hand marshalled container size is a multiple
9905 * of 4 bytes for RPC alignment.
9909 needed += 4-(needed % 4);
9912 r_u->needed = needed;
9913 r_u->returned = num_entries;
9915 if (needed > in_size) {
9916 result = WERR_MORE_DATA;
9920 /* copy data into the reply */
9922 /* mz: Vista x64 returns 0x6f7 (The stub received bad data), if the
9923 response buffer size is != the offered buffer size
9925 r_u->ctr.size = r_u->needed;
9927 r_u->ctr.size = in_size;
9929 r_u->ctr.size_of_array = r_u->returned;
9930 r_u->ctr.values = enum_values;
9934 free_a_printer(&printer, 2);
9939 /****************************************************************************
9940 ****************************************************************************/
9942 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
9943 const char *servername,
9944 const char *environment,
9945 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9950 werr = compose_spoolss_server_path(mem_ctx,
9953 SPOOLSS_PRTPROCS_PATH,
9955 if (!W_ERROR_IS_OK(werr)) {
9959 DEBUG(4,("print processor directory: [%s]\n", path));
9961 r->directory_name = path;
9966 /****************************************************************
9967 _spoolss_GetPrintProcessorDirectory
9968 ****************************************************************/
9970 WERROR _spoolss_GetPrintProcessorDirectory(pipes_struct *p,
9971 struct spoolss_GetPrintProcessorDirectory *r)
9975 /* that's an [in out] buffer */
9977 if (!r->in.buffer && (r->in.offered != 0)) {
9978 return WERR_INVALID_PARAM;
9981 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9986 /* r->in.level is ignored */
9988 result = getprintprocessordirectory_level_1(p->mem_ctx,
9991 &r->out.info->info1);
9992 if (!W_ERROR_IS_OK(result)) {
9993 TALLOC_FREE(r->out.info);
9997 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo, NULL,
9998 r->out.info, r->in.level);
9999 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
10001 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
10004 /*******************************************************************
10005 ********************************************************************/
10007 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
10008 const char *dllname)
10010 enum ndr_err_code ndr_err;
10011 struct spoolss_MonitorUi ui;
10013 ui.dll_name = dllname;
10015 ndr_err = ndr_push_struct_blob(buf, mem_ctx, NULL, &ui,
10016 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
10017 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
10018 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
10020 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
10023 /*******************************************************************
10024 Streams the monitor UI DLL name in UNICODE
10025 *******************************************************************/
10027 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
10028 NT_USER_TOKEN *token, DATA_BLOB *in,
10029 DATA_BLOB *out, uint32_t *needed)
10031 const char *dllname = "tcpmonui.dll";
10033 *needed = (strlen(dllname)+1) * 2;
10035 if (out->length < *needed) {
10036 return WERR_INSUFFICIENT_BUFFER;
10039 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
10046 /*******************************************************************
10047 ********************************************************************/
10049 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
10050 struct spoolss_PortData1 *port1,
10051 const DATA_BLOB *buf)
10053 enum ndr_err_code ndr_err;
10054 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, NULL, port1,
10055 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
10056 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
10057 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
10059 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
10062 /*******************************************************************
10063 ********************************************************************/
10065 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
10066 struct spoolss_PortData2 *port2,
10067 const DATA_BLOB *buf)
10069 enum ndr_err_code ndr_err;
10070 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, NULL, port2,
10071 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
10072 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
10073 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
10075 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
10078 /*******************************************************************
10079 Create a new TCP/IP port
10080 *******************************************************************/
10082 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
10083 NT_USER_TOKEN *token, DATA_BLOB *in,
10084 DATA_BLOB *out, uint32_t *needed)
10086 struct spoolss_PortData1 port1;
10087 struct spoolss_PortData2 port2;
10088 char *device_uri = NULL;
10091 const char *portname;
10092 const char *hostaddress;
10094 uint32_t port_number;
10097 /* peek for spoolss_PortData version */
10099 if (!in || (in->length < (128 + 4))) {
10100 return WERR_GENERAL_FAILURE;
10103 version = IVAL(in->data, 128);
10107 ZERO_STRUCT(port1);
10109 if (!pull_port_data_1(mem_ctx, &port1, in)) {
10113 portname = port1.portname;
10114 hostaddress = port1.hostaddress;
10115 queue = port1.queue;
10116 protocol = port1.protocol;
10117 port_number = port1.port_number;
10121 ZERO_STRUCT(port2);
10123 if (!pull_port_data_2(mem_ctx, &port2, in)) {
10127 portname = port2.portname;
10128 hostaddress = port2.hostaddress;
10129 queue = port2.queue;
10130 protocol = port2.protocol;
10131 port_number = port2.port_number;
10135 DEBUG(1,("xcvtcp_addport: "
10136 "unknown version of port_data: %d\n", version));
10137 return WERR_UNKNOWN_PORT;
10140 /* create the device URI and call the add_port_hook() */
10142 switch (protocol) {
10143 case PROTOCOL_RAWTCP_TYPE:
10144 device_uri = talloc_asprintf(mem_ctx,
10145 "socket://%s:%d/", hostaddress,
10149 case PROTOCOL_LPR_TYPE:
10150 device_uri = talloc_asprintf(mem_ctx,
10151 "lpr://%s/%s", hostaddress, queue );
10155 return WERR_UNKNOWN_PORT;
10162 return add_port_hook(mem_ctx, token, portname, device_uri);
10165 /*******************************************************************
10166 *******************************************************************/
10168 struct xcv_api_table xcvtcp_cmds[] = {
10169 { "MonitorUI", xcvtcp_monitorui },
10170 { "AddPort", xcvtcp_addport},
10174 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
10175 NT_USER_TOKEN *token, const char *command,
10182 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
10184 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
10185 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
10186 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
10189 return WERR_BADFUNC;
10192 /*******************************************************************
10193 *******************************************************************/
10194 #if 0 /* don't support management using the "Local Port" monitor */
10196 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
10197 NT_USER_TOKEN *token, DATA_BLOB *in,
10198 DATA_BLOB *out, uint32_t *needed)
10200 const char *dllname = "localui.dll";
10202 *needed = (strlen(dllname)+1) * 2;
10204 if (out->length < *needed) {
10205 return WERR_INSUFFICIENT_BUFFER;
10208 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
10215 /*******************************************************************
10216 *******************************************************************/
10218 struct xcv_api_table xcvlocal_cmds[] = {
10219 { "MonitorUI", xcvlocal_monitorui },
10223 struct xcv_api_table xcvlocal_cmds[] = {
10230 /*******************************************************************
10231 *******************************************************************/
10233 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
10234 NT_USER_TOKEN *token, const char *command,
10235 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
10240 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
10242 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
10243 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
10244 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
10246 return WERR_BADFUNC;
10249 /****************************************************************
10251 ****************************************************************/
10253 WERROR _spoolss_XcvData(pipes_struct *p,
10254 struct spoolss_XcvData *r)
10256 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
10257 DATA_BLOB out_data = data_blob_null;
10261 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
10262 OUR_HANDLE(r->in.handle)));
10263 return WERR_BADFID;
10266 /* Has to be a handle to the TCP/IP port monitor */
10268 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
10269 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
10270 return WERR_BADFID;
10273 /* requires administrative access to the server */
10275 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
10276 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
10277 return WERR_ACCESS_DENIED;
10280 /* Allocate the outgoing buffer */
10282 if (r->in.out_data_size) {
10283 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
10284 if (out_data.data == NULL) {
10289 switch ( Printer->printer_type ) {
10290 case SPLHND_PORTMON_TCP:
10291 werror = process_xcvtcp_command(p->mem_ctx,
10292 p->server_info->ptok,
10293 r->in.function_name,
10294 &r->in.in_data, &out_data,
10297 case SPLHND_PORTMON_LOCAL:
10298 werror = process_xcvlocal_command(p->mem_ctx,
10299 p->server_info->ptok,
10300 r->in.function_name,
10301 &r->in.in_data, &out_data,
10305 werror = WERR_INVALID_PRINT_MONITOR;
10308 if (!W_ERROR_IS_OK(werror)) {
10312 *r->out.status_code = 0;
10314 memcpy(r->out.out_data, out_data.data, out_data.length);
10319 /****************************************************************
10320 _spoolss_AddPrintProcessor
10321 ****************************************************************/
10323 WERROR _spoolss_AddPrintProcessor(pipes_struct *p,
10324 struct spoolss_AddPrintProcessor *r)
10326 /* for now, just indicate success and ignore the add. We'll
10327 automatically set the winprint processor for printer
10328 entries later. Used to debug the LexMark Optra S 1855 PCL
10334 /****************************************************************
10335 _spoolss_EnumPrinters
10336 ****************************************************************/
10338 WERROR _spoolss_EnumPrinters(pipes_struct *p,
10339 struct spoolss_EnumPrinters *r)
10341 p->rng_fault_state = true;
10342 return WERR_NOT_SUPPORTED;
10345 /****************************************************************
10347 ****************************************************************/
10349 WERROR _spoolss_GetJob(pipes_struct *p,
10350 struct spoolss_GetJob *r)
10352 p->rng_fault_state = true;
10353 return WERR_NOT_SUPPORTED;
10356 /****************************************************************
10358 ****************************************************************/
10360 WERROR _spoolss_EnumJobs(pipes_struct *p,
10361 struct spoolss_EnumJobs *r)
10363 p->rng_fault_state = true;
10364 return WERR_NOT_SUPPORTED;
10367 /****************************************************************
10368 _spoolss_AddPrinter
10369 ****************************************************************/
10371 WERROR _spoolss_AddPrinter(pipes_struct *p,
10372 struct spoolss_AddPrinter *r)
10374 p->rng_fault_state = true;
10375 return WERR_NOT_SUPPORTED;
10378 /****************************************************************
10379 _spoolss_GetPrinter
10380 ****************************************************************/
10382 WERROR _spoolss_GetPrinter(pipes_struct *p,
10383 struct spoolss_GetPrinter *r)
10385 p->rng_fault_state = true;
10386 return WERR_NOT_SUPPORTED;
10389 /****************************************************************
10390 _spoolss_EnumPrinterDrivers
10391 ****************************************************************/
10393 WERROR _spoolss_EnumPrinterDrivers(pipes_struct *p,
10394 struct spoolss_EnumPrinterDrivers *r)
10396 p->rng_fault_state = true;
10397 return WERR_NOT_SUPPORTED;
10400 /****************************************************************
10401 _spoolss_GetPrinterDriver
10402 ****************************************************************/
10404 WERROR _spoolss_GetPrinterDriver(pipes_struct *p,
10405 struct spoolss_GetPrinterDriver *r)
10407 p->rng_fault_state = true;
10408 return WERR_NOT_SUPPORTED;
10411 /****************************************************************
10412 _spoolss_ReadPrinter
10413 ****************************************************************/
10415 WERROR _spoolss_ReadPrinter(pipes_struct *p,
10416 struct spoolss_ReadPrinter *r)
10418 p->rng_fault_state = true;
10419 return WERR_NOT_SUPPORTED;
10422 /****************************************************************
10423 _spoolss_GetPrinterData
10424 ****************************************************************/
10426 WERROR _spoolss_GetPrinterData(pipes_struct *p,
10427 struct spoolss_GetPrinterData *r)
10429 p->rng_fault_state = true;
10430 return WERR_NOT_SUPPORTED;
10433 /****************************************************************
10434 _spoolss_SetPrinterData
10435 ****************************************************************/
10437 WERROR _spoolss_SetPrinterData(pipes_struct *p,
10438 struct spoolss_SetPrinterData *r)
10440 p->rng_fault_state = true;
10441 return WERR_NOT_SUPPORTED;
10444 /****************************************************************
10445 _spoolss_WaitForPrinterChange
10446 ****************************************************************/
10448 WERROR _spoolss_WaitForPrinterChange(pipes_struct *p,
10449 struct spoolss_WaitForPrinterChange *r)
10451 p->rng_fault_state = true;
10452 return WERR_NOT_SUPPORTED;
10455 /****************************************************************
10457 ****************************************************************/
10459 WERROR _spoolss_AddPort(pipes_struct *p,
10460 struct spoolss_AddPort *r)
10462 p->rng_fault_state = true;
10463 return WERR_NOT_SUPPORTED;
10466 /****************************************************************
10467 _spoolss_ConfigurePort
10468 ****************************************************************/
10470 WERROR _spoolss_ConfigurePort(pipes_struct *p,
10471 struct spoolss_ConfigurePort *r)
10473 p->rng_fault_state = true;
10474 return WERR_NOT_SUPPORTED;
10477 /****************************************************************
10478 _spoolss_DeletePort
10479 ****************************************************************/
10481 WERROR _spoolss_DeletePort(pipes_struct *p,
10482 struct spoolss_DeletePort *r)
10484 p->rng_fault_state = true;
10485 return WERR_NOT_SUPPORTED;
10488 /****************************************************************
10489 _spoolss_CreatePrinterIC
10490 ****************************************************************/
10492 WERROR _spoolss_CreatePrinterIC(pipes_struct *p,
10493 struct spoolss_CreatePrinterIC *r)
10495 p->rng_fault_state = true;
10496 return WERR_NOT_SUPPORTED;
10499 /****************************************************************
10500 _spoolss_PlayGDIScriptOnPrinterIC
10501 ****************************************************************/
10503 WERROR _spoolss_PlayGDIScriptOnPrinterIC(pipes_struct *p,
10504 struct spoolss_PlayGDIScriptOnPrinterIC *r)
10506 p->rng_fault_state = true;
10507 return WERR_NOT_SUPPORTED;
10510 /****************************************************************
10511 _spoolss_DeletePrinterIC
10512 ****************************************************************/
10514 WERROR _spoolss_DeletePrinterIC(pipes_struct *p,
10515 struct spoolss_DeletePrinterIC *r)
10517 p->rng_fault_state = true;
10518 return WERR_NOT_SUPPORTED;
10521 /****************************************************************
10522 _spoolss_AddPrinterConnection
10523 ****************************************************************/
10525 WERROR _spoolss_AddPrinterConnection(pipes_struct *p,
10526 struct spoolss_AddPrinterConnection *r)
10528 p->rng_fault_state = true;
10529 return WERR_NOT_SUPPORTED;
10532 /****************************************************************
10533 _spoolss_DeletePrinterConnection
10534 ****************************************************************/
10536 WERROR _spoolss_DeletePrinterConnection(pipes_struct *p,
10537 struct spoolss_DeletePrinterConnection *r)
10539 p->rng_fault_state = true;
10540 return WERR_NOT_SUPPORTED;
10543 /****************************************************************
10544 _spoolss_PrinterMessageBox
10545 ****************************************************************/
10547 WERROR _spoolss_PrinterMessageBox(pipes_struct *p,
10548 struct spoolss_PrinterMessageBox *r)
10550 p->rng_fault_state = true;
10551 return WERR_NOT_SUPPORTED;
10554 /****************************************************************
10555 _spoolss_AddMonitor
10556 ****************************************************************/
10558 WERROR _spoolss_AddMonitor(pipes_struct *p,
10559 struct spoolss_AddMonitor *r)
10561 p->rng_fault_state = true;
10562 return WERR_NOT_SUPPORTED;
10565 /****************************************************************
10566 _spoolss_DeleteMonitor
10567 ****************************************************************/
10569 WERROR _spoolss_DeleteMonitor(pipes_struct *p,
10570 struct spoolss_DeleteMonitor *r)
10572 p->rng_fault_state = true;
10573 return WERR_NOT_SUPPORTED;
10576 /****************************************************************
10577 _spoolss_DeletePrintProcessor
10578 ****************************************************************/
10580 WERROR _spoolss_DeletePrintProcessor(pipes_struct *p,
10581 struct spoolss_DeletePrintProcessor *r)
10583 p->rng_fault_state = true;
10584 return WERR_NOT_SUPPORTED;
10587 /****************************************************************
10588 _spoolss_AddPrintProvidor
10589 ****************************************************************/
10591 WERROR _spoolss_AddPrintProvidor(pipes_struct *p,
10592 struct spoolss_AddPrintProvidor *r)
10594 p->rng_fault_state = true;
10595 return WERR_NOT_SUPPORTED;
10598 /****************************************************************
10599 _spoolss_DeletePrintProvidor
10600 ****************************************************************/
10602 WERROR _spoolss_DeletePrintProvidor(pipes_struct *p,
10603 struct spoolss_DeletePrintProvidor *r)
10605 p->rng_fault_state = true;
10606 return WERR_NOT_SUPPORTED;
10609 /****************************************************************
10610 _spoolss_GetPrinterDriver2
10611 ****************************************************************/
10613 WERROR _spoolss_GetPrinterDriver2(pipes_struct *p,
10614 struct spoolss_GetPrinterDriver2 *r)
10616 p->rng_fault_state = true;
10617 return WERR_NOT_SUPPORTED;
10620 /****************************************************************
10621 _spoolss_FindFirstPrinterChangeNotification
10622 ****************************************************************/
10624 WERROR _spoolss_FindFirstPrinterChangeNotification(pipes_struct *p,
10625 struct spoolss_FindFirstPrinterChangeNotification *r)
10627 p->rng_fault_state = true;
10628 return WERR_NOT_SUPPORTED;
10631 /****************************************************************
10632 _spoolss_FindNextPrinterChangeNotification
10633 ****************************************************************/
10635 WERROR _spoolss_FindNextPrinterChangeNotification(pipes_struct *p,
10636 struct spoolss_FindNextPrinterChangeNotification *r)
10638 p->rng_fault_state = true;
10639 return WERR_NOT_SUPPORTED;
10642 /****************************************************************
10643 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10644 ****************************************************************/
10646 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(pipes_struct *p,
10647 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
10649 p->rng_fault_state = true;
10650 return WERR_NOT_SUPPORTED;
10653 /****************************************************************
10654 _spoolss_ReplyOpenPrinter
10655 ****************************************************************/
10657 WERROR _spoolss_ReplyOpenPrinter(pipes_struct *p,
10658 struct spoolss_ReplyOpenPrinter *r)
10660 p->rng_fault_state = true;
10661 return WERR_NOT_SUPPORTED;
10664 /****************************************************************
10665 _spoolss_RouterReplyPrinter
10666 ****************************************************************/
10668 WERROR _spoolss_RouterReplyPrinter(pipes_struct *p,
10669 struct spoolss_RouterReplyPrinter *r)
10671 p->rng_fault_state = true;
10672 return WERR_NOT_SUPPORTED;
10675 /****************************************************************
10676 _spoolss_ReplyClosePrinter
10677 ****************************************************************/
10679 WERROR _spoolss_ReplyClosePrinter(pipes_struct *p,
10680 struct spoolss_ReplyClosePrinter *r)
10682 p->rng_fault_state = true;
10683 return WERR_NOT_SUPPORTED;
10686 /****************************************************************
10688 ****************************************************************/
10690 WERROR _spoolss_AddPortEx(pipes_struct *p,
10691 struct spoolss_AddPortEx *r)
10693 p->rng_fault_state = true;
10694 return WERR_NOT_SUPPORTED;
10697 /****************************************************************
10698 _spoolss_RouterFindFirstPrinterChangeNotification
10699 ****************************************************************/
10701 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(pipes_struct *p,
10702 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
10704 p->rng_fault_state = true;
10705 return WERR_NOT_SUPPORTED;
10708 /****************************************************************
10709 _spoolss_SpoolerInit
10710 ****************************************************************/
10712 WERROR _spoolss_SpoolerInit(pipes_struct *p,
10713 struct spoolss_SpoolerInit *r)
10715 p->rng_fault_state = true;
10716 return WERR_NOT_SUPPORTED;
10719 /****************************************************************
10720 _spoolss_ResetPrinterEx
10721 ****************************************************************/
10723 WERROR _spoolss_ResetPrinterEx(pipes_struct *p,
10724 struct spoolss_ResetPrinterEx *r)
10726 p->rng_fault_state = true;
10727 return WERR_NOT_SUPPORTED;
10730 /****************************************************************
10731 _spoolss_RouterReplyPrinterEx
10732 ****************************************************************/
10734 WERROR _spoolss_RouterReplyPrinterEx(pipes_struct *p,
10735 struct spoolss_RouterReplyPrinterEx *r)
10737 p->rng_fault_state = true;
10738 return WERR_NOT_SUPPORTED;
10741 /****************************************************************
10743 ****************************************************************/
10745 WERROR _spoolss_44(pipes_struct *p,
10746 struct spoolss_44 *r)
10748 p->rng_fault_state = true;
10749 return WERR_NOT_SUPPORTED;
10752 /****************************************************************
10754 ****************************************************************/
10756 WERROR _spoolss_47(pipes_struct *p,
10757 struct spoolss_47 *r)
10759 p->rng_fault_state = true;
10760 return WERR_NOT_SUPPORTED;
10763 /****************************************************************
10764 _spoolss_EnumPrinterData
10765 ****************************************************************/
10767 WERROR _spoolss_EnumPrinterData(pipes_struct *p,
10768 struct spoolss_EnumPrinterData *r)
10770 p->rng_fault_state = true;
10771 return WERR_NOT_SUPPORTED;
10774 /****************************************************************
10776 ****************************************************************/
10778 WERROR _spoolss_4a(pipes_struct *p,
10779 struct spoolss_4a *r)
10781 p->rng_fault_state = true;
10782 return WERR_NOT_SUPPORTED;
10785 /****************************************************************
10787 ****************************************************************/
10789 WERROR _spoolss_4b(pipes_struct *p,
10790 struct spoolss_4b *r)
10792 p->rng_fault_state = true;
10793 return WERR_NOT_SUPPORTED;
10796 /****************************************************************
10798 ****************************************************************/
10800 WERROR _spoolss_4c(pipes_struct *p,
10801 struct spoolss_4c *r)
10803 p->rng_fault_state = true;
10804 return WERR_NOT_SUPPORTED;
10807 /****************************************************************
10808 _spoolss_EnumPrinterDataEx
10809 ****************************************************************/
10811 WERROR _spoolss_EnumPrinterDataEx(pipes_struct *p,
10812 struct spoolss_EnumPrinterDataEx *r)
10814 p->rng_fault_state = true;
10815 return WERR_NOT_SUPPORTED;
10818 /****************************************************************
10819 _spoolss_EnumPrinterKey
10820 ****************************************************************/
10822 WERROR _spoolss_EnumPrinterKey(pipes_struct *p,
10823 struct spoolss_EnumPrinterKey *r)
10825 p->rng_fault_state = true;
10826 return WERR_NOT_SUPPORTED;
10829 /****************************************************************
10831 ****************************************************************/
10833 WERROR _spoolss_53(pipes_struct *p,
10834 struct spoolss_53 *r)
10836 p->rng_fault_state = true;
10837 return WERR_NOT_SUPPORTED;
10840 /****************************************************************
10842 ****************************************************************/
10844 WERROR _spoolss_55(pipes_struct *p,
10845 struct spoolss_55 *r)
10847 p->rng_fault_state = true;
10848 return WERR_NOT_SUPPORTED;
10851 /****************************************************************
10853 ****************************************************************/
10855 WERROR _spoolss_56(pipes_struct *p,
10856 struct spoolss_56 *r)
10858 p->rng_fault_state = true;
10859 return WERR_NOT_SUPPORTED;
10862 /****************************************************************
10864 ****************************************************************/
10866 WERROR _spoolss_57(pipes_struct *p,
10867 struct spoolss_57 *r)
10869 p->rng_fault_state = true;
10870 return WERR_NOT_SUPPORTED;
10873 /****************************************************************
10875 ****************************************************************/
10877 WERROR _spoolss_5a(pipes_struct *p,
10878 struct spoolss_5a *r)
10880 p->rng_fault_state = true;
10881 return WERR_NOT_SUPPORTED;
10884 /****************************************************************
10886 ****************************************************************/
10888 WERROR _spoolss_5b(pipes_struct *p,
10889 struct spoolss_5b *r)
10891 p->rng_fault_state = true;
10892 return WERR_NOT_SUPPORTED;
10895 /****************************************************************
10897 ****************************************************************/
10899 WERROR _spoolss_5c(pipes_struct *p,
10900 struct spoolss_5c *r)
10902 p->rng_fault_state = true;
10903 return WERR_NOT_SUPPORTED;
10906 /****************************************************************
10908 ****************************************************************/
10910 WERROR _spoolss_5d(pipes_struct *p,
10911 struct spoolss_5d *r)
10913 p->rng_fault_state = true;
10914 return WERR_NOT_SUPPORTED;
10917 /****************************************************************
10919 ****************************************************************/
10921 WERROR _spoolss_5e(pipes_struct *p,
10922 struct spoolss_5e *r)
10924 p->rng_fault_state = true;
10925 return WERR_NOT_SUPPORTED;
10928 /****************************************************************
10930 ****************************************************************/
10932 WERROR _spoolss_5f(pipes_struct *p,
10933 struct spoolss_5f *r)
10935 p->rng_fault_state = true;
10936 return WERR_NOT_SUPPORTED;