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.
10 * Copyright (C) Guenther Deschner 2009.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <http://www.gnu.org/licenses/>.
26 /* Since the SPOOLSS rpc routines are basically DOS 16-bit calls wrapped
27 up, all the errors returned are DOS errors, not NT status codes. */
31 /* macros stolen from s4 spoolss server */
32 #define SPOOLSS_BUFFER_UNION(fn,ic,info,level) \
33 ((info)?ndr_size_##fn(info, level, ic, 0):0)
35 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,ic,info,level,count) \
36 ((info)?ndr_size_##fn##_info(mem_ctx, ic, level, count, info):0)
38 #define SPOOLSS_BUFFER_ARRAY(mem_ctx,fn,ic,info,count) \
39 ((info)?ndr_size_##fn##_info(mem_ctx, ic, count, info):0)
41 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
44 extern userdom_struct current_user_info;
47 #define DBGC_CLASS DBGC_RPC_SRV
49 #ifndef MAX_OPEN_PRINTER_EXS
50 #define MAX_OPEN_PRINTER_EXS 50
53 #define MAGIC_DISPLAY_FREQUENCY 0xfade2bad
54 #define PHANTOM_DEVMODE_KEY "_p_f_a_n_t_0_m_"
57 const char *long_archi;
58 const char *short_archi;
62 static Printer_entry *printers_list;
64 typedef struct _counter_printer_0 {
65 struct _counter_printer_0 *next;
66 struct _counter_printer_0 *prev;
72 static counter_printer_0 *counter_list;
74 static struct rpc_pipe_client *notify_cli_pipe; /* print notify back-channel pipe handle*/
75 static uint32_t smb_connections = 0;
78 /* in printing/nt_printing.c */
80 extern struct standard_mapping printer_std_mapping, printserver_std_mapping;
82 /* API table for Xcv Monitor functions */
84 struct xcv_api_table {
86 WERROR(*fn) (TALLOC_CTX *mem_ctx, NT_USER_TOKEN *token, DATA_BLOB *in, DATA_BLOB *out, uint32_t *needed);
89 /********************************************************************
90 * Canonicalize servername.
91 ********************************************************************/
93 static const char *canon_servername(const char *servername)
95 const char *pservername = servername;
96 while (*pservername == '\\') {
102 /* translate between internal status numbers and NT status numbers */
103 static int nt_printj_status(int v)
109 return JOB_STATUS_PAUSED;
111 return JOB_STATUS_SPOOLING;
113 return JOB_STATUS_PRINTING;
115 return JOB_STATUS_ERROR;
117 return JOB_STATUS_DELETING;
119 return JOB_STATUS_OFFLINE;
121 return JOB_STATUS_PAPEROUT;
123 return JOB_STATUS_PRINTED;
125 return JOB_STATUS_DELETED;
127 return JOB_STATUS_BLOCKED_DEVQ;
128 case LPQ_USER_INTERVENTION:
129 return JOB_STATUS_USER_INTERVENTION;
134 static int nt_printq_status(int v)
138 return PRINTER_STATUS_PAUSED;
147 /***************************************************************************
148 Disconnect from the client
149 ****************************************************************************/
151 static void srv_spoolss_replycloseprinter(int snum, struct policy_handle *handle)
157 * Tell the specific printing tdb we no longer want messages for this printer
158 * by deregistering our PID.
161 if (!print_notify_deregister_pid(snum))
162 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", lp_const_servicename(snum) ));
164 /* weird if the test succeds !!! */
165 if (smb_connections==0) {
166 DEBUG(0,("srv_spoolss_replycloseprinter:Trying to close non-existant notify backchannel !\n"));
170 status = rpccli_spoolss_ReplyClosePrinter(notify_cli_pipe, talloc_tos(),
173 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
174 DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed [%s].\n",
175 win_errstr(result)));
177 /* if it's the last connection, deconnect the IPC$ share */
178 if (smb_connections==1) {
180 cli_shutdown( rpc_pipe_np_smb_conn(notify_cli_pipe) );
181 notify_cli_pipe = NULL; /* The above call shuts downn the pipe also. */
183 messaging_deregister(smbd_messaging_context(),
184 MSG_PRINTER_NOTIFY2, NULL);
186 /* Tell the connections db we're no longer interested in
187 * printer notify messages. */
189 register_message_flags(false, FLAG_MSG_PRINT_NOTIFY);
195 /****************************************************************************
196 Functions to free a printer entry datastruct.
197 ****************************************************************************/
199 static int printer_entry_destructor(Printer_entry *Printer)
201 if (Printer->notify.client_connected == true) {
204 if ( Printer->printer_type == SPLHND_SERVER) {
206 srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
207 } else if (Printer->printer_type == SPLHND_PRINTER) {
208 snum = print_queue_snum(Printer->sharename);
210 srv_spoolss_replycloseprinter(snum,
211 &Printer->notify.client_hnd);
215 Printer->notify.flags=0;
216 Printer->notify.options=0;
217 Printer->notify.localmachine[0]='\0';
218 Printer->notify.printerlocal=0;
219 TALLOC_FREE(Printer->notify.option);
220 Printer->notify.client_connected = false;
222 free_nt_devicemode( &Printer->nt_devmode );
223 free_a_printer( &Printer->printer_info, 2 );
225 /* Remove from the internal list. */
226 DLIST_REMOVE(printers_list, Printer);
230 /****************************************************************************
231 find printer index by handle
232 ****************************************************************************/
234 static Printer_entry *find_printer_index_by_hnd(pipes_struct *p,
235 struct policy_handle *hnd)
237 Printer_entry *find_printer = NULL;
239 if(!find_policy_by_hnd(p,hnd,(void **)(void *)&find_printer)) {
240 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
247 /****************************************************************************
248 Close printer index by handle.
249 ****************************************************************************/
251 static bool close_printer_handle(pipes_struct *p, struct policy_handle *hnd)
253 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
256 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n",
261 close_policy_hnd(p, hnd);
266 /****************************************************************************
267 Delete a printer given a handle.
268 ****************************************************************************/
270 WERROR delete_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *sharename )
272 char *cmd = lp_deleteprinter_cmd();
273 char *command = NULL;
275 SE_PRIV se_printop = SE_PRINT_OPERATOR;
276 bool is_print_op = false;
278 /* can't fail if we don't try */
283 command = talloc_asprintf(ctx,
290 is_print_op = user_has_privileges( token, &se_printop );
292 DEBUG(10,("Running [%s]\n", command));
294 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
299 if ( (ret = smbrun(command, NULL)) == 0 ) {
300 /* Tell everyone we updated smb.conf. */
301 message_send_all(smbd_messaging_context(),
302 MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
308 /********** END SePrintOperatorPrivlege BLOCK **********/
310 DEBUGADD(10,("returned [%d]\n", ret));
312 TALLOC_FREE(command);
315 return WERR_BADFID; /* What to return here? */
317 /* go ahead and re-read the services immediately */
318 reload_services(false);
320 if ( lp_servicenumber( sharename ) < 0 )
321 return WERR_ACCESS_DENIED;
326 /****************************************************************************
327 Delete a printer given a handle.
328 ****************************************************************************/
330 static WERROR delete_printer_handle(pipes_struct *p, struct policy_handle *hnd)
332 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
335 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
341 * It turns out that Windows allows delete printer on a handle
342 * opened by an admin user, then used on a pipe handle created
343 * by an anonymous user..... but they're working on security.... riiight !
347 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
348 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
349 return WERR_ACCESS_DENIED;
352 /* this does not need a become root since the access check has been
353 done on the handle already */
355 if (del_a_printer( Printer->sharename ) != 0) {
356 DEBUG(3,("Error deleting printer %s\n", Printer->sharename));
360 return delete_printer_hook(p->mem_ctx, p->server_info->ptok,
361 Printer->sharename );
364 /****************************************************************************
365 Return the snum of a printer corresponding to an handle.
366 ****************************************************************************/
368 static bool get_printer_snum(pipes_struct *p, struct policy_handle *hnd,
369 int *number, struct share_params **params)
371 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
374 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
379 switch (Printer->printer_type) {
381 DEBUG(4,("short name:%s\n", Printer->sharename));
382 *number = print_queue_snum(Printer->sharename);
383 return (*number != -1);
391 /****************************************************************************
392 Set printer handle type.
393 Check if it's \\server or \\server\printer
394 ****************************************************************************/
396 static bool set_printer_hnd_printertype(Printer_entry *Printer, const char *handlename)
398 DEBUG(3,("Setting printer type=%s\n", handlename));
400 if ( strlen(handlename) < 3 ) {
401 DEBUGADD(4,("A print server must have at least 1 char ! %s\n", handlename));
405 /* it's a print server */
406 if (*handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) {
407 DEBUGADD(4,("Printer is a print server\n"));
408 Printer->printer_type = SPLHND_SERVER;
410 /* it's a printer (set_printer_hnd_name() will handle port monitors */
412 DEBUGADD(4,("Printer is a printer\n"));
413 Printer->printer_type = SPLHND_PRINTER;
419 /****************************************************************************
420 Set printer handle name.. Accept names like \\server, \\server\printer,
421 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
422 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
423 XcvDataPort() interface.
424 ****************************************************************************/
426 static bool set_printer_hnd_name(Printer_entry *Printer, const char *handlename)
429 int n_services=lp_numservices();
430 char *aprinter, *printername;
431 const char *servername;
434 NT_PRINTER_INFO_LEVEL *printer = NULL;
437 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename,
438 (unsigned long)strlen(handlename)));
440 aprinter = CONST_DISCARD(char *, handlename);
441 if ( *handlename == '\\' ) {
442 servername = canon_servername(handlename);
443 if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
448 servername = global_myname();
451 /* save the servername to fill in replies on this handle */
453 if ( !is_myname_or_ipaddr( servername ) )
456 fstrcpy( Printer->servername, servername );
458 if ( Printer->printer_type == SPLHND_SERVER )
461 if ( Printer->printer_type != SPLHND_PRINTER )
464 DEBUGADD(5, ("searching for [%s]\n", aprinter ));
466 /* check for the Port Monitor Interface */
468 if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
469 Printer->printer_type = SPLHND_PORTMON_TCP;
470 fstrcpy(sname, SPL_XCV_MONITOR_TCPMON);
473 else if ( strequal( aprinter, SPL_XCV_MONITOR_LOCALMON ) ) {
474 Printer->printer_type = SPLHND_PORTMON_LOCAL;
475 fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON);
479 /* Search all sharenames first as this is easier than pulling
480 the printer_info_2 off of disk. Don't use find_service() since
481 that calls out to map_username() */
483 /* do another loop to look for printernames */
485 for (snum=0; !found && snum<n_services; snum++) {
487 /* no point going on if this is not a printer */
489 if ( !(lp_snum_ok(snum) && lp_print_ok(snum)) )
492 fstrcpy(sname, lp_servicename(snum));
493 if ( strequal( aprinter, sname ) ) {
498 /* no point looking up the printer object if
499 we aren't allowing printername != sharename */
501 if ( lp_force_printername(snum) )
504 fstrcpy(sname, lp_servicename(snum));
508 /* This call doesn't fill in the location or comment from
509 * a CUPS server for efficiency with large numbers of printers.
513 result = get_a_printer_search( NULL, &printer, 2, sname );
514 if ( !W_ERROR_IS_OK(result) ) {
515 DEBUG(0,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
516 sname, win_errstr(result)));
520 /* printername is always returned as \\server\printername */
521 if ( !(printername = strchr_m(&printer->info_2->printername[2], '\\')) ) {
522 DEBUG(0,("set_printer_hnd_name: info2->printername in wrong format! [%s]\n",
523 printer->info_2->printername));
524 free_a_printer( &printer, 2);
530 if ( strequal(printername, aprinter) ) {
531 free_a_printer( &printer, 2);
536 DEBUGADD(10, ("printername: %s\n", printername));
538 free_a_printer( &printer, 2);
541 free_a_printer( &printer, 2);
544 DEBUGADD(4,("Printer not found\n"));
548 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));
550 fstrcpy(Printer->sharename, sname);
555 /****************************************************************************
556 Find first available printer slot. creates a printer handle for you.
557 ****************************************************************************/
559 static bool open_printer_hnd(pipes_struct *p, struct policy_handle *hnd,
560 const char *name, uint32_t access_granted)
562 Printer_entry *new_printer;
564 DEBUG(10,("open_printer_hnd: name [%s]\n", name));
566 new_printer = TALLOC_ZERO_P(NULL, Printer_entry);
567 if (new_printer == NULL) {
570 talloc_set_destructor(new_printer, printer_entry_destructor);
572 if (!create_policy_hnd(p, hnd, new_printer)) {
573 TALLOC_FREE(new_printer);
577 /* Add to the internal list. */
578 DLIST_ADD(printers_list, new_printer);
580 new_printer->notify.option=NULL;
582 if (!set_printer_hnd_printertype(new_printer, name)) {
583 close_printer_handle(p, hnd);
587 if (!set_printer_hnd_name(new_printer, name)) {
588 close_printer_handle(p, hnd);
592 new_printer->access_granted = access_granted;
594 DEBUG(5, ("%d printer handles active\n", (int)p->pipe_handles->count ));
599 /***************************************************************************
600 check to see if the client motify handle is monitoring the notification
601 given by (notify_type, notify_field).
602 **************************************************************************/
604 static bool is_monitoring_event_flags(uint32_t flags, uint16_t notify_type,
605 uint16_t notify_field)
610 static bool is_monitoring_event(Printer_entry *p, uint16_t notify_type,
611 uint16_t notify_field)
613 struct spoolss_NotifyOption *option = p->notify.option;
617 * Flags should always be zero when the change notify
618 * is registered by the client's spooler. A user Win32 app
619 * might use the flags though instead of the NOTIFY_OPTION_INFO
628 return is_monitoring_event_flags(
629 p->notify.flags, notify_type, notify_field);
631 for (i = 0; i < option->count; i++) {
633 /* Check match for notify_type */
635 if (option->types[i].type != notify_type)
638 /* Check match for field */
640 for (j = 0; j < option->types[i].count; j++) {
641 if (option->types[i].fields[j].field == notify_field) {
647 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
648 p->servername, p->sharename, notify_type, notify_field));
653 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
654 _data->data.integer[0] = _integer; \
655 _data->data.integer[1] = 0;
658 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
659 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
660 if (!_data->data.string.string) {\
661 _data->data.string.size = 0; \
663 _data->data.string.size = strlen_m_term(_p) * 2;
665 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
666 _data->data.devmode.devmode = _devmode;
668 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _size, _sd) \
669 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
670 if (!_data->data.sd.sd) { \
671 _data->data.sd.sd_size = 0; \
673 _data->data.sd.sd_size = _size;
675 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
680 struct spoolss_Time st;
684 if (!init_systemtime(&st, t)) {
688 p = talloc_array(mem_ctx, char, len);
694 * Systemtime must be linearized as a set of UINT16's.
695 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
698 SSVAL(p, 0, st.year);
699 SSVAL(p, 2, st.month);
700 SSVAL(p, 4, st.day_of_week);
702 SSVAL(p, 8, st.hour);
703 SSVAL(p, 10, st.minute);
704 SSVAL(p, 12, st.second);
705 SSVAL(p, 14, st.millisecond);
711 /* Convert a notification message to a struct spoolss_Notify */
713 static void notify_one_value(struct spoolss_notify_msg *msg,
714 struct spoolss_Notify *data,
717 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, msg->notify.value[0]);
720 static void notify_string(struct spoolss_notify_msg *msg,
721 struct spoolss_Notify *data,
724 /* The length of the message includes the trailing \0 */
726 data->data.string.size = msg->len * 2;
727 data->data.string.string = talloc_strdup(mem_ctx, msg->notify.data);
728 if (!data->data.string.string) {
729 data->data.string.size = 0;
734 static void notify_system_time(struct spoolss_notify_msg *msg,
735 struct spoolss_Notify *data,
738 data->data.string.string = NULL;
739 data->data.string.size = 0;
741 if (msg->len != sizeof(time_t)) {
742 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
747 init_systemtime_buffer(mem_ctx, gmtime((time_t *)msg->notify.data),
748 &data->data.string.string,
749 &data->data.string.size);
752 struct notify2_message_table {
754 void (*fn)(struct spoolss_notify_msg *msg,
755 struct spoolss_Notify *data, TALLOC_CTX *mem_ctx);
758 static struct notify2_message_table printer_notify_table[] = {
759 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string },
760 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string },
761 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string },
762 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string },
763 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string },
764 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string },
765 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string },
766 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL },
767 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string },
768 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string },
769 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL },
770 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string },
771 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
772 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value },
773 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value },
774 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL },
775 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL },
776 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL },
777 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value },
780 static struct notify2_message_table job_notify_table[] = {
781 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL },
782 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL },
783 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL },
784 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string },
785 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL },
786 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL },
787 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL },
788 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL },
789 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL },
790 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL },
791 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value },
792 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL },
793 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
794 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string },
795 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL },
796 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL },
797 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time },
798 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL },
799 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL },
800 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL },
801 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value },
802 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL },
803 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value },
804 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL },
808 /***********************************************************************
809 Allocate talloc context for container object
810 **********************************************************************/
812 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
817 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
822 /***********************************************************************
823 release all allocated memory and zero out structure
824 **********************************************************************/
826 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
832 talloc_destroy(ctr->ctx);
839 /***********************************************************************
840 **********************************************************************/
842 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
850 /***********************************************************************
851 **********************************************************************/
853 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
855 if ( !ctr || !ctr->msg_groups )
858 if ( idx >= ctr->num_groups )
861 return &ctr->msg_groups[idx];
865 /***********************************************************************
866 How many groups of change messages do we have ?
867 **********************************************************************/
869 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
874 return ctr->num_groups;
877 /***********************************************************************
878 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
879 **********************************************************************/
881 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
883 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
884 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
885 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
891 /* loop over all groups looking for a matching printer name */
893 for ( i=0; i<ctr->num_groups; i++ ) {
894 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
898 /* add a new group? */
900 if ( i == ctr->num_groups ) {
903 if ( !(groups = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
904 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
907 ctr->msg_groups = groups;
909 /* clear the new entry and set the printer name */
911 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
912 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
915 /* add the change messages; 'i' is the correct index now regardless */
917 msg_grp = &ctr->msg_groups[i];
921 if ( !(msg_list = TALLOC_REALLOC_ARRAY( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
922 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
925 msg_grp->msgs = msg_list;
927 new_slot = msg_grp->num_msgs-1;
928 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
930 /* need to allocate own copy of data */
933 msg_grp->msgs[new_slot].notify.data = (char *)
934 TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len );
936 return ctr->num_groups;
939 /***********************************************************************
940 Send a change notication message on all handles which have a call
942 **********************************************************************/
944 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
947 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
948 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
949 SPOOLSS_NOTIFY_MSG *messages;
950 int sending_msg_count;
953 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
957 messages = msg_group->msgs;
960 DEBUG(5,("send_notify2_changes() called with no messages!\n"));
964 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
966 /* loop over all printers */
968 for (p = printers_list; p; p = p->next) {
969 struct spoolss_Notify *notifies;
974 /* Is there notification on this handle? */
976 if ( !p->notify.client_connected )
979 DEBUG(10,("Client connected! [\\\\%s\\%s]\n", p->servername, p->sharename));
981 /* For this printer? Print servers always receive
984 if ( ( p->printer_type == SPLHND_PRINTER ) &&
985 ( !strequal(msg_group->printername, p->sharename) ) )
988 DEBUG(10,("Our printer\n"));
990 /* allocate the max entries possible */
992 notifies = TALLOC_ZERO_ARRAY(mem_ctx, struct spoolss_Notify, msg_group->num_msgs);
997 /* build the array of change notifications */
999 sending_msg_count = 0;
1001 for ( i=0; i<msg_group->num_msgs; i++ ) {
1002 SPOOLSS_NOTIFY_MSG *msg = &messages[i];
1004 /* Are we monitoring this event? */
1006 if (!is_monitoring_event(p, msg->type, msg->field))
1009 sending_msg_count++;
1012 DEBUG(10,("process_notify2_message: Sending message type [0x%x] field [0x%2x] for printer [%s]\n",
1013 msg->type, msg->field, p->sharename));
1016 * if the is a printer notification handle and not a job notification
1017 * type, then set the id to 0. Other wise just use what was specified
1020 * When registering change notification on a print server handle
1021 * we always need to send back the id (snum) matching the printer
1022 * for which the change took place. For change notify registered
1023 * on a printer handle, this does not matter and the id should be 0.
1028 if ( ( p->printer_type == SPLHND_PRINTER ) && ( msg->type == PRINTER_NOTIFY_TYPE ) )
1034 /* Convert unix jobid to smb jobid */
1036 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1037 id = sysjob_to_jobid(msg->id);
1040 DEBUG(3, ("no such unix jobid %d\n", msg->id));
1045 construct_info_data( ¬ifies[count], msg->type, msg->field, id );
1048 case PRINTER_NOTIFY_TYPE:
1049 if ( printer_notify_table[msg->field].fn )
1050 printer_notify_table[msg->field].fn(msg, ¬ifies[count], mem_ctx);
1053 case JOB_NOTIFY_TYPE:
1054 if ( job_notify_table[msg->field].fn )
1055 job_notify_table[msg->field].fn(msg, ¬ifies[count], mem_ctx);
1059 DEBUG(5, ("Unknown notification type %d\n", msg->type));
1066 if ( sending_msg_count ) {
1069 union spoolss_ReplyPrinterInfo info;
1070 struct spoolss_NotifyInfo info0;
1071 uint32_t reply_result;
1073 info0.version = 0x2;
1074 info0.flags = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
1075 info0.count = count;
1076 info0.notifies = notifies;
1078 info.info0 = &info0;
1080 status = rpccli_spoolss_RouterReplyPrinterEx(notify_cli_pipe, mem_ctx,
1081 &p->notify.client_hnd,
1082 p->notify.change, /* color */
1085 0, /* reply_type, must be 0 */
1088 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) {
1089 DEBUG(1,("RouterReplyPrinterEx to client: %s failed: %s\n",
1090 notify_cli_pipe->srv_name_slash,
1093 switch (reply_result) {
1096 case PRINTER_NOTIFY_INFO_DISCARDED:
1097 case PRINTER_NOTIFY_INFO_DISCARDNOTED:
1098 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
1107 DEBUG(8,("send_notify2_changes: Exit...\n"));
1111 /***********************************************************************
1112 **********************************************************************/
1114 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1117 uint32_t tv_sec, tv_usec;
1120 /* Unpack message */
1122 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "f",
1125 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "ddddddd",
1127 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1130 tdb_unpack((uint8_t *)buf + offset, len - offset, "dd",
1131 &msg->notify.value[0], &msg->notify.value[1]);
1133 tdb_unpack((uint8_t *)buf + offset, len - offset, "B",
1134 &msg->len, &msg->notify.data);
1136 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1137 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1139 tv->tv_sec = tv_sec;
1140 tv->tv_usec = tv_usec;
1143 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1144 msg->notify.value[1]));
1146 dump_data(3, (uint8_t *)msg->notify.data, msg->len);
1151 /********************************************************************
1152 Receive a notify2 message list
1153 ********************************************************************/
1155 static void receive_notify2_message_list(struct messaging_context *msg,
1158 struct server_id server_id,
1161 size_t msg_count, i;
1162 char *buf = (char *)data->data;
1165 SPOOLSS_NOTIFY_MSG notify;
1166 SPOOLSS_NOTIFY_MSG_CTR messages;
1169 if (data->length < 4) {
1170 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1174 msg_count = IVAL(buf, 0);
1177 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1179 if (msg_count == 0) {
1180 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1184 /* initialize the container */
1186 ZERO_STRUCT( messages );
1187 notify_msg_ctr_init( &messages );
1190 * build message groups for each printer identified
1191 * in a change_notify msg. Remember that a PCN message
1192 * includes the handle returned for the srv_spoolss_replyopenprinter()
1193 * call. Therefore messages are grouped according to printer handle.
1196 for ( i=0; i<msg_count; i++ ) {
1197 struct timeval msg_tv;
1199 if (msg_ptr + 4 - buf > data->length) {
1200 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1204 msg_len = IVAL(msg_ptr,0);
1207 if (msg_ptr + msg_len - buf > data->length) {
1208 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1212 /* unpack messages */
1214 ZERO_STRUCT( notify );
1215 notify2_unpack_msg( ¬ify, &msg_tv, msg_ptr, msg_len );
1218 /* add to correct list in container */
1220 notify_msg_ctr_addmsg( &messages, ¬ify );
1222 /* free memory that might have been allocated by notify2_unpack_msg() */
1224 if ( notify.len != 0 )
1225 SAFE_FREE( notify.notify.data );
1228 /* process each group of messages */
1230 num_groups = notify_msg_ctr_numgroups( &messages );
1231 for ( i=0; i<num_groups; i++ )
1232 send_notify2_changes( &messages, i );
1237 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1238 (uint32_t)msg_count ));
1240 notify_msg_ctr_destroy( &messages );
1245 /********************************************************************
1246 Send a message to ourself about new driver being installed
1247 so we can upgrade the information for each printer bound to this
1249 ********************************************************************/
1251 static bool srv_spoolss_drv_upgrade_printer(const char *drivername)
1253 int len = strlen(drivername);
1258 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1261 messaging_send_buf(smbd_messaging_context(), procid_self(),
1262 MSG_PRINTER_DRVUPGRADE,
1263 (uint8_t *)drivername, len+1);
1268 /**********************************************************************
1269 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1270 over all printers, upgrading ones as necessary
1271 **********************************************************************/
1273 void do_drv_upgrade_printer(struct messaging_context *msg,
1276 struct server_id server_id,
1281 int n_services = lp_numservices();
1284 len = MIN(data->length,sizeof(drivername)-1);
1285 strncpy(drivername, (const char *)data->data, len);
1287 DEBUG(10,("do_drv_upgrade_printer: Got message for new driver [%s]\n", drivername ));
1289 /* Iterate the printer list */
1291 for (snum=0; snum<n_services; snum++)
1293 if (lp_snum_ok(snum) && lp_print_ok(snum) )
1296 NT_PRINTER_INFO_LEVEL *printer = NULL;
1298 result = get_a_printer(NULL, &printer, 2, lp_const_servicename(snum));
1299 if (!W_ERROR_IS_OK(result))
1302 if (printer && printer->info_2 && !strcmp(drivername, printer->info_2->drivername))
1304 DEBUG(6,("Updating printer [%s]\n", printer->info_2->printername));
1306 /* all we care about currently is the change_id */
1308 result = mod_a_printer(printer, 2);
1309 if (!W_ERROR_IS_OK(result)) {
1310 DEBUG(3,("do_drv_upgrade_printer: mod_a_printer() failed with status [%s]\n",
1311 win_errstr(result)));
1315 free_a_printer(&printer, 2);
1322 /********************************************************************
1323 Update the cache for all printq's with a registered client
1325 ********************************************************************/
1327 void update_monitored_printq_cache( void )
1329 Printer_entry *printer = printers_list;
1332 /* loop through all printers and update the cache where
1333 client_connected == true */
1336 if ( (printer->printer_type == SPLHND_PRINTER)
1337 && printer->notify.client_connected )
1339 snum = print_queue_snum(printer->sharename);
1340 print_queue_status( snum, NULL, NULL );
1343 printer = printer->next;
1348 /********************************************************************
1349 Send a message to ourself about new driver being installed
1350 so we can upgrade the information for each printer bound to this
1352 ********************************************************************/
1354 static bool srv_spoolss_reset_printerdata(char* drivername)
1356 int len = strlen(drivername);
1361 DEBUG(10,("srv_spoolss_reset_printerdata: Sending message about resetting printerdata [%s]\n",
1364 messaging_send_buf(smbd_messaging_context(), procid_self(),
1365 MSG_PRINTERDATA_INIT_RESET,
1366 (uint8_t *)drivername, len+1);
1371 /**********************************************************************
1372 callback to receive a MSG_PRINTERDATA_INIT_RESET message and interate
1373 over all printers, resetting printer data as neessary
1374 **********************************************************************/
1376 void reset_all_printerdata(struct messaging_context *msg,
1379 struct server_id server_id,
1384 int n_services = lp_numservices();
1387 len = MIN( data->length, sizeof(drivername)-1 );
1388 strncpy( drivername, (const char *)data->data, len );
1390 DEBUG(10,("reset_all_printerdata: Got message for new driver [%s]\n", drivername ));
1392 /* Iterate the printer list */
1394 for ( snum=0; snum<n_services; snum++ )
1396 if ( lp_snum_ok(snum) && lp_print_ok(snum) )
1399 NT_PRINTER_INFO_LEVEL *printer = NULL;
1401 result = get_a_printer( NULL, &printer, 2, lp_const_servicename(snum) );
1402 if ( !W_ERROR_IS_OK(result) )
1406 * if the printer is bound to the driver,
1407 * then reset to the new driver initdata
1410 if ( printer && printer->info_2 && !strcmp(drivername, printer->info_2->drivername) )
1412 DEBUG(6,("reset_all_printerdata: Updating printer [%s]\n", printer->info_2->printername));
1414 if ( !set_driver_init(printer, 2) ) {
1415 DEBUG(5,("reset_all_printerdata: Error resetting printer data for printer [%s], driver [%s]!\n",
1416 printer->info_2->printername, printer->info_2->drivername));
1419 result = mod_a_printer( printer, 2 );
1420 if ( !W_ERROR_IS_OK(result) ) {
1421 DEBUG(3,("reset_all_printerdata: mod_a_printer() failed! (%s)\n",
1422 get_dos_error_msg(result)));
1426 free_a_printer( &printer, 2 );
1435 /****************************************************************
1436 _spoolss_OpenPrinter
1437 ****************************************************************/
1439 WERROR _spoolss_OpenPrinter(pipes_struct *p,
1440 struct spoolss_OpenPrinter *r)
1442 struct spoolss_OpenPrinterEx e;
1445 ZERO_STRUCT(e.in.userlevel);
1447 e.in.printername = r->in.printername;
1448 e.in.datatype = r->in.datatype;
1449 e.in.devmode_ctr = r->in.devmode_ctr;
1450 e.in.access_mask = r->in.access_mask;
1453 e.out.handle = r->out.handle;
1455 werr = _spoolss_OpenPrinterEx(p, &e);
1457 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1458 /* OpenPrinterEx returns this for a bad
1459 * printer name. We must return WERR_INVALID_PRINTER_NAME
1462 werr = WERR_INVALID_PRINTER_NAME;
1468 /********************************************************************
1469 ********************************************************************/
1471 bool convert_devicemode(const char *printername,
1472 const struct spoolss_DeviceMode *devmode,
1473 NT_DEVICEMODE **pp_nt_devmode)
1475 NT_DEVICEMODE *nt_devmode = *pp_nt_devmode;
1478 * Ensure nt_devmode is a valid pointer
1479 * as we will be overwriting it.
1482 if (nt_devmode == NULL) {
1483 DEBUG(5, ("convert_devicemode: allocating a generic devmode\n"));
1484 if ((nt_devmode = construct_nt_devicemode(printername)) == NULL)
1488 rpcstr_push(nt_devmode->devicename, devmode->devicename, 31, 0);
1489 rpcstr_push(nt_devmode->formname, devmode->formname, 31, 0);
1491 nt_devmode->specversion = devmode->specversion;
1492 nt_devmode->driverversion = devmode->driverversion;
1493 nt_devmode->size = devmode->size;
1494 nt_devmode->fields = devmode->fields;
1495 nt_devmode->orientation = devmode->orientation;
1496 nt_devmode->papersize = devmode->papersize;
1497 nt_devmode->paperlength = devmode->paperlength;
1498 nt_devmode->paperwidth = devmode->paperwidth;
1499 nt_devmode->scale = devmode->scale;
1500 nt_devmode->copies = devmode->copies;
1501 nt_devmode->defaultsource = devmode->defaultsource;
1502 nt_devmode->printquality = devmode->printquality;
1503 nt_devmode->color = devmode->color;
1504 nt_devmode->duplex = devmode->duplex;
1505 nt_devmode->yresolution = devmode->yresolution;
1506 nt_devmode->ttoption = devmode->ttoption;
1507 nt_devmode->collate = devmode->collate;
1509 nt_devmode->logpixels = devmode->logpixels;
1510 nt_devmode->bitsperpel = devmode->bitsperpel;
1511 nt_devmode->pelswidth = devmode->pelswidth;
1512 nt_devmode->pelsheight = devmode->pelsheight;
1513 nt_devmode->displayflags = devmode->displayflags;
1514 nt_devmode->displayfrequency = devmode->displayfrequency;
1515 nt_devmode->icmmethod = devmode->icmmethod;
1516 nt_devmode->icmintent = devmode->icmintent;
1517 nt_devmode->mediatype = devmode->mediatype;
1518 nt_devmode->dithertype = devmode->dithertype;
1519 nt_devmode->reserved1 = devmode->reserved1;
1520 nt_devmode->reserved2 = devmode->reserved2;
1521 nt_devmode->panningwidth = devmode->panningwidth;
1522 nt_devmode->panningheight = devmode->panningheight;
1525 * Only change private and driverextra if the incoming devmode
1526 * has a new one. JRA.
1529 if ((devmode->__driverextra_length != 0) && (devmode->driverextra_data.data != NULL)) {
1530 SAFE_FREE(nt_devmode->nt_dev_private);
1531 nt_devmode->driverextra = devmode->__driverextra_length;
1532 if((nt_devmode->nt_dev_private = SMB_MALLOC_ARRAY(uint8_t, nt_devmode->driverextra)) == NULL)
1534 memcpy(nt_devmode->nt_dev_private, devmode->driverextra_data.data, nt_devmode->driverextra);
1537 *pp_nt_devmode = nt_devmode;
1542 /****************************************************************
1543 _spoolss_OpenPrinterEx
1544 ****************************************************************/
1546 WERROR _spoolss_OpenPrinterEx(pipes_struct *p,
1547 struct spoolss_OpenPrinterEx *r)
1550 Printer_entry *Printer=NULL;
1552 if (!r->in.printername) {
1553 return WERR_INVALID_PARAM;
1556 /* some sanity check because you can open a printer or a print server */
1557 /* aka: \\server\printer or \\server */
1559 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1561 if (!open_printer_hnd(p, r->out.handle, r->in.printername, 0)) {
1562 ZERO_STRUCTP(r->out.handle);
1563 return WERR_INVALID_PARAM;
1566 Printer = find_printer_index_by_hnd(p, r->out.handle);
1568 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1569 "handle we created for printer %s\n", r->in.printername));
1570 close_printer_handle(p, r->out.handle);
1571 ZERO_STRUCTP(r->out.handle);
1572 return WERR_INVALID_PARAM;
1576 * First case: the user is opening the print server:
1578 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1579 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1581 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1582 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1583 * or if the user is listed in the smb.conf printer admin parameter.
1585 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1586 * client view printer folder, but does not show the MSAPW.
1588 * Note: this test needs code to check access rights here too. Jeremy
1589 * could you look at this?
1591 * Second case: the user is opening a printer:
1592 * NT doesn't let us connect to a printer if the connecting user
1593 * doesn't have print permission.
1595 * Third case: user is opening a Port Monitor
1596 * access checks same as opening a handle to the print server.
1599 switch (Printer->printer_type )
1602 case SPLHND_PORTMON_TCP:
1603 case SPLHND_PORTMON_LOCAL:
1604 /* Printserver handles use global struct... */
1608 /* Map standard access rights to object specific access rights */
1610 se_map_standard(&r->in.access_mask,
1611 &printserver_std_mapping);
1613 /* Deny any object specific bits that don't apply to print
1614 servers (i.e printer and job specific bits) */
1616 r->in.access_mask &= SPECIFIC_RIGHTS_MASK;
1618 if (r->in.access_mask &
1619 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1620 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1621 close_printer_handle(p, r->out.handle);
1622 ZERO_STRUCTP(r->out.handle);
1623 return WERR_ACCESS_DENIED;
1626 /* Allow admin access */
1628 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1630 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1632 if (!lp_ms_add_printer_wizard()) {
1633 close_printer_handle(p, r->out.handle);
1634 ZERO_STRUCTP(r->out.handle);
1635 return WERR_ACCESS_DENIED;
1638 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1639 and not a printer admin, then fail */
1641 if ((p->server_info->utok.uid != 0) &&
1642 !user_has_privileges(p->server_info->ptok,
1644 !token_contains_name_in_list(
1645 uidtoname(p->server_info->utok.uid),
1647 p->server_info->ptok,
1648 lp_printer_admin(snum))) {
1649 close_printer_handle(p, r->out.handle);
1650 ZERO_STRUCTP(r->out.handle);
1651 return WERR_ACCESS_DENIED;
1654 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1658 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1661 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1662 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1664 /* We fall through to return WERR_OK */
1667 case SPLHND_PRINTER:
1668 /* NT doesn't let us connect to a printer if the connecting user
1669 doesn't have print permission. */
1671 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1672 close_printer_handle(p, r->out.handle);
1673 ZERO_STRUCTP(r->out.handle);
1677 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1679 /* map an empty access mask to the minimum access mask */
1680 if (r->in.access_mask == 0x0)
1681 r->in.access_mask = PRINTER_ACCESS_USE;
1684 * If we are not serving the printer driver for this printer,
1685 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1686 * will keep NT clients happy --jerry
1689 if (lp_use_client_driver(snum)
1690 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1692 r->in.access_mask = PRINTER_ACCESS_USE;
1695 /* check smb.conf parameters and the the sec_desc */
1697 if ( !check_access(get_client_fd(), lp_hostsallow(snum), lp_hostsdeny(snum)) ) {
1698 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1699 ZERO_STRUCTP(r->out.handle);
1700 return WERR_ACCESS_DENIED;
1703 if (!user_ok_token(uidtoname(p->server_info->utok.uid), NULL,
1704 p->server_info->ptok, snum) ||
1705 !print_access_check(p->server_info, snum,
1706 r->in.access_mask)) {
1707 DEBUG(3, ("access DENIED for printer open\n"));
1708 close_printer_handle(p, r->out.handle);
1709 ZERO_STRUCTP(r->out.handle);
1710 return WERR_ACCESS_DENIED;
1713 if ((r->in.access_mask & SPECIFIC_RIGHTS_MASK)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1714 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1715 close_printer_handle(p, r->out.handle);
1716 ZERO_STRUCTP(r->out.handle);
1717 return WERR_ACCESS_DENIED;
1720 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1721 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1723 r->in.access_mask = PRINTER_ACCESS_USE;
1725 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1726 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1731 /* sanity check to prevent programmer error */
1732 ZERO_STRUCTP(r->out.handle);
1736 Printer->access_granted = r->in.access_mask;
1739 * If the client sent a devmode in the OpenPrinter() call, then
1740 * save it here in case we get a job submission on this handle
1743 if ((Printer->printer_type != SPLHND_SERVER) &&
1744 r->in.devmode_ctr.devmode) {
1745 convert_devicemode(Printer->sharename,
1746 r->in.devmode_ctr.devmode,
1747 &Printer->nt_devmode);
1750 #if 0 /* JERRY -- I'm doubtful this is really effective */
1751 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1752 optimization in Windows 2000 clients --jerry */
1754 if ( (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1755 && (RA_WIN2K == get_remote_arch()) )
1757 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1758 sys_usleep( 500000 );
1765 /****************************************************************************
1766 ****************************************************************************/
1768 static bool printer_info2_to_nt_printer_info2(struct spoolss_SetPrinterInfo2 *r,
1769 NT_PRINTER_INFO_LEVEL_2 *d)
1771 DEBUG(7,("printer_info2_to_nt_printer_info2\n"));
1777 d->attributes = r->attributes;
1778 d->priority = r->priority;
1779 d->default_priority = r->defaultpriority;
1780 d->starttime = r->starttime;
1781 d->untiltime = r->untiltime;
1782 d->status = r->status;
1783 d->cjobs = r->cjobs;
1785 fstrcpy(d->servername, r->servername);
1786 fstrcpy(d->printername, r->printername);
1787 fstrcpy(d->sharename, r->sharename);
1788 fstrcpy(d->portname, r->portname);
1789 fstrcpy(d->drivername, r->drivername);
1790 slprintf(d->comment, sizeof(d->comment)-1, "%s", r->comment);
1791 fstrcpy(d->location, r->location);
1792 fstrcpy(d->sepfile, r->sepfile);
1793 fstrcpy(d->printprocessor, r->printprocessor);
1794 fstrcpy(d->datatype, r->datatype);
1795 fstrcpy(d->parameters, r->parameters);
1800 /****************************************************************************
1801 ****************************************************************************/
1803 static bool convert_printer_info(struct spoolss_SetPrinterInfoCtr *info_ctr,
1804 NT_PRINTER_INFO_LEVEL *printer)
1808 switch (info_ctr->level) {
1810 /* allocate memory if needed. Messy because
1811 convert_printer_info is used to update an existing
1812 printer or build a new one */
1814 if (!printer->info_2) {
1815 printer->info_2 = TALLOC_ZERO_P(printer, NT_PRINTER_INFO_LEVEL_2);
1816 if (!printer->info_2) {
1817 DEBUG(0,("convert_printer_info: "
1818 "talloc() failed!\n"));
1823 ret = printer_info2_to_nt_printer_info2(info_ctr->info.info2,
1825 printer->info_2->setuptime = time(NULL);
1832 /*******************************************************************
1833 ********************************************************************/
1835 static bool string_array_to_fstring_array(const char **sarray, fstring **farray)
1844 *farray = SMB_MALLOC_ARRAY(fstring, 1);
1849 for (i=0; sarray[i] != NULL; i++) {
1850 *farray = SMB_REALLOC_ARRAY(*farray, fstring, i+2);
1854 fstrcpy((*farray)[i], sarray[i]);
1857 fstrcpy((*farray)[i], "");
1862 /*******************************************************************
1863 ********************************************************************/
1865 static bool driver_info3_to_nt_driver_info3(struct spoolss_AddDriverInfo3 *r,
1866 NT_PRINTER_DRIVER_INFO_LEVEL_3 **p)
1868 NT_PRINTER_DRIVER_INFO_LEVEL_3 *d;
1870 DEBUG(7,("driver_info3_to_nt_driver_info3: Converting from UNICODE to ASCII\n"));
1873 *p = SMB_MALLOC_P(NT_PRINTER_DRIVER_INFO_LEVEL_3);
1882 d->cversion = r->version;
1884 fstrcpy(d->name, r->driver_name);
1885 fstrcpy(d->environment, r->architecture);
1886 fstrcpy(d->driverpath, r->driver_path);
1887 fstrcpy(d->datafile, r->data_file);
1888 fstrcpy(d->configfile, r->config_file);
1889 fstrcpy(d->helpfile, r->help_file);
1890 fstrcpy(d->monitorname, r->monitor_name);
1891 fstrcpy(d->defaultdatatype, r->default_datatype);
1893 DEBUGADD(8,( "version: %d\n", d->cversion));
1894 DEBUGADD(8,( "name: %s\n", d->name));
1895 DEBUGADD(8,( "environment: %s\n", d->environment));
1896 DEBUGADD(8,( "driverpath: %s\n", d->driverpath));
1897 DEBUGADD(8,( "datafile: %s\n", d->datafile));
1898 DEBUGADD(8,( "configfile: %s\n", d->configfile));
1899 DEBUGADD(8,( "helpfile: %s\n", d->helpfile));
1900 DEBUGADD(8,( "monitorname: %s\n", d->monitorname));
1901 DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
1903 if (r->dependent_files) {
1904 if (!string_array_to_fstring_array(r->dependent_files->string,
1905 &d->dependentfiles)) {
1914 /*******************************************************************
1915 ********************************************************************/
1917 static bool driver_info6_to_nt_driver_info6(struct spoolss_AddDriverInfo6 *r,
1918 NT_PRINTER_DRIVER_INFO_LEVEL_6 **p)
1920 NT_PRINTER_DRIVER_INFO_LEVEL_6 *d;
1922 DEBUG(7,("driver_info6_to_nt_driver_info6: Converting from UNICODE to ASCII\n"));
1925 *p = SMB_MALLOC_P(NT_PRINTER_DRIVER_INFO_LEVEL_6);
1934 d->version = r->version;
1936 fstrcpy(d->name, r->driver_name);
1937 fstrcpy(d->environment, r->architecture);
1938 fstrcpy(d->driverpath, r->driver_path);
1939 fstrcpy(d->datafile, r->data_file);
1940 fstrcpy(d->configfile, r->config_file);
1941 fstrcpy(d->helpfile, r->help_file);
1942 fstrcpy(d->monitorname, r->monitor_name);
1943 fstrcpy(d->defaultdatatype, r->default_datatype);
1945 DEBUGADD(8,( "version: %d\n", d->version));
1946 DEBUGADD(8,( "name: %s\n", d->name));
1947 DEBUGADD(8,( "environment: %s\n", d->environment));
1948 DEBUGADD(8,( "driverpath: %s\n", d->driverpath));
1949 DEBUGADD(8,( "datafile: %s\n", d->datafile));
1950 DEBUGADD(8,( "configfile: %s\n", d->configfile));
1951 DEBUGADD(8,( "helpfile: %s\n", d->helpfile));
1952 DEBUGADD(8,( "monitorname: %s\n", d->monitorname));
1953 DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
1955 if (r->dependent_files) {
1956 if (!string_array_to_fstring_array(r->dependent_files->string,
1957 &d->dependentfiles)) {
1962 if (r->previous_names) {
1963 if (!string_array_to_fstring_array(r->previous_names->string,
1964 &d->previousnames)) {
1976 /********************************************************************
1977 ********************************************************************/
1979 static bool convert_printer_driver_info(const struct spoolss_AddDriverInfoCtr *r,
1980 NT_PRINTER_DRIVER_INFO_LEVEL *printer,
1985 printer->info_3 = NULL;
1986 if (!driver_info3_to_nt_driver_info3(r->info.info3, &printer->info_3)) {
1991 printer->info_6 = NULL;
1992 if (!driver_info6_to_nt_driver_info6(r->info.info6, &printer->info_6)) {
2003 /********************************************************************
2004 * _spoolss_enddocprinter_internal.
2005 ********************************************************************/
2007 static WERROR _spoolss_enddocprinter_internal(pipes_struct *p,
2008 struct policy_handle *handle)
2010 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
2014 DEBUG(2,("_spoolss_enddocprinter_internal: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle)));
2018 if (!get_printer_snum(p, handle, &snum, NULL))
2021 Printer->document_started = false;
2022 print_job_end(snum, Printer->jobid,NORMAL_CLOSE);
2023 /* error codes unhandled so far ... */
2028 /****************************************************************
2029 _spoolss_ClosePrinter
2030 ****************************************************************/
2032 WERROR _spoolss_ClosePrinter(pipes_struct *p,
2033 struct spoolss_ClosePrinter *r)
2035 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
2037 if (Printer && Printer->document_started)
2038 _spoolss_enddocprinter_internal(p, r->in.handle); /* print job was not closed */
2040 if (!close_printer_handle(p, r->in.handle))
2043 /* clear the returned printer handle. Observed behavior
2044 from Win2k server. Don't think this really matters.
2045 Previous code just copied the value of the closed
2048 ZERO_STRUCTP(r->out.handle);
2053 /****************************************************************
2054 _spoolss_DeletePrinter
2055 ****************************************************************/
2057 WERROR _spoolss_DeletePrinter(pipes_struct *p,
2058 struct spoolss_DeletePrinter *r)
2060 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
2063 if (Printer && Printer->document_started)
2064 _spoolss_enddocprinter_internal(p, r->in.handle); /* print job was not closed */
2066 result = delete_printer_handle(p, r->in.handle);
2068 update_c_setprinter(false);
2073 /*******************************************************************
2074 * static function to lookup the version id corresponding to an
2075 * long architecture string
2076 ******************************************************************/
2078 static int get_version_id(const char *arch)
2081 struct table_node archi_table[]= {
2083 {"Windows 4.0", "WIN40", 0 },
2084 {"Windows NT x86", "W32X86", 2 },
2085 {"Windows NT R4000", "W32MIPS", 2 },
2086 {"Windows NT Alpha_AXP", "W32ALPHA", 2 },
2087 {"Windows NT PowerPC", "W32PPC", 2 },
2088 {"Windows IA64", "IA64", 3 },
2089 {"Windows x64", "x64", 3 },
2093 for (i=0; archi_table[i].long_archi != NULL; i++)
2095 if (strcmp(arch, archi_table[i].long_archi) == 0)
2096 return (archi_table[i].version);
2102 /****************************************************************
2103 _spoolss_DeletePrinterDriver
2104 ****************************************************************/
2106 WERROR _spoolss_DeletePrinterDriver(pipes_struct *p,
2107 struct spoolss_DeletePrinterDriver *r)
2109 NT_PRINTER_DRIVER_INFO_LEVEL info;
2110 NT_PRINTER_DRIVER_INFO_LEVEL info_win2k;
2113 WERROR status_win2k = WERR_ACCESS_DENIED;
2114 SE_PRIV se_printop = SE_PRINT_OPERATOR;
2116 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2117 and not a printer admin, then fail */
2119 if ( (p->server_info->utok.uid != 0)
2120 && !user_has_privileges(p->server_info->ptok, &se_printop )
2121 && !token_contains_name_in_list(
2122 uidtoname(p->server_info->utok.uid), NULL,
2123 NULL, p->server_info->ptok,
2124 lp_printer_admin(-1)) )
2126 return WERR_ACCESS_DENIED;
2129 /* check that we have a valid driver name first */
2131 if ((version = get_version_id(r->in.architecture)) == -1)
2132 return WERR_INVALID_ENVIRONMENT;
2135 ZERO_STRUCT(info_win2k);
2137 if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, r->in.driver,
2141 /* try for Win2k driver if "Windows NT x86" */
2143 if ( version == 2 ) {
2145 if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3,
2149 status = WERR_UNKNOWN_PRINTER_DRIVER;
2153 /* otherwise it was a failure */
2155 status = WERR_UNKNOWN_PRINTER_DRIVER;
2161 if (printer_driver_in_use(info.info_3)) {
2162 status = WERR_PRINTER_DRIVER_IN_USE;
2168 if (W_ERROR_IS_OK(get_a_printer_driver(&info_win2k, 3,
2170 r->in.architecture, 3)))
2172 /* if we get to here, we now have 2 driver info structures to remove */
2173 /* remove the Win2k driver first*/
2175 status_win2k = delete_printer_driver(
2176 p, info_win2k.info_3, 3, false);
2177 free_a_printer_driver( info_win2k, 3 );
2179 /* this should not have failed---if it did, report to client */
2180 if ( !W_ERROR_IS_OK(status_win2k) )
2182 status = status_win2k;
2188 status = delete_printer_driver(p, info.info_3, version, false);
2190 /* if at least one of the deletes succeeded return OK */
2192 if ( W_ERROR_IS_OK(status) || W_ERROR_IS_OK(status_win2k) )
2196 free_a_printer_driver( info, 3 );
2201 /****************************************************************
2202 _spoolss_DeletePrinterDriverEx
2203 ****************************************************************/
2205 WERROR _spoolss_DeletePrinterDriverEx(pipes_struct *p,
2206 struct spoolss_DeletePrinterDriverEx *r)
2208 NT_PRINTER_DRIVER_INFO_LEVEL info;
2209 NT_PRINTER_DRIVER_INFO_LEVEL info_win2k;
2213 WERROR status_win2k = WERR_ACCESS_DENIED;
2214 SE_PRIV se_printop = SE_PRINT_OPERATOR;
2216 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2217 and not a printer admin, then fail */
2219 if ( (p->server_info->utok.uid != 0)
2220 && !user_has_privileges(p->server_info->ptok, &se_printop )
2221 && !token_contains_name_in_list(
2222 uidtoname(p->server_info->utok.uid), NULL, NULL,
2223 p->server_info->ptok, lp_printer_admin(-1)) )
2225 return WERR_ACCESS_DENIED;
2228 /* check that we have a valid driver name first */
2229 if ((version = get_version_id(r->in.architecture)) == -1) {
2230 /* this is what NT returns */
2231 return WERR_INVALID_ENVIRONMENT;
2234 if (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
2235 version = r->in.version;
2238 ZERO_STRUCT(info_win2k);
2240 status = get_a_printer_driver(&info, 3, r->in.driver,
2241 r->in.architecture, version);
2243 if ( !W_ERROR_IS_OK(status) )
2246 * if the client asked for a specific version,
2247 * or this is something other than Windows NT x86,
2251 if ( (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
2254 /* try for Win2k driver if "Windows NT x86" */
2257 if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, r->in.driver,
2260 status = WERR_UNKNOWN_PRINTER_DRIVER;
2265 if ( printer_driver_in_use(info.info_3) ) {
2266 status = WERR_PRINTER_DRIVER_IN_USE;
2271 * we have a couple of cases to consider.
2272 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
2273 * then the delete should fail if **any** files overlap with
2275 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
2276 * non-overlapping files
2277 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
2278 * is set, the do not delete any files
2279 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2282 delete_files = r->in.delete_flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
2284 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
2286 if ( delete_files && printer_driver_files_in_use(info.info_3) & (r->in.delete_flags & DPD_DELETE_ALL_FILES) ) {
2287 /* no idea of the correct error here */
2288 status = WERR_ACCESS_DENIED;
2293 /* also check for W32X86/3 if necessary; maybe we already have? */
2295 if ( (version == 2) && ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
2296 if (W_ERROR_IS_OK(get_a_printer_driver(&info_win2k, 3,
2298 r->in.architecture, 3)))
2301 if ( delete_files && printer_driver_files_in_use(info_win2k.info_3) & (r->in.delete_flags & DPD_DELETE_ALL_FILES) ) {
2302 /* no idea of the correct error here */
2303 free_a_printer_driver( info_win2k, 3 );
2304 status = WERR_ACCESS_DENIED;
2308 /* if we get to here, we now have 2 driver info structures to remove */
2309 /* remove the Win2k driver first*/
2311 status_win2k = delete_printer_driver(
2312 p, info_win2k.info_3, 3, delete_files);
2313 free_a_printer_driver( info_win2k, 3 );
2315 /* this should not have failed---if it did, report to client */
2317 if ( !W_ERROR_IS_OK(status_win2k) )
2322 status = delete_printer_driver(p, info.info_3, version, delete_files);
2324 if ( W_ERROR_IS_OK(status) || W_ERROR_IS_OK(status_win2k) )
2327 free_a_printer_driver( info, 3 );
2333 /****************************************************************************
2334 Internal routine for removing printerdata
2335 ***************************************************************************/
2337 static WERROR delete_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char *key, const char *value )
2339 return delete_printer_data( printer->info_2, key, value );
2342 /****************************************************************************
2343 Internal routine for storing printerdata
2344 ***************************************************************************/
2346 WERROR set_printer_dataex(NT_PRINTER_INFO_LEVEL *printer,
2347 const char *key, const char *value,
2348 uint32_t type, uint8_t *data, int real_len)
2350 /* the registry objects enforce uniqueness based on value name */
2352 return add_printer_data( printer->info_2, key, value, type, data, real_len );
2355 /********************************************************************
2356 GetPrinterData on a printer server Handle.
2357 ********************************************************************/
2359 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2361 enum winreg_Type *type,
2362 union spoolss_PrinterData *data)
2364 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2366 if (!StrCaseCmp(value, "W3SvcInstalled")) {
2372 if (!StrCaseCmp(value, "BeepEnabled")) {
2378 if (!StrCaseCmp(value, "EventLog")) {
2380 /* formally was 0x1b */
2385 if (!StrCaseCmp(value, "NetPopup")) {
2391 if (!StrCaseCmp(value, "MajorVersion")) {
2394 /* Windows NT 4.0 seems to not allow uploading of drivers
2395 to a server that reports 0x3 as the MajorVersion.
2396 need to investigate more how Win2k gets around this .
2399 if (RA_WINNT == get_remote_arch()) {
2408 if (!StrCaseCmp(value, "MinorVersion")) {
2415 * uint32_t size = 0x114
2416 * uint32_t major = 5
2417 * uint32_t minor = [0|1]
2418 * uint32_t build = [2195|2600]
2419 * extra unicode string = e.g. "Service Pack 3"
2421 if (!StrCaseCmp(value, "OSVersion")) {
2423 enum ndr_err_code ndr_err;
2424 struct spoolss_OSVersion os;
2426 os.major = 5; /* Windows 2000 == 5.0 */
2428 os.build = 2195; /* build */
2429 os.extra_string = ""; /* leave extra string empty */
2431 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, NULL, &os,
2432 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2433 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2434 return WERR_GENERAL_FAILURE;
2438 data->binary = blob;
2444 if (!StrCaseCmp(value, "DefaultSpoolDirectory")) {
2447 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2448 W_ERROR_HAVE_NO_MEMORY(data->string);
2453 if (!StrCaseCmp(value, "Architecture")) {
2456 data->string = talloc_strdup(mem_ctx, "Windows NT x86");
2457 W_ERROR_HAVE_NO_MEMORY(data->string);
2462 if (!StrCaseCmp(value, "DsPresent")) {
2465 /* only show the publish check box if we are a
2466 member of a AD domain */
2468 if (lp_security() == SEC_ADS) {
2476 if (!StrCaseCmp(value, "DNSMachineName")) {
2477 const char *hostname = get_mydnsfullname();
2480 return WERR_BADFILE;
2484 data->string = talloc_strdup(mem_ctx, hostname);
2485 W_ERROR_HAVE_NO_MEMORY(data->string);
2490 return WERR_INVALID_PARAM;
2493 /****************************************************************
2494 _spoolss_GetPrinterData
2495 ****************************************************************/
2497 WERROR _spoolss_GetPrinterData(pipes_struct *p,
2498 struct spoolss_GetPrinterData *r)
2501 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
2502 NT_PRINTER_INFO_LEVEL *printer = NULL;
2506 * Reminder: when it's a string, the length is in BYTES
2507 * even if UNICODE is negociated.
2512 /* in case of problem, return some default values */
2517 DEBUG(4,("_spoolss_GetPrinterData\n"));
2520 DEBUG(2,("_spoolss_GetPrinterData: Invalid handle (%s:%u:%u).\n",
2521 OUR_HANDLE(r->in.handle)));
2522 result = WERR_BADFID;
2526 if (Printer->printer_type == SPLHND_SERVER) {
2527 result = getprinterdata_printer_server(p->mem_ctx,
2532 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
2533 result = WERR_BADFID;
2537 result = get_a_printer(Printer, &printer, 2, lp_servicename(snum));
2538 if (!W_ERROR_IS_OK(result)) {
2542 /* XP sends this and wants to change id value from the PRINTER_INFO_0 */
2544 if (strequal(r->in.value_name, "ChangeId")) {
2545 *r->out.type = REG_DWORD;
2546 r->out.data->value = printer->info_2->changeid;
2552 v = get_printer_data(printer->info_2,
2553 SPOOL_PRINTERDATA_KEY,
2556 result = WERR_BADFILE;
2560 *r->out.type = v->type;
2562 blob = data_blob_const(v->data_p, v->size);
2564 result = pull_spoolss_PrinterData(p->mem_ctx, &blob,
2571 /* cleanup & exit */
2574 free_a_printer(&printer, 2);
2577 if (!W_ERROR_IS_OK(result)) {
2581 *r->out.needed = ndr_size_spoolss_PrinterData(r->out.data, *r->out.type, NULL, 0);
2582 *r->out.type = SPOOLSS_BUFFER_OK(*r->out.type, REG_NONE);
2583 r->out.data = SPOOLSS_BUFFER_OK(r->out.data, r->out.data);
2585 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
2588 /*********************************************************
2589 Connect to the client machine.
2590 **********************************************************/
2592 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2593 struct sockaddr_storage *client_ss, const char *remote_machine)
2596 struct cli_state *the_cli;
2597 struct sockaddr_storage rm_addr;
2599 if ( is_zero_addr((struct sockaddr *)client_ss) ) {
2600 if ( !resolve_name( remote_machine, &rm_addr, 0x20) ) {
2601 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2605 if (ismyaddr((struct sockaddr *)&rm_addr)) {
2606 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n", remote_machine));
2610 char addr[INET6_ADDRSTRLEN];
2611 rm_addr = *client_ss;
2612 print_sockaddr(addr, sizeof(addr), &rm_addr);
2613 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2617 /* setup the connection */
2619 ret = cli_full_connection( &the_cli, global_myname(), remote_machine,
2620 &rm_addr, 0, "IPC$", "IPC",
2624 0, lp_client_signing(), NULL );
2626 if ( !NT_STATUS_IS_OK( ret ) ) {
2627 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2632 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2633 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2634 cli_shutdown(the_cli);
2639 * Ok - we have an anonymous connection to the IPC$ share.
2640 * Now start the NT Domain stuff :-).
2643 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2644 if (!NT_STATUS_IS_OK(ret)) {
2645 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2646 remote_machine, nt_errstr(ret)));
2647 cli_shutdown(the_cli);
2654 /***************************************************************************
2655 Connect to the client.
2656 ****************************************************************************/
2658 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2659 uint32_t localprinter, uint32_t type,
2660 struct policy_handle *handle,
2661 struct sockaddr_storage *client_ss)
2667 * If it's the first connection, contact the client
2668 * and connect to the IPC$ share anonymously
2670 if (smb_connections==0) {
2671 fstring unix_printer;
2673 fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */
2675 if ( !spoolss_connect_to_client( ¬ify_cli_pipe, client_ss, unix_printer ))
2678 messaging_register(smbd_messaging_context(), NULL,
2679 MSG_PRINTER_NOTIFY2,
2680 receive_notify2_message_list);
2681 /* Tell the connections db we're now interested in printer
2682 * notify messages. */
2683 register_message_flags(true, FLAG_MSG_PRINT_NOTIFY);
2687 * Tell the specific printing tdb we want messages for this printer
2688 * by registering our PID.
2691 if (!print_notify_register_pid(snum))
2692 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", printer ));
2696 status = rpccli_spoolss_ReplyOpenPrinter(notify_cli_pipe, talloc_tos(),
2704 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
2705 DEBUG(5,("srv_spoolss_reply_open_printer: Client RPC returned [%s]\n",
2706 win_errstr(result)));
2708 return (W_ERROR_IS_OK(result));
2711 /****************************************************************
2712 ****************************************************************/
2714 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2715 const struct spoolss_NotifyOption *r)
2717 struct spoolss_NotifyOption *option;
2724 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2731 if (!option->count) {
2735 option->types = talloc_zero_array(option,
2736 struct spoolss_NotifyOptionType, option->count);
2737 if (!option->types) {
2738 talloc_free(option);
2742 for (i=0; i < option->count; i++) {
2743 option->types[i] = r->types[i];
2745 if (option->types[i].count) {
2746 option->types[i].fields = talloc_zero_array(option,
2747 union spoolss_Field, option->types[i].count);
2748 if (!option->types[i].fields) {
2749 talloc_free(option);
2752 for (k=0; k<option->types[i].count; k++) {
2753 option->types[i].fields[k] =
2754 r->types[i].fields[k];
2762 /****************************************************************
2763 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2765 * before replying OK: status=0 a rpc call is made to the workstation
2766 * asking ReplyOpenPrinter
2768 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2769 * called from api_spoolss_rffpcnex
2770 ****************************************************************/
2772 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(pipes_struct *p,
2773 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2776 struct spoolss_NotifyOption *option = r->in.notify_options;
2777 struct sockaddr_storage client_ss;
2779 /* store the notify value in the printer struct */
2781 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
2784 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2785 "Invalid handle (%s:%u:%u).\n",
2786 OUR_HANDLE(r->in.handle)));
2790 Printer->notify.flags = r->in.flags;
2791 Printer->notify.options = r->in.options;
2792 Printer->notify.printerlocal = r->in.printer_local;
2794 TALLOC_FREE(Printer->notify.option);
2795 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2797 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2799 /* Connect to the client machine and send a ReplyOpenPrinter */
2801 if ( Printer->printer_type == SPLHND_SERVER)
2803 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2804 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2807 if (!interpret_string_addr(&client_ss, p->client_address,
2809 return WERR_SERVER_UNAVAILABLE;
2812 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2813 Printer->notify.printerlocal, 1,
2814 &Printer->notify.client_hnd, &client_ss))
2815 return WERR_SERVER_UNAVAILABLE;
2817 Printer->notify.client_connected = true;
2822 /*******************************************************************
2823 * fill a notify_info_data with the servername
2824 ********************************************************************/
2826 void spoolss_notify_server_name(int snum,
2827 struct spoolss_Notify *data,
2828 print_queue_struct *queue,
2829 NT_PRINTER_INFO_LEVEL *printer,
2830 TALLOC_CTX *mem_ctx)
2832 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->servername);
2835 /*******************************************************************
2836 * fill a notify_info_data with the printername (not including the servername).
2837 ********************************************************************/
2839 void spoolss_notify_printer_name(int snum,
2840 struct spoolss_Notify *data,
2841 print_queue_struct *queue,
2842 NT_PRINTER_INFO_LEVEL *printer,
2843 TALLOC_CTX *mem_ctx)
2845 /* the notify name should not contain the \\server\ part */
2846 char *p = strrchr(printer->info_2->printername, '\\');
2849 p = printer->info_2->printername;
2854 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2857 /*******************************************************************
2858 * fill a notify_info_data with the servicename
2859 ********************************************************************/
2861 void spoolss_notify_share_name(int snum,
2862 struct spoolss_Notify *data,
2863 print_queue_struct *queue,
2864 NT_PRINTER_INFO_LEVEL *printer,
2865 TALLOC_CTX *mem_ctx)
2867 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
2870 /*******************************************************************
2871 * fill a notify_info_data with the port name
2872 ********************************************************************/
2874 void spoolss_notify_port_name(int snum,
2875 struct spoolss_Notify *data,
2876 print_queue_struct *queue,
2877 NT_PRINTER_INFO_LEVEL *printer,
2878 TALLOC_CTX *mem_ctx)
2880 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->portname);
2883 /*******************************************************************
2884 * fill a notify_info_data with the printername
2885 * but it doesn't exist, have to see what to do
2886 ********************************************************************/
2888 void spoolss_notify_driver_name(int snum,
2889 struct spoolss_Notify *data,
2890 print_queue_struct *queue,
2891 NT_PRINTER_INFO_LEVEL *printer,
2892 TALLOC_CTX *mem_ctx)
2894 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->drivername);
2897 /*******************************************************************
2898 * fill a notify_info_data with the comment
2899 ********************************************************************/
2901 void spoolss_notify_comment(int snum,
2902 struct spoolss_Notify *data,
2903 print_queue_struct *queue,
2904 NT_PRINTER_INFO_LEVEL *printer,
2905 TALLOC_CTX *mem_ctx)
2909 if (*printer->info_2->comment == '\0') {
2910 p = lp_comment(snum);
2912 p = printer->info_2->comment;
2915 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->comment);
2918 /*******************************************************************
2919 * fill a notify_info_data with the comment
2920 * location = "Room 1, floor 2, building 3"
2921 ********************************************************************/
2923 void spoolss_notify_location(int snum,
2924 struct spoolss_Notify *data,
2925 print_queue_struct *queue,
2926 NT_PRINTER_INFO_LEVEL *printer,
2927 TALLOC_CTX *mem_ctx)
2929 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->location);
2932 /*******************************************************************
2933 * fill a notify_info_data with the device mode
2934 * jfm:xxxx don't to it for know but that's a real problem !!!
2935 ********************************************************************/
2937 static void spoolss_notify_devmode(int snum,
2938 struct spoolss_Notify *data,
2939 print_queue_struct *queue,
2940 NT_PRINTER_INFO_LEVEL *printer,
2941 TALLOC_CTX *mem_ctx)
2943 /* for a dummy implementation we have to zero the fields */
2944 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2947 /*******************************************************************
2948 * fill a notify_info_data with the separator file name
2949 ********************************************************************/
2951 void spoolss_notify_sepfile(int snum,
2952 struct spoolss_Notify *data,
2953 print_queue_struct *queue,
2954 NT_PRINTER_INFO_LEVEL *printer,
2955 TALLOC_CTX *mem_ctx)
2957 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->sepfile);
2960 /*******************************************************************
2961 * fill a notify_info_data with the print processor
2962 * jfm:xxxx return always winprint to indicate we don't do anything to it
2963 ********************************************************************/
2965 void spoolss_notify_print_processor(int snum,
2966 struct spoolss_Notify *data,
2967 print_queue_struct *queue,
2968 NT_PRINTER_INFO_LEVEL *printer,
2969 TALLOC_CTX *mem_ctx)
2971 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->printprocessor);
2974 /*******************************************************************
2975 * fill a notify_info_data with the print processor options
2976 * jfm:xxxx send an empty string
2977 ********************************************************************/
2979 void spoolss_notify_parameters(int snum,
2980 struct spoolss_Notify *data,
2981 print_queue_struct *queue,
2982 NT_PRINTER_INFO_LEVEL *printer,
2983 TALLOC_CTX *mem_ctx)
2985 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->parameters);
2988 /*******************************************************************
2989 * fill a notify_info_data with the data type
2990 * jfm:xxxx always send RAW as data type
2991 ********************************************************************/
2993 void spoolss_notify_datatype(int snum,
2994 struct spoolss_Notify *data,
2995 print_queue_struct *queue,
2996 NT_PRINTER_INFO_LEVEL *printer,
2997 TALLOC_CTX *mem_ctx)
2999 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->datatype);
3002 /*******************************************************************
3003 * fill a notify_info_data with the security descriptor
3004 * jfm:xxxx send an null pointer to say no security desc
3005 * have to implement security before !
3006 ********************************************************************/
3008 static void spoolss_notify_security_desc(int snum,
3009 struct spoolss_Notify *data,
3010 print_queue_struct *queue,
3011 NT_PRINTER_INFO_LEVEL *printer,
3012 TALLOC_CTX *mem_ctx)
3014 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data,
3015 printer->info_2->secdesc_buf->sd_size,
3016 printer->info_2->secdesc_buf->sd);
3019 /*******************************************************************
3020 * fill a notify_info_data with the attributes
3021 * jfm:xxxx a samba printer is always shared
3022 ********************************************************************/
3024 void spoolss_notify_attributes(int snum,
3025 struct spoolss_Notify *data,
3026 print_queue_struct *queue,
3027 NT_PRINTER_INFO_LEVEL *printer,
3028 TALLOC_CTX *mem_ctx)
3030 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->attributes);
3033 /*******************************************************************
3034 * fill a notify_info_data with the priority
3035 ********************************************************************/
3037 static void spoolss_notify_priority(int snum,
3038 struct spoolss_Notify *data,
3039 print_queue_struct *queue,
3040 NT_PRINTER_INFO_LEVEL *printer,
3041 TALLOC_CTX *mem_ctx)
3043 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->priority);
3046 /*******************************************************************
3047 * fill a notify_info_data with the default priority
3048 ********************************************************************/
3050 static void spoolss_notify_default_priority(int snum,
3051 struct spoolss_Notify *data,
3052 print_queue_struct *queue,
3053 NT_PRINTER_INFO_LEVEL *printer,
3054 TALLOC_CTX *mem_ctx)
3056 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->default_priority);
3059 /*******************************************************************
3060 * fill a notify_info_data with the start time
3061 ********************************************************************/
3063 static void spoolss_notify_start_time(int snum,
3064 struct spoolss_Notify *data,
3065 print_queue_struct *queue,
3066 NT_PRINTER_INFO_LEVEL *printer,
3067 TALLOC_CTX *mem_ctx)
3069 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->starttime);
3072 /*******************************************************************
3073 * fill a notify_info_data with the until time
3074 ********************************************************************/
3076 static void spoolss_notify_until_time(int snum,
3077 struct spoolss_Notify *data,
3078 print_queue_struct *queue,
3079 NT_PRINTER_INFO_LEVEL *printer,
3080 TALLOC_CTX *mem_ctx)
3082 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->untiltime);
3085 /*******************************************************************
3086 * fill a notify_info_data with the status
3087 ********************************************************************/
3089 static void spoolss_notify_status(int snum,
3090 struct spoolss_Notify *data,
3091 print_queue_struct *queue,
3092 NT_PRINTER_INFO_LEVEL *printer,
3093 TALLOC_CTX *mem_ctx)
3095 print_status_struct status;
3097 print_queue_length(snum, &status);
3098 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
3101 /*******************************************************************
3102 * fill a notify_info_data with the number of jobs queued
3103 ********************************************************************/
3105 void spoolss_notify_cjobs(int snum,
3106 struct spoolss_Notify *data,
3107 print_queue_struct *queue,
3108 NT_PRINTER_INFO_LEVEL *printer,
3109 TALLOC_CTX *mem_ctx)
3111 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, print_queue_length(snum, NULL));
3114 /*******************************************************************
3115 * fill a notify_info_data with the average ppm
3116 ********************************************************************/
3118 static void spoolss_notify_average_ppm(int snum,
3119 struct spoolss_Notify *data,
3120 print_queue_struct *queue,
3121 NT_PRINTER_INFO_LEVEL *printer,
3122 TALLOC_CTX *mem_ctx)
3124 /* always respond 8 pages per minutes */
3125 /* a little hard ! */
3126 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->averageppm);
3129 /*******************************************************************
3130 * fill a notify_info_data with username
3131 ********************************************************************/
3133 static void spoolss_notify_username(int snum,
3134 struct spoolss_Notify *data,
3135 print_queue_struct *queue,
3136 NT_PRINTER_INFO_LEVEL *printer,
3137 TALLOC_CTX *mem_ctx)
3139 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
3142 /*******************************************************************
3143 * fill a notify_info_data with job status
3144 ********************************************************************/
3146 static void spoolss_notify_job_status(int snum,
3147 struct spoolss_Notify *data,
3148 print_queue_struct *queue,
3149 NT_PRINTER_INFO_LEVEL *printer,
3150 TALLOC_CTX *mem_ctx)
3152 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
3155 /*******************************************************************
3156 * fill a notify_info_data with job name
3157 ********************************************************************/
3159 static void spoolss_notify_job_name(int snum,
3160 struct spoolss_Notify *data,
3161 print_queue_struct *queue,
3162 NT_PRINTER_INFO_LEVEL *printer,
3163 TALLOC_CTX *mem_ctx)
3165 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
3168 /*******************************************************************
3169 * fill a notify_info_data with job status
3170 ********************************************************************/
3172 static void spoolss_notify_job_status_string(int snum,
3173 struct spoolss_Notify *data,
3174 print_queue_struct *queue,
3175 NT_PRINTER_INFO_LEVEL *printer,
3176 TALLOC_CTX *mem_ctx)
3179 * Now we're returning job status codes we just return a "" here. JRA.
3184 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3187 switch (queue->status) {
3192 p = ""; /* NT provides the paused string */
3201 #endif /* NO LONGER NEEDED. */
3203 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
3206 /*******************************************************************
3207 * fill a notify_info_data with job time
3208 ********************************************************************/
3210 static void spoolss_notify_job_time(int snum,
3211 struct spoolss_Notify *data,
3212 print_queue_struct *queue,
3213 NT_PRINTER_INFO_LEVEL *printer,
3214 TALLOC_CTX *mem_ctx)
3216 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3219 /*******************************************************************
3220 * fill a notify_info_data with job size
3221 ********************************************************************/
3223 static void spoolss_notify_job_size(int snum,
3224 struct spoolss_Notify *data,
3225 print_queue_struct *queue,
3226 NT_PRINTER_INFO_LEVEL *printer,
3227 TALLOC_CTX *mem_ctx)
3229 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
3232 /*******************************************************************
3233 * fill a notify_info_data with page info
3234 ********************************************************************/
3235 static void spoolss_notify_total_pages(int snum,
3236 struct spoolss_Notify *data,
3237 print_queue_struct *queue,
3238 NT_PRINTER_INFO_LEVEL *printer,
3239 TALLOC_CTX *mem_ctx)
3241 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
3244 /*******************************************************************
3245 * fill a notify_info_data with pages printed info.
3246 ********************************************************************/
3247 static void spoolss_notify_pages_printed(int snum,
3248 struct spoolss_Notify *data,
3249 print_queue_struct *queue,
3250 NT_PRINTER_INFO_LEVEL *printer,
3251 TALLOC_CTX *mem_ctx)
3253 /* Add code when back-end tracks this */
3254 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3257 /*******************************************************************
3258 Fill a notify_info_data with job position.
3259 ********************************************************************/
3261 static void spoolss_notify_job_position(int snum,
3262 struct spoolss_Notify *data,
3263 print_queue_struct *queue,
3264 NT_PRINTER_INFO_LEVEL *printer,
3265 TALLOC_CTX *mem_ctx)
3267 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
3270 /*******************************************************************
3271 Fill a notify_info_data with submitted time.
3272 ********************************************************************/
3274 static void spoolss_notify_submitted_time(int snum,
3275 struct spoolss_Notify *data,
3276 print_queue_struct *queue,
3277 NT_PRINTER_INFO_LEVEL *printer,
3278 TALLOC_CTX *mem_ctx)
3280 data->data.string.string = NULL;
3281 data->data.string.size = 0;
3283 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
3284 &data->data.string.string,
3285 &data->data.string.size);
3289 struct s_notify_info_data_table
3291 enum spoolss_NotifyType type;
3294 enum spoolss_NotifyTable variable_type;
3295 void (*fn) (int snum, struct spoolss_Notify *data,
3296 print_queue_struct *queue,
3297 NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx);
3300 /* A table describing the various print notification constants and
3301 whether the notification data is a pointer to a variable sized
3302 buffer, a one value uint32_t or a two value uint32_t. */
3304 static const struct s_notify_info_data_table notify_info_data_table[] =
3306 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3307 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3308 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
3309 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3310 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3311 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
3312 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
3313 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3314 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
3315 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3316 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3317 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3318 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
3319 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
3320 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3321 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
3322 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3323 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3324 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
3325 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
3326 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
3327 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
3328 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
3329 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3330 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
3331 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3332 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3333 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3334 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3335 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3336 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3337 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3338 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3339 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3340 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3341 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3342 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
3343 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
3344 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
3345 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
3346 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3347 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
3348 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
3349 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3350 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3351 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
3352 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
3353 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
3354 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
3357 /*******************************************************************
3358 Return the variable_type of info_data structure.
3359 ********************************************************************/
3361 static uint32_t variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3366 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3367 if ( (notify_info_data_table[i].type == type) &&
3368 (notify_info_data_table[i].field == field) ) {
3369 return notify_info_data_table[i].variable_type;
3373 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3378 /****************************************************************************
3379 ****************************************************************************/
3381 static bool search_notify(enum spoolss_NotifyType type,
3387 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3388 if (notify_info_data_table[i].type == type &&
3389 notify_info_data_table[i].field == field &&
3390 notify_info_data_table[i].fn != NULL) {
3399 /****************************************************************************
3400 ****************************************************************************/
3402 void construct_info_data(struct spoolss_Notify *info_data,
3403 enum spoolss_NotifyType type,
3407 info_data->type = type;
3408 info_data->field.field = field;
3409 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3410 info_data->job_id = id;
3413 /*******************************************************************
3415 * fill a notify_info struct with info asked
3417 ********************************************************************/
3419 static bool construct_notify_printer_info(Printer_entry *print_hnd,
3420 struct spoolss_NotifyInfo *info,
3422 const struct spoolss_NotifyOptionType *option_type,
3424 TALLOC_CTX *mem_ctx)
3427 enum spoolss_NotifyType type;
3430 struct spoolss_Notify *current_data;
3431 NT_PRINTER_INFO_LEVEL *printer = NULL;
3432 print_queue_struct *queue=NULL;
3434 type = option_type->type;
3436 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3437 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3438 option_type->count, lp_servicename(snum)));
3440 if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &printer, 2, lp_const_servicename(snum))))
3443 for(field_num=0; field_num < option_type->count; field_num++) {
3444 field = option_type->fields[field_num].field;
3446 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3448 if (!search_notify(type, field, &j) )
3451 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3452 struct spoolss_Notify,
3454 if (info->notifies == NULL) {
3455 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3456 free_a_printer(&printer, 2);
3460 current_data = &info->notifies[info->count];
3462 construct_info_data(current_data, type, field, id);
3464 DEBUG(10,("construct_notify_printer_info: calling [%s] snum=%d printername=[%s])\n",
3465 notify_info_data_table[j].name, snum, printer->info_2->printername ));
3467 notify_info_data_table[j].fn(snum, current_data, queue,
3473 free_a_printer(&printer, 2);
3477 /*******************************************************************
3479 * fill a notify_info struct with info asked
3481 ********************************************************************/
3483 static bool construct_notify_jobs_info(print_queue_struct *queue,
3484 struct spoolss_NotifyInfo *info,
3485 NT_PRINTER_INFO_LEVEL *printer,
3487 const struct spoolss_NotifyOptionType *option_type,
3489 TALLOC_CTX *mem_ctx)
3492 enum spoolss_NotifyType type;
3494 struct spoolss_Notify *current_data;
3496 DEBUG(4,("construct_notify_jobs_info\n"));
3498 type = option_type->type;
3500 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3501 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3502 option_type->count));
3504 for(field_num=0; field_num<option_type->count; field_num++) {
3505 field = option_type->fields[field_num].field;
3507 if (!search_notify(type, field, &j) )
3510 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3511 struct spoolss_Notify,
3513 if (info->notifies == NULL) {
3514 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3518 current_data=&(info->notifies[info->count]);
3520 construct_info_data(current_data, type, field, id);
3521 notify_info_data_table[j].fn(snum, current_data, queue,
3530 * JFM: The enumeration is not that simple, it's even non obvious.
3532 * let's take an example: I want to monitor the PRINTER SERVER for
3533 * the printer's name and the number of jobs currently queued.
3534 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3535 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3537 * I have 3 printers on the back of my server.
3539 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3542 * 1 printer 1 name 1
3543 * 2 printer 1 cjob 1
3544 * 3 printer 2 name 2
3545 * 4 printer 2 cjob 2
3546 * 5 printer 3 name 3
3547 * 6 printer 3 name 3
3549 * that's the print server case, the printer case is even worse.
3552 /*******************************************************************
3554 * enumerate all printers on the printserver
3555 * fill a notify_info struct with info asked
3557 ********************************************************************/
3559 static WERROR printserver_notify_info(pipes_struct *p,
3560 struct policy_handle *hnd,
3561 struct spoolss_NotifyInfo *info,
3562 TALLOC_CTX *mem_ctx)
3565 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3566 int n_services=lp_numservices();
3568 struct spoolss_NotifyOption *option;
3569 struct spoolss_NotifyOptionType option_type;
3571 DEBUG(4,("printserver_notify_info\n"));
3576 option = Printer->notify.option;
3579 info->notifies = NULL;
3582 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3583 sending a ffpcn() request first */
3588 for (i=0; i<option->count; i++) {
3589 option_type = option->types[i];
3591 if (option_type.type != PRINTER_NOTIFY_TYPE)
3594 for (snum=0; snum<n_services; snum++)
3596 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
3597 construct_notify_printer_info ( Printer, info, snum, &option_type, snum, mem_ctx );
3603 * Debugging information, don't delete.
3606 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3607 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3608 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3610 for (i=0; i<info->count; i++) {
3611 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3612 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3613 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3620 /*******************************************************************
3622 * fill a notify_info struct with info asked
3624 ********************************************************************/
3626 static WERROR printer_notify_info(pipes_struct *p, struct policy_handle *hnd,
3627 struct spoolss_NotifyInfo *info,
3628 TALLOC_CTX *mem_ctx)
3631 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3634 struct spoolss_NotifyOption *option;
3635 struct spoolss_NotifyOptionType option_type;
3637 print_queue_struct *queue=NULL;
3638 print_status_struct status;
3640 DEBUG(4,("printer_notify_info\n"));
3645 option = Printer->notify.option;
3649 info->notifies = NULL;
3652 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3653 sending a ffpcn() request first */
3658 get_printer_snum(p, hnd, &snum, NULL);
3660 for (i=0; i<option->count; i++) {
3661 option_type = option->types[i];
3663 switch (option_type.type) {
3664 case PRINTER_NOTIFY_TYPE:
3665 if(construct_notify_printer_info(Printer, info, snum,
3671 case JOB_NOTIFY_TYPE: {
3672 NT_PRINTER_INFO_LEVEL *printer = NULL;
3674 count = print_queue_status(snum, &queue, &status);
3676 if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum))))
3679 for (j=0; j<count; j++) {
3680 construct_notify_jobs_info(&queue[j], info,
3687 free_a_printer(&printer, 2);
3697 * Debugging information, don't delete.
3700 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3701 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3702 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3704 for (i=0; i<info->count; i++) {
3705 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3706 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3707 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3713 /****************************************************************
3714 _spoolss_RouterRefreshPrinterChangeNotify
3715 ****************************************************************/
3717 WERROR _spoolss_RouterRefreshPrinterChangeNotify(pipes_struct *p,
3718 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3720 struct spoolss_NotifyInfo *info;
3722 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
3723 WERROR result = WERR_BADFID;
3725 /* we always have a spoolss_NotifyInfo struct */
3726 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3728 result = WERR_NOMEM;
3732 *r->out.info = info;
3735 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3736 "Invalid handle (%s:%u:%u).\n",
3737 OUR_HANDLE(r->in.handle)));
3741 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3744 * We are now using the change value, and
3745 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3746 * I don't have a global notification system, I'm sending back all the
3747 * informations even when _NOTHING_ has changed.
3750 /* We need to keep track of the change value to send back in
3751 RRPCN replies otherwise our updates are ignored. */
3753 Printer->notify.fnpcn = true;
3755 if (Printer->notify.client_connected) {
3756 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3757 "Saving change value in request [%x]\n",
3759 Printer->notify.change = r->in.change_low;
3762 /* just ignore the spoolss_NotifyOption */
3764 switch (Printer->printer_type) {
3766 result = printserver_notify_info(p, r->in.handle,
3770 case SPLHND_PRINTER:
3771 result = printer_notify_info(p, r->in.handle,
3776 Printer->notify.fnpcn = false;
3782 /********************************************************************
3783 * construct_printer_info_0
3784 * fill a printer_info_0 struct
3785 ********************************************************************/
3787 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3788 const NT_PRINTER_INFO_LEVEL *ntprinter,
3789 struct spoolss_PrinterInfo0 *r,
3793 counter_printer_0 *session_counter;
3795 print_status_struct status;
3797 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
3798 W_ERROR_HAVE_NO_MEMORY(r->printername);
3800 r->servername = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
3801 W_ERROR_HAVE_NO_MEMORY(r->servername);
3803 count = print_queue_length(snum, &status);
3805 /* check if we already have a counter for this printer */
3806 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3807 if (session_counter->snum == snum)
3811 /* it's the first time, add it to the list */
3812 if (session_counter == NULL) {
3813 session_counter = SMB_MALLOC_P(counter_printer_0);
3814 W_ERROR_HAVE_NO_MEMORY(session_counter);
3815 ZERO_STRUCTP(session_counter);
3816 session_counter->snum = snum;
3817 session_counter->counter = 0;
3818 DLIST_ADD(counter_list, session_counter);
3822 session_counter->counter++;
3828 setuptime = (time_t)ntprinter->info_2->setuptime;
3830 init_systemtime(&r->time, gmtime(&setuptime));
3833 * the global_counter should be stored in a TDB as it's common to all the clients
3834 * and should be zeroed on samba startup
3836 r->global_counter = session_counter->counter;
3838 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3839 r->version = 0x0005; /* NT 5 */
3840 r->free_build = 0x0893; /* build 2195 */
3842 r->max_spooling = 0;
3843 r->session_counter = session_counter->counter;
3844 r->num_error_out_of_paper = 0x0;
3845 r->num_error_not_ready = 0x0; /* number of print failure */
3847 r->number_of_processors = 0x1;
3848 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3849 r->high_part_total_bytes = 0x0;
3850 r->change_id = ntprinter->info_2->changeid; /* ChangeID in milliseconds*/
3851 r->last_error = WERR_OK;
3852 r->status = nt_printq_status(status.status);
3853 r->enumerate_network_printers = 0x0;
3854 r->c_setprinter = get_c_setprinter(); /* monotonically increasing sum of delta printer counts */
3855 r->processor_architecture = 0x0;
3856 r->processor_level = 0x6; /* 6 ???*/
3864 /****************************************************************************
3865 Convert an NT_DEVICEMODE to a spoolss_DeviceMode structure. Both pointers
3866 should be valid upon entry
3867 ****************************************************************************/
3869 static WERROR convert_nt_devicemode(TALLOC_CTX *mem_ctx,
3870 struct spoolss_DeviceMode *r,
3871 const NT_DEVICEMODE *ntdevmode)
3873 if (!r || !ntdevmode) {
3874 return WERR_INVALID_PARAM;
3877 r->devicename = talloc_strdup(mem_ctx, ntdevmode->devicename);
3878 W_ERROR_HAVE_NO_MEMORY(r->devicename);
3880 r->specversion = ntdevmode->specversion;
3881 r->driverversion = ntdevmode->driverversion;
3882 r->size = ntdevmode->size;
3883 r->__driverextra_length = ntdevmode->driverextra;
3884 r->fields = ntdevmode->fields;
3886 r->orientation = ntdevmode->orientation;
3887 r->papersize = ntdevmode->papersize;
3888 r->paperlength = ntdevmode->paperlength;
3889 r->paperwidth = ntdevmode->paperwidth;
3890 r->scale = ntdevmode->scale;
3891 r->copies = ntdevmode->copies;
3892 r->defaultsource = ntdevmode->defaultsource;
3893 r->printquality = ntdevmode->printquality;
3894 r->color = ntdevmode->color;
3895 r->duplex = ntdevmode->duplex;
3896 r->yresolution = ntdevmode->yresolution;
3897 r->ttoption = ntdevmode->ttoption;
3898 r->collate = ntdevmode->collate;
3900 r->formname = talloc_strdup(mem_ctx, ntdevmode->formname);
3901 W_ERROR_HAVE_NO_MEMORY(r->formname);
3903 /* all 0 below are values that have not been set in the old parsing/copy
3904 * function, maybe they should... - gd */
3910 r->displayflags = 0;
3911 r->displayfrequency = 0;
3912 r->icmmethod = ntdevmode->icmmethod;
3913 r->icmintent = ntdevmode->icmintent;
3914 r->mediatype = ntdevmode->mediatype;
3915 r->dithertype = ntdevmode->dithertype;
3918 r->panningwidth = 0;
3919 r->panningheight = 0;
3921 if (ntdevmode->nt_dev_private != NULL) {
3922 r->driverextra_data = data_blob_talloc(mem_ctx,
3923 ntdevmode->nt_dev_private,
3924 ntdevmode->driverextra);
3925 W_ERROR_HAVE_NO_MEMORY(r->driverextra_data.data);
3932 /****************************************************************************
3933 Create a spoolss_DeviceMode struct. Returns talloced memory.
3934 ****************************************************************************/
3936 struct spoolss_DeviceMode *construct_dev_mode(TALLOC_CTX *mem_ctx,
3937 const char *servicename)
3940 NT_PRINTER_INFO_LEVEL *printer = NULL;
3941 struct spoolss_DeviceMode *devmode = NULL;
3943 DEBUG(7,("construct_dev_mode\n"));
3945 DEBUGADD(8,("getting printer characteristics\n"));
3947 if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, servicename)))
3950 if (!printer->info_2->devmode) {
3951 DEBUG(5, ("BONG! There was no device mode!\n"));
3955 devmode = TALLOC_ZERO_P(mem_ctx, struct spoolss_DeviceMode);
3957 DEBUG(2,("construct_dev_mode: talloc fail.\n"));
3961 DEBUGADD(8,("loading DEVICEMODE\n"));
3963 result = convert_nt_devicemode(mem_ctx, devmode, printer->info_2->devmode);
3964 if (!W_ERROR_IS_OK(result)) {
3965 TALLOC_FREE(devmode);
3969 free_a_printer(&printer,2);
3974 /********************************************************************
3975 * construct_printer_info3
3976 * fill a spoolss_PrinterInfo3 struct
3977 ********************************************************************/
3979 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
3980 const NT_PRINTER_INFO_LEVEL *ntprinter,
3981 struct spoolss_PrinterInfo3 *r,
3984 /* These are the components of the SD we are returning. */
3986 if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->sd_size != 0) {
3987 /* don't use talloc_steal() here unless you do a deep steal of all
3988 the SEC_DESC members */
3990 r->secdesc = dup_sec_desc(mem_ctx,
3991 ntprinter->info_2->secdesc_buf->sd);
3992 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
3998 /********************************************************************
3999 * construct_printer_info4
4000 * fill a spoolss_PrinterInfo4 struct
4001 ********************************************************************/
4003 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
4004 const NT_PRINTER_INFO_LEVEL *ntprinter,
4005 struct spoolss_PrinterInfo4 *r,
4008 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
4009 W_ERROR_HAVE_NO_MEMORY(r->printername);
4010 r->servername = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
4011 W_ERROR_HAVE_NO_MEMORY(r->servername);
4013 r->attributes = ntprinter->info_2->attributes;
4018 /********************************************************************
4019 * construct_printer_info5
4020 * fill a spoolss_PrinterInfo5 struct
4021 ********************************************************************/
4023 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
4024 const NT_PRINTER_INFO_LEVEL *ntprinter,
4025 struct spoolss_PrinterInfo5 *r,
4028 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
4029 W_ERROR_HAVE_NO_MEMORY(r->printername);
4030 r->portname = talloc_strdup(mem_ctx, ntprinter->info_2->portname);
4031 W_ERROR_HAVE_NO_MEMORY(r->portname);
4033 r->attributes = ntprinter->info_2->attributes;
4035 /* these two are not used by NT+ according to MSDN */
4037 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
4038 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
4043 /********************************************************************
4044 * construct_printer_info_6
4045 * fill a spoolss_PrinterInfo6 struct
4046 ********************************************************************/
4048 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
4049 const NT_PRINTER_INFO_LEVEL *ntprinter,
4050 struct spoolss_PrinterInfo6 *r,
4054 print_status_struct status;
4056 count = print_queue_length(snum, &status);
4058 r->status = nt_printq_status(status.status);
4063 /********************************************************************
4064 * construct_printer_info7
4065 * fill a spoolss_PrinterInfo7 struct
4066 ********************************************************************/
4068 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
4069 Printer_entry *print_hnd,
4070 struct spoolss_PrinterInfo7 *r,
4075 if (is_printer_published(print_hnd, snum, &guid)) {
4076 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
4077 r->action = DSPRINT_PUBLISH;
4079 r->guid = talloc_strdup(mem_ctx, "");
4080 r->action = DSPRINT_UNPUBLISH;
4082 W_ERROR_HAVE_NO_MEMORY(r->guid);
4087 /********************************************************************
4088 * construct_printer_info8
4089 * fill a spoolss_PrinterInfo8 struct
4090 ********************************************************************/
4092 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
4093 const NT_PRINTER_INFO_LEVEL *ntprinter,
4094 struct spoolss_DeviceModeInfo *r,
4097 struct spoolss_DeviceMode *devmode;
4100 if (!ntprinter->info_2->devmode) {
4105 devmode = TALLOC_ZERO_P(mem_ctx, struct spoolss_DeviceMode);
4106 W_ERROR_HAVE_NO_MEMORY(devmode);
4108 result = convert_nt_devicemode(mem_ctx, devmode, ntprinter->info_2->devmode);
4109 if (!W_ERROR_IS_OK(result)) {
4110 TALLOC_FREE(devmode);
4114 r->devmode = devmode;
4120 /********************************************************************
4121 * construct_printer_info1
4122 * fill a spoolss_PrinterInfo1 struct
4123 ********************************************************************/
4125 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
4126 const NT_PRINTER_INFO_LEVEL *ntprinter,
4128 struct spoolss_PrinterInfo1 *r,
4133 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
4134 ntprinter->info_2->printername,
4135 ntprinter->info_2->drivername,
4136 ntprinter->info_2->location);
4137 W_ERROR_HAVE_NO_MEMORY(r->description);
4139 if (*ntprinter->info_2->comment == '\0') {
4140 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
4142 r->comment = talloc_strdup(mem_ctx, ntprinter->info_2->comment); /* saved comment */
4144 W_ERROR_HAVE_NO_MEMORY(r->comment);
4146 r->name = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
4147 W_ERROR_HAVE_NO_MEMORY(r->name);
4152 /********************************************************************
4153 * construct_printer_info2
4154 * fill a spoolss_PrinterInfo2 struct
4155 ********************************************************************/
4157 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
4158 const NT_PRINTER_INFO_LEVEL *ntprinter,
4159 struct spoolss_PrinterInfo2 *r,
4164 print_status_struct status;
4166 count = print_queue_length(snum, &status);
4168 r->servername = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
4169 W_ERROR_HAVE_NO_MEMORY(r->servername);
4170 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
4171 W_ERROR_HAVE_NO_MEMORY(r->printername);
4172 r->sharename = talloc_strdup(mem_ctx, lp_servicename(snum));
4173 W_ERROR_HAVE_NO_MEMORY(r->sharename);
4174 r->portname = talloc_strdup(mem_ctx, ntprinter->info_2->portname);
4175 W_ERROR_HAVE_NO_MEMORY(r->portname);
4176 r->drivername = talloc_strdup(mem_ctx, ntprinter->info_2->drivername);
4177 W_ERROR_HAVE_NO_MEMORY(r->drivername);
4179 if (*ntprinter->info_2->comment == '\0') {
4180 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
4182 r->comment = talloc_strdup(mem_ctx, ntprinter->info_2->comment);
4184 W_ERROR_HAVE_NO_MEMORY(r->comment);
4186 r->location = talloc_strdup(mem_ctx, ntprinter->info_2->location);
4187 W_ERROR_HAVE_NO_MEMORY(r->location);
4188 r->sepfile = talloc_strdup(mem_ctx, ntprinter->info_2->sepfile);
4189 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
4190 r->printprocessor = talloc_strdup(mem_ctx, ntprinter->info_2->printprocessor);
4191 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
4192 r->datatype = talloc_strdup(mem_ctx, ntprinter->info_2->datatype);
4193 W_ERROR_HAVE_NO_MEMORY(r->datatype);
4194 r->parameters = talloc_strdup(mem_ctx, ntprinter->info_2->parameters);
4195 W_ERROR_HAVE_NO_MEMORY(r->parameters);
4197 r->attributes = ntprinter->info_2->attributes;
4199 r->priority = ntprinter->info_2->priority;
4200 r->defaultpriority = ntprinter->info_2->default_priority;
4201 r->starttime = ntprinter->info_2->starttime;
4202 r->untiltime = ntprinter->info_2->untiltime;
4203 r->status = nt_printq_status(status.status);
4205 r->averageppm = ntprinter->info_2->averageppm;
4207 r->devmode = construct_dev_mode(mem_ctx, lp_const_servicename(snum));
4209 DEBUG(8,("Returning NULL Devicemode!\n"));
4214 if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->sd_size != 0) {
4215 /* don't use talloc_steal() here unless you do a deep steal of all
4216 the SEC_DESC members */
4218 r->secdesc = dup_sec_desc(mem_ctx, ntprinter->info_2->secdesc_buf->sd);
4224 /********************************************************************
4225 ********************************************************************/
4227 static bool snum_is_shared_printer(int snum)
4229 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
4232 /********************************************************************
4233 Spoolss_enumprinters.
4234 ********************************************************************/
4236 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
4239 union spoolss_PrinterInfo **info_p,
4243 int n_services = lp_numservices();
4244 union spoolss_PrinterInfo *info = NULL;
4246 WERROR result = WERR_OK;
4251 for (snum = 0; snum < n_services; snum++) {
4253 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
4255 if (!snum_is_shared_printer(snum)) {
4259 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
4260 lp_servicename(snum), snum));
4262 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4263 union spoolss_PrinterInfo,
4266 result = WERR_NOMEM;
4270 result = get_a_printer(NULL, &ntprinter, 2,
4271 lp_const_servicename(snum));
4272 if (!W_ERROR_IS_OK(result)) {
4278 result = construct_printer_info0(info, ntprinter,
4279 &info[count].info0, snum);
4282 result = construct_printer_info1(info, ntprinter, flags,
4283 &info[count].info1, snum);
4286 result = construct_printer_info2(info, ntprinter,
4287 &info[count].info2, snum);
4290 result = construct_printer_info4(info, ntprinter,
4291 &info[count].info4, snum);
4294 result = construct_printer_info5(info, ntprinter,
4295 &info[count].info5, snum);
4299 result = WERR_UNKNOWN_LEVEL;
4300 free_a_printer(&ntprinter, 2);
4304 free_a_printer(&ntprinter, 2);
4305 if (!W_ERROR_IS_OK(result)) {
4316 if (!W_ERROR_IS_OK(result)) {
4326 /********************************************************************
4327 * handle enumeration of printers at level 0
4328 ********************************************************************/
4330 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
4332 const char *servername,
4333 union spoolss_PrinterInfo **info,
4336 DEBUG(4,("enum_all_printers_info_0\n"));
4338 return enum_all_printers_info_level(mem_ctx, 0, flags, info, count);
4342 /********************************************************************
4343 ********************************************************************/
4345 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
4347 union spoolss_PrinterInfo **info,
4350 DEBUG(4,("enum_all_printers_info_1\n"));
4352 return enum_all_printers_info_level(mem_ctx, 1, flags, info, count);
4355 /********************************************************************
4356 enum_all_printers_info_1_local.
4357 *********************************************************************/
4359 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
4360 union spoolss_PrinterInfo **info,
4363 DEBUG(4,("enum_all_printers_info_1_local\n"));
4365 return enum_all_printers_info_1(mem_ctx, PRINTER_ENUM_ICON8, info, count);
4368 /********************************************************************
4369 enum_all_printers_info_1_name.
4370 *********************************************************************/
4372 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
4374 union spoolss_PrinterInfo **info,
4377 const char *s = name;
4379 DEBUG(4,("enum_all_printers_info_1_name\n"));
4381 if ((name[0] == '\\') && (name[1] == '\\')) {
4385 if (!is_myname_or_ipaddr(s)) {
4386 return WERR_INVALID_NAME;
4389 return enum_all_printers_info_1(mem_ctx, PRINTER_ENUM_ICON8, info, count);
4392 /********************************************************************
4393 enum_all_printers_info_1_network.
4394 *********************************************************************/
4396 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
4398 union spoolss_PrinterInfo **info,
4401 const char *s = name;
4403 DEBUG(4,("enum_all_printers_info_1_network\n"));
4405 /* If we respond to a enum_printers level 1 on our name with flags
4406 set to PRINTER_ENUM_REMOTE with a list of printers then these
4407 printers incorrectly appear in the APW browse list.
4408 Specifically the printers for the server appear at the workgroup
4409 level where all the other servers in the domain are
4410 listed. Windows responds to this call with a
4411 WERR_CAN_NOT_COMPLETE so we should do the same. */
4413 if (name[0] == '\\' && name[1] == '\\') {
4417 if (is_myname_or_ipaddr(s)) {
4418 return WERR_CAN_NOT_COMPLETE;
4421 return enum_all_printers_info_1(mem_ctx, PRINTER_ENUM_NAME, info, count);
4424 /********************************************************************
4425 * api_spoolss_enumprinters
4427 * called from api_spoolss_enumprinters (see this to understand)
4428 ********************************************************************/
4430 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
4431 union spoolss_PrinterInfo **info,
4434 DEBUG(4,("enum_all_printers_info_2\n"));
4436 return enum_all_printers_info_level(mem_ctx, 2, 0, info, count);
4439 /********************************************************************
4440 * handle enumeration of printers at level 1
4441 ********************************************************************/
4443 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
4446 union spoolss_PrinterInfo **info,
4449 /* Not all the flags are equals */
4451 if (flags & PRINTER_ENUM_LOCAL) {
4452 return enum_all_printers_info_1_local(mem_ctx, info, count);
4455 if (flags & PRINTER_ENUM_NAME) {
4456 return enum_all_printers_info_1_name(mem_ctx, name, info, count);
4459 if (flags & PRINTER_ENUM_NETWORK) {
4460 return enum_all_printers_info_1_network(mem_ctx, name, info, count);
4463 return WERR_OK; /* NT4sp5 does that */
4466 /********************************************************************
4467 * handle enumeration of printers at level 2
4468 ********************************************************************/
4470 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4472 const char *servername,
4473 union spoolss_PrinterInfo **info,
4476 if (flags & PRINTER_ENUM_LOCAL) {
4477 return enum_all_printers_info_2(mem_ctx, info, count);
4480 if (flags & PRINTER_ENUM_NAME) {
4481 if (!is_myname_or_ipaddr(canon_servername(servername))) {
4482 return WERR_INVALID_NAME;
4485 return enum_all_printers_info_2(mem_ctx, info, count);
4488 if (flags & PRINTER_ENUM_REMOTE) {
4489 return WERR_UNKNOWN_LEVEL;
4495 /********************************************************************
4496 * handle enumeration of printers at level 4
4497 ********************************************************************/
4499 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4501 const char *servername,
4502 union spoolss_PrinterInfo **info,
4505 DEBUG(4,("enum_all_printers_info_4\n"));
4507 return enum_all_printers_info_level(mem_ctx, 4, flags, info, count);
4511 /********************************************************************
4512 * handle enumeration of printers at level 5
4513 ********************************************************************/
4515 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4517 const char *servername,
4518 union spoolss_PrinterInfo **info,
4521 DEBUG(4,("enum_all_printers_info_5\n"));
4523 return enum_all_printers_info_level(mem_ctx, 5, flags, info, count);
4526 /****************************************************************
4527 _spoolss_EnumPrinters
4528 ****************************************************************/
4530 WERROR _spoolss_EnumPrinters(pipes_struct *p,
4531 struct spoolss_EnumPrinters *r)
4536 /* that's an [in out] buffer */
4538 if (!r->in.buffer && (r->in.offered != 0)) {
4539 return WERR_INVALID_PARAM;
4542 DEBUG(4,("_spoolss_EnumPrinters\n"));
4546 *r->out.info = NULL;
4550 * flags==PRINTER_ENUM_NAME
4551 * if name=="" then enumerates all printers
4552 * if name!="" then enumerate the printer
4553 * flags==PRINTER_ENUM_REMOTE
4554 * name is NULL, enumerate printers
4555 * Level 2: name!="" enumerates printers, name can't be NULL
4556 * Level 3: doesn't exist
4557 * Level 4: does a local registry lookup
4558 * Level 5: same as Level 2
4561 name = talloc_strdup_upper(p->mem_ctx, r->in.server);
4562 W_ERROR_HAVE_NO_MEMORY(name);
4564 switch (r->in.level) {
4566 result = enumprinters_level0(p->mem_ctx, r->in.flags, name,
4567 r->out.info, r->out.count);
4570 result = enumprinters_level1(p->mem_ctx, r->in.flags, name,
4571 r->out.info, r->out.count);
4574 result = enumprinters_level2(p->mem_ctx, r->in.flags, name,
4575 r->out.info, r->out.count);
4578 result = enumprinters_level4(p->mem_ctx, r->in.flags, name,
4579 r->out.info, r->out.count);
4582 result = enumprinters_level5(p->mem_ctx, r->in.flags, name,
4583 r->out.info, r->out.count);
4586 return WERR_UNKNOWN_LEVEL;
4589 if (!W_ERROR_IS_OK(result)) {
4593 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4594 spoolss_EnumPrinters, NULL,
4595 *r->out.info, r->in.level,
4597 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4598 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4600 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4603 /****************************************************************
4605 ****************************************************************/
4607 WERROR _spoolss_GetPrinter(pipes_struct *p,
4608 struct spoolss_GetPrinter *r)
4610 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
4611 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
4612 WERROR result = WERR_OK;
4616 /* that's an [in out] buffer */
4618 if (!r->in.buffer && (r->in.offered != 0)) {
4619 return WERR_INVALID_PARAM;
4624 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4628 result = get_a_printer(Printer, &ntprinter, 2,
4629 lp_const_servicename(snum));
4630 if (!W_ERROR_IS_OK(result)) {
4634 switch (r->in.level) {
4636 result = construct_printer_info0(p->mem_ctx, ntprinter,
4637 &r->out.info->info0, snum);
4640 result = construct_printer_info1(p->mem_ctx, ntprinter,
4642 &r->out.info->info1, snum);
4645 result = construct_printer_info2(p->mem_ctx, ntprinter,
4646 &r->out.info->info2, snum);
4649 result = construct_printer_info3(p->mem_ctx, ntprinter,
4650 &r->out.info->info3, snum);
4653 result = construct_printer_info4(p->mem_ctx, ntprinter,
4654 &r->out.info->info4, snum);
4657 result = construct_printer_info5(p->mem_ctx, ntprinter,
4658 &r->out.info->info5, snum);
4661 result = construct_printer_info6(p->mem_ctx, ntprinter,
4662 &r->out.info->info6, snum);
4665 result = construct_printer_info7(p->mem_ctx, Printer,
4666 &r->out.info->info7, snum);
4669 result = construct_printer_info8(p->mem_ctx, ntprinter,
4670 &r->out.info->info8, snum);
4673 result = WERR_UNKNOWN_LEVEL;
4677 free_a_printer(&ntprinter, 2);
4679 if (!W_ERROR_IS_OK(result)) {
4680 TALLOC_FREE(r->out.info);
4684 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo, NULL,
4685 r->out.info, r->in.level);
4686 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4688 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4691 /********************************************************************
4692 ********************************************************************/
4694 static const char **string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4695 fstring *fstring_array,
4696 const char *cservername)
4698 int i, num_strings = 0;
4699 const char **array = NULL;
4701 for (i=0; fstring_array && fstring_array[i][0] != '\0'; i++) {
4703 const char *str = talloc_asprintf(mem_ctx, "\\\\%s%s",
4704 cservername, fstring_array[i]);
4711 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4718 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4719 &array, &num_strings);
4725 /********************************************************************
4726 * fill a spoolss_DriverInfo1 struct
4727 ********************************************************************/
4729 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4730 struct spoolss_DriverInfo1 *r,
4731 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
4732 const char *servername,
4733 const char *architecture)
4735 r->driver_name = talloc_strdup(mem_ctx, driver->info_3->name);
4736 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4741 /********************************************************************
4742 * fill a spoolss_DriverInfo2 struct
4743 ********************************************************************/
4745 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4746 struct spoolss_DriverInfo2 *r,
4747 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
4748 const char *servername)
4751 const char *cservername = canon_servername(servername);
4753 r->version = driver->info_3->cversion;
4755 r->driver_name = talloc_strdup(mem_ctx, driver->info_3->name);
4756 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4757 r->architecture = talloc_strdup(mem_ctx, driver->info_3->environment);
4758 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4760 if (strlen(driver->info_3->driverpath)) {
4761 r->driver_path = talloc_asprintf(mem_ctx, "\\\\%s%s",
4762 cservername, driver->info_3->driverpath);
4764 r->driver_path = talloc_strdup(mem_ctx, "");
4766 W_ERROR_HAVE_NO_MEMORY(r->driver_path);
4768 if (strlen(driver->info_3->datafile)) {
4769 r->data_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4770 cservername, driver->info_3->datafile);
4772 r->data_file = talloc_strdup(mem_ctx, "");
4774 W_ERROR_HAVE_NO_MEMORY(r->data_file);
4776 if (strlen(driver->info_3->configfile)) {
4777 r->config_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4778 cservername, driver->info_3->configfile);
4780 r->config_file = talloc_strdup(mem_ctx, "");
4782 W_ERROR_HAVE_NO_MEMORY(r->config_file);
4787 /********************************************************************
4788 * fill a spoolss_DriverInfo3 struct
4789 ********************************************************************/
4791 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4792 struct spoolss_DriverInfo3 *r,
4793 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
4794 const char *servername)
4796 const char *cservername = canon_servername(servername);
4798 r->version = driver->info_3->cversion;
4800 r->driver_name = talloc_strdup(mem_ctx, driver->info_3->name);
4801 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4802 r->architecture = talloc_strdup(mem_ctx, driver->info_3->environment);
4803 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4805 if (strlen(driver->info_3->driverpath)) {
4806 r->driver_path = talloc_asprintf(mem_ctx, "\\\\%s%s",
4807 cservername, driver->info_3->driverpath);
4809 r->driver_path = talloc_strdup(mem_ctx, "");
4811 W_ERROR_HAVE_NO_MEMORY(r->driver_path);
4813 if (strlen(driver->info_3->datafile)) {
4814 r->data_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4815 cservername, driver->info_3->datafile);
4817 r->data_file = talloc_strdup(mem_ctx, "");
4819 W_ERROR_HAVE_NO_MEMORY(r->data_file);
4821 if (strlen(driver->info_3->configfile)) {
4822 r->config_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4823 cservername, driver->info_3->configfile);
4825 r->config_file = talloc_strdup(mem_ctx, "");
4827 W_ERROR_HAVE_NO_MEMORY(r->config_file);
4829 if (strlen(driver->info_3->helpfile)) {
4830 r->help_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4831 cservername, driver->info_3->helpfile);
4833 r->help_file = talloc_strdup(mem_ctx, "");
4835 W_ERROR_HAVE_NO_MEMORY(r->help_file);
4837 r->monitor_name = talloc_strdup(mem_ctx, driver->info_3->monitorname);
4838 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
4839 r->default_datatype = talloc_strdup(mem_ctx, driver->info_3->defaultdatatype);
4840 W_ERROR_HAVE_NO_MEMORY(r->default_datatype);
4842 r->dependent_files = string_array_from_driver_info(mem_ctx,
4843 driver->info_3->dependentfiles,
4848 /********************************************************************
4849 * fill a spoolss_DriverInfo4 struct
4850 ********************************************************************/
4852 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
4853 struct spoolss_DriverInfo4 *r,
4854 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
4855 const char *servername)
4857 const char *cservername = canon_servername(servername);
4859 r->version = driver->info_3->cversion;
4861 r->driver_name = talloc_strdup(mem_ctx, driver->info_3->name);
4862 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4863 r->architecture = talloc_strdup(mem_ctx, driver->info_3->environment);
4864 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4866 if (strlen(driver->info_3->driverpath)) {
4867 r->driver_path = talloc_asprintf(mem_ctx, "\\\\%s%s",
4868 cservername, driver->info_3->driverpath);
4870 r->driver_path = talloc_strdup(mem_ctx, "");
4872 W_ERROR_HAVE_NO_MEMORY(r->driver_path);
4874 if (strlen(driver->info_3->datafile)) {
4875 r->data_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4876 cservername, driver->info_3->datafile);
4878 r->data_file = talloc_strdup(mem_ctx, "");
4880 W_ERROR_HAVE_NO_MEMORY(r->data_file);
4882 if (strlen(driver->info_3->configfile)) {
4883 r->config_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4884 cservername, driver->info_3->configfile);
4886 r->config_file = talloc_strdup(mem_ctx, "");
4888 W_ERROR_HAVE_NO_MEMORY(r->config_file);
4890 if (strlen(driver->info_3->helpfile)) {
4891 r->help_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4892 cservername, driver->info_3->helpfile);
4894 r->help_file = talloc_strdup(mem_ctx, "");
4896 W_ERROR_HAVE_NO_MEMORY(r->help_file);
4898 r->dependent_files = string_array_from_driver_info(mem_ctx,
4899 driver->info_3->dependentfiles,
4903 r->monitor_name = talloc_strdup(mem_ctx, driver->info_3->monitorname);
4904 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
4905 r->default_datatype = talloc_strdup(mem_ctx, driver->info_3->defaultdatatype);
4906 W_ERROR_HAVE_NO_MEMORY(r->default_datatype);
4908 r->previous_names = string_array_from_driver_info(mem_ctx,
4915 /********************************************************************
4916 * fill a spoolss_DriverInfo6 struct
4917 ********************************************************************/
4919 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
4920 struct spoolss_DriverInfo6 *r,
4921 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
4922 const char *servername)
4924 const char *cservername = canon_servername(servername);
4926 r->version = driver->info_3->cversion;
4928 r->driver_name = talloc_strdup(mem_ctx, driver->info_3->name);
4929 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4930 r->architecture = talloc_strdup(mem_ctx, driver->info_3->environment);
4931 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4933 if (strlen(driver->info_3->driverpath)) {
4934 r->driver_path = talloc_asprintf(mem_ctx, "\\\\%s%s",
4935 cservername, driver->info_3->driverpath);
4937 r->driver_path = talloc_strdup(mem_ctx, "");
4939 W_ERROR_HAVE_NO_MEMORY(r->driver_path);
4941 if (strlen(driver->info_3->datafile)) {
4942 r->data_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4943 cservername, driver->info_3->datafile);
4945 r->data_file = talloc_strdup(mem_ctx, "");
4947 W_ERROR_HAVE_NO_MEMORY(r->data_file);
4949 if (strlen(driver->info_3->configfile)) {
4950 r->config_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4951 cservername, driver->info_3->configfile);
4953 r->config_file = talloc_strdup(mem_ctx, "");
4955 W_ERROR_HAVE_NO_MEMORY(r->config_file);
4957 if (strlen(driver->info_3->helpfile)) {
4958 r->help_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4959 cservername, driver->info_3->helpfile);
4961 r->help_file = talloc_strdup(mem_ctx, "");
4963 W_ERROR_HAVE_NO_MEMORY(r->config_file);
4965 r->monitor_name = talloc_strdup(mem_ctx, driver->info_3->monitorname);
4966 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
4967 r->default_datatype = talloc_strdup(mem_ctx, driver->info_3->defaultdatatype);
4968 W_ERROR_HAVE_NO_MEMORY(r->default_datatype);
4970 r->dependent_files = string_array_from_driver_info(mem_ctx,
4971 driver->info_3->dependentfiles,
4973 r->previous_names = string_array_from_driver_info(mem_ctx,
4978 r->driver_version = 0;
4980 r->manufacturer_name = talloc_strdup(mem_ctx, "");
4981 W_ERROR_HAVE_NO_MEMORY(r->manufacturer_name);
4982 r->manufacturer_url = talloc_strdup(mem_ctx, "");
4983 W_ERROR_HAVE_NO_MEMORY(r->manufacturer_url);
4984 r->hardware_id = talloc_strdup(mem_ctx, "");
4985 W_ERROR_HAVE_NO_MEMORY(r->hardware_id);
4986 r->provider = talloc_strdup(mem_ctx, "");
4987 W_ERROR_HAVE_NO_MEMORY(r->provider);
4992 /********************************************************************
4993 ********************************************************************/
4995 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
4996 struct spoolss_DriverFileInfo *r,
4997 const char *cservername,
4998 const char *file_name,
4999 enum spoolss_DriverFileType file_type,
5000 uint32_t file_version)
5002 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
5003 cservername, file_name);
5004 W_ERROR_HAVE_NO_MEMORY(r->file_name);
5005 r->file_type = file_type;
5006 r->file_version = file_version;
5011 /********************************************************************
5012 ********************************************************************/
5014 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
5015 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
5016 const char *cservername,
5017 struct spoolss_DriverFileInfo **info_p,
5020 struct spoolss_DriverFileInfo *info = NULL;
5028 if (strlen(driver->info_3->driverpath)) {
5029 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5030 struct spoolss_DriverFileInfo,
5032 W_ERROR_HAVE_NO_MEMORY(info);
5033 result = fill_spoolss_DriverFileInfo(info,
5036 driver->info_3->driverpath,
5037 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
5039 W_ERROR_NOT_OK_RETURN(result);
5043 if (strlen(driver->info_3->configfile)) {
5044 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5045 struct spoolss_DriverFileInfo,
5047 W_ERROR_HAVE_NO_MEMORY(info);
5048 result = fill_spoolss_DriverFileInfo(info,
5051 driver->info_3->configfile,
5052 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
5054 W_ERROR_NOT_OK_RETURN(result);
5058 if (strlen(driver->info_3->datafile)) {
5059 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5060 struct spoolss_DriverFileInfo,
5062 W_ERROR_HAVE_NO_MEMORY(info);
5063 result = fill_spoolss_DriverFileInfo(info,
5066 driver->info_3->datafile,
5067 SPOOLSS_DRIVER_FILE_TYPE_DATA,
5069 W_ERROR_NOT_OK_RETURN(result);
5073 if (strlen(driver->info_3->helpfile)) {
5074 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5075 struct spoolss_DriverFileInfo,
5077 W_ERROR_HAVE_NO_MEMORY(info);
5078 result = fill_spoolss_DriverFileInfo(info,
5081 driver->info_3->helpfile,
5082 SPOOLSS_DRIVER_FILE_TYPE_HELP,
5084 W_ERROR_NOT_OK_RETURN(result);
5088 for (i=0; driver->info_3->dependentfiles[i][0] != '\0'; i++) {
5089 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5090 struct spoolss_DriverFileInfo,
5092 W_ERROR_HAVE_NO_MEMORY(info);
5093 result = fill_spoolss_DriverFileInfo(info,
5096 driver->info_3->dependentfiles[i],
5097 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
5099 W_ERROR_NOT_OK_RETURN(result);
5109 /********************************************************************
5110 * fill a spoolss_DriverInfo101 sttruct
5111 ********************************************************************/
5113 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
5114 struct spoolss_DriverInfo101 *r,
5115 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
5116 const char *servername)
5118 const char *cservername = canon_servername(servername);
5121 r->version = driver->info_3->cversion;
5123 r->driver_name = talloc_strdup(mem_ctx, driver->info_3->name);
5124 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5125 r->architecture = talloc_strdup(mem_ctx, driver->info_3->environment);
5126 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5128 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
5132 if (!W_ERROR_IS_OK(result)) {
5136 r->monitor_name = talloc_strdup(mem_ctx, driver->info_3->monitorname);
5137 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
5139 r->default_datatype = talloc_strdup(mem_ctx, driver->info_3->defaultdatatype);
5140 W_ERROR_HAVE_NO_MEMORY(r->default_datatype);
5142 r->previous_names = string_array_from_driver_info(mem_ctx,
5146 r->driver_version = 0;
5148 r->manufacturer_name = talloc_strdup(mem_ctx, "");
5149 W_ERROR_HAVE_NO_MEMORY(r->manufacturer_name);
5150 r->manufacturer_url = talloc_strdup(mem_ctx, "");
5151 W_ERROR_HAVE_NO_MEMORY(r->manufacturer_url);
5152 r->hardware_id = talloc_strdup(mem_ctx, "");
5153 W_ERROR_HAVE_NO_MEMORY(r->hardware_id);
5154 r->provider = talloc_strdup(mem_ctx, "");
5155 W_ERROR_HAVE_NO_MEMORY(r->provider);
5160 /********************************************************************
5161 * construct_printer_driver_info_1
5162 ********************************************************************/
5164 static WERROR construct_printer_driver_info_1(TALLOC_CTX *mem_ctx,
5165 struct spoolss_DriverInfo1 *r,
5167 const char *servername,
5168 const char *architecture,
5171 NT_PRINTER_INFO_LEVEL *printer = NULL;
5172 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5175 ZERO_STRUCT(driver);
5177 if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, lp_const_servicename(snum))))
5178 return WERR_INVALID_PRINTER_NAME;
5180 if (!W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version))) {
5181 free_a_printer(&printer, 2);
5182 return WERR_UNKNOWN_PRINTER_DRIVER;
5185 result = fill_printer_driver_info1(mem_ctx, r, &driver, servername, architecture);
5187 free_a_printer(&printer,2);
5192 /********************************************************************
5193 * construct_printer_driver_info_2
5194 * fill a printer_info_2 struct
5195 ********************************************************************/
5197 static WERROR construct_printer_driver_info_2(TALLOC_CTX *mem_ctx,
5198 struct spoolss_DriverInfo2 *r,
5200 const char *servername,
5201 const char *architecture,
5204 NT_PRINTER_INFO_LEVEL *printer = NULL;
5205 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5208 ZERO_STRUCT(printer);
5209 ZERO_STRUCT(driver);
5211 if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, lp_const_servicename(snum))))
5212 return WERR_INVALID_PRINTER_NAME;
5214 if (!W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version))) {
5215 free_a_printer(&printer, 2);
5216 return WERR_UNKNOWN_PRINTER_DRIVER;
5219 result = fill_printer_driver_info2(mem_ctx, r, &driver, servername);
5221 free_a_printer(&printer,2);
5226 /********************************************************************
5227 * construct_printer_info_3
5228 * fill a printer_info_3 struct
5229 ********************************************************************/
5231 static WERROR construct_printer_driver_info_3(TALLOC_CTX *mem_ctx,
5232 struct spoolss_DriverInfo3 *r,
5234 const char *servername,
5235 const char *architecture,
5238 NT_PRINTER_INFO_LEVEL *printer = NULL;
5239 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5241 ZERO_STRUCT(driver);
5243 status=get_a_printer(NULL, &printer, 2, lp_const_servicename(snum) );
5244 DEBUG(8,("construct_printer_driver_info_3: status: %s\n", win_errstr(status)));
5245 if (!W_ERROR_IS_OK(status))
5246 return WERR_INVALID_PRINTER_NAME;
5248 status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version);
5249 DEBUG(8,("construct_printer_driver_info_3: status: %s\n", win_errstr(status)));
5254 * I put this code in during testing. Helpful when commenting out the
5255 * support for DRIVER_INFO_6 in regards to win2k. Not needed in general
5256 * as win2k always queries the driver using an infor level of 6.
5257 * I've left it in (but ifdef'd out) because I'll probably
5258 * use it in experimentation again in the future. --jerry 22/01/2002
5261 if (!W_ERROR_IS_OK(status)) {
5263 * Is this a W2k client ?
5266 /* Yes - try again with a WinNT driver. */
5268 status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version);
5269 DEBUG(8,("construct_printer_driver_info_3: status: %s\n", win_errstr(status)));
5273 if (!W_ERROR_IS_OK(status)) {
5274 free_a_printer(&printer,2);
5275 return WERR_UNKNOWN_PRINTER_DRIVER;
5283 status = fill_printer_driver_info3(mem_ctx, r, &driver, servername);
5285 free_a_printer(&printer,2);
5290 /********************************************************************
5291 * construct_printer_info_6
5292 * fill a printer_info_6 struct
5293 ********************************************************************/
5295 static WERROR construct_printer_driver_info_6(TALLOC_CTX *mem_ctx,
5296 struct spoolss_DriverInfo6 *r,
5298 const char *servername,
5299 const char *architecture,
5302 NT_PRINTER_INFO_LEVEL *printer = NULL;
5303 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5306 ZERO_STRUCT(driver);
5308 status=get_a_printer(NULL, &printer, 2, lp_const_servicename(snum) );
5310 DEBUG(8,("construct_printer_driver_info_6: status: %s\n", win_errstr(status)));
5312 if (!W_ERROR_IS_OK(status))
5313 return WERR_INVALID_PRINTER_NAME;
5315 status = get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version);
5317 DEBUG(8,("construct_printer_driver_info_6: status: %s\n", win_errstr(status)));
5319 if (!W_ERROR_IS_OK(status))
5322 * Is this a W2k client ?
5326 free_a_printer(&printer,2);
5327 return WERR_UNKNOWN_PRINTER_DRIVER;
5330 /* Yes - try again with a WinNT driver. */
5332 status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version);
5333 DEBUG(8,("construct_printer_driver_info_6: status: %s\n", win_errstr(status)));
5334 if (!W_ERROR_IS_OK(status)) {
5335 free_a_printer(&printer,2);
5336 return WERR_UNKNOWN_PRINTER_DRIVER;
5340 status = fill_printer_driver_info6(mem_ctx, r, &driver, servername);
5342 free_a_printer(&printer,2);
5343 free_a_printer_driver(driver, 3);
5348 /********************************************************************
5349 * construct_printer_info_101
5350 * fill a printer_info_101 struct
5351 ********************************************************************/
5353 static WERROR construct_printer_driver_info_101(TALLOC_CTX *mem_ctx,
5354 struct spoolss_DriverInfo101 *r,
5356 const char *servername,
5357 const char *architecture,
5360 NT_PRINTER_INFO_LEVEL *printer = NULL;
5361 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5364 ZERO_STRUCT(driver);
5366 result = get_a_printer(NULL, &printer, 2, lp_const_servicename(snum));
5368 DEBUG(8,("construct_printer_driver_info_101: status: %s\n",
5369 win_errstr(result)));
5371 if (!W_ERROR_IS_OK(result)) {
5372 return WERR_INVALID_PRINTER_NAME;
5375 result = get_a_printer_driver(&driver, 3, printer->info_2->drivername,
5376 architecture, version);
5378 DEBUG(8,("construct_printer_driver_info_101: status: %s\n",
5379 win_errstr(result)));
5381 if (!W_ERROR_IS_OK(result)) {
5383 * Is this a W2k client ?
5387 free_a_printer(&printer, 2);
5388 return WERR_UNKNOWN_PRINTER_DRIVER;
5391 /* Yes - try again with a WinNT driver. */
5393 result = get_a_printer_driver(&driver, 3, printer->info_2->drivername,
5394 architecture, version);
5395 DEBUG(8,("construct_printer_driver_info_6: status: %s\n",
5396 win_errstr(result)));
5397 if (!W_ERROR_IS_OK(result)) {
5398 free_a_printer(&printer, 2);
5399 return WERR_UNKNOWN_PRINTER_DRIVER;
5403 result = fill_printer_driver_info101(mem_ctx, r, &driver, servername);
5405 free_a_printer(&printer, 2);
5406 free_a_printer_driver(driver, 3);
5411 /****************************************************************
5412 _spoolss_GetPrinterDriver2
5413 ****************************************************************/
5415 WERROR _spoolss_GetPrinterDriver2(pipes_struct *p,
5416 struct spoolss_GetPrinterDriver2 *r)
5418 Printer_entry *printer;
5421 const char *servername;
5424 /* that's an [in out] buffer */
5426 if (!r->in.buffer && (r->in.offered != 0)) {
5427 return WERR_INVALID_PARAM;
5430 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5432 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5433 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5434 return WERR_INVALID_PRINTER_NAME;
5438 *r->out.server_major_version = 0;
5439 *r->out.server_minor_version = 0;
5441 servername = get_server_name(printer);
5443 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5447 switch (r->in.level) {
5449 result = construct_printer_driver_info_1(p->mem_ctx,
5450 &r->out.info->info1,
5454 r->in.client_major_version);
5457 result = construct_printer_driver_info_2(p->mem_ctx,
5458 &r->out.info->info2,
5462 r->in.client_major_version);
5465 result = construct_printer_driver_info_3(p->mem_ctx,
5466 &r->out.info->info3,
5470 r->in.client_major_version);
5473 result = construct_printer_driver_info_6(p->mem_ctx,
5474 &r->out.info->info6,
5478 r->in.client_major_version);
5481 result = construct_printer_driver_info_101(p->mem_ctx,
5482 &r->out.info->info101,
5486 r->in.client_major_version);
5489 result = WERR_UNKNOWN_LEVEL;
5493 if (!W_ERROR_IS_OK(result)) {
5494 TALLOC_FREE(r->out.info);
5498 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo, NULL,
5499 r->out.info, r->in.level);
5500 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5502 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5506 /****************************************************************
5507 _spoolss_StartPagePrinter
5508 ****************************************************************/
5510 WERROR _spoolss_StartPagePrinter(pipes_struct *p,
5511 struct spoolss_StartPagePrinter *r)
5513 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5516 DEBUG(3,("_spoolss_StartPagePrinter: "
5517 "Error in startpageprinter printer handle\n"));
5521 Printer->page_started = true;
5525 /****************************************************************
5526 _spoolss_EndPagePrinter
5527 ****************************************************************/
5529 WERROR _spoolss_EndPagePrinter(pipes_struct *p,
5530 struct spoolss_EndPagePrinter *r)
5534 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5537 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5538 OUR_HANDLE(r->in.handle)));
5542 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5545 Printer->page_started = false;
5546 print_job_endpage(snum, Printer->jobid);
5551 /****************************************************************
5552 _spoolss_StartDocPrinter
5553 ****************************************************************/
5555 WERROR _spoolss_StartDocPrinter(pipes_struct *p,
5556 struct spoolss_StartDocPrinter *r)
5558 struct spoolss_DocumentInfo1 *info_1;
5560 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5563 DEBUG(2,("_spoolss_StartDocPrinter: "
5564 "Invalid handle (%s:%u:%u)\n",
5565 OUR_HANDLE(r->in.handle)));
5569 if (r->in.level != 1) {
5570 return WERR_UNKNOWN_LEVEL;
5573 info_1 = r->in.info.info1;
5576 * a nice thing with NT is it doesn't listen to what you tell it.
5577 * when asked to send _only_ RAW datas, it tries to send datas
5580 * So I add checks like in NT Server ...
5583 if (info_1->datatype) {
5584 if (strcmp(info_1->datatype, "RAW") != 0) {
5586 return WERR_INVALID_DATATYPE;
5590 /* get the share number of the printer */
5591 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5595 Printer->jobid = print_job_start(p->server_info, snum,
5596 info_1->document_name,
5597 Printer->nt_devmode);
5599 /* An error occured in print_job_start() so return an appropriate
5602 if (Printer->jobid == -1) {
5603 return map_werror_from_unix(errno);
5606 Printer->document_started = true;
5607 *r->out.job_id = Printer->jobid;
5612 /****************************************************************
5613 _spoolss_EndDocPrinter
5614 ****************************************************************/
5616 WERROR _spoolss_EndDocPrinter(pipes_struct *p,
5617 struct spoolss_EndDocPrinter *r)
5619 return _spoolss_enddocprinter_internal(p, r->in.handle);
5622 /****************************************************************
5623 _spoolss_WritePrinter
5624 ****************************************************************/
5626 WERROR _spoolss_WritePrinter(pipes_struct *p,
5627 struct spoolss_WritePrinter *r)
5629 uint32_t buffer_written;
5631 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5634 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5635 OUR_HANDLE(r->in.handle)));
5636 *r->out.num_written = r->in._data_size;
5640 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5643 buffer_written = (uint32_t)print_job_write(snum, Printer->jobid,
5644 (const char *)r->in.data.data,
5646 (size_t)r->in._data_size);
5647 if (buffer_written == (uint32_t)-1) {
5648 *r->out.num_written = 0;
5649 if (errno == ENOSPC)
5650 return WERR_NO_SPOOL_SPACE;
5652 return WERR_ACCESS_DENIED;
5655 *r->out.num_written = r->in._data_size;
5660 /********************************************************************
5661 * api_spoolss_getprinter
5662 * called from the spoolss dispatcher
5664 ********************************************************************/
5666 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5670 WERROR errcode = WERR_BADFUNC;
5671 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5674 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5675 OUR_HANDLE(handle)));
5679 if (!get_printer_snum(p, handle, &snum, NULL))
5683 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5684 if (print_queue_pause(p->server_info, snum, &errcode)) {
5688 case SPOOLSS_PRINTER_CONTROL_RESUME:
5689 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5690 if (print_queue_resume(p->server_info, snum, &errcode)) {
5694 case SPOOLSS_PRINTER_CONTROL_PURGE:
5695 if (print_queue_purge(p->server_info, snum, &errcode)) {
5700 return WERR_UNKNOWN_LEVEL;
5707 /****************************************************************
5708 _spoolss_AbortPrinter
5709 * From MSDN: "Deletes printer's spool file if printer is configured
5711 ****************************************************************/
5713 WERROR _spoolss_AbortPrinter(pipes_struct *p,
5714 struct spoolss_AbortPrinter *r)
5716 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5718 WERROR errcode = WERR_OK;
5721 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5722 OUR_HANDLE(r->in.handle)));
5726 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5729 print_job_delete(p->server_info, snum, Printer->jobid, &errcode );
5734 /********************************************************************
5735 * called by spoolss_api_setprinter
5736 * when updating a printer description
5737 ********************************************************************/
5739 static WERROR update_printer_sec(struct policy_handle *handle,
5740 pipes_struct *p, SEC_DESC_BUF *secdesc_ctr)
5742 SEC_DESC_BUF *new_secdesc_ctr = NULL, *old_secdesc_ctr = NULL;
5746 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5748 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
5749 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5750 OUR_HANDLE(handle)));
5752 result = WERR_BADFID;
5757 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5758 result = WERR_INVALID_PARAM;
5762 /* Check the user has permissions to change the security
5763 descriptor. By experimentation with two NT machines, the user
5764 requires Full Access to the printer to change security
5767 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
5768 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5769 result = WERR_ACCESS_DENIED;
5773 /* NT seems to like setting the security descriptor even though
5774 nothing may have actually changed. */
5776 if ( !nt_printing_getsec(p->mem_ctx, Printer->sharename, &old_secdesc_ctr)) {
5777 DEBUG(2,("update_printer_sec: nt_printing_getsec() failed\n"));
5778 result = WERR_BADFID;
5782 if (DEBUGLEVEL >= 10) {
5786 the_acl = old_secdesc_ctr->sd->dacl;
5787 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
5788 PRINTERNAME(snum), the_acl->num_aces));
5790 for (i = 0; i < the_acl->num_aces; i++) {
5791 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5792 &the_acl->aces[i].trustee),
5793 the_acl->aces[i].access_mask));
5796 the_acl = secdesc_ctr->sd->dacl;
5799 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
5800 PRINTERNAME(snum), the_acl->num_aces));
5802 for (i = 0; i < the_acl->num_aces; i++) {
5803 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5804 &the_acl->aces[i].trustee),
5805 the_acl->aces[i].access_mask));
5808 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
5812 new_secdesc_ctr = sec_desc_merge(p->mem_ctx, secdesc_ctr, old_secdesc_ctr);
5813 if (!new_secdesc_ctr) {
5814 result = WERR_NOMEM;
5818 if (sec_desc_equal(new_secdesc_ctr->sd, old_secdesc_ctr->sd)) {
5823 result = nt_printing_setsec(Printer->sharename, new_secdesc_ctr);
5830 /********************************************************************
5831 Canonicalize printer info from a client
5833 ATTN: It does not matter what we set the servername to hear
5834 since we do the necessary work in get_a_printer() to set it to
5835 the correct value based on what the client sent in the
5836 _spoolss_open_printer_ex().
5837 ********************************************************************/
5839 static bool check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum)
5841 fstring printername;
5844 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
5845 "portname=%s drivername=%s comment=%s location=%s\n",
5846 info->servername, info->printername, info->sharename,
5847 info->portname, info->drivername, info->comment, info->location));
5849 /* we force some elements to "correct" values */
5850 slprintf(info->servername, sizeof(info->servername)-1, "\\\\%s", global_myname());
5851 fstrcpy(info->sharename, lp_servicename(snum));
5853 /* check to see if we allow printername != sharename */
5855 if ( lp_force_printername(snum) ) {
5856 slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s",
5857 global_myname(), info->sharename );
5860 /* make sure printername is in \\server\printername format */
5862 fstrcpy( printername, info->printername );
5864 if ( printername[0] == '\\' && printername[1] == '\\' ) {
5865 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
5869 slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s",
5870 global_myname(), p );
5873 info->attributes |= PRINTER_ATTRIBUTE_SAMBA;
5874 info->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
5881 /****************************************************************************
5882 ****************************************************************************/
5884 WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *portname, const char *uri )
5886 char *cmd = lp_addport_cmd();
5887 char *command = NULL;
5889 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5890 bool is_print_op = false;
5893 return WERR_ACCESS_DENIED;
5896 command = talloc_asprintf(ctx,
5897 "%s \"%s\" \"%s\"", cmd, portname, uri );
5903 is_print_op = user_has_privileges( token, &se_printop );
5905 DEBUG(10,("Running [%s]\n", command));
5907 /********* BEGIN SePrintOperatorPrivilege **********/
5912 ret = smbrun(command, NULL);
5917 /********* END SePrintOperatorPrivilege **********/
5919 DEBUGADD(10,("returned [%d]\n", ret));
5921 TALLOC_FREE(command);
5924 return WERR_ACCESS_DENIED;
5930 /****************************************************************************
5931 ****************************************************************************/
5933 bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer)
5935 char *cmd = lp_addprinter_cmd();
5937 char *command = NULL;
5941 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5942 bool is_print_op = false;
5943 char *remote_machine = talloc_strdup(ctx, "%m");
5945 if (!remote_machine) {
5948 remote_machine = talloc_sub_basic(ctx,
5949 current_user_info.smb_name,
5950 current_user_info.domain,
5952 if (!remote_machine) {
5956 command = talloc_asprintf(ctx,
5957 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
5958 cmd, printer->info_2->printername, printer->info_2->sharename,
5959 printer->info_2->portname, printer->info_2->drivername,
5960 printer->info_2->location, printer->info_2->comment, remote_machine);
5966 is_print_op = user_has_privileges( token, &se_printop );
5968 DEBUG(10,("Running [%s]\n", command));
5970 /********* BEGIN SePrintOperatorPrivilege **********/
5975 if ( (ret = smbrun(command, &fd)) == 0 ) {
5976 /* Tell everyone we updated smb.conf. */
5977 message_send_all(smbd_messaging_context(),
5978 MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
5984 /********* END SePrintOperatorPrivilege **********/
5986 DEBUGADD(10,("returned [%d]\n", ret));
5988 TALLOC_FREE(command);
5989 TALLOC_FREE(remote_machine);
5997 /* reload our services immediately */
5998 reload_services(false);
6001 /* Get lines and convert them back to dos-codepage */
6002 qlines = fd_lines_load(fd, &numlines, 0, NULL);
6003 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
6006 /* Set the portname to what the script says the portname should be. */
6007 /* but don't require anything to be return from the script exit a good error code */
6010 /* Set the portname to what the script says the portname should be. */
6011 strncpy(printer->info_2->portname, qlines[0], sizeof(printer->info_2->portname));
6012 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
6015 TALLOC_FREE(qlines);
6020 /********************************************************************
6021 * Called by spoolss_api_setprinter
6022 * when updating a printer description.
6023 ********************************************************************/
6025 static WERROR update_printer(pipes_struct *p, struct policy_handle *handle,
6026 struct spoolss_SetPrinterInfoCtr *info_ctr,
6027 struct spoolss_DeviceMode *devmode)
6030 NT_PRINTER_INFO_LEVEL *printer = NULL, *old_printer = NULL;
6031 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
6036 DEBUG(8,("update_printer\n"));
6041 result = WERR_BADFID;
6045 if (!get_printer_snum(p, handle, &snum, NULL)) {
6046 result = WERR_BADFID;
6050 if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum))) ||
6051 (!W_ERROR_IS_OK(get_a_printer(Printer, &old_printer, 2, lp_const_servicename(snum))))) {
6052 result = WERR_BADFID;
6056 DEBUGADD(8,("Converting info_2 struct\n"));
6059 * convert_printer_info converts the incoming
6060 * info from the client and overwrites the info
6061 * just read from the tdb in the pointer 'printer'.
6064 if (!convert_printer_info(info_ctr, printer)) {
6065 result = WERR_NOMEM;
6070 /* we have a valid devmode
6071 convert it and link it*/
6073 DEBUGADD(8,("update_printer: Converting the devicemode struct\n"));
6074 if (!convert_devicemode(printer->info_2->printername, devmode,
6075 &printer->info_2->devmode)) {
6076 result = WERR_NOMEM;
6081 /* Do sanity check on the requested changes for Samba */
6083 if (!check_printer_ok(printer->info_2, snum)) {
6084 result = WERR_INVALID_PARAM;
6088 /* FIXME!!! If the driver has changed we really should verify that
6089 it is installed before doing much else --jerry */
6091 /* Check calling user has permission to update printer description */
6093 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6094 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6095 result = WERR_ACCESS_DENIED;
6099 /* Call addprinter hook */
6100 /* Check changes to see if this is really needed */
6102 if ( *lp_addprinter_cmd()
6103 && (!strequal(printer->info_2->drivername, old_printer->info_2->drivername)
6104 || !strequal(printer->info_2->comment, old_printer->info_2->comment)
6105 || !strequal(printer->info_2->portname, old_printer->info_2->portname)
6106 || !strequal(printer->info_2->location, old_printer->info_2->location)) )
6108 /* add_printer_hook() will call reload_services() */
6110 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
6112 result = WERR_ACCESS_DENIED;
6118 * When a *new* driver is bound to a printer, the drivername is used to
6119 * lookup previously saved driver initialization info, which is then
6120 * bound to the printer, simulating what happens in the Windows arch.
6122 if (!strequal(printer->info_2->drivername, old_printer->info_2->drivername))
6124 if (!set_driver_init(printer, 2))
6126 DEBUG(5,("update_printer: Error restoring driver initialization data for driver [%s]!\n",
6127 printer->info_2->drivername));
6130 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6131 printer->info_2->drivername));
6133 notify_printer_driver(snum, printer->info_2->drivername);
6137 * flag which changes actually occured. This is a small subset of
6138 * all the possible changes. We also have to update things in the
6142 if (!strequal(printer->info_2->comment, old_printer->info_2->comment)) {
6143 init_unistr2( &buffer, printer->info_2->comment, UNI_STR_TERMINATE);
6144 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "description",
6145 REG_SZ, (uint8_t *)buffer.buffer, buffer.uni_str_len*2 );
6147 notify_printer_comment(snum, printer->info_2->comment);
6150 if (!strequal(printer->info_2->sharename, old_printer->info_2->sharename)) {
6151 init_unistr2( &buffer, printer->info_2->sharename, UNI_STR_TERMINATE);
6152 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "shareName",
6153 REG_SZ, (uint8_t *)buffer.buffer, buffer.uni_str_len*2 );
6155 notify_printer_sharename(snum, printer->info_2->sharename);
6158 if (!strequal(printer->info_2->printername, old_printer->info_2->printername)) {
6161 if ( (pname = strchr_m( printer->info_2->printername+2, '\\' )) != NULL )
6164 pname = printer->info_2->printername;
6167 init_unistr2( &buffer, pname, UNI_STR_TERMINATE);
6168 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "printerName",
6169 REG_SZ, (uint8_t *)buffer.buffer, buffer.uni_str_len*2 );
6171 notify_printer_printername( snum, pname );
6174 if (!strequal(printer->info_2->portname, old_printer->info_2->portname)) {
6175 init_unistr2( &buffer, printer->info_2->portname, UNI_STR_TERMINATE);
6176 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "portName",
6177 REG_SZ, (uint8_t *)buffer.buffer, buffer.uni_str_len*2 );
6179 notify_printer_port(snum, printer->info_2->portname);
6182 if (!strequal(printer->info_2->location, old_printer->info_2->location)) {
6183 init_unistr2( &buffer, printer->info_2->location, UNI_STR_TERMINATE);
6184 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "location",
6185 REG_SZ, (uint8_t *)buffer.buffer, buffer.uni_str_len*2 );
6187 notify_printer_location(snum, printer->info_2->location);
6190 /* here we need to update some more DsSpooler keys */
6191 /* uNCName, serverName, shortServerName */
6193 init_unistr2( &buffer, global_myname(), UNI_STR_TERMINATE);
6194 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "serverName",
6195 REG_SZ, (uint8_t *)buffer.buffer, buffer.uni_str_len*2 );
6196 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "shortServerName",
6197 REG_SZ, (uint8_t *)buffer.buffer, buffer.uni_str_len*2 );
6199 slprintf( asc_buffer, sizeof(asc_buffer)-1, "\\\\%s\\%s",
6200 global_myname(), printer->info_2->sharename );
6201 init_unistr2( &buffer, asc_buffer, UNI_STR_TERMINATE);
6202 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "uNCName",
6203 REG_SZ, (uint8_t *)buffer.buffer, buffer.uni_str_len*2 );
6205 /* Update printer info */
6206 result = mod_a_printer(printer, 2);
6209 free_a_printer(&printer, 2);
6210 free_a_printer(&old_printer, 2);
6216 /****************************************************************************
6217 ****************************************************************************/
6218 static WERROR publish_or_unpublish_printer(pipes_struct *p,
6219 struct policy_handle *handle,
6220 struct spoolss_SetPrinterInfo7 *info7)
6224 Printer_entry *Printer;
6226 if ( lp_security() != SEC_ADS ) {
6227 return WERR_UNKNOWN_LEVEL;
6230 Printer = find_printer_index_by_hnd(p, handle);
6232 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6237 if (!get_printer_snum(p, handle, &snum, NULL))
6240 nt_printer_publish(Printer, snum, info7->action);
6244 return WERR_UNKNOWN_LEVEL;
6248 /****************************************************************
6250 ****************************************************************/
6252 WERROR _spoolss_SetPrinter(pipes_struct *p,
6253 struct spoolss_SetPrinter *r)
6257 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
6260 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6261 OUR_HANDLE(r->in.handle)));
6265 /* check the level */
6266 switch (r->in.info_ctr->level) {
6268 return control_printer(r->in.handle, r->in.command, p);
6270 result = update_printer(p, r->in.handle,
6272 r->in.devmode_ctr->devmode);
6273 if (!W_ERROR_IS_OK(result))
6275 if (r->in.secdesc_ctr->sd)
6276 result = update_printer_sec(r->in.handle, p,
6280 return update_printer_sec(r->in.handle, p,
6283 return publish_or_unpublish_printer(p, r->in.handle,
6284 r->in.info_ctr->info.info7);
6286 return WERR_UNKNOWN_LEVEL;
6290 /****************************************************************
6291 _spoolss_FindClosePrinterNotify
6292 ****************************************************************/
6294 WERROR _spoolss_FindClosePrinterNotify(pipes_struct *p,
6295 struct spoolss_FindClosePrinterNotify *r)
6297 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
6300 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6301 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
6305 if (Printer->notify.client_connected == true) {
6308 if ( Printer->printer_type == SPLHND_SERVER)
6310 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
6311 !get_printer_snum(p, r->in.handle, &snum, NULL) )
6314 srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
6317 Printer->notify.flags=0;
6318 Printer->notify.options=0;
6319 Printer->notify.localmachine[0]='\0';
6320 Printer->notify.printerlocal=0;
6321 TALLOC_FREE(Printer->notify.option);
6322 Printer->notify.client_connected = false;
6327 /****************************************************************
6329 ****************************************************************/
6331 WERROR _spoolss_AddJob(pipes_struct *p,
6332 struct spoolss_AddJob *r)
6334 if (!r->in.buffer && (r->in.offered != 0)) {
6335 return WERR_INVALID_PARAM;
6338 /* this is what a NT server returns for AddJob. AddJob must fail on
6339 * non-local printers */
6341 if (r->in.level != 1) {
6342 return WERR_UNKNOWN_LEVEL;
6345 return WERR_INVALID_PARAM;
6348 /****************************************************************************
6350 ****************************************************************************/
6352 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
6353 struct spoolss_JobInfo1 *r,
6354 const print_queue_struct *queue,
6355 int position, int snum,
6356 const NT_PRINTER_INFO_LEVEL *ntprinter)
6360 t = gmtime(&queue->time);
6362 r->job_id = queue->job;
6364 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6365 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6366 r->server_name = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
6367 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6368 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6369 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6370 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6371 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6372 r->data_type = talloc_strdup(mem_ctx, "RAW");
6373 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6374 r->text_status = talloc_strdup(mem_ctx, "");
6375 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6377 r->status = nt_printj_status(queue->status);
6378 r->priority = queue->priority;
6379 r->position = position;
6380 r->total_pages = queue->page_count;
6381 r->pages_printed = 0; /* ??? */
6383 init_systemtime(&r->submitted, t);
6388 /****************************************************************************
6390 ****************************************************************************/
6392 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
6393 struct spoolss_JobInfo2 *r,
6394 const print_queue_struct *queue,
6395 int position, int snum,
6396 const NT_PRINTER_INFO_LEVEL *ntprinter,
6397 struct spoolss_DeviceMode *devmode)
6401 t = gmtime(&queue->time);
6403 r->job_id = queue->job;
6405 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6406 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6407 r->server_name = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
6408 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6409 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6410 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6411 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6412 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6413 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
6414 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
6415 r->data_type = talloc_strdup(mem_ctx, "RAW");
6416 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6417 r->print_processor = talloc_strdup(mem_ctx, "winprint");
6418 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
6419 r->parameters = talloc_strdup(mem_ctx, "");
6420 W_ERROR_HAVE_NO_MEMORY(r->parameters);
6421 r->driver_name = talloc_strdup(mem_ctx, ntprinter->info_2->drivername);
6422 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
6424 r->devmode = devmode;
6426 r->text_status = talloc_strdup(mem_ctx, "");
6427 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6431 r->status = nt_printj_status(queue->status);
6432 r->priority = queue->priority;
6433 r->position = position;
6436 r->total_pages = queue->page_count;
6437 r->size = queue->size;
6438 init_systemtime(&r->submitted, t);
6440 r->pages_printed = 0; /* ??? */
6445 /****************************************************************************
6446 Enumjobs at level 1.
6447 ****************************************************************************/
6449 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
6450 const print_queue_struct *queue,
6451 uint32_t num_queues, int snum,
6452 const NT_PRINTER_INFO_LEVEL *ntprinter,
6453 union spoolss_JobInfo **info_p,
6456 union spoolss_JobInfo *info;
6458 WERROR result = WERR_OK;
6460 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6461 W_ERROR_HAVE_NO_MEMORY(info);
6463 *count = num_queues;
6465 for (i=0; i<*count; i++) {
6466 result = fill_job_info1(info,
6472 if (!W_ERROR_IS_OK(result)) {
6478 if (!W_ERROR_IS_OK(result)) {
6489 /****************************************************************************
6490 Enumjobs at level 2.
6491 ****************************************************************************/
6493 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
6494 const print_queue_struct *queue,
6495 uint32_t num_queues, int snum,
6496 const NT_PRINTER_INFO_LEVEL *ntprinter,
6497 union spoolss_JobInfo **info_p,
6500 union spoolss_JobInfo *info;
6502 WERROR result = WERR_OK;
6504 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6505 W_ERROR_HAVE_NO_MEMORY(info);
6507 *count = num_queues;
6509 for (i=0; i<*count; i++) {
6511 struct spoolss_DeviceMode *devmode;
6513 devmode = construct_dev_mode(info, lp_const_servicename(snum));
6515 result = WERR_NOMEM;
6519 result = fill_job_info2(info,
6526 if (!W_ERROR_IS_OK(result)) {
6532 if (!W_ERROR_IS_OK(result)) {
6543 /****************************************************************
6545 ****************************************************************/
6547 WERROR _spoolss_EnumJobs(pipes_struct *p,
6548 struct spoolss_EnumJobs *r)
6551 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
6553 print_status_struct prt_status;
6554 print_queue_struct *queue = NULL;
6557 /* that's an [in out] buffer */
6559 if (!r->in.buffer && (r->in.offered != 0)) {
6560 return WERR_INVALID_PARAM;
6563 DEBUG(4,("_spoolss_EnumJobs\n"));
6567 *r->out.info = NULL;
6569 /* lookup the printer snum and tdb entry */
6571 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6575 result = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum));
6576 if (!W_ERROR_IS_OK(result)) {
6580 count = print_queue_status(snum, &queue, &prt_status);
6581 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
6582 count, prt_status.status, prt_status.message));
6586 free_a_printer(&ntprinter, 2);
6590 switch (r->in.level) {
6592 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
6593 ntprinter, r->out.info, r->out.count);
6596 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
6597 ntprinter, r->out.info, r->out.count);
6600 result = WERR_UNKNOWN_LEVEL;
6605 free_a_printer(&ntprinter, 2);
6607 if (!W_ERROR_IS_OK(result)) {
6611 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6612 spoolss_EnumJobs, NULL,
6613 *r->out.info, r->in.level,
6615 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6616 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6618 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6621 /****************************************************************
6622 _spoolss_ScheduleJob
6623 ****************************************************************/
6625 WERROR _spoolss_ScheduleJob(pipes_struct *p,
6626 struct spoolss_ScheduleJob *r)
6631 /****************************************************************
6633 ****************************************************************/
6635 WERROR _spoolss_SetJob(pipes_struct *p,
6636 struct spoolss_SetJob *r)
6639 WERROR errcode = WERR_BADFUNC;
6641 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6645 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
6646 return WERR_INVALID_PRINTER_NAME;
6649 switch (r->in.command) {
6650 case SPOOLSS_JOB_CONTROL_CANCEL:
6651 case SPOOLSS_JOB_CONTROL_DELETE:
6652 if (print_job_delete(p->server_info, snum, r->in.job_id, &errcode)) {
6656 case SPOOLSS_JOB_CONTROL_PAUSE:
6657 if (print_job_pause(p->server_info, snum, r->in.job_id, &errcode)) {
6661 case SPOOLSS_JOB_CONTROL_RESTART:
6662 case SPOOLSS_JOB_CONTROL_RESUME:
6663 if (print_job_resume(p->server_info, snum, r->in.job_id, &errcode)) {
6668 return WERR_UNKNOWN_LEVEL;
6674 /****************************************************************************
6675 Enumerates all printer drivers by level.
6676 ****************************************************************************/
6678 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
6679 const char *servername,
6680 const char *architecture,
6682 union spoolss_DriverInfo **info_p,
6688 fstring *list = NULL;
6689 NT_PRINTER_DRIVER_INFO_LEVEL driver;
6690 union spoolss_DriverInfo *info = NULL;
6692 WERROR result = WERR_OK;
6697 for (version=0; version<DRIVER_MAX_VERSION; version++) {
6699 ndrivers = get_ntdrivers(&list, architecture, version);
6700 DEBUGADD(4,("we have:[%d] drivers in environment [%s] and version [%d]\n",
6701 ndrivers, architecture, version));
6703 if (ndrivers == -1) {
6704 result = WERR_NOMEM;
6708 if (ndrivers != 0) {
6709 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
6710 union spoolss_DriverInfo,
6713 DEBUG(0,("enumprinterdrivers_level1: "
6714 "failed to enlarge driver info buffer!\n"));
6715 result = WERR_NOMEM;
6720 for (i=0; i<ndrivers; i++) {
6721 DEBUGADD(5,("\tdriver: [%s]\n", list[i]));
6722 ZERO_STRUCT(driver);
6723 result = get_a_printer_driver(&driver, 3, list[i],
6724 architecture, version);
6725 if (!W_ERROR_IS_OK(result)) {
6731 result = fill_printer_driver_info1(info, &info[count+i].info1,
6732 &driver, servername,
6736 result = fill_printer_driver_info2(info, &info[count+i].info2,
6737 &driver, servername);
6740 result = fill_printer_driver_info3(info, &info[count+i].info3,
6741 &driver, servername);
6744 result = fill_printer_driver_info4(info, &info[count+i].info4,
6745 &driver, servername);
6748 result = WERR_UNKNOWN_LEVEL;
6752 if (!W_ERROR_IS_OK(result)) {
6753 free_a_printer_driver(driver, 3);
6756 free_a_printer_driver(driver, 3);
6766 if (!W_ERROR_IS_OK(result)) {
6777 /****************************************************************************
6778 Enumerates all printer drivers at level 1.
6779 ****************************************************************************/
6781 static WERROR enumprinterdrivers_level1(TALLOC_CTX *mem_ctx,
6782 const char *servername,
6783 const char *architecture,
6784 union spoolss_DriverInfo **info_p,
6787 return enumprinterdrivers_level(mem_ctx, servername, architecture, 1,
6791 /****************************************************************************
6792 Enumerates all printer drivers at level 2.
6793 ****************************************************************************/
6795 static WERROR enumprinterdrivers_level2(TALLOC_CTX *mem_ctx,
6796 const char *servername,
6797 const char *architecture,
6798 union spoolss_DriverInfo **info_p,
6801 return enumprinterdrivers_level(mem_ctx, servername, architecture, 2,
6805 /****************************************************************************
6806 Enumerates all printer drivers at level 3.
6807 ****************************************************************************/
6809 static WERROR enumprinterdrivers_level3(TALLOC_CTX *mem_ctx,
6810 const char *servername,
6811 const char *architecture,
6812 union spoolss_DriverInfo **info_p,
6815 return enumprinterdrivers_level(mem_ctx, servername, architecture, 3,
6819 /****************************************************************************
6820 Enumerates all printer drivers at level 4.
6821 ****************************************************************************/
6823 static WERROR enumprinterdrivers_level4(TALLOC_CTX *mem_ctx,
6824 const char *servername,
6825 const char *architecture,
6826 union spoolss_DriverInfo **info_p,
6829 return enumprinterdrivers_level(mem_ctx, servername, architecture, 4,
6833 /****************************************************************
6834 _spoolss_EnumPrinterDrivers
6835 ****************************************************************/
6837 WERROR _spoolss_EnumPrinterDrivers(pipes_struct *p,
6838 struct spoolss_EnumPrinterDrivers *r)
6840 const char *cservername;
6843 /* that's an [in out] buffer */
6845 if (!r->in.buffer && (r->in.offered != 0)) {
6846 return WERR_INVALID_PARAM;
6849 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
6853 *r->out.info = NULL;
6855 cservername = canon_servername(r->in.server);
6857 if (!is_myname_or_ipaddr(cservername)) {
6858 return WERR_UNKNOWN_PRINTER_DRIVER;
6861 switch (r->in.level) {
6863 result = enumprinterdrivers_level1(p->mem_ctx, cservername,
6865 r->out.info, r->out.count);
6868 result = enumprinterdrivers_level2(p->mem_ctx, cservername,
6870 r->out.info, r->out.count);
6873 result = enumprinterdrivers_level3(p->mem_ctx, cservername,
6875 r->out.info, r->out.count);
6878 result = enumprinterdrivers_level4(p->mem_ctx, cservername,
6880 r->out.info, r->out.count);
6883 return WERR_UNKNOWN_LEVEL;
6886 if (!W_ERROR_IS_OK(result)) {
6890 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6891 spoolss_EnumPrinterDrivers, NULL,
6892 *r->out.info, r->in.level,
6894 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6895 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6897 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6900 /****************************************************************************
6901 ****************************************************************************/
6903 static WERROR fill_form_info_1(TALLOC_CTX *mem_ctx,
6904 struct spoolss_FormInfo1 *r,
6905 const nt_forms_struct *form)
6907 r->form_name = talloc_strdup(mem_ctx, form->name);
6908 W_ERROR_HAVE_NO_MEMORY(r->form_name);
6910 r->flags = form->flag;
6911 r->size.width = form->width;
6912 r->size.height = form->length;
6913 r->area.left = form->left;
6914 r->area.top = form->top;
6915 r->area.right = form->right;
6916 r->area.bottom = form->bottom;
6921 /****************************************************************
6922 spoolss_enumforms_level1
6923 ****************************************************************/
6925 static WERROR spoolss_enumforms_level1(TALLOC_CTX *mem_ctx,
6926 const nt_forms_struct *builtin_forms,
6927 uint32_t num_builtin_forms,
6928 const nt_forms_struct *user_forms,
6929 uint32_t num_user_forms,
6930 union spoolss_FormInfo **info_p,
6933 union spoolss_FormInfo *info;
6934 WERROR result = WERR_OK;
6937 *count = num_builtin_forms + num_user_forms;
6939 info = TALLOC_ARRAY(mem_ctx, union spoolss_FormInfo, *count);
6940 W_ERROR_HAVE_NO_MEMORY(info);
6942 /* construct the list of form structures */
6943 for (i=0; i<num_builtin_forms; i++) {
6944 DEBUGADD(6,("Filling form number [%d]\n",i));
6945 result = fill_form_info_1(info, &info[i].info1,
6947 if (!W_ERROR_IS_OK(result)) {
6952 for (; i<num_user_forms; i++) {
6953 DEBUGADD(6,("Filling form number [%d]\n",i));
6954 result = fill_form_info_1(info, &info[i].info1,
6955 &user_forms[i-num_builtin_forms]);
6956 if (!W_ERROR_IS_OK(result)) {
6962 if (!W_ERROR_IS_OK(result)) {
6973 /****************************************************************
6975 ****************************************************************/
6977 WERROR _spoolss_EnumForms(pipes_struct *p,
6978 struct spoolss_EnumForms *r)
6981 nt_forms_struct *user_forms = NULL;
6982 nt_forms_struct *builtin_forms = NULL;
6983 uint32_t num_user_forms;
6984 uint32_t num_builtin_forms;
6988 *r->out.info = NULL;
6990 /* that's an [in out] buffer */
6992 if (!r->in.buffer && (r->in.offered != 0) ) {
6993 return WERR_INVALID_PARAM;
6996 DEBUG(4,("_spoolss_EnumForms\n"));
6997 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
6998 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7000 num_builtin_forms = get_builtin_ntforms(&builtin_forms);
7001 DEBUGADD(5,("Number of builtin forms [%d]\n", num_builtin_forms));
7002 num_user_forms = get_ntforms(&user_forms);
7003 DEBUGADD(5,("Number of user forms [%d]\n", num_user_forms));
7005 if (num_user_forms + num_builtin_forms == 0) {
7006 SAFE_FREE(builtin_forms);
7007 SAFE_FREE(user_forms);
7008 return WERR_NO_MORE_ITEMS;
7011 switch (r->in.level) {
7013 result = spoolss_enumforms_level1(p->mem_ctx,
7022 result = WERR_UNKNOWN_LEVEL;
7026 SAFE_FREE(user_forms);
7027 SAFE_FREE(builtin_forms);
7029 if (!W_ERROR_IS_OK(result)) {
7033 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7034 spoolss_EnumForms, NULL,
7035 *r->out.info, r->in.level,
7037 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7038 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7040 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7043 /****************************************************************
7044 ****************************************************************/
7046 static WERROR find_form_byname(const char *name,
7047 nt_forms_struct *form)
7049 nt_forms_struct *list = NULL;
7050 int num_forms = 0, i = 0;
7052 if (get_a_builtin_ntform_by_string(name, form)) {
7056 num_forms = get_ntforms(&list);
7057 DEBUGADD(5,("Number of forms [%d]\n", num_forms));
7059 if (num_forms == 0) {
7063 /* Check if the requested name is in the list of form structures */
7064 for (i = 0; i < num_forms; i++) {
7066 DEBUG(4,("checking form %s (want %s)\n", list[i].name, name));
7068 if (strequal(name, list[i].name)) {
7069 DEBUGADD(6,("Found form %s number [%d]\n", name, i));
7081 /****************************************************************
7083 ****************************************************************/
7085 WERROR _spoolss_GetForm(pipes_struct *p,
7086 struct spoolss_GetForm *r)
7089 nt_forms_struct form;
7091 /* that's an [in out] buffer */
7093 if (!r->in.buffer && (r->in.offered != 0)) {
7094 return WERR_INVALID_PARAM;
7097 DEBUG(4,("_spoolss_GetForm\n"));
7098 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7099 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7101 result = find_form_byname(r->in.form_name, &form);
7102 if (!W_ERROR_IS_OK(result)) {
7103 TALLOC_FREE(r->out.info);
7107 switch (r->in.level) {
7109 result = fill_form_info_1(p->mem_ctx,
7110 &r->out.info->info1,
7115 result = WERR_UNKNOWN_LEVEL;
7119 if (!W_ERROR_IS_OK(result)) {
7120 TALLOC_FREE(r->out.info);
7124 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo, NULL,
7125 r->out.info, r->in.level);
7126 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7128 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7131 /****************************************************************************
7132 ****************************************************************************/
7134 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
7135 struct spoolss_PortInfo1 *r,
7138 r->port_name = talloc_strdup(mem_ctx, name);
7139 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7144 /****************************************************************************
7145 TODO: This probably needs distinguish between TCP/IP and Local ports
7147 ****************************************************************************/
7149 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
7150 struct spoolss_PortInfo2 *r,
7153 r->port_name = talloc_strdup(mem_ctx, name);
7154 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7156 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
7157 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
7159 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
7160 W_ERROR_HAVE_NO_MEMORY(r->description);
7162 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
7169 /****************************************************************************
7170 wrapper around the enumer ports command
7171 ****************************************************************************/
7173 WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines )
7175 char *cmd = lp_enumports_cmd();
7176 char **qlines = NULL;
7177 char *command = NULL;
7185 /* if no hook then just fill in the default port */
7188 if (!(qlines = TALLOC_ARRAY( NULL, char*, 2 ))) {
7191 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7192 TALLOC_FREE(qlines);
7199 /* we have a valid enumport command */
7201 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7206 DEBUG(10,("Running [%s]\n", command));
7207 ret = smbrun(command, &fd);
7208 DEBUG(10,("Returned [%d]\n", ret));
7209 TALLOC_FREE(command);
7214 return WERR_ACCESS_DENIED;
7218 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7219 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7229 /****************************************************************************
7231 ****************************************************************************/
7233 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7234 union spoolss_PortInfo **info_p,
7237 union spoolss_PortInfo *info = NULL;
7239 WERROR result = WERR_OK;
7240 char **qlines = NULL;
7243 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7244 if (!W_ERROR_IS_OK(result)) {
7249 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7251 DEBUG(10,("Returning WERR_NOMEM\n"));
7252 result = WERR_NOMEM;
7256 for (i=0; i<numlines; i++) {
7257 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7258 result = fill_port_1(info, &info[i].info1, qlines[i]);
7259 if (!W_ERROR_IS_OK(result)) {
7264 TALLOC_FREE(qlines);
7267 if (!W_ERROR_IS_OK(result)) {
7269 TALLOC_FREE(qlines);
7281 /****************************************************************************
7283 ****************************************************************************/
7285 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7286 union spoolss_PortInfo **info_p,
7289 union spoolss_PortInfo *info = NULL;
7291 WERROR result = WERR_OK;
7292 char **qlines = NULL;
7295 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7296 if (!W_ERROR_IS_OK(result)) {
7301 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7303 DEBUG(10,("Returning WERR_NOMEM\n"));
7304 result = WERR_NOMEM;
7308 for (i=0; i<numlines; i++) {
7309 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7310 result = fill_port_2(info, &info[i].info2, qlines[i]);
7311 if (!W_ERROR_IS_OK(result)) {
7316 TALLOC_FREE(qlines);
7319 if (!W_ERROR_IS_OK(result)) {
7321 TALLOC_FREE(qlines);
7333 /****************************************************************
7335 ****************************************************************/
7337 WERROR _spoolss_EnumPorts(pipes_struct *p,
7338 struct spoolss_EnumPorts *r)
7342 /* that's an [in out] buffer */
7344 if (!r->in.buffer && (r->in.offered != 0)) {
7345 return WERR_INVALID_PARAM;
7348 DEBUG(4,("_spoolss_EnumPorts\n"));
7352 *r->out.info = NULL;
7354 switch (r->in.level) {
7356 result = enumports_level_1(p->mem_ctx, r->out.info,
7360 result = enumports_level_2(p->mem_ctx, r->out.info,
7364 return WERR_UNKNOWN_LEVEL;
7367 if (!W_ERROR_IS_OK(result)) {
7371 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7372 spoolss_EnumPorts, NULL,
7373 *r->out.info, r->in.level,
7375 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7376 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7378 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7381 /****************************************************************************
7382 ****************************************************************************/
7384 static WERROR spoolss_addprinterex_level_2(pipes_struct *p,
7386 struct spoolss_SetPrinterInfoCtr *info_ctr,
7387 struct spoolss_DeviceMode *devmode,
7388 struct security_descriptor *sec_desc,
7389 struct spoolss_UserLevelCtr *user_ctr,
7390 struct policy_handle *handle)
7392 NT_PRINTER_INFO_LEVEL *printer = NULL;
7395 WERROR err = WERR_OK;
7397 if ( !(printer = TALLOC_ZERO_P(NULL, NT_PRINTER_INFO_LEVEL)) ) {
7398 DEBUG(0,("spoolss_addprinterex_level_2: malloc fail.\n"));
7402 /* convert from UNICODE to ASCII - this allocates the info_2 struct inside *printer.*/
7403 if (!convert_printer_info(info_ctr, printer)) {
7404 free_a_printer(&printer, 2);
7408 /* check to see if the printer already exists */
7410 if ((snum = print_queue_snum(printer->info_2->sharename)) != -1) {
7411 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7412 printer->info_2->sharename));
7413 free_a_printer(&printer, 2);
7414 return WERR_PRINTER_ALREADY_EXISTS;
7417 /* FIXME!!! smbd should check to see if the driver is installed before
7418 trying to add a printer like this --jerry */
7420 if (*lp_addprinter_cmd() ) {
7421 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
7423 free_a_printer(&printer,2);
7424 return WERR_ACCESS_DENIED;
7427 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
7428 "smb.conf parameter \"addprinter command\" is defined. This"
7429 "parameter must exist for this call to succeed\n",
7430 printer->info_2->sharename ));
7433 /* use our primary netbios name since get_a_printer() will convert
7434 it to what the client expects on a case by case basis */
7436 slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname(),
7437 printer->info_2->sharename);
7440 if ((snum = print_queue_snum(printer->info_2->sharename)) == -1) {
7441 free_a_printer(&printer,2);
7442 return WERR_ACCESS_DENIED;
7445 /* you must be a printer admin to add a new printer */
7446 if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) {
7447 free_a_printer(&printer,2);
7448 return WERR_ACCESS_DENIED;
7452 * Do sanity check on the requested changes for Samba.
7455 if (!check_printer_ok(printer->info_2, snum)) {
7456 free_a_printer(&printer,2);
7457 return WERR_INVALID_PARAM;
7461 * When a printer is created, the drivername bound to the printer is used
7462 * to lookup previously saved driver initialization info, which is then
7463 * bound to the new printer, simulating what happens in the Windows arch.
7468 set_driver_init(printer, 2);
7472 /* A valid devmode was included, convert and link it
7474 DEBUGADD(10, ("spoolss_addprinterex_level_2: devmode included, converting\n"));
7476 if (!convert_devicemode(printer->info_2->printername, devmode,
7477 &printer->info_2->devmode)) {
7482 /* write the ASCII on disk */
7483 err = mod_a_printer(printer, 2);
7484 if (!W_ERROR_IS_OK(err)) {
7485 free_a_printer(&printer,2);
7489 if (!open_printer_hnd(p, handle, name, PRINTER_ACCESS_ADMINISTER)) {
7490 /* Handle open failed - remove addition. */
7491 del_a_printer(printer->info_2->sharename);
7492 free_a_printer(&printer,2);
7493 ZERO_STRUCTP(handle);
7494 return WERR_ACCESS_DENIED;
7497 update_c_setprinter(false);
7498 free_a_printer(&printer,2);
7503 /****************************************************************
7504 _spoolss_AddPrinterEx
7505 ****************************************************************/
7507 WERROR _spoolss_AddPrinterEx(pipes_struct *p,
7508 struct spoolss_AddPrinterEx *r)
7510 switch (r->in.info_ctr->level) {
7512 /* we don't handle yet */
7513 /* but I know what to do ... */
7514 return WERR_UNKNOWN_LEVEL;
7516 return spoolss_addprinterex_level_2(p, r->in.server,
7518 r->in.devmode_ctr->devmode,
7519 r->in.secdesc_ctr->sd,
7520 r->in.userlevel_ctr,
7523 return WERR_UNKNOWN_LEVEL;
7527 /****************************************************************
7528 _spoolss_AddPrinterDriver
7529 ****************************************************************/
7531 WERROR _spoolss_AddPrinterDriver(pipes_struct *p,
7532 struct spoolss_AddPrinterDriver *r)
7534 uint32_t level = r->in.info_ctr->level;
7535 struct spoolss_AddDriverInfoCtr *info = r->in.info_ctr;
7536 WERROR err = WERR_OK;
7537 NT_PRINTER_DRIVER_INFO_LEVEL driver;
7538 const char *driver_name = NULL;
7542 switch (p->hdr_req.opnum) {
7543 case NDR_SPOOLSS_ADDPRINTERDRIVER:
7544 fn = "_spoolss_AddPrinterDriver";
7546 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
7547 fn = "_spoolss_AddPrinterDriverEx";
7550 return WERR_INVALID_PARAM;
7555 if (level != 3 && level != 6) {
7556 /* Clever hack from Martin Zielinski <mz@seh.de>
7557 * to allow downgrade from level 8 (Vista).
7559 DEBUG(0,("%s: level %d not yet implemented\n", fn, level));
7560 return WERR_UNKNOWN_LEVEL;
7563 ZERO_STRUCT(driver);
7565 if (!convert_printer_driver_info(info, &driver, level)) {
7570 DEBUG(5,("Cleaning driver's information\n"));
7571 err = clean_up_driver_struct(p, driver, level);
7572 if (!W_ERROR_IS_OK(err))
7575 DEBUG(5,("Moving driver to final destination\n"));
7576 if( !W_ERROR_IS_OK(err = move_driver_to_download_area(p, driver, level,
7581 if (add_a_printer_driver(driver, level)!=0) {
7582 err = WERR_ACCESS_DENIED;
7588 driver_name = driver.info_3->name ? driver.info_3->name : "";
7591 driver_name = driver.info_6->name ? driver.info_6->name : "";
7596 * I think this is where he DrvUpgradePrinter() hook would be
7597 * be called in a driver's interface DLL on a Windows NT 4.0/2k
7598 * server. Right now, we just need to send ourselves a message
7599 * to update each printer bound to this driver. --jerry
7602 if (!srv_spoolss_drv_upgrade_printer(driver_name)) {
7603 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
7608 * Based on the version (e.g. driver destination dir: 0=9x,2=Nt/2k,3=2k/Xp),
7609 * decide if the driver init data should be deleted. The rules are:
7610 * 1) never delete init data if it is a 9x driver, they don't use it anyway
7611 * 2) delete init data only if there is no 2k/Xp driver
7612 * 3) always delete init data
7613 * The generalized rule is always use init data from the highest order driver.
7614 * It is necessary to follow the driver install by an initialization step to
7615 * finish off this process.
7618 version = driver.info_3->cversion;
7619 else if (level == 6)
7620 version = driver.info_6->version;
7625 * 9x printer driver - never delete init data
7628 DEBUG(10,("%s: init data not deleted for 9x driver [%s]\n",
7633 * Nt or 2k (compatiblity mode) printer driver - only delete init data if
7634 * there is no 2k/Xp driver init data for this driver name.
7638 NT_PRINTER_DRIVER_INFO_LEVEL driver1;
7640 if (!W_ERROR_IS_OK(get_a_printer_driver(&driver1, 3, driver_name, "Windows NT x86", 3))) {
7642 * No 2k/Xp driver found, delete init data (if any) for the new Nt driver.
7644 if (!del_driver_init(driver_name))
7645 DEBUG(6,("%s: del_driver_init(%s) Nt failed!\n",
7649 * a 2k/Xp driver was found, don't delete init data because Nt driver will use it.
7651 free_a_printer_driver(driver1,3);
7652 DEBUG(10,("%s: init data not deleted for Nt driver [%s]\n",
7659 * 2k or Xp printer driver - always delete init data
7662 if (!del_driver_init(driver_name))
7663 DEBUG(6,("%s: del_driver_init(%s) 2k/Xp failed!\n",
7668 DEBUG(0,("%s: invalid level=%d\n", fn, level));
7674 free_a_printer_driver(driver, level);
7678 /****************************************************************
7679 _spoolss_AddPrinterDriverEx
7680 ****************************************************************/
7682 WERROR _spoolss_AddPrinterDriverEx(pipes_struct *p,
7683 struct spoolss_AddPrinterDriverEx *r)
7685 struct spoolss_AddPrinterDriver a;
7688 * we only support the semantics of AddPrinterDriver()
7689 * i.e. only copy files that are newer than existing ones
7692 if (r->in.flags != APD_COPY_NEW_FILES) {
7693 return WERR_ACCESS_DENIED;
7696 a.in.servername = r->in.servername;
7697 a.in.info_ctr = r->in.info_ctr;
7699 return _spoolss_AddPrinterDriver(p, &a);
7702 /****************************************************************************
7703 ****************************************************************************/
7705 struct _spoolss_paths {
7711 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
7713 static const struct _spoolss_paths spoolss_paths[]= {
7714 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
7715 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
7718 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
7719 const char *servername,
7720 const char *environment,
7724 const char *pservername = NULL;
7725 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
7726 const char *short_archi;
7730 /* environment may be empty */
7731 if (environment && strlen(environment)) {
7732 long_archi = environment;
7735 /* servername may be empty */
7736 if (servername && strlen(servername)) {
7737 pservername = canon_servername(servername);
7739 if (!is_myname_or_ipaddr(pservername)) {
7740 return WERR_INVALID_PARAM;
7744 if (!(short_archi = get_short_archi(long_archi))) {
7745 return WERR_INVALID_ENVIRONMENT;
7748 switch (component) {
7749 case SPOOLSS_PRTPROCS_PATH:
7750 case SPOOLSS_DRIVER_PATH:
7752 *path = talloc_asprintf(mem_ctx,
7755 spoolss_paths[component].share,
7758 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
7759 SPOOLSS_DEFAULT_SERVER_PATH,
7760 spoolss_paths[component].dir,
7765 return WERR_INVALID_PARAM;
7775 /****************************************************************************
7776 ****************************************************************************/
7778 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
7779 const char *servername,
7780 const char *environment,
7781 struct spoolss_DriverDirectoryInfo1 *r)
7786 werr = compose_spoolss_server_path(mem_ctx,
7789 SPOOLSS_DRIVER_PATH,
7791 if (!W_ERROR_IS_OK(werr)) {
7795 DEBUG(4,("printer driver directory: [%s]\n", path));
7797 r->directory_name = path;
7802 /****************************************************************
7803 _spoolss_GetPrinterDriverDirectory
7804 ****************************************************************/
7806 WERROR _spoolss_GetPrinterDriverDirectory(pipes_struct *p,
7807 struct spoolss_GetPrinterDriverDirectory *r)
7811 /* that's an [in out] buffer */
7813 if (!r->in.buffer && (r->in.offered != 0)) {
7814 return WERR_INVALID_PARAM;
7817 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
7822 /* r->in.level is ignored */
7824 werror = getprinterdriverdir_level_1(p->mem_ctx,
7827 &r->out.info->info1);
7828 if (!W_ERROR_IS_OK(werror)) {
7829 TALLOC_FREE(r->out.info);
7833 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo, NULL,
7834 r->out.info, r->in.level);
7835 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7837 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7840 /****************************************************************
7841 _spoolss_EnumPrinterData
7842 ****************************************************************/
7844 WERROR _spoolss_EnumPrinterData(pipes_struct *p,
7845 struct spoolss_EnumPrinterData *r)
7847 NT_PRINTER_INFO_LEVEL *printer = NULL;
7848 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7851 REGISTRY_VALUE *val = NULL;
7852 NT_PRINTER_DATA *p_data;
7853 int i, key_index, num_values;
7856 *r->out.value_needed = 0;
7857 *r->out.type = REG_NONE;
7858 *r->out.data_needed = 0;
7860 DEBUG(5,("_spoolss_EnumPrinterData\n"));
7863 DEBUG(2,("_spoolss_EnumPrinterData: Invalid handle (%s:%u:%u).\n",
7864 OUR_HANDLE(r->in.handle)));
7868 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7872 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
7873 if (!W_ERROR_IS_OK(result)) {
7877 p_data = printer->info_2->data;
7878 key_index = lookup_printerkey( p_data, SPOOL_PRINTERDATA_KEY );
7883 * The NT machine wants to know the biggest size of value and data
7885 * cf: MSDN EnumPrinterData remark section
7888 if (!r->in.value_offered && !r->in.data_offered && (key_index != -1)) {
7890 uint32_t biggest_valuesize = 0;
7891 uint32_t biggest_datasize = 0;
7893 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
7895 num_values = regval_ctr_numvals( p_data->keys[key_index].values );
7897 for ( i=0; i<num_values; i++ )
7899 val = regval_ctr_specific_value( p_data->keys[key_index].values, i );
7901 name_length = strlen(val->valuename);
7902 if ( strlen(val->valuename) > biggest_valuesize )
7903 biggest_valuesize = name_length;
7905 if ( val->size > biggest_datasize )
7906 biggest_datasize = val->size;
7908 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
7912 /* the value is an UNICODE string but real_value_size is the length
7913 in bytes including the trailing 0 */
7915 *r->out.value_needed = 2 * (1 + biggest_valuesize);
7916 *r->out.data_needed = biggest_datasize;
7918 DEBUG(6,("final values: [%d], [%d]\n",
7919 *r->out.value_needed, *r->out.data_needed));
7925 * the value len is wrong in NT sp3
7926 * that's the number of bytes not the number of unicode chars
7929 if (key_index != -1) {
7930 val = regval_ctr_specific_value(p_data->keys[key_index].values,
7936 /* out_value should default to "" or else NT4 has
7937 problems unmarshalling the response */
7939 if (r->in.value_offered) {
7940 *r->out.value_needed = 1;
7941 r->out.value_name = talloc_strdup(r, "");
7942 if (!r->out.value_name) {
7943 result = WERR_NOMEM;
7947 r->out.value_name = NULL;
7948 *r->out.value_needed = 0;
7951 /* the data is counted in bytes */
7953 *r->out.data_needed = r->in.data_offered;
7955 result = WERR_NO_MORE_ITEMS;
7959 * - counted in bytes in the request
7960 * - counted in UNICODE chars in the max reply
7961 * - counted in bytes in the real size
7963 * take a pause *before* coding not *during* coding
7967 if (r->in.value_offered) {
7968 r->out.value_name = talloc_strdup(r, regval_name(val));
7969 if (!r->out.value_name) {
7970 result = WERR_NOMEM;
7973 *r->out.value_needed = strlen_m(regval_name(val));
7975 r->out.value_name = NULL;
7976 *r->out.value_needed = 0;
7981 *r->out.type = regval_type(val);
7983 /* data - counted in bytes */
7985 if (r->out.data && regval_size(val)) {
7986 memcpy(r->out.data, regval_data_p(val), regval_size(val));
7989 *r->out.data_needed = regval_size(val);
7993 free_a_printer(&printer, 2);
7997 /****************************************************************
7998 _spoolss_SetPrinterData
7999 ****************************************************************/
8001 WERROR _spoolss_SetPrinterData(pipes_struct *p,
8002 struct spoolss_SetPrinterData *r)
8004 NT_PRINTER_INFO_LEVEL *printer = NULL;
8006 WERROR result = WERR_OK;
8007 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8010 DEBUG(5,("_spoolss_SetPrinterData\n"));
8013 DEBUG(2,("_spoolss_SetPrinterData: Invalid handle (%s:%u:%u).\n",
8014 OUR_HANDLE(r->in.handle)));
8018 if (Printer->printer_type == SPLHND_SERVER) {
8019 DEBUG(10,("_spoolss_SetPrinterData: "
8020 "Not implemented for server handles yet\n"));
8021 return WERR_INVALID_PARAM;
8024 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8029 * Access check : NT returns "access denied" if you make a
8030 * SetPrinterData call without the necessary privildge.
8031 * we were originally returning OK if nothing changed
8032 * which made Win2k issue **a lot** of SetPrinterData
8033 * when connecting to a printer --jerry
8036 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8037 DEBUG(3,("_spoolss_SetPrinterData: "
8038 "change denied by handle access permissions\n"));
8039 result = WERR_ACCESS_DENIED;
8043 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8044 if (!W_ERROR_IS_OK(result)) {
8048 result = push_spoolss_PrinterData(p->mem_ctx, &blob,
8049 r->in.type, &r->in.data);
8050 if (!W_ERROR_IS_OK(result)) {
8055 * When client side code sets a magic printer data key, detect it and save
8056 * the current printer data and the magic key's data (its the DEVMODE) for
8057 * future printer/driver initializations.
8059 if ((r->in.type == REG_BINARY) && strequal(r->in.value_name, PHANTOM_DEVMODE_KEY)) {
8060 /* Set devmode and printer initialization info */
8061 result = save_driver_init(printer, 2, blob.data, blob.length);
8063 srv_spoolss_reset_printerdata(printer->info_2->drivername);
8068 result = set_printer_dataex(printer, SPOOL_PRINTERDATA_KEY,
8069 r->in.value_name, r->in.type,
8070 blob.data, blob.length);
8071 if (W_ERROR_IS_OK(result)) {
8072 result = mod_a_printer(printer, 2);
8076 free_a_printer(&printer, 2);
8081 /****************************************************************
8082 _spoolss_ResetPrinter
8083 ****************************************************************/
8085 WERROR _spoolss_ResetPrinter(pipes_struct *p,
8086 struct spoolss_ResetPrinter *r)
8088 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8091 DEBUG(5,("_spoolss_ResetPrinter\n"));
8094 * All we do is to check to see if the handle and queue is valid.
8095 * This call really doesn't mean anything to us because we only
8096 * support RAW printing. --jerry
8100 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8101 OUR_HANDLE(r->in.handle)));
8105 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8109 /* blindly return success */
8113 /****************************************************************
8114 _spoolss_DeletePrinterData
8115 ****************************************************************/
8117 WERROR _spoolss_DeletePrinterData(pipes_struct *p,
8118 struct spoolss_DeletePrinterData *r)
8120 NT_PRINTER_INFO_LEVEL *printer = NULL;
8122 WERROR status = WERR_OK;
8123 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8125 DEBUG(5,("_spoolss_DeletePrinterData\n"));
8128 DEBUG(2,("_spoolss_DeletePrinterData: Invalid handle (%s:%u:%u).\n",
8129 OUR_HANDLE(r->in.handle)));
8133 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8136 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8137 DEBUG(3, ("_spoolss_DeletePrinterData: "
8138 "printer properties change denied by handle\n"));
8139 return WERR_ACCESS_DENIED;
8142 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8143 if (!W_ERROR_IS_OK(status))
8146 if (!r->in.value_name) {
8147 free_a_printer(&printer, 2);
8151 status = delete_printer_dataex( printer, SPOOL_PRINTERDATA_KEY,
8154 if ( W_ERROR_IS_OK(status) )
8155 mod_a_printer( printer, 2 );
8157 free_a_printer(&printer, 2);
8162 /****************************************************************
8164 ****************************************************************/
8166 WERROR _spoolss_AddForm(pipes_struct *p,
8167 struct spoolss_AddForm *r)
8169 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8170 nt_forms_struct tmpForm;
8172 WERROR status = WERR_OK;
8173 NT_PRINTER_INFO_LEVEL *printer = NULL;
8174 SE_PRIV se_printop = SE_PRINT_OPERATOR;
8177 nt_forms_struct *list=NULL;
8178 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8180 DEBUG(5,("_spoolss_AddForm\n"));
8183 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8184 OUR_HANDLE(r->in.handle)));
8189 /* forms can be added on printer of on the print server handle */
8191 if ( Printer->printer_type == SPLHND_PRINTER )
8193 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8196 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8197 if (!W_ERROR_IS_OK(status))
8201 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8202 and not a printer admin, then fail */
8204 if ((p->server_info->utok.uid != 0) &&
8205 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8206 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8208 p->server_info->ptok,
8209 lp_printer_admin(snum))) {
8210 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
8211 return WERR_ACCESS_DENIED;
8214 /* can't add if builtin */
8216 if (get_a_builtin_ntform_by_string(form->form_name, &tmpForm)) {
8217 status = WERR_FILE_EXISTS;
8221 count = get_ntforms(&list);
8223 if(!add_a_form(&list, form, &count)) {
8224 status = WERR_NOMEM;
8228 write_ntforms(&list, count);
8231 * ChangeID must always be set if this is a printer
8234 if ( Printer->printer_type == SPLHND_PRINTER )
8235 status = mod_a_printer(printer, 2);
8239 free_a_printer(&printer, 2);
8245 /****************************************************************
8247 ****************************************************************/
8249 WERROR _spoolss_DeleteForm(pipes_struct *p,
8250 struct spoolss_DeleteForm *r)
8252 const char *form_name = r->in.form_name;
8253 nt_forms_struct tmpForm;
8255 nt_forms_struct *list=NULL;
8256 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8258 WERROR status = WERR_OK;
8259 NT_PRINTER_INFO_LEVEL *printer = NULL;
8260 SE_PRIV se_printop = SE_PRINT_OPERATOR;
8262 DEBUG(5,("_spoolss_DeleteForm\n"));
8265 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8266 OUR_HANDLE(r->in.handle)));
8270 /* forms can be deleted on printer of on the print server handle */
8272 if ( Printer->printer_type == SPLHND_PRINTER )
8274 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8277 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8278 if (!W_ERROR_IS_OK(status))
8282 if ((p->server_info->utok.uid != 0) &&
8283 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8284 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8286 p->server_info->ptok,
8287 lp_printer_admin(snum))) {
8288 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8289 return WERR_ACCESS_DENIED;
8293 /* can't delete if builtin */
8295 if (get_a_builtin_ntform_by_string(form_name,&tmpForm)) {
8296 status = WERR_INVALID_PARAM;
8300 count = get_ntforms(&list);
8302 if ( !delete_a_form(&list, form_name, &count, &status ))
8306 * ChangeID must always be set if this is a printer
8309 if ( Printer->printer_type == SPLHND_PRINTER )
8310 status = mod_a_printer(printer, 2);
8314 free_a_printer(&printer, 2);
8320 /****************************************************************
8322 ****************************************************************/
8324 WERROR _spoolss_SetForm(pipes_struct *p,
8325 struct spoolss_SetForm *r)
8327 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8328 nt_forms_struct tmpForm;
8330 WERROR status = WERR_OK;
8331 NT_PRINTER_INFO_LEVEL *printer = NULL;
8332 SE_PRIV se_printop = SE_PRINT_OPERATOR;
8335 nt_forms_struct *list=NULL;
8336 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8338 DEBUG(5,("_spoolss_SetForm\n"));
8341 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8342 OUR_HANDLE(r->in.handle)));
8346 /* forms can be modified on printer of on the print server handle */
8348 if ( Printer->printer_type == SPLHND_PRINTER )
8350 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8353 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8354 if (!W_ERROR_IS_OK(status))
8358 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8359 and not a printer admin, then fail */
8361 if ((p->server_info->utok.uid != 0) &&
8362 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8363 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8365 p->server_info->ptok,
8366 lp_printer_admin(snum))) {
8367 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8368 return WERR_ACCESS_DENIED;
8371 /* can't set if builtin */
8372 if (get_a_builtin_ntform_by_string(form->form_name, &tmpForm)) {
8373 status = WERR_INVALID_PARAM;
8377 count = get_ntforms(&list);
8378 update_a_form(&list, form, count);
8379 write_ntforms(&list, count);
8382 * ChangeID must always be set if this is a printer
8385 if ( Printer->printer_type == SPLHND_PRINTER )
8386 status = mod_a_printer(printer, 2);
8391 free_a_printer(&printer, 2);
8397 /****************************************************************************
8398 fill_print_processor1
8399 ****************************************************************************/
8401 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8402 struct spoolss_PrintProcessorInfo1 *r,
8403 const char *print_processor_name)
8405 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8406 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8411 /****************************************************************************
8412 enumprintprocessors level 1.
8413 ****************************************************************************/
8415 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8416 union spoolss_PrintProcessorInfo **info_p,
8419 union spoolss_PrintProcessorInfo *info;
8422 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8423 W_ERROR_HAVE_NO_MEMORY(info);
8427 result = fill_print_processor1(info, &info[0].info1, "winprint");
8428 if (!W_ERROR_IS_OK(result)) {
8433 if (!W_ERROR_IS_OK(result)) {
8444 /****************************************************************
8445 _spoolss_EnumPrintProcessors
8446 ****************************************************************/
8448 WERROR _spoolss_EnumPrintProcessors(pipes_struct *p,
8449 struct spoolss_EnumPrintProcessors *r)
8453 /* that's an [in out] buffer */
8455 if (!r->in.buffer && (r->in.offered != 0)) {
8456 return WERR_INVALID_PARAM;
8459 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8462 * Enumerate the print processors ...
8464 * Just reply with "winprint", to keep NT happy
8465 * and I can use my nice printer checker.
8470 *r->out.info = NULL;
8472 switch (r->in.level) {
8474 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8478 return WERR_UNKNOWN_LEVEL;
8481 if (!W_ERROR_IS_OK(result)) {
8485 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8486 spoolss_EnumPrintProcessors, NULL,
8487 *r->out.info, r->in.level,
8489 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8490 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8492 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8495 /****************************************************************************
8496 fill_printprocdatatype1
8497 ****************************************************************************/
8499 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8500 struct spoolss_PrintProcDataTypesInfo1 *r,
8501 const char *name_array)
8503 r->name_array = talloc_strdup(mem_ctx, name_array);
8504 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8509 /****************************************************************************
8510 enumprintprocdatatypes level 1.
8511 ****************************************************************************/
8513 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8514 union spoolss_PrintProcDataTypesInfo **info_p,
8518 union spoolss_PrintProcDataTypesInfo *info;
8520 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8521 W_ERROR_HAVE_NO_MEMORY(info);
8525 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
8526 if (!W_ERROR_IS_OK(result)) {
8531 if (!W_ERROR_IS_OK(result)) {
8542 /****************************************************************
8543 _spoolss_EnumPrintProcDataTypes
8544 ****************************************************************/
8546 WERROR _spoolss_EnumPrintProcDataTypes(pipes_struct *p,
8547 struct spoolss_EnumPrintProcDataTypes *r)
8551 /* that's an [in out] buffer */
8553 if (!r->in.buffer && (r->in.offered != 0)) {
8554 return WERR_INVALID_PARAM;
8557 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8561 *r->out.info = NULL;
8563 switch (r->in.level) {
8565 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
8569 return WERR_UNKNOWN_LEVEL;
8572 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8573 spoolss_EnumPrintProcDataTypes, NULL,
8574 *r->out.info, r->in.level,
8576 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8577 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8579 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8582 /****************************************************************************
8584 ****************************************************************************/
8586 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
8587 struct spoolss_MonitorInfo1 *r,
8588 const char *monitor_name)
8590 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8591 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8596 /****************************************************************************
8598 ****************************************************************************/
8600 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
8601 struct spoolss_MonitorInfo2 *r,
8602 const char *monitor_name,
8603 const char *environment,
8604 const char *dll_name)
8606 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8607 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8608 r->environment = talloc_strdup(mem_ctx, environment);
8609 W_ERROR_HAVE_NO_MEMORY(r->environment);
8610 r->dll_name = talloc_strdup(mem_ctx, dll_name);
8611 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
8616 /****************************************************************************
8617 enumprintmonitors level 1.
8618 ****************************************************************************/
8620 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
8621 union spoolss_MonitorInfo **info_p,
8624 union spoolss_MonitorInfo *info;
8625 WERROR result = WERR_OK;
8627 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8628 W_ERROR_HAVE_NO_MEMORY(info);
8632 result = fill_monitor_1(info, &info[0].info1,
8634 if (!W_ERROR_IS_OK(result)) {
8638 result = fill_monitor_1(info, &info[1].info1,
8640 if (!W_ERROR_IS_OK(result)) {
8645 if (!W_ERROR_IS_OK(result)) {
8656 /****************************************************************************
8657 enumprintmonitors level 2.
8658 ****************************************************************************/
8660 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
8661 union spoolss_MonitorInfo **info_p,
8664 union spoolss_MonitorInfo *info;
8665 WERROR result = WERR_OK;
8667 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8668 W_ERROR_HAVE_NO_MEMORY(info);
8672 result = fill_monitor_2(info, &info[0].info2,
8674 "Windows NT X86", /* FIXME */
8676 if (!W_ERROR_IS_OK(result)) {
8680 result = fill_monitor_2(info, &info[1].info2,
8682 "Windows NT X86", /* FIXME */
8684 if (!W_ERROR_IS_OK(result)) {
8689 if (!W_ERROR_IS_OK(result)) {
8700 /****************************************************************
8701 _spoolss_EnumMonitors
8702 ****************************************************************/
8704 WERROR _spoolss_EnumMonitors(pipes_struct *p,
8705 struct spoolss_EnumMonitors *r)
8709 /* that's an [in out] buffer */
8711 if (!r->in.buffer && (r->in.offered != 0)) {
8712 return WERR_INVALID_PARAM;
8715 DEBUG(5,("_spoolss_EnumMonitors\n"));
8718 * Enumerate the print monitors ...
8720 * Just reply with "Local Port", to keep NT happy
8721 * and I can use my nice printer checker.
8726 *r->out.info = NULL;
8728 switch (r->in.level) {
8730 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
8734 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
8738 return WERR_UNKNOWN_LEVEL;
8741 if (!W_ERROR_IS_OK(result)) {
8745 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8746 spoolss_EnumMonitors, NULL,
8747 *r->out.info, r->in.level,
8749 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8750 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8752 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8755 /****************************************************************************
8756 ****************************************************************************/
8758 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
8759 const print_queue_struct *queue,
8760 int count, int snum,
8761 const NT_PRINTER_INFO_LEVEL *ntprinter,
8763 struct spoolss_JobInfo1 *r)
8768 for (i=0; i<count && found == false; i++) {
8769 if (queue[i].job == (int)jobid) {
8774 if (found == false) {
8775 /* NT treats not found as bad param... yet another bad choice */
8776 return WERR_INVALID_PARAM;
8779 return fill_job_info1(mem_ctx,
8787 /****************************************************************************
8788 ****************************************************************************/
8790 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
8791 const print_queue_struct *queue,
8792 int count, int snum,
8793 const NT_PRINTER_INFO_LEVEL *ntprinter,
8795 struct spoolss_JobInfo2 *r)
8799 struct spoolss_DeviceMode *devmode;
8800 NT_DEVICEMODE *nt_devmode;
8803 for (i=0; i<count && found == false; i++) {
8804 if (queue[i].job == (int)jobid) {
8809 if (found == false) {
8810 /* NT treats not found as bad param... yet another bad
8812 return WERR_INVALID_PARAM;
8816 * if the print job does not have a DEVMODE associated with it,
8817 * just use the one for the printer. A NULL devicemode is not
8818 * a failure condition
8821 nt_devmode = print_job_devmode(lp_const_servicename(snum), jobid);
8823 devmode = TALLOC_ZERO_P(mem_ctx, struct spoolss_DeviceMode);
8824 W_ERROR_HAVE_NO_MEMORY(devmode);
8825 result = convert_nt_devicemode(devmode, devmode, nt_devmode);
8826 if (!W_ERROR_IS_OK(result)) {
8830 devmode = construct_dev_mode(mem_ctx, lp_const_servicename(snum));
8831 W_ERROR_HAVE_NO_MEMORY(devmode);
8834 return fill_job_info2(mem_ctx,
8843 /****************************************************************
8845 ****************************************************************/
8847 WERROR _spoolss_GetJob(pipes_struct *p,
8848 struct spoolss_GetJob *r)
8850 WERROR result = WERR_OK;
8851 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
8854 print_queue_struct *queue = NULL;
8855 print_status_struct prt_status;
8857 /* that's an [in out] buffer */
8859 if (!r->in.buffer && (r->in.offered != 0)) {
8860 return WERR_INVALID_PARAM;
8863 DEBUG(5,("_spoolss_GetJob\n"));
8867 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8871 result = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum));
8872 if (!W_ERROR_IS_OK(result)) {
8876 count = print_queue_status(snum, &queue, &prt_status);
8878 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
8879 count, prt_status.status, prt_status.message));
8881 switch (r->in.level) {
8883 result = getjob_level_1(p->mem_ctx,
8884 queue, count, snum, ntprinter,
8885 r->in.job_id, &r->out.info->info1);
8888 result = getjob_level_2(p->mem_ctx,
8889 queue, count, snum, ntprinter,
8890 r->in.job_id, &r->out.info->info2);
8893 result = WERR_UNKNOWN_LEVEL;
8898 free_a_printer(&ntprinter, 2);
8900 if (!W_ERROR_IS_OK(result)) {
8901 TALLOC_FREE(r->out.info);
8905 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, NULL,
8906 r->out.info, r->in.level);
8907 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8909 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8912 /****************************************************************
8913 _spoolss_GetPrinterDataEx
8915 From MSDN documentation of GetPrinterDataEx: pass request
8916 to GetPrinterData if key is "PrinterDriverData".
8917 ****************************************************************/
8919 WERROR _spoolss_GetPrinterDataEx(pipes_struct *p,
8920 struct spoolss_GetPrinterDataEx *r)
8923 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8924 REGISTRY_VALUE *val = NULL;
8925 NT_PRINTER_INFO_LEVEL *printer = NULL;
8927 WERROR result = WERR_OK;
8929 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
8931 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
8932 r->in.key_name, r->in.value_name));
8934 /* in case of problem, return some default values */
8937 *r->out.type = REG_NONE;
8940 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
8941 OUR_HANDLE(r->in.handle)));
8942 result = WERR_BADFID;
8946 /* Is the handle to a printer or to the server? */
8948 if (Printer->printer_type == SPLHND_SERVER) {
8949 DEBUG(10,("_spoolss_GetPrinterDataEx: "
8950 "Not implemented for server handles yet\n"));
8951 result = WERR_INVALID_PARAM;
8955 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8959 result = get_a_printer(Printer, &printer, 2, lp_servicename(snum));
8960 if (!W_ERROR_IS_OK(result)) {
8964 /* check to see if the keyname is valid */
8965 if (!strlen(r->in.key_name)) {
8966 result = WERR_INVALID_PARAM;
8970 if (lookup_printerkey(printer->info_2->data, r->in.key_name) == -1) {
8971 DEBUG(4,("_spoolss_GetPrinterDataEx: "
8972 "Invalid keyname [%s]\n", r->in.key_name ));
8973 result = WERR_BADFILE;
8977 /* When given a new keyname, we should just create it */
8979 val = get_printer_data(printer->info_2,
8980 r->in.key_name, r->in.value_name);
8982 result = WERR_BADFILE;
8986 *r->out.needed = regval_size(val);
8988 if (*r->out.needed > r->in.offered) {
8989 result = WERR_MORE_DATA;
8993 *r->out.type = regval_type(val);
8995 memcpy(r->out.buffer, regval_data_p(val), regval_size(val));
8999 free_a_printer(&printer, 2);
9005 /****************************************************************
9006 _spoolss_SetPrinterDataEx
9007 ****************************************************************/
9009 WERROR _spoolss_SetPrinterDataEx(pipes_struct *p,
9010 struct spoolss_SetPrinterDataEx *r)
9012 NT_PRINTER_INFO_LEVEL *printer = NULL;
9014 WERROR result = WERR_OK;
9015 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9018 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
9020 /* From MSDN documentation of SetPrinterDataEx: pass request to
9021 SetPrinterData if key is "PrinterDriverData" */
9024 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9025 OUR_HANDLE(r->in.handle)));
9029 if (Printer->printer_type == SPLHND_SERVER) {
9030 DEBUG(10,("_spoolss_SetPrinterDataEx: "
9031 "Not implemented for server handles yet\n"));
9032 return WERR_INVALID_PARAM;
9035 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9040 * Access check : NT returns "access denied" if you make a
9041 * SetPrinterData call without the necessary privildge.
9042 * we were originally returning OK if nothing changed
9043 * which made Win2k issue **a lot** of SetPrinterData
9044 * when connecting to a printer --jerry
9047 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9048 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
9049 "change denied by handle access permissions\n"));
9050 return WERR_ACCESS_DENIED;
9053 result = get_a_printer(Printer, &printer, 2, lp_servicename(snum));
9054 if (!W_ERROR_IS_OK(result)) {
9058 /* check for OID in valuename */
9060 oid_string = strchr(r->in.value_name, ',');
9066 /* save the registry data */
9068 result = set_printer_dataex(printer, r->in.key_name, r->in.value_name,
9069 r->in.type, r->in.buffer, r->in.offered);
9071 if (W_ERROR_IS_OK(result)) {
9072 /* save the OID if one was specified */
9074 char *str = talloc_asprintf(p->mem_ctx, "%s\\%s",
9075 r->in.key_name, SPOOL_OID_KEY);
9077 result = WERR_NOMEM;
9082 * I'm not checking the status here on purpose. Don't know
9083 * if this is right, but I'm returning the status from the
9084 * previous set_printer_dataex() call. I have no idea if
9085 * this is right. --jerry
9088 set_printer_dataex(printer, str, r->in.value_name,
9089 REG_SZ, (uint8_t *)oid_string,
9090 strlen(oid_string)+1);
9093 result = mod_a_printer(printer, 2);
9097 free_a_printer(&printer, 2);
9102 /****************************************************************
9103 _spoolss_DeletePrinterDataEx
9104 ****************************************************************/
9106 WERROR _spoolss_DeletePrinterDataEx(pipes_struct *p,
9107 struct spoolss_DeletePrinterDataEx *r)
9109 NT_PRINTER_INFO_LEVEL *printer = NULL;
9111 WERROR status = WERR_OK;
9112 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9114 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9117 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9118 "Invalid handle (%s:%u:%u).\n",
9119 OUR_HANDLE(r->in.handle)));
9123 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
9126 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9127 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9128 "printer properties change denied by handle\n"));
9129 return WERR_ACCESS_DENIED;
9132 if (!r->in.value_name || !r->in.key_name) {
9136 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9137 if (!W_ERROR_IS_OK(status))
9140 status = delete_printer_dataex( printer, r->in.key_name, r->in.value_name );
9142 if ( W_ERROR_IS_OK(status) )
9143 mod_a_printer( printer, 2 );
9145 free_a_printer(&printer, 2);
9150 /****************************************************************
9151 _spoolss_EnumPrinterKey
9152 ****************************************************************/
9154 WERROR _spoolss_EnumPrinterKey(pipes_struct *p,
9155 struct spoolss_EnumPrinterKey *r)
9157 fstring *keynames = NULL;
9159 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9160 NT_PRINTER_DATA *data;
9161 NT_PRINTER_INFO_LEVEL *printer = NULL;
9163 WERROR result = WERR_BADFILE;
9165 const char **array = NULL;
9168 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
9171 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
9172 OUR_HANDLE(r->in.handle)));
9176 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9180 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9181 if (!W_ERROR_IS_OK(result)) {
9185 /* get the list of subkey names */
9187 data = printer->info_2->data;
9189 num_keys = get_printer_subkeys(data, r->in.key_name, &keynames);
9190 if (num_keys == -1) {
9191 result = WERR_BADFILE;
9197 array = talloc_zero_array(r->out.key_buffer, const char *, num_keys + 1);
9199 result = WERR_NOMEM;
9203 for (i=0; i < num_keys; i++) {
9204 array[i] = talloc_strdup(array, keynames[i]);
9206 result = WERR_NOMEM;
9210 *r->out.needed += strlen_m_term(keynames[i]) * 2;
9213 if (r->in.offered < *r->out.needed) {
9214 result = WERR_MORE_DATA;
9220 *r->out.key_buffer = array;
9223 if (!W_ERROR_IS_OK(result)) {
9225 ZERO_STRUCTP(r->out.key_buffer);
9228 free_a_printer(&printer, 2);
9229 SAFE_FREE(keynames);
9234 /****************************************************************
9235 _spoolss_DeletePrinterKey
9236 ****************************************************************/
9238 WERROR _spoolss_DeletePrinterKey(pipes_struct *p,
9239 struct spoolss_DeletePrinterKey *r)
9241 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9242 NT_PRINTER_INFO_LEVEL *printer = NULL;
9246 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9249 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9250 OUR_HANDLE(r->in.handle)));
9254 /* if keyname == NULL, return error */
9256 if ( !r->in.key_name )
9257 return WERR_INVALID_PARAM;
9259 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
9262 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9263 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9264 "printer properties change denied by handle\n"));
9265 return WERR_ACCESS_DENIED;
9268 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9269 if (!W_ERROR_IS_OK(status))
9272 /* delete the key and all subneys */
9274 status = delete_all_printer_data( printer->info_2, r->in.key_name );
9276 if ( W_ERROR_IS_OK(status) )
9277 status = mod_a_printer(printer, 2);
9279 free_a_printer( &printer, 2 );
9284 /****************************************************************
9285 ****************************************************************/
9287 static WERROR registry_value_to_printer_enum_value(TALLOC_CTX *mem_ctx,
9289 struct spoolss_PrinterEnumValues *r)
9293 r->data = TALLOC_ZERO_P(mem_ctx, union spoolss_PrinterData);
9294 W_ERROR_HAVE_NO_MEMORY(r->data);
9296 r->value_name = talloc_strdup(mem_ctx, regval_name(v));
9297 W_ERROR_HAVE_NO_MEMORY(r->value_name);
9299 r->type = regval_type(v);
9300 r->data_length = regval_size(v);
9302 if (r->data_length) {
9303 DATA_BLOB blob = data_blob_const(regval_data_p(v),
9305 result = pull_spoolss_PrinterData(mem_ctx, &blob,
9308 if (!W_ERROR_IS_OK(result)) {
9316 /****************************************************************
9317 _spoolss_EnumPrinterDataEx
9318 ****************************************************************/
9320 WERROR _spoolss_EnumPrinterDataEx(pipes_struct *p,
9321 struct spoolss_EnumPrinterDataEx *r)
9324 NT_PRINTER_INFO_LEVEL *printer = NULL;
9325 struct spoolss_PrinterEnumValues *info = NULL;
9326 NT_PRINTER_DATA *p_data;
9327 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9333 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9337 *r->out.info = NULL;
9340 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9341 OUR_HANDLE(r->in.handle)));
9346 * first check for a keyname of NULL or "". Win2k seems to send
9347 * this a lot and we should send back WERR_INVALID_PARAM
9348 * no need to spend time looking up the printer in this case.
9352 if (!strlen(r->in.key_name)) {
9353 result = WERR_INVALID_PARAM;
9357 /* get the printer off of disk */
9359 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9363 ZERO_STRUCT(printer);
9364 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9365 if (!W_ERROR_IS_OK(result)) {
9369 /* now look for a match on the key name */
9371 p_data = printer->info_2->data;
9373 key_index = lookup_printerkey(p_data, r->in.key_name);
9374 if (key_index == -1) {
9375 DEBUG(10,("_spoolss_EnumPrinterDataEx: Unknown keyname [%s]\n",
9377 result = WERR_INVALID_PARAM;
9381 /* allocate the memory for the array of pointers -- if necessary */
9383 count = regval_ctr_numvals(p_data->keys[key_index].values);
9385 result = WERR_OK; /* ??? */
9389 info = TALLOC_ZERO_ARRAY(p->mem_ctx,
9390 struct spoolss_PrinterEnumValues,
9393 DEBUG(0,("_spoolss_EnumPrinterDataEx: talloc() failed\n"));
9394 result = WERR_NOMEM;
9399 * loop through all params and build the array to pass
9400 * back to the client
9403 for (i=0; i < count; i++) {
9405 REGISTRY_VALUE *val;
9407 /* lookup the registry value */
9409 val = regval_ctr_specific_value(p_data->keys[key_index].values, i);
9411 DEBUG(10,("retrieved value number [%d] [%s]\n", i, regval_name(val)));
9415 result = registry_value_to_printer_enum_value(info, val, &info[i]);
9416 if (!W_ERROR_IS_OK(result)) {
9421 #if 0 /* FIXME - gd */
9422 /* housekeeping information in the reply */
9424 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9425 * the hand marshalled container size is a multiple
9426 * of 4 bytes for RPC alignment.
9430 needed += 4-(needed % 4);
9433 *r->out.count = count;
9434 *r->out.info = info;
9439 free_a_printer(&printer, 2);
9442 if (!W_ERROR_IS_OK(result)) {
9446 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
9447 spoolss_EnumPrinterDataEx, NULL,
9450 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9451 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
9453 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9456 /****************************************************************************
9457 ****************************************************************************/
9459 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
9460 const char *servername,
9461 const char *environment,
9462 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9467 werr = compose_spoolss_server_path(mem_ctx,
9470 SPOOLSS_PRTPROCS_PATH,
9472 if (!W_ERROR_IS_OK(werr)) {
9476 DEBUG(4,("print processor directory: [%s]\n", path));
9478 r->directory_name = path;
9483 /****************************************************************
9484 _spoolss_GetPrintProcessorDirectory
9485 ****************************************************************/
9487 WERROR _spoolss_GetPrintProcessorDirectory(pipes_struct *p,
9488 struct spoolss_GetPrintProcessorDirectory *r)
9492 /* that's an [in out] buffer */
9494 if (!r->in.buffer && (r->in.offered != 0)) {
9495 return WERR_INVALID_PARAM;
9498 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9503 /* r->in.level is ignored */
9505 result = getprintprocessordirectory_level_1(p->mem_ctx,
9508 &r->out.info->info1);
9509 if (!W_ERROR_IS_OK(result)) {
9510 TALLOC_FREE(r->out.info);
9514 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo, NULL,
9515 r->out.info, r->in.level);
9516 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9518 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9521 /*******************************************************************
9522 ********************************************************************/
9524 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
9525 const char *dllname)
9527 enum ndr_err_code ndr_err;
9528 struct spoolss_MonitorUi ui;
9530 ui.dll_name = dllname;
9532 ndr_err = ndr_push_struct_blob(buf, mem_ctx, NULL, &ui,
9533 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
9534 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9535 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
9537 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9540 /*******************************************************************
9541 Streams the monitor UI DLL name in UNICODE
9542 *******************************************************************/
9544 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
9545 NT_USER_TOKEN *token, DATA_BLOB *in,
9546 DATA_BLOB *out, uint32_t *needed)
9548 const char *dllname = "tcpmonui.dll";
9550 *needed = (strlen(dllname)+1) * 2;
9552 if (out->length < *needed) {
9553 return WERR_INSUFFICIENT_BUFFER;
9556 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9563 /*******************************************************************
9564 ********************************************************************/
9566 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
9567 struct spoolss_PortData1 *port1,
9568 const DATA_BLOB *buf)
9570 enum ndr_err_code ndr_err;
9571 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, NULL, port1,
9572 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
9573 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9574 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
9576 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9579 /*******************************************************************
9580 ********************************************************************/
9582 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
9583 struct spoolss_PortData2 *port2,
9584 const DATA_BLOB *buf)
9586 enum ndr_err_code ndr_err;
9587 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, NULL, port2,
9588 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
9589 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9590 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
9592 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9595 /*******************************************************************
9596 Create a new TCP/IP port
9597 *******************************************************************/
9599 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
9600 NT_USER_TOKEN *token, DATA_BLOB *in,
9601 DATA_BLOB *out, uint32_t *needed)
9603 struct spoolss_PortData1 port1;
9604 struct spoolss_PortData2 port2;
9605 char *device_uri = NULL;
9608 const char *portname;
9609 const char *hostaddress;
9611 uint32_t port_number;
9614 /* peek for spoolss_PortData version */
9616 if (!in || (in->length < (128 + 4))) {
9617 return WERR_GENERAL_FAILURE;
9620 version = IVAL(in->data, 128);
9626 if (!pull_port_data_1(mem_ctx, &port1, in)) {
9630 portname = port1.portname;
9631 hostaddress = port1.hostaddress;
9632 queue = port1.queue;
9633 protocol = port1.protocol;
9634 port_number = port1.port_number;
9640 if (!pull_port_data_2(mem_ctx, &port2, in)) {
9644 portname = port2.portname;
9645 hostaddress = port2.hostaddress;
9646 queue = port2.queue;
9647 protocol = port2.protocol;
9648 port_number = port2.port_number;
9652 DEBUG(1,("xcvtcp_addport: "
9653 "unknown version of port_data: %d\n", version));
9654 return WERR_UNKNOWN_PORT;
9657 /* create the device URI and call the add_port_hook() */
9660 case PROTOCOL_RAWTCP_TYPE:
9661 device_uri = talloc_asprintf(mem_ctx,
9662 "socket://%s:%d/", hostaddress,
9666 case PROTOCOL_LPR_TYPE:
9667 device_uri = talloc_asprintf(mem_ctx,
9668 "lpr://%s/%s", hostaddress, queue );
9672 return WERR_UNKNOWN_PORT;
9679 return add_port_hook(mem_ctx, token, portname, device_uri);
9682 /*******************************************************************
9683 *******************************************************************/
9685 struct xcv_api_table xcvtcp_cmds[] = {
9686 { "MonitorUI", xcvtcp_monitorui },
9687 { "AddPort", xcvtcp_addport},
9691 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
9692 NT_USER_TOKEN *token, const char *command,
9699 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
9701 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
9702 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
9703 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9706 return WERR_BADFUNC;
9709 /*******************************************************************
9710 *******************************************************************/
9711 #if 0 /* don't support management using the "Local Port" monitor */
9713 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
9714 NT_USER_TOKEN *token, DATA_BLOB *in,
9715 DATA_BLOB *out, uint32_t *needed)
9717 const char *dllname = "localui.dll";
9719 *needed = (strlen(dllname)+1) * 2;
9721 if (out->length < *needed) {
9722 return WERR_INSUFFICIENT_BUFFER;
9725 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9732 /*******************************************************************
9733 *******************************************************************/
9735 struct xcv_api_table xcvlocal_cmds[] = {
9736 { "MonitorUI", xcvlocal_monitorui },
9740 struct xcv_api_table xcvlocal_cmds[] = {
9747 /*******************************************************************
9748 *******************************************************************/
9750 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
9751 NT_USER_TOKEN *token, const char *command,
9752 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
9757 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
9759 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
9760 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
9761 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9763 return WERR_BADFUNC;
9766 /****************************************************************
9768 ****************************************************************/
9770 WERROR _spoolss_XcvData(pipes_struct *p,
9771 struct spoolss_XcvData *r)
9773 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9774 DATA_BLOB out_data = data_blob_null;
9778 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
9779 OUR_HANDLE(r->in.handle)));
9783 /* Has to be a handle to the TCP/IP port monitor */
9785 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
9786 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
9790 /* requires administrative access to the server */
9792 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
9793 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
9794 return WERR_ACCESS_DENIED;
9797 /* Allocate the outgoing buffer */
9799 if (r->in.out_data_size) {
9800 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
9801 if (out_data.data == NULL) {
9806 switch ( Printer->printer_type ) {
9807 case SPLHND_PORTMON_TCP:
9808 werror = process_xcvtcp_command(p->mem_ctx,
9809 p->server_info->ptok,
9810 r->in.function_name,
9811 &r->in.in_data, &out_data,
9814 case SPLHND_PORTMON_LOCAL:
9815 werror = process_xcvlocal_command(p->mem_ctx,
9816 p->server_info->ptok,
9817 r->in.function_name,
9818 &r->in.in_data, &out_data,
9822 werror = WERR_INVALID_PRINT_MONITOR;
9825 if (!W_ERROR_IS_OK(werror)) {
9829 *r->out.status_code = 0;
9831 memcpy(r->out.out_data, out_data.data, out_data.length);
9836 /****************************************************************
9837 _spoolss_AddPrintProcessor
9838 ****************************************************************/
9840 WERROR _spoolss_AddPrintProcessor(pipes_struct *p,
9841 struct spoolss_AddPrintProcessor *r)
9843 /* for now, just indicate success and ignore the add. We'll
9844 automatically set the winprint processor for printer
9845 entries later. Used to debug the LexMark Optra S 1855 PCL
9851 /****************************************************************
9853 ****************************************************************/
9855 WERROR _spoolss_AddPort(pipes_struct *p,
9856 struct spoolss_AddPort *r)
9858 /* do what w2k3 does */
9860 return WERR_NOT_SUPPORTED;
9863 /****************************************************************
9865 ****************************************************************/
9867 WERROR _spoolss_AddPrinter(pipes_struct *p,
9868 struct spoolss_AddPrinter *r)
9870 p->rng_fault_state = true;
9871 return WERR_NOT_SUPPORTED;
9874 /****************************************************************
9875 _spoolss_GetPrinterDriver
9876 ****************************************************************/
9878 WERROR _spoolss_GetPrinterDriver(pipes_struct *p,
9879 struct spoolss_GetPrinterDriver *r)
9881 p->rng_fault_state = true;
9882 return WERR_NOT_SUPPORTED;
9885 /****************************************************************
9886 _spoolss_ReadPrinter
9887 ****************************************************************/
9889 WERROR _spoolss_ReadPrinter(pipes_struct *p,
9890 struct spoolss_ReadPrinter *r)
9892 p->rng_fault_state = true;
9893 return WERR_NOT_SUPPORTED;
9896 /****************************************************************
9897 _spoolss_WaitForPrinterChange
9898 ****************************************************************/
9900 WERROR _spoolss_WaitForPrinterChange(pipes_struct *p,
9901 struct spoolss_WaitForPrinterChange *r)
9903 p->rng_fault_state = true;
9904 return WERR_NOT_SUPPORTED;
9907 /****************************************************************
9908 _spoolss_ConfigurePort
9909 ****************************************************************/
9911 WERROR _spoolss_ConfigurePort(pipes_struct *p,
9912 struct spoolss_ConfigurePort *r)
9914 p->rng_fault_state = true;
9915 return WERR_NOT_SUPPORTED;
9918 /****************************************************************
9920 ****************************************************************/
9922 WERROR _spoolss_DeletePort(pipes_struct *p,
9923 struct spoolss_DeletePort *r)
9925 p->rng_fault_state = true;
9926 return WERR_NOT_SUPPORTED;
9929 /****************************************************************
9930 _spoolss_CreatePrinterIC
9931 ****************************************************************/
9933 WERROR _spoolss_CreatePrinterIC(pipes_struct *p,
9934 struct spoolss_CreatePrinterIC *r)
9936 p->rng_fault_state = true;
9937 return WERR_NOT_SUPPORTED;
9940 /****************************************************************
9941 _spoolss_PlayGDIScriptOnPrinterIC
9942 ****************************************************************/
9944 WERROR _spoolss_PlayGDIScriptOnPrinterIC(pipes_struct *p,
9945 struct spoolss_PlayGDIScriptOnPrinterIC *r)
9947 p->rng_fault_state = true;
9948 return WERR_NOT_SUPPORTED;
9951 /****************************************************************
9952 _spoolss_DeletePrinterIC
9953 ****************************************************************/
9955 WERROR _spoolss_DeletePrinterIC(pipes_struct *p,
9956 struct spoolss_DeletePrinterIC *r)
9958 p->rng_fault_state = true;
9959 return WERR_NOT_SUPPORTED;
9962 /****************************************************************
9963 _spoolss_AddPrinterConnection
9964 ****************************************************************/
9966 WERROR _spoolss_AddPrinterConnection(pipes_struct *p,
9967 struct spoolss_AddPrinterConnection *r)
9969 p->rng_fault_state = true;
9970 return WERR_NOT_SUPPORTED;
9973 /****************************************************************
9974 _spoolss_DeletePrinterConnection
9975 ****************************************************************/
9977 WERROR _spoolss_DeletePrinterConnection(pipes_struct *p,
9978 struct spoolss_DeletePrinterConnection *r)
9980 p->rng_fault_state = true;
9981 return WERR_NOT_SUPPORTED;
9984 /****************************************************************
9985 _spoolss_PrinterMessageBox
9986 ****************************************************************/
9988 WERROR _spoolss_PrinterMessageBox(pipes_struct *p,
9989 struct spoolss_PrinterMessageBox *r)
9991 p->rng_fault_state = true;
9992 return WERR_NOT_SUPPORTED;
9995 /****************************************************************
9997 ****************************************************************/
9999 WERROR _spoolss_AddMonitor(pipes_struct *p,
10000 struct spoolss_AddMonitor *r)
10002 p->rng_fault_state = true;
10003 return WERR_NOT_SUPPORTED;
10006 /****************************************************************
10007 _spoolss_DeleteMonitor
10008 ****************************************************************/
10010 WERROR _spoolss_DeleteMonitor(pipes_struct *p,
10011 struct spoolss_DeleteMonitor *r)
10013 p->rng_fault_state = true;
10014 return WERR_NOT_SUPPORTED;
10017 /****************************************************************
10018 _spoolss_DeletePrintProcessor
10019 ****************************************************************/
10021 WERROR _spoolss_DeletePrintProcessor(pipes_struct *p,
10022 struct spoolss_DeletePrintProcessor *r)
10024 p->rng_fault_state = true;
10025 return WERR_NOT_SUPPORTED;
10028 /****************************************************************
10029 _spoolss_AddPrintProvidor
10030 ****************************************************************/
10032 WERROR _spoolss_AddPrintProvidor(pipes_struct *p,
10033 struct spoolss_AddPrintProvidor *r)
10035 p->rng_fault_state = true;
10036 return WERR_NOT_SUPPORTED;
10039 /****************************************************************
10040 _spoolss_DeletePrintProvidor
10041 ****************************************************************/
10043 WERROR _spoolss_DeletePrintProvidor(pipes_struct *p,
10044 struct spoolss_DeletePrintProvidor *r)
10046 p->rng_fault_state = true;
10047 return WERR_NOT_SUPPORTED;
10050 /****************************************************************
10051 _spoolss_FindFirstPrinterChangeNotification
10052 ****************************************************************/
10054 WERROR _spoolss_FindFirstPrinterChangeNotification(pipes_struct *p,
10055 struct spoolss_FindFirstPrinterChangeNotification *r)
10057 p->rng_fault_state = true;
10058 return WERR_NOT_SUPPORTED;
10061 /****************************************************************
10062 _spoolss_FindNextPrinterChangeNotification
10063 ****************************************************************/
10065 WERROR _spoolss_FindNextPrinterChangeNotification(pipes_struct *p,
10066 struct spoolss_FindNextPrinterChangeNotification *r)
10068 p->rng_fault_state = true;
10069 return WERR_NOT_SUPPORTED;
10072 /****************************************************************
10073 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10074 ****************************************************************/
10076 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(pipes_struct *p,
10077 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
10079 p->rng_fault_state = true;
10080 return WERR_NOT_SUPPORTED;
10083 /****************************************************************
10084 _spoolss_ReplyOpenPrinter
10085 ****************************************************************/
10087 WERROR _spoolss_ReplyOpenPrinter(pipes_struct *p,
10088 struct spoolss_ReplyOpenPrinter *r)
10090 p->rng_fault_state = true;
10091 return WERR_NOT_SUPPORTED;
10094 /****************************************************************
10095 _spoolss_RouterReplyPrinter
10096 ****************************************************************/
10098 WERROR _spoolss_RouterReplyPrinter(pipes_struct *p,
10099 struct spoolss_RouterReplyPrinter *r)
10101 p->rng_fault_state = true;
10102 return WERR_NOT_SUPPORTED;
10105 /****************************************************************
10106 _spoolss_ReplyClosePrinter
10107 ****************************************************************/
10109 WERROR _spoolss_ReplyClosePrinter(pipes_struct *p,
10110 struct spoolss_ReplyClosePrinter *r)
10112 p->rng_fault_state = true;
10113 return WERR_NOT_SUPPORTED;
10116 /****************************************************************
10118 ****************************************************************/
10120 WERROR _spoolss_AddPortEx(pipes_struct *p,
10121 struct spoolss_AddPortEx *r)
10123 p->rng_fault_state = true;
10124 return WERR_NOT_SUPPORTED;
10127 /****************************************************************
10128 _spoolss_RouterFindFirstPrinterChangeNotification
10129 ****************************************************************/
10131 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(pipes_struct *p,
10132 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
10134 p->rng_fault_state = true;
10135 return WERR_NOT_SUPPORTED;
10138 /****************************************************************
10139 _spoolss_SpoolerInit
10140 ****************************************************************/
10142 WERROR _spoolss_SpoolerInit(pipes_struct *p,
10143 struct spoolss_SpoolerInit *r)
10145 p->rng_fault_state = true;
10146 return WERR_NOT_SUPPORTED;
10149 /****************************************************************
10150 _spoolss_ResetPrinterEx
10151 ****************************************************************/
10153 WERROR _spoolss_ResetPrinterEx(pipes_struct *p,
10154 struct spoolss_ResetPrinterEx *r)
10156 p->rng_fault_state = true;
10157 return WERR_NOT_SUPPORTED;
10160 /****************************************************************
10161 _spoolss_RouterReplyPrinterEx
10162 ****************************************************************/
10164 WERROR _spoolss_RouterReplyPrinterEx(pipes_struct *p,
10165 struct spoolss_RouterReplyPrinterEx *r)
10167 p->rng_fault_state = true;
10168 return WERR_NOT_SUPPORTED;
10171 /****************************************************************
10173 ****************************************************************/
10175 WERROR _spoolss_44(pipes_struct *p,
10176 struct spoolss_44 *r)
10178 p->rng_fault_state = true;
10179 return WERR_NOT_SUPPORTED;
10182 /****************************************************************
10184 ****************************************************************/
10186 WERROR _spoolss_47(pipes_struct *p,
10187 struct spoolss_47 *r)
10189 p->rng_fault_state = true;
10190 return WERR_NOT_SUPPORTED;
10193 /****************************************************************
10195 ****************************************************************/
10197 WERROR _spoolss_4a(pipes_struct *p,
10198 struct spoolss_4a *r)
10200 p->rng_fault_state = true;
10201 return WERR_NOT_SUPPORTED;
10204 /****************************************************************
10206 ****************************************************************/
10208 WERROR _spoolss_4b(pipes_struct *p,
10209 struct spoolss_4b *r)
10211 p->rng_fault_state = true;
10212 return WERR_NOT_SUPPORTED;
10215 /****************************************************************
10217 ****************************************************************/
10219 WERROR _spoolss_4c(pipes_struct *p,
10220 struct spoolss_4c *r)
10222 p->rng_fault_state = true;
10223 return WERR_NOT_SUPPORTED;
10226 /****************************************************************
10228 ****************************************************************/
10230 WERROR _spoolss_53(pipes_struct *p,
10231 struct spoolss_53 *r)
10233 p->rng_fault_state = true;
10234 return WERR_NOT_SUPPORTED;
10237 /****************************************************************
10239 ****************************************************************/
10241 WERROR _spoolss_55(pipes_struct *p,
10242 struct spoolss_55 *r)
10244 p->rng_fault_state = true;
10245 return WERR_NOT_SUPPORTED;
10248 /****************************************************************
10250 ****************************************************************/
10252 WERROR _spoolss_56(pipes_struct *p,
10253 struct spoolss_56 *r)
10255 p->rng_fault_state = true;
10256 return WERR_NOT_SUPPORTED;
10259 /****************************************************************
10261 ****************************************************************/
10263 WERROR _spoolss_57(pipes_struct *p,
10264 struct spoolss_57 *r)
10266 p->rng_fault_state = true;
10267 return WERR_NOT_SUPPORTED;
10270 /****************************************************************
10272 ****************************************************************/
10274 WERROR _spoolss_5a(pipes_struct *p,
10275 struct spoolss_5a *r)
10277 p->rng_fault_state = true;
10278 return WERR_NOT_SUPPORTED;
10281 /****************************************************************
10283 ****************************************************************/
10285 WERROR _spoolss_5b(pipes_struct *p,
10286 struct spoolss_5b *r)
10288 p->rng_fault_state = true;
10289 return WERR_NOT_SUPPORTED;
10292 /****************************************************************
10294 ****************************************************************/
10296 WERROR _spoolss_5c(pipes_struct *p,
10297 struct spoolss_5c *r)
10299 p->rng_fault_state = true;
10300 return WERR_NOT_SUPPORTED;
10303 /****************************************************************
10305 ****************************************************************/
10307 WERROR _spoolss_5d(pipes_struct *p,
10308 struct spoolss_5d *r)
10310 p->rng_fault_state = true;
10311 return WERR_NOT_SUPPORTED;
10314 /****************************************************************
10316 ****************************************************************/
10318 WERROR _spoolss_5e(pipes_struct *p,
10319 struct spoolss_5e *r)
10321 p->rng_fault_state = true;
10322 return WERR_NOT_SUPPORTED;
10325 /****************************************************************
10327 ****************************************************************/
10329 WERROR _spoolss_5f(pipes_struct *p,
10330 struct spoolss_5f *r)
10332 p->rng_fault_state = true;
10333 return WERR_NOT_SUPPORTED;