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",
595 (int)num_pipe_handles(p->pipe_handles)));
600 /***************************************************************************
601 check to see if the client motify handle is monitoring the notification
602 given by (notify_type, notify_field).
603 **************************************************************************/
605 static bool is_monitoring_event_flags(uint32_t flags, uint16_t notify_type,
606 uint16_t notify_field)
611 static bool is_monitoring_event(Printer_entry *p, uint16_t notify_type,
612 uint16_t notify_field)
614 struct spoolss_NotifyOption *option = p->notify.option;
618 * Flags should always be zero when the change notify
619 * is registered by the client's spooler. A user Win32 app
620 * might use the flags though instead of the NOTIFY_OPTION_INFO
629 return is_monitoring_event_flags(
630 p->notify.flags, notify_type, notify_field);
632 for (i = 0; i < option->count; i++) {
634 /* Check match for notify_type */
636 if (option->types[i].type != notify_type)
639 /* Check match for field */
641 for (j = 0; j < option->types[i].count; j++) {
642 if (option->types[i].fields[j].field == notify_field) {
648 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
649 p->servername, p->sharename, notify_type, notify_field));
654 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
655 _data->data.integer[0] = _integer; \
656 _data->data.integer[1] = 0;
659 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
660 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
661 if (!_data->data.string.string) {\
662 _data->data.string.size = 0; \
664 _data->data.string.size = strlen_m_term(_p) * 2;
666 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
667 _data->data.devmode.devmode = _devmode;
669 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _size, _sd) \
670 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
671 if (!_data->data.sd.sd) { \
672 _data->data.sd.sd_size = 0; \
674 _data->data.sd.sd_size = _size;
676 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
681 struct spoolss_Time st;
685 if (!init_systemtime(&st, t)) {
689 p = talloc_array(mem_ctx, char, len);
695 * Systemtime must be linearized as a set of UINT16's.
696 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
699 SSVAL(p, 0, st.year);
700 SSVAL(p, 2, st.month);
701 SSVAL(p, 4, st.day_of_week);
703 SSVAL(p, 8, st.hour);
704 SSVAL(p, 10, st.minute);
705 SSVAL(p, 12, st.second);
706 SSVAL(p, 14, st.millisecond);
712 /* Convert a notification message to a struct spoolss_Notify */
714 static void notify_one_value(struct spoolss_notify_msg *msg,
715 struct spoolss_Notify *data,
718 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, msg->notify.value[0]);
721 static void notify_string(struct spoolss_notify_msg *msg,
722 struct spoolss_Notify *data,
725 /* The length of the message includes the trailing \0 */
727 data->data.string.size = msg->len * 2;
728 data->data.string.string = talloc_strdup(mem_ctx, msg->notify.data);
729 if (!data->data.string.string) {
730 data->data.string.size = 0;
735 static void notify_system_time(struct spoolss_notify_msg *msg,
736 struct spoolss_Notify *data,
739 data->data.string.string = NULL;
740 data->data.string.size = 0;
742 if (msg->len != sizeof(time_t)) {
743 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
748 init_systemtime_buffer(mem_ctx, gmtime((time_t *)msg->notify.data),
749 &data->data.string.string,
750 &data->data.string.size);
753 struct notify2_message_table {
755 void (*fn)(struct spoolss_notify_msg *msg,
756 struct spoolss_Notify *data, TALLOC_CTX *mem_ctx);
759 static struct notify2_message_table printer_notify_table[] = {
760 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string },
761 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string },
762 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string },
763 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string },
764 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string },
765 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string },
766 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string },
767 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL },
768 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string },
769 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string },
770 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL },
771 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string },
772 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
773 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value },
774 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value },
775 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL },
776 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL },
777 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL },
778 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value },
781 static struct notify2_message_table job_notify_table[] = {
782 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL },
783 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL },
784 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL },
785 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string },
786 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL },
787 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL },
788 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL },
789 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL },
790 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL },
791 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL },
792 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value },
793 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL },
794 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
795 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string },
796 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL },
797 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL },
798 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time },
799 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL },
800 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL },
801 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL },
802 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value },
803 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL },
804 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value },
805 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL },
809 /***********************************************************************
810 Allocate talloc context for container object
811 **********************************************************************/
813 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
818 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
823 /***********************************************************************
824 release all allocated memory and zero out structure
825 **********************************************************************/
827 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
833 talloc_destroy(ctr->ctx);
840 /***********************************************************************
841 **********************************************************************/
843 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
851 /***********************************************************************
852 **********************************************************************/
854 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
856 if ( !ctr || !ctr->msg_groups )
859 if ( idx >= ctr->num_groups )
862 return &ctr->msg_groups[idx];
866 /***********************************************************************
867 How many groups of change messages do we have ?
868 **********************************************************************/
870 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
875 return ctr->num_groups;
878 /***********************************************************************
879 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
880 **********************************************************************/
882 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
884 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
885 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
886 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
892 /* loop over all groups looking for a matching printer name */
894 for ( i=0; i<ctr->num_groups; i++ ) {
895 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
899 /* add a new group? */
901 if ( i == ctr->num_groups ) {
904 if ( !(groups = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
905 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
908 ctr->msg_groups = groups;
910 /* clear the new entry and set the printer name */
912 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
913 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
916 /* add the change messages; 'i' is the correct index now regardless */
918 msg_grp = &ctr->msg_groups[i];
922 if ( !(msg_list = TALLOC_REALLOC_ARRAY( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
923 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
926 msg_grp->msgs = msg_list;
928 new_slot = msg_grp->num_msgs-1;
929 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
931 /* need to allocate own copy of data */
934 msg_grp->msgs[new_slot].notify.data = (char *)
935 TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len );
937 return ctr->num_groups;
940 /***********************************************************************
941 Send a change notication message on all handles which have a call
943 **********************************************************************/
945 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
948 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
949 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
950 SPOOLSS_NOTIFY_MSG *messages;
951 int sending_msg_count;
954 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
958 messages = msg_group->msgs;
961 DEBUG(5,("send_notify2_changes() called with no messages!\n"));
965 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
967 /* loop over all printers */
969 for (p = printers_list; p; p = p->next) {
970 struct spoolss_Notify *notifies;
975 /* Is there notification on this handle? */
977 if ( !p->notify.client_connected )
980 DEBUG(10,("Client connected! [\\\\%s\\%s]\n", p->servername, p->sharename));
982 /* For this printer? Print servers always receive
985 if ( ( p->printer_type == SPLHND_PRINTER ) &&
986 ( !strequal(msg_group->printername, p->sharename) ) )
989 DEBUG(10,("Our printer\n"));
991 /* allocate the max entries possible */
993 notifies = TALLOC_ZERO_ARRAY(mem_ctx, struct spoolss_Notify, msg_group->num_msgs);
998 /* build the array of change notifications */
1000 sending_msg_count = 0;
1002 for ( i=0; i<msg_group->num_msgs; i++ ) {
1003 SPOOLSS_NOTIFY_MSG *msg = &messages[i];
1005 /* Are we monitoring this event? */
1007 if (!is_monitoring_event(p, msg->type, msg->field))
1010 sending_msg_count++;
1013 DEBUG(10,("process_notify2_message: Sending message type [0x%x] field [0x%2x] for printer [%s]\n",
1014 msg->type, msg->field, p->sharename));
1017 * if the is a printer notification handle and not a job notification
1018 * type, then set the id to 0. Other wise just use what was specified
1021 * When registering change notification on a print server handle
1022 * we always need to send back the id (snum) matching the printer
1023 * for which the change took place. For change notify registered
1024 * on a printer handle, this does not matter and the id should be 0.
1029 if ( ( p->printer_type == SPLHND_PRINTER ) && ( msg->type == PRINTER_NOTIFY_TYPE ) )
1035 /* Convert unix jobid to smb jobid */
1037 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1038 id = sysjob_to_jobid(msg->id);
1041 DEBUG(3, ("no such unix jobid %d\n", msg->id));
1046 construct_info_data( ¬ifies[count], msg->type, msg->field, id );
1049 case PRINTER_NOTIFY_TYPE:
1050 if ( printer_notify_table[msg->field].fn )
1051 printer_notify_table[msg->field].fn(msg, ¬ifies[count], mem_ctx);
1054 case JOB_NOTIFY_TYPE:
1055 if ( job_notify_table[msg->field].fn )
1056 job_notify_table[msg->field].fn(msg, ¬ifies[count], mem_ctx);
1060 DEBUG(5, ("Unknown notification type %d\n", msg->type));
1067 if ( sending_msg_count ) {
1070 union spoolss_ReplyPrinterInfo info;
1071 struct spoolss_NotifyInfo info0;
1072 uint32_t reply_result;
1074 info0.version = 0x2;
1075 info0.flags = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
1076 info0.count = count;
1077 info0.notifies = notifies;
1079 info.info0 = &info0;
1081 status = rpccli_spoolss_RouterReplyPrinterEx(notify_cli_pipe, mem_ctx,
1082 &p->notify.client_hnd,
1083 p->notify.change, /* color */
1086 0, /* reply_type, must be 0 */
1089 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) {
1090 DEBUG(1,("RouterReplyPrinterEx to client: %s failed: %s\n",
1091 notify_cli_pipe->srv_name_slash,
1094 switch (reply_result) {
1097 case PRINTER_NOTIFY_INFO_DISCARDED:
1098 case PRINTER_NOTIFY_INFO_DISCARDNOTED:
1099 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
1108 DEBUG(8,("send_notify2_changes: Exit...\n"));
1112 /***********************************************************************
1113 **********************************************************************/
1115 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1118 uint32_t tv_sec, tv_usec;
1121 /* Unpack message */
1123 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "f",
1126 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "ddddddd",
1128 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1131 tdb_unpack((uint8_t *)buf + offset, len - offset, "dd",
1132 &msg->notify.value[0], &msg->notify.value[1]);
1134 tdb_unpack((uint8_t *)buf + offset, len - offset, "B",
1135 &msg->len, &msg->notify.data);
1137 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1138 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1140 tv->tv_sec = tv_sec;
1141 tv->tv_usec = tv_usec;
1144 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1145 msg->notify.value[1]));
1147 dump_data(3, (uint8_t *)msg->notify.data, msg->len);
1152 /********************************************************************
1153 Receive a notify2 message list
1154 ********************************************************************/
1156 static void receive_notify2_message_list(struct messaging_context *msg,
1159 struct server_id server_id,
1162 size_t msg_count, i;
1163 char *buf = (char *)data->data;
1166 SPOOLSS_NOTIFY_MSG notify;
1167 SPOOLSS_NOTIFY_MSG_CTR messages;
1170 if (data->length < 4) {
1171 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1175 msg_count = IVAL(buf, 0);
1178 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1180 if (msg_count == 0) {
1181 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1185 /* initialize the container */
1187 ZERO_STRUCT( messages );
1188 notify_msg_ctr_init( &messages );
1191 * build message groups for each printer identified
1192 * in a change_notify msg. Remember that a PCN message
1193 * includes the handle returned for the srv_spoolss_replyopenprinter()
1194 * call. Therefore messages are grouped according to printer handle.
1197 for ( i=0; i<msg_count; i++ ) {
1198 struct timeval msg_tv;
1200 if (msg_ptr + 4 - buf > data->length) {
1201 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1205 msg_len = IVAL(msg_ptr,0);
1208 if (msg_ptr + msg_len - buf > data->length) {
1209 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1213 /* unpack messages */
1215 ZERO_STRUCT( notify );
1216 notify2_unpack_msg( ¬ify, &msg_tv, msg_ptr, msg_len );
1219 /* add to correct list in container */
1221 notify_msg_ctr_addmsg( &messages, ¬ify );
1223 /* free memory that might have been allocated by notify2_unpack_msg() */
1225 if ( notify.len != 0 )
1226 SAFE_FREE( notify.notify.data );
1229 /* process each group of messages */
1231 num_groups = notify_msg_ctr_numgroups( &messages );
1232 for ( i=0; i<num_groups; i++ )
1233 send_notify2_changes( &messages, i );
1238 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1239 (uint32_t)msg_count ));
1241 notify_msg_ctr_destroy( &messages );
1246 /********************************************************************
1247 Send a message to ourself about new driver being installed
1248 so we can upgrade the information for each printer bound to this
1250 ********************************************************************/
1252 static bool srv_spoolss_drv_upgrade_printer(const char *drivername)
1254 int len = strlen(drivername);
1259 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1262 messaging_send_buf(smbd_messaging_context(), procid_self(),
1263 MSG_PRINTER_DRVUPGRADE,
1264 (uint8_t *)drivername, len+1);
1269 /**********************************************************************
1270 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1271 over all printers, upgrading ones as necessary
1272 **********************************************************************/
1274 void do_drv_upgrade_printer(struct messaging_context *msg,
1277 struct server_id server_id,
1282 int n_services = lp_numservices();
1285 len = MIN(data->length,sizeof(drivername)-1);
1286 strncpy(drivername, (const char *)data->data, len);
1288 DEBUG(10,("do_drv_upgrade_printer: Got message for new driver [%s]\n", drivername ));
1290 /* Iterate the printer list */
1292 for (snum=0; snum<n_services; snum++)
1294 if (lp_snum_ok(snum) && lp_print_ok(snum) )
1297 NT_PRINTER_INFO_LEVEL *printer = NULL;
1299 result = get_a_printer(NULL, &printer, 2, lp_const_servicename(snum));
1300 if (!W_ERROR_IS_OK(result))
1303 if (printer && printer->info_2 && !strcmp(drivername, printer->info_2->drivername))
1305 DEBUG(6,("Updating printer [%s]\n", printer->info_2->printername));
1307 /* all we care about currently is the change_id */
1309 result = mod_a_printer(printer, 2);
1310 if (!W_ERROR_IS_OK(result)) {
1311 DEBUG(3,("do_drv_upgrade_printer: mod_a_printer() failed with status [%s]\n",
1312 win_errstr(result)));
1316 free_a_printer(&printer, 2);
1323 /********************************************************************
1324 Update the cache for all printq's with a registered client
1326 ********************************************************************/
1328 void update_monitored_printq_cache( void )
1330 Printer_entry *printer = printers_list;
1333 /* loop through all printers and update the cache where
1334 client_connected == true */
1337 if ( (printer->printer_type == SPLHND_PRINTER)
1338 && printer->notify.client_connected )
1340 snum = print_queue_snum(printer->sharename);
1341 print_queue_status( snum, NULL, NULL );
1344 printer = printer->next;
1349 /********************************************************************
1350 Send a message to ourself about new driver being installed
1351 so we can upgrade the information for each printer bound to this
1353 ********************************************************************/
1355 static bool srv_spoolss_reset_printerdata(char* drivername)
1357 int len = strlen(drivername);
1362 DEBUG(10,("srv_spoolss_reset_printerdata: Sending message about resetting printerdata [%s]\n",
1365 messaging_send_buf(smbd_messaging_context(), procid_self(),
1366 MSG_PRINTERDATA_INIT_RESET,
1367 (uint8_t *)drivername, len+1);
1372 /**********************************************************************
1373 callback to receive a MSG_PRINTERDATA_INIT_RESET message and interate
1374 over all printers, resetting printer data as neessary
1375 **********************************************************************/
1377 void reset_all_printerdata(struct messaging_context *msg,
1380 struct server_id server_id,
1385 int n_services = lp_numservices();
1388 len = MIN( data->length, sizeof(drivername)-1 );
1389 strncpy( drivername, (const char *)data->data, len );
1391 DEBUG(10,("reset_all_printerdata: Got message for new driver [%s]\n", drivername ));
1393 /* Iterate the printer list */
1395 for ( snum=0; snum<n_services; snum++ )
1397 if ( lp_snum_ok(snum) && lp_print_ok(snum) )
1400 NT_PRINTER_INFO_LEVEL *printer = NULL;
1402 result = get_a_printer( NULL, &printer, 2, lp_const_servicename(snum) );
1403 if ( !W_ERROR_IS_OK(result) )
1407 * if the printer is bound to the driver,
1408 * then reset to the new driver initdata
1411 if ( printer && printer->info_2 && !strcmp(drivername, printer->info_2->drivername) )
1413 DEBUG(6,("reset_all_printerdata: Updating printer [%s]\n", printer->info_2->printername));
1415 if ( !set_driver_init(printer, 2) ) {
1416 DEBUG(5,("reset_all_printerdata: Error resetting printer data for printer [%s], driver [%s]!\n",
1417 printer->info_2->printername, printer->info_2->drivername));
1420 result = mod_a_printer( printer, 2 );
1421 if ( !W_ERROR_IS_OK(result) ) {
1422 DEBUG(3,("reset_all_printerdata: mod_a_printer() failed! (%s)\n",
1423 get_dos_error_msg(result)));
1427 free_a_printer( &printer, 2 );
1436 /****************************************************************
1437 _spoolss_OpenPrinter
1438 ****************************************************************/
1440 WERROR _spoolss_OpenPrinter(pipes_struct *p,
1441 struct spoolss_OpenPrinter *r)
1443 struct spoolss_OpenPrinterEx e;
1446 ZERO_STRUCT(e.in.userlevel);
1448 e.in.printername = r->in.printername;
1449 e.in.datatype = r->in.datatype;
1450 e.in.devmode_ctr = r->in.devmode_ctr;
1451 e.in.access_mask = r->in.access_mask;
1454 e.out.handle = r->out.handle;
1456 werr = _spoolss_OpenPrinterEx(p, &e);
1458 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1459 /* OpenPrinterEx returns this for a bad
1460 * printer name. We must return WERR_INVALID_PRINTER_NAME
1463 werr = WERR_INVALID_PRINTER_NAME;
1469 /********************************************************************
1470 ********************************************************************/
1472 bool convert_devicemode(const char *printername,
1473 const struct spoolss_DeviceMode *devmode,
1474 NT_DEVICEMODE **pp_nt_devmode)
1476 NT_DEVICEMODE *nt_devmode = *pp_nt_devmode;
1479 * Ensure nt_devmode is a valid pointer
1480 * as we will be overwriting it.
1483 if (nt_devmode == NULL) {
1484 DEBUG(5, ("convert_devicemode: allocating a generic devmode\n"));
1485 if ((nt_devmode = construct_nt_devicemode(printername)) == NULL)
1489 rpcstr_push(nt_devmode->devicename, devmode->devicename, 31, 0);
1490 rpcstr_push(nt_devmode->formname, devmode->formname, 31, 0);
1492 nt_devmode->specversion = devmode->specversion;
1493 nt_devmode->driverversion = devmode->driverversion;
1494 nt_devmode->size = devmode->size;
1495 nt_devmode->fields = devmode->fields;
1496 nt_devmode->orientation = devmode->orientation;
1497 nt_devmode->papersize = devmode->papersize;
1498 nt_devmode->paperlength = devmode->paperlength;
1499 nt_devmode->paperwidth = devmode->paperwidth;
1500 nt_devmode->scale = devmode->scale;
1501 nt_devmode->copies = devmode->copies;
1502 nt_devmode->defaultsource = devmode->defaultsource;
1503 nt_devmode->printquality = devmode->printquality;
1504 nt_devmode->color = devmode->color;
1505 nt_devmode->duplex = devmode->duplex;
1506 nt_devmode->yresolution = devmode->yresolution;
1507 nt_devmode->ttoption = devmode->ttoption;
1508 nt_devmode->collate = devmode->collate;
1510 nt_devmode->logpixels = devmode->logpixels;
1511 nt_devmode->bitsperpel = devmode->bitsperpel;
1512 nt_devmode->pelswidth = devmode->pelswidth;
1513 nt_devmode->pelsheight = devmode->pelsheight;
1514 nt_devmode->displayflags = devmode->displayflags;
1515 nt_devmode->displayfrequency = devmode->displayfrequency;
1516 nt_devmode->icmmethod = devmode->icmmethod;
1517 nt_devmode->icmintent = devmode->icmintent;
1518 nt_devmode->mediatype = devmode->mediatype;
1519 nt_devmode->dithertype = devmode->dithertype;
1520 nt_devmode->reserved1 = devmode->reserved1;
1521 nt_devmode->reserved2 = devmode->reserved2;
1522 nt_devmode->panningwidth = devmode->panningwidth;
1523 nt_devmode->panningheight = devmode->panningheight;
1526 * Only change private and driverextra if the incoming devmode
1527 * has a new one. JRA.
1530 if ((devmode->__driverextra_length != 0) && (devmode->driverextra_data.data != NULL)) {
1531 SAFE_FREE(nt_devmode->nt_dev_private);
1532 nt_devmode->driverextra = devmode->__driverextra_length;
1533 if((nt_devmode->nt_dev_private = SMB_MALLOC_ARRAY(uint8_t, nt_devmode->driverextra)) == NULL)
1535 memcpy(nt_devmode->nt_dev_private, devmode->driverextra_data.data, nt_devmode->driverextra);
1538 *pp_nt_devmode = nt_devmode;
1543 /****************************************************************
1544 _spoolss_OpenPrinterEx
1545 ****************************************************************/
1547 WERROR _spoolss_OpenPrinterEx(pipes_struct *p,
1548 struct spoolss_OpenPrinterEx *r)
1551 Printer_entry *Printer=NULL;
1553 if (!r->in.printername) {
1554 return WERR_INVALID_PARAM;
1557 /* some sanity check because you can open a printer or a print server */
1558 /* aka: \\server\printer or \\server */
1560 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1562 if (!open_printer_hnd(p, r->out.handle, r->in.printername, 0)) {
1563 ZERO_STRUCTP(r->out.handle);
1564 return WERR_INVALID_PARAM;
1567 Printer = find_printer_index_by_hnd(p, r->out.handle);
1569 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1570 "handle we created for printer %s\n", r->in.printername));
1571 close_printer_handle(p, r->out.handle);
1572 ZERO_STRUCTP(r->out.handle);
1573 return WERR_INVALID_PARAM;
1577 * First case: the user is opening the print server:
1579 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1580 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1582 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1583 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1584 * or if the user is listed in the smb.conf printer admin parameter.
1586 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1587 * client view printer folder, but does not show the MSAPW.
1589 * Note: this test needs code to check access rights here too. Jeremy
1590 * could you look at this?
1592 * Second case: the user is opening a printer:
1593 * NT doesn't let us connect to a printer if the connecting user
1594 * doesn't have print permission.
1596 * Third case: user is opening a Port Monitor
1597 * access checks same as opening a handle to the print server.
1600 switch (Printer->printer_type )
1603 case SPLHND_PORTMON_TCP:
1604 case SPLHND_PORTMON_LOCAL:
1605 /* Printserver handles use global struct... */
1609 /* Map standard access rights to object specific access rights */
1611 se_map_standard(&r->in.access_mask,
1612 &printserver_std_mapping);
1614 /* Deny any object specific bits that don't apply to print
1615 servers (i.e printer and job specific bits) */
1617 r->in.access_mask &= SPECIFIC_RIGHTS_MASK;
1619 if (r->in.access_mask &
1620 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1621 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1622 close_printer_handle(p, r->out.handle);
1623 ZERO_STRUCTP(r->out.handle);
1624 return WERR_ACCESS_DENIED;
1627 /* Allow admin access */
1629 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1631 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1633 if (!lp_ms_add_printer_wizard()) {
1634 close_printer_handle(p, r->out.handle);
1635 ZERO_STRUCTP(r->out.handle);
1636 return WERR_ACCESS_DENIED;
1639 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1640 and not a printer admin, then fail */
1642 if ((p->server_info->utok.uid != sec_initial_uid()) &&
1643 !user_has_privileges(p->server_info->ptok,
1645 !token_contains_name_in_list(
1646 uidtoname(p->server_info->utok.uid),
1648 p->server_info->ptok,
1649 lp_printer_admin(snum))) {
1650 close_printer_handle(p, r->out.handle);
1651 ZERO_STRUCTP(r->out.handle);
1652 return WERR_ACCESS_DENIED;
1655 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1659 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1662 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1663 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1665 /* We fall through to return WERR_OK */
1668 case SPLHND_PRINTER:
1669 /* NT doesn't let us connect to a printer if the connecting user
1670 doesn't have print permission. */
1672 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1673 close_printer_handle(p, r->out.handle);
1674 ZERO_STRUCTP(r->out.handle);
1678 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1680 /* map an empty access mask to the minimum access mask */
1681 if (r->in.access_mask == 0x0)
1682 r->in.access_mask = PRINTER_ACCESS_USE;
1685 * If we are not serving the printer driver for this printer,
1686 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1687 * will keep NT clients happy --jerry
1690 if (lp_use_client_driver(snum)
1691 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1693 r->in.access_mask = PRINTER_ACCESS_USE;
1696 /* check smb.conf parameters and the the sec_desc */
1698 if ( !check_access(get_client_fd(), lp_hostsallow(snum), lp_hostsdeny(snum)) ) {
1699 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1700 ZERO_STRUCTP(r->out.handle);
1701 return WERR_ACCESS_DENIED;
1704 if (!user_ok_token(uidtoname(p->server_info->utok.uid), NULL,
1705 p->server_info->ptok, snum) ||
1706 !print_access_check(p->server_info, snum,
1707 r->in.access_mask)) {
1708 DEBUG(3, ("access DENIED for printer open\n"));
1709 close_printer_handle(p, r->out.handle);
1710 ZERO_STRUCTP(r->out.handle);
1711 return WERR_ACCESS_DENIED;
1714 if ((r->in.access_mask & SPECIFIC_RIGHTS_MASK)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1715 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1716 close_printer_handle(p, r->out.handle);
1717 ZERO_STRUCTP(r->out.handle);
1718 return WERR_ACCESS_DENIED;
1721 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1722 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1724 r->in.access_mask = PRINTER_ACCESS_USE;
1726 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1727 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1732 /* sanity check to prevent programmer error */
1733 ZERO_STRUCTP(r->out.handle);
1737 Printer->access_granted = r->in.access_mask;
1740 * If the client sent a devmode in the OpenPrinter() call, then
1741 * save it here in case we get a job submission on this handle
1744 if ((Printer->printer_type != SPLHND_SERVER) &&
1745 r->in.devmode_ctr.devmode) {
1746 convert_devicemode(Printer->sharename,
1747 r->in.devmode_ctr.devmode,
1748 &Printer->nt_devmode);
1751 #if 0 /* JERRY -- I'm doubtful this is really effective */
1752 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1753 optimization in Windows 2000 clients --jerry */
1755 if ( (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1756 && (RA_WIN2K == get_remote_arch()) )
1758 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1759 sys_usleep( 500000 );
1766 /****************************************************************************
1767 ****************************************************************************/
1769 static bool printer_info2_to_nt_printer_info2(struct spoolss_SetPrinterInfo2 *r,
1770 NT_PRINTER_INFO_LEVEL_2 *d)
1772 DEBUG(7,("printer_info2_to_nt_printer_info2\n"));
1778 d->attributes = r->attributes;
1779 d->priority = r->priority;
1780 d->default_priority = r->defaultpriority;
1781 d->starttime = r->starttime;
1782 d->untiltime = r->untiltime;
1783 d->status = r->status;
1784 d->cjobs = r->cjobs;
1786 fstrcpy(d->servername, r->servername);
1787 fstrcpy(d->printername, r->printername);
1788 fstrcpy(d->sharename, r->sharename);
1789 fstrcpy(d->portname, r->portname);
1790 fstrcpy(d->drivername, r->drivername);
1791 slprintf(d->comment, sizeof(d->comment)-1, "%s", r->comment);
1792 fstrcpy(d->location, r->location);
1793 fstrcpy(d->sepfile, r->sepfile);
1794 fstrcpy(d->printprocessor, r->printprocessor);
1795 fstrcpy(d->datatype, r->datatype);
1796 fstrcpy(d->parameters, r->parameters);
1801 /****************************************************************************
1802 ****************************************************************************/
1804 static bool convert_printer_info(struct spoolss_SetPrinterInfoCtr *info_ctr,
1805 NT_PRINTER_INFO_LEVEL *printer)
1809 switch (info_ctr->level) {
1811 /* allocate memory if needed. Messy because
1812 convert_printer_info is used to update an existing
1813 printer or build a new one */
1815 if (!printer->info_2) {
1816 printer->info_2 = TALLOC_ZERO_P(printer, NT_PRINTER_INFO_LEVEL_2);
1817 if (!printer->info_2) {
1818 DEBUG(0,("convert_printer_info: "
1819 "talloc() failed!\n"));
1824 ret = printer_info2_to_nt_printer_info2(info_ctr->info.info2,
1826 printer->info_2->setuptime = time(NULL);
1833 /*******************************************************************
1834 ********************************************************************/
1836 static bool string_array_to_fstring_array(const char **sarray, fstring **farray)
1845 *farray = SMB_MALLOC_ARRAY(fstring, 1);
1850 for (i=0; sarray[i] != NULL; i++) {
1851 *farray = SMB_REALLOC_ARRAY(*farray, fstring, i+2);
1855 fstrcpy((*farray)[i], sarray[i]);
1858 fstrcpy((*farray)[i], "");
1863 /*******************************************************************
1864 ********************************************************************/
1866 static bool driver_info3_to_nt_driver_info3(struct spoolss_AddDriverInfo3 *r,
1867 NT_PRINTER_DRIVER_INFO_LEVEL_3 **p)
1869 NT_PRINTER_DRIVER_INFO_LEVEL_3 *d;
1871 DEBUG(7,("driver_info3_to_nt_driver_info3: Converting from UNICODE to ASCII\n"));
1874 *p = SMB_MALLOC_P(NT_PRINTER_DRIVER_INFO_LEVEL_3);
1883 d->cversion = r->version;
1885 fstrcpy(d->name, r->driver_name);
1886 fstrcpy(d->environment, r->architecture);
1887 fstrcpy(d->driverpath, r->driver_path);
1888 fstrcpy(d->datafile, r->data_file);
1889 fstrcpy(d->configfile, r->config_file);
1890 fstrcpy(d->helpfile, r->help_file);
1891 fstrcpy(d->monitorname, r->monitor_name);
1892 fstrcpy(d->defaultdatatype, r->default_datatype);
1894 DEBUGADD(8,( "version: %d\n", d->cversion));
1895 DEBUGADD(8,( "name: %s\n", d->name));
1896 DEBUGADD(8,( "environment: %s\n", d->environment));
1897 DEBUGADD(8,( "driverpath: %s\n", d->driverpath));
1898 DEBUGADD(8,( "datafile: %s\n", d->datafile));
1899 DEBUGADD(8,( "configfile: %s\n", d->configfile));
1900 DEBUGADD(8,( "helpfile: %s\n", d->helpfile));
1901 DEBUGADD(8,( "monitorname: %s\n", d->monitorname));
1902 DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
1904 if (r->dependent_files) {
1905 if (!string_array_to_fstring_array(r->dependent_files->string,
1906 &d->dependentfiles)) {
1915 /*******************************************************************
1916 ********************************************************************/
1918 static bool driver_info6_to_nt_driver_info6(struct spoolss_AddDriverInfo6 *r,
1919 NT_PRINTER_DRIVER_INFO_LEVEL_6 **p)
1921 NT_PRINTER_DRIVER_INFO_LEVEL_6 *d;
1923 DEBUG(7,("driver_info6_to_nt_driver_info6: Converting from UNICODE to ASCII\n"));
1926 *p = SMB_MALLOC_P(NT_PRINTER_DRIVER_INFO_LEVEL_6);
1935 d->version = r->version;
1937 fstrcpy(d->name, r->driver_name);
1938 fstrcpy(d->environment, r->architecture);
1939 fstrcpy(d->driverpath, r->driver_path);
1940 fstrcpy(d->datafile, r->data_file);
1941 fstrcpy(d->configfile, r->config_file);
1942 fstrcpy(d->helpfile, r->help_file);
1943 fstrcpy(d->monitorname, r->monitor_name);
1944 fstrcpy(d->defaultdatatype, r->default_datatype);
1946 DEBUGADD(8,( "version: %d\n", d->version));
1947 DEBUGADD(8,( "name: %s\n", d->name));
1948 DEBUGADD(8,( "environment: %s\n", d->environment));
1949 DEBUGADD(8,( "driverpath: %s\n", d->driverpath));
1950 DEBUGADD(8,( "datafile: %s\n", d->datafile));
1951 DEBUGADD(8,( "configfile: %s\n", d->configfile));
1952 DEBUGADD(8,( "helpfile: %s\n", d->helpfile));
1953 DEBUGADD(8,( "monitorname: %s\n", d->monitorname));
1954 DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
1956 if (r->dependent_files) {
1957 if (!string_array_to_fstring_array(r->dependent_files->string,
1958 &d->dependentfiles)) {
1963 if (r->previous_names) {
1964 if (!string_array_to_fstring_array(r->previous_names->string,
1965 &d->previousnames)) {
1977 /********************************************************************
1978 ********************************************************************/
1980 static bool convert_printer_driver_info(const struct spoolss_AddDriverInfoCtr *r,
1981 NT_PRINTER_DRIVER_INFO_LEVEL *printer,
1986 printer->info_3 = NULL;
1987 if (!driver_info3_to_nt_driver_info3(r->info.info3, &printer->info_3)) {
1992 printer->info_6 = NULL;
1993 if (!driver_info6_to_nt_driver_info6(r->info.info6, &printer->info_6)) {
2004 /********************************************************************
2005 * _spoolss_enddocprinter_internal.
2006 ********************************************************************/
2008 static WERROR _spoolss_enddocprinter_internal(pipes_struct *p,
2009 struct policy_handle *handle)
2011 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
2015 DEBUG(2,("_spoolss_enddocprinter_internal: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle)));
2019 if (!get_printer_snum(p, handle, &snum, NULL))
2022 Printer->document_started = false;
2023 print_job_end(snum, Printer->jobid,NORMAL_CLOSE);
2024 /* error codes unhandled so far ... */
2029 /****************************************************************
2030 _spoolss_ClosePrinter
2031 ****************************************************************/
2033 WERROR _spoolss_ClosePrinter(pipes_struct *p,
2034 struct spoolss_ClosePrinter *r)
2036 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
2038 if (Printer && Printer->document_started)
2039 _spoolss_enddocprinter_internal(p, r->in.handle); /* print job was not closed */
2041 if (!close_printer_handle(p, r->in.handle))
2044 /* clear the returned printer handle. Observed behavior
2045 from Win2k server. Don't think this really matters.
2046 Previous code just copied the value of the closed
2049 ZERO_STRUCTP(r->out.handle);
2054 /****************************************************************
2055 _spoolss_DeletePrinter
2056 ****************************************************************/
2058 WERROR _spoolss_DeletePrinter(pipes_struct *p,
2059 struct spoolss_DeletePrinter *r)
2061 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
2064 if (Printer && Printer->document_started)
2065 _spoolss_enddocprinter_internal(p, r->in.handle); /* print job was not closed */
2067 result = delete_printer_handle(p, r->in.handle);
2069 update_c_setprinter(false);
2074 /*******************************************************************
2075 * static function to lookup the version id corresponding to an
2076 * long architecture string
2077 ******************************************************************/
2079 static int get_version_id(const char *arch)
2082 struct table_node archi_table[]= {
2084 {"Windows 4.0", "WIN40", 0 },
2085 {"Windows NT x86", "W32X86", 2 },
2086 {"Windows NT R4000", "W32MIPS", 2 },
2087 {"Windows NT Alpha_AXP", "W32ALPHA", 2 },
2088 {"Windows NT PowerPC", "W32PPC", 2 },
2089 {"Windows IA64", "IA64", 3 },
2090 {"Windows x64", "x64", 3 },
2094 for (i=0; archi_table[i].long_archi != NULL; i++)
2096 if (strcmp(arch, archi_table[i].long_archi) == 0)
2097 return (archi_table[i].version);
2103 /****************************************************************
2104 _spoolss_DeletePrinterDriver
2105 ****************************************************************/
2107 WERROR _spoolss_DeletePrinterDriver(pipes_struct *p,
2108 struct spoolss_DeletePrinterDriver *r)
2110 NT_PRINTER_DRIVER_INFO_LEVEL info;
2111 NT_PRINTER_DRIVER_INFO_LEVEL info_win2k;
2114 WERROR status_win2k = WERR_ACCESS_DENIED;
2115 SE_PRIV se_printop = SE_PRINT_OPERATOR;
2117 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2118 and not a printer admin, then fail */
2120 if ( (p->server_info->utok.uid != sec_initial_uid())
2121 && !user_has_privileges(p->server_info->ptok, &se_printop )
2122 && !token_contains_name_in_list(
2123 uidtoname(p->server_info->utok.uid), NULL,
2124 NULL, p->server_info->ptok,
2125 lp_printer_admin(-1)) )
2127 return WERR_ACCESS_DENIED;
2130 /* check that we have a valid driver name first */
2132 if ((version = get_version_id(r->in.architecture)) == -1)
2133 return WERR_INVALID_ENVIRONMENT;
2136 ZERO_STRUCT(info_win2k);
2138 if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, r->in.driver,
2142 /* try for Win2k driver if "Windows NT x86" */
2144 if ( version == 2 ) {
2146 if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3,
2150 status = WERR_UNKNOWN_PRINTER_DRIVER;
2154 /* otherwise it was a failure */
2156 status = WERR_UNKNOWN_PRINTER_DRIVER;
2162 if (printer_driver_in_use(info.info_3)) {
2163 status = WERR_PRINTER_DRIVER_IN_USE;
2169 if (W_ERROR_IS_OK(get_a_printer_driver(&info_win2k, 3,
2171 r->in.architecture, 3)))
2173 /* if we get to here, we now have 2 driver info structures to remove */
2174 /* remove the Win2k driver first*/
2176 status_win2k = delete_printer_driver(
2177 p, info_win2k.info_3, 3, false);
2178 free_a_printer_driver( info_win2k, 3 );
2180 /* this should not have failed---if it did, report to client */
2181 if ( !W_ERROR_IS_OK(status_win2k) )
2183 status = status_win2k;
2189 status = delete_printer_driver(p, info.info_3, version, false);
2191 /* if at least one of the deletes succeeded return OK */
2193 if ( W_ERROR_IS_OK(status) || W_ERROR_IS_OK(status_win2k) )
2197 free_a_printer_driver( info, 3 );
2202 /****************************************************************
2203 _spoolss_DeletePrinterDriverEx
2204 ****************************************************************/
2206 WERROR _spoolss_DeletePrinterDriverEx(pipes_struct *p,
2207 struct spoolss_DeletePrinterDriverEx *r)
2209 NT_PRINTER_DRIVER_INFO_LEVEL info;
2210 NT_PRINTER_DRIVER_INFO_LEVEL info_win2k;
2214 WERROR status_win2k = WERR_ACCESS_DENIED;
2215 SE_PRIV se_printop = SE_PRINT_OPERATOR;
2217 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2218 and not a printer admin, then fail */
2220 if ( (p->server_info->utok.uid != sec_initial_uid())
2221 && !user_has_privileges(p->server_info->ptok, &se_printop )
2222 && !token_contains_name_in_list(
2223 uidtoname(p->server_info->utok.uid), NULL, NULL,
2224 p->server_info->ptok, lp_printer_admin(-1)) )
2226 return WERR_ACCESS_DENIED;
2229 /* check that we have a valid driver name first */
2230 if ((version = get_version_id(r->in.architecture)) == -1) {
2231 /* this is what NT returns */
2232 return WERR_INVALID_ENVIRONMENT;
2235 if (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
2236 version = r->in.version;
2239 ZERO_STRUCT(info_win2k);
2241 status = get_a_printer_driver(&info, 3, r->in.driver,
2242 r->in.architecture, version);
2244 if ( !W_ERROR_IS_OK(status) )
2247 * if the client asked for a specific version,
2248 * or this is something other than Windows NT x86,
2252 if ( (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
2255 /* try for Win2k driver if "Windows NT x86" */
2258 if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, r->in.driver,
2261 status = WERR_UNKNOWN_PRINTER_DRIVER;
2266 if ( printer_driver_in_use(info.info_3) ) {
2267 status = WERR_PRINTER_DRIVER_IN_USE;
2272 * we have a couple of cases to consider.
2273 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
2274 * then the delete should fail if **any** files overlap with
2276 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
2277 * non-overlapping files
2278 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
2279 * is set, the do not delete any files
2280 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2283 delete_files = r->in.delete_flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
2285 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
2287 if ( delete_files && printer_driver_files_in_use(info.info_3) & (r->in.delete_flags & DPD_DELETE_ALL_FILES) ) {
2288 /* no idea of the correct error here */
2289 status = WERR_ACCESS_DENIED;
2294 /* also check for W32X86/3 if necessary; maybe we already have? */
2296 if ( (version == 2) && ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
2297 if (W_ERROR_IS_OK(get_a_printer_driver(&info_win2k, 3,
2299 r->in.architecture, 3)))
2302 if ( delete_files && printer_driver_files_in_use(info_win2k.info_3) & (r->in.delete_flags & DPD_DELETE_ALL_FILES) ) {
2303 /* no idea of the correct error here */
2304 free_a_printer_driver( info_win2k, 3 );
2305 status = WERR_ACCESS_DENIED;
2309 /* if we get to here, we now have 2 driver info structures to remove */
2310 /* remove the Win2k driver first*/
2312 status_win2k = delete_printer_driver(
2313 p, info_win2k.info_3, 3, delete_files);
2314 free_a_printer_driver( info_win2k, 3 );
2316 /* this should not have failed---if it did, report to client */
2318 if ( !W_ERROR_IS_OK(status_win2k) )
2323 status = delete_printer_driver(p, info.info_3, version, delete_files);
2325 if ( W_ERROR_IS_OK(status) || W_ERROR_IS_OK(status_win2k) )
2328 free_a_printer_driver( info, 3 );
2334 /****************************************************************************
2335 Internal routine for removing printerdata
2336 ***************************************************************************/
2338 static WERROR delete_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char *key, const char *value )
2340 return delete_printer_data( printer->info_2, key, value );
2343 /****************************************************************************
2344 Internal routine for storing printerdata
2345 ***************************************************************************/
2347 WERROR set_printer_dataex(NT_PRINTER_INFO_LEVEL *printer,
2348 const char *key, const char *value,
2349 uint32_t type, uint8_t *data, int real_len)
2351 /* the registry objects enforce uniqueness based on value name */
2353 return add_printer_data( printer->info_2, key, value, type, data, real_len );
2356 /********************************************************************
2357 GetPrinterData on a printer server Handle.
2358 ********************************************************************/
2360 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2362 enum winreg_Type *type,
2363 union spoolss_PrinterData *data)
2365 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2367 if (!StrCaseCmp(value, "W3SvcInstalled")) {
2373 if (!StrCaseCmp(value, "BeepEnabled")) {
2379 if (!StrCaseCmp(value, "EventLog")) {
2381 /* formally was 0x1b */
2386 if (!StrCaseCmp(value, "NetPopup")) {
2392 if (!StrCaseCmp(value, "MajorVersion")) {
2395 /* Windows NT 4.0 seems to not allow uploading of drivers
2396 to a server that reports 0x3 as the MajorVersion.
2397 need to investigate more how Win2k gets around this .
2400 if (RA_WINNT == get_remote_arch()) {
2409 if (!StrCaseCmp(value, "MinorVersion")) {
2416 * uint32_t size = 0x114
2417 * uint32_t major = 5
2418 * uint32_t minor = [0|1]
2419 * uint32_t build = [2195|2600]
2420 * extra unicode string = e.g. "Service Pack 3"
2422 if (!StrCaseCmp(value, "OSVersion")) {
2424 enum ndr_err_code ndr_err;
2425 struct spoolss_OSVersion os;
2427 os.major = 5; /* Windows 2000 == 5.0 */
2429 os.build = 2195; /* build */
2430 os.extra_string = ""; /* leave extra string empty */
2432 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, NULL, &os,
2433 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2434 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2435 return WERR_GENERAL_FAILURE;
2439 data->binary = blob;
2445 if (!StrCaseCmp(value, "DefaultSpoolDirectory")) {
2448 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2449 W_ERROR_HAVE_NO_MEMORY(data->string);
2454 if (!StrCaseCmp(value, "Architecture")) {
2457 data->string = talloc_strdup(mem_ctx, "Windows NT x86");
2458 W_ERROR_HAVE_NO_MEMORY(data->string);
2463 if (!StrCaseCmp(value, "DsPresent")) {
2466 /* only show the publish check box if we are a
2467 member of a AD domain */
2469 if (lp_security() == SEC_ADS) {
2477 if (!StrCaseCmp(value, "DNSMachineName")) {
2478 const char *hostname = get_mydnsfullname();
2481 return WERR_BADFILE;
2485 data->string = talloc_strdup(mem_ctx, hostname);
2486 W_ERROR_HAVE_NO_MEMORY(data->string);
2491 return WERR_INVALID_PARAM;
2494 /****************************************************************
2495 _spoolss_GetPrinterData
2496 ****************************************************************/
2498 WERROR _spoolss_GetPrinterData(pipes_struct *p,
2499 struct spoolss_GetPrinterData *r)
2502 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
2503 NT_PRINTER_INFO_LEVEL *printer = NULL;
2507 * Reminder: when it's a string, the length is in BYTES
2508 * even if UNICODE is negociated.
2513 /* in case of problem, return some default values */
2518 DEBUG(4,("_spoolss_GetPrinterData\n"));
2521 DEBUG(2,("_spoolss_GetPrinterData: Invalid handle (%s:%u:%u).\n",
2522 OUR_HANDLE(r->in.handle)));
2523 result = WERR_BADFID;
2527 if (Printer->printer_type == SPLHND_SERVER) {
2528 result = getprinterdata_printer_server(p->mem_ctx,
2533 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
2534 result = WERR_BADFID;
2538 result = get_a_printer(Printer, &printer, 2, lp_servicename(snum));
2539 if (!W_ERROR_IS_OK(result)) {
2543 /* XP sends this and wants to change id value from the PRINTER_INFO_0 */
2545 if (strequal(r->in.value_name, "ChangeId")) {
2546 *r->out.type = REG_DWORD;
2547 r->out.data->value = printer->info_2->changeid;
2550 struct regval_blob *v;
2553 v = get_printer_data(printer->info_2,
2554 SPOOL_PRINTERDATA_KEY,
2557 result = WERR_BADFILE;
2561 *r->out.type = v->type;
2563 blob = data_blob_const(v->data_p, v->size);
2565 result = pull_spoolss_PrinterData(p->mem_ctx, &blob,
2572 /* cleanup & exit */
2575 free_a_printer(&printer, 2);
2578 if (!W_ERROR_IS_OK(result)) {
2582 *r->out.needed = ndr_size_spoolss_PrinterData(r->out.data, *r->out.type, NULL, 0);
2583 *r->out.type = SPOOLSS_BUFFER_OK(*r->out.type, REG_NONE);
2584 r->out.data = SPOOLSS_BUFFER_OK(r->out.data, r->out.data);
2586 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
2589 /*********************************************************
2590 Connect to the client machine.
2591 **********************************************************/
2593 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2594 struct sockaddr_storage *client_ss, const char *remote_machine)
2597 struct cli_state *the_cli;
2598 struct sockaddr_storage rm_addr;
2600 if ( is_zero_addr((struct sockaddr *)client_ss) ) {
2601 if ( !resolve_name( remote_machine, &rm_addr, 0x20) ) {
2602 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2606 if (ismyaddr((struct sockaddr *)&rm_addr)) {
2607 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n", remote_machine));
2611 char addr[INET6_ADDRSTRLEN];
2612 rm_addr = *client_ss;
2613 print_sockaddr(addr, sizeof(addr), &rm_addr);
2614 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2618 /* setup the connection */
2620 ret = cli_full_connection( &the_cli, global_myname(), remote_machine,
2621 &rm_addr, 0, "IPC$", "IPC",
2625 0, lp_client_signing(), NULL );
2627 if ( !NT_STATUS_IS_OK( ret ) ) {
2628 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2633 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2634 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2635 cli_shutdown(the_cli);
2640 * Ok - we have an anonymous connection to the IPC$ share.
2641 * Now start the NT Domain stuff :-).
2644 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2645 if (!NT_STATUS_IS_OK(ret)) {
2646 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2647 remote_machine, nt_errstr(ret)));
2648 cli_shutdown(the_cli);
2655 /***************************************************************************
2656 Connect to the client.
2657 ****************************************************************************/
2659 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2660 uint32_t localprinter, uint32_t type,
2661 struct policy_handle *handle,
2662 struct sockaddr_storage *client_ss)
2668 * If it's the first connection, contact the client
2669 * and connect to the IPC$ share anonymously
2671 if (smb_connections==0) {
2672 fstring unix_printer;
2674 fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */
2676 if ( !spoolss_connect_to_client( ¬ify_cli_pipe, client_ss, unix_printer ))
2679 messaging_register(smbd_messaging_context(), NULL,
2680 MSG_PRINTER_NOTIFY2,
2681 receive_notify2_message_list);
2682 /* Tell the connections db we're now interested in printer
2683 * notify messages. */
2684 register_message_flags(true, FLAG_MSG_PRINT_NOTIFY);
2688 * Tell the specific printing tdb we want messages for this printer
2689 * by registering our PID.
2692 if (!print_notify_register_pid(snum))
2693 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", printer ));
2697 status = rpccli_spoolss_ReplyOpenPrinter(notify_cli_pipe, talloc_tos(),
2705 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
2706 DEBUG(5,("srv_spoolss_reply_open_printer: Client RPC returned [%s]\n",
2707 win_errstr(result)));
2709 return (W_ERROR_IS_OK(result));
2712 /****************************************************************
2713 ****************************************************************/
2715 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2716 const struct spoolss_NotifyOption *r)
2718 struct spoolss_NotifyOption *option;
2725 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2732 if (!option->count) {
2736 option->types = talloc_zero_array(option,
2737 struct spoolss_NotifyOptionType, option->count);
2738 if (!option->types) {
2739 talloc_free(option);
2743 for (i=0; i < option->count; i++) {
2744 option->types[i] = r->types[i];
2746 if (option->types[i].count) {
2747 option->types[i].fields = talloc_zero_array(option,
2748 union spoolss_Field, option->types[i].count);
2749 if (!option->types[i].fields) {
2750 talloc_free(option);
2753 for (k=0; k<option->types[i].count; k++) {
2754 option->types[i].fields[k] =
2755 r->types[i].fields[k];
2763 /****************************************************************
2764 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2766 * before replying OK: status=0 a rpc call is made to the workstation
2767 * asking ReplyOpenPrinter
2769 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2770 * called from api_spoolss_rffpcnex
2771 ****************************************************************/
2773 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(pipes_struct *p,
2774 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2777 struct spoolss_NotifyOption *option = r->in.notify_options;
2778 struct sockaddr_storage client_ss;
2780 /* store the notify value in the printer struct */
2782 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
2785 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2786 "Invalid handle (%s:%u:%u).\n",
2787 OUR_HANDLE(r->in.handle)));
2791 Printer->notify.flags = r->in.flags;
2792 Printer->notify.options = r->in.options;
2793 Printer->notify.printerlocal = r->in.printer_local;
2795 TALLOC_FREE(Printer->notify.option);
2796 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2798 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2800 /* Connect to the client machine and send a ReplyOpenPrinter */
2802 if ( Printer->printer_type == SPLHND_SERVER)
2804 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2805 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2808 if (!interpret_string_addr(&client_ss, p->client_address,
2810 return WERR_SERVER_UNAVAILABLE;
2813 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2814 Printer->notify.printerlocal, 1,
2815 &Printer->notify.client_hnd, &client_ss))
2816 return WERR_SERVER_UNAVAILABLE;
2818 Printer->notify.client_connected = true;
2823 /*******************************************************************
2824 * fill a notify_info_data with the servername
2825 ********************************************************************/
2827 void spoolss_notify_server_name(int snum,
2828 struct spoolss_Notify *data,
2829 print_queue_struct *queue,
2830 NT_PRINTER_INFO_LEVEL *printer,
2831 TALLOC_CTX *mem_ctx)
2833 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->servername);
2836 /*******************************************************************
2837 * fill a notify_info_data with the printername (not including the servername).
2838 ********************************************************************/
2840 void spoolss_notify_printer_name(int snum,
2841 struct spoolss_Notify *data,
2842 print_queue_struct *queue,
2843 NT_PRINTER_INFO_LEVEL *printer,
2844 TALLOC_CTX *mem_ctx)
2846 /* the notify name should not contain the \\server\ part */
2847 char *p = strrchr(printer->info_2->printername, '\\');
2850 p = printer->info_2->printername;
2855 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2858 /*******************************************************************
2859 * fill a notify_info_data with the servicename
2860 ********************************************************************/
2862 void spoolss_notify_share_name(int snum,
2863 struct spoolss_Notify *data,
2864 print_queue_struct *queue,
2865 NT_PRINTER_INFO_LEVEL *printer,
2866 TALLOC_CTX *mem_ctx)
2868 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
2871 /*******************************************************************
2872 * fill a notify_info_data with the port name
2873 ********************************************************************/
2875 void spoolss_notify_port_name(int snum,
2876 struct spoolss_Notify *data,
2877 print_queue_struct *queue,
2878 NT_PRINTER_INFO_LEVEL *printer,
2879 TALLOC_CTX *mem_ctx)
2881 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->portname);
2884 /*******************************************************************
2885 * fill a notify_info_data with the printername
2886 * but it doesn't exist, have to see what to do
2887 ********************************************************************/
2889 void spoolss_notify_driver_name(int snum,
2890 struct spoolss_Notify *data,
2891 print_queue_struct *queue,
2892 NT_PRINTER_INFO_LEVEL *printer,
2893 TALLOC_CTX *mem_ctx)
2895 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->drivername);
2898 /*******************************************************************
2899 * fill a notify_info_data with the comment
2900 ********************************************************************/
2902 void spoolss_notify_comment(int snum,
2903 struct spoolss_Notify *data,
2904 print_queue_struct *queue,
2905 NT_PRINTER_INFO_LEVEL *printer,
2906 TALLOC_CTX *mem_ctx)
2910 if (*printer->info_2->comment == '\0') {
2911 p = lp_comment(snum);
2913 p = printer->info_2->comment;
2916 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->comment);
2919 /*******************************************************************
2920 * fill a notify_info_data with the comment
2921 * location = "Room 1, floor 2, building 3"
2922 ********************************************************************/
2924 void spoolss_notify_location(int snum,
2925 struct spoolss_Notify *data,
2926 print_queue_struct *queue,
2927 NT_PRINTER_INFO_LEVEL *printer,
2928 TALLOC_CTX *mem_ctx)
2930 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->location);
2933 /*******************************************************************
2934 * fill a notify_info_data with the device mode
2935 * jfm:xxxx don't to it for know but that's a real problem !!!
2936 ********************************************************************/
2938 static void spoolss_notify_devmode(int snum,
2939 struct spoolss_Notify *data,
2940 print_queue_struct *queue,
2941 NT_PRINTER_INFO_LEVEL *printer,
2942 TALLOC_CTX *mem_ctx)
2944 /* for a dummy implementation we have to zero the fields */
2945 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2948 /*******************************************************************
2949 * fill a notify_info_data with the separator file name
2950 ********************************************************************/
2952 void spoolss_notify_sepfile(int snum,
2953 struct spoolss_Notify *data,
2954 print_queue_struct *queue,
2955 NT_PRINTER_INFO_LEVEL *printer,
2956 TALLOC_CTX *mem_ctx)
2958 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->sepfile);
2961 /*******************************************************************
2962 * fill a notify_info_data with the print processor
2963 * jfm:xxxx return always winprint to indicate we don't do anything to it
2964 ********************************************************************/
2966 void spoolss_notify_print_processor(int snum,
2967 struct spoolss_Notify *data,
2968 print_queue_struct *queue,
2969 NT_PRINTER_INFO_LEVEL *printer,
2970 TALLOC_CTX *mem_ctx)
2972 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->printprocessor);
2975 /*******************************************************************
2976 * fill a notify_info_data with the print processor options
2977 * jfm:xxxx send an empty string
2978 ********************************************************************/
2980 void spoolss_notify_parameters(int snum,
2981 struct spoolss_Notify *data,
2982 print_queue_struct *queue,
2983 NT_PRINTER_INFO_LEVEL *printer,
2984 TALLOC_CTX *mem_ctx)
2986 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->parameters);
2989 /*******************************************************************
2990 * fill a notify_info_data with the data type
2991 * jfm:xxxx always send RAW as data type
2992 ********************************************************************/
2994 void spoolss_notify_datatype(int snum,
2995 struct spoolss_Notify *data,
2996 print_queue_struct *queue,
2997 NT_PRINTER_INFO_LEVEL *printer,
2998 TALLOC_CTX *mem_ctx)
3000 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->datatype);
3003 /*******************************************************************
3004 * fill a notify_info_data with the security descriptor
3005 * jfm:xxxx send an null pointer to say no security desc
3006 * have to implement security before !
3007 ********************************************************************/
3009 static void spoolss_notify_security_desc(int snum,
3010 struct spoolss_Notify *data,
3011 print_queue_struct *queue,
3012 NT_PRINTER_INFO_LEVEL *printer,
3013 TALLOC_CTX *mem_ctx)
3015 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data,
3016 printer->info_2->secdesc_buf->sd_size,
3017 printer->info_2->secdesc_buf->sd);
3020 /*******************************************************************
3021 * fill a notify_info_data with the attributes
3022 * jfm:xxxx a samba printer is always shared
3023 ********************************************************************/
3025 void spoolss_notify_attributes(int snum,
3026 struct spoolss_Notify *data,
3027 print_queue_struct *queue,
3028 NT_PRINTER_INFO_LEVEL *printer,
3029 TALLOC_CTX *mem_ctx)
3031 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->attributes);
3034 /*******************************************************************
3035 * fill a notify_info_data with the priority
3036 ********************************************************************/
3038 static void spoolss_notify_priority(int snum,
3039 struct spoolss_Notify *data,
3040 print_queue_struct *queue,
3041 NT_PRINTER_INFO_LEVEL *printer,
3042 TALLOC_CTX *mem_ctx)
3044 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->priority);
3047 /*******************************************************************
3048 * fill a notify_info_data with the default priority
3049 ********************************************************************/
3051 static void spoolss_notify_default_priority(int snum,
3052 struct spoolss_Notify *data,
3053 print_queue_struct *queue,
3054 NT_PRINTER_INFO_LEVEL *printer,
3055 TALLOC_CTX *mem_ctx)
3057 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->default_priority);
3060 /*******************************************************************
3061 * fill a notify_info_data with the start time
3062 ********************************************************************/
3064 static void spoolss_notify_start_time(int snum,
3065 struct spoolss_Notify *data,
3066 print_queue_struct *queue,
3067 NT_PRINTER_INFO_LEVEL *printer,
3068 TALLOC_CTX *mem_ctx)
3070 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->starttime);
3073 /*******************************************************************
3074 * fill a notify_info_data with the until time
3075 ********************************************************************/
3077 static void spoolss_notify_until_time(int snum,
3078 struct spoolss_Notify *data,
3079 print_queue_struct *queue,
3080 NT_PRINTER_INFO_LEVEL *printer,
3081 TALLOC_CTX *mem_ctx)
3083 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->untiltime);
3086 /*******************************************************************
3087 * fill a notify_info_data with the status
3088 ********************************************************************/
3090 static void spoolss_notify_status(int snum,
3091 struct spoolss_Notify *data,
3092 print_queue_struct *queue,
3093 NT_PRINTER_INFO_LEVEL *printer,
3094 TALLOC_CTX *mem_ctx)
3096 print_status_struct status;
3098 print_queue_length(snum, &status);
3099 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
3102 /*******************************************************************
3103 * fill a notify_info_data with the number of jobs queued
3104 ********************************************************************/
3106 void spoolss_notify_cjobs(int snum,
3107 struct spoolss_Notify *data,
3108 print_queue_struct *queue,
3109 NT_PRINTER_INFO_LEVEL *printer,
3110 TALLOC_CTX *mem_ctx)
3112 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, print_queue_length(snum, NULL));
3115 /*******************************************************************
3116 * fill a notify_info_data with the average ppm
3117 ********************************************************************/
3119 static void spoolss_notify_average_ppm(int snum,
3120 struct spoolss_Notify *data,
3121 print_queue_struct *queue,
3122 NT_PRINTER_INFO_LEVEL *printer,
3123 TALLOC_CTX *mem_ctx)
3125 /* always respond 8 pages per minutes */
3126 /* a little hard ! */
3127 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->averageppm);
3130 /*******************************************************************
3131 * fill a notify_info_data with username
3132 ********************************************************************/
3134 static void spoolss_notify_username(int snum,
3135 struct spoolss_Notify *data,
3136 print_queue_struct *queue,
3137 NT_PRINTER_INFO_LEVEL *printer,
3138 TALLOC_CTX *mem_ctx)
3140 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
3143 /*******************************************************************
3144 * fill a notify_info_data with job status
3145 ********************************************************************/
3147 static void spoolss_notify_job_status(int snum,
3148 struct spoolss_Notify *data,
3149 print_queue_struct *queue,
3150 NT_PRINTER_INFO_LEVEL *printer,
3151 TALLOC_CTX *mem_ctx)
3153 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
3156 /*******************************************************************
3157 * fill a notify_info_data with job name
3158 ********************************************************************/
3160 static void spoolss_notify_job_name(int snum,
3161 struct spoolss_Notify *data,
3162 print_queue_struct *queue,
3163 NT_PRINTER_INFO_LEVEL *printer,
3164 TALLOC_CTX *mem_ctx)
3166 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
3169 /*******************************************************************
3170 * fill a notify_info_data with job status
3171 ********************************************************************/
3173 static void spoolss_notify_job_status_string(int snum,
3174 struct spoolss_Notify *data,
3175 print_queue_struct *queue,
3176 NT_PRINTER_INFO_LEVEL *printer,
3177 TALLOC_CTX *mem_ctx)
3180 * Now we're returning job status codes we just return a "" here. JRA.
3185 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3188 switch (queue->status) {
3193 p = ""; /* NT provides the paused string */
3202 #endif /* NO LONGER NEEDED. */
3204 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
3207 /*******************************************************************
3208 * fill a notify_info_data with job time
3209 ********************************************************************/
3211 static void spoolss_notify_job_time(int snum,
3212 struct spoolss_Notify *data,
3213 print_queue_struct *queue,
3214 NT_PRINTER_INFO_LEVEL *printer,
3215 TALLOC_CTX *mem_ctx)
3217 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3220 /*******************************************************************
3221 * fill a notify_info_data with job size
3222 ********************************************************************/
3224 static void spoolss_notify_job_size(int snum,
3225 struct spoolss_Notify *data,
3226 print_queue_struct *queue,
3227 NT_PRINTER_INFO_LEVEL *printer,
3228 TALLOC_CTX *mem_ctx)
3230 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
3233 /*******************************************************************
3234 * fill a notify_info_data with page info
3235 ********************************************************************/
3236 static void spoolss_notify_total_pages(int snum,
3237 struct spoolss_Notify *data,
3238 print_queue_struct *queue,
3239 NT_PRINTER_INFO_LEVEL *printer,
3240 TALLOC_CTX *mem_ctx)
3242 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
3245 /*******************************************************************
3246 * fill a notify_info_data with pages printed info.
3247 ********************************************************************/
3248 static void spoolss_notify_pages_printed(int snum,
3249 struct spoolss_Notify *data,
3250 print_queue_struct *queue,
3251 NT_PRINTER_INFO_LEVEL *printer,
3252 TALLOC_CTX *mem_ctx)
3254 /* Add code when back-end tracks this */
3255 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3258 /*******************************************************************
3259 Fill a notify_info_data with job position.
3260 ********************************************************************/
3262 static void spoolss_notify_job_position(int snum,
3263 struct spoolss_Notify *data,
3264 print_queue_struct *queue,
3265 NT_PRINTER_INFO_LEVEL *printer,
3266 TALLOC_CTX *mem_ctx)
3268 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
3271 /*******************************************************************
3272 Fill a notify_info_data with submitted time.
3273 ********************************************************************/
3275 static void spoolss_notify_submitted_time(int snum,
3276 struct spoolss_Notify *data,
3277 print_queue_struct *queue,
3278 NT_PRINTER_INFO_LEVEL *printer,
3279 TALLOC_CTX *mem_ctx)
3281 data->data.string.string = NULL;
3282 data->data.string.size = 0;
3284 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
3285 &data->data.string.string,
3286 &data->data.string.size);
3290 struct s_notify_info_data_table
3292 enum spoolss_NotifyType type;
3295 enum spoolss_NotifyTable variable_type;
3296 void (*fn) (int snum, struct spoolss_Notify *data,
3297 print_queue_struct *queue,
3298 NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx);
3301 /* A table describing the various print notification constants and
3302 whether the notification data is a pointer to a variable sized
3303 buffer, a one value uint32_t or a two value uint32_t. */
3305 static const struct s_notify_info_data_table notify_info_data_table[] =
3307 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3308 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3309 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
3310 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3311 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3312 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
3313 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
3314 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3315 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
3316 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3317 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3318 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3319 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
3320 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
3321 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3322 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
3323 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3324 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3325 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
3326 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
3327 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
3328 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
3329 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
3330 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3331 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
3332 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3333 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3334 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3335 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3336 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3337 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3338 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3339 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3340 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3341 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3342 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3343 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
3344 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
3345 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
3346 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
3347 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3348 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
3349 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
3350 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3351 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3352 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
3353 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
3354 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
3355 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
3358 /*******************************************************************
3359 Return the variable_type of info_data structure.
3360 ********************************************************************/
3362 static uint32_t variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3367 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3368 if ( (notify_info_data_table[i].type == type) &&
3369 (notify_info_data_table[i].field == field) ) {
3370 return notify_info_data_table[i].variable_type;
3374 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3379 /****************************************************************************
3380 ****************************************************************************/
3382 static bool search_notify(enum spoolss_NotifyType type,
3388 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3389 if (notify_info_data_table[i].type == type &&
3390 notify_info_data_table[i].field == field &&
3391 notify_info_data_table[i].fn != NULL) {
3400 /****************************************************************************
3401 ****************************************************************************/
3403 void construct_info_data(struct spoolss_Notify *info_data,
3404 enum spoolss_NotifyType type,
3408 info_data->type = type;
3409 info_data->field.field = field;
3410 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3411 info_data->job_id = id;
3414 /*******************************************************************
3416 * fill a notify_info struct with info asked
3418 ********************************************************************/
3420 static bool construct_notify_printer_info(Printer_entry *print_hnd,
3421 struct spoolss_NotifyInfo *info,
3423 const struct spoolss_NotifyOptionType *option_type,
3425 TALLOC_CTX *mem_ctx)
3428 enum spoolss_NotifyType type;
3431 struct spoolss_Notify *current_data;
3432 NT_PRINTER_INFO_LEVEL *printer = NULL;
3433 print_queue_struct *queue=NULL;
3435 type = option_type->type;
3437 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3438 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3439 option_type->count, lp_servicename(snum)));
3441 if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &printer, 2, lp_const_servicename(snum))))
3444 for(field_num=0; field_num < option_type->count; field_num++) {
3445 field = option_type->fields[field_num].field;
3447 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3449 if (!search_notify(type, field, &j) )
3452 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3453 struct spoolss_Notify,
3455 if (info->notifies == NULL) {
3456 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3457 free_a_printer(&printer, 2);
3461 current_data = &info->notifies[info->count];
3463 construct_info_data(current_data, type, field, id);
3465 DEBUG(10,("construct_notify_printer_info: calling [%s] snum=%d printername=[%s])\n",
3466 notify_info_data_table[j].name, snum, printer->info_2->printername ));
3468 notify_info_data_table[j].fn(snum, current_data, queue,
3474 free_a_printer(&printer, 2);
3478 /*******************************************************************
3480 * fill a notify_info struct with info asked
3482 ********************************************************************/
3484 static bool construct_notify_jobs_info(print_queue_struct *queue,
3485 struct spoolss_NotifyInfo *info,
3486 NT_PRINTER_INFO_LEVEL *printer,
3488 const struct spoolss_NotifyOptionType *option_type,
3490 TALLOC_CTX *mem_ctx)
3493 enum spoolss_NotifyType type;
3495 struct spoolss_Notify *current_data;
3497 DEBUG(4,("construct_notify_jobs_info\n"));
3499 type = option_type->type;
3501 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3502 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3503 option_type->count));
3505 for(field_num=0; field_num<option_type->count; field_num++) {
3506 field = option_type->fields[field_num].field;
3508 if (!search_notify(type, field, &j) )
3511 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3512 struct spoolss_Notify,
3514 if (info->notifies == NULL) {
3515 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3519 current_data=&(info->notifies[info->count]);
3521 construct_info_data(current_data, type, field, id);
3522 notify_info_data_table[j].fn(snum, current_data, queue,
3531 * JFM: The enumeration is not that simple, it's even non obvious.
3533 * let's take an example: I want to monitor the PRINTER SERVER for
3534 * the printer's name and the number of jobs currently queued.
3535 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3536 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3538 * I have 3 printers on the back of my server.
3540 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3543 * 1 printer 1 name 1
3544 * 2 printer 1 cjob 1
3545 * 3 printer 2 name 2
3546 * 4 printer 2 cjob 2
3547 * 5 printer 3 name 3
3548 * 6 printer 3 name 3
3550 * that's the print server case, the printer case is even worse.
3553 /*******************************************************************
3555 * enumerate all printers on the printserver
3556 * fill a notify_info struct with info asked
3558 ********************************************************************/
3560 static WERROR printserver_notify_info(pipes_struct *p,
3561 struct policy_handle *hnd,
3562 struct spoolss_NotifyInfo *info,
3563 TALLOC_CTX *mem_ctx)
3566 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3567 int n_services=lp_numservices();
3569 struct spoolss_NotifyOption *option;
3570 struct spoolss_NotifyOptionType option_type;
3572 DEBUG(4,("printserver_notify_info\n"));
3577 option = Printer->notify.option;
3580 info->notifies = NULL;
3583 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3584 sending a ffpcn() request first */
3589 for (i=0; i<option->count; i++) {
3590 option_type = option->types[i];
3592 if (option_type.type != PRINTER_NOTIFY_TYPE)
3595 for (snum=0; snum<n_services; snum++)
3597 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
3598 construct_notify_printer_info ( Printer, info, snum, &option_type, snum, mem_ctx );
3604 * Debugging information, don't delete.
3607 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3608 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3609 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3611 for (i=0; i<info->count; i++) {
3612 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3613 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3614 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3621 /*******************************************************************
3623 * fill a notify_info struct with info asked
3625 ********************************************************************/
3627 static WERROR printer_notify_info(pipes_struct *p, struct policy_handle *hnd,
3628 struct spoolss_NotifyInfo *info,
3629 TALLOC_CTX *mem_ctx)
3632 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3635 struct spoolss_NotifyOption *option;
3636 struct spoolss_NotifyOptionType option_type;
3638 print_queue_struct *queue=NULL;
3639 print_status_struct status;
3641 DEBUG(4,("printer_notify_info\n"));
3646 option = Printer->notify.option;
3650 info->notifies = NULL;
3653 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3654 sending a ffpcn() request first */
3659 get_printer_snum(p, hnd, &snum, NULL);
3661 for (i=0; i<option->count; i++) {
3662 option_type = option->types[i];
3664 switch (option_type.type) {
3665 case PRINTER_NOTIFY_TYPE:
3666 if(construct_notify_printer_info(Printer, info, snum,
3672 case JOB_NOTIFY_TYPE: {
3673 NT_PRINTER_INFO_LEVEL *printer = NULL;
3675 count = print_queue_status(snum, &queue, &status);
3677 if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum))))
3680 for (j=0; j<count; j++) {
3681 construct_notify_jobs_info(&queue[j], info,
3688 free_a_printer(&printer, 2);
3698 * Debugging information, don't delete.
3701 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3702 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3703 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3705 for (i=0; i<info->count; i++) {
3706 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3707 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3708 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3714 /****************************************************************
3715 _spoolss_RouterRefreshPrinterChangeNotify
3716 ****************************************************************/
3718 WERROR _spoolss_RouterRefreshPrinterChangeNotify(pipes_struct *p,
3719 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3721 struct spoolss_NotifyInfo *info;
3723 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
3724 WERROR result = WERR_BADFID;
3726 /* we always have a spoolss_NotifyInfo struct */
3727 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3729 result = WERR_NOMEM;
3733 *r->out.info = info;
3736 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3737 "Invalid handle (%s:%u:%u).\n",
3738 OUR_HANDLE(r->in.handle)));
3742 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3745 * We are now using the change value, and
3746 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3747 * I don't have a global notification system, I'm sending back all the
3748 * informations even when _NOTHING_ has changed.
3751 /* We need to keep track of the change value to send back in
3752 RRPCN replies otherwise our updates are ignored. */
3754 Printer->notify.fnpcn = true;
3756 if (Printer->notify.client_connected) {
3757 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3758 "Saving change value in request [%x]\n",
3760 Printer->notify.change = r->in.change_low;
3763 /* just ignore the spoolss_NotifyOption */
3765 switch (Printer->printer_type) {
3767 result = printserver_notify_info(p, r->in.handle,
3771 case SPLHND_PRINTER:
3772 result = printer_notify_info(p, r->in.handle,
3777 Printer->notify.fnpcn = false;
3783 /********************************************************************
3784 * construct_printer_info_0
3785 * fill a printer_info_0 struct
3786 ********************************************************************/
3788 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3789 const NT_PRINTER_INFO_LEVEL *ntprinter,
3790 struct spoolss_PrinterInfo0 *r,
3794 counter_printer_0 *session_counter;
3796 print_status_struct status;
3798 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
3799 W_ERROR_HAVE_NO_MEMORY(r->printername);
3801 r->servername = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
3802 W_ERROR_HAVE_NO_MEMORY(r->servername);
3804 count = print_queue_length(snum, &status);
3806 /* check if we already have a counter for this printer */
3807 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3808 if (session_counter->snum == snum)
3812 /* it's the first time, add it to the list */
3813 if (session_counter == NULL) {
3814 session_counter = SMB_MALLOC_P(counter_printer_0);
3815 W_ERROR_HAVE_NO_MEMORY(session_counter);
3816 ZERO_STRUCTP(session_counter);
3817 session_counter->snum = snum;
3818 session_counter->counter = 0;
3819 DLIST_ADD(counter_list, session_counter);
3823 session_counter->counter++;
3829 setuptime = (time_t)ntprinter->info_2->setuptime;
3831 init_systemtime(&r->time, gmtime(&setuptime));
3834 * the global_counter should be stored in a TDB as it's common to all the clients
3835 * and should be zeroed on samba startup
3837 r->global_counter = session_counter->counter;
3839 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3840 r->version = 0x0005; /* NT 5 */
3841 r->free_build = 0x0893; /* build 2195 */
3843 r->max_spooling = 0;
3844 r->session_counter = session_counter->counter;
3845 r->num_error_out_of_paper = 0x0;
3846 r->num_error_not_ready = 0x0; /* number of print failure */
3848 r->number_of_processors = 0x1;
3849 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3850 r->high_part_total_bytes = 0x0;
3851 r->change_id = ntprinter->info_2->changeid; /* ChangeID in milliseconds*/
3852 r->last_error = WERR_OK;
3853 r->status = nt_printq_status(status.status);
3854 r->enumerate_network_printers = 0x0;
3855 r->c_setprinter = get_c_setprinter(); /* monotonically increasing sum of delta printer counts */
3856 r->processor_architecture = 0x0;
3857 r->processor_level = 0x6; /* 6 ???*/
3865 /****************************************************************************
3866 Convert an NT_DEVICEMODE to a spoolss_DeviceMode structure. Both pointers
3867 should be valid upon entry
3868 ****************************************************************************/
3870 static WERROR convert_nt_devicemode(TALLOC_CTX *mem_ctx,
3871 struct spoolss_DeviceMode *r,
3872 const NT_DEVICEMODE *ntdevmode)
3874 if (!r || !ntdevmode) {
3875 return WERR_INVALID_PARAM;
3878 r->devicename = talloc_strdup(mem_ctx, ntdevmode->devicename);
3879 W_ERROR_HAVE_NO_MEMORY(r->devicename);
3881 r->specversion = ntdevmode->specversion;
3882 r->driverversion = ntdevmode->driverversion;
3883 r->size = ntdevmode->size;
3884 r->__driverextra_length = ntdevmode->driverextra;
3885 r->fields = ntdevmode->fields;
3887 r->orientation = ntdevmode->orientation;
3888 r->papersize = ntdevmode->papersize;
3889 r->paperlength = ntdevmode->paperlength;
3890 r->paperwidth = ntdevmode->paperwidth;
3891 r->scale = ntdevmode->scale;
3892 r->copies = ntdevmode->copies;
3893 r->defaultsource = ntdevmode->defaultsource;
3894 r->printquality = ntdevmode->printquality;
3895 r->color = ntdevmode->color;
3896 r->duplex = ntdevmode->duplex;
3897 r->yresolution = ntdevmode->yresolution;
3898 r->ttoption = ntdevmode->ttoption;
3899 r->collate = ntdevmode->collate;
3901 r->formname = talloc_strdup(mem_ctx, ntdevmode->formname);
3902 W_ERROR_HAVE_NO_MEMORY(r->formname);
3904 /* all 0 below are values that have not been set in the old parsing/copy
3905 * function, maybe they should... - gd */
3911 r->displayflags = 0;
3912 r->displayfrequency = 0;
3913 r->icmmethod = ntdevmode->icmmethod;
3914 r->icmintent = ntdevmode->icmintent;
3915 r->mediatype = ntdevmode->mediatype;
3916 r->dithertype = ntdevmode->dithertype;
3919 r->panningwidth = 0;
3920 r->panningheight = 0;
3922 if (ntdevmode->nt_dev_private != NULL) {
3923 r->driverextra_data = data_blob_talloc(mem_ctx,
3924 ntdevmode->nt_dev_private,
3925 ntdevmode->driverextra);
3926 W_ERROR_HAVE_NO_MEMORY(r->driverextra_data.data);
3933 /****************************************************************************
3934 Create a spoolss_DeviceMode struct. Returns talloced memory.
3935 ****************************************************************************/
3937 struct spoolss_DeviceMode *construct_dev_mode(TALLOC_CTX *mem_ctx,
3938 const char *servicename)
3941 NT_PRINTER_INFO_LEVEL *printer = NULL;
3942 struct spoolss_DeviceMode *devmode = NULL;
3944 DEBUG(7,("construct_dev_mode\n"));
3946 DEBUGADD(8,("getting printer characteristics\n"));
3948 if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, servicename)))
3951 if (!printer->info_2->devmode) {
3952 DEBUG(5, ("BONG! There was no device mode!\n"));
3956 devmode = TALLOC_ZERO_P(mem_ctx, struct spoolss_DeviceMode);
3958 DEBUG(2,("construct_dev_mode: talloc fail.\n"));
3962 DEBUGADD(8,("loading DEVICEMODE\n"));
3964 result = convert_nt_devicemode(mem_ctx, devmode, printer->info_2->devmode);
3965 if (!W_ERROR_IS_OK(result)) {
3966 TALLOC_FREE(devmode);
3970 free_a_printer(&printer,2);
3975 /********************************************************************
3976 * construct_printer_info3
3977 * fill a spoolss_PrinterInfo3 struct
3978 ********************************************************************/
3980 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
3981 const NT_PRINTER_INFO_LEVEL *ntprinter,
3982 struct spoolss_PrinterInfo3 *r,
3985 /* These are the components of the SD we are returning. */
3987 if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->sd_size != 0) {
3988 /* don't use talloc_steal() here unless you do a deep steal of all
3989 the SEC_DESC members */
3991 r->secdesc = dup_sec_desc(mem_ctx,
3992 ntprinter->info_2->secdesc_buf->sd);
3993 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
3999 /********************************************************************
4000 * construct_printer_info4
4001 * fill a spoolss_PrinterInfo4 struct
4002 ********************************************************************/
4004 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
4005 const NT_PRINTER_INFO_LEVEL *ntprinter,
4006 struct spoolss_PrinterInfo4 *r,
4009 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
4010 W_ERROR_HAVE_NO_MEMORY(r->printername);
4011 r->servername = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
4012 W_ERROR_HAVE_NO_MEMORY(r->servername);
4014 r->attributes = ntprinter->info_2->attributes;
4019 /********************************************************************
4020 * construct_printer_info5
4021 * fill a spoolss_PrinterInfo5 struct
4022 ********************************************************************/
4024 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
4025 const NT_PRINTER_INFO_LEVEL *ntprinter,
4026 struct spoolss_PrinterInfo5 *r,
4029 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
4030 W_ERROR_HAVE_NO_MEMORY(r->printername);
4031 r->portname = talloc_strdup(mem_ctx, ntprinter->info_2->portname);
4032 W_ERROR_HAVE_NO_MEMORY(r->portname);
4034 r->attributes = ntprinter->info_2->attributes;
4036 /* these two are not used by NT+ according to MSDN */
4038 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
4039 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
4044 /********************************************************************
4045 * construct_printer_info_6
4046 * fill a spoolss_PrinterInfo6 struct
4047 ********************************************************************/
4049 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
4050 const NT_PRINTER_INFO_LEVEL *ntprinter,
4051 struct spoolss_PrinterInfo6 *r,
4055 print_status_struct status;
4057 count = print_queue_length(snum, &status);
4059 r->status = nt_printq_status(status.status);
4064 /********************************************************************
4065 * construct_printer_info7
4066 * fill a spoolss_PrinterInfo7 struct
4067 ********************************************************************/
4069 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
4070 Printer_entry *print_hnd,
4071 struct spoolss_PrinterInfo7 *r,
4076 if (is_printer_published(print_hnd, snum, &guid)) {
4077 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
4078 r->action = DSPRINT_PUBLISH;
4080 r->guid = talloc_strdup(mem_ctx, "");
4081 r->action = DSPRINT_UNPUBLISH;
4083 W_ERROR_HAVE_NO_MEMORY(r->guid);
4088 /********************************************************************
4089 * construct_printer_info8
4090 * fill a spoolss_PrinterInfo8 struct
4091 ********************************************************************/
4093 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
4094 const NT_PRINTER_INFO_LEVEL *ntprinter,
4095 struct spoolss_DeviceModeInfo *r,
4098 struct spoolss_DeviceMode *devmode;
4101 if (!ntprinter->info_2->devmode) {
4106 devmode = TALLOC_ZERO_P(mem_ctx, struct spoolss_DeviceMode);
4107 W_ERROR_HAVE_NO_MEMORY(devmode);
4109 result = convert_nt_devicemode(mem_ctx, devmode, ntprinter->info_2->devmode);
4110 if (!W_ERROR_IS_OK(result)) {
4111 TALLOC_FREE(devmode);
4115 r->devmode = devmode;
4121 /********************************************************************
4122 * construct_printer_info1
4123 * fill a spoolss_PrinterInfo1 struct
4124 ********************************************************************/
4126 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
4127 const NT_PRINTER_INFO_LEVEL *ntprinter,
4129 struct spoolss_PrinterInfo1 *r,
4134 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
4135 ntprinter->info_2->printername,
4136 ntprinter->info_2->drivername,
4137 ntprinter->info_2->location);
4138 W_ERROR_HAVE_NO_MEMORY(r->description);
4140 if (*ntprinter->info_2->comment == '\0') {
4141 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
4143 r->comment = talloc_strdup(mem_ctx, ntprinter->info_2->comment); /* saved comment */
4145 W_ERROR_HAVE_NO_MEMORY(r->comment);
4147 r->name = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
4148 W_ERROR_HAVE_NO_MEMORY(r->name);
4153 /********************************************************************
4154 * construct_printer_info2
4155 * fill a spoolss_PrinterInfo2 struct
4156 ********************************************************************/
4158 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
4159 const NT_PRINTER_INFO_LEVEL *ntprinter,
4160 struct spoolss_PrinterInfo2 *r,
4165 print_status_struct status;
4167 count = print_queue_length(snum, &status);
4169 r->servername = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
4170 W_ERROR_HAVE_NO_MEMORY(r->servername);
4171 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
4172 W_ERROR_HAVE_NO_MEMORY(r->printername);
4173 r->sharename = talloc_strdup(mem_ctx, lp_servicename(snum));
4174 W_ERROR_HAVE_NO_MEMORY(r->sharename);
4175 r->portname = talloc_strdup(mem_ctx, ntprinter->info_2->portname);
4176 W_ERROR_HAVE_NO_MEMORY(r->portname);
4177 r->drivername = talloc_strdup(mem_ctx, ntprinter->info_2->drivername);
4178 W_ERROR_HAVE_NO_MEMORY(r->drivername);
4180 if (*ntprinter->info_2->comment == '\0') {
4181 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
4183 r->comment = talloc_strdup(mem_ctx, ntprinter->info_2->comment);
4185 W_ERROR_HAVE_NO_MEMORY(r->comment);
4187 r->location = talloc_strdup(mem_ctx, ntprinter->info_2->location);
4188 W_ERROR_HAVE_NO_MEMORY(r->location);
4189 r->sepfile = talloc_strdup(mem_ctx, ntprinter->info_2->sepfile);
4190 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
4191 r->printprocessor = talloc_strdup(mem_ctx, ntprinter->info_2->printprocessor);
4192 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
4193 r->datatype = talloc_strdup(mem_ctx, ntprinter->info_2->datatype);
4194 W_ERROR_HAVE_NO_MEMORY(r->datatype);
4195 r->parameters = talloc_strdup(mem_ctx, ntprinter->info_2->parameters);
4196 W_ERROR_HAVE_NO_MEMORY(r->parameters);
4198 r->attributes = ntprinter->info_2->attributes;
4200 r->priority = ntprinter->info_2->priority;
4201 r->defaultpriority = ntprinter->info_2->default_priority;
4202 r->starttime = ntprinter->info_2->starttime;
4203 r->untiltime = ntprinter->info_2->untiltime;
4204 r->status = nt_printq_status(status.status);
4206 r->averageppm = ntprinter->info_2->averageppm;
4208 r->devmode = construct_dev_mode(mem_ctx, lp_const_servicename(snum));
4210 DEBUG(8,("Returning NULL Devicemode!\n"));
4215 if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->sd_size != 0) {
4216 /* don't use talloc_steal() here unless you do a deep steal of all
4217 the SEC_DESC members */
4219 r->secdesc = dup_sec_desc(mem_ctx, ntprinter->info_2->secdesc_buf->sd);
4225 /********************************************************************
4226 ********************************************************************/
4228 static bool snum_is_shared_printer(int snum)
4230 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
4233 /********************************************************************
4234 Spoolss_enumprinters.
4235 ********************************************************************/
4237 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
4240 union spoolss_PrinterInfo **info_p,
4244 int n_services = lp_numservices();
4245 union spoolss_PrinterInfo *info = NULL;
4247 WERROR result = WERR_OK;
4252 for (snum = 0; snum < n_services; snum++) {
4254 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
4256 if (!snum_is_shared_printer(snum)) {
4260 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
4261 lp_servicename(snum), snum));
4263 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4264 union spoolss_PrinterInfo,
4267 result = WERR_NOMEM;
4271 result = get_a_printer(NULL, &ntprinter, 2,
4272 lp_const_servicename(snum));
4273 if (!W_ERROR_IS_OK(result)) {
4279 result = construct_printer_info0(info, ntprinter,
4280 &info[count].info0, snum);
4283 result = construct_printer_info1(info, ntprinter, flags,
4284 &info[count].info1, snum);
4287 result = construct_printer_info2(info, ntprinter,
4288 &info[count].info2, snum);
4291 result = construct_printer_info4(info, ntprinter,
4292 &info[count].info4, snum);
4295 result = construct_printer_info5(info, ntprinter,
4296 &info[count].info5, snum);
4300 result = WERR_UNKNOWN_LEVEL;
4301 free_a_printer(&ntprinter, 2);
4305 free_a_printer(&ntprinter, 2);
4306 if (!W_ERROR_IS_OK(result)) {
4317 if (!W_ERROR_IS_OK(result)) {
4327 /********************************************************************
4328 * handle enumeration of printers at level 0
4329 ********************************************************************/
4331 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
4333 const char *servername,
4334 union spoolss_PrinterInfo **info,
4337 DEBUG(4,("enum_all_printers_info_0\n"));
4339 return enum_all_printers_info_level(mem_ctx, 0, flags, info, count);
4343 /********************************************************************
4344 ********************************************************************/
4346 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
4348 union spoolss_PrinterInfo **info,
4351 DEBUG(4,("enum_all_printers_info_1\n"));
4353 return enum_all_printers_info_level(mem_ctx, 1, flags, info, count);
4356 /********************************************************************
4357 enum_all_printers_info_1_local.
4358 *********************************************************************/
4360 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
4361 union spoolss_PrinterInfo **info,
4364 DEBUG(4,("enum_all_printers_info_1_local\n"));
4366 return enum_all_printers_info_1(mem_ctx, PRINTER_ENUM_ICON8, info, count);
4369 /********************************************************************
4370 enum_all_printers_info_1_name.
4371 *********************************************************************/
4373 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
4375 union spoolss_PrinterInfo **info,
4378 const char *s = name;
4380 DEBUG(4,("enum_all_printers_info_1_name\n"));
4382 if ((name[0] == '\\') && (name[1] == '\\')) {
4386 if (!is_myname_or_ipaddr(s)) {
4387 return WERR_INVALID_NAME;
4390 return enum_all_printers_info_1(mem_ctx, PRINTER_ENUM_ICON8, info, count);
4393 /********************************************************************
4394 enum_all_printers_info_1_network.
4395 *********************************************************************/
4397 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
4399 union spoolss_PrinterInfo **info,
4402 const char *s = name;
4404 DEBUG(4,("enum_all_printers_info_1_network\n"));
4406 /* If we respond to a enum_printers level 1 on our name with flags
4407 set to PRINTER_ENUM_REMOTE with a list of printers then these
4408 printers incorrectly appear in the APW browse list.
4409 Specifically the printers for the server appear at the workgroup
4410 level where all the other servers in the domain are
4411 listed. Windows responds to this call with a
4412 WERR_CAN_NOT_COMPLETE so we should do the same. */
4414 if (name[0] == '\\' && name[1] == '\\') {
4418 if (is_myname_or_ipaddr(s)) {
4419 return WERR_CAN_NOT_COMPLETE;
4422 return enum_all_printers_info_1(mem_ctx, PRINTER_ENUM_NAME, info, count);
4425 /********************************************************************
4426 * api_spoolss_enumprinters
4428 * called from api_spoolss_enumprinters (see this to understand)
4429 ********************************************************************/
4431 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
4432 union spoolss_PrinterInfo **info,
4435 DEBUG(4,("enum_all_printers_info_2\n"));
4437 return enum_all_printers_info_level(mem_ctx, 2, 0, info, count);
4440 /********************************************************************
4441 * handle enumeration of printers at level 1
4442 ********************************************************************/
4444 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
4447 union spoolss_PrinterInfo **info,
4450 /* Not all the flags are equals */
4452 if (flags & PRINTER_ENUM_LOCAL) {
4453 return enum_all_printers_info_1_local(mem_ctx, info, count);
4456 if (flags & PRINTER_ENUM_NAME) {
4457 return enum_all_printers_info_1_name(mem_ctx, name, info, count);
4460 if (flags & PRINTER_ENUM_NETWORK) {
4461 return enum_all_printers_info_1_network(mem_ctx, name, info, count);
4464 return WERR_OK; /* NT4sp5 does that */
4467 /********************************************************************
4468 * handle enumeration of printers at level 2
4469 ********************************************************************/
4471 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4473 const char *servername,
4474 union spoolss_PrinterInfo **info,
4477 if (flags & PRINTER_ENUM_LOCAL) {
4478 return enum_all_printers_info_2(mem_ctx, info, count);
4481 if (flags & PRINTER_ENUM_NAME) {
4482 if (!is_myname_or_ipaddr(canon_servername(servername))) {
4483 return WERR_INVALID_NAME;
4486 return enum_all_printers_info_2(mem_ctx, info, count);
4489 if (flags & PRINTER_ENUM_REMOTE) {
4490 return WERR_UNKNOWN_LEVEL;
4496 /********************************************************************
4497 * handle enumeration of printers at level 4
4498 ********************************************************************/
4500 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4502 const char *servername,
4503 union spoolss_PrinterInfo **info,
4506 DEBUG(4,("enum_all_printers_info_4\n"));
4508 return enum_all_printers_info_level(mem_ctx, 4, flags, info, count);
4512 /********************************************************************
4513 * handle enumeration of printers at level 5
4514 ********************************************************************/
4516 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4518 const char *servername,
4519 union spoolss_PrinterInfo **info,
4522 DEBUG(4,("enum_all_printers_info_5\n"));
4524 return enum_all_printers_info_level(mem_ctx, 5, flags, info, count);
4527 /****************************************************************
4528 _spoolss_EnumPrinters
4529 ****************************************************************/
4531 WERROR _spoolss_EnumPrinters(pipes_struct *p,
4532 struct spoolss_EnumPrinters *r)
4537 /* that's an [in out] buffer */
4539 if (!r->in.buffer && (r->in.offered != 0)) {
4540 return WERR_INVALID_PARAM;
4543 DEBUG(4,("_spoolss_EnumPrinters\n"));
4547 *r->out.info = NULL;
4551 * flags==PRINTER_ENUM_NAME
4552 * if name=="" then enumerates all printers
4553 * if name!="" then enumerate the printer
4554 * flags==PRINTER_ENUM_REMOTE
4555 * name is NULL, enumerate printers
4556 * Level 2: name!="" enumerates printers, name can't be NULL
4557 * Level 3: doesn't exist
4558 * Level 4: does a local registry lookup
4559 * Level 5: same as Level 2
4562 name = talloc_strdup_upper(p->mem_ctx, r->in.server);
4563 W_ERROR_HAVE_NO_MEMORY(name);
4565 switch (r->in.level) {
4567 result = enumprinters_level0(p->mem_ctx, r->in.flags, name,
4568 r->out.info, r->out.count);
4571 result = enumprinters_level1(p->mem_ctx, r->in.flags, name,
4572 r->out.info, r->out.count);
4575 result = enumprinters_level2(p->mem_ctx, r->in.flags, name,
4576 r->out.info, r->out.count);
4579 result = enumprinters_level4(p->mem_ctx, r->in.flags, name,
4580 r->out.info, r->out.count);
4583 result = enumprinters_level5(p->mem_ctx, r->in.flags, name,
4584 r->out.info, r->out.count);
4587 return WERR_UNKNOWN_LEVEL;
4590 if (!W_ERROR_IS_OK(result)) {
4594 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4595 spoolss_EnumPrinters, NULL,
4596 *r->out.info, r->in.level,
4598 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4599 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4601 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4604 /****************************************************************
4606 ****************************************************************/
4608 WERROR _spoolss_GetPrinter(pipes_struct *p,
4609 struct spoolss_GetPrinter *r)
4611 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
4612 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
4613 WERROR result = WERR_OK;
4617 /* that's an [in out] buffer */
4619 if (!r->in.buffer && (r->in.offered != 0)) {
4620 return WERR_INVALID_PARAM;
4625 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4629 result = get_a_printer(Printer, &ntprinter, 2,
4630 lp_const_servicename(snum));
4631 if (!W_ERROR_IS_OK(result)) {
4635 switch (r->in.level) {
4637 result = construct_printer_info0(p->mem_ctx, ntprinter,
4638 &r->out.info->info0, snum);
4641 result = construct_printer_info1(p->mem_ctx, ntprinter,
4643 &r->out.info->info1, snum);
4646 result = construct_printer_info2(p->mem_ctx, ntprinter,
4647 &r->out.info->info2, snum);
4650 result = construct_printer_info3(p->mem_ctx, ntprinter,
4651 &r->out.info->info3, snum);
4654 result = construct_printer_info4(p->mem_ctx, ntprinter,
4655 &r->out.info->info4, snum);
4658 result = construct_printer_info5(p->mem_ctx, ntprinter,
4659 &r->out.info->info5, snum);
4662 result = construct_printer_info6(p->mem_ctx, ntprinter,
4663 &r->out.info->info6, snum);
4666 result = construct_printer_info7(p->mem_ctx, Printer,
4667 &r->out.info->info7, snum);
4670 result = construct_printer_info8(p->mem_ctx, ntprinter,
4671 &r->out.info->info8, snum);
4674 result = WERR_UNKNOWN_LEVEL;
4678 free_a_printer(&ntprinter, 2);
4680 if (!W_ERROR_IS_OK(result)) {
4681 TALLOC_FREE(r->out.info);
4685 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo, NULL,
4686 r->out.info, r->in.level);
4687 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4689 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4692 /********************************************************************
4693 ********************************************************************/
4695 static const char **string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4696 fstring *fstring_array,
4697 const char *cservername)
4699 int i, num_strings = 0;
4700 const char **array = NULL;
4702 for (i=0; fstring_array && fstring_array[i][0] != '\0'; i++) {
4704 const char *str = talloc_asprintf(mem_ctx, "\\\\%s%s",
4705 cservername, fstring_array[i]);
4712 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4719 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4720 &array, &num_strings);
4726 /********************************************************************
4727 * fill a spoolss_DriverInfo1 struct
4728 ********************************************************************/
4730 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4731 struct spoolss_DriverInfo1 *r,
4732 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
4733 const char *servername,
4734 const char *architecture)
4736 r->driver_name = talloc_strdup(mem_ctx, driver->info_3->name);
4737 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4742 /********************************************************************
4743 * fill a spoolss_DriverInfo2 struct
4744 ********************************************************************/
4746 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4747 struct spoolss_DriverInfo2 *r,
4748 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
4749 const char *servername)
4752 const char *cservername = canon_servername(servername);
4754 r->version = driver->info_3->cversion;
4756 r->driver_name = talloc_strdup(mem_ctx, driver->info_3->name);
4757 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4758 r->architecture = talloc_strdup(mem_ctx, driver->info_3->environment);
4759 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4761 if (strlen(driver->info_3->driverpath)) {
4762 r->driver_path = talloc_asprintf(mem_ctx, "\\\\%s%s",
4763 cservername, driver->info_3->driverpath);
4765 r->driver_path = talloc_strdup(mem_ctx, "");
4767 W_ERROR_HAVE_NO_MEMORY(r->driver_path);
4769 if (strlen(driver->info_3->datafile)) {
4770 r->data_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4771 cservername, driver->info_3->datafile);
4773 r->data_file = talloc_strdup(mem_ctx, "");
4775 W_ERROR_HAVE_NO_MEMORY(r->data_file);
4777 if (strlen(driver->info_3->configfile)) {
4778 r->config_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4779 cservername, driver->info_3->configfile);
4781 r->config_file = talloc_strdup(mem_ctx, "");
4783 W_ERROR_HAVE_NO_MEMORY(r->config_file);
4788 /********************************************************************
4789 * fill a spoolss_DriverInfo3 struct
4790 ********************************************************************/
4792 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4793 struct spoolss_DriverInfo3 *r,
4794 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
4795 const char *servername)
4797 const char *cservername = canon_servername(servername);
4799 r->version = driver->info_3->cversion;
4801 r->driver_name = talloc_strdup(mem_ctx, driver->info_3->name);
4802 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4803 r->architecture = talloc_strdup(mem_ctx, driver->info_3->environment);
4804 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4806 if (strlen(driver->info_3->driverpath)) {
4807 r->driver_path = talloc_asprintf(mem_ctx, "\\\\%s%s",
4808 cservername, driver->info_3->driverpath);
4810 r->driver_path = talloc_strdup(mem_ctx, "");
4812 W_ERROR_HAVE_NO_MEMORY(r->driver_path);
4814 if (strlen(driver->info_3->datafile)) {
4815 r->data_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4816 cservername, driver->info_3->datafile);
4818 r->data_file = talloc_strdup(mem_ctx, "");
4820 W_ERROR_HAVE_NO_MEMORY(r->data_file);
4822 if (strlen(driver->info_3->configfile)) {
4823 r->config_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4824 cservername, driver->info_3->configfile);
4826 r->config_file = talloc_strdup(mem_ctx, "");
4828 W_ERROR_HAVE_NO_MEMORY(r->config_file);
4830 if (strlen(driver->info_3->helpfile)) {
4831 r->help_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4832 cservername, driver->info_3->helpfile);
4834 r->help_file = talloc_strdup(mem_ctx, "");
4836 W_ERROR_HAVE_NO_MEMORY(r->help_file);
4838 r->monitor_name = talloc_strdup(mem_ctx, driver->info_3->monitorname);
4839 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
4840 r->default_datatype = talloc_strdup(mem_ctx, driver->info_3->defaultdatatype);
4841 W_ERROR_HAVE_NO_MEMORY(r->default_datatype);
4843 r->dependent_files = string_array_from_driver_info(mem_ctx,
4844 driver->info_3->dependentfiles,
4849 /********************************************************************
4850 * fill a spoolss_DriverInfo4 struct
4851 ********************************************************************/
4853 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
4854 struct spoolss_DriverInfo4 *r,
4855 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
4856 const char *servername)
4858 const char *cservername = canon_servername(servername);
4860 r->version = driver->info_3->cversion;
4862 r->driver_name = talloc_strdup(mem_ctx, driver->info_3->name);
4863 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4864 r->architecture = talloc_strdup(mem_ctx, driver->info_3->environment);
4865 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4867 if (strlen(driver->info_3->driverpath)) {
4868 r->driver_path = talloc_asprintf(mem_ctx, "\\\\%s%s",
4869 cservername, driver->info_3->driverpath);
4871 r->driver_path = talloc_strdup(mem_ctx, "");
4873 W_ERROR_HAVE_NO_MEMORY(r->driver_path);
4875 if (strlen(driver->info_3->datafile)) {
4876 r->data_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4877 cservername, driver->info_3->datafile);
4879 r->data_file = talloc_strdup(mem_ctx, "");
4881 W_ERROR_HAVE_NO_MEMORY(r->data_file);
4883 if (strlen(driver->info_3->configfile)) {
4884 r->config_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4885 cservername, driver->info_3->configfile);
4887 r->config_file = talloc_strdup(mem_ctx, "");
4889 W_ERROR_HAVE_NO_MEMORY(r->config_file);
4891 if (strlen(driver->info_3->helpfile)) {
4892 r->help_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4893 cservername, driver->info_3->helpfile);
4895 r->help_file = talloc_strdup(mem_ctx, "");
4897 W_ERROR_HAVE_NO_MEMORY(r->help_file);
4899 r->dependent_files = string_array_from_driver_info(mem_ctx,
4900 driver->info_3->dependentfiles,
4904 r->monitor_name = talloc_strdup(mem_ctx, driver->info_3->monitorname);
4905 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
4906 r->default_datatype = talloc_strdup(mem_ctx, driver->info_3->defaultdatatype);
4907 W_ERROR_HAVE_NO_MEMORY(r->default_datatype);
4909 r->previous_names = string_array_from_driver_info(mem_ctx,
4916 /********************************************************************
4917 * fill a spoolss_DriverInfo5 struct
4918 ********************************************************************/
4920 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
4921 struct spoolss_DriverInfo5 *r,
4922 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
4923 const char *servername)
4925 const char *cservername = canon_servername(servername);
4927 r->version = driver->info_3->cversion;
4929 r->driver_name = talloc_strdup(mem_ctx, driver->info_3->name);
4930 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4931 r->architecture = talloc_strdup(mem_ctx, driver->info_3->environment);
4932 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4934 if (strlen(driver->info_3->driverpath)) {
4935 r->driver_path = talloc_asprintf(mem_ctx, "\\\\%s%s",
4936 cservername, driver->info_3->driverpath);
4938 r->driver_path = talloc_strdup(mem_ctx, "");
4940 W_ERROR_HAVE_NO_MEMORY(r->driver_path);
4942 if (strlen(driver->info_3->datafile)) {
4943 r->data_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4944 cservername, driver->info_3->datafile);
4946 r->data_file = talloc_strdup(mem_ctx, "");
4948 W_ERROR_HAVE_NO_MEMORY(r->data_file);
4950 if (strlen(driver->info_3->configfile)) {
4951 r->config_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4952 cservername, driver->info_3->configfile);
4954 r->config_file = talloc_strdup(mem_ctx, "");
4956 W_ERROR_HAVE_NO_MEMORY(r->config_file);
4958 r->driver_attributes = 0;
4959 r->config_version = 0;
4960 r->driver_version = 0;
4964 /********************************************************************
4965 * fill a spoolss_DriverInfo6 struct
4966 ********************************************************************/
4968 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
4969 struct spoolss_DriverInfo6 *r,
4970 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
4971 const char *servername)
4973 const char *cservername = canon_servername(servername);
4975 r->version = driver->info_3->cversion;
4977 r->driver_name = talloc_strdup(mem_ctx, driver->info_3->name);
4978 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4979 r->architecture = talloc_strdup(mem_ctx, driver->info_3->environment);
4980 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4982 if (strlen(driver->info_3->driverpath)) {
4983 r->driver_path = talloc_asprintf(mem_ctx, "\\\\%s%s",
4984 cservername, driver->info_3->driverpath);
4986 r->driver_path = talloc_strdup(mem_ctx, "");
4988 W_ERROR_HAVE_NO_MEMORY(r->driver_path);
4990 if (strlen(driver->info_3->datafile)) {
4991 r->data_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4992 cservername, driver->info_3->datafile);
4994 r->data_file = talloc_strdup(mem_ctx, "");
4996 W_ERROR_HAVE_NO_MEMORY(r->data_file);
4998 if (strlen(driver->info_3->configfile)) {
4999 r->config_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
5000 cservername, driver->info_3->configfile);
5002 r->config_file = talloc_strdup(mem_ctx, "");
5004 W_ERROR_HAVE_NO_MEMORY(r->config_file);
5006 if (strlen(driver->info_3->helpfile)) {
5007 r->help_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
5008 cservername, driver->info_3->helpfile);
5010 r->help_file = talloc_strdup(mem_ctx, "");
5012 W_ERROR_HAVE_NO_MEMORY(r->help_file);
5014 r->monitor_name = talloc_strdup(mem_ctx, driver->info_3->monitorname);
5015 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
5016 r->default_datatype = talloc_strdup(mem_ctx, driver->info_3->defaultdatatype);
5017 W_ERROR_HAVE_NO_MEMORY(r->default_datatype);
5019 r->dependent_files = string_array_from_driver_info(mem_ctx,
5020 driver->info_3->dependentfiles,
5022 r->previous_names = string_array_from_driver_info(mem_ctx,
5027 r->driver_version = 0;
5029 r->manufacturer_name = talloc_strdup(mem_ctx, "");
5030 W_ERROR_HAVE_NO_MEMORY(r->manufacturer_name);
5031 r->manufacturer_url = talloc_strdup(mem_ctx, "");
5032 W_ERROR_HAVE_NO_MEMORY(r->manufacturer_url);
5033 r->hardware_id = talloc_strdup(mem_ctx, "");
5034 W_ERROR_HAVE_NO_MEMORY(r->hardware_id);
5035 r->provider = talloc_strdup(mem_ctx, "");
5036 W_ERROR_HAVE_NO_MEMORY(r->provider);
5041 /********************************************************************
5042 ********************************************************************/
5044 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
5045 struct spoolss_DriverFileInfo *r,
5046 const char *cservername,
5047 const char *file_name,
5048 enum spoolss_DriverFileType file_type,
5049 uint32_t file_version)
5051 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
5052 cservername, file_name);
5053 W_ERROR_HAVE_NO_MEMORY(r->file_name);
5054 r->file_type = file_type;
5055 r->file_version = file_version;
5060 /********************************************************************
5061 ********************************************************************/
5063 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
5064 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
5065 const char *cservername,
5066 struct spoolss_DriverFileInfo **info_p,
5069 struct spoolss_DriverFileInfo *info = NULL;
5077 if (strlen(driver->info_3->driverpath)) {
5078 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5079 struct spoolss_DriverFileInfo,
5081 W_ERROR_HAVE_NO_MEMORY(info);
5082 result = fill_spoolss_DriverFileInfo(info,
5085 driver->info_3->driverpath,
5086 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
5088 W_ERROR_NOT_OK_RETURN(result);
5092 if (strlen(driver->info_3->configfile)) {
5093 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5094 struct spoolss_DriverFileInfo,
5096 W_ERROR_HAVE_NO_MEMORY(info);
5097 result = fill_spoolss_DriverFileInfo(info,
5100 driver->info_3->configfile,
5101 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
5103 W_ERROR_NOT_OK_RETURN(result);
5107 if (strlen(driver->info_3->datafile)) {
5108 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5109 struct spoolss_DriverFileInfo,
5111 W_ERROR_HAVE_NO_MEMORY(info);
5112 result = fill_spoolss_DriverFileInfo(info,
5115 driver->info_3->datafile,
5116 SPOOLSS_DRIVER_FILE_TYPE_DATA,
5118 W_ERROR_NOT_OK_RETURN(result);
5122 if (strlen(driver->info_3->helpfile)) {
5123 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5124 struct spoolss_DriverFileInfo,
5126 W_ERROR_HAVE_NO_MEMORY(info);
5127 result = fill_spoolss_DriverFileInfo(info,
5130 driver->info_3->helpfile,
5131 SPOOLSS_DRIVER_FILE_TYPE_HELP,
5133 W_ERROR_NOT_OK_RETURN(result);
5137 for (i=0; driver->info_3->dependentfiles[i][0] != '\0'; i++) {
5138 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5139 struct spoolss_DriverFileInfo,
5141 W_ERROR_HAVE_NO_MEMORY(info);
5142 result = fill_spoolss_DriverFileInfo(info,
5145 driver->info_3->dependentfiles[i],
5146 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
5148 W_ERROR_NOT_OK_RETURN(result);
5158 /********************************************************************
5159 * fill a spoolss_DriverInfo101 sttruct
5160 ********************************************************************/
5162 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
5163 struct spoolss_DriverInfo101 *r,
5164 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
5165 const char *servername)
5167 const char *cservername = canon_servername(servername);
5170 r->version = driver->info_3->cversion;
5172 r->driver_name = talloc_strdup(mem_ctx, driver->info_3->name);
5173 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5174 r->architecture = talloc_strdup(mem_ctx, driver->info_3->environment);
5175 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5177 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
5181 if (!W_ERROR_IS_OK(result)) {
5185 r->monitor_name = talloc_strdup(mem_ctx, driver->info_3->monitorname);
5186 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
5188 r->default_datatype = talloc_strdup(mem_ctx, driver->info_3->defaultdatatype);
5189 W_ERROR_HAVE_NO_MEMORY(r->default_datatype);
5191 r->previous_names = string_array_from_driver_info(mem_ctx,
5195 r->driver_version = 0;
5197 r->manufacturer_name = talloc_strdup(mem_ctx, "");
5198 W_ERROR_HAVE_NO_MEMORY(r->manufacturer_name);
5199 r->manufacturer_url = talloc_strdup(mem_ctx, "");
5200 W_ERROR_HAVE_NO_MEMORY(r->manufacturer_url);
5201 r->hardware_id = talloc_strdup(mem_ctx, "");
5202 W_ERROR_HAVE_NO_MEMORY(r->hardware_id);
5203 r->provider = talloc_strdup(mem_ctx, "");
5204 W_ERROR_HAVE_NO_MEMORY(r->provider);
5209 /********************************************************************
5210 * construct_printer_driver_info_1
5211 ********************************************************************/
5213 static WERROR construct_printer_driver_info_1(TALLOC_CTX *mem_ctx,
5214 struct spoolss_DriverInfo1 *r,
5216 const char *servername,
5217 const char *architecture,
5220 NT_PRINTER_INFO_LEVEL *printer = NULL;
5221 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5224 ZERO_STRUCT(driver);
5226 if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, lp_const_servicename(snum))))
5227 return WERR_INVALID_PRINTER_NAME;
5229 if (!W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version))) {
5230 free_a_printer(&printer, 2);
5231 return WERR_UNKNOWN_PRINTER_DRIVER;
5234 result = fill_printer_driver_info1(mem_ctx, r, &driver, servername, architecture);
5236 free_a_printer(&printer,2);
5241 /********************************************************************
5242 * construct_printer_driver_info_2
5243 * fill a printer_info_2 struct
5244 ********************************************************************/
5246 static WERROR construct_printer_driver_info_2(TALLOC_CTX *mem_ctx,
5247 struct spoolss_DriverInfo2 *r,
5249 const char *servername,
5250 const char *architecture,
5253 NT_PRINTER_INFO_LEVEL *printer = NULL;
5254 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5257 ZERO_STRUCT(printer);
5258 ZERO_STRUCT(driver);
5260 if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, lp_const_servicename(snum))))
5261 return WERR_INVALID_PRINTER_NAME;
5263 if (!W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version))) {
5264 free_a_printer(&printer, 2);
5265 return WERR_UNKNOWN_PRINTER_DRIVER;
5268 result = fill_printer_driver_info2(mem_ctx, r, &driver, servername);
5270 free_a_printer(&printer,2);
5275 /********************************************************************
5276 * construct_printer_info_3
5277 * fill a printer_info_3 struct
5278 ********************************************************************/
5280 static WERROR construct_printer_driver_info_3(TALLOC_CTX *mem_ctx,
5281 struct spoolss_DriverInfo3 *r,
5283 const char *servername,
5284 const char *architecture,
5287 NT_PRINTER_INFO_LEVEL *printer = NULL;
5288 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5290 ZERO_STRUCT(driver);
5292 status=get_a_printer(NULL, &printer, 2, lp_const_servicename(snum) );
5293 DEBUG(8,("construct_printer_driver_info_3: status: %s\n", win_errstr(status)));
5294 if (!W_ERROR_IS_OK(status))
5295 return WERR_INVALID_PRINTER_NAME;
5297 status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version);
5298 DEBUG(8,("construct_printer_driver_info_3: status: %s\n", win_errstr(status)));
5303 * I put this code in during testing. Helpful when commenting out the
5304 * support for DRIVER_INFO_6 in regards to win2k. Not needed in general
5305 * as win2k always queries the driver using an infor level of 6.
5306 * I've left it in (but ifdef'd out) because I'll probably
5307 * use it in experimentation again in the future. --jerry 22/01/2002
5310 if (!W_ERROR_IS_OK(status)) {
5312 * Is this a W2k client ?
5315 /* Yes - try again with a WinNT driver. */
5317 status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version);
5318 DEBUG(8,("construct_printer_driver_info_3: status: %s\n", win_errstr(status)));
5322 if (!W_ERROR_IS_OK(status)) {
5323 free_a_printer(&printer,2);
5324 return WERR_UNKNOWN_PRINTER_DRIVER;
5332 status = fill_printer_driver_info3(mem_ctx, r, &driver, servername);
5334 free_a_printer(&printer,2);
5339 /********************************************************************
5340 * construct_printer_info_6
5341 * fill a printer_info_6 struct
5342 ********************************************************************/
5344 static WERROR construct_printer_driver_info_6(TALLOC_CTX *mem_ctx,
5345 struct spoolss_DriverInfo6 *r,
5347 const char *servername,
5348 const char *architecture,
5351 NT_PRINTER_INFO_LEVEL *printer = NULL;
5352 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5355 ZERO_STRUCT(driver);
5357 status=get_a_printer(NULL, &printer, 2, lp_const_servicename(snum) );
5359 DEBUG(8,("construct_printer_driver_info_6: status: %s\n", win_errstr(status)));
5361 if (!W_ERROR_IS_OK(status))
5362 return WERR_INVALID_PRINTER_NAME;
5364 status = get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version);
5366 DEBUG(8,("construct_printer_driver_info_6: status: %s\n", win_errstr(status)));
5368 if (!W_ERROR_IS_OK(status))
5371 * Is this a W2k client ?
5375 free_a_printer(&printer,2);
5376 return WERR_UNKNOWN_PRINTER_DRIVER;
5379 /* Yes - try again with a WinNT driver. */
5381 status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version);
5382 DEBUG(8,("construct_printer_driver_info_6: status: %s\n", win_errstr(status)));
5383 if (!W_ERROR_IS_OK(status)) {
5384 free_a_printer(&printer,2);
5385 return WERR_UNKNOWN_PRINTER_DRIVER;
5389 status = fill_printer_driver_info6(mem_ctx, r, &driver, servername);
5391 free_a_printer(&printer,2);
5392 free_a_printer_driver(driver, 3);
5397 /********************************************************************
5398 * construct_printer_info_101
5399 * fill a printer_info_101 struct
5400 ********************************************************************/
5402 static WERROR construct_printer_driver_info_101(TALLOC_CTX *mem_ctx,
5403 struct spoolss_DriverInfo101 *r,
5405 const char *servername,
5406 const char *architecture,
5409 NT_PRINTER_INFO_LEVEL *printer = NULL;
5410 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5413 ZERO_STRUCT(driver);
5415 result = get_a_printer(NULL, &printer, 2, lp_const_servicename(snum));
5417 DEBUG(8,("construct_printer_driver_info_101: status: %s\n",
5418 win_errstr(result)));
5420 if (!W_ERROR_IS_OK(result)) {
5421 return WERR_INVALID_PRINTER_NAME;
5424 result = get_a_printer_driver(&driver, 3, printer->info_2->drivername,
5425 architecture, version);
5427 DEBUG(8,("construct_printer_driver_info_101: status: %s\n",
5428 win_errstr(result)));
5430 if (!W_ERROR_IS_OK(result)) {
5432 * Is this a W2k client ?
5436 free_a_printer(&printer, 2);
5437 return WERR_UNKNOWN_PRINTER_DRIVER;
5440 /* Yes - try again with a WinNT driver. */
5442 result = get_a_printer_driver(&driver, 3, printer->info_2->drivername,
5443 architecture, version);
5444 DEBUG(8,("construct_printer_driver_info_6: status: %s\n",
5445 win_errstr(result)));
5446 if (!W_ERROR_IS_OK(result)) {
5447 free_a_printer(&printer, 2);
5448 return WERR_UNKNOWN_PRINTER_DRIVER;
5452 result = fill_printer_driver_info101(mem_ctx, r, &driver, servername);
5454 free_a_printer(&printer, 2);
5455 free_a_printer_driver(driver, 3);
5460 /****************************************************************
5461 _spoolss_GetPrinterDriver2
5462 ****************************************************************/
5464 WERROR _spoolss_GetPrinterDriver2(pipes_struct *p,
5465 struct spoolss_GetPrinterDriver2 *r)
5467 Printer_entry *printer;
5470 const char *servername;
5473 /* that's an [in out] buffer */
5475 if (!r->in.buffer && (r->in.offered != 0)) {
5476 return WERR_INVALID_PARAM;
5479 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5481 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5482 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5483 return WERR_INVALID_PRINTER_NAME;
5487 *r->out.server_major_version = 0;
5488 *r->out.server_minor_version = 0;
5490 servername = get_server_name(printer);
5492 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5496 switch (r->in.level) {
5498 result = construct_printer_driver_info_1(p->mem_ctx,
5499 &r->out.info->info1,
5503 r->in.client_major_version);
5506 result = construct_printer_driver_info_2(p->mem_ctx,
5507 &r->out.info->info2,
5511 r->in.client_major_version);
5514 result = construct_printer_driver_info_3(p->mem_ctx,
5515 &r->out.info->info3,
5519 r->in.client_major_version);
5522 result = construct_printer_driver_info_6(p->mem_ctx,
5523 &r->out.info->info6,
5527 r->in.client_major_version);
5530 result = construct_printer_driver_info_101(p->mem_ctx,
5531 &r->out.info->info101,
5535 r->in.client_major_version);
5538 result = WERR_UNKNOWN_LEVEL;
5542 if (!W_ERROR_IS_OK(result)) {
5543 TALLOC_FREE(r->out.info);
5547 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo, NULL,
5548 r->out.info, r->in.level);
5549 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5551 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5555 /****************************************************************
5556 _spoolss_StartPagePrinter
5557 ****************************************************************/
5559 WERROR _spoolss_StartPagePrinter(pipes_struct *p,
5560 struct spoolss_StartPagePrinter *r)
5562 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5565 DEBUG(3,("_spoolss_StartPagePrinter: "
5566 "Error in startpageprinter printer handle\n"));
5570 Printer->page_started = true;
5574 /****************************************************************
5575 _spoolss_EndPagePrinter
5576 ****************************************************************/
5578 WERROR _spoolss_EndPagePrinter(pipes_struct *p,
5579 struct spoolss_EndPagePrinter *r)
5583 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5586 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5587 OUR_HANDLE(r->in.handle)));
5591 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5594 Printer->page_started = false;
5595 print_job_endpage(snum, Printer->jobid);
5600 /****************************************************************
5601 _spoolss_StartDocPrinter
5602 ****************************************************************/
5604 WERROR _spoolss_StartDocPrinter(pipes_struct *p,
5605 struct spoolss_StartDocPrinter *r)
5607 struct spoolss_DocumentInfo1 *info_1;
5609 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5612 DEBUG(2,("_spoolss_StartDocPrinter: "
5613 "Invalid handle (%s:%u:%u)\n",
5614 OUR_HANDLE(r->in.handle)));
5618 if (r->in.level != 1) {
5619 return WERR_UNKNOWN_LEVEL;
5622 info_1 = r->in.info.info1;
5625 * a nice thing with NT is it doesn't listen to what you tell it.
5626 * when asked to send _only_ RAW datas, it tries to send datas
5629 * So I add checks like in NT Server ...
5632 if (info_1->datatype) {
5633 if (strcmp(info_1->datatype, "RAW") != 0) {
5635 return WERR_INVALID_DATATYPE;
5639 /* get the share number of the printer */
5640 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5644 Printer->jobid = print_job_start(p->server_info, snum,
5645 info_1->document_name,
5646 Printer->nt_devmode);
5648 /* An error occured in print_job_start() so return an appropriate
5651 if (Printer->jobid == -1) {
5652 return map_werror_from_unix(errno);
5655 Printer->document_started = true;
5656 *r->out.job_id = Printer->jobid;
5661 /****************************************************************
5662 _spoolss_EndDocPrinter
5663 ****************************************************************/
5665 WERROR _spoolss_EndDocPrinter(pipes_struct *p,
5666 struct spoolss_EndDocPrinter *r)
5668 return _spoolss_enddocprinter_internal(p, r->in.handle);
5671 /****************************************************************
5672 _spoolss_WritePrinter
5673 ****************************************************************/
5675 WERROR _spoolss_WritePrinter(pipes_struct *p,
5676 struct spoolss_WritePrinter *r)
5678 uint32_t buffer_written;
5680 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5683 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5684 OUR_HANDLE(r->in.handle)));
5685 *r->out.num_written = r->in._data_size;
5689 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5692 buffer_written = (uint32_t)print_job_write(snum, Printer->jobid,
5693 (const char *)r->in.data.data,
5695 (size_t)r->in._data_size);
5696 if (buffer_written == (uint32_t)-1) {
5697 *r->out.num_written = 0;
5698 if (errno == ENOSPC)
5699 return WERR_NO_SPOOL_SPACE;
5701 return WERR_ACCESS_DENIED;
5704 *r->out.num_written = r->in._data_size;
5709 /********************************************************************
5710 * api_spoolss_getprinter
5711 * called from the spoolss dispatcher
5713 ********************************************************************/
5715 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5719 WERROR errcode = WERR_BADFUNC;
5720 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5723 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5724 OUR_HANDLE(handle)));
5728 if (!get_printer_snum(p, handle, &snum, NULL))
5732 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5733 errcode = print_queue_pause(p->server_info, snum);
5735 case SPOOLSS_PRINTER_CONTROL_RESUME:
5736 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5737 errcode = print_queue_resume(p->server_info, snum);
5739 case SPOOLSS_PRINTER_CONTROL_PURGE:
5740 errcode = print_queue_purge(p->server_info, snum);
5743 return WERR_UNKNOWN_LEVEL;
5750 /****************************************************************
5751 _spoolss_AbortPrinter
5752 * From MSDN: "Deletes printer's spool file if printer is configured
5754 ****************************************************************/
5756 WERROR _spoolss_AbortPrinter(pipes_struct *p,
5757 struct spoolss_AbortPrinter *r)
5759 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5761 WERROR errcode = WERR_OK;
5764 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5765 OUR_HANDLE(r->in.handle)));
5769 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5772 print_job_delete(p->server_info, snum, Printer->jobid, &errcode );
5777 /********************************************************************
5778 * called by spoolss_api_setprinter
5779 * when updating a printer description
5780 ********************************************************************/
5782 static WERROR update_printer_sec(struct policy_handle *handle,
5783 pipes_struct *p, SEC_DESC_BUF *secdesc_ctr)
5785 SEC_DESC_BUF *new_secdesc_ctr = NULL, *old_secdesc_ctr = NULL;
5789 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5791 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
5792 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5793 OUR_HANDLE(handle)));
5795 result = WERR_BADFID;
5800 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5801 result = WERR_INVALID_PARAM;
5805 /* Check the user has permissions to change the security
5806 descriptor. By experimentation with two NT machines, the user
5807 requires Full Access to the printer to change security
5810 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
5811 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5812 result = WERR_ACCESS_DENIED;
5816 /* NT seems to like setting the security descriptor even though
5817 nothing may have actually changed. */
5819 if ( !nt_printing_getsec(p->mem_ctx, Printer->sharename, &old_secdesc_ctr)) {
5820 DEBUG(2,("update_printer_sec: nt_printing_getsec() failed\n"));
5821 result = WERR_BADFID;
5825 if (DEBUGLEVEL >= 10) {
5829 the_acl = old_secdesc_ctr->sd->dacl;
5830 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
5831 PRINTERNAME(snum), the_acl->num_aces));
5833 for (i = 0; i < the_acl->num_aces; i++) {
5834 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5835 &the_acl->aces[i].trustee),
5836 the_acl->aces[i].access_mask));
5839 the_acl = secdesc_ctr->sd->dacl;
5842 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
5843 PRINTERNAME(snum), the_acl->num_aces));
5845 for (i = 0; i < the_acl->num_aces; i++) {
5846 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5847 &the_acl->aces[i].trustee),
5848 the_acl->aces[i].access_mask));
5851 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
5855 new_secdesc_ctr = sec_desc_merge(p->mem_ctx, secdesc_ctr, old_secdesc_ctr);
5856 if (!new_secdesc_ctr) {
5857 result = WERR_NOMEM;
5861 if (security_descriptor_equal(new_secdesc_ctr->sd, old_secdesc_ctr->sd)) {
5866 result = nt_printing_setsec(Printer->sharename, new_secdesc_ctr);
5873 /********************************************************************
5874 Canonicalize printer info from a client
5876 ATTN: It does not matter what we set the servername to hear
5877 since we do the necessary work in get_a_printer() to set it to
5878 the correct value based on what the client sent in the
5879 _spoolss_open_printer_ex().
5880 ********************************************************************/
5882 static bool check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum)
5884 fstring printername;
5887 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
5888 "portname=%s drivername=%s comment=%s location=%s\n",
5889 info->servername, info->printername, info->sharename,
5890 info->portname, info->drivername, info->comment, info->location));
5892 /* we force some elements to "correct" values */
5893 slprintf(info->servername, sizeof(info->servername)-1, "\\\\%s", global_myname());
5894 fstrcpy(info->sharename, lp_servicename(snum));
5896 /* check to see if we allow printername != sharename */
5898 if ( lp_force_printername(snum) ) {
5899 slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s",
5900 global_myname(), info->sharename );
5903 /* make sure printername is in \\server\printername format */
5905 fstrcpy( printername, info->printername );
5907 if ( printername[0] == '\\' && printername[1] == '\\' ) {
5908 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
5912 slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s",
5913 global_myname(), p );
5916 info->attributes |= PRINTER_ATTRIBUTE_SAMBA;
5917 info->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
5924 /****************************************************************************
5925 ****************************************************************************/
5927 WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *portname, const char *uri )
5929 char *cmd = lp_addport_cmd();
5930 char *command = NULL;
5932 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5933 bool is_print_op = false;
5936 return WERR_ACCESS_DENIED;
5939 command = talloc_asprintf(ctx,
5940 "%s \"%s\" \"%s\"", cmd, portname, uri );
5946 is_print_op = user_has_privileges( token, &se_printop );
5948 DEBUG(10,("Running [%s]\n", command));
5950 /********* BEGIN SePrintOperatorPrivilege **********/
5955 ret = smbrun(command, NULL);
5960 /********* END SePrintOperatorPrivilege **********/
5962 DEBUGADD(10,("returned [%d]\n", ret));
5964 TALLOC_FREE(command);
5967 return WERR_ACCESS_DENIED;
5973 /****************************************************************************
5974 ****************************************************************************/
5976 bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer)
5978 char *cmd = lp_addprinter_cmd();
5980 char *command = NULL;
5984 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5985 bool is_print_op = false;
5986 char *remote_machine = talloc_strdup(ctx, "%m");
5988 if (!remote_machine) {
5991 remote_machine = talloc_sub_basic(ctx,
5992 current_user_info.smb_name,
5993 current_user_info.domain,
5995 if (!remote_machine) {
5999 command = talloc_asprintf(ctx,
6000 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
6001 cmd, printer->info_2->printername, printer->info_2->sharename,
6002 printer->info_2->portname, printer->info_2->drivername,
6003 printer->info_2->location, printer->info_2->comment, remote_machine);
6009 is_print_op = user_has_privileges( token, &se_printop );
6011 DEBUG(10,("Running [%s]\n", command));
6013 /********* BEGIN SePrintOperatorPrivilege **********/
6018 if ( (ret = smbrun(command, &fd)) == 0 ) {
6019 /* Tell everyone we updated smb.conf. */
6020 message_send_all(smbd_messaging_context(),
6021 MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
6027 /********* END SePrintOperatorPrivilege **********/
6029 DEBUGADD(10,("returned [%d]\n", ret));
6031 TALLOC_FREE(command);
6032 TALLOC_FREE(remote_machine);
6040 /* reload our services immediately */
6041 reload_services(false);
6044 /* Get lines and convert them back to dos-codepage */
6045 qlines = fd_lines_load(fd, &numlines, 0, NULL);
6046 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
6049 /* Set the portname to what the script says the portname should be. */
6050 /* but don't require anything to be return from the script exit a good error code */
6053 /* Set the portname to what the script says the portname should be. */
6054 strncpy(printer->info_2->portname, qlines[0], sizeof(printer->info_2->portname));
6055 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
6058 TALLOC_FREE(qlines);
6063 /********************************************************************
6064 * Called by spoolss_api_setprinter
6065 * when updating a printer description.
6066 ********************************************************************/
6068 static WERROR update_printer(pipes_struct *p, struct policy_handle *handle,
6069 struct spoolss_SetPrinterInfoCtr *info_ctr,
6070 struct spoolss_DeviceMode *devmode)
6073 NT_PRINTER_INFO_LEVEL *printer = NULL, *old_printer = NULL;
6074 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
6079 DEBUG(8,("update_printer\n"));
6084 result = WERR_BADFID;
6088 if (!get_printer_snum(p, handle, &snum, NULL)) {
6089 result = WERR_BADFID;
6093 if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum))) ||
6094 (!W_ERROR_IS_OK(get_a_printer(Printer, &old_printer, 2, lp_const_servicename(snum))))) {
6095 result = WERR_BADFID;
6099 DEBUGADD(8,("Converting info_2 struct\n"));
6102 * convert_printer_info converts the incoming
6103 * info from the client and overwrites the info
6104 * just read from the tdb in the pointer 'printer'.
6107 if (!convert_printer_info(info_ctr, printer)) {
6108 result = WERR_NOMEM;
6113 /* we have a valid devmode
6114 convert it and link it*/
6116 DEBUGADD(8,("update_printer: Converting the devicemode struct\n"));
6117 if (!convert_devicemode(printer->info_2->printername, devmode,
6118 &printer->info_2->devmode)) {
6119 result = WERR_NOMEM;
6124 /* Do sanity check on the requested changes for Samba */
6126 if (!check_printer_ok(printer->info_2, snum)) {
6127 result = WERR_INVALID_PARAM;
6131 /* FIXME!!! If the driver has changed we really should verify that
6132 it is installed before doing much else --jerry */
6134 /* Check calling user has permission to update printer description */
6136 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6137 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6138 result = WERR_ACCESS_DENIED;
6142 /* Call addprinter hook */
6143 /* Check changes to see if this is really needed */
6145 if ( *lp_addprinter_cmd()
6146 && (!strequal(printer->info_2->drivername, old_printer->info_2->drivername)
6147 || !strequal(printer->info_2->comment, old_printer->info_2->comment)
6148 || !strequal(printer->info_2->portname, old_printer->info_2->portname)
6149 || !strequal(printer->info_2->location, old_printer->info_2->location)) )
6151 /* add_printer_hook() will call reload_services() */
6153 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
6155 result = WERR_ACCESS_DENIED;
6161 * When a *new* driver is bound to a printer, the drivername is used to
6162 * lookup previously saved driver initialization info, which is then
6163 * bound to the printer, simulating what happens in the Windows arch.
6165 if (!strequal(printer->info_2->drivername, old_printer->info_2->drivername))
6167 if (!set_driver_init(printer, 2))
6169 DEBUG(5,("update_printer: Error restoring driver initialization data for driver [%s]!\n",
6170 printer->info_2->drivername));
6173 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6174 printer->info_2->drivername));
6176 notify_printer_driver(snum, printer->info_2->drivername);
6180 * flag which changes actually occured. This is a small subset of
6181 * all the possible changes. We also have to update things in the
6185 if (!strequal(printer->info_2->comment, old_printer->info_2->comment)) {
6186 init_unistr2( &buffer, printer->info_2->comment, UNI_STR_TERMINATE);
6187 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "description",
6188 REG_SZ, (uint8_t *)buffer.buffer, buffer.uni_str_len*2 );
6190 notify_printer_comment(snum, printer->info_2->comment);
6193 if (!strequal(printer->info_2->sharename, old_printer->info_2->sharename)) {
6194 init_unistr2( &buffer, printer->info_2->sharename, UNI_STR_TERMINATE);
6195 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "shareName",
6196 REG_SZ, (uint8_t *)buffer.buffer, buffer.uni_str_len*2 );
6198 notify_printer_sharename(snum, printer->info_2->sharename);
6201 if (!strequal(printer->info_2->printername, old_printer->info_2->printername)) {
6204 if ( (pname = strchr_m( printer->info_2->printername+2, '\\' )) != NULL )
6207 pname = printer->info_2->printername;
6210 init_unistr2( &buffer, pname, UNI_STR_TERMINATE);
6211 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "printerName",
6212 REG_SZ, (uint8_t *)buffer.buffer, buffer.uni_str_len*2 );
6214 notify_printer_printername( snum, pname );
6217 if (!strequal(printer->info_2->portname, old_printer->info_2->portname)) {
6218 init_unistr2( &buffer, printer->info_2->portname, UNI_STR_TERMINATE);
6219 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "portName",
6220 REG_SZ, (uint8_t *)buffer.buffer, buffer.uni_str_len*2 );
6222 notify_printer_port(snum, printer->info_2->portname);
6225 if (!strequal(printer->info_2->location, old_printer->info_2->location)) {
6226 init_unistr2( &buffer, printer->info_2->location, UNI_STR_TERMINATE);
6227 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "location",
6228 REG_SZ, (uint8_t *)buffer.buffer, buffer.uni_str_len*2 );
6230 notify_printer_location(snum, printer->info_2->location);
6233 /* here we need to update some more DsSpooler keys */
6234 /* uNCName, serverName, shortServerName */
6236 init_unistr2( &buffer, global_myname(), UNI_STR_TERMINATE);
6237 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "serverName",
6238 REG_SZ, (uint8_t *)buffer.buffer, buffer.uni_str_len*2 );
6239 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "shortServerName",
6240 REG_SZ, (uint8_t *)buffer.buffer, buffer.uni_str_len*2 );
6242 slprintf( asc_buffer, sizeof(asc_buffer)-1, "\\\\%s\\%s",
6243 global_myname(), printer->info_2->sharename );
6244 init_unistr2( &buffer, asc_buffer, UNI_STR_TERMINATE);
6245 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "uNCName",
6246 REG_SZ, (uint8_t *)buffer.buffer, buffer.uni_str_len*2 );
6248 /* Update printer info */
6249 result = mod_a_printer(printer, 2);
6252 free_a_printer(&printer, 2);
6253 free_a_printer(&old_printer, 2);
6259 /****************************************************************************
6260 ****************************************************************************/
6261 static WERROR publish_or_unpublish_printer(pipes_struct *p,
6262 struct policy_handle *handle,
6263 struct spoolss_SetPrinterInfo7 *info7)
6267 Printer_entry *Printer;
6269 if ( lp_security() != SEC_ADS ) {
6270 return WERR_UNKNOWN_LEVEL;
6273 Printer = find_printer_index_by_hnd(p, handle);
6275 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6280 if (!get_printer_snum(p, handle, &snum, NULL))
6283 nt_printer_publish(Printer, snum, info7->action);
6287 return WERR_UNKNOWN_LEVEL;
6291 /****************************************************************
6293 ****************************************************************/
6295 WERROR _spoolss_SetPrinter(pipes_struct *p,
6296 struct spoolss_SetPrinter *r)
6300 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
6303 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6304 OUR_HANDLE(r->in.handle)));
6308 /* check the level */
6309 switch (r->in.info_ctr->level) {
6311 return control_printer(r->in.handle, r->in.command, p);
6313 result = update_printer(p, r->in.handle,
6315 r->in.devmode_ctr->devmode);
6316 if (!W_ERROR_IS_OK(result))
6318 if (r->in.secdesc_ctr->sd)
6319 result = update_printer_sec(r->in.handle, p,
6323 return update_printer_sec(r->in.handle, p,
6326 return publish_or_unpublish_printer(p, r->in.handle,
6327 r->in.info_ctr->info.info7);
6329 return WERR_UNKNOWN_LEVEL;
6333 /****************************************************************
6334 _spoolss_FindClosePrinterNotify
6335 ****************************************************************/
6337 WERROR _spoolss_FindClosePrinterNotify(pipes_struct *p,
6338 struct spoolss_FindClosePrinterNotify *r)
6340 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
6343 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6344 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
6348 if (Printer->notify.client_connected == true) {
6351 if ( Printer->printer_type == SPLHND_SERVER)
6353 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
6354 !get_printer_snum(p, r->in.handle, &snum, NULL) )
6357 srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
6360 Printer->notify.flags=0;
6361 Printer->notify.options=0;
6362 Printer->notify.localmachine[0]='\0';
6363 Printer->notify.printerlocal=0;
6364 TALLOC_FREE(Printer->notify.option);
6365 Printer->notify.client_connected = false;
6370 /****************************************************************
6372 ****************************************************************/
6374 WERROR _spoolss_AddJob(pipes_struct *p,
6375 struct spoolss_AddJob *r)
6377 if (!r->in.buffer && (r->in.offered != 0)) {
6378 return WERR_INVALID_PARAM;
6381 /* this is what a NT server returns for AddJob. AddJob must fail on
6382 * non-local printers */
6384 if (r->in.level != 1) {
6385 return WERR_UNKNOWN_LEVEL;
6388 return WERR_INVALID_PARAM;
6391 /****************************************************************************
6393 ****************************************************************************/
6395 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
6396 struct spoolss_JobInfo1 *r,
6397 const print_queue_struct *queue,
6398 int position, int snum,
6399 const NT_PRINTER_INFO_LEVEL *ntprinter)
6403 t = gmtime(&queue->time);
6405 r->job_id = queue->job;
6407 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6408 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6409 r->server_name = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
6410 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6411 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6412 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6413 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6414 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6415 r->data_type = talloc_strdup(mem_ctx, "RAW");
6416 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6417 r->text_status = talloc_strdup(mem_ctx, "");
6418 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6420 r->status = nt_printj_status(queue->status);
6421 r->priority = queue->priority;
6422 r->position = position;
6423 r->total_pages = queue->page_count;
6424 r->pages_printed = 0; /* ??? */
6426 init_systemtime(&r->submitted, t);
6431 /****************************************************************************
6433 ****************************************************************************/
6435 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
6436 struct spoolss_JobInfo2 *r,
6437 const print_queue_struct *queue,
6438 int position, int snum,
6439 const NT_PRINTER_INFO_LEVEL *ntprinter,
6440 struct spoolss_DeviceMode *devmode)
6444 t = gmtime(&queue->time);
6446 r->job_id = queue->job;
6448 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6449 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6450 r->server_name = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
6451 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6452 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6453 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6454 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6455 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6456 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
6457 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
6458 r->data_type = talloc_strdup(mem_ctx, "RAW");
6459 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6460 r->print_processor = talloc_strdup(mem_ctx, "winprint");
6461 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
6462 r->parameters = talloc_strdup(mem_ctx, "");
6463 W_ERROR_HAVE_NO_MEMORY(r->parameters);
6464 r->driver_name = talloc_strdup(mem_ctx, ntprinter->info_2->drivername);
6465 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
6467 r->devmode = devmode;
6469 r->text_status = talloc_strdup(mem_ctx, "");
6470 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6474 r->status = nt_printj_status(queue->status);
6475 r->priority = queue->priority;
6476 r->position = position;
6479 r->total_pages = queue->page_count;
6480 r->size = queue->size;
6481 init_systemtime(&r->submitted, t);
6483 r->pages_printed = 0; /* ??? */
6488 /****************************************************************************
6489 Enumjobs at level 1.
6490 ****************************************************************************/
6492 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
6493 const print_queue_struct *queue,
6494 uint32_t num_queues, int snum,
6495 const NT_PRINTER_INFO_LEVEL *ntprinter,
6496 union spoolss_JobInfo **info_p,
6499 union spoolss_JobInfo *info;
6501 WERROR result = WERR_OK;
6503 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6504 W_ERROR_HAVE_NO_MEMORY(info);
6506 *count = num_queues;
6508 for (i=0; i<*count; i++) {
6509 result = fill_job_info1(info,
6515 if (!W_ERROR_IS_OK(result)) {
6521 if (!W_ERROR_IS_OK(result)) {
6532 /****************************************************************************
6533 Enumjobs at level 2.
6534 ****************************************************************************/
6536 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
6537 const print_queue_struct *queue,
6538 uint32_t num_queues, int snum,
6539 const NT_PRINTER_INFO_LEVEL *ntprinter,
6540 union spoolss_JobInfo **info_p,
6543 union spoolss_JobInfo *info;
6545 WERROR result = WERR_OK;
6547 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6548 W_ERROR_HAVE_NO_MEMORY(info);
6550 *count = num_queues;
6552 for (i=0; i<*count; i++) {
6554 struct spoolss_DeviceMode *devmode;
6556 devmode = construct_dev_mode(info, lp_const_servicename(snum));
6558 result = WERR_NOMEM;
6562 result = fill_job_info2(info,
6569 if (!W_ERROR_IS_OK(result)) {
6575 if (!W_ERROR_IS_OK(result)) {
6586 /****************************************************************
6588 ****************************************************************/
6590 WERROR _spoolss_EnumJobs(pipes_struct *p,
6591 struct spoolss_EnumJobs *r)
6594 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
6596 print_status_struct prt_status;
6597 print_queue_struct *queue = NULL;
6600 /* that's an [in out] buffer */
6602 if (!r->in.buffer && (r->in.offered != 0)) {
6603 return WERR_INVALID_PARAM;
6606 DEBUG(4,("_spoolss_EnumJobs\n"));
6610 *r->out.info = NULL;
6612 /* lookup the printer snum and tdb entry */
6614 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6618 result = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum));
6619 if (!W_ERROR_IS_OK(result)) {
6623 count = print_queue_status(snum, &queue, &prt_status);
6624 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
6625 count, prt_status.status, prt_status.message));
6629 free_a_printer(&ntprinter, 2);
6633 switch (r->in.level) {
6635 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
6636 ntprinter, r->out.info, r->out.count);
6639 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
6640 ntprinter, r->out.info, r->out.count);
6643 result = WERR_UNKNOWN_LEVEL;
6648 free_a_printer(&ntprinter, 2);
6650 if (!W_ERROR_IS_OK(result)) {
6654 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6655 spoolss_EnumJobs, NULL,
6656 *r->out.info, r->in.level,
6658 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6659 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6661 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6664 /****************************************************************
6665 _spoolss_ScheduleJob
6666 ****************************************************************/
6668 WERROR _spoolss_ScheduleJob(pipes_struct *p,
6669 struct spoolss_ScheduleJob *r)
6674 /****************************************************************
6676 ****************************************************************/
6678 WERROR _spoolss_SetJob(pipes_struct *p,
6679 struct spoolss_SetJob *r)
6682 WERROR errcode = WERR_BADFUNC;
6684 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6688 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
6689 return WERR_INVALID_PRINTER_NAME;
6692 switch (r->in.command) {
6693 case SPOOLSS_JOB_CONTROL_CANCEL:
6694 case SPOOLSS_JOB_CONTROL_DELETE:
6695 if (print_job_delete(p->server_info, snum, r->in.job_id, &errcode)) {
6699 case SPOOLSS_JOB_CONTROL_PAUSE:
6700 if (print_job_pause(p->server_info, snum, r->in.job_id, &errcode)) {
6704 case SPOOLSS_JOB_CONTROL_RESTART:
6705 case SPOOLSS_JOB_CONTROL_RESUME:
6706 if (print_job_resume(p->server_info, snum, r->in.job_id, &errcode)) {
6711 return WERR_UNKNOWN_LEVEL;
6717 /****************************************************************************
6718 Enumerates all printer drivers by level.
6719 ****************************************************************************/
6721 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
6722 const char *servername,
6723 const char *architecture,
6725 union spoolss_DriverInfo **info_p,
6731 fstring *list = NULL;
6732 NT_PRINTER_DRIVER_INFO_LEVEL driver;
6733 union spoolss_DriverInfo *info = NULL;
6735 WERROR result = WERR_OK;
6740 for (version=0; version<DRIVER_MAX_VERSION; version++) {
6742 ndrivers = get_ntdrivers(&list, architecture, version);
6743 DEBUGADD(4,("we have:[%d] drivers in environment [%s] and version [%d]\n",
6744 ndrivers, architecture, version));
6746 if (ndrivers == -1) {
6747 result = WERR_NOMEM;
6751 if (ndrivers != 0) {
6752 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
6753 union spoolss_DriverInfo,
6756 DEBUG(0,("enumprinterdrivers_level1: "
6757 "failed to enlarge driver info buffer!\n"));
6758 result = WERR_NOMEM;
6763 for (i=0; i<ndrivers; i++) {
6764 DEBUGADD(5,("\tdriver: [%s]\n", list[i]));
6765 ZERO_STRUCT(driver);
6766 result = get_a_printer_driver(&driver, 3, list[i],
6767 architecture, version);
6768 if (!W_ERROR_IS_OK(result)) {
6774 result = fill_printer_driver_info1(info, &info[count+i].info1,
6775 &driver, servername,
6779 result = fill_printer_driver_info2(info, &info[count+i].info2,
6780 &driver, servername);
6783 result = fill_printer_driver_info3(info, &info[count+i].info3,
6784 &driver, servername);
6787 result = fill_printer_driver_info4(info, &info[count+i].info4,
6788 &driver, servername);
6791 result = fill_printer_driver_info5(info, &info[count+i].info5,
6792 &driver, servername);
6795 result = fill_printer_driver_info6(info, &info[count+i].info6,
6796 &driver, servername);
6799 result = WERR_UNKNOWN_LEVEL;
6803 if (!W_ERROR_IS_OK(result)) {
6804 free_a_printer_driver(driver, 3);
6807 free_a_printer_driver(driver, 3);
6817 if (!W_ERROR_IS_OK(result)) {
6828 /****************************************************************************
6829 Enumerates all printer drivers at level 1.
6830 ****************************************************************************/
6832 static WERROR enumprinterdrivers_level1(TALLOC_CTX *mem_ctx,
6833 const char *servername,
6834 const char *architecture,
6835 union spoolss_DriverInfo **info_p,
6838 return enumprinterdrivers_level(mem_ctx, servername, architecture, 1,
6842 /****************************************************************************
6843 Enumerates all printer drivers at level 2.
6844 ****************************************************************************/
6846 static WERROR enumprinterdrivers_level2(TALLOC_CTX *mem_ctx,
6847 const char *servername,
6848 const char *architecture,
6849 union spoolss_DriverInfo **info_p,
6852 return enumprinterdrivers_level(mem_ctx, servername, architecture, 2,
6856 /****************************************************************************
6857 Enumerates all printer drivers at level 3.
6858 ****************************************************************************/
6860 static WERROR enumprinterdrivers_level3(TALLOC_CTX *mem_ctx,
6861 const char *servername,
6862 const char *architecture,
6863 union spoolss_DriverInfo **info_p,
6866 return enumprinterdrivers_level(mem_ctx, servername, architecture, 3,
6870 /****************************************************************************
6871 Enumerates all printer drivers at level 4.
6872 ****************************************************************************/
6874 static WERROR enumprinterdrivers_level4(TALLOC_CTX *mem_ctx,
6875 const char *servername,
6876 const char *architecture,
6877 union spoolss_DriverInfo **info_p,
6880 return enumprinterdrivers_level(mem_ctx, servername, architecture, 4,
6884 /****************************************************************************
6885 Enumerates all printer drivers at level 5.
6886 ****************************************************************************/
6888 static WERROR enumprinterdrivers_level5(TALLOC_CTX *mem_ctx,
6889 const char *servername,
6890 const char *architecture,
6891 union spoolss_DriverInfo **info_p,
6894 return enumprinterdrivers_level(mem_ctx, servername, architecture, 5,
6898 /****************************************************************************
6899 Enumerates all printer drivers at level 6.
6900 ****************************************************************************/
6902 static WERROR enumprinterdrivers_level6(TALLOC_CTX *mem_ctx,
6903 const char *servername,
6904 const char *architecture,
6905 union spoolss_DriverInfo **info_p,
6908 return enumprinterdrivers_level(mem_ctx, servername, architecture, 6,
6913 /****************************************************************
6914 _spoolss_EnumPrinterDrivers
6915 ****************************************************************/
6917 WERROR _spoolss_EnumPrinterDrivers(pipes_struct *p,
6918 struct spoolss_EnumPrinterDrivers *r)
6920 const char *cservername;
6923 /* that's an [in out] buffer */
6925 if (!r->in.buffer && (r->in.offered != 0)) {
6926 return WERR_INVALID_PARAM;
6929 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
6933 *r->out.info = NULL;
6935 cservername = canon_servername(r->in.server);
6937 if (!is_myname_or_ipaddr(cservername)) {
6938 return WERR_UNKNOWN_PRINTER_DRIVER;
6941 switch (r->in.level) {
6943 result = enumprinterdrivers_level1(p->mem_ctx, cservername,
6945 r->out.info, r->out.count);
6948 result = enumprinterdrivers_level2(p->mem_ctx, cservername,
6950 r->out.info, r->out.count);
6953 result = enumprinterdrivers_level3(p->mem_ctx, cservername,
6955 r->out.info, r->out.count);
6958 result = enumprinterdrivers_level4(p->mem_ctx, cservername,
6960 r->out.info, r->out.count);
6963 result = enumprinterdrivers_level5(p->mem_ctx, cservername,
6965 r->out.info, r->out.count);
6968 result = enumprinterdrivers_level6(p->mem_ctx, cservername,
6970 r->out.info, r->out.count);
6973 return WERR_UNKNOWN_LEVEL;
6976 if (!W_ERROR_IS_OK(result)) {
6980 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6981 spoolss_EnumPrinterDrivers, NULL,
6982 *r->out.info, r->in.level,
6984 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6985 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6987 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6990 /****************************************************************************
6991 ****************************************************************************/
6993 static WERROR fill_form_info_1(TALLOC_CTX *mem_ctx,
6994 struct spoolss_FormInfo1 *r,
6995 const nt_forms_struct *form)
6997 r->form_name = talloc_strdup(mem_ctx, form->name);
6998 W_ERROR_HAVE_NO_MEMORY(r->form_name);
7000 r->flags = form->flag;
7001 r->size.width = form->width;
7002 r->size.height = form->length;
7003 r->area.left = form->left;
7004 r->area.top = form->top;
7005 r->area.right = form->right;
7006 r->area.bottom = form->bottom;
7011 /****************************************************************
7012 spoolss_enumforms_level1
7013 ****************************************************************/
7015 static WERROR spoolss_enumforms_level1(TALLOC_CTX *mem_ctx,
7016 const nt_forms_struct *builtin_forms,
7017 uint32_t num_builtin_forms,
7018 const nt_forms_struct *user_forms,
7019 uint32_t num_user_forms,
7020 union spoolss_FormInfo **info_p,
7023 union spoolss_FormInfo *info;
7024 WERROR result = WERR_OK;
7027 *count = num_builtin_forms + num_user_forms;
7029 info = TALLOC_ARRAY(mem_ctx, union spoolss_FormInfo, *count);
7030 W_ERROR_HAVE_NO_MEMORY(info);
7032 /* construct the list of form structures */
7033 for (i=0; i<num_builtin_forms; i++) {
7034 DEBUGADD(6,("Filling form number [%d]\n",i));
7035 result = fill_form_info_1(info, &info[i].info1,
7037 if (!W_ERROR_IS_OK(result)) {
7042 for (; i<num_user_forms; i++) {
7043 DEBUGADD(6,("Filling form number [%d]\n",i));
7044 result = fill_form_info_1(info, &info[i].info1,
7045 &user_forms[i-num_builtin_forms]);
7046 if (!W_ERROR_IS_OK(result)) {
7052 if (!W_ERROR_IS_OK(result)) {
7063 /****************************************************************
7065 ****************************************************************/
7067 WERROR _spoolss_EnumForms(pipes_struct *p,
7068 struct spoolss_EnumForms *r)
7071 nt_forms_struct *user_forms = NULL;
7072 nt_forms_struct *builtin_forms = NULL;
7073 uint32_t num_user_forms;
7074 uint32_t num_builtin_forms;
7078 *r->out.info = NULL;
7080 /* that's an [in out] buffer */
7082 if (!r->in.buffer && (r->in.offered != 0) ) {
7083 return WERR_INVALID_PARAM;
7086 DEBUG(4,("_spoolss_EnumForms\n"));
7087 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7088 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7090 num_builtin_forms = get_builtin_ntforms(&builtin_forms);
7091 DEBUGADD(5,("Number of builtin forms [%d]\n", num_builtin_forms));
7092 num_user_forms = get_ntforms(&user_forms);
7093 DEBUGADD(5,("Number of user forms [%d]\n", num_user_forms));
7095 if (num_user_forms + num_builtin_forms == 0) {
7096 SAFE_FREE(builtin_forms);
7097 SAFE_FREE(user_forms);
7098 return WERR_NO_MORE_ITEMS;
7101 switch (r->in.level) {
7103 result = spoolss_enumforms_level1(p->mem_ctx,
7112 result = WERR_UNKNOWN_LEVEL;
7116 SAFE_FREE(user_forms);
7117 SAFE_FREE(builtin_forms);
7119 if (!W_ERROR_IS_OK(result)) {
7123 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7124 spoolss_EnumForms, NULL,
7125 *r->out.info, r->in.level,
7127 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7128 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7130 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7133 /****************************************************************
7134 ****************************************************************/
7136 static WERROR find_form_byname(const char *name,
7137 nt_forms_struct *form)
7139 nt_forms_struct *list = NULL;
7140 int num_forms = 0, i = 0;
7142 if (get_a_builtin_ntform_by_string(name, form)) {
7146 num_forms = get_ntforms(&list);
7147 DEBUGADD(5,("Number of forms [%d]\n", num_forms));
7149 if (num_forms == 0) {
7153 /* Check if the requested name is in the list of form structures */
7154 for (i = 0; i < num_forms; i++) {
7156 DEBUG(4,("checking form %s (want %s)\n", list[i].name, name));
7158 if (strequal(name, list[i].name)) {
7159 DEBUGADD(6,("Found form %s number [%d]\n", name, i));
7171 /****************************************************************
7173 ****************************************************************/
7175 WERROR _spoolss_GetForm(pipes_struct *p,
7176 struct spoolss_GetForm *r)
7179 nt_forms_struct form;
7181 /* that's an [in out] buffer */
7183 if (!r->in.buffer && (r->in.offered != 0)) {
7184 return WERR_INVALID_PARAM;
7187 DEBUG(4,("_spoolss_GetForm\n"));
7188 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7189 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7191 result = find_form_byname(r->in.form_name, &form);
7192 if (!W_ERROR_IS_OK(result)) {
7193 TALLOC_FREE(r->out.info);
7197 switch (r->in.level) {
7199 result = fill_form_info_1(p->mem_ctx,
7200 &r->out.info->info1,
7205 result = WERR_UNKNOWN_LEVEL;
7209 if (!W_ERROR_IS_OK(result)) {
7210 TALLOC_FREE(r->out.info);
7214 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo, NULL,
7215 r->out.info, r->in.level);
7216 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7218 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7221 /****************************************************************************
7222 ****************************************************************************/
7224 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
7225 struct spoolss_PortInfo1 *r,
7228 r->port_name = talloc_strdup(mem_ctx, name);
7229 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7234 /****************************************************************************
7235 TODO: This probably needs distinguish between TCP/IP and Local ports
7237 ****************************************************************************/
7239 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
7240 struct spoolss_PortInfo2 *r,
7243 r->port_name = talloc_strdup(mem_ctx, name);
7244 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7246 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
7247 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
7249 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
7250 W_ERROR_HAVE_NO_MEMORY(r->description);
7252 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
7259 /****************************************************************************
7260 wrapper around the enumer ports command
7261 ****************************************************************************/
7263 WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines )
7265 char *cmd = lp_enumports_cmd();
7266 char **qlines = NULL;
7267 char *command = NULL;
7275 /* if no hook then just fill in the default port */
7278 if (!(qlines = TALLOC_ARRAY( NULL, char*, 2 ))) {
7281 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7282 TALLOC_FREE(qlines);
7289 /* we have a valid enumport command */
7291 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7296 DEBUG(10,("Running [%s]\n", command));
7297 ret = smbrun(command, &fd);
7298 DEBUG(10,("Returned [%d]\n", ret));
7299 TALLOC_FREE(command);
7304 return WERR_ACCESS_DENIED;
7308 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7309 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7319 /****************************************************************************
7321 ****************************************************************************/
7323 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7324 union spoolss_PortInfo **info_p,
7327 union spoolss_PortInfo *info = NULL;
7329 WERROR result = WERR_OK;
7330 char **qlines = NULL;
7333 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7334 if (!W_ERROR_IS_OK(result)) {
7339 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7341 DEBUG(10,("Returning WERR_NOMEM\n"));
7342 result = WERR_NOMEM;
7346 for (i=0; i<numlines; i++) {
7347 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7348 result = fill_port_1(info, &info[i].info1, qlines[i]);
7349 if (!W_ERROR_IS_OK(result)) {
7354 TALLOC_FREE(qlines);
7357 if (!W_ERROR_IS_OK(result)) {
7359 TALLOC_FREE(qlines);
7371 /****************************************************************************
7373 ****************************************************************************/
7375 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7376 union spoolss_PortInfo **info_p,
7379 union spoolss_PortInfo *info = NULL;
7381 WERROR result = WERR_OK;
7382 char **qlines = NULL;
7385 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7386 if (!W_ERROR_IS_OK(result)) {
7391 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7393 DEBUG(10,("Returning WERR_NOMEM\n"));
7394 result = WERR_NOMEM;
7398 for (i=0; i<numlines; i++) {
7399 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7400 result = fill_port_2(info, &info[i].info2, qlines[i]);
7401 if (!W_ERROR_IS_OK(result)) {
7406 TALLOC_FREE(qlines);
7409 if (!W_ERROR_IS_OK(result)) {
7411 TALLOC_FREE(qlines);
7423 /****************************************************************
7425 ****************************************************************/
7427 WERROR _spoolss_EnumPorts(pipes_struct *p,
7428 struct spoolss_EnumPorts *r)
7432 /* that's an [in out] buffer */
7434 if (!r->in.buffer && (r->in.offered != 0)) {
7435 return WERR_INVALID_PARAM;
7438 DEBUG(4,("_spoolss_EnumPorts\n"));
7442 *r->out.info = NULL;
7444 switch (r->in.level) {
7446 result = enumports_level_1(p->mem_ctx, r->out.info,
7450 result = enumports_level_2(p->mem_ctx, r->out.info,
7454 return WERR_UNKNOWN_LEVEL;
7457 if (!W_ERROR_IS_OK(result)) {
7461 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7462 spoolss_EnumPorts, NULL,
7463 *r->out.info, r->in.level,
7465 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7466 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7468 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7471 /****************************************************************************
7472 ****************************************************************************/
7474 static WERROR spoolss_addprinterex_level_2(pipes_struct *p,
7476 struct spoolss_SetPrinterInfoCtr *info_ctr,
7477 struct spoolss_DeviceMode *devmode,
7478 struct security_descriptor *sec_desc,
7479 struct spoolss_UserLevelCtr *user_ctr,
7480 struct policy_handle *handle)
7482 NT_PRINTER_INFO_LEVEL *printer = NULL;
7485 WERROR err = WERR_OK;
7487 if ( !(printer = TALLOC_ZERO_P(NULL, NT_PRINTER_INFO_LEVEL)) ) {
7488 DEBUG(0,("spoolss_addprinterex_level_2: malloc fail.\n"));
7492 /* convert from UNICODE to ASCII - this allocates the info_2 struct inside *printer.*/
7493 if (!convert_printer_info(info_ctr, printer)) {
7494 free_a_printer(&printer, 2);
7498 /* check to see if the printer already exists */
7500 if ((snum = print_queue_snum(printer->info_2->sharename)) != -1) {
7501 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7502 printer->info_2->sharename));
7503 free_a_printer(&printer, 2);
7504 return WERR_PRINTER_ALREADY_EXISTS;
7507 /* FIXME!!! smbd should check to see if the driver is installed before
7508 trying to add a printer like this --jerry */
7510 if (*lp_addprinter_cmd() ) {
7511 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
7513 free_a_printer(&printer,2);
7514 return WERR_ACCESS_DENIED;
7517 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
7518 "smb.conf parameter \"addprinter command\" is defined. This"
7519 "parameter must exist for this call to succeed\n",
7520 printer->info_2->sharename ));
7523 /* use our primary netbios name since get_a_printer() will convert
7524 it to what the client expects on a case by case basis */
7526 slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname(),
7527 printer->info_2->sharename);
7530 if ((snum = print_queue_snum(printer->info_2->sharename)) == -1) {
7531 free_a_printer(&printer,2);
7532 return WERR_ACCESS_DENIED;
7535 /* you must be a printer admin to add a new printer */
7536 if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) {
7537 free_a_printer(&printer,2);
7538 return WERR_ACCESS_DENIED;
7542 * Do sanity check on the requested changes for Samba.
7545 if (!check_printer_ok(printer->info_2, snum)) {
7546 free_a_printer(&printer,2);
7547 return WERR_INVALID_PARAM;
7551 * When a printer is created, the drivername bound to the printer is used
7552 * to lookup previously saved driver initialization info, which is then
7553 * bound to the new printer, simulating what happens in the Windows arch.
7558 set_driver_init(printer, 2);
7562 /* A valid devmode was included, convert and link it
7564 DEBUGADD(10, ("spoolss_addprinterex_level_2: devmode included, converting\n"));
7566 if (!convert_devicemode(printer->info_2->printername, devmode,
7567 &printer->info_2->devmode)) {
7572 /* write the ASCII on disk */
7573 err = mod_a_printer(printer, 2);
7574 if (!W_ERROR_IS_OK(err)) {
7575 free_a_printer(&printer,2);
7579 if (!open_printer_hnd(p, handle, name, PRINTER_ACCESS_ADMINISTER)) {
7580 /* Handle open failed - remove addition. */
7581 del_a_printer(printer->info_2->sharename);
7582 free_a_printer(&printer,2);
7583 ZERO_STRUCTP(handle);
7584 return WERR_ACCESS_DENIED;
7587 update_c_setprinter(false);
7588 free_a_printer(&printer,2);
7593 /****************************************************************
7594 _spoolss_AddPrinterEx
7595 ****************************************************************/
7597 WERROR _spoolss_AddPrinterEx(pipes_struct *p,
7598 struct spoolss_AddPrinterEx *r)
7600 switch (r->in.info_ctr->level) {
7602 /* we don't handle yet */
7603 /* but I know what to do ... */
7604 return WERR_UNKNOWN_LEVEL;
7606 return spoolss_addprinterex_level_2(p, r->in.server,
7608 r->in.devmode_ctr->devmode,
7609 r->in.secdesc_ctr->sd,
7610 r->in.userlevel_ctr,
7613 return WERR_UNKNOWN_LEVEL;
7617 /****************************************************************
7618 _spoolss_AddPrinterDriver
7619 ****************************************************************/
7621 WERROR _spoolss_AddPrinterDriver(pipes_struct *p,
7622 struct spoolss_AddPrinterDriver *r)
7624 uint32_t level = r->in.info_ctr->level;
7625 struct spoolss_AddDriverInfoCtr *info = r->in.info_ctr;
7626 WERROR err = WERR_OK;
7627 NT_PRINTER_DRIVER_INFO_LEVEL driver;
7628 const char *driver_name = NULL;
7632 switch (p->hdr_req.opnum) {
7633 case NDR_SPOOLSS_ADDPRINTERDRIVER:
7634 fn = "_spoolss_AddPrinterDriver";
7636 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
7637 fn = "_spoolss_AddPrinterDriverEx";
7640 return WERR_INVALID_PARAM;
7645 if (level != 3 && level != 6) {
7646 /* Clever hack from Martin Zielinski <mz@seh.de>
7647 * to allow downgrade from level 8 (Vista).
7649 DEBUG(0,("%s: level %d not yet implemented\n", fn, level));
7650 return WERR_UNKNOWN_LEVEL;
7653 ZERO_STRUCT(driver);
7655 if (!convert_printer_driver_info(info, &driver, level)) {
7660 DEBUG(5,("Cleaning driver's information\n"));
7661 err = clean_up_driver_struct(p, driver, level);
7662 if (!W_ERROR_IS_OK(err))
7665 DEBUG(5,("Moving driver to final destination\n"));
7666 if( !W_ERROR_IS_OK(err = move_driver_to_download_area(p, driver, level,
7671 if (add_a_printer_driver(driver, level)!=0) {
7672 err = WERR_ACCESS_DENIED;
7678 driver_name = driver.info_3->name ? driver.info_3->name : "";
7681 driver_name = driver.info_6->name ? driver.info_6->name : "";
7686 * I think this is where he DrvUpgradePrinter() hook would be
7687 * be called in a driver's interface DLL on a Windows NT 4.0/2k
7688 * server. Right now, we just need to send ourselves a message
7689 * to update each printer bound to this driver. --jerry
7692 if (!srv_spoolss_drv_upgrade_printer(driver_name)) {
7693 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
7698 * Based on the version (e.g. driver destination dir: 0=9x,2=Nt/2k,3=2k/Xp),
7699 * decide if the driver init data should be deleted. The rules are:
7700 * 1) never delete init data if it is a 9x driver, they don't use it anyway
7701 * 2) delete init data only if there is no 2k/Xp driver
7702 * 3) always delete init data
7703 * The generalized rule is always use init data from the highest order driver.
7704 * It is necessary to follow the driver install by an initialization step to
7705 * finish off this process.
7708 version = driver.info_3->cversion;
7709 else if (level == 6)
7710 version = driver.info_6->version;
7715 * 9x printer driver - never delete init data
7718 DEBUG(10,("%s: init data not deleted for 9x driver [%s]\n",
7723 * Nt or 2k (compatiblity mode) printer driver - only delete init data if
7724 * there is no 2k/Xp driver init data for this driver name.
7728 NT_PRINTER_DRIVER_INFO_LEVEL driver1;
7730 if (!W_ERROR_IS_OK(get_a_printer_driver(&driver1, 3, driver_name, "Windows NT x86", 3))) {
7732 * No 2k/Xp driver found, delete init data (if any) for the new Nt driver.
7734 if (!del_driver_init(driver_name))
7735 DEBUG(6,("%s: del_driver_init(%s) Nt failed!\n",
7739 * a 2k/Xp driver was found, don't delete init data because Nt driver will use it.
7741 free_a_printer_driver(driver1,3);
7742 DEBUG(10,("%s: init data not deleted for Nt driver [%s]\n",
7749 * 2k or Xp printer driver - always delete init data
7752 if (!del_driver_init(driver_name))
7753 DEBUG(6,("%s: del_driver_init(%s) 2k/Xp failed!\n",
7758 DEBUG(0,("%s: invalid level=%d\n", fn, level));
7764 free_a_printer_driver(driver, level);
7768 /****************************************************************
7769 _spoolss_AddPrinterDriverEx
7770 ****************************************************************/
7772 WERROR _spoolss_AddPrinterDriverEx(pipes_struct *p,
7773 struct spoolss_AddPrinterDriverEx *r)
7775 struct spoolss_AddPrinterDriver a;
7778 * we only support the semantics of AddPrinterDriver()
7779 * i.e. only copy files that are newer than existing ones
7782 if (r->in.flags != APD_COPY_NEW_FILES) {
7783 return WERR_ACCESS_DENIED;
7786 a.in.servername = r->in.servername;
7787 a.in.info_ctr = r->in.info_ctr;
7789 return _spoolss_AddPrinterDriver(p, &a);
7792 /****************************************************************************
7793 ****************************************************************************/
7795 struct _spoolss_paths {
7801 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
7803 static const struct _spoolss_paths spoolss_paths[]= {
7804 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
7805 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
7808 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
7809 const char *servername,
7810 const char *environment,
7814 const char *pservername = NULL;
7815 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
7816 const char *short_archi;
7820 /* environment may be empty */
7821 if (environment && strlen(environment)) {
7822 long_archi = environment;
7825 /* servername may be empty */
7826 if (servername && strlen(servername)) {
7827 pservername = canon_servername(servername);
7829 if (!is_myname_or_ipaddr(pservername)) {
7830 return WERR_INVALID_PARAM;
7834 if (!(short_archi = get_short_archi(long_archi))) {
7835 return WERR_INVALID_ENVIRONMENT;
7838 switch (component) {
7839 case SPOOLSS_PRTPROCS_PATH:
7840 case SPOOLSS_DRIVER_PATH:
7842 *path = talloc_asprintf(mem_ctx,
7845 spoolss_paths[component].share,
7848 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
7849 SPOOLSS_DEFAULT_SERVER_PATH,
7850 spoolss_paths[component].dir,
7855 return WERR_INVALID_PARAM;
7865 /****************************************************************************
7866 ****************************************************************************/
7868 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
7869 const char *servername,
7870 const char *environment,
7871 struct spoolss_DriverDirectoryInfo1 *r)
7876 werr = compose_spoolss_server_path(mem_ctx,
7879 SPOOLSS_DRIVER_PATH,
7881 if (!W_ERROR_IS_OK(werr)) {
7885 DEBUG(4,("printer driver directory: [%s]\n", path));
7887 r->directory_name = path;
7892 /****************************************************************
7893 _spoolss_GetPrinterDriverDirectory
7894 ****************************************************************/
7896 WERROR _spoolss_GetPrinterDriverDirectory(pipes_struct *p,
7897 struct spoolss_GetPrinterDriverDirectory *r)
7901 /* that's an [in out] buffer */
7903 if (!r->in.buffer && (r->in.offered != 0)) {
7904 return WERR_INVALID_PARAM;
7907 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
7912 /* r->in.level is ignored */
7914 werror = getprinterdriverdir_level_1(p->mem_ctx,
7917 &r->out.info->info1);
7918 if (!W_ERROR_IS_OK(werror)) {
7919 TALLOC_FREE(r->out.info);
7923 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo, NULL,
7924 r->out.info, r->in.level);
7925 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7927 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7930 /****************************************************************
7931 _spoolss_EnumPrinterData
7932 ****************************************************************/
7934 WERROR _spoolss_EnumPrinterData(pipes_struct *p,
7935 struct spoolss_EnumPrinterData *r)
7937 NT_PRINTER_INFO_LEVEL *printer = NULL;
7938 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7941 struct regval_blob *val = NULL;
7942 NT_PRINTER_DATA *p_data;
7943 int i, key_index, num_values;
7946 *r->out.value_needed = 0;
7947 *r->out.type = REG_NONE;
7948 *r->out.data_needed = 0;
7950 DEBUG(5,("_spoolss_EnumPrinterData\n"));
7953 DEBUG(2,("_spoolss_EnumPrinterData: Invalid handle (%s:%u:%u).\n",
7954 OUR_HANDLE(r->in.handle)));
7958 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7962 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
7963 if (!W_ERROR_IS_OK(result)) {
7967 p_data = printer->info_2->data;
7968 key_index = lookup_printerkey( p_data, SPOOL_PRINTERDATA_KEY );
7973 * The NT machine wants to know the biggest size of value and data
7975 * cf: MSDN EnumPrinterData remark section
7978 if (!r->in.value_offered && !r->in.data_offered && (key_index != -1)) {
7980 uint32_t biggest_valuesize = 0;
7981 uint32_t biggest_datasize = 0;
7983 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
7985 num_values = regval_ctr_numvals( p_data->keys[key_index].values );
7987 for ( i=0; i<num_values; i++ )
7989 val = regval_ctr_specific_value( p_data->keys[key_index].values, i );
7991 name_length = strlen(val->valuename);
7992 if ( strlen(val->valuename) > biggest_valuesize )
7993 biggest_valuesize = name_length;
7995 if ( val->size > biggest_datasize )
7996 biggest_datasize = val->size;
7998 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
8002 /* the value is an UNICODE string but real_value_size is the length
8003 in bytes including the trailing 0 */
8005 *r->out.value_needed = 2 * (1 + biggest_valuesize);
8006 *r->out.data_needed = biggest_datasize;
8008 DEBUG(6,("final values: [%d], [%d]\n",
8009 *r->out.value_needed, *r->out.data_needed));
8015 * the value len is wrong in NT sp3
8016 * that's the number of bytes not the number of unicode chars
8019 if (key_index != -1) {
8020 val = regval_ctr_specific_value(p_data->keys[key_index].values,
8026 /* out_value should default to "" or else NT4 has
8027 problems unmarshalling the response */
8029 if (r->in.value_offered) {
8030 *r->out.value_needed = 1;
8031 r->out.value_name = talloc_strdup(r, "");
8032 if (!r->out.value_name) {
8033 result = WERR_NOMEM;
8037 r->out.value_name = NULL;
8038 *r->out.value_needed = 0;
8041 /* the data is counted in bytes */
8043 *r->out.data_needed = r->in.data_offered;
8045 result = WERR_NO_MORE_ITEMS;
8049 * - counted in bytes in the request
8050 * - counted in UNICODE chars in the max reply
8051 * - counted in bytes in the real size
8053 * take a pause *before* coding not *during* coding
8057 if (r->in.value_offered) {
8058 r->out.value_name = talloc_strdup(r, regval_name(val));
8059 if (!r->out.value_name) {
8060 result = WERR_NOMEM;
8063 *r->out.value_needed = strlen_m(regval_name(val));
8065 r->out.value_name = NULL;
8066 *r->out.value_needed = 0;
8071 *r->out.type = regval_type(val);
8073 /* data - counted in bytes */
8075 if (r->out.data && regval_size(val)) {
8076 memcpy(r->out.data, regval_data_p(val), regval_size(val));
8079 *r->out.data_needed = regval_size(val);
8083 free_a_printer(&printer, 2);
8087 /****************************************************************
8088 _spoolss_SetPrinterData
8089 ****************************************************************/
8091 WERROR _spoolss_SetPrinterData(pipes_struct *p,
8092 struct spoolss_SetPrinterData *r)
8094 NT_PRINTER_INFO_LEVEL *printer = NULL;
8096 WERROR result = WERR_OK;
8097 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8100 DEBUG(5,("_spoolss_SetPrinterData\n"));
8103 DEBUG(2,("_spoolss_SetPrinterData: Invalid handle (%s:%u:%u).\n",
8104 OUR_HANDLE(r->in.handle)));
8108 if (Printer->printer_type == SPLHND_SERVER) {
8109 DEBUG(10,("_spoolss_SetPrinterData: "
8110 "Not implemented for server handles yet\n"));
8111 return WERR_INVALID_PARAM;
8114 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8119 * Access check : NT returns "access denied" if you make a
8120 * SetPrinterData call without the necessary privildge.
8121 * we were originally returning OK if nothing changed
8122 * which made Win2k issue **a lot** of SetPrinterData
8123 * when connecting to a printer --jerry
8126 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8127 DEBUG(3,("_spoolss_SetPrinterData: "
8128 "change denied by handle access permissions\n"));
8129 result = WERR_ACCESS_DENIED;
8133 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8134 if (!W_ERROR_IS_OK(result)) {
8138 result = push_spoolss_PrinterData(p->mem_ctx, &blob,
8139 r->in.type, &r->in.data);
8140 if (!W_ERROR_IS_OK(result)) {
8145 * When client side code sets a magic printer data key, detect it and save
8146 * the current printer data and the magic key's data (its the DEVMODE) for
8147 * future printer/driver initializations.
8149 if ((r->in.type == REG_BINARY) && strequal(r->in.value_name, PHANTOM_DEVMODE_KEY)) {
8150 /* Set devmode and printer initialization info */
8151 result = save_driver_init(printer, 2, blob.data, blob.length);
8153 srv_spoolss_reset_printerdata(printer->info_2->drivername);
8158 result = set_printer_dataex(printer, SPOOL_PRINTERDATA_KEY,
8159 r->in.value_name, r->in.type,
8160 blob.data, blob.length);
8161 if (W_ERROR_IS_OK(result)) {
8162 result = mod_a_printer(printer, 2);
8166 free_a_printer(&printer, 2);
8171 /****************************************************************
8172 _spoolss_ResetPrinter
8173 ****************************************************************/
8175 WERROR _spoolss_ResetPrinter(pipes_struct *p,
8176 struct spoolss_ResetPrinter *r)
8178 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8181 DEBUG(5,("_spoolss_ResetPrinter\n"));
8184 * All we do is to check to see if the handle and queue is valid.
8185 * This call really doesn't mean anything to us because we only
8186 * support RAW printing. --jerry
8190 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8191 OUR_HANDLE(r->in.handle)));
8195 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8199 /* blindly return success */
8203 /****************************************************************
8204 _spoolss_DeletePrinterData
8205 ****************************************************************/
8207 WERROR _spoolss_DeletePrinterData(pipes_struct *p,
8208 struct spoolss_DeletePrinterData *r)
8210 NT_PRINTER_INFO_LEVEL *printer = NULL;
8212 WERROR status = WERR_OK;
8213 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8215 DEBUG(5,("_spoolss_DeletePrinterData\n"));
8218 DEBUG(2,("_spoolss_DeletePrinterData: Invalid handle (%s:%u:%u).\n",
8219 OUR_HANDLE(r->in.handle)));
8223 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8226 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8227 DEBUG(3, ("_spoolss_DeletePrinterData: "
8228 "printer properties change denied by handle\n"));
8229 return WERR_ACCESS_DENIED;
8232 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8233 if (!W_ERROR_IS_OK(status))
8236 if (!r->in.value_name) {
8237 free_a_printer(&printer, 2);
8241 status = delete_printer_dataex( printer, SPOOL_PRINTERDATA_KEY,
8244 if ( W_ERROR_IS_OK(status) )
8245 mod_a_printer( printer, 2 );
8247 free_a_printer(&printer, 2);
8252 /****************************************************************
8254 ****************************************************************/
8256 WERROR _spoolss_AddForm(pipes_struct *p,
8257 struct spoolss_AddForm *r)
8259 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8260 nt_forms_struct tmpForm;
8262 WERROR status = WERR_OK;
8263 NT_PRINTER_INFO_LEVEL *printer = NULL;
8264 SE_PRIV se_printop = SE_PRINT_OPERATOR;
8267 nt_forms_struct *list=NULL;
8268 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8270 DEBUG(5,("_spoolss_AddForm\n"));
8273 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8274 OUR_HANDLE(r->in.handle)));
8279 /* forms can be added on printer of on the print server handle */
8281 if ( Printer->printer_type == SPLHND_PRINTER )
8283 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8286 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8287 if (!W_ERROR_IS_OK(status))
8291 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8292 and not a printer admin, then fail */
8294 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8295 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8296 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8298 p->server_info->ptok,
8299 lp_printer_admin(snum))) {
8300 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
8301 return WERR_ACCESS_DENIED;
8304 /* can't add if builtin */
8306 if (get_a_builtin_ntform_by_string(form->form_name, &tmpForm)) {
8307 status = WERR_FILE_EXISTS;
8311 count = get_ntforms(&list);
8313 if(!add_a_form(&list, form, &count)) {
8314 status = WERR_NOMEM;
8319 write_ntforms(&list, count);
8323 * ChangeID must always be set if this is a printer
8326 if ( Printer->printer_type == SPLHND_PRINTER )
8327 status = mod_a_printer(printer, 2);
8331 free_a_printer(&printer, 2);
8337 /****************************************************************
8339 ****************************************************************/
8341 WERROR _spoolss_DeleteForm(pipes_struct *p,
8342 struct spoolss_DeleteForm *r)
8344 const char *form_name = r->in.form_name;
8345 nt_forms_struct tmpForm;
8347 nt_forms_struct *list=NULL;
8348 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8350 WERROR status = WERR_OK;
8351 NT_PRINTER_INFO_LEVEL *printer = NULL;
8352 SE_PRIV se_printop = SE_PRINT_OPERATOR;
8355 DEBUG(5,("_spoolss_DeleteForm\n"));
8358 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8359 OUR_HANDLE(r->in.handle)));
8363 /* forms can be deleted on printer of on the print server handle */
8365 if ( Printer->printer_type == SPLHND_PRINTER )
8367 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8370 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8371 if (!W_ERROR_IS_OK(status))
8375 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8376 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8377 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8379 p->server_info->ptok,
8380 lp_printer_admin(snum))) {
8381 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8382 return WERR_ACCESS_DENIED;
8386 /* can't delete if builtin */
8388 if (get_a_builtin_ntform_by_string(form_name,&tmpForm)) {
8389 status = WERR_INVALID_PARAM;
8393 count = get_ntforms(&list);
8396 ret = delete_a_form(&list, form_name, &count, &status);
8403 * ChangeID must always be set if this is a printer
8406 if ( Printer->printer_type == SPLHND_PRINTER )
8407 status = mod_a_printer(printer, 2);
8411 free_a_printer(&printer, 2);
8417 /****************************************************************
8419 ****************************************************************/
8421 WERROR _spoolss_SetForm(pipes_struct *p,
8422 struct spoolss_SetForm *r)
8424 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8425 nt_forms_struct tmpForm;
8427 WERROR status = WERR_OK;
8428 NT_PRINTER_INFO_LEVEL *printer = NULL;
8429 SE_PRIV se_printop = SE_PRINT_OPERATOR;
8432 nt_forms_struct *list=NULL;
8433 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8435 DEBUG(5,("_spoolss_SetForm\n"));
8438 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8439 OUR_HANDLE(r->in.handle)));
8443 /* forms can be modified on printer of on the print server handle */
8445 if ( Printer->printer_type == SPLHND_PRINTER )
8447 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8450 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8451 if (!W_ERROR_IS_OK(status))
8455 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8456 and not a printer admin, then fail */
8458 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8459 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8460 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8462 p->server_info->ptok,
8463 lp_printer_admin(snum))) {
8464 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8465 return WERR_ACCESS_DENIED;
8468 /* can't set if builtin */
8469 if (get_a_builtin_ntform_by_string(form->form_name, &tmpForm)) {
8470 status = WERR_INVALID_PARAM;
8474 count = get_ntforms(&list);
8475 update_a_form(&list, form, count);
8477 write_ntforms(&list, count);
8481 * ChangeID must always be set if this is a printer
8484 if ( Printer->printer_type == SPLHND_PRINTER )
8485 status = mod_a_printer(printer, 2);
8490 free_a_printer(&printer, 2);
8496 /****************************************************************************
8497 fill_print_processor1
8498 ****************************************************************************/
8500 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8501 struct spoolss_PrintProcessorInfo1 *r,
8502 const char *print_processor_name)
8504 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8505 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8510 /****************************************************************************
8511 enumprintprocessors level 1.
8512 ****************************************************************************/
8514 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8515 union spoolss_PrintProcessorInfo **info_p,
8518 union spoolss_PrintProcessorInfo *info;
8521 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8522 W_ERROR_HAVE_NO_MEMORY(info);
8526 result = fill_print_processor1(info, &info[0].info1, "winprint");
8527 if (!W_ERROR_IS_OK(result)) {
8532 if (!W_ERROR_IS_OK(result)) {
8543 /****************************************************************
8544 _spoolss_EnumPrintProcessors
8545 ****************************************************************/
8547 WERROR _spoolss_EnumPrintProcessors(pipes_struct *p,
8548 struct spoolss_EnumPrintProcessors *r)
8552 /* that's an [in out] buffer */
8554 if (!r->in.buffer && (r->in.offered != 0)) {
8555 return WERR_INVALID_PARAM;
8558 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8561 * Enumerate the print processors ...
8563 * Just reply with "winprint", to keep NT happy
8564 * and I can use my nice printer checker.
8569 *r->out.info = NULL;
8571 switch (r->in.level) {
8573 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8577 return WERR_UNKNOWN_LEVEL;
8580 if (!W_ERROR_IS_OK(result)) {
8584 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8585 spoolss_EnumPrintProcessors, NULL,
8586 *r->out.info, r->in.level,
8588 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8589 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8591 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8594 /****************************************************************************
8595 fill_printprocdatatype1
8596 ****************************************************************************/
8598 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8599 struct spoolss_PrintProcDataTypesInfo1 *r,
8600 const char *name_array)
8602 r->name_array = talloc_strdup(mem_ctx, name_array);
8603 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8608 /****************************************************************************
8609 enumprintprocdatatypes level 1.
8610 ****************************************************************************/
8612 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8613 union spoolss_PrintProcDataTypesInfo **info_p,
8617 union spoolss_PrintProcDataTypesInfo *info;
8619 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8620 W_ERROR_HAVE_NO_MEMORY(info);
8624 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
8625 if (!W_ERROR_IS_OK(result)) {
8630 if (!W_ERROR_IS_OK(result)) {
8641 /****************************************************************
8642 _spoolss_EnumPrintProcDataTypes
8643 ****************************************************************/
8645 WERROR _spoolss_EnumPrintProcDataTypes(pipes_struct *p,
8646 struct spoolss_EnumPrintProcDataTypes *r)
8650 /* that's an [in out] buffer */
8652 if (!r->in.buffer && (r->in.offered != 0)) {
8653 return WERR_INVALID_PARAM;
8656 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8660 *r->out.info = NULL;
8662 switch (r->in.level) {
8664 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
8668 return WERR_UNKNOWN_LEVEL;
8671 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8672 spoolss_EnumPrintProcDataTypes, NULL,
8673 *r->out.info, r->in.level,
8675 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8676 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8678 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8681 /****************************************************************************
8683 ****************************************************************************/
8685 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
8686 struct spoolss_MonitorInfo1 *r,
8687 const char *monitor_name)
8689 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8690 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8695 /****************************************************************************
8697 ****************************************************************************/
8699 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
8700 struct spoolss_MonitorInfo2 *r,
8701 const char *monitor_name,
8702 const char *environment,
8703 const char *dll_name)
8705 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8706 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8707 r->environment = talloc_strdup(mem_ctx, environment);
8708 W_ERROR_HAVE_NO_MEMORY(r->environment);
8709 r->dll_name = talloc_strdup(mem_ctx, dll_name);
8710 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
8715 /****************************************************************************
8716 enumprintmonitors level 1.
8717 ****************************************************************************/
8719 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
8720 union spoolss_MonitorInfo **info_p,
8723 union spoolss_MonitorInfo *info;
8724 WERROR result = WERR_OK;
8726 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8727 W_ERROR_HAVE_NO_MEMORY(info);
8731 result = fill_monitor_1(info, &info[0].info1,
8733 if (!W_ERROR_IS_OK(result)) {
8737 result = fill_monitor_1(info, &info[1].info1,
8739 if (!W_ERROR_IS_OK(result)) {
8744 if (!W_ERROR_IS_OK(result)) {
8755 /****************************************************************************
8756 enumprintmonitors level 2.
8757 ****************************************************************************/
8759 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
8760 union spoolss_MonitorInfo **info_p,
8763 union spoolss_MonitorInfo *info;
8764 WERROR result = WERR_OK;
8766 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8767 W_ERROR_HAVE_NO_MEMORY(info);
8771 result = fill_monitor_2(info, &info[0].info2,
8773 "Windows NT X86", /* FIXME */
8775 if (!W_ERROR_IS_OK(result)) {
8779 result = fill_monitor_2(info, &info[1].info2,
8781 "Windows NT X86", /* FIXME */
8783 if (!W_ERROR_IS_OK(result)) {
8788 if (!W_ERROR_IS_OK(result)) {
8799 /****************************************************************
8800 _spoolss_EnumMonitors
8801 ****************************************************************/
8803 WERROR _spoolss_EnumMonitors(pipes_struct *p,
8804 struct spoolss_EnumMonitors *r)
8808 /* that's an [in out] buffer */
8810 if (!r->in.buffer && (r->in.offered != 0)) {
8811 return WERR_INVALID_PARAM;
8814 DEBUG(5,("_spoolss_EnumMonitors\n"));
8817 * Enumerate the print monitors ...
8819 * Just reply with "Local Port", to keep NT happy
8820 * and I can use my nice printer checker.
8825 *r->out.info = NULL;
8827 switch (r->in.level) {
8829 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
8833 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
8837 return WERR_UNKNOWN_LEVEL;
8840 if (!W_ERROR_IS_OK(result)) {
8844 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8845 spoolss_EnumMonitors, NULL,
8846 *r->out.info, r->in.level,
8848 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8849 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8851 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8854 /****************************************************************************
8855 ****************************************************************************/
8857 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
8858 const print_queue_struct *queue,
8859 int count, int snum,
8860 const NT_PRINTER_INFO_LEVEL *ntprinter,
8862 struct spoolss_JobInfo1 *r)
8867 for (i=0; i<count && found == false; i++) {
8868 if (queue[i].job == (int)jobid) {
8873 if (found == false) {
8874 /* NT treats not found as bad param... yet another bad choice */
8875 return WERR_INVALID_PARAM;
8878 return fill_job_info1(mem_ctx,
8886 /****************************************************************************
8887 ****************************************************************************/
8889 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
8890 const print_queue_struct *queue,
8891 int count, int snum,
8892 const NT_PRINTER_INFO_LEVEL *ntprinter,
8894 struct spoolss_JobInfo2 *r)
8898 struct spoolss_DeviceMode *devmode;
8899 NT_DEVICEMODE *nt_devmode;
8902 for (i=0; i<count && found == false; i++) {
8903 if (queue[i].job == (int)jobid) {
8908 if (found == false) {
8909 /* NT treats not found as bad param... yet another bad
8911 return WERR_INVALID_PARAM;
8915 * if the print job does not have a DEVMODE associated with it,
8916 * just use the one for the printer. A NULL devicemode is not
8917 * a failure condition
8920 nt_devmode = print_job_devmode(lp_const_servicename(snum), jobid);
8922 devmode = TALLOC_ZERO_P(mem_ctx, struct spoolss_DeviceMode);
8923 W_ERROR_HAVE_NO_MEMORY(devmode);
8924 result = convert_nt_devicemode(devmode, devmode, nt_devmode);
8925 if (!W_ERROR_IS_OK(result)) {
8929 devmode = construct_dev_mode(mem_ctx, lp_const_servicename(snum));
8930 W_ERROR_HAVE_NO_MEMORY(devmode);
8933 return fill_job_info2(mem_ctx,
8942 /****************************************************************
8944 ****************************************************************/
8946 WERROR _spoolss_GetJob(pipes_struct *p,
8947 struct spoolss_GetJob *r)
8949 WERROR result = WERR_OK;
8950 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
8953 print_queue_struct *queue = NULL;
8954 print_status_struct prt_status;
8956 /* that's an [in out] buffer */
8958 if (!r->in.buffer && (r->in.offered != 0)) {
8959 return WERR_INVALID_PARAM;
8962 DEBUG(5,("_spoolss_GetJob\n"));
8966 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8970 result = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum));
8971 if (!W_ERROR_IS_OK(result)) {
8975 count = print_queue_status(snum, &queue, &prt_status);
8977 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
8978 count, prt_status.status, prt_status.message));
8980 switch (r->in.level) {
8982 result = getjob_level_1(p->mem_ctx,
8983 queue, count, snum, ntprinter,
8984 r->in.job_id, &r->out.info->info1);
8987 result = getjob_level_2(p->mem_ctx,
8988 queue, count, snum, ntprinter,
8989 r->in.job_id, &r->out.info->info2);
8992 result = WERR_UNKNOWN_LEVEL;
8997 free_a_printer(&ntprinter, 2);
8999 if (!W_ERROR_IS_OK(result)) {
9000 TALLOC_FREE(r->out.info);
9004 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, NULL,
9005 r->out.info, r->in.level);
9006 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9008 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9011 /****************************************************************
9012 _spoolss_GetPrinterDataEx
9014 From MSDN documentation of GetPrinterDataEx: pass request
9015 to GetPrinterData if key is "PrinterDriverData".
9016 ****************************************************************/
9018 WERROR _spoolss_GetPrinterDataEx(pipes_struct *p,
9019 struct spoolss_GetPrinterDataEx *r)
9022 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9023 struct regval_blob *val = NULL;
9024 NT_PRINTER_INFO_LEVEL *printer = NULL;
9026 WERROR result = WERR_OK;
9028 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
9030 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
9031 r->in.key_name, r->in.value_name));
9033 /* in case of problem, return some default values */
9036 *r->out.type = REG_NONE;
9039 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9040 OUR_HANDLE(r->in.handle)));
9041 result = WERR_BADFID;
9045 /* Is the handle to a printer or to the server? */
9047 if (Printer->printer_type == SPLHND_SERVER) {
9048 DEBUG(10,("_spoolss_GetPrinterDataEx: "
9049 "Not implemented for server handles yet\n"));
9050 result = WERR_INVALID_PARAM;
9054 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9058 result = get_a_printer(Printer, &printer, 2, lp_servicename(snum));
9059 if (!W_ERROR_IS_OK(result)) {
9063 /* check to see if the keyname is valid */
9064 if (!strlen(r->in.key_name)) {
9065 result = WERR_INVALID_PARAM;
9069 if (lookup_printerkey(printer->info_2->data, r->in.key_name) == -1) {
9070 DEBUG(4,("_spoolss_GetPrinterDataEx: "
9071 "Invalid keyname [%s]\n", r->in.key_name ));
9072 result = WERR_BADFILE;
9076 /* When given a new keyname, we should just create it */
9078 val = get_printer_data(printer->info_2,
9079 r->in.key_name, r->in.value_name);
9081 result = WERR_BADFILE;
9085 *r->out.needed = regval_size(val);
9087 if (*r->out.needed > r->in.offered) {
9088 result = WERR_MORE_DATA;
9092 *r->out.type = regval_type(val);
9094 memcpy(r->out.buffer, regval_data_p(val), regval_size(val));
9098 free_a_printer(&printer, 2);
9104 /****************************************************************
9105 _spoolss_SetPrinterDataEx
9106 ****************************************************************/
9108 WERROR _spoolss_SetPrinterDataEx(pipes_struct *p,
9109 struct spoolss_SetPrinterDataEx *r)
9111 NT_PRINTER_INFO_LEVEL *printer = NULL;
9113 WERROR result = WERR_OK;
9114 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9117 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
9119 /* From MSDN documentation of SetPrinterDataEx: pass request to
9120 SetPrinterData if key is "PrinterDriverData" */
9123 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9124 OUR_HANDLE(r->in.handle)));
9128 if (Printer->printer_type == SPLHND_SERVER) {
9129 DEBUG(10,("_spoolss_SetPrinterDataEx: "
9130 "Not implemented for server handles yet\n"));
9131 return WERR_INVALID_PARAM;
9134 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9139 * Access check : NT returns "access denied" if you make a
9140 * SetPrinterData call without the necessary privildge.
9141 * we were originally returning OK if nothing changed
9142 * which made Win2k issue **a lot** of SetPrinterData
9143 * when connecting to a printer --jerry
9146 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9147 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
9148 "change denied by handle access permissions\n"));
9149 return WERR_ACCESS_DENIED;
9152 result = get_a_printer(Printer, &printer, 2, lp_servicename(snum));
9153 if (!W_ERROR_IS_OK(result)) {
9157 /* check for OID in valuename */
9159 oid_string = strchr(r->in.value_name, ',');
9165 /* save the registry data */
9167 result = set_printer_dataex(printer, r->in.key_name, r->in.value_name,
9168 r->in.type, r->in.buffer, r->in.offered);
9170 if (W_ERROR_IS_OK(result)) {
9171 /* save the OID if one was specified */
9173 char *str = talloc_asprintf(p->mem_ctx, "%s\\%s",
9174 r->in.key_name, SPOOL_OID_KEY);
9176 result = WERR_NOMEM;
9181 * I'm not checking the status here on purpose. Don't know
9182 * if this is right, but I'm returning the status from the
9183 * previous set_printer_dataex() call. I have no idea if
9184 * this is right. --jerry
9187 set_printer_dataex(printer, str, r->in.value_name,
9188 REG_SZ, (uint8_t *)oid_string,
9189 strlen(oid_string)+1);
9192 result = mod_a_printer(printer, 2);
9196 free_a_printer(&printer, 2);
9201 /****************************************************************
9202 _spoolss_DeletePrinterDataEx
9203 ****************************************************************/
9205 WERROR _spoolss_DeletePrinterDataEx(pipes_struct *p,
9206 struct spoolss_DeletePrinterDataEx *r)
9208 NT_PRINTER_INFO_LEVEL *printer = NULL;
9210 WERROR status = WERR_OK;
9211 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9213 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9216 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9217 "Invalid handle (%s:%u:%u).\n",
9218 OUR_HANDLE(r->in.handle)));
9222 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
9225 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9226 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9227 "printer properties change denied by handle\n"));
9228 return WERR_ACCESS_DENIED;
9231 if (!r->in.value_name || !r->in.key_name) {
9235 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9236 if (!W_ERROR_IS_OK(status))
9239 status = delete_printer_dataex( printer, r->in.key_name, r->in.value_name );
9241 if ( W_ERROR_IS_OK(status) )
9242 mod_a_printer( printer, 2 );
9244 free_a_printer(&printer, 2);
9249 /****************************************************************
9250 _spoolss_EnumPrinterKey
9251 ****************************************************************/
9253 WERROR _spoolss_EnumPrinterKey(pipes_struct *p,
9254 struct spoolss_EnumPrinterKey *r)
9256 fstring *keynames = NULL;
9258 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9259 NT_PRINTER_DATA *data;
9260 NT_PRINTER_INFO_LEVEL *printer = NULL;
9262 WERROR result = WERR_BADFILE;
9264 const char **array = NULL;
9267 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
9270 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
9271 OUR_HANDLE(r->in.handle)));
9275 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9279 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9280 if (!W_ERROR_IS_OK(result)) {
9284 /* get the list of subkey names */
9286 data = printer->info_2->data;
9288 num_keys = get_printer_subkeys(data, r->in.key_name, &keynames);
9289 if (num_keys == -1) {
9290 result = WERR_BADFILE;
9296 array = talloc_zero_array(r->out.key_buffer, const char *, num_keys + 1);
9298 result = WERR_NOMEM;
9302 for (i=0; i < num_keys; i++) {
9303 array[i] = talloc_strdup(array, keynames[i]);
9305 result = WERR_NOMEM;
9309 *r->out.needed += strlen_m_term(keynames[i]) * 2;
9312 if (r->in.offered < *r->out.needed) {
9313 result = WERR_MORE_DATA;
9319 *r->out.key_buffer = array;
9322 if (!W_ERROR_IS_OK(result)) {
9324 ZERO_STRUCTP(r->out.key_buffer);
9327 free_a_printer(&printer, 2);
9328 SAFE_FREE(keynames);
9333 /****************************************************************
9334 _spoolss_DeletePrinterKey
9335 ****************************************************************/
9337 WERROR _spoolss_DeletePrinterKey(pipes_struct *p,
9338 struct spoolss_DeletePrinterKey *r)
9340 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9341 NT_PRINTER_INFO_LEVEL *printer = NULL;
9345 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9348 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9349 OUR_HANDLE(r->in.handle)));
9353 /* if keyname == NULL, return error */
9355 if ( !r->in.key_name )
9356 return WERR_INVALID_PARAM;
9358 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
9361 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9362 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9363 "printer properties change denied by handle\n"));
9364 return WERR_ACCESS_DENIED;
9367 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9368 if (!W_ERROR_IS_OK(status))
9371 /* delete the key and all subneys */
9373 status = delete_all_printer_data( printer->info_2, r->in.key_name );
9375 if ( W_ERROR_IS_OK(status) )
9376 status = mod_a_printer(printer, 2);
9378 free_a_printer( &printer, 2 );
9383 /****************************************************************
9384 ****************************************************************/
9386 static WERROR registry_value_to_printer_enum_value(TALLOC_CTX *mem_ctx,
9387 struct regval_blob *v,
9388 struct spoolss_PrinterEnumValues *r)
9392 r->data = TALLOC_ZERO_P(mem_ctx, union spoolss_PrinterData);
9393 W_ERROR_HAVE_NO_MEMORY(r->data);
9395 r->value_name = talloc_strdup(mem_ctx, regval_name(v));
9396 W_ERROR_HAVE_NO_MEMORY(r->value_name);
9398 r->type = regval_type(v);
9399 r->data_length = regval_size(v);
9401 if (r->data_length) {
9402 DATA_BLOB blob = data_blob_const(regval_data_p(v),
9404 result = pull_spoolss_PrinterData(mem_ctx, &blob,
9407 if (!W_ERROR_IS_OK(result)) {
9415 /****************************************************************
9416 _spoolss_EnumPrinterDataEx
9417 ****************************************************************/
9419 WERROR _spoolss_EnumPrinterDataEx(pipes_struct *p,
9420 struct spoolss_EnumPrinterDataEx *r)
9423 NT_PRINTER_INFO_LEVEL *printer = NULL;
9424 struct spoolss_PrinterEnumValues *info = NULL;
9425 NT_PRINTER_DATA *p_data;
9426 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9432 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9436 *r->out.info = NULL;
9439 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9440 OUR_HANDLE(r->in.handle)));
9445 * first check for a keyname of NULL or "". Win2k seems to send
9446 * this a lot and we should send back WERR_INVALID_PARAM
9447 * no need to spend time looking up the printer in this case.
9451 if (!strlen(r->in.key_name)) {
9452 result = WERR_INVALID_PARAM;
9456 /* get the printer off of disk */
9458 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9462 ZERO_STRUCT(printer);
9463 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9464 if (!W_ERROR_IS_OK(result)) {
9468 /* now look for a match on the key name */
9470 p_data = printer->info_2->data;
9472 key_index = lookup_printerkey(p_data, r->in.key_name);
9473 if (key_index == -1) {
9474 DEBUG(10,("_spoolss_EnumPrinterDataEx: Unknown keyname [%s]\n",
9476 result = WERR_INVALID_PARAM;
9480 /* allocate the memory for the array of pointers -- if necessary */
9482 count = regval_ctr_numvals(p_data->keys[key_index].values);
9484 result = WERR_OK; /* ??? */
9488 info = TALLOC_ZERO_ARRAY(p->mem_ctx,
9489 struct spoolss_PrinterEnumValues,
9492 DEBUG(0,("_spoolss_EnumPrinterDataEx: talloc() failed\n"));
9493 result = WERR_NOMEM;
9498 * loop through all params and build the array to pass
9499 * back to the client
9502 for (i=0; i < count; i++) {
9504 struct regval_blob *val;
9506 /* lookup the registry value */
9508 val = regval_ctr_specific_value(p_data->keys[key_index].values, i);
9510 DEBUG(10,("retrieved value number [%d] [%s]\n", i, regval_name(val)));
9514 result = registry_value_to_printer_enum_value(info, val, &info[i]);
9515 if (!W_ERROR_IS_OK(result)) {
9520 #if 0 /* FIXME - gd */
9521 /* housekeeping information in the reply */
9523 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9524 * the hand marshalled container size is a multiple
9525 * of 4 bytes for RPC alignment.
9529 needed += 4-(needed % 4);
9532 *r->out.count = count;
9533 *r->out.info = info;
9538 free_a_printer(&printer, 2);
9541 if (!W_ERROR_IS_OK(result)) {
9545 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
9546 spoolss_EnumPrinterDataEx, NULL,
9549 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9550 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
9552 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9555 /****************************************************************************
9556 ****************************************************************************/
9558 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
9559 const char *servername,
9560 const char *environment,
9561 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9566 werr = compose_spoolss_server_path(mem_ctx,
9569 SPOOLSS_PRTPROCS_PATH,
9571 if (!W_ERROR_IS_OK(werr)) {
9575 DEBUG(4,("print processor directory: [%s]\n", path));
9577 r->directory_name = path;
9582 /****************************************************************
9583 _spoolss_GetPrintProcessorDirectory
9584 ****************************************************************/
9586 WERROR _spoolss_GetPrintProcessorDirectory(pipes_struct *p,
9587 struct spoolss_GetPrintProcessorDirectory *r)
9591 /* that's an [in out] buffer */
9593 if (!r->in.buffer && (r->in.offered != 0)) {
9594 return WERR_INVALID_PARAM;
9597 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9602 /* r->in.level is ignored */
9604 result = getprintprocessordirectory_level_1(p->mem_ctx,
9607 &r->out.info->info1);
9608 if (!W_ERROR_IS_OK(result)) {
9609 TALLOC_FREE(r->out.info);
9613 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo, NULL,
9614 r->out.info, r->in.level);
9615 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9617 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9620 /*******************************************************************
9621 ********************************************************************/
9623 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
9624 const char *dllname)
9626 enum ndr_err_code ndr_err;
9627 struct spoolss_MonitorUi ui;
9629 ui.dll_name = dllname;
9631 ndr_err = ndr_push_struct_blob(buf, mem_ctx, NULL, &ui,
9632 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
9633 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9634 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
9636 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9639 /*******************************************************************
9640 Streams the monitor UI DLL name in UNICODE
9641 *******************************************************************/
9643 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
9644 NT_USER_TOKEN *token, DATA_BLOB *in,
9645 DATA_BLOB *out, uint32_t *needed)
9647 const char *dllname = "tcpmonui.dll";
9649 *needed = (strlen(dllname)+1) * 2;
9651 if (out->length < *needed) {
9652 return WERR_INSUFFICIENT_BUFFER;
9655 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9662 /*******************************************************************
9663 ********************************************************************/
9665 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
9666 struct spoolss_PortData1 *port1,
9667 const DATA_BLOB *buf)
9669 enum ndr_err_code ndr_err;
9670 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, NULL, port1,
9671 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
9672 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9673 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
9675 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9678 /*******************************************************************
9679 ********************************************************************/
9681 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
9682 struct spoolss_PortData2 *port2,
9683 const DATA_BLOB *buf)
9685 enum ndr_err_code ndr_err;
9686 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, NULL, port2,
9687 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
9688 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9689 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
9691 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9694 /*******************************************************************
9695 Create a new TCP/IP port
9696 *******************************************************************/
9698 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
9699 NT_USER_TOKEN *token, DATA_BLOB *in,
9700 DATA_BLOB *out, uint32_t *needed)
9702 struct spoolss_PortData1 port1;
9703 struct spoolss_PortData2 port2;
9704 char *device_uri = NULL;
9707 const char *portname;
9708 const char *hostaddress;
9710 uint32_t port_number;
9713 /* peek for spoolss_PortData version */
9715 if (!in || (in->length < (128 + 4))) {
9716 return WERR_GENERAL_FAILURE;
9719 version = IVAL(in->data, 128);
9725 if (!pull_port_data_1(mem_ctx, &port1, in)) {
9729 portname = port1.portname;
9730 hostaddress = port1.hostaddress;
9731 queue = port1.queue;
9732 protocol = port1.protocol;
9733 port_number = port1.port_number;
9739 if (!pull_port_data_2(mem_ctx, &port2, in)) {
9743 portname = port2.portname;
9744 hostaddress = port2.hostaddress;
9745 queue = port2.queue;
9746 protocol = port2.protocol;
9747 port_number = port2.port_number;
9751 DEBUG(1,("xcvtcp_addport: "
9752 "unknown version of port_data: %d\n", version));
9753 return WERR_UNKNOWN_PORT;
9756 /* create the device URI and call the add_port_hook() */
9759 case PROTOCOL_RAWTCP_TYPE:
9760 device_uri = talloc_asprintf(mem_ctx,
9761 "socket://%s:%d/", hostaddress,
9765 case PROTOCOL_LPR_TYPE:
9766 device_uri = talloc_asprintf(mem_ctx,
9767 "lpr://%s/%s", hostaddress, queue );
9771 return WERR_UNKNOWN_PORT;
9778 return add_port_hook(mem_ctx, token, portname, device_uri);
9781 /*******************************************************************
9782 *******************************************************************/
9784 struct xcv_api_table xcvtcp_cmds[] = {
9785 { "MonitorUI", xcvtcp_monitorui },
9786 { "AddPort", xcvtcp_addport},
9790 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
9791 NT_USER_TOKEN *token, const char *command,
9798 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
9800 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
9801 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
9802 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9805 return WERR_BADFUNC;
9808 /*******************************************************************
9809 *******************************************************************/
9810 #if 0 /* don't support management using the "Local Port" monitor */
9812 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
9813 NT_USER_TOKEN *token, DATA_BLOB *in,
9814 DATA_BLOB *out, uint32_t *needed)
9816 const char *dllname = "localui.dll";
9818 *needed = (strlen(dllname)+1) * 2;
9820 if (out->length < *needed) {
9821 return WERR_INSUFFICIENT_BUFFER;
9824 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9831 /*******************************************************************
9832 *******************************************************************/
9834 struct xcv_api_table xcvlocal_cmds[] = {
9835 { "MonitorUI", xcvlocal_monitorui },
9839 struct xcv_api_table xcvlocal_cmds[] = {
9846 /*******************************************************************
9847 *******************************************************************/
9849 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
9850 NT_USER_TOKEN *token, const char *command,
9851 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
9856 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
9858 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
9859 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
9860 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9862 return WERR_BADFUNC;
9865 /****************************************************************
9867 ****************************************************************/
9869 WERROR _spoolss_XcvData(pipes_struct *p,
9870 struct spoolss_XcvData *r)
9872 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9873 DATA_BLOB out_data = data_blob_null;
9877 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
9878 OUR_HANDLE(r->in.handle)));
9882 /* Has to be a handle to the TCP/IP port monitor */
9884 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
9885 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
9889 /* requires administrative access to the server */
9891 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
9892 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
9893 return WERR_ACCESS_DENIED;
9896 /* Allocate the outgoing buffer */
9898 if (r->in.out_data_size) {
9899 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
9900 if (out_data.data == NULL) {
9905 switch ( Printer->printer_type ) {
9906 case SPLHND_PORTMON_TCP:
9907 werror = process_xcvtcp_command(p->mem_ctx,
9908 p->server_info->ptok,
9909 r->in.function_name,
9910 &r->in.in_data, &out_data,
9913 case SPLHND_PORTMON_LOCAL:
9914 werror = process_xcvlocal_command(p->mem_ctx,
9915 p->server_info->ptok,
9916 r->in.function_name,
9917 &r->in.in_data, &out_data,
9921 werror = WERR_INVALID_PRINT_MONITOR;
9924 if (!W_ERROR_IS_OK(werror)) {
9928 *r->out.status_code = 0;
9930 memcpy(r->out.out_data, out_data.data, out_data.length);
9935 /****************************************************************
9936 _spoolss_AddPrintProcessor
9937 ****************************************************************/
9939 WERROR _spoolss_AddPrintProcessor(pipes_struct *p,
9940 struct spoolss_AddPrintProcessor *r)
9942 /* for now, just indicate success and ignore the add. We'll
9943 automatically set the winprint processor for printer
9944 entries later. Used to debug the LexMark Optra S 1855 PCL
9950 /****************************************************************
9952 ****************************************************************/
9954 WERROR _spoolss_AddPort(pipes_struct *p,
9955 struct spoolss_AddPort *r)
9957 /* do what w2k3 does */
9959 return WERR_NOT_SUPPORTED;
9962 /****************************************************************
9964 ****************************************************************/
9966 WERROR _spoolss_AddPrinter(pipes_struct *p,
9967 struct spoolss_AddPrinter *r)
9969 p->rng_fault_state = true;
9970 return WERR_NOT_SUPPORTED;
9973 /****************************************************************
9974 _spoolss_GetPrinterDriver
9975 ****************************************************************/
9977 WERROR _spoolss_GetPrinterDriver(pipes_struct *p,
9978 struct spoolss_GetPrinterDriver *r)
9980 p->rng_fault_state = true;
9981 return WERR_NOT_SUPPORTED;
9984 /****************************************************************
9985 _spoolss_ReadPrinter
9986 ****************************************************************/
9988 WERROR _spoolss_ReadPrinter(pipes_struct *p,
9989 struct spoolss_ReadPrinter *r)
9991 p->rng_fault_state = true;
9992 return WERR_NOT_SUPPORTED;
9995 /****************************************************************
9996 _spoolss_WaitForPrinterChange
9997 ****************************************************************/
9999 WERROR _spoolss_WaitForPrinterChange(pipes_struct *p,
10000 struct spoolss_WaitForPrinterChange *r)
10002 p->rng_fault_state = true;
10003 return WERR_NOT_SUPPORTED;
10006 /****************************************************************
10007 _spoolss_ConfigurePort
10008 ****************************************************************/
10010 WERROR _spoolss_ConfigurePort(pipes_struct *p,
10011 struct spoolss_ConfigurePort *r)
10013 p->rng_fault_state = true;
10014 return WERR_NOT_SUPPORTED;
10017 /****************************************************************
10018 _spoolss_DeletePort
10019 ****************************************************************/
10021 WERROR _spoolss_DeletePort(pipes_struct *p,
10022 struct spoolss_DeletePort *r)
10024 p->rng_fault_state = true;
10025 return WERR_NOT_SUPPORTED;
10028 /****************************************************************
10029 _spoolss_CreatePrinterIC
10030 ****************************************************************/
10032 WERROR _spoolss_CreatePrinterIC(pipes_struct *p,
10033 struct spoolss_CreatePrinterIC *r)
10035 p->rng_fault_state = true;
10036 return WERR_NOT_SUPPORTED;
10039 /****************************************************************
10040 _spoolss_PlayGDIScriptOnPrinterIC
10041 ****************************************************************/
10043 WERROR _spoolss_PlayGDIScriptOnPrinterIC(pipes_struct *p,
10044 struct spoolss_PlayGDIScriptOnPrinterIC *r)
10046 p->rng_fault_state = true;
10047 return WERR_NOT_SUPPORTED;
10050 /****************************************************************
10051 _spoolss_DeletePrinterIC
10052 ****************************************************************/
10054 WERROR _spoolss_DeletePrinterIC(pipes_struct *p,
10055 struct spoolss_DeletePrinterIC *r)
10057 p->rng_fault_state = true;
10058 return WERR_NOT_SUPPORTED;
10061 /****************************************************************
10062 _spoolss_AddPrinterConnection
10063 ****************************************************************/
10065 WERROR _spoolss_AddPrinterConnection(pipes_struct *p,
10066 struct spoolss_AddPrinterConnection *r)
10068 p->rng_fault_state = true;
10069 return WERR_NOT_SUPPORTED;
10072 /****************************************************************
10073 _spoolss_DeletePrinterConnection
10074 ****************************************************************/
10076 WERROR _spoolss_DeletePrinterConnection(pipes_struct *p,
10077 struct spoolss_DeletePrinterConnection *r)
10079 p->rng_fault_state = true;
10080 return WERR_NOT_SUPPORTED;
10083 /****************************************************************
10084 _spoolss_PrinterMessageBox
10085 ****************************************************************/
10087 WERROR _spoolss_PrinterMessageBox(pipes_struct *p,
10088 struct spoolss_PrinterMessageBox *r)
10090 p->rng_fault_state = true;
10091 return WERR_NOT_SUPPORTED;
10094 /****************************************************************
10095 _spoolss_AddMonitor
10096 ****************************************************************/
10098 WERROR _spoolss_AddMonitor(pipes_struct *p,
10099 struct spoolss_AddMonitor *r)
10101 p->rng_fault_state = true;
10102 return WERR_NOT_SUPPORTED;
10105 /****************************************************************
10106 _spoolss_DeleteMonitor
10107 ****************************************************************/
10109 WERROR _spoolss_DeleteMonitor(pipes_struct *p,
10110 struct spoolss_DeleteMonitor *r)
10112 p->rng_fault_state = true;
10113 return WERR_NOT_SUPPORTED;
10116 /****************************************************************
10117 _spoolss_DeletePrintProcessor
10118 ****************************************************************/
10120 WERROR _spoolss_DeletePrintProcessor(pipes_struct *p,
10121 struct spoolss_DeletePrintProcessor *r)
10123 p->rng_fault_state = true;
10124 return WERR_NOT_SUPPORTED;
10127 /****************************************************************
10128 _spoolss_AddPrintProvidor
10129 ****************************************************************/
10131 WERROR _spoolss_AddPrintProvidor(pipes_struct *p,
10132 struct spoolss_AddPrintProvidor *r)
10134 p->rng_fault_state = true;
10135 return WERR_NOT_SUPPORTED;
10138 /****************************************************************
10139 _spoolss_DeletePrintProvidor
10140 ****************************************************************/
10142 WERROR _spoolss_DeletePrintProvidor(pipes_struct *p,
10143 struct spoolss_DeletePrintProvidor *r)
10145 p->rng_fault_state = true;
10146 return WERR_NOT_SUPPORTED;
10149 /****************************************************************
10150 _spoolss_FindFirstPrinterChangeNotification
10151 ****************************************************************/
10153 WERROR _spoolss_FindFirstPrinterChangeNotification(pipes_struct *p,
10154 struct spoolss_FindFirstPrinterChangeNotification *r)
10156 p->rng_fault_state = true;
10157 return WERR_NOT_SUPPORTED;
10160 /****************************************************************
10161 _spoolss_FindNextPrinterChangeNotification
10162 ****************************************************************/
10164 WERROR _spoolss_FindNextPrinterChangeNotification(pipes_struct *p,
10165 struct spoolss_FindNextPrinterChangeNotification *r)
10167 p->rng_fault_state = true;
10168 return WERR_NOT_SUPPORTED;
10171 /****************************************************************
10172 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10173 ****************************************************************/
10175 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(pipes_struct *p,
10176 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
10178 p->rng_fault_state = true;
10179 return WERR_NOT_SUPPORTED;
10182 /****************************************************************
10183 _spoolss_ReplyOpenPrinter
10184 ****************************************************************/
10186 WERROR _spoolss_ReplyOpenPrinter(pipes_struct *p,
10187 struct spoolss_ReplyOpenPrinter *r)
10189 p->rng_fault_state = true;
10190 return WERR_NOT_SUPPORTED;
10193 /****************************************************************
10194 _spoolss_RouterReplyPrinter
10195 ****************************************************************/
10197 WERROR _spoolss_RouterReplyPrinter(pipes_struct *p,
10198 struct spoolss_RouterReplyPrinter *r)
10200 p->rng_fault_state = true;
10201 return WERR_NOT_SUPPORTED;
10204 /****************************************************************
10205 _spoolss_ReplyClosePrinter
10206 ****************************************************************/
10208 WERROR _spoolss_ReplyClosePrinter(pipes_struct *p,
10209 struct spoolss_ReplyClosePrinter *r)
10211 p->rng_fault_state = true;
10212 return WERR_NOT_SUPPORTED;
10215 /****************************************************************
10217 ****************************************************************/
10219 WERROR _spoolss_AddPortEx(pipes_struct *p,
10220 struct spoolss_AddPortEx *r)
10222 p->rng_fault_state = true;
10223 return WERR_NOT_SUPPORTED;
10226 /****************************************************************
10227 _spoolss_RouterFindFirstPrinterChangeNotification
10228 ****************************************************************/
10230 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(pipes_struct *p,
10231 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
10233 p->rng_fault_state = true;
10234 return WERR_NOT_SUPPORTED;
10237 /****************************************************************
10238 _spoolss_SpoolerInit
10239 ****************************************************************/
10241 WERROR _spoolss_SpoolerInit(pipes_struct *p,
10242 struct spoolss_SpoolerInit *r)
10244 p->rng_fault_state = true;
10245 return WERR_NOT_SUPPORTED;
10248 /****************************************************************
10249 _spoolss_ResetPrinterEx
10250 ****************************************************************/
10252 WERROR _spoolss_ResetPrinterEx(pipes_struct *p,
10253 struct spoolss_ResetPrinterEx *r)
10255 p->rng_fault_state = true;
10256 return WERR_NOT_SUPPORTED;
10259 /****************************************************************
10260 _spoolss_RouterReplyPrinterEx
10261 ****************************************************************/
10263 WERROR _spoolss_RouterReplyPrinterEx(pipes_struct *p,
10264 struct spoolss_RouterReplyPrinterEx *r)
10266 p->rng_fault_state = true;
10267 return WERR_NOT_SUPPORTED;
10270 /****************************************************************
10272 ****************************************************************/
10274 WERROR _spoolss_44(pipes_struct *p,
10275 struct spoolss_44 *r)
10277 p->rng_fault_state = true;
10278 return WERR_NOT_SUPPORTED;
10281 /****************************************************************
10283 ****************************************************************/
10285 WERROR _spoolss_47(pipes_struct *p,
10286 struct spoolss_47 *r)
10288 p->rng_fault_state = true;
10289 return WERR_NOT_SUPPORTED;
10292 /****************************************************************
10294 ****************************************************************/
10296 WERROR _spoolss_4a(pipes_struct *p,
10297 struct spoolss_4a *r)
10299 p->rng_fault_state = true;
10300 return WERR_NOT_SUPPORTED;
10303 /****************************************************************
10305 ****************************************************************/
10307 WERROR _spoolss_4b(pipes_struct *p,
10308 struct spoolss_4b *r)
10310 p->rng_fault_state = true;
10311 return WERR_NOT_SUPPORTED;
10314 /****************************************************************
10316 ****************************************************************/
10318 WERROR _spoolss_4c(pipes_struct *p,
10319 struct spoolss_4c *r)
10321 p->rng_fault_state = true;
10322 return WERR_NOT_SUPPORTED;
10325 /****************************************************************
10327 ****************************************************************/
10329 WERROR _spoolss_53(pipes_struct *p,
10330 struct spoolss_53 *r)
10332 p->rng_fault_state = true;
10333 return WERR_NOT_SUPPORTED;
10336 /****************************************************************
10338 ****************************************************************/
10340 WERROR _spoolss_55(pipes_struct *p,
10341 struct spoolss_55 *r)
10343 p->rng_fault_state = true;
10344 return WERR_NOT_SUPPORTED;
10347 /****************************************************************
10349 ****************************************************************/
10351 WERROR _spoolss_56(pipes_struct *p,
10352 struct spoolss_56 *r)
10354 p->rng_fault_state = true;
10355 return WERR_NOT_SUPPORTED;
10358 /****************************************************************
10360 ****************************************************************/
10362 WERROR _spoolss_57(pipes_struct *p,
10363 struct spoolss_57 *r)
10365 p->rng_fault_state = true;
10366 return WERR_NOT_SUPPORTED;
10369 /****************************************************************
10371 ****************************************************************/
10373 WERROR _spoolss_5a(pipes_struct *p,
10374 struct spoolss_5a *r)
10376 p->rng_fault_state = true;
10377 return WERR_NOT_SUPPORTED;
10380 /****************************************************************
10382 ****************************************************************/
10384 WERROR _spoolss_5b(pipes_struct *p,
10385 struct spoolss_5b *r)
10387 p->rng_fault_state = true;
10388 return WERR_NOT_SUPPORTED;
10391 /****************************************************************
10393 ****************************************************************/
10395 WERROR _spoolss_5c(pipes_struct *p,
10396 struct spoolss_5c *r)
10398 p->rng_fault_state = true;
10399 return WERR_NOT_SUPPORTED;
10402 /****************************************************************
10404 ****************************************************************/
10406 WERROR _spoolss_5d(pipes_struct *p,
10407 struct spoolss_5d *r)
10409 p->rng_fault_state = true;
10410 return WERR_NOT_SUPPORTED;
10413 /****************************************************************
10415 ****************************************************************/
10417 WERROR _spoolss_5e(pipes_struct *p,
10418 struct spoolss_5e *r)
10420 p->rng_fault_state = true;
10421 return WERR_NOT_SUPPORTED;
10424 /****************************************************************
10426 ****************************************************************/
10428 WERROR _spoolss_5f(pipes_struct *p,
10429 struct spoolss_5f *r)
10431 p->rng_fault_state = true;
10432 return WERR_NOT_SUPPORTED;