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. */
30 #include "../librpc/gen_ndr/srv_spoolss.h"
31 #include "../librpc/gen_ndr/cli_spoolss.h"
33 /* macros stolen from s4 spoolss server */
34 #define SPOOLSS_BUFFER_UNION(fn,ic,info,level) \
35 ((info)?ndr_size_##fn(info, level, ic, 0):0)
37 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,ic,info,level,count) \
38 ((info)?ndr_size_##fn##_info(mem_ctx, ic, level, count, info):0)
40 #define SPOOLSS_BUFFER_ARRAY(mem_ctx,fn,ic,info,count) \
41 ((info)?ndr_size_##fn##_info(mem_ctx, ic, count, info):0)
43 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
46 extern userdom_struct current_user_info;
49 #define DBGC_CLASS DBGC_RPC_SRV
51 #ifndef MAX_OPEN_PRINTER_EXS
52 #define MAX_OPEN_PRINTER_EXS 50
55 #define MAGIC_DISPLAY_FREQUENCY 0xfade2bad
56 #define PHANTOM_DEVMODE_KEY "_p_f_a_n_t_0_m_"
58 static Printer_entry *printers_list;
60 typedef struct _counter_printer_0 {
61 struct _counter_printer_0 *next;
62 struct _counter_printer_0 *prev;
68 static counter_printer_0 *counter_list;
70 static struct rpc_pipe_client *notify_cli_pipe; /* print notify back-channel pipe handle*/
71 static uint32_t smb_connections = 0;
74 /* in printing/nt_printing.c */
76 extern struct standard_mapping printer_std_mapping, printserver_std_mapping;
78 /* API table for Xcv Monitor functions */
80 struct xcv_api_table {
82 WERROR(*fn) (TALLOC_CTX *mem_ctx, NT_USER_TOKEN *token, DATA_BLOB *in, DATA_BLOB *out, uint32_t *needed);
85 /********************************************************************
86 * Canonicalize servername.
87 ********************************************************************/
89 static const char *canon_servername(const char *servername)
91 const char *pservername = servername;
92 while (*pservername == '\\') {
98 /* translate between internal status numbers and NT status numbers */
99 static int nt_printj_status(int v)
105 return JOB_STATUS_PAUSED;
107 return JOB_STATUS_SPOOLING;
109 return JOB_STATUS_PRINTING;
111 return JOB_STATUS_ERROR;
113 return JOB_STATUS_DELETING;
115 return JOB_STATUS_OFFLINE;
117 return JOB_STATUS_PAPEROUT;
119 return JOB_STATUS_PRINTED;
121 return JOB_STATUS_DELETED;
123 return JOB_STATUS_BLOCKED_DEVQ;
124 case LPQ_USER_INTERVENTION:
125 return JOB_STATUS_USER_INTERVENTION;
130 static int nt_printq_status(int v)
134 return PRINTER_STATUS_PAUSED;
143 /***************************************************************************
144 Disconnect from the client
145 ****************************************************************************/
147 static void srv_spoolss_replycloseprinter(int snum, struct policy_handle *handle)
153 * Tell the specific printing tdb we no longer want messages for this printer
154 * by deregistering our PID.
157 if (!print_notify_deregister_pid(snum))
158 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", lp_const_servicename(snum) ));
160 /* weird if the test succeds !!! */
161 if (smb_connections==0) {
162 DEBUG(0,("srv_spoolss_replycloseprinter:Trying to close non-existant notify backchannel !\n"));
166 status = rpccli_spoolss_ReplyClosePrinter(notify_cli_pipe, talloc_tos(),
169 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
170 DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed [%s].\n",
171 win_errstr(result)));
173 /* if it's the last connection, deconnect the IPC$ share */
174 if (smb_connections==1) {
176 cli_shutdown( rpc_pipe_np_smb_conn(notify_cli_pipe) );
177 notify_cli_pipe = NULL; /* The above call shuts downn the pipe also. */
179 messaging_deregister(smbd_messaging_context(),
180 MSG_PRINTER_NOTIFY2, NULL);
182 /* Tell the connections db we're no longer interested in
183 * printer notify messages. */
185 register_message_flags(false, FLAG_MSG_PRINT_NOTIFY);
191 /****************************************************************************
192 Functions to free a printer entry datastruct.
193 ****************************************************************************/
195 static int printer_entry_destructor(Printer_entry *Printer)
197 if (Printer->notify.client_connected == true) {
200 if ( Printer->printer_type == SPLHND_SERVER) {
202 srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
203 } else if (Printer->printer_type == SPLHND_PRINTER) {
204 snum = print_queue_snum(Printer->sharename);
206 srv_spoolss_replycloseprinter(snum,
207 &Printer->notify.client_hnd);
211 Printer->notify.flags=0;
212 Printer->notify.options=0;
213 Printer->notify.localmachine[0]='\0';
214 Printer->notify.printerlocal=0;
215 TALLOC_FREE(Printer->notify.option);
216 Printer->notify.client_connected = false;
218 free_nt_devicemode( &Printer->nt_devmode );
219 free_a_printer( &Printer->printer_info, 2 );
221 /* Remove from the internal list. */
222 DLIST_REMOVE(printers_list, Printer);
226 /****************************************************************************
227 find printer index by handle
228 ****************************************************************************/
230 static Printer_entry *find_printer_index_by_hnd(pipes_struct *p,
231 struct policy_handle *hnd)
233 Printer_entry *find_printer = NULL;
235 if(!find_policy_by_hnd(p,hnd,(void **)(void *)&find_printer)) {
236 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
243 /****************************************************************************
244 Close printer index by handle.
245 ****************************************************************************/
247 static bool close_printer_handle(pipes_struct *p, struct policy_handle *hnd)
249 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
252 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n",
257 close_policy_hnd(p, hnd);
262 /****************************************************************************
263 Delete a printer given a handle.
264 ****************************************************************************/
266 static WERROR delete_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *sharename)
268 char *cmd = lp_deleteprinter_cmd();
269 char *command = NULL;
271 SE_PRIV se_printop = SE_PRINT_OPERATOR;
272 bool is_print_op = false;
274 /* can't fail if we don't try */
279 command = talloc_asprintf(ctx,
286 is_print_op = user_has_privileges( token, &se_printop );
288 DEBUG(10,("Running [%s]\n", command));
290 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
295 if ( (ret = smbrun(command, NULL)) == 0 ) {
296 /* Tell everyone we updated smb.conf. */
297 message_send_all(smbd_messaging_context(),
298 MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
304 /********** END SePrintOperatorPrivlege BLOCK **********/
306 DEBUGADD(10,("returned [%d]\n", ret));
308 TALLOC_FREE(command);
311 return WERR_BADFID; /* What to return here? */
313 /* go ahead and re-read the services immediately */
315 reload_services(false);
318 if ( lp_servicenumber( sharename ) < 0 )
319 return WERR_ACCESS_DENIED;
324 /****************************************************************************
325 Delete a printer given a handle.
326 ****************************************************************************/
328 static WERROR delete_printer_handle(pipes_struct *p, struct policy_handle *hnd)
330 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
333 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
339 * It turns out that Windows allows delete printer on a handle
340 * opened by an admin user, then used on a pipe handle created
341 * by an anonymous user..... but they're working on security.... riiight !
345 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
346 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
347 return WERR_ACCESS_DENIED;
350 /* this does not need a become root since the access check has been
351 done on the handle already */
353 if (del_a_printer( Printer->sharename ) != 0) {
354 DEBUG(3,("Error deleting printer %s\n", Printer->sharename));
358 return delete_printer_hook(p->mem_ctx, p->server_info->ptok,
359 Printer->sharename );
362 /****************************************************************************
363 Return the snum of a printer corresponding to an handle.
364 ****************************************************************************/
366 static bool get_printer_snum(pipes_struct *p, struct policy_handle *hnd,
367 int *number, struct share_params **params)
369 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
372 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
377 switch (Printer->printer_type) {
379 DEBUG(4,("short name:%s\n", Printer->sharename));
380 *number = print_queue_snum(Printer->sharename);
381 return (*number != -1);
389 /****************************************************************************
390 Set printer handle type.
391 Check if it's \\server or \\server\printer
392 ****************************************************************************/
394 static bool set_printer_hnd_printertype(Printer_entry *Printer, const char *handlename)
396 DEBUG(3,("Setting printer type=%s\n", handlename));
398 if ( strlen(handlename) < 3 ) {
399 DEBUGADD(4,("A print server must have at least 1 char ! %s\n", handlename));
403 /* it's a print server */
404 if (*handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) {
405 DEBUGADD(4,("Printer is a print server\n"));
406 Printer->printer_type = SPLHND_SERVER;
408 /* it's a printer (set_printer_hnd_name() will handle port monitors */
410 DEBUGADD(4,("Printer is a printer\n"));
411 Printer->printer_type = SPLHND_PRINTER;
417 /****************************************************************************
418 Set printer handle name.. Accept names like \\server, \\server\printer,
419 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
420 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
421 XcvDataPort() interface.
422 ****************************************************************************/
424 static bool set_printer_hnd_name(Printer_entry *Printer, const char *handlename)
427 int n_services=lp_numservices();
428 char *aprinter, *printername;
429 const char *servername;
432 NT_PRINTER_INFO_LEVEL *printer = NULL;
435 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename,
436 (unsigned long)strlen(handlename)));
438 aprinter = CONST_DISCARD(char *, handlename);
439 if ( *handlename == '\\' ) {
440 servername = canon_servername(handlename);
441 if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
446 servername = global_myname();
449 /* save the servername to fill in replies on this handle */
451 if ( !is_myname_or_ipaddr( servername ) )
454 fstrcpy( Printer->servername, servername );
456 if ( Printer->printer_type == SPLHND_SERVER )
459 if ( Printer->printer_type != SPLHND_PRINTER )
462 DEBUGADD(5, ("searching for [%s]\n", aprinter ));
464 /* check for the Port Monitor Interface */
466 if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
467 Printer->printer_type = SPLHND_PORTMON_TCP;
468 fstrcpy(sname, SPL_XCV_MONITOR_TCPMON);
471 else if ( strequal( aprinter, SPL_XCV_MONITOR_LOCALMON ) ) {
472 Printer->printer_type = SPLHND_PORTMON_LOCAL;
473 fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON);
477 /* Search all sharenames first as this is easier than pulling
478 the printer_info_2 off of disk. Don't use find_service() since
479 that calls out to map_username() */
481 /* do another loop to look for printernames */
483 for (snum=0; !found && snum<n_services; snum++) {
485 /* no point going on if this is not a printer */
487 if ( !(lp_snum_ok(snum) && lp_print_ok(snum)) )
490 fstrcpy(sname, lp_servicename(snum));
491 if ( strequal( aprinter, sname ) ) {
496 /* no point looking up the printer object if
497 we aren't allowing printername != sharename */
499 if ( lp_force_printername(snum) )
502 fstrcpy(sname, lp_servicename(snum));
506 /* This call doesn't fill in the location or comment from
507 * a CUPS server for efficiency with large numbers of printers.
511 result = get_a_printer_search( NULL, &printer, 2, sname );
512 if ( !W_ERROR_IS_OK(result) ) {
513 DEBUG(0,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
514 sname, win_errstr(result)));
518 /* printername is always returned as \\server\printername */
519 if ( !(printername = strchr_m(&printer->info_2->printername[2], '\\')) ) {
520 DEBUG(0,("set_printer_hnd_name: info2->printername in wrong format! [%s]\n",
521 printer->info_2->printername));
522 free_a_printer( &printer, 2);
528 if ( strequal(printername, aprinter) ) {
529 free_a_printer( &printer, 2);
534 DEBUGADD(10, ("printername: %s\n", printername));
536 free_a_printer( &printer, 2);
539 free_a_printer( &printer, 2);
542 DEBUGADD(4,("Printer not found\n"));
546 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));
548 fstrcpy(Printer->sharename, sname);
553 /****************************************************************************
554 Find first available printer slot. creates a printer handle for you.
555 ****************************************************************************/
557 static bool open_printer_hnd(pipes_struct *p, struct policy_handle *hnd,
558 const char *name, uint32_t access_granted)
560 Printer_entry *new_printer;
562 DEBUG(10,("open_printer_hnd: name [%s]\n", name));
564 new_printer = TALLOC_ZERO_P(NULL, Printer_entry);
565 if (new_printer == NULL) {
568 talloc_set_destructor(new_printer, printer_entry_destructor);
570 if (!create_policy_hnd(p, hnd, new_printer)) {
571 TALLOC_FREE(new_printer);
575 /* Add to the internal list. */
576 DLIST_ADD(printers_list, new_printer);
578 new_printer->notify.option=NULL;
580 if (!set_printer_hnd_printertype(new_printer, name)) {
581 close_printer_handle(p, hnd);
585 if (!set_printer_hnd_name(new_printer, name)) {
586 close_printer_handle(p, hnd);
590 new_printer->access_granted = access_granted;
592 DEBUG(5, ("%d printer handles active\n",
593 (int)num_pipe_handles(p->pipe_handles)));
598 /***************************************************************************
599 check to see if the client motify handle is monitoring the notification
600 given by (notify_type, notify_field).
601 **************************************************************************/
603 static bool is_monitoring_event_flags(uint32_t flags, uint16_t notify_type,
604 uint16_t notify_field)
609 static bool is_monitoring_event(Printer_entry *p, uint16_t notify_type,
610 uint16_t notify_field)
612 struct spoolss_NotifyOption *option = p->notify.option;
616 * Flags should always be zero when the change notify
617 * is registered by the client's spooler. A user Win32 app
618 * might use the flags though instead of the NOTIFY_OPTION_INFO
627 return is_monitoring_event_flags(
628 p->notify.flags, notify_type, notify_field);
630 for (i = 0; i < option->count; i++) {
632 /* Check match for notify_type */
634 if (option->types[i].type != notify_type)
637 /* Check match for field */
639 for (j = 0; j < option->types[i].count; j++) {
640 if (option->types[i].fields[j].field == notify_field) {
646 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
647 p->servername, p->sharename, notify_type, notify_field));
652 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
653 _data->data.integer[0] = _integer; \
654 _data->data.integer[1] = 0;
657 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
658 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
659 if (!_data->data.string.string) {\
660 _data->data.string.size = 0; \
662 _data->data.string.size = strlen_m_term(_p) * 2;
664 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
665 _data->data.devmode.devmode = _devmode;
667 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _size, _sd) \
668 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
669 if (!_data->data.sd.sd) { \
670 _data->data.sd.sd_size = 0; \
672 _data->data.sd.sd_size = _size;
674 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
679 struct spoolss_Time st;
683 if (!init_systemtime(&st, t)) {
687 p = talloc_array(mem_ctx, char, len);
693 * Systemtime must be linearized as a set of UINT16's.
694 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
697 SSVAL(p, 0, st.year);
698 SSVAL(p, 2, st.month);
699 SSVAL(p, 4, st.day_of_week);
701 SSVAL(p, 8, st.hour);
702 SSVAL(p, 10, st.minute);
703 SSVAL(p, 12, st.second);
704 SSVAL(p, 14, st.millisecond);
710 /* Convert a notification message to a struct spoolss_Notify */
712 static void notify_one_value(struct spoolss_notify_msg *msg,
713 struct spoolss_Notify *data,
716 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, msg->notify.value[0]);
719 static void notify_string(struct spoolss_notify_msg *msg,
720 struct spoolss_Notify *data,
723 /* The length of the message includes the trailing \0 */
725 data->data.string.size = msg->len * 2;
726 data->data.string.string = talloc_strdup(mem_ctx, msg->notify.data);
727 if (!data->data.string.string) {
728 data->data.string.size = 0;
733 static void notify_system_time(struct spoolss_notify_msg *msg,
734 struct spoolss_Notify *data,
737 data->data.string.string = NULL;
738 data->data.string.size = 0;
740 if (msg->len != sizeof(time_t)) {
741 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
746 init_systemtime_buffer(mem_ctx, gmtime((time_t *)msg->notify.data),
747 &data->data.string.string,
748 &data->data.string.size);
751 struct notify2_message_table {
753 void (*fn)(struct spoolss_notify_msg *msg,
754 struct spoolss_Notify *data, TALLOC_CTX *mem_ctx);
757 static struct notify2_message_table printer_notify_table[] = {
758 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string },
759 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string },
760 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string },
761 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string },
762 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string },
763 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string },
764 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string },
765 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL },
766 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string },
767 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string },
768 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL },
769 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string },
770 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
771 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value },
772 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value },
773 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL },
774 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL },
775 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL },
776 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value },
779 static struct notify2_message_table job_notify_table[] = {
780 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL },
781 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL },
782 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL },
783 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string },
784 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL },
785 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL },
786 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL },
787 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL },
788 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL },
789 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL },
790 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value },
791 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL },
792 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
793 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string },
794 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL },
795 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL },
796 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time },
797 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL },
798 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL },
799 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL },
800 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value },
801 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL },
802 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value },
803 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL },
807 /***********************************************************************
808 Allocate talloc context for container object
809 **********************************************************************/
811 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
816 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
821 /***********************************************************************
822 release all allocated memory and zero out structure
823 **********************************************************************/
825 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
831 talloc_destroy(ctr->ctx);
838 /***********************************************************************
839 **********************************************************************/
841 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
849 /***********************************************************************
850 **********************************************************************/
852 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
854 if ( !ctr || !ctr->msg_groups )
857 if ( idx >= ctr->num_groups )
860 return &ctr->msg_groups[idx];
864 /***********************************************************************
865 How many groups of change messages do we have ?
866 **********************************************************************/
868 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
873 return ctr->num_groups;
876 /***********************************************************************
877 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
878 **********************************************************************/
880 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
882 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
883 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
884 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
890 /* loop over all groups looking for a matching printer name */
892 for ( i=0; i<ctr->num_groups; i++ ) {
893 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
897 /* add a new group? */
899 if ( i == ctr->num_groups ) {
902 if ( !(groups = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
903 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
906 ctr->msg_groups = groups;
908 /* clear the new entry and set the printer name */
910 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
911 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
914 /* add the change messages; 'i' is the correct index now regardless */
916 msg_grp = &ctr->msg_groups[i];
920 if ( !(msg_list = TALLOC_REALLOC_ARRAY( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
921 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
924 msg_grp->msgs = msg_list;
926 new_slot = msg_grp->num_msgs-1;
927 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
929 /* need to allocate own copy of data */
932 msg_grp->msgs[new_slot].notify.data = (char *)
933 TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len );
935 return ctr->num_groups;
938 /***********************************************************************
939 Send a change notication message on all handles which have a call
941 **********************************************************************/
943 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
946 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
947 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
948 SPOOLSS_NOTIFY_MSG *messages;
949 int sending_msg_count;
952 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
956 messages = msg_group->msgs;
959 DEBUG(5,("send_notify2_changes() called with no messages!\n"));
963 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
965 /* loop over all printers */
967 for (p = printers_list; p; p = p->next) {
968 struct spoolss_Notify *notifies;
973 /* Is there notification on this handle? */
975 if ( !p->notify.client_connected )
978 DEBUG(10,("Client connected! [\\\\%s\\%s]\n", p->servername, p->sharename));
980 /* For this printer? Print servers always receive
983 if ( ( p->printer_type == SPLHND_PRINTER ) &&
984 ( !strequal(msg_group->printername, p->sharename) ) )
987 DEBUG(10,("Our printer\n"));
989 /* allocate the max entries possible */
991 notifies = TALLOC_ZERO_ARRAY(mem_ctx, struct spoolss_Notify, msg_group->num_msgs);
996 /* build the array of change notifications */
998 sending_msg_count = 0;
1000 for ( i=0; i<msg_group->num_msgs; i++ ) {
1001 SPOOLSS_NOTIFY_MSG *msg = &messages[i];
1003 /* Are we monitoring this event? */
1005 if (!is_monitoring_event(p, msg->type, msg->field))
1008 sending_msg_count++;
1011 DEBUG(10,("process_notify2_message: Sending message type [0x%x] field [0x%2x] for printer [%s]\n",
1012 msg->type, msg->field, p->sharename));
1015 * if the is a printer notification handle and not a job notification
1016 * type, then set the id to 0. Other wise just use what was specified
1019 * When registering change notification on a print server handle
1020 * we always need to send back the id (snum) matching the printer
1021 * for which the change took place. For change notify registered
1022 * on a printer handle, this does not matter and the id should be 0.
1027 if ( ( p->printer_type == SPLHND_PRINTER ) && ( msg->type == PRINTER_NOTIFY_TYPE ) )
1033 /* Convert unix jobid to smb jobid */
1035 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1036 id = sysjob_to_jobid(msg->id);
1039 DEBUG(3, ("no such unix jobid %d\n", msg->id));
1044 construct_info_data( ¬ifies[count], msg->type, msg->field, id );
1047 case PRINTER_NOTIFY_TYPE:
1048 if ( printer_notify_table[msg->field].fn )
1049 printer_notify_table[msg->field].fn(msg, ¬ifies[count], mem_ctx);
1052 case JOB_NOTIFY_TYPE:
1053 if ( job_notify_table[msg->field].fn )
1054 job_notify_table[msg->field].fn(msg, ¬ifies[count], mem_ctx);
1058 DEBUG(5, ("Unknown notification type %d\n", msg->type));
1065 if ( sending_msg_count ) {
1068 union spoolss_ReplyPrinterInfo info;
1069 struct spoolss_NotifyInfo info0;
1070 uint32_t reply_result;
1072 info0.version = 0x2;
1073 info0.flags = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
1074 info0.count = count;
1075 info0.notifies = notifies;
1077 info.info0 = &info0;
1079 status = rpccli_spoolss_RouterReplyPrinterEx(notify_cli_pipe, mem_ctx,
1080 &p->notify.client_hnd,
1081 p->notify.change, /* color */
1084 0, /* reply_type, must be 0 */
1087 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) {
1088 DEBUG(1,("RouterReplyPrinterEx to client: %s failed: %s\n",
1089 notify_cli_pipe->srv_name_slash,
1092 switch (reply_result) {
1095 case PRINTER_NOTIFY_INFO_DISCARDED:
1096 case PRINTER_NOTIFY_INFO_DISCARDNOTED:
1097 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
1106 DEBUG(8,("send_notify2_changes: Exit...\n"));
1110 /***********************************************************************
1111 **********************************************************************/
1113 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1116 uint32_t tv_sec, tv_usec;
1119 /* Unpack message */
1121 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "f",
1124 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "ddddddd",
1126 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1129 tdb_unpack((uint8_t *)buf + offset, len - offset, "dd",
1130 &msg->notify.value[0], &msg->notify.value[1]);
1132 tdb_unpack((uint8_t *)buf + offset, len - offset, "B",
1133 &msg->len, &msg->notify.data);
1135 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1136 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1138 tv->tv_sec = tv_sec;
1139 tv->tv_usec = tv_usec;
1142 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1143 msg->notify.value[1]));
1145 dump_data(3, (uint8_t *)msg->notify.data, msg->len);
1150 /********************************************************************
1151 Receive a notify2 message list
1152 ********************************************************************/
1154 static void receive_notify2_message_list(struct messaging_context *msg,
1157 struct server_id server_id,
1160 size_t msg_count, i;
1161 char *buf = (char *)data->data;
1164 SPOOLSS_NOTIFY_MSG notify;
1165 SPOOLSS_NOTIFY_MSG_CTR messages;
1168 if (data->length < 4) {
1169 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1173 msg_count = IVAL(buf, 0);
1176 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1178 if (msg_count == 0) {
1179 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1183 /* initialize the container */
1185 ZERO_STRUCT( messages );
1186 notify_msg_ctr_init( &messages );
1189 * build message groups for each printer identified
1190 * in a change_notify msg. Remember that a PCN message
1191 * includes the handle returned for the srv_spoolss_replyopenprinter()
1192 * call. Therefore messages are grouped according to printer handle.
1195 for ( i=0; i<msg_count; i++ ) {
1196 struct timeval msg_tv;
1198 if (msg_ptr + 4 - buf > data->length) {
1199 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1203 msg_len = IVAL(msg_ptr,0);
1206 if (msg_ptr + msg_len - buf > data->length) {
1207 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1211 /* unpack messages */
1213 ZERO_STRUCT( notify );
1214 notify2_unpack_msg( ¬ify, &msg_tv, msg_ptr, msg_len );
1217 /* add to correct list in container */
1219 notify_msg_ctr_addmsg( &messages, ¬ify );
1221 /* free memory that might have been allocated by notify2_unpack_msg() */
1223 if ( notify.len != 0 )
1224 SAFE_FREE( notify.notify.data );
1227 /* process each group of messages */
1229 num_groups = notify_msg_ctr_numgroups( &messages );
1230 for ( i=0; i<num_groups; i++ )
1231 send_notify2_changes( &messages, i );
1236 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1237 (uint32_t)msg_count ));
1239 notify_msg_ctr_destroy( &messages );
1244 /********************************************************************
1245 Send a message to ourself about new driver being installed
1246 so we can upgrade the information for each printer bound to this
1248 ********************************************************************/
1250 static bool srv_spoolss_drv_upgrade_printer(const char *drivername)
1252 int len = strlen(drivername);
1257 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1260 messaging_send_buf(smbd_messaging_context(), procid_self(),
1261 MSG_PRINTER_DRVUPGRADE,
1262 (uint8_t *)drivername, len+1);
1267 /**********************************************************************
1268 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1269 over all printers, upgrading ones as necessary
1270 **********************************************************************/
1272 void do_drv_upgrade_printer(struct messaging_context *msg,
1275 struct server_id server_id,
1280 int n_services = lp_numservices();
1283 len = MIN(data->length,sizeof(drivername)-1);
1284 strncpy(drivername, (const char *)data->data, len);
1286 DEBUG(10,("do_drv_upgrade_printer: Got message for new driver [%s]\n", drivername ));
1288 /* Iterate the printer list */
1290 for (snum=0; snum<n_services; snum++)
1292 if (lp_snum_ok(snum) && lp_print_ok(snum) )
1295 NT_PRINTER_INFO_LEVEL *printer = NULL;
1297 result = get_a_printer(NULL, &printer, 2, lp_const_servicename(snum));
1298 if (!W_ERROR_IS_OK(result))
1301 if (printer && printer->info_2 && !strcmp(drivername, printer->info_2->drivername))
1303 DEBUG(6,("Updating printer [%s]\n", printer->info_2->printername));
1305 /* all we care about currently is the change_id */
1307 result = mod_a_printer(printer, 2);
1308 if (!W_ERROR_IS_OK(result)) {
1309 DEBUG(3,("do_drv_upgrade_printer: mod_a_printer() failed with status [%s]\n",
1310 win_errstr(result)));
1314 free_a_printer(&printer, 2);
1321 /********************************************************************
1322 Update the cache for all printq's with a registered client
1324 ********************************************************************/
1326 void update_monitored_printq_cache( void )
1328 Printer_entry *printer = printers_list;
1331 /* loop through all printers and update the cache where
1332 client_connected == true */
1335 if ( (printer->printer_type == SPLHND_PRINTER)
1336 && printer->notify.client_connected )
1338 snum = print_queue_snum(printer->sharename);
1339 print_queue_status( snum, NULL, NULL );
1342 printer = printer->next;
1347 /********************************************************************
1348 Send a message to ourself about new driver being installed
1349 so we can upgrade the information for each printer bound to this
1351 ********************************************************************/
1353 static bool srv_spoolss_reset_printerdata(char* drivername)
1355 int len = strlen(drivername);
1360 DEBUG(10,("srv_spoolss_reset_printerdata: Sending message about resetting printerdata [%s]\n",
1363 messaging_send_buf(smbd_messaging_context(), procid_self(),
1364 MSG_PRINTERDATA_INIT_RESET,
1365 (uint8_t *)drivername, len+1);
1370 /**********************************************************************
1371 callback to receive a MSG_PRINTERDATA_INIT_RESET message and interate
1372 over all printers, resetting printer data as neessary
1373 **********************************************************************/
1375 void reset_all_printerdata(struct messaging_context *msg,
1378 struct server_id server_id,
1383 int n_services = lp_numservices();
1386 len = MIN( data->length, sizeof(drivername)-1 );
1387 strncpy( drivername, (const char *)data->data, len );
1389 DEBUG(10,("reset_all_printerdata: Got message for new driver [%s]\n", drivername ));
1391 /* Iterate the printer list */
1393 for ( snum=0; snum<n_services; snum++ )
1395 if ( lp_snum_ok(snum) && lp_print_ok(snum) )
1398 NT_PRINTER_INFO_LEVEL *printer = NULL;
1400 result = get_a_printer( NULL, &printer, 2, lp_const_servicename(snum) );
1401 if ( !W_ERROR_IS_OK(result) )
1405 * if the printer is bound to the driver,
1406 * then reset to the new driver initdata
1409 if ( printer && printer->info_2 && !strcmp(drivername, printer->info_2->drivername) )
1411 DEBUG(6,("reset_all_printerdata: Updating printer [%s]\n", printer->info_2->printername));
1413 if ( !set_driver_init(printer, 2) ) {
1414 DEBUG(5,("reset_all_printerdata: Error resetting printer data for printer [%s], driver [%s]!\n",
1415 printer->info_2->printername, printer->info_2->drivername));
1418 result = mod_a_printer( printer, 2 );
1419 if ( !W_ERROR_IS_OK(result) ) {
1420 DEBUG(3,("reset_all_printerdata: mod_a_printer() failed! (%s)\n",
1421 get_dos_error_msg(result)));
1425 free_a_printer( &printer, 2 );
1434 /****************************************************************
1435 _spoolss_OpenPrinter
1436 ****************************************************************/
1438 WERROR _spoolss_OpenPrinter(pipes_struct *p,
1439 struct spoolss_OpenPrinter *r)
1441 struct spoolss_OpenPrinterEx e;
1444 ZERO_STRUCT(e.in.userlevel);
1446 e.in.printername = r->in.printername;
1447 e.in.datatype = r->in.datatype;
1448 e.in.devmode_ctr = r->in.devmode_ctr;
1449 e.in.access_mask = r->in.access_mask;
1452 e.out.handle = r->out.handle;
1454 werr = _spoolss_OpenPrinterEx(p, &e);
1456 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1457 /* OpenPrinterEx returns this for a bad
1458 * printer name. We must return WERR_INVALID_PRINTER_NAME
1461 werr = WERR_INVALID_PRINTER_NAME;
1467 /********************************************************************
1468 ********************************************************************/
1470 bool convert_devicemode(const char *printername,
1471 const struct spoolss_DeviceMode *devmode,
1472 NT_DEVICEMODE **pp_nt_devmode)
1474 NT_DEVICEMODE *nt_devmode = *pp_nt_devmode;
1477 * Ensure nt_devmode is a valid pointer
1478 * as we will be overwriting it.
1481 if (nt_devmode == NULL) {
1482 DEBUG(5, ("convert_devicemode: allocating a generic devmode\n"));
1483 if ((nt_devmode = construct_nt_devicemode(printername)) == NULL)
1487 fstrcpy(nt_devmode->devicename, devmode->devicename);
1488 fstrcpy(nt_devmode->formname, devmode->formname);
1490 nt_devmode->devicename[31] = '\0';
1491 nt_devmode->formname[31] = '\0';
1493 nt_devmode->specversion = devmode->specversion;
1494 nt_devmode->driverversion = devmode->driverversion;
1495 nt_devmode->size = devmode->size;
1496 nt_devmode->fields = devmode->fields;
1497 nt_devmode->orientation = devmode->orientation;
1498 nt_devmode->papersize = devmode->papersize;
1499 nt_devmode->paperlength = devmode->paperlength;
1500 nt_devmode->paperwidth = devmode->paperwidth;
1501 nt_devmode->scale = devmode->scale;
1502 nt_devmode->copies = devmode->copies;
1503 nt_devmode->defaultsource = devmode->defaultsource;
1504 nt_devmode->printquality = devmode->printquality;
1505 nt_devmode->color = devmode->color;
1506 nt_devmode->duplex = devmode->duplex;
1507 nt_devmode->yresolution = devmode->yresolution;
1508 nt_devmode->ttoption = devmode->ttoption;
1509 nt_devmode->collate = devmode->collate;
1511 nt_devmode->logpixels = devmode->logpixels;
1512 nt_devmode->bitsperpel = devmode->bitsperpel;
1513 nt_devmode->pelswidth = devmode->pelswidth;
1514 nt_devmode->pelsheight = devmode->pelsheight;
1515 nt_devmode->displayflags = devmode->displayflags;
1516 nt_devmode->displayfrequency = devmode->displayfrequency;
1517 nt_devmode->icmmethod = devmode->icmmethod;
1518 nt_devmode->icmintent = devmode->icmintent;
1519 nt_devmode->mediatype = devmode->mediatype;
1520 nt_devmode->dithertype = devmode->dithertype;
1521 nt_devmode->reserved1 = devmode->reserved1;
1522 nt_devmode->reserved2 = devmode->reserved2;
1523 nt_devmode->panningwidth = devmode->panningwidth;
1524 nt_devmode->panningheight = devmode->panningheight;
1527 * Only change private and driverextra if the incoming devmode
1528 * has a new one. JRA.
1531 if ((devmode->__driverextra_length != 0) && (devmode->driverextra_data.data != NULL)) {
1532 SAFE_FREE(nt_devmode->nt_dev_private);
1533 nt_devmode->driverextra = devmode->__driverextra_length;
1534 if((nt_devmode->nt_dev_private = SMB_MALLOC_ARRAY(uint8_t, nt_devmode->driverextra)) == NULL)
1536 memcpy(nt_devmode->nt_dev_private, devmode->driverextra_data.data, nt_devmode->driverextra);
1539 *pp_nt_devmode = nt_devmode;
1544 /****************************************************************
1545 _spoolss_OpenPrinterEx
1546 ****************************************************************/
1548 WERROR _spoolss_OpenPrinterEx(pipes_struct *p,
1549 struct spoolss_OpenPrinterEx *r)
1552 Printer_entry *Printer=NULL;
1554 if (!r->in.printername) {
1555 return WERR_INVALID_PARAM;
1558 /* some sanity check because you can open a printer or a print server */
1559 /* aka: \\server\printer or \\server */
1561 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1563 if (!open_printer_hnd(p, r->out.handle, r->in.printername, 0)) {
1564 ZERO_STRUCTP(r->out.handle);
1565 return WERR_INVALID_PARAM;
1568 Printer = find_printer_index_by_hnd(p, r->out.handle);
1570 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1571 "handle we created for printer %s\n", r->in.printername));
1572 close_printer_handle(p, r->out.handle);
1573 ZERO_STRUCTP(r->out.handle);
1574 return WERR_INVALID_PARAM;
1578 * First case: the user is opening the print server:
1580 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1581 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1583 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1584 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1585 * or if the user is listed in the smb.conf printer admin parameter.
1587 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1588 * client view printer folder, but does not show the MSAPW.
1590 * Note: this test needs code to check access rights here too. Jeremy
1591 * could you look at this?
1593 * Second case: the user is opening a printer:
1594 * NT doesn't let us connect to a printer if the connecting user
1595 * doesn't have print permission.
1597 * Third case: user is opening a Port Monitor
1598 * access checks same as opening a handle to the print server.
1601 switch (Printer->printer_type )
1604 case SPLHND_PORTMON_TCP:
1605 case SPLHND_PORTMON_LOCAL:
1606 /* Printserver handles use global struct... */
1610 /* Map standard access rights to object specific access rights */
1612 se_map_standard(&r->in.access_mask,
1613 &printserver_std_mapping);
1615 /* Deny any object specific bits that don't apply to print
1616 servers (i.e printer and job specific bits) */
1618 r->in.access_mask &= SPECIFIC_RIGHTS_MASK;
1620 if (r->in.access_mask &
1621 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1622 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1623 close_printer_handle(p, r->out.handle);
1624 ZERO_STRUCTP(r->out.handle);
1625 return WERR_ACCESS_DENIED;
1628 /* Allow admin access */
1630 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1632 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1634 if (!lp_ms_add_printer_wizard()) {
1635 close_printer_handle(p, r->out.handle);
1636 ZERO_STRUCTP(r->out.handle);
1637 return WERR_ACCESS_DENIED;
1640 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1641 and not a printer admin, then fail */
1643 if ((p->server_info->utok.uid != sec_initial_uid()) &&
1644 !user_has_privileges(p->server_info->ptok,
1646 !token_contains_name_in_list(
1647 uidtoname(p->server_info->utok.uid),
1649 p->server_info->ptok,
1650 lp_printer_admin(snum))) {
1651 close_printer_handle(p, r->out.handle);
1652 ZERO_STRUCTP(r->out.handle);
1653 return WERR_ACCESS_DENIED;
1656 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1660 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1663 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1664 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1666 /* We fall through to return WERR_OK */
1669 case SPLHND_PRINTER:
1670 /* NT doesn't let us connect to a printer if the connecting user
1671 doesn't have print permission. */
1673 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1674 close_printer_handle(p, r->out.handle);
1675 ZERO_STRUCTP(r->out.handle);
1679 if (r->in.access_mask == SEC_FLAG_MAXIMUM_ALLOWED) {
1680 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1683 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1685 /* map an empty access mask to the minimum access mask */
1686 if (r->in.access_mask == 0x0)
1687 r->in.access_mask = PRINTER_ACCESS_USE;
1690 * If we are not serving the printer driver for this printer,
1691 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1692 * will keep NT clients happy --jerry
1695 if (lp_use_client_driver(snum)
1696 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1698 r->in.access_mask = PRINTER_ACCESS_USE;
1701 /* check smb.conf parameters and the the sec_desc */
1703 if ( !check_access(get_client_fd(), lp_hostsallow(snum), lp_hostsdeny(snum)) ) {
1704 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1705 ZERO_STRUCTP(r->out.handle);
1706 return WERR_ACCESS_DENIED;
1709 if (!user_ok_token(uidtoname(p->server_info->utok.uid), NULL,
1710 p->server_info->ptok, snum) ||
1711 !print_access_check(p->server_info, snum,
1712 r->in.access_mask)) {
1713 DEBUG(3, ("access DENIED for printer open\n"));
1714 close_printer_handle(p, r->out.handle);
1715 ZERO_STRUCTP(r->out.handle);
1716 return WERR_ACCESS_DENIED;
1719 if ((r->in.access_mask & SPECIFIC_RIGHTS_MASK)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1720 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1721 close_printer_handle(p, r->out.handle);
1722 ZERO_STRUCTP(r->out.handle);
1723 return WERR_ACCESS_DENIED;
1726 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1727 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1729 r->in.access_mask = PRINTER_ACCESS_USE;
1731 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1732 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1737 /* sanity check to prevent programmer error */
1738 ZERO_STRUCTP(r->out.handle);
1742 Printer->access_granted = r->in.access_mask;
1745 * If the client sent a devmode in the OpenPrinter() call, then
1746 * save it here in case we get a job submission on this handle
1749 if ((Printer->printer_type != SPLHND_SERVER) &&
1750 r->in.devmode_ctr.devmode) {
1751 convert_devicemode(Printer->sharename,
1752 r->in.devmode_ctr.devmode,
1753 &Printer->nt_devmode);
1756 #if 0 /* JERRY -- I'm doubtful this is really effective */
1757 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1758 optimization in Windows 2000 clients --jerry */
1760 if ( (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1761 && (RA_WIN2K == get_remote_arch()) )
1763 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1764 sys_usleep( 500000 );
1771 /****************************************************************************
1772 ****************************************************************************/
1774 static bool printer_info2_to_nt_printer_info2(struct spoolss_SetPrinterInfo2 *r,
1775 NT_PRINTER_INFO_LEVEL_2 *d)
1777 DEBUG(7,("printer_info2_to_nt_printer_info2\n"));
1783 d->attributes = r->attributes;
1784 d->priority = r->priority;
1785 d->default_priority = r->defaultpriority;
1786 d->starttime = r->starttime;
1787 d->untiltime = r->untiltime;
1788 d->status = r->status;
1789 d->cjobs = r->cjobs;
1791 fstrcpy(d->servername, r->servername);
1792 fstrcpy(d->printername, r->printername);
1793 fstrcpy(d->sharename, r->sharename);
1794 fstrcpy(d->portname, r->portname);
1795 fstrcpy(d->drivername, r->drivername);
1796 slprintf(d->comment, sizeof(d->comment)-1, "%s", r->comment);
1797 fstrcpy(d->location, r->location);
1798 fstrcpy(d->sepfile, r->sepfile);
1799 fstrcpy(d->printprocessor, r->printprocessor);
1800 fstrcpy(d->datatype, r->datatype);
1801 fstrcpy(d->parameters, r->parameters);
1806 /****************************************************************************
1807 ****************************************************************************/
1809 static bool convert_printer_info(struct spoolss_SetPrinterInfoCtr *info_ctr,
1810 NT_PRINTER_INFO_LEVEL *printer)
1814 switch (info_ctr->level) {
1816 /* allocate memory if needed. Messy because
1817 convert_printer_info is used to update an existing
1818 printer or build a new one */
1820 if (!printer->info_2) {
1821 printer->info_2 = TALLOC_ZERO_P(printer, NT_PRINTER_INFO_LEVEL_2);
1822 if (!printer->info_2) {
1823 DEBUG(0,("convert_printer_info: "
1824 "talloc() failed!\n"));
1829 ret = printer_info2_to_nt_printer_info2(info_ctr->info.info2,
1831 printer->info_2->setuptime = time(NULL);
1838 /****************************************************************
1839 _spoolss_ClosePrinter
1840 ****************************************************************/
1842 WERROR _spoolss_ClosePrinter(pipes_struct *p,
1843 struct spoolss_ClosePrinter *r)
1845 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
1847 if (Printer && Printer->document_started) {
1848 struct spoolss_EndDocPrinter e;
1850 e.in.handle = r->in.handle;
1852 _spoolss_EndDocPrinter(p, &e);
1855 if (!close_printer_handle(p, r->in.handle))
1858 /* clear the returned printer handle. Observed behavior
1859 from Win2k server. Don't think this really matters.
1860 Previous code just copied the value of the closed
1863 ZERO_STRUCTP(r->out.handle);
1868 /****************************************************************
1869 _spoolss_DeletePrinter
1870 ****************************************************************/
1872 WERROR _spoolss_DeletePrinter(pipes_struct *p,
1873 struct spoolss_DeletePrinter *r)
1875 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
1878 if (Printer && Printer->document_started) {
1879 struct spoolss_EndDocPrinter e;
1881 e.in.handle = r->in.handle;
1883 _spoolss_EndDocPrinter(p, &e);
1886 result = delete_printer_handle(p, r->in.handle);
1888 update_c_setprinter(false);
1893 /*******************************************************************
1894 * static function to lookup the version id corresponding to an
1895 * long architecture string
1896 ******************************************************************/
1898 static const struct print_architecture_table_node archi_table[]= {
1900 {"Windows 4.0", SPL_ARCH_WIN40, 0 },
1901 {"Windows NT x86", SPL_ARCH_W32X86, 2 },
1902 {"Windows NT R4000", SPL_ARCH_W32MIPS, 2 },
1903 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA, 2 },
1904 {"Windows NT PowerPC", SPL_ARCH_W32PPC, 2 },
1905 {"Windows IA64", SPL_ARCH_IA64, 3 },
1906 {"Windows x64", SPL_ARCH_X64, 3 },
1910 static int get_version_id(const char *arch)
1914 for (i=0; archi_table[i].long_archi != NULL; i++)
1916 if (strcmp(arch, archi_table[i].long_archi) == 0)
1917 return (archi_table[i].version);
1923 /****************************************************************
1924 _spoolss_DeletePrinterDriver
1925 ****************************************************************/
1927 WERROR _spoolss_DeletePrinterDriver(pipes_struct *p,
1928 struct spoolss_DeletePrinterDriver *r)
1931 union spoolss_DriverInfo *info = NULL;
1932 union spoolss_DriverInfo *info_win2k = NULL;
1935 WERROR status_win2k = WERR_ACCESS_DENIED;
1936 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1938 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1939 and not a printer admin, then fail */
1941 if ( (p->server_info->utok.uid != sec_initial_uid())
1942 && !user_has_privileges(p->server_info->ptok, &se_printop )
1943 && !token_contains_name_in_list(
1944 uidtoname(p->server_info->utok.uid), NULL,
1945 NULL, p->server_info->ptok,
1946 lp_printer_admin(-1)) )
1948 return WERR_ACCESS_DENIED;
1951 /* check that we have a valid driver name first */
1953 if ((version = get_version_id(r->in.architecture)) == -1)
1954 return WERR_INVALID_ENVIRONMENT;
1956 if (!W_ERROR_IS_OK(get_a_printer_driver(p->mem_ctx, &info, 3, r->in.driver,
1960 /* try for Win2k driver if "Windows NT x86" */
1962 if ( version == 2 ) {
1964 if (!W_ERROR_IS_OK(get_a_printer_driver(p->mem_ctx,
1969 status = WERR_UNKNOWN_PRINTER_DRIVER;
1973 /* otherwise it was a failure */
1975 status = WERR_UNKNOWN_PRINTER_DRIVER;
1981 if (printer_driver_in_use(&info->info3)) {
1982 status = WERR_PRINTER_DRIVER_IN_USE;
1988 if (W_ERROR_IS_OK(get_a_printer_driver(p->mem_ctx,
1991 r->in.architecture, 3)))
1993 /* if we get to here, we now have 2 driver info structures to remove */
1994 /* remove the Win2k driver first*/
1996 status_win2k = delete_printer_driver(
1997 p, &info_win2k->info3, 3, false);
1998 free_a_printer_driver(info_win2k);
2000 /* this should not have failed---if it did, report to client */
2001 if ( !W_ERROR_IS_OK(status_win2k) )
2003 status = status_win2k;
2009 status = delete_printer_driver(p, &info->info3, version, false);
2011 /* if at least one of the deletes succeeded return OK */
2013 if ( W_ERROR_IS_OK(status) || W_ERROR_IS_OK(status_win2k) )
2017 free_a_printer_driver(info);
2022 /****************************************************************
2023 _spoolss_DeletePrinterDriverEx
2024 ****************************************************************/
2026 WERROR _spoolss_DeletePrinterDriverEx(pipes_struct *p,
2027 struct spoolss_DeletePrinterDriverEx *r)
2029 union spoolss_DriverInfo *info = NULL;
2030 union spoolss_DriverInfo *info_win2k = NULL;
2034 WERROR status_win2k = WERR_ACCESS_DENIED;
2035 SE_PRIV se_printop = SE_PRINT_OPERATOR;
2037 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2038 and not a printer admin, then fail */
2040 if ( (p->server_info->utok.uid != sec_initial_uid())
2041 && !user_has_privileges(p->server_info->ptok, &se_printop )
2042 && !token_contains_name_in_list(
2043 uidtoname(p->server_info->utok.uid), NULL, NULL,
2044 p->server_info->ptok, lp_printer_admin(-1)) )
2046 return WERR_ACCESS_DENIED;
2049 /* check that we have a valid driver name first */
2050 if ((version = get_version_id(r->in.architecture)) == -1) {
2051 /* this is what NT returns */
2052 return WERR_INVALID_ENVIRONMENT;
2055 if (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
2056 version = r->in.version;
2058 status = get_a_printer_driver(p->mem_ctx, &info, 3, r->in.driver,
2059 r->in.architecture, version);
2061 if ( !W_ERROR_IS_OK(status) )
2064 * if the client asked for a specific version,
2065 * or this is something other than Windows NT x86,
2069 if ( (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
2072 /* try for Win2k driver if "Windows NT x86" */
2075 if (!W_ERROR_IS_OK(get_a_printer_driver(p->mem_ctx, &info, 3, r->in.driver,
2078 status = WERR_UNKNOWN_PRINTER_DRIVER;
2083 if ( printer_driver_in_use(&info->info3) ) {
2084 status = WERR_PRINTER_DRIVER_IN_USE;
2089 * we have a couple of cases to consider.
2090 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
2091 * then the delete should fail if **any** files overlap with
2093 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
2094 * non-overlapping files
2095 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
2096 * is set, the do not delete any files
2097 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2100 delete_files = r->in.delete_flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
2102 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
2104 if ( delete_files && printer_driver_files_in_use(info, &info->info3) & (r->in.delete_flags & DPD_DELETE_ALL_FILES) ) {
2105 /* no idea of the correct error here */
2106 status = WERR_ACCESS_DENIED;
2111 /* also check for W32X86/3 if necessary; maybe we already have? */
2113 if ( (version == 2) && ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
2114 if (W_ERROR_IS_OK(get_a_printer_driver(p->mem_ctx, &info_win2k, 3,
2116 r->in.architecture, 3)))
2119 if ( delete_files && printer_driver_files_in_use(info, &info_win2k->info3) & (r->in.delete_flags & DPD_DELETE_ALL_FILES) ) {
2120 /* no idea of the correct error here */
2121 free_a_printer_driver(info_win2k);
2122 status = WERR_ACCESS_DENIED;
2126 /* if we get to here, we now have 2 driver info structures to remove */
2127 /* remove the Win2k driver first*/
2129 status_win2k = delete_printer_driver(
2130 p, &info_win2k->info3, 3, delete_files);
2131 free_a_printer_driver(info_win2k);
2133 /* this should not have failed---if it did, report to client */
2135 if ( !W_ERROR_IS_OK(status_win2k) )
2140 status = delete_printer_driver(p, &info->info3, version, delete_files);
2142 if ( W_ERROR_IS_OK(status) || W_ERROR_IS_OK(status_win2k) )
2145 free_a_printer_driver(info);
2151 /****************************************************************************
2152 Internal routine for removing printerdata
2153 ***************************************************************************/
2155 static WERROR delete_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char *key, const char *value )
2157 return delete_printer_data( printer->info_2, key, value );
2160 /****************************************************************************
2161 Internal routine for storing printerdata
2162 ***************************************************************************/
2164 WERROR set_printer_dataex(NT_PRINTER_INFO_LEVEL *printer,
2165 const char *key, const char *value,
2166 uint32_t type, uint8_t *data, int real_len)
2168 /* the registry objects enforce uniqueness based on value name */
2170 return add_printer_data( printer->info_2, key, value, type, data, real_len );
2173 /********************************************************************
2174 GetPrinterData on a printer server Handle.
2175 ********************************************************************/
2177 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2179 enum winreg_Type *type,
2180 union spoolss_PrinterData *data)
2182 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2184 if (!StrCaseCmp(value, "W3SvcInstalled")) {
2190 if (!StrCaseCmp(value, "BeepEnabled")) {
2196 if (!StrCaseCmp(value, "EventLog")) {
2198 /* formally was 0x1b */
2203 if (!StrCaseCmp(value, "NetPopup")) {
2209 if (!StrCaseCmp(value, "MajorVersion")) {
2212 /* Windows NT 4.0 seems to not allow uploading of drivers
2213 to a server that reports 0x3 as the MajorVersion.
2214 need to investigate more how Win2k gets around this .
2217 if (RA_WINNT == get_remote_arch()) {
2226 if (!StrCaseCmp(value, "MinorVersion")) {
2233 * uint32_t size = 0x114
2234 * uint32_t major = 5
2235 * uint32_t minor = [0|1]
2236 * uint32_t build = [2195|2600]
2237 * extra unicode string = e.g. "Service Pack 3"
2239 if (!StrCaseCmp(value, "OSVersion")) {
2241 enum ndr_err_code ndr_err;
2242 struct spoolss_OSVersion os;
2244 os.major = 5; /* Windows 2000 == 5.0 */
2246 os.build = 2195; /* build */
2247 os.extra_string = ""; /* leave extra string empty */
2249 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, NULL, &os,
2250 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2251 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2252 return WERR_GENERAL_FAILURE;
2256 data->binary = blob;
2262 if (!StrCaseCmp(value, "DefaultSpoolDirectory")) {
2265 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2266 W_ERROR_HAVE_NO_MEMORY(data->string);
2271 if (!StrCaseCmp(value, "Architecture")) {
2274 data->string = talloc_strdup(mem_ctx, "Windows NT x86");
2275 W_ERROR_HAVE_NO_MEMORY(data->string);
2280 if (!StrCaseCmp(value, "DsPresent")) {
2283 /* only show the publish check box if we are a
2284 member of a AD domain */
2286 if (lp_security() == SEC_ADS) {
2294 if (!StrCaseCmp(value, "DNSMachineName")) {
2295 const char *hostname = get_mydnsfullname();
2298 return WERR_BADFILE;
2302 data->string = talloc_strdup(mem_ctx, hostname);
2303 W_ERROR_HAVE_NO_MEMORY(data->string);
2308 return WERR_INVALID_PARAM;
2311 /****************************************************************
2312 _spoolss_GetPrinterData
2313 ****************************************************************/
2315 WERROR _spoolss_GetPrinterData(pipes_struct *p,
2316 struct spoolss_GetPrinterData *r)
2319 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
2320 NT_PRINTER_INFO_LEVEL *printer = NULL;
2324 * Reminder: when it's a string, the length is in BYTES
2325 * even if UNICODE is negociated.
2330 /* in case of problem, return some default values */
2335 DEBUG(4,("_spoolss_GetPrinterData\n"));
2338 DEBUG(2,("_spoolss_GetPrinterData: Invalid handle (%s:%u:%u).\n",
2339 OUR_HANDLE(r->in.handle)));
2340 result = WERR_BADFID;
2344 if (Printer->printer_type == SPLHND_SERVER) {
2345 result = getprinterdata_printer_server(p->mem_ctx,
2350 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
2351 result = WERR_BADFID;
2355 result = get_a_printer(Printer, &printer, 2, lp_servicename(snum));
2356 if (!W_ERROR_IS_OK(result)) {
2360 /* XP sends this and wants to change id value from the PRINTER_INFO_0 */
2362 if (strequal(r->in.value_name, "ChangeId")) {
2363 *r->out.type = REG_DWORD;
2364 r->out.data->value = printer->info_2->changeid;
2367 struct regval_blob *v;
2370 v = get_printer_data(printer->info_2,
2371 SPOOL_PRINTERDATA_KEY,
2374 result = WERR_BADFILE;
2378 *r->out.type = v->type;
2380 blob = data_blob_const(v->data_p, v->size);
2382 result = pull_spoolss_PrinterData(p->mem_ctx, &blob,
2389 /* cleanup & exit */
2392 free_a_printer(&printer, 2);
2395 if (!W_ERROR_IS_OK(result)) {
2399 *r->out.needed = ndr_size_spoolss_PrinterData(r->out.data, *r->out.type, NULL, 0);
2400 *r->out.type = SPOOLSS_BUFFER_OK(*r->out.type, REG_NONE);
2401 r->out.data = SPOOLSS_BUFFER_OK(r->out.data, r->out.data);
2403 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
2406 /*********************************************************
2407 Connect to the client machine.
2408 **********************************************************/
2410 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2411 struct sockaddr_storage *client_ss, const char *remote_machine)
2414 struct cli_state *the_cli;
2415 struct sockaddr_storage rm_addr;
2417 if ( is_zero_addr((struct sockaddr *)client_ss) ) {
2418 if ( !resolve_name( remote_machine, &rm_addr, 0x20, false) ) {
2419 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2423 if (ismyaddr((struct sockaddr *)&rm_addr)) {
2424 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n", remote_machine));
2428 char addr[INET6_ADDRSTRLEN];
2429 rm_addr = *client_ss;
2430 print_sockaddr(addr, sizeof(addr), &rm_addr);
2431 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2435 /* setup the connection */
2437 ret = cli_full_connection( &the_cli, global_myname(), remote_machine,
2438 &rm_addr, 0, "IPC$", "IPC",
2442 0, lp_client_signing(), NULL );
2444 if ( !NT_STATUS_IS_OK( ret ) ) {
2445 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2450 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2451 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2452 cli_shutdown(the_cli);
2457 * Ok - we have an anonymous connection to the IPC$ share.
2458 * Now start the NT Domain stuff :-).
2461 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2462 if (!NT_STATUS_IS_OK(ret)) {
2463 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2464 remote_machine, nt_errstr(ret)));
2465 cli_shutdown(the_cli);
2472 /***************************************************************************
2473 Connect to the client.
2474 ****************************************************************************/
2476 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2477 uint32_t localprinter, uint32_t type,
2478 struct policy_handle *handle,
2479 struct sockaddr_storage *client_ss)
2485 * If it's the first connection, contact the client
2486 * and connect to the IPC$ share anonymously
2488 if (smb_connections==0) {
2489 fstring unix_printer;
2491 fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */
2493 if ( !spoolss_connect_to_client( ¬ify_cli_pipe, client_ss, unix_printer ))
2496 messaging_register(smbd_messaging_context(), NULL,
2497 MSG_PRINTER_NOTIFY2,
2498 receive_notify2_message_list);
2499 /* Tell the connections db we're now interested in printer
2500 * notify messages. */
2501 register_message_flags(true, FLAG_MSG_PRINT_NOTIFY);
2505 * Tell the specific printing tdb we want messages for this printer
2506 * by registering our PID.
2509 if (!print_notify_register_pid(snum))
2510 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", printer ));
2514 status = rpccli_spoolss_ReplyOpenPrinter(notify_cli_pipe, talloc_tos(),
2522 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
2523 DEBUG(5,("srv_spoolss_reply_open_printer: Client RPC returned [%s]\n",
2524 win_errstr(result)));
2526 return (W_ERROR_IS_OK(result));
2529 /****************************************************************
2530 ****************************************************************/
2532 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2533 const struct spoolss_NotifyOption *r)
2535 struct spoolss_NotifyOption *option;
2542 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2549 if (!option->count) {
2553 option->types = talloc_zero_array(option,
2554 struct spoolss_NotifyOptionType, option->count);
2555 if (!option->types) {
2556 talloc_free(option);
2560 for (i=0; i < option->count; i++) {
2561 option->types[i] = r->types[i];
2563 if (option->types[i].count) {
2564 option->types[i].fields = talloc_zero_array(option,
2565 union spoolss_Field, option->types[i].count);
2566 if (!option->types[i].fields) {
2567 talloc_free(option);
2570 for (k=0; k<option->types[i].count; k++) {
2571 option->types[i].fields[k] =
2572 r->types[i].fields[k];
2580 /****************************************************************
2581 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2583 * before replying OK: status=0 a rpc call is made to the workstation
2584 * asking ReplyOpenPrinter
2586 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2587 * called from api_spoolss_rffpcnex
2588 ****************************************************************/
2590 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(pipes_struct *p,
2591 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2594 struct spoolss_NotifyOption *option = r->in.notify_options;
2595 struct sockaddr_storage client_ss;
2597 /* store the notify value in the printer struct */
2599 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
2602 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2603 "Invalid handle (%s:%u:%u).\n",
2604 OUR_HANDLE(r->in.handle)));
2608 Printer->notify.flags = r->in.flags;
2609 Printer->notify.options = r->in.options;
2610 Printer->notify.printerlocal = r->in.printer_local;
2612 TALLOC_FREE(Printer->notify.option);
2613 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2615 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2617 /* Connect to the client machine and send a ReplyOpenPrinter */
2619 if ( Printer->printer_type == SPLHND_SERVER)
2621 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2622 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2625 if (!interpret_string_addr(&client_ss, p->client_address,
2627 return WERR_SERVER_UNAVAILABLE;
2630 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2631 Printer->notify.printerlocal, 1,
2632 &Printer->notify.client_hnd, &client_ss))
2633 return WERR_SERVER_UNAVAILABLE;
2635 Printer->notify.client_connected = true;
2640 /*******************************************************************
2641 * fill a notify_info_data with the servername
2642 ********************************************************************/
2644 void spoolss_notify_server_name(int snum,
2645 struct spoolss_Notify *data,
2646 print_queue_struct *queue,
2647 NT_PRINTER_INFO_LEVEL *printer,
2648 TALLOC_CTX *mem_ctx)
2650 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->servername);
2653 /*******************************************************************
2654 * fill a notify_info_data with the printername (not including the servername).
2655 ********************************************************************/
2657 void spoolss_notify_printer_name(int snum,
2658 struct spoolss_Notify *data,
2659 print_queue_struct *queue,
2660 NT_PRINTER_INFO_LEVEL *printer,
2661 TALLOC_CTX *mem_ctx)
2663 /* the notify name should not contain the \\server\ part */
2664 char *p = strrchr(printer->info_2->printername, '\\');
2667 p = printer->info_2->printername;
2672 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2675 /*******************************************************************
2676 * fill a notify_info_data with the servicename
2677 ********************************************************************/
2679 void spoolss_notify_share_name(int snum,
2680 struct spoolss_Notify *data,
2681 print_queue_struct *queue,
2682 NT_PRINTER_INFO_LEVEL *printer,
2683 TALLOC_CTX *mem_ctx)
2685 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
2688 /*******************************************************************
2689 * fill a notify_info_data with the port name
2690 ********************************************************************/
2692 void spoolss_notify_port_name(int snum,
2693 struct spoolss_Notify *data,
2694 print_queue_struct *queue,
2695 NT_PRINTER_INFO_LEVEL *printer,
2696 TALLOC_CTX *mem_ctx)
2698 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->portname);
2701 /*******************************************************************
2702 * fill a notify_info_data with the printername
2703 * but it doesn't exist, have to see what to do
2704 ********************************************************************/
2706 void spoolss_notify_driver_name(int snum,
2707 struct spoolss_Notify *data,
2708 print_queue_struct *queue,
2709 NT_PRINTER_INFO_LEVEL *printer,
2710 TALLOC_CTX *mem_ctx)
2712 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->drivername);
2715 /*******************************************************************
2716 * fill a notify_info_data with the comment
2717 ********************************************************************/
2719 void spoolss_notify_comment(int snum,
2720 struct spoolss_Notify *data,
2721 print_queue_struct *queue,
2722 NT_PRINTER_INFO_LEVEL *printer,
2723 TALLOC_CTX *mem_ctx)
2727 if (*printer->info_2->comment == '\0') {
2728 p = lp_comment(snum);
2730 p = printer->info_2->comment;
2733 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->comment);
2736 /*******************************************************************
2737 * fill a notify_info_data with the comment
2738 * location = "Room 1, floor 2, building 3"
2739 ********************************************************************/
2741 void spoolss_notify_location(int snum,
2742 struct spoolss_Notify *data,
2743 print_queue_struct *queue,
2744 NT_PRINTER_INFO_LEVEL *printer,
2745 TALLOC_CTX *mem_ctx)
2747 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->location);
2750 /*******************************************************************
2751 * fill a notify_info_data with the device mode
2752 * jfm:xxxx don't to it for know but that's a real problem !!!
2753 ********************************************************************/
2755 static void spoolss_notify_devmode(int snum,
2756 struct spoolss_Notify *data,
2757 print_queue_struct *queue,
2758 NT_PRINTER_INFO_LEVEL *printer,
2759 TALLOC_CTX *mem_ctx)
2761 /* for a dummy implementation we have to zero the fields */
2762 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2765 /*******************************************************************
2766 * fill a notify_info_data with the separator file name
2767 ********************************************************************/
2769 void spoolss_notify_sepfile(int snum,
2770 struct spoolss_Notify *data,
2771 print_queue_struct *queue,
2772 NT_PRINTER_INFO_LEVEL *printer,
2773 TALLOC_CTX *mem_ctx)
2775 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->sepfile);
2778 /*******************************************************************
2779 * fill a notify_info_data with the print processor
2780 * jfm:xxxx return always winprint to indicate we don't do anything to it
2781 ********************************************************************/
2783 void spoolss_notify_print_processor(int snum,
2784 struct spoolss_Notify *data,
2785 print_queue_struct *queue,
2786 NT_PRINTER_INFO_LEVEL *printer,
2787 TALLOC_CTX *mem_ctx)
2789 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->printprocessor);
2792 /*******************************************************************
2793 * fill a notify_info_data with the print processor options
2794 * jfm:xxxx send an empty string
2795 ********************************************************************/
2797 void spoolss_notify_parameters(int snum,
2798 struct spoolss_Notify *data,
2799 print_queue_struct *queue,
2800 NT_PRINTER_INFO_LEVEL *printer,
2801 TALLOC_CTX *mem_ctx)
2803 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->parameters);
2806 /*******************************************************************
2807 * fill a notify_info_data with the data type
2808 * jfm:xxxx always send RAW as data type
2809 ********************************************************************/
2811 void spoolss_notify_datatype(int snum,
2812 struct spoolss_Notify *data,
2813 print_queue_struct *queue,
2814 NT_PRINTER_INFO_LEVEL *printer,
2815 TALLOC_CTX *mem_ctx)
2817 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->datatype);
2820 /*******************************************************************
2821 * fill a notify_info_data with the security descriptor
2822 * jfm:xxxx send an null pointer to say no security desc
2823 * have to implement security before !
2824 ********************************************************************/
2826 static void spoolss_notify_security_desc(int snum,
2827 struct spoolss_Notify *data,
2828 print_queue_struct *queue,
2829 NT_PRINTER_INFO_LEVEL *printer,
2830 TALLOC_CTX *mem_ctx)
2832 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data,
2833 printer->info_2->secdesc_buf->sd_size,
2834 printer->info_2->secdesc_buf->sd);
2837 /*******************************************************************
2838 * fill a notify_info_data with the attributes
2839 * jfm:xxxx a samba printer is always shared
2840 ********************************************************************/
2842 void spoolss_notify_attributes(int snum,
2843 struct spoolss_Notify *data,
2844 print_queue_struct *queue,
2845 NT_PRINTER_INFO_LEVEL *printer,
2846 TALLOC_CTX *mem_ctx)
2848 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->attributes);
2851 /*******************************************************************
2852 * fill a notify_info_data with the priority
2853 ********************************************************************/
2855 static void spoolss_notify_priority(int snum,
2856 struct spoolss_Notify *data,
2857 print_queue_struct *queue,
2858 NT_PRINTER_INFO_LEVEL *printer,
2859 TALLOC_CTX *mem_ctx)
2861 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->priority);
2864 /*******************************************************************
2865 * fill a notify_info_data with the default priority
2866 ********************************************************************/
2868 static void spoolss_notify_default_priority(int snum,
2869 struct spoolss_Notify *data,
2870 print_queue_struct *queue,
2871 NT_PRINTER_INFO_LEVEL *printer,
2872 TALLOC_CTX *mem_ctx)
2874 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->default_priority);
2877 /*******************************************************************
2878 * fill a notify_info_data with the start time
2879 ********************************************************************/
2881 static void spoolss_notify_start_time(int snum,
2882 struct spoolss_Notify *data,
2883 print_queue_struct *queue,
2884 NT_PRINTER_INFO_LEVEL *printer,
2885 TALLOC_CTX *mem_ctx)
2887 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->starttime);
2890 /*******************************************************************
2891 * fill a notify_info_data with the until time
2892 ********************************************************************/
2894 static void spoolss_notify_until_time(int snum,
2895 struct spoolss_Notify *data,
2896 print_queue_struct *queue,
2897 NT_PRINTER_INFO_LEVEL *printer,
2898 TALLOC_CTX *mem_ctx)
2900 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->untiltime);
2903 /*******************************************************************
2904 * fill a notify_info_data with the status
2905 ********************************************************************/
2907 static void spoolss_notify_status(int snum,
2908 struct spoolss_Notify *data,
2909 print_queue_struct *queue,
2910 NT_PRINTER_INFO_LEVEL *printer,
2911 TALLOC_CTX *mem_ctx)
2913 print_status_struct status;
2915 print_queue_length(snum, &status);
2916 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
2919 /*******************************************************************
2920 * fill a notify_info_data with the number of jobs queued
2921 ********************************************************************/
2923 void spoolss_notify_cjobs(int snum,
2924 struct spoolss_Notify *data,
2925 print_queue_struct *queue,
2926 NT_PRINTER_INFO_LEVEL *printer,
2927 TALLOC_CTX *mem_ctx)
2929 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, print_queue_length(snum, NULL));
2932 /*******************************************************************
2933 * fill a notify_info_data with the average ppm
2934 ********************************************************************/
2936 static void spoolss_notify_average_ppm(int snum,
2937 struct spoolss_Notify *data,
2938 print_queue_struct *queue,
2939 NT_PRINTER_INFO_LEVEL *printer,
2940 TALLOC_CTX *mem_ctx)
2942 /* always respond 8 pages per minutes */
2943 /* a little hard ! */
2944 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->averageppm);
2947 /*******************************************************************
2948 * fill a notify_info_data with username
2949 ********************************************************************/
2951 static void spoolss_notify_username(int snum,
2952 struct spoolss_Notify *data,
2953 print_queue_struct *queue,
2954 NT_PRINTER_INFO_LEVEL *printer,
2955 TALLOC_CTX *mem_ctx)
2957 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
2960 /*******************************************************************
2961 * fill a notify_info_data with job status
2962 ********************************************************************/
2964 static void spoolss_notify_job_status(int snum,
2965 struct spoolss_Notify *data,
2966 print_queue_struct *queue,
2967 NT_PRINTER_INFO_LEVEL *printer,
2968 TALLOC_CTX *mem_ctx)
2970 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
2973 /*******************************************************************
2974 * fill a notify_info_data with job name
2975 ********************************************************************/
2977 static void spoolss_notify_job_name(int snum,
2978 struct spoolss_Notify *data,
2979 print_queue_struct *queue,
2980 NT_PRINTER_INFO_LEVEL *printer,
2981 TALLOC_CTX *mem_ctx)
2983 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
2986 /*******************************************************************
2987 * fill a notify_info_data with job status
2988 ********************************************************************/
2990 static void spoolss_notify_job_status_string(int snum,
2991 struct spoolss_Notify *data,
2992 print_queue_struct *queue,
2993 NT_PRINTER_INFO_LEVEL *printer,
2994 TALLOC_CTX *mem_ctx)
2997 * Now we're returning job status codes we just return a "" here. JRA.
3002 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3005 switch (queue->status) {
3010 p = ""; /* NT provides the paused string */
3019 #endif /* NO LONGER NEEDED. */
3021 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
3024 /*******************************************************************
3025 * fill a notify_info_data with job time
3026 ********************************************************************/
3028 static void spoolss_notify_job_time(int snum,
3029 struct spoolss_Notify *data,
3030 print_queue_struct *queue,
3031 NT_PRINTER_INFO_LEVEL *printer,
3032 TALLOC_CTX *mem_ctx)
3034 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3037 /*******************************************************************
3038 * fill a notify_info_data with job size
3039 ********************************************************************/
3041 static void spoolss_notify_job_size(int snum,
3042 struct spoolss_Notify *data,
3043 print_queue_struct *queue,
3044 NT_PRINTER_INFO_LEVEL *printer,
3045 TALLOC_CTX *mem_ctx)
3047 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
3050 /*******************************************************************
3051 * fill a notify_info_data with page info
3052 ********************************************************************/
3053 static void spoolss_notify_total_pages(int snum,
3054 struct spoolss_Notify *data,
3055 print_queue_struct *queue,
3056 NT_PRINTER_INFO_LEVEL *printer,
3057 TALLOC_CTX *mem_ctx)
3059 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
3062 /*******************************************************************
3063 * fill a notify_info_data with pages printed info.
3064 ********************************************************************/
3065 static void spoolss_notify_pages_printed(int snum,
3066 struct spoolss_Notify *data,
3067 print_queue_struct *queue,
3068 NT_PRINTER_INFO_LEVEL *printer,
3069 TALLOC_CTX *mem_ctx)
3071 /* Add code when back-end tracks this */
3072 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3075 /*******************************************************************
3076 Fill a notify_info_data with job position.
3077 ********************************************************************/
3079 static void spoolss_notify_job_position(int snum,
3080 struct spoolss_Notify *data,
3081 print_queue_struct *queue,
3082 NT_PRINTER_INFO_LEVEL *printer,
3083 TALLOC_CTX *mem_ctx)
3085 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
3088 /*******************************************************************
3089 Fill a notify_info_data with submitted time.
3090 ********************************************************************/
3092 static void spoolss_notify_submitted_time(int snum,
3093 struct spoolss_Notify *data,
3094 print_queue_struct *queue,
3095 NT_PRINTER_INFO_LEVEL *printer,
3096 TALLOC_CTX *mem_ctx)
3098 data->data.string.string = NULL;
3099 data->data.string.size = 0;
3101 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
3102 &data->data.string.string,
3103 &data->data.string.size);
3107 struct s_notify_info_data_table
3109 enum spoolss_NotifyType type;
3112 enum spoolss_NotifyTable variable_type;
3113 void (*fn) (int snum, struct spoolss_Notify *data,
3114 print_queue_struct *queue,
3115 NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx);
3118 /* A table describing the various print notification constants and
3119 whether the notification data is a pointer to a variable sized
3120 buffer, a one value uint32_t or a two value uint32_t. */
3122 static const struct s_notify_info_data_table notify_info_data_table[] =
3124 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3125 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3126 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
3127 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3128 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3129 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
3130 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
3131 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3132 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
3133 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3134 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3135 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3136 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
3137 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
3138 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3139 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
3140 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3141 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3142 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
3143 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
3144 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
3145 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
3146 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
3147 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3148 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
3149 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3150 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3151 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3152 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3153 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3154 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3155 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3156 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3157 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3158 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3159 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3160 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
3161 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
3162 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
3163 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
3164 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3165 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
3166 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
3167 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3168 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3169 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
3170 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
3171 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
3172 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
3175 /*******************************************************************
3176 Return the variable_type of info_data structure.
3177 ********************************************************************/
3179 static uint32_t variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3184 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3185 if ( (notify_info_data_table[i].type == type) &&
3186 (notify_info_data_table[i].field == field) ) {
3187 return notify_info_data_table[i].variable_type;
3191 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3196 /****************************************************************************
3197 ****************************************************************************/
3199 static bool search_notify(enum spoolss_NotifyType type,
3205 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3206 if (notify_info_data_table[i].type == type &&
3207 notify_info_data_table[i].field == field &&
3208 notify_info_data_table[i].fn != NULL) {
3217 /****************************************************************************
3218 ****************************************************************************/
3220 void construct_info_data(struct spoolss_Notify *info_data,
3221 enum spoolss_NotifyType type,
3225 info_data->type = type;
3226 info_data->field.field = field;
3227 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3228 info_data->job_id = id;
3231 /*******************************************************************
3233 * fill a notify_info struct with info asked
3235 ********************************************************************/
3237 static bool construct_notify_printer_info(Printer_entry *print_hnd,
3238 struct spoolss_NotifyInfo *info,
3240 const struct spoolss_NotifyOptionType *option_type,
3242 TALLOC_CTX *mem_ctx)
3245 enum spoolss_NotifyType type;
3248 struct spoolss_Notify *current_data;
3249 NT_PRINTER_INFO_LEVEL *printer = NULL;
3250 print_queue_struct *queue=NULL;
3252 type = option_type->type;
3254 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3255 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3256 option_type->count, lp_servicename(snum)));
3258 if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &printer, 2, lp_const_servicename(snum))))
3261 for(field_num=0; field_num < option_type->count; field_num++) {
3262 field = option_type->fields[field_num].field;
3264 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3266 if (!search_notify(type, field, &j) )
3269 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3270 struct spoolss_Notify,
3272 if (info->notifies == NULL) {
3273 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3274 free_a_printer(&printer, 2);
3278 current_data = &info->notifies[info->count];
3280 construct_info_data(current_data, type, field, id);
3282 DEBUG(10,("construct_notify_printer_info: calling [%s] snum=%d printername=[%s])\n",
3283 notify_info_data_table[j].name, snum, printer->info_2->printername ));
3285 notify_info_data_table[j].fn(snum, current_data, queue,
3291 free_a_printer(&printer, 2);
3295 /*******************************************************************
3297 * fill a notify_info struct with info asked
3299 ********************************************************************/
3301 static bool construct_notify_jobs_info(print_queue_struct *queue,
3302 struct spoolss_NotifyInfo *info,
3303 NT_PRINTER_INFO_LEVEL *printer,
3305 const struct spoolss_NotifyOptionType *option_type,
3307 TALLOC_CTX *mem_ctx)
3310 enum spoolss_NotifyType type;
3312 struct spoolss_Notify *current_data;
3314 DEBUG(4,("construct_notify_jobs_info\n"));
3316 type = option_type->type;
3318 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3319 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3320 option_type->count));
3322 for(field_num=0; field_num<option_type->count; field_num++) {
3323 field = option_type->fields[field_num].field;
3325 if (!search_notify(type, field, &j) )
3328 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3329 struct spoolss_Notify,
3331 if (info->notifies == NULL) {
3332 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3336 current_data=&(info->notifies[info->count]);
3338 construct_info_data(current_data, type, field, id);
3339 notify_info_data_table[j].fn(snum, current_data, queue,
3348 * JFM: The enumeration is not that simple, it's even non obvious.
3350 * let's take an example: I want to monitor the PRINTER SERVER for
3351 * the printer's name and the number of jobs currently queued.
3352 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3353 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3355 * I have 3 printers on the back of my server.
3357 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3360 * 1 printer 1 name 1
3361 * 2 printer 1 cjob 1
3362 * 3 printer 2 name 2
3363 * 4 printer 2 cjob 2
3364 * 5 printer 3 name 3
3365 * 6 printer 3 name 3
3367 * that's the print server case, the printer case is even worse.
3370 /*******************************************************************
3372 * enumerate all printers on the printserver
3373 * fill a notify_info struct with info asked
3375 ********************************************************************/
3377 static WERROR printserver_notify_info(pipes_struct *p,
3378 struct policy_handle *hnd,
3379 struct spoolss_NotifyInfo *info,
3380 TALLOC_CTX *mem_ctx)
3383 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3384 int n_services=lp_numservices();
3386 struct spoolss_NotifyOption *option;
3387 struct spoolss_NotifyOptionType option_type;
3389 DEBUG(4,("printserver_notify_info\n"));
3394 option = Printer->notify.option;
3397 info->notifies = NULL;
3400 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3401 sending a ffpcn() request first */
3406 for (i=0; i<option->count; i++) {
3407 option_type = option->types[i];
3409 if (option_type.type != PRINTER_NOTIFY_TYPE)
3412 for (snum=0; snum<n_services; snum++)
3414 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
3415 construct_notify_printer_info ( Printer, info, snum, &option_type, snum, mem_ctx );
3421 * Debugging information, don't delete.
3424 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3425 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3426 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3428 for (i=0; i<info->count; i++) {
3429 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3430 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3431 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3438 /*******************************************************************
3440 * fill a notify_info struct with info asked
3442 ********************************************************************/
3444 static WERROR printer_notify_info(pipes_struct *p, struct policy_handle *hnd,
3445 struct spoolss_NotifyInfo *info,
3446 TALLOC_CTX *mem_ctx)
3449 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3452 struct spoolss_NotifyOption *option;
3453 struct spoolss_NotifyOptionType option_type;
3455 print_queue_struct *queue=NULL;
3456 print_status_struct status;
3458 DEBUG(4,("printer_notify_info\n"));
3463 option = Printer->notify.option;
3467 info->notifies = NULL;
3470 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3471 sending a ffpcn() request first */
3476 get_printer_snum(p, hnd, &snum, NULL);
3478 for (i=0; i<option->count; i++) {
3479 option_type = option->types[i];
3481 switch (option_type.type) {
3482 case PRINTER_NOTIFY_TYPE:
3483 if(construct_notify_printer_info(Printer, info, snum,
3489 case JOB_NOTIFY_TYPE: {
3490 NT_PRINTER_INFO_LEVEL *printer = NULL;
3492 count = print_queue_status(snum, &queue, &status);
3494 if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum))))
3497 for (j=0; j<count; j++) {
3498 construct_notify_jobs_info(&queue[j], info,
3505 free_a_printer(&printer, 2);
3515 * Debugging information, don't delete.
3518 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3519 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3520 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3522 for (i=0; i<info->count; i++) {
3523 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3524 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3525 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3531 /****************************************************************
3532 _spoolss_RouterRefreshPrinterChangeNotify
3533 ****************************************************************/
3535 WERROR _spoolss_RouterRefreshPrinterChangeNotify(pipes_struct *p,
3536 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3538 struct spoolss_NotifyInfo *info;
3540 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
3541 WERROR result = WERR_BADFID;
3543 /* we always have a spoolss_NotifyInfo struct */
3544 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3546 result = WERR_NOMEM;
3550 *r->out.info = info;
3553 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3554 "Invalid handle (%s:%u:%u).\n",
3555 OUR_HANDLE(r->in.handle)));
3559 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3562 * We are now using the change value, and
3563 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3564 * I don't have a global notification system, I'm sending back all the
3565 * informations even when _NOTHING_ has changed.
3568 /* We need to keep track of the change value to send back in
3569 RRPCN replies otherwise our updates are ignored. */
3571 Printer->notify.fnpcn = true;
3573 if (Printer->notify.client_connected) {
3574 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3575 "Saving change value in request [%x]\n",
3577 Printer->notify.change = r->in.change_low;
3580 /* just ignore the spoolss_NotifyOption */
3582 switch (Printer->printer_type) {
3584 result = printserver_notify_info(p, r->in.handle,
3588 case SPLHND_PRINTER:
3589 result = printer_notify_info(p, r->in.handle,
3594 Printer->notify.fnpcn = false;
3600 /********************************************************************
3601 * construct_printer_info_0
3602 * fill a printer_info_0 struct
3603 ********************************************************************/
3605 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3606 const NT_PRINTER_INFO_LEVEL *ntprinter,
3607 struct spoolss_PrinterInfo0 *r,
3611 counter_printer_0 *session_counter;
3613 print_status_struct status;
3615 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
3616 W_ERROR_HAVE_NO_MEMORY(r->printername);
3618 r->servername = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
3619 W_ERROR_HAVE_NO_MEMORY(r->servername);
3621 count = print_queue_length(snum, &status);
3623 /* check if we already have a counter for this printer */
3624 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3625 if (session_counter->snum == snum)
3629 /* it's the first time, add it to the list */
3630 if (session_counter == NULL) {
3631 session_counter = SMB_MALLOC_P(counter_printer_0);
3632 W_ERROR_HAVE_NO_MEMORY(session_counter);
3633 ZERO_STRUCTP(session_counter);
3634 session_counter->snum = snum;
3635 session_counter->counter = 0;
3636 DLIST_ADD(counter_list, session_counter);
3640 session_counter->counter++;
3646 setuptime = (time_t)ntprinter->info_2->setuptime;
3648 init_systemtime(&r->time, gmtime(&setuptime));
3651 * the global_counter should be stored in a TDB as it's common to all the clients
3652 * and should be zeroed on samba startup
3654 r->global_counter = session_counter->counter;
3656 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3657 r->version = 0x0005; /* NT 5 */
3658 r->free_build = 0x0893; /* build 2195 */
3660 r->max_spooling = 0;
3661 r->session_counter = session_counter->counter;
3662 r->num_error_out_of_paper = 0x0;
3663 r->num_error_not_ready = 0x0; /* number of print failure */
3665 r->number_of_processors = 0x1;
3666 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3667 r->high_part_total_bytes = 0x0;
3668 r->change_id = ntprinter->info_2->changeid; /* ChangeID in milliseconds*/
3669 r->last_error = WERR_OK;
3670 r->status = nt_printq_status(status.status);
3671 r->enumerate_network_printers = 0x0;
3672 r->c_setprinter = get_c_setprinter(); /* monotonically increasing sum of delta printer counts */
3673 r->processor_architecture = 0x0;
3674 r->processor_level = 0x6; /* 6 ???*/
3682 /****************************************************************************
3683 Convert an NT_DEVICEMODE to a spoolss_DeviceMode structure. Both pointers
3684 should be valid upon entry
3685 ****************************************************************************/
3687 static WERROR convert_nt_devicemode(TALLOC_CTX *mem_ctx,
3688 struct spoolss_DeviceMode *r,
3689 const NT_DEVICEMODE *ntdevmode)
3691 if (!r || !ntdevmode) {
3692 return WERR_INVALID_PARAM;
3695 r->devicename = talloc_strdup(mem_ctx, ntdevmode->devicename);
3696 W_ERROR_HAVE_NO_MEMORY(r->devicename);
3698 r->specversion = ntdevmode->specversion;
3699 r->driverversion = ntdevmode->driverversion;
3700 r->size = ntdevmode->size;
3701 r->__driverextra_length = ntdevmode->driverextra;
3702 r->fields = ntdevmode->fields;
3704 r->orientation = ntdevmode->orientation;
3705 r->papersize = ntdevmode->papersize;
3706 r->paperlength = ntdevmode->paperlength;
3707 r->paperwidth = ntdevmode->paperwidth;
3708 r->scale = ntdevmode->scale;
3709 r->copies = ntdevmode->copies;
3710 r->defaultsource = ntdevmode->defaultsource;
3711 r->printquality = ntdevmode->printquality;
3712 r->color = ntdevmode->color;
3713 r->duplex = ntdevmode->duplex;
3714 r->yresolution = ntdevmode->yresolution;
3715 r->ttoption = ntdevmode->ttoption;
3716 r->collate = ntdevmode->collate;
3718 r->formname = talloc_strdup(mem_ctx, ntdevmode->formname);
3719 W_ERROR_HAVE_NO_MEMORY(r->formname);
3721 /* all 0 below are values that have not been set in the old parsing/copy
3722 * function, maybe they should... - gd */
3728 r->displayflags = 0;
3729 r->displayfrequency = 0;
3730 r->icmmethod = ntdevmode->icmmethod;
3731 r->icmintent = ntdevmode->icmintent;
3732 r->mediatype = ntdevmode->mediatype;
3733 r->dithertype = ntdevmode->dithertype;
3736 r->panningwidth = 0;
3737 r->panningheight = 0;
3739 if (ntdevmode->nt_dev_private != NULL) {
3740 r->driverextra_data = data_blob_talloc(mem_ctx,
3741 ntdevmode->nt_dev_private,
3742 ntdevmode->driverextra);
3743 W_ERROR_HAVE_NO_MEMORY(r->driverextra_data.data);
3750 /****************************************************************************
3751 Create a spoolss_DeviceMode struct. Returns talloced memory.
3752 ****************************************************************************/
3754 struct spoolss_DeviceMode *construct_dev_mode(TALLOC_CTX *mem_ctx,
3755 const char *servicename)
3758 NT_PRINTER_INFO_LEVEL *printer = NULL;
3759 struct spoolss_DeviceMode *devmode = NULL;
3761 DEBUG(7,("construct_dev_mode\n"));
3763 DEBUGADD(8,("getting printer characteristics\n"));
3765 if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, servicename)))
3768 if (!printer->info_2->devmode) {
3769 DEBUG(5, ("BONG! There was no device mode!\n"));
3773 devmode = TALLOC_ZERO_P(mem_ctx, struct spoolss_DeviceMode);
3775 DEBUG(2,("construct_dev_mode: talloc fail.\n"));
3779 DEBUGADD(8,("loading DEVICEMODE\n"));
3781 result = convert_nt_devicemode(mem_ctx, devmode, printer->info_2->devmode);
3782 if (!W_ERROR_IS_OK(result)) {
3783 TALLOC_FREE(devmode);
3787 free_a_printer(&printer,2);
3792 /********************************************************************
3793 * construct_printer_info1
3794 * fill a spoolss_PrinterInfo1 struct
3795 ********************************************************************/
3797 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
3798 const NT_PRINTER_INFO_LEVEL *ntprinter,
3800 struct spoolss_PrinterInfo1 *r,
3805 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
3806 ntprinter->info_2->printername,
3807 ntprinter->info_2->drivername,
3808 ntprinter->info_2->location);
3809 W_ERROR_HAVE_NO_MEMORY(r->description);
3811 if (*ntprinter->info_2->comment == '\0') {
3812 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3814 r->comment = talloc_strdup(mem_ctx, ntprinter->info_2->comment); /* saved comment */
3816 W_ERROR_HAVE_NO_MEMORY(r->comment);
3818 r->name = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
3819 W_ERROR_HAVE_NO_MEMORY(r->name);
3824 /********************************************************************
3825 * construct_printer_info2
3826 * fill a spoolss_PrinterInfo2 struct
3827 ********************************************************************/
3829 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
3830 const NT_PRINTER_INFO_LEVEL *ntprinter,
3831 struct spoolss_PrinterInfo2 *r,
3836 print_status_struct status;
3838 count = print_queue_length(snum, &status);
3840 r->servername = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
3841 W_ERROR_HAVE_NO_MEMORY(r->servername);
3842 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
3843 W_ERROR_HAVE_NO_MEMORY(r->printername);
3844 r->sharename = talloc_strdup(mem_ctx, lp_servicename(snum));
3845 W_ERROR_HAVE_NO_MEMORY(r->sharename);
3846 r->portname = talloc_strdup(mem_ctx, ntprinter->info_2->portname);
3847 W_ERROR_HAVE_NO_MEMORY(r->portname);
3848 r->drivername = talloc_strdup(mem_ctx, ntprinter->info_2->drivername);
3849 W_ERROR_HAVE_NO_MEMORY(r->drivername);
3851 if (*ntprinter->info_2->comment == '\0') {
3852 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3854 r->comment = talloc_strdup(mem_ctx, ntprinter->info_2->comment);
3856 W_ERROR_HAVE_NO_MEMORY(r->comment);
3858 r->location = talloc_strdup(mem_ctx, ntprinter->info_2->location);
3859 W_ERROR_HAVE_NO_MEMORY(r->location);
3860 r->sepfile = talloc_strdup(mem_ctx, ntprinter->info_2->sepfile);
3861 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
3862 r->printprocessor = talloc_strdup(mem_ctx, ntprinter->info_2->printprocessor);
3863 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
3864 r->datatype = talloc_strdup(mem_ctx, ntprinter->info_2->datatype);
3865 W_ERROR_HAVE_NO_MEMORY(r->datatype);
3866 r->parameters = talloc_strdup(mem_ctx, ntprinter->info_2->parameters);
3867 W_ERROR_HAVE_NO_MEMORY(r->parameters);
3869 r->attributes = ntprinter->info_2->attributes;
3871 r->priority = ntprinter->info_2->priority;
3872 r->defaultpriority = ntprinter->info_2->default_priority;
3873 r->starttime = ntprinter->info_2->starttime;
3874 r->untiltime = ntprinter->info_2->untiltime;
3875 r->status = nt_printq_status(status.status);
3877 r->averageppm = ntprinter->info_2->averageppm;
3879 r->devmode = construct_dev_mode(mem_ctx, lp_const_servicename(snum));
3881 DEBUG(8,("Returning NULL Devicemode!\n"));
3886 if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->sd_size != 0) {
3887 /* don't use talloc_steal() here unless you do a deep steal of all
3888 the SEC_DESC members */
3890 r->secdesc = dup_sec_desc(mem_ctx, ntprinter->info_2->secdesc_buf->sd);
3896 /********************************************************************
3897 * construct_printer_info3
3898 * fill a spoolss_PrinterInfo3 struct
3899 ********************************************************************/
3901 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
3902 const NT_PRINTER_INFO_LEVEL *ntprinter,
3903 struct spoolss_PrinterInfo3 *r,
3906 /* These are the components of the SD we are returning. */
3908 if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->sd_size != 0) {
3909 /* don't use talloc_steal() here unless you do a deep steal of all
3910 the SEC_DESC members */
3912 r->secdesc = dup_sec_desc(mem_ctx,
3913 ntprinter->info_2->secdesc_buf->sd);
3914 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
3920 /********************************************************************
3921 * construct_printer_info4
3922 * fill a spoolss_PrinterInfo4 struct
3923 ********************************************************************/
3925 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
3926 const NT_PRINTER_INFO_LEVEL *ntprinter,
3927 struct spoolss_PrinterInfo4 *r,
3930 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
3931 W_ERROR_HAVE_NO_MEMORY(r->printername);
3932 r->servername = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
3933 W_ERROR_HAVE_NO_MEMORY(r->servername);
3935 r->attributes = ntprinter->info_2->attributes;
3940 /********************************************************************
3941 * construct_printer_info5
3942 * fill a spoolss_PrinterInfo5 struct
3943 ********************************************************************/
3945 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
3946 const NT_PRINTER_INFO_LEVEL *ntprinter,
3947 struct spoolss_PrinterInfo5 *r,
3950 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
3951 W_ERROR_HAVE_NO_MEMORY(r->printername);
3952 r->portname = talloc_strdup(mem_ctx, ntprinter->info_2->portname);
3953 W_ERROR_HAVE_NO_MEMORY(r->portname);
3955 r->attributes = ntprinter->info_2->attributes;
3957 /* these two are not used by NT+ according to MSDN */
3959 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
3960 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
3965 /********************************************************************
3966 * construct_printer_info_6
3967 * fill a spoolss_PrinterInfo6 struct
3968 ********************************************************************/
3970 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
3971 const NT_PRINTER_INFO_LEVEL *ntprinter,
3972 struct spoolss_PrinterInfo6 *r,
3976 print_status_struct status;
3978 count = print_queue_length(snum, &status);
3980 r->status = nt_printq_status(status.status);
3985 /********************************************************************
3986 * construct_printer_info7
3987 * fill a spoolss_PrinterInfo7 struct
3988 ********************************************************************/
3990 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
3991 Printer_entry *print_hnd,
3992 struct spoolss_PrinterInfo7 *r,
3997 if (is_printer_published(print_hnd, snum, &guid)) {
3998 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
3999 r->action = DSPRINT_PUBLISH;
4001 r->guid = talloc_strdup(mem_ctx, "");
4002 r->action = DSPRINT_UNPUBLISH;
4004 W_ERROR_HAVE_NO_MEMORY(r->guid);
4009 /********************************************************************
4010 * construct_printer_info8
4011 * fill a spoolss_PrinterInfo8 struct
4012 ********************************************************************/
4014 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
4015 const NT_PRINTER_INFO_LEVEL *ntprinter,
4016 struct spoolss_DeviceModeInfo *r,
4019 struct spoolss_DeviceMode *devmode;
4022 if (!ntprinter->info_2->devmode) {
4027 devmode = TALLOC_ZERO_P(mem_ctx, struct spoolss_DeviceMode);
4028 W_ERROR_HAVE_NO_MEMORY(devmode);
4030 result = convert_nt_devicemode(mem_ctx, devmode, ntprinter->info_2->devmode);
4031 if (!W_ERROR_IS_OK(result)) {
4032 TALLOC_FREE(devmode);
4036 r->devmode = devmode;
4042 /********************************************************************
4043 ********************************************************************/
4045 static bool snum_is_shared_printer(int snum)
4047 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
4050 /********************************************************************
4051 Spoolss_enumprinters.
4052 ********************************************************************/
4054 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
4057 union spoolss_PrinterInfo **info_p,
4061 int n_services = lp_numservices();
4062 union spoolss_PrinterInfo *info = NULL;
4064 WERROR result = WERR_OK;
4069 for (snum = 0; snum < n_services; snum++) {
4071 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
4073 if (!snum_is_shared_printer(snum)) {
4077 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
4078 lp_servicename(snum), snum));
4080 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4081 union spoolss_PrinterInfo,
4084 result = WERR_NOMEM;
4088 result = get_a_printer(NULL, &ntprinter, 2,
4089 lp_const_servicename(snum));
4090 if (!W_ERROR_IS_OK(result)) {
4096 result = construct_printer_info0(info, ntprinter,
4097 &info[count].info0, snum);
4100 result = construct_printer_info1(info, ntprinter, flags,
4101 &info[count].info1, snum);
4104 result = construct_printer_info2(info, ntprinter,
4105 &info[count].info2, snum);
4108 result = construct_printer_info4(info, ntprinter,
4109 &info[count].info4, snum);
4112 result = construct_printer_info5(info, ntprinter,
4113 &info[count].info5, snum);
4117 result = WERR_UNKNOWN_LEVEL;
4118 free_a_printer(&ntprinter, 2);
4122 free_a_printer(&ntprinter, 2);
4123 if (!W_ERROR_IS_OK(result)) {
4134 if (!W_ERROR_IS_OK(result)) {
4144 /********************************************************************
4145 * handle enumeration of printers at level 0
4146 ********************************************************************/
4148 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
4150 const char *servername,
4151 union spoolss_PrinterInfo **info,
4154 DEBUG(4,("enum_all_printers_info_0\n"));
4156 return enum_all_printers_info_level(mem_ctx, 0, flags, info, count);
4160 /********************************************************************
4161 ********************************************************************/
4163 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
4165 union spoolss_PrinterInfo **info,
4168 DEBUG(4,("enum_all_printers_info_1\n"));
4170 return enum_all_printers_info_level(mem_ctx, 1, flags, info, count);
4173 /********************************************************************
4174 enum_all_printers_info_1_local.
4175 *********************************************************************/
4177 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
4178 union spoolss_PrinterInfo **info,
4181 DEBUG(4,("enum_all_printers_info_1_local\n"));
4183 return enum_all_printers_info_1(mem_ctx, PRINTER_ENUM_ICON8, info, count);
4186 /********************************************************************
4187 enum_all_printers_info_1_name.
4188 *********************************************************************/
4190 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
4192 union spoolss_PrinterInfo **info,
4195 const char *s = name;
4197 DEBUG(4,("enum_all_printers_info_1_name\n"));
4199 if ((name[0] == '\\') && (name[1] == '\\')) {
4203 if (!is_myname_or_ipaddr(s)) {
4204 return WERR_INVALID_NAME;
4207 return enum_all_printers_info_1(mem_ctx, PRINTER_ENUM_ICON8, info, count);
4210 /********************************************************************
4211 enum_all_printers_info_1_network.
4212 *********************************************************************/
4214 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
4216 union spoolss_PrinterInfo **info,
4219 const char *s = name;
4221 DEBUG(4,("enum_all_printers_info_1_network\n"));
4223 /* If we respond to a enum_printers level 1 on our name with flags
4224 set to PRINTER_ENUM_REMOTE with a list of printers then these
4225 printers incorrectly appear in the APW browse list.
4226 Specifically the printers for the server appear at the workgroup
4227 level where all the other servers in the domain are
4228 listed. Windows responds to this call with a
4229 WERR_CAN_NOT_COMPLETE so we should do the same. */
4231 if (name[0] == '\\' && name[1] == '\\') {
4235 if (is_myname_or_ipaddr(s)) {
4236 return WERR_CAN_NOT_COMPLETE;
4239 return enum_all_printers_info_1(mem_ctx, PRINTER_ENUM_NAME, info, count);
4242 /********************************************************************
4243 * api_spoolss_enumprinters
4245 * called from api_spoolss_enumprinters (see this to understand)
4246 ********************************************************************/
4248 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
4249 union spoolss_PrinterInfo **info,
4252 DEBUG(4,("enum_all_printers_info_2\n"));
4254 return enum_all_printers_info_level(mem_ctx, 2, 0, info, count);
4257 /********************************************************************
4258 * handle enumeration of printers at level 1
4259 ********************************************************************/
4261 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
4264 union spoolss_PrinterInfo **info,
4267 /* Not all the flags are equals */
4269 if (flags & PRINTER_ENUM_LOCAL) {
4270 return enum_all_printers_info_1_local(mem_ctx, info, count);
4273 if (flags & PRINTER_ENUM_NAME) {
4274 return enum_all_printers_info_1_name(mem_ctx, name, info, count);
4277 if (flags & PRINTER_ENUM_NETWORK) {
4278 return enum_all_printers_info_1_network(mem_ctx, name, info, count);
4281 return WERR_OK; /* NT4sp5 does that */
4284 /********************************************************************
4285 * handle enumeration of printers at level 2
4286 ********************************************************************/
4288 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4290 const char *servername,
4291 union spoolss_PrinterInfo **info,
4294 if (flags & PRINTER_ENUM_LOCAL) {
4295 return enum_all_printers_info_2(mem_ctx, info, count);
4298 if (flags & PRINTER_ENUM_NAME) {
4299 if (!is_myname_or_ipaddr(canon_servername(servername))) {
4300 return WERR_INVALID_NAME;
4303 return enum_all_printers_info_2(mem_ctx, info, count);
4306 if (flags & PRINTER_ENUM_REMOTE) {
4307 return WERR_UNKNOWN_LEVEL;
4313 /********************************************************************
4314 * handle enumeration of printers at level 4
4315 ********************************************************************/
4317 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4319 const char *servername,
4320 union spoolss_PrinterInfo **info,
4323 DEBUG(4,("enum_all_printers_info_4\n"));
4325 return enum_all_printers_info_level(mem_ctx, 4, flags, info, count);
4329 /********************************************************************
4330 * handle enumeration of printers at level 5
4331 ********************************************************************/
4333 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4335 const char *servername,
4336 union spoolss_PrinterInfo **info,
4339 DEBUG(4,("enum_all_printers_info_5\n"));
4341 return enum_all_printers_info_level(mem_ctx, 5, flags, info, count);
4344 /****************************************************************
4345 _spoolss_EnumPrinters
4346 ****************************************************************/
4348 WERROR _spoolss_EnumPrinters(pipes_struct *p,
4349 struct spoolss_EnumPrinters *r)
4354 /* that's an [in out] buffer */
4356 if (!r->in.buffer && (r->in.offered != 0)) {
4357 return WERR_INVALID_PARAM;
4360 DEBUG(4,("_spoolss_EnumPrinters\n"));
4364 *r->out.info = NULL;
4368 * flags==PRINTER_ENUM_NAME
4369 * if name=="" then enumerates all printers
4370 * if name!="" then enumerate the printer
4371 * flags==PRINTER_ENUM_REMOTE
4372 * name is NULL, enumerate printers
4373 * Level 2: name!="" enumerates printers, name can't be NULL
4374 * Level 3: doesn't exist
4375 * Level 4: does a local registry lookup
4376 * Level 5: same as Level 2
4379 name = talloc_strdup_upper(p->mem_ctx, r->in.server);
4380 W_ERROR_HAVE_NO_MEMORY(name);
4382 switch (r->in.level) {
4384 result = enumprinters_level0(p->mem_ctx, r->in.flags, name,
4385 r->out.info, r->out.count);
4388 result = enumprinters_level1(p->mem_ctx, r->in.flags, name,
4389 r->out.info, r->out.count);
4392 result = enumprinters_level2(p->mem_ctx, r->in.flags, name,
4393 r->out.info, r->out.count);
4396 result = enumprinters_level4(p->mem_ctx, r->in.flags, name,
4397 r->out.info, r->out.count);
4400 result = enumprinters_level5(p->mem_ctx, r->in.flags, name,
4401 r->out.info, r->out.count);
4404 return WERR_UNKNOWN_LEVEL;
4407 if (!W_ERROR_IS_OK(result)) {
4411 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4412 spoolss_EnumPrinters, NULL,
4413 *r->out.info, r->in.level,
4415 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4416 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4418 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4421 /****************************************************************
4423 ****************************************************************/
4425 WERROR _spoolss_GetPrinter(pipes_struct *p,
4426 struct spoolss_GetPrinter *r)
4428 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
4429 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
4430 WERROR result = WERR_OK;
4434 /* that's an [in out] buffer */
4436 if (!r->in.buffer && (r->in.offered != 0)) {
4437 return WERR_INVALID_PARAM;
4442 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4446 result = get_a_printer(Printer, &ntprinter, 2,
4447 lp_const_servicename(snum));
4448 if (!W_ERROR_IS_OK(result)) {
4452 switch (r->in.level) {
4454 result = construct_printer_info0(p->mem_ctx, ntprinter,
4455 &r->out.info->info0, snum);
4458 result = construct_printer_info1(p->mem_ctx, ntprinter,
4460 &r->out.info->info1, snum);
4463 result = construct_printer_info2(p->mem_ctx, ntprinter,
4464 &r->out.info->info2, snum);
4467 result = construct_printer_info3(p->mem_ctx, ntprinter,
4468 &r->out.info->info3, snum);
4471 result = construct_printer_info4(p->mem_ctx, ntprinter,
4472 &r->out.info->info4, snum);
4475 result = construct_printer_info5(p->mem_ctx, ntprinter,
4476 &r->out.info->info5, snum);
4479 result = construct_printer_info6(p->mem_ctx, ntprinter,
4480 &r->out.info->info6, snum);
4483 result = construct_printer_info7(p->mem_ctx, Printer,
4484 &r->out.info->info7, snum);
4487 result = construct_printer_info8(p->mem_ctx, ntprinter,
4488 &r->out.info->info8, snum);
4491 result = WERR_UNKNOWN_LEVEL;
4495 free_a_printer(&ntprinter, 2);
4497 if (!W_ERROR_IS_OK(result)) {
4498 TALLOC_FREE(r->out.info);
4502 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo, NULL,
4503 r->out.info, r->in.level);
4504 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4506 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4509 /********************************************************************
4510 ********************************************************************/
4512 static const char **string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4513 const char **string_array,
4514 const char *cservername)
4516 int i, num_strings = 0;
4517 const char **array = NULL;
4519 if (!string_array) {
4523 for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
4525 const char *str = talloc_asprintf(mem_ctx, "\\\\%s%s",
4526 cservername, string_array[i]);
4533 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4540 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4541 &array, &num_strings);
4547 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4549 if (in && strlen(in)) { \
4550 out = talloc_strdup(mem_ctx, in); \
4551 W_ERROR_HAVE_NO_MEMORY(out); \
4555 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, in, out) \
4557 if (in && strlen(in)) { \
4558 out = talloc_asprintf(mem_ctx, "\\\\%s%s", server, in); \
4560 out = talloc_strdup(mem_ctx, ""); \
4562 W_ERROR_HAVE_NO_MEMORY(out); \
4565 /********************************************************************
4566 * fill a spoolss_DriverInfo1 struct
4567 ********************************************************************/
4569 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4570 struct spoolss_DriverInfo1 *r,
4571 const struct spoolss_DriverInfo3 *driver,
4572 const char *servername,
4573 const char *architecture)
4575 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4576 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4581 /********************************************************************
4582 * fill a spoolss_DriverInfo2 struct
4583 ********************************************************************/
4585 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4586 struct spoolss_DriverInfo2 *r,
4587 const struct spoolss_DriverInfo3 *driver,
4588 const char *servername)
4591 const char *cservername = canon_servername(servername);
4593 r->version = driver->version;
4595 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4596 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4597 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4598 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4600 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4601 driver->driver_path,
4604 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4608 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4609 driver->config_file,
4615 /********************************************************************
4616 * fill a spoolss_DriverInfo3 struct
4617 ********************************************************************/
4619 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4620 struct spoolss_DriverInfo3 *r,
4621 const struct spoolss_DriverInfo3 *driver,
4622 const char *servername)
4624 const char *cservername = canon_servername(servername);
4626 r->version = driver->version;
4628 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4629 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4630 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4631 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4633 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4634 driver->driver_path,
4637 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4641 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4642 driver->config_file,
4645 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4649 FILL_DRIVER_STRING(mem_ctx,
4650 driver->monitor_name,
4653 FILL_DRIVER_STRING(mem_ctx,
4654 driver->default_datatype,
4655 r->default_datatype);
4657 r->dependent_files = string_array_from_driver_info(mem_ctx,
4658 driver->dependent_files,
4663 /********************************************************************
4664 * fill a spoolss_DriverInfo4 struct
4665 ********************************************************************/
4667 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
4668 struct spoolss_DriverInfo4 *r,
4669 const struct spoolss_DriverInfo3 *driver,
4670 const char *servername)
4672 const char *cservername = canon_servername(servername);
4674 r->version = driver->version;
4676 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4677 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4678 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4679 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4681 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4682 driver->driver_path,
4685 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4689 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4690 driver->config_file,
4693 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4697 r->dependent_files = string_array_from_driver_info(mem_ctx,
4698 driver->dependent_files,
4701 FILL_DRIVER_STRING(mem_ctx,
4702 driver->monitor_name,
4705 FILL_DRIVER_STRING(mem_ctx,
4706 driver->default_datatype,
4707 r->default_datatype);
4709 r->previous_names = string_array_from_driver_info(mem_ctx,
4716 /********************************************************************
4717 * fill a spoolss_DriverInfo5 struct
4718 ********************************************************************/
4720 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
4721 struct spoolss_DriverInfo5 *r,
4722 const struct spoolss_DriverInfo3 *driver,
4723 const char *servername)
4725 const char *cservername = canon_servername(servername);
4727 r->version = driver->version;
4729 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4730 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4731 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4732 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4734 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4735 driver->driver_path,
4738 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4742 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4743 driver->config_file,
4746 r->driver_attributes = 0;
4747 r->config_version = 0;
4748 r->driver_version = 0;
4752 /********************************************************************
4753 * fill a spoolss_DriverInfo6 struct
4754 ********************************************************************/
4756 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
4757 struct spoolss_DriverInfo6 *r,
4758 const struct spoolss_DriverInfo3 *driver,
4759 const char *servername)
4761 const char *cservername = canon_servername(servername);
4763 r->version = driver->version;
4765 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4766 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4767 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4768 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4770 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4771 driver->driver_path,
4774 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4778 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4779 driver->config_file,
4782 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4786 FILL_DRIVER_STRING(mem_ctx,
4787 driver->monitor_name,
4790 FILL_DRIVER_STRING(mem_ctx,
4791 driver->default_datatype,
4792 r->default_datatype);
4794 r->dependent_files = string_array_from_driver_info(mem_ctx,
4795 driver->dependent_files,
4797 r->previous_names = string_array_from_driver_info(mem_ctx,
4802 r->driver_version = 0;
4804 FILL_DRIVER_STRING(mem_ctx, "",
4805 r->manufacturer_name);
4806 FILL_DRIVER_STRING(mem_ctx, "",
4807 r->manufacturer_url);
4808 FILL_DRIVER_STRING(mem_ctx, "",
4810 FILL_DRIVER_STRING(mem_ctx, "",
4816 /********************************************************************
4817 ********************************************************************/
4819 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
4820 struct spoolss_DriverFileInfo *r,
4821 const char *cservername,
4822 const char *file_name,
4823 enum spoolss_DriverFileType file_type,
4824 uint32_t file_version)
4826 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
4827 cservername, file_name);
4828 W_ERROR_HAVE_NO_MEMORY(r->file_name);
4829 r->file_type = file_type;
4830 r->file_version = file_version;
4835 /********************************************************************
4836 ********************************************************************/
4838 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
4839 const struct spoolss_DriverInfo3 *driver,
4840 const char *cservername,
4841 struct spoolss_DriverFileInfo **info_p,
4844 struct spoolss_DriverFileInfo *info = NULL;
4852 if (strlen(driver->driver_path)) {
4853 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4854 struct spoolss_DriverFileInfo,
4856 W_ERROR_HAVE_NO_MEMORY(info);
4857 result = fill_spoolss_DriverFileInfo(info,
4860 driver->driver_path,
4861 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
4863 W_ERROR_NOT_OK_RETURN(result);
4867 if (strlen(driver->config_file)) {
4868 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4869 struct spoolss_DriverFileInfo,
4871 W_ERROR_HAVE_NO_MEMORY(info);
4872 result = fill_spoolss_DriverFileInfo(info,
4875 driver->config_file,
4876 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
4878 W_ERROR_NOT_OK_RETURN(result);
4882 if (strlen(driver->data_file)) {
4883 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4884 struct spoolss_DriverFileInfo,
4886 W_ERROR_HAVE_NO_MEMORY(info);
4887 result = fill_spoolss_DriverFileInfo(info,
4891 SPOOLSS_DRIVER_FILE_TYPE_DATA,
4893 W_ERROR_NOT_OK_RETURN(result);
4897 if (strlen(driver->help_file)) {
4898 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4899 struct spoolss_DriverFileInfo,
4901 W_ERROR_HAVE_NO_MEMORY(info);
4902 result = fill_spoolss_DriverFileInfo(info,
4906 SPOOLSS_DRIVER_FILE_TYPE_HELP,
4908 W_ERROR_NOT_OK_RETURN(result);
4912 for (i=0; driver->dependent_files[i] && driver->dependent_files[i][0] != '\0'; i++) {
4913 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4914 struct spoolss_DriverFileInfo,
4916 W_ERROR_HAVE_NO_MEMORY(info);
4917 result = fill_spoolss_DriverFileInfo(info,
4920 driver->dependent_files[i],
4921 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
4923 W_ERROR_NOT_OK_RETURN(result);
4933 /********************************************************************
4934 * fill a spoolss_DriverInfo101 sttruct
4935 ********************************************************************/
4937 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
4938 struct spoolss_DriverInfo101 *r,
4939 const struct spoolss_DriverInfo3 *driver,
4940 const char *servername)
4942 const char *cservername = canon_servername(servername);
4945 r->version = driver->version;
4947 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4948 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4949 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4950 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4952 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
4956 if (!W_ERROR_IS_OK(result)) {
4960 FILL_DRIVER_STRING(mem_ctx,
4961 driver->monitor_name,
4964 FILL_DRIVER_STRING(mem_ctx,
4965 driver->default_datatype,
4966 r->default_datatype);
4968 r->previous_names = string_array_from_driver_info(mem_ctx,
4972 r->driver_version = 0;
4974 FILL_DRIVER_STRING(mem_ctx, "",
4975 r->manufacturer_name);
4976 FILL_DRIVER_STRING(mem_ctx, "",
4977 r->manufacturer_url);
4978 FILL_DRIVER_STRING(mem_ctx, "",
4980 FILL_DRIVER_STRING(mem_ctx, "",
4986 /********************************************************************
4987 * construct_printer_driver_info_1
4988 ********************************************************************/
4990 static WERROR construct_printer_driver_info_1(TALLOC_CTX *mem_ctx,
4991 struct spoolss_DriverInfo1 *r,
4993 const char *servername,
4994 const char *architecture,
4997 NT_PRINTER_INFO_LEVEL *printer = NULL;
4998 union spoolss_DriverInfo *driver;
5001 if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, lp_const_servicename(snum))))
5002 return WERR_INVALID_PRINTER_NAME;
5004 if (!W_ERROR_IS_OK(get_a_printer_driver(mem_ctx, &driver, 3, printer->info_2->drivername, architecture, version))) {
5005 free_a_printer(&printer, 2);
5006 return WERR_UNKNOWN_PRINTER_DRIVER;
5009 result = fill_printer_driver_info1(mem_ctx, r, &driver->info3, servername, architecture);
5011 free_a_printer_driver(driver);
5012 free_a_printer(&printer,2);
5017 /********************************************************************
5018 * construct_printer_driver_info_2
5019 * fill a printer_info_2 struct
5020 ********************************************************************/
5022 static WERROR construct_printer_driver_info_2(TALLOC_CTX *mem_ctx,
5023 struct spoolss_DriverInfo2 *r,
5025 const char *servername,
5026 const char *architecture,
5029 NT_PRINTER_INFO_LEVEL *printer = NULL;
5030 union spoolss_DriverInfo *driver;
5033 ZERO_STRUCT(printer);
5035 if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, lp_const_servicename(snum))))
5036 return WERR_INVALID_PRINTER_NAME;
5038 if (!W_ERROR_IS_OK(get_a_printer_driver(mem_ctx, &driver, 3, printer->info_2->drivername, architecture, version))) {
5039 free_a_printer(&printer, 2);
5040 return WERR_UNKNOWN_PRINTER_DRIVER;
5043 result = fill_printer_driver_info2(mem_ctx, r, &driver->info3, servername);
5045 free_a_printer_driver(driver);
5046 free_a_printer(&printer,2);
5051 /********************************************************************
5052 * construct_printer_info_3
5053 * fill a printer_info_3 struct
5054 ********************************************************************/
5056 static WERROR construct_printer_driver_info_3(TALLOC_CTX *mem_ctx,
5057 struct spoolss_DriverInfo3 *r,
5059 const char *servername,
5060 const char *architecture,
5063 NT_PRINTER_INFO_LEVEL *printer = NULL;
5064 union spoolss_DriverInfo *driver;
5066 ZERO_STRUCT(driver);
5068 status=get_a_printer(NULL, &printer, 2, lp_const_servicename(snum) );
5069 DEBUG(8,("construct_printer_driver_info_3: status: %s\n", win_errstr(status)));
5070 if (!W_ERROR_IS_OK(status))
5071 return WERR_INVALID_PRINTER_NAME;
5073 status = get_a_printer_driver(mem_ctx, &driver, 3, printer->info_2->drivername, architecture, version);
5074 DEBUG(8,("construct_printer_driver_info_3: status: %s\n", win_errstr(status)));
5079 * I put this code in during testing. Helpful when commenting out the
5080 * support for DRIVER_INFO_6 in regards to win2k. Not needed in general
5081 * as win2k always queries the driver using an infor level of 6.
5082 * I've left it in (but ifdef'd out) because I'll probably
5083 * use it in experimentation again in the future. --jerry 22/01/2002
5086 if (!W_ERROR_IS_OK(status)) {
5088 * Is this a W2k client ?
5091 /* Yes - try again with a WinNT driver. */
5093 status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version);
5094 DEBUG(8,("construct_printer_driver_info_3: status: %s\n", win_errstr(status)));
5098 if (!W_ERROR_IS_OK(status)) {
5099 free_a_printer(&printer,2);
5100 return WERR_UNKNOWN_PRINTER_DRIVER;
5108 status = fill_printer_driver_info3(mem_ctx, r, &driver->info3, servername);
5110 free_a_printer_driver(driver);
5111 free_a_printer(&printer,2);
5116 /********************************************************************
5117 * construct_printer_info_6
5118 * fill a printer_info_6 struct
5119 ********************************************************************/
5121 static WERROR construct_printer_driver_info_6(TALLOC_CTX *mem_ctx,
5122 struct spoolss_DriverInfo6 *r,
5124 const char *servername,
5125 const char *architecture,
5128 NT_PRINTER_INFO_LEVEL *printer = NULL;
5129 union spoolss_DriverInfo *driver;
5132 status=get_a_printer(NULL, &printer, 2, lp_const_servicename(snum) );
5134 DEBUG(8,("construct_printer_driver_info_6: status: %s\n", win_errstr(status)));
5136 if (!W_ERROR_IS_OK(status))
5137 return WERR_INVALID_PRINTER_NAME;
5139 status = get_a_printer_driver(mem_ctx, &driver, 3, printer->info_2->drivername, architecture, version);
5141 DEBUG(8,("construct_printer_driver_info_6: status: %s\n", win_errstr(status)));
5143 if (!W_ERROR_IS_OK(status))
5146 * Is this a W2k client ?
5150 free_a_printer(&printer,2);
5151 return WERR_UNKNOWN_PRINTER_DRIVER;
5154 /* Yes - try again with a WinNT driver. */
5156 status = get_a_printer_driver(mem_ctx, &driver, 3, printer->info_2->drivername, architecture, version);
5157 DEBUG(8,("construct_printer_driver_info_6: status: %s\n", win_errstr(status)));
5158 if (!W_ERROR_IS_OK(status)) {
5159 free_a_printer(&printer,2);
5160 return WERR_UNKNOWN_PRINTER_DRIVER;
5164 status = fill_printer_driver_info6(mem_ctx, r, &driver->info3, servername);
5166 free_a_printer(&printer,2);
5167 free_a_printer_driver(driver);
5172 /********************************************************************
5173 * construct_printer_info_101
5174 * fill a printer_info_101 struct
5175 ********************************************************************/
5177 static WERROR construct_printer_driver_info_101(TALLOC_CTX *mem_ctx,
5178 struct spoolss_DriverInfo101 *r,
5180 const char *servername,
5181 const char *architecture,
5184 NT_PRINTER_INFO_LEVEL *printer = NULL;
5185 union spoolss_DriverInfo *driver;
5188 result = get_a_printer(NULL, &printer, 2, lp_const_servicename(snum));
5190 DEBUG(8,("construct_printer_driver_info_101: status: %s\n",
5191 win_errstr(result)));
5193 if (!W_ERROR_IS_OK(result)) {
5194 return WERR_INVALID_PRINTER_NAME;
5197 result = get_a_printer_driver(mem_ctx, &driver, 3, printer->info_2->drivername,
5198 architecture, version);
5200 DEBUG(8,("construct_printer_driver_info_101: status: %s\n",
5201 win_errstr(result)));
5203 if (!W_ERROR_IS_OK(result)) {
5205 * Is this a W2k client ?
5209 free_a_printer(&printer, 2);
5210 return WERR_UNKNOWN_PRINTER_DRIVER;
5213 /* Yes - try again with a WinNT driver. */
5215 result = get_a_printer_driver(mem_ctx, &driver, 3, printer->info_2->drivername,
5216 architecture, version);
5217 DEBUG(8,("construct_printer_driver_info_6: status: %s\n",
5218 win_errstr(result)));
5219 if (!W_ERROR_IS_OK(result)) {
5220 free_a_printer(&printer, 2);
5221 return WERR_UNKNOWN_PRINTER_DRIVER;
5225 result = fill_printer_driver_info101(mem_ctx, r, &driver->info3, servername);
5227 free_a_printer(&printer, 2);
5228 free_a_printer_driver(driver);
5233 /****************************************************************
5234 _spoolss_GetPrinterDriver2
5235 ****************************************************************/
5237 WERROR _spoolss_GetPrinterDriver2(pipes_struct *p,
5238 struct spoolss_GetPrinterDriver2 *r)
5240 Printer_entry *printer;
5243 const char *servername;
5246 /* that's an [in out] buffer */
5248 if (!r->in.buffer && (r->in.offered != 0)) {
5249 return WERR_INVALID_PARAM;
5252 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5254 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5255 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5256 return WERR_INVALID_PRINTER_NAME;
5260 *r->out.server_major_version = 0;
5261 *r->out.server_minor_version = 0;
5263 servername = get_server_name(printer);
5265 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5269 switch (r->in.level) {
5271 result = construct_printer_driver_info_1(p->mem_ctx,
5272 &r->out.info->info1,
5276 r->in.client_major_version);
5279 result = construct_printer_driver_info_2(p->mem_ctx,
5280 &r->out.info->info2,
5284 r->in.client_major_version);
5287 result = construct_printer_driver_info_3(p->mem_ctx,
5288 &r->out.info->info3,
5292 r->in.client_major_version);
5295 result = construct_printer_driver_info_6(p->mem_ctx,
5296 &r->out.info->info6,
5300 r->in.client_major_version);
5303 result = construct_printer_driver_info_101(p->mem_ctx,
5304 &r->out.info->info101,
5308 r->in.client_major_version);
5311 result = WERR_UNKNOWN_LEVEL;
5315 if (!W_ERROR_IS_OK(result)) {
5316 TALLOC_FREE(r->out.info);
5320 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo, NULL,
5321 r->out.info, r->in.level);
5322 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5324 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5328 /****************************************************************
5329 _spoolss_StartPagePrinter
5330 ****************************************************************/
5332 WERROR _spoolss_StartPagePrinter(pipes_struct *p,
5333 struct spoolss_StartPagePrinter *r)
5335 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5338 DEBUG(3,("_spoolss_StartPagePrinter: "
5339 "Error in startpageprinter printer handle\n"));
5343 Printer->page_started = true;
5347 /****************************************************************
5348 _spoolss_EndPagePrinter
5349 ****************************************************************/
5351 WERROR _spoolss_EndPagePrinter(pipes_struct *p,
5352 struct spoolss_EndPagePrinter *r)
5356 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5359 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5360 OUR_HANDLE(r->in.handle)));
5364 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5367 Printer->page_started = false;
5368 print_job_endpage(snum, Printer->jobid);
5373 /****************************************************************
5374 _spoolss_StartDocPrinter
5375 ****************************************************************/
5377 WERROR _spoolss_StartDocPrinter(pipes_struct *p,
5378 struct spoolss_StartDocPrinter *r)
5380 struct spoolss_DocumentInfo1 *info_1;
5382 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5385 DEBUG(2,("_spoolss_StartDocPrinter: "
5386 "Invalid handle (%s:%u:%u)\n",
5387 OUR_HANDLE(r->in.handle)));
5391 if (r->in.level != 1) {
5392 return WERR_UNKNOWN_LEVEL;
5395 info_1 = r->in.info.info1;
5398 * a nice thing with NT is it doesn't listen to what you tell it.
5399 * when asked to send _only_ RAW datas, it tries to send datas
5402 * So I add checks like in NT Server ...
5405 if (info_1->datatype) {
5406 if (strcmp(info_1->datatype, "RAW") != 0) {
5408 return WERR_INVALID_DATATYPE;
5412 /* get the share number of the printer */
5413 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5417 Printer->jobid = print_job_start(p->server_info, snum,
5418 info_1->document_name,
5419 Printer->nt_devmode);
5421 /* An error occured in print_job_start() so return an appropriate
5424 if (Printer->jobid == -1) {
5425 return map_werror_from_unix(errno);
5428 Printer->document_started = true;
5429 *r->out.job_id = Printer->jobid;
5434 /****************************************************************
5435 _spoolss_EndDocPrinter
5436 ****************************************************************/
5438 WERROR _spoolss_EndDocPrinter(pipes_struct *p,
5439 struct spoolss_EndDocPrinter *r)
5441 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5445 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5446 OUR_HANDLE(r->in.handle)));
5450 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5454 Printer->document_started = false;
5455 print_job_end(snum, Printer->jobid, NORMAL_CLOSE);
5456 /* error codes unhandled so far ... */
5461 /****************************************************************
5462 _spoolss_WritePrinter
5463 ****************************************************************/
5465 WERROR _spoolss_WritePrinter(pipes_struct *p,
5466 struct spoolss_WritePrinter *r)
5468 uint32_t buffer_written;
5470 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5473 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5474 OUR_HANDLE(r->in.handle)));
5475 *r->out.num_written = r->in._data_size;
5479 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5482 buffer_written = (uint32_t)print_job_write(snum, Printer->jobid,
5483 (const char *)r->in.data.data,
5485 (size_t)r->in._data_size);
5486 if (buffer_written == (uint32_t)-1) {
5487 *r->out.num_written = 0;
5488 if (errno == ENOSPC)
5489 return WERR_NO_SPOOL_SPACE;
5491 return WERR_ACCESS_DENIED;
5494 *r->out.num_written = r->in._data_size;
5499 /********************************************************************
5500 * api_spoolss_getprinter
5501 * called from the spoolss dispatcher
5503 ********************************************************************/
5505 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5509 WERROR errcode = WERR_BADFUNC;
5510 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5513 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5514 OUR_HANDLE(handle)));
5518 if (!get_printer_snum(p, handle, &snum, NULL))
5522 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5523 errcode = print_queue_pause(p->server_info, snum);
5525 case SPOOLSS_PRINTER_CONTROL_RESUME:
5526 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5527 errcode = print_queue_resume(p->server_info, snum);
5529 case SPOOLSS_PRINTER_CONTROL_PURGE:
5530 errcode = print_queue_purge(p->server_info, snum);
5533 return WERR_UNKNOWN_LEVEL;
5540 /****************************************************************
5541 _spoolss_AbortPrinter
5542 * From MSDN: "Deletes printer's spool file if printer is configured
5544 ****************************************************************/
5546 WERROR _spoolss_AbortPrinter(pipes_struct *p,
5547 struct spoolss_AbortPrinter *r)
5549 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5551 WERROR errcode = WERR_OK;
5554 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5555 OUR_HANDLE(r->in.handle)));
5559 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5562 print_job_delete(p->server_info, snum, Printer->jobid, &errcode );
5567 /********************************************************************
5568 * called by spoolss_api_setprinter
5569 * when updating a printer description
5570 ********************************************************************/
5572 static WERROR update_printer_sec(struct policy_handle *handle,
5573 pipes_struct *p, SEC_DESC_BUF *secdesc_ctr)
5575 SEC_DESC_BUF *new_secdesc_ctr = NULL, *old_secdesc_ctr = NULL;
5579 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5581 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
5582 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5583 OUR_HANDLE(handle)));
5585 result = WERR_BADFID;
5590 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5591 result = WERR_INVALID_PARAM;
5595 /* Check the user has permissions to change the security
5596 descriptor. By experimentation with two NT machines, the user
5597 requires Full Access to the printer to change security
5600 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
5601 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5602 result = WERR_ACCESS_DENIED;
5606 /* NT seems to like setting the security descriptor even though
5607 nothing may have actually changed. */
5609 if ( !nt_printing_getsec(p->mem_ctx, Printer->sharename, &old_secdesc_ctr)) {
5610 DEBUG(2,("update_printer_sec: nt_printing_getsec() failed\n"));
5611 result = WERR_BADFID;
5615 if (DEBUGLEVEL >= 10) {
5619 the_acl = old_secdesc_ctr->sd->dacl;
5620 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
5621 PRINTERNAME(snum), the_acl->num_aces));
5623 for (i = 0; i < the_acl->num_aces; i++) {
5624 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5625 &the_acl->aces[i].trustee),
5626 the_acl->aces[i].access_mask));
5629 the_acl = secdesc_ctr->sd->dacl;
5632 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
5633 PRINTERNAME(snum), the_acl->num_aces));
5635 for (i = 0; i < the_acl->num_aces; i++) {
5636 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5637 &the_acl->aces[i].trustee),
5638 the_acl->aces[i].access_mask));
5641 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
5645 new_secdesc_ctr = sec_desc_merge(p->mem_ctx, secdesc_ctr, old_secdesc_ctr);
5646 if (!new_secdesc_ctr) {
5647 result = WERR_NOMEM;
5651 if (security_descriptor_equal(new_secdesc_ctr->sd, old_secdesc_ctr->sd)) {
5656 result = nt_printing_setsec(Printer->sharename, new_secdesc_ctr);
5663 /********************************************************************
5664 Canonicalize printer info from a client
5666 ATTN: It does not matter what we set the servername to hear
5667 since we do the necessary work in get_a_printer() to set it to
5668 the correct value based on what the client sent in the
5669 _spoolss_open_printer_ex().
5670 ********************************************************************/
5672 static bool check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum)
5674 fstring printername;
5677 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
5678 "portname=%s drivername=%s comment=%s location=%s\n",
5679 info->servername, info->printername, info->sharename,
5680 info->portname, info->drivername, info->comment, info->location));
5682 /* we force some elements to "correct" values */
5683 slprintf(info->servername, sizeof(info->servername)-1, "\\\\%s", global_myname());
5684 fstrcpy(info->sharename, lp_servicename(snum));
5686 /* check to see if we allow printername != sharename */
5688 if ( lp_force_printername(snum) ) {
5689 slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s",
5690 global_myname(), info->sharename );
5693 /* make sure printername is in \\server\printername format */
5695 fstrcpy( printername, info->printername );
5697 if ( printername[0] == '\\' && printername[1] == '\\' ) {
5698 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
5702 slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s",
5703 global_myname(), p );
5706 info->attributes |= PRINTER_ATTRIBUTE_SAMBA;
5707 info->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
5714 /****************************************************************************
5715 ****************************************************************************/
5717 static WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *portname, const char *uri)
5719 char *cmd = lp_addport_cmd();
5720 char *command = NULL;
5722 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5723 bool is_print_op = false;
5726 return WERR_ACCESS_DENIED;
5729 command = talloc_asprintf(ctx,
5730 "%s \"%s\" \"%s\"", cmd, portname, uri );
5736 is_print_op = user_has_privileges( token, &se_printop );
5738 DEBUG(10,("Running [%s]\n", command));
5740 /********* BEGIN SePrintOperatorPrivilege **********/
5745 ret = smbrun(command, NULL);
5750 /********* END SePrintOperatorPrivilege **********/
5752 DEBUGADD(10,("returned [%d]\n", ret));
5754 TALLOC_FREE(command);
5757 return WERR_ACCESS_DENIED;
5763 /****************************************************************************
5764 ****************************************************************************/
5766 bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer)
5768 char *cmd = lp_addprinter_cmd();
5770 char *command = NULL;
5774 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5775 bool is_print_op = false;
5776 char *remote_machine = talloc_strdup(ctx, "%m");
5778 if (!remote_machine) {
5781 remote_machine = talloc_sub_basic(ctx,
5782 current_user_info.smb_name,
5783 current_user_info.domain,
5785 if (!remote_machine) {
5789 command = talloc_asprintf(ctx,
5790 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
5791 cmd, printer->info_2->printername, printer->info_2->sharename,
5792 printer->info_2->portname, printer->info_2->drivername,
5793 printer->info_2->location, printer->info_2->comment, remote_machine);
5799 is_print_op = user_has_privileges( token, &se_printop );
5801 DEBUG(10,("Running [%s]\n", command));
5803 /********* BEGIN SePrintOperatorPrivilege **********/
5808 if ( (ret = smbrun(command, &fd)) == 0 ) {
5809 /* Tell everyone we updated smb.conf. */
5810 message_send_all(smbd_messaging_context(),
5811 MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
5817 /********* END SePrintOperatorPrivilege **********/
5819 DEBUGADD(10,("returned [%d]\n", ret));
5821 TALLOC_FREE(command);
5822 TALLOC_FREE(remote_machine);
5830 /* reload our services immediately */
5832 reload_services(false);
5836 /* Get lines and convert them back to dos-codepage */
5837 qlines = fd_lines_load(fd, &numlines, 0, NULL);
5838 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
5841 /* Set the portname to what the script says the portname should be. */
5842 /* but don't require anything to be return from the script exit a good error code */
5845 /* Set the portname to what the script says the portname should be. */
5846 strncpy(printer->info_2->portname, qlines[0], sizeof(printer->info_2->portname));
5847 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
5850 TALLOC_FREE(qlines);
5855 /********************************************************************
5856 * Called by spoolss_api_setprinter
5857 * when updating a printer description.
5858 ********************************************************************/
5860 static WERROR update_printer(pipes_struct *p, struct policy_handle *handle,
5861 struct spoolss_SetPrinterInfoCtr *info_ctr,
5862 struct spoolss_DeviceMode *devmode)
5865 NT_PRINTER_INFO_LEVEL *printer = NULL, *old_printer = NULL;
5866 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5871 DEBUG(8,("update_printer\n"));
5876 result = WERR_BADFID;
5880 if (!get_printer_snum(p, handle, &snum, NULL)) {
5881 result = WERR_BADFID;
5885 if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum))) ||
5886 (!W_ERROR_IS_OK(get_a_printer(Printer, &old_printer, 2, lp_const_servicename(snum))))) {
5887 result = WERR_BADFID;
5891 DEBUGADD(8,("Converting info_2 struct\n"));
5894 * convert_printer_info converts the incoming
5895 * info from the client and overwrites the info
5896 * just read from the tdb in the pointer 'printer'.
5899 if (!convert_printer_info(info_ctr, printer)) {
5900 result = WERR_NOMEM;
5905 /* we have a valid devmode
5906 convert it and link it*/
5908 DEBUGADD(8,("update_printer: Converting the devicemode struct\n"));
5909 if (!convert_devicemode(printer->info_2->printername, devmode,
5910 &printer->info_2->devmode)) {
5911 result = WERR_NOMEM;
5916 /* Do sanity check on the requested changes for Samba */
5918 if (!check_printer_ok(printer->info_2, snum)) {
5919 result = WERR_INVALID_PARAM;
5923 /* FIXME!!! If the driver has changed we really should verify that
5924 it is installed before doing much else --jerry */
5926 /* Check calling user has permission to update printer description */
5928 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
5929 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
5930 result = WERR_ACCESS_DENIED;
5934 /* Call addprinter hook */
5935 /* Check changes to see if this is really needed */
5937 if ( *lp_addprinter_cmd()
5938 && (!strequal(printer->info_2->drivername, old_printer->info_2->drivername)
5939 || !strequal(printer->info_2->comment, old_printer->info_2->comment)
5940 || !strequal(printer->info_2->portname, old_printer->info_2->portname)
5941 || !strequal(printer->info_2->location, old_printer->info_2->location)) )
5943 /* add_printer_hook() will call reload_services() */
5945 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
5947 result = WERR_ACCESS_DENIED;
5953 * When a *new* driver is bound to a printer, the drivername is used to
5954 * lookup previously saved driver initialization info, which is then
5955 * bound to the printer, simulating what happens in the Windows arch.
5957 if (!strequal(printer->info_2->drivername, old_printer->info_2->drivername))
5959 if (!set_driver_init(printer, 2))
5961 DEBUG(5,("update_printer: Error restoring driver initialization data for driver [%s]!\n",
5962 printer->info_2->drivername));
5965 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
5966 printer->info_2->drivername));
5968 notify_printer_driver(snum, printer->info_2->drivername);
5972 * flag which changes actually occured. This is a small subset of
5973 * all the possible changes. We also have to update things in the
5977 if (!strequal(printer->info_2->comment, old_printer->info_2->comment)) {
5978 push_reg_sz(talloc_tos(), &buffer, printer->info_2->comment);
5979 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "description",
5980 REG_SZ, buffer.data, buffer.length);
5982 notify_printer_comment(snum, printer->info_2->comment);
5985 if (!strequal(printer->info_2->sharename, old_printer->info_2->sharename)) {
5986 push_reg_sz(talloc_tos(), &buffer, printer->info_2->sharename);
5987 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "shareName",
5988 REG_SZ, buffer.data, buffer.length);
5990 notify_printer_sharename(snum, printer->info_2->sharename);
5993 if (!strequal(printer->info_2->printername, old_printer->info_2->printername)) {
5996 if ( (pname = strchr_m( printer->info_2->printername+2, '\\' )) != NULL )
5999 pname = printer->info_2->printername;
6002 push_reg_sz(talloc_tos(), &buffer, pname);
6003 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "printerName",
6004 REG_SZ, buffer.data, buffer.length);
6006 notify_printer_printername( snum, pname );
6009 if (!strequal(printer->info_2->portname, old_printer->info_2->portname)) {
6010 push_reg_sz(talloc_tos(), &buffer, printer->info_2->portname);
6011 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "portName",
6012 REG_SZ, buffer.data, buffer.length);
6014 notify_printer_port(snum, printer->info_2->portname);
6017 if (!strequal(printer->info_2->location, old_printer->info_2->location)) {
6018 push_reg_sz(talloc_tos(), &buffer, printer->info_2->location);
6019 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "location",
6020 REG_SZ, buffer.data, buffer.length);
6022 notify_printer_location(snum, printer->info_2->location);
6025 /* here we need to update some more DsSpooler keys */
6026 /* uNCName, serverName, shortServerName */
6028 push_reg_sz(talloc_tos(), &buffer, global_myname());
6029 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "serverName",
6030 REG_SZ, buffer.data, buffer.length);
6031 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "shortServerName",
6032 REG_SZ, buffer.data, buffer.length);
6034 slprintf( asc_buffer, sizeof(asc_buffer)-1, "\\\\%s\\%s",
6035 global_myname(), printer->info_2->sharename );
6036 push_reg_sz(talloc_tos(), &buffer, asc_buffer);
6037 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "uNCName",
6038 REG_SZ, buffer.data, buffer.length);
6040 /* Update printer info */
6041 result = mod_a_printer(printer, 2);
6044 free_a_printer(&printer, 2);
6045 free_a_printer(&old_printer, 2);
6051 /****************************************************************************
6052 ****************************************************************************/
6053 static WERROR publish_or_unpublish_printer(pipes_struct *p,
6054 struct policy_handle *handle,
6055 struct spoolss_SetPrinterInfo7 *info7)
6059 Printer_entry *Printer;
6061 if ( lp_security() != SEC_ADS ) {
6062 return WERR_UNKNOWN_LEVEL;
6065 Printer = find_printer_index_by_hnd(p, handle);
6067 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6072 if (!get_printer_snum(p, handle, &snum, NULL))
6075 nt_printer_publish(Printer, snum, info7->action);
6079 return WERR_UNKNOWN_LEVEL;
6083 /****************************************************************
6085 ****************************************************************/
6087 WERROR _spoolss_SetPrinter(pipes_struct *p,
6088 struct spoolss_SetPrinter *r)
6092 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
6095 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6096 OUR_HANDLE(r->in.handle)));
6100 /* check the level */
6101 switch (r->in.info_ctr->level) {
6103 return control_printer(r->in.handle, r->in.command, p);
6105 result = update_printer(p, r->in.handle,
6107 r->in.devmode_ctr->devmode);
6108 if (!W_ERROR_IS_OK(result))
6110 if (r->in.secdesc_ctr->sd)
6111 result = update_printer_sec(r->in.handle, p,
6115 return update_printer_sec(r->in.handle, p,
6118 return publish_or_unpublish_printer(p, r->in.handle,
6119 r->in.info_ctr->info.info7);
6121 return WERR_UNKNOWN_LEVEL;
6125 /****************************************************************
6126 _spoolss_FindClosePrinterNotify
6127 ****************************************************************/
6129 WERROR _spoolss_FindClosePrinterNotify(pipes_struct *p,
6130 struct spoolss_FindClosePrinterNotify *r)
6132 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
6135 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6136 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
6140 if (Printer->notify.client_connected == true) {
6143 if ( Printer->printer_type == SPLHND_SERVER)
6145 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
6146 !get_printer_snum(p, r->in.handle, &snum, NULL) )
6149 srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
6152 Printer->notify.flags=0;
6153 Printer->notify.options=0;
6154 Printer->notify.localmachine[0]='\0';
6155 Printer->notify.printerlocal=0;
6156 TALLOC_FREE(Printer->notify.option);
6157 Printer->notify.client_connected = false;
6162 /****************************************************************
6164 ****************************************************************/
6166 WERROR _spoolss_AddJob(pipes_struct *p,
6167 struct spoolss_AddJob *r)
6169 if (!r->in.buffer && (r->in.offered != 0)) {
6170 return WERR_INVALID_PARAM;
6173 /* this is what a NT server returns for AddJob. AddJob must fail on
6174 * non-local printers */
6176 if (r->in.level != 1) {
6177 return WERR_UNKNOWN_LEVEL;
6180 return WERR_INVALID_PARAM;
6183 /****************************************************************************
6185 ****************************************************************************/
6187 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
6188 struct spoolss_JobInfo1 *r,
6189 const print_queue_struct *queue,
6190 int position, int snum,
6191 const NT_PRINTER_INFO_LEVEL *ntprinter)
6195 t = gmtime(&queue->time);
6197 r->job_id = queue->job;
6199 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6200 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6201 r->server_name = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
6202 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6203 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6204 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6205 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6206 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6207 r->data_type = talloc_strdup(mem_ctx, "RAW");
6208 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6209 r->text_status = talloc_strdup(mem_ctx, "");
6210 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6212 r->status = nt_printj_status(queue->status);
6213 r->priority = queue->priority;
6214 r->position = position;
6215 r->total_pages = queue->page_count;
6216 r->pages_printed = 0; /* ??? */
6218 init_systemtime(&r->submitted, t);
6223 /****************************************************************************
6225 ****************************************************************************/
6227 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
6228 struct spoolss_JobInfo2 *r,
6229 const print_queue_struct *queue,
6230 int position, int snum,
6231 const NT_PRINTER_INFO_LEVEL *ntprinter,
6232 struct spoolss_DeviceMode *devmode)
6236 t = gmtime(&queue->time);
6238 r->job_id = queue->job;
6240 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6241 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6242 r->server_name = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
6243 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6244 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6245 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6246 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6247 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6248 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
6249 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
6250 r->data_type = talloc_strdup(mem_ctx, "RAW");
6251 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6252 r->print_processor = talloc_strdup(mem_ctx, "winprint");
6253 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
6254 r->parameters = talloc_strdup(mem_ctx, "");
6255 W_ERROR_HAVE_NO_MEMORY(r->parameters);
6256 r->driver_name = talloc_strdup(mem_ctx, ntprinter->info_2->drivername);
6257 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
6259 r->devmode = devmode;
6261 r->text_status = talloc_strdup(mem_ctx, "");
6262 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6266 r->status = nt_printj_status(queue->status);
6267 r->priority = queue->priority;
6268 r->position = position;
6271 r->total_pages = queue->page_count;
6272 r->size = queue->size;
6273 init_systemtime(&r->submitted, t);
6275 r->pages_printed = 0; /* ??? */
6280 /****************************************************************************
6281 Enumjobs at level 1.
6282 ****************************************************************************/
6284 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
6285 const print_queue_struct *queue,
6286 uint32_t num_queues, int snum,
6287 const NT_PRINTER_INFO_LEVEL *ntprinter,
6288 union spoolss_JobInfo **info_p,
6291 union spoolss_JobInfo *info;
6293 WERROR result = WERR_OK;
6295 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6296 W_ERROR_HAVE_NO_MEMORY(info);
6298 *count = num_queues;
6300 for (i=0; i<*count; i++) {
6301 result = fill_job_info1(info,
6307 if (!W_ERROR_IS_OK(result)) {
6313 if (!W_ERROR_IS_OK(result)) {
6324 /****************************************************************************
6325 Enumjobs at level 2.
6326 ****************************************************************************/
6328 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
6329 const print_queue_struct *queue,
6330 uint32_t num_queues, int snum,
6331 const NT_PRINTER_INFO_LEVEL *ntprinter,
6332 union spoolss_JobInfo **info_p,
6335 union spoolss_JobInfo *info;
6337 WERROR result = WERR_OK;
6339 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6340 W_ERROR_HAVE_NO_MEMORY(info);
6342 *count = num_queues;
6344 for (i=0; i<*count; i++) {
6346 struct spoolss_DeviceMode *devmode;
6348 devmode = construct_dev_mode(info, lp_const_servicename(snum));
6350 result = WERR_NOMEM;
6354 result = fill_job_info2(info,
6361 if (!W_ERROR_IS_OK(result)) {
6367 if (!W_ERROR_IS_OK(result)) {
6378 /****************************************************************
6380 ****************************************************************/
6382 WERROR _spoolss_EnumJobs(pipes_struct *p,
6383 struct spoolss_EnumJobs *r)
6386 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
6388 print_status_struct prt_status;
6389 print_queue_struct *queue = NULL;
6392 /* that's an [in out] buffer */
6394 if (!r->in.buffer && (r->in.offered != 0)) {
6395 return WERR_INVALID_PARAM;
6398 DEBUG(4,("_spoolss_EnumJobs\n"));
6402 *r->out.info = NULL;
6404 /* lookup the printer snum and tdb entry */
6406 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6410 result = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum));
6411 if (!W_ERROR_IS_OK(result)) {
6415 count = print_queue_status(snum, &queue, &prt_status);
6416 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
6417 count, prt_status.status, prt_status.message));
6421 free_a_printer(&ntprinter, 2);
6425 switch (r->in.level) {
6427 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
6428 ntprinter, r->out.info, r->out.count);
6431 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
6432 ntprinter, r->out.info, r->out.count);
6435 result = WERR_UNKNOWN_LEVEL;
6440 free_a_printer(&ntprinter, 2);
6442 if (!W_ERROR_IS_OK(result)) {
6446 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6447 spoolss_EnumJobs, NULL,
6448 *r->out.info, r->in.level,
6450 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6451 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6453 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6456 /****************************************************************
6457 _spoolss_ScheduleJob
6458 ****************************************************************/
6460 WERROR _spoolss_ScheduleJob(pipes_struct *p,
6461 struct spoolss_ScheduleJob *r)
6466 /****************************************************************
6468 ****************************************************************/
6470 WERROR _spoolss_SetJob(pipes_struct *p,
6471 struct spoolss_SetJob *r)
6474 WERROR errcode = WERR_BADFUNC;
6476 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6480 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
6481 return WERR_INVALID_PRINTER_NAME;
6484 switch (r->in.command) {
6485 case SPOOLSS_JOB_CONTROL_CANCEL:
6486 case SPOOLSS_JOB_CONTROL_DELETE:
6487 if (print_job_delete(p->server_info, snum, r->in.job_id, &errcode)) {
6491 case SPOOLSS_JOB_CONTROL_PAUSE:
6492 if (print_job_pause(p->server_info, snum, r->in.job_id, &errcode)) {
6496 case SPOOLSS_JOB_CONTROL_RESTART:
6497 case SPOOLSS_JOB_CONTROL_RESUME:
6498 if (print_job_resume(p->server_info, snum, r->in.job_id, &errcode)) {
6503 return WERR_UNKNOWN_LEVEL;
6509 /****************************************************************************
6510 Enumerates all printer drivers by level and architecture.
6511 ****************************************************************************/
6513 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
6514 const char *servername,
6515 const char *architecture,
6517 union spoolss_DriverInfo **info_p,
6523 fstring *list = NULL;
6524 union spoolss_DriverInfo *driver;
6525 union spoolss_DriverInfo *info = NULL;
6527 WERROR result = WERR_OK;
6532 for (version=0; version<DRIVER_MAX_VERSION; version++) {
6534 ndrivers = get_ntdrivers(&list, architecture, version);
6535 DEBUGADD(4,("we have:[%d] drivers in environment [%s] and version [%d]\n",
6536 ndrivers, architecture, version));
6538 if (ndrivers == -1) {
6539 result = WERR_NOMEM;
6543 if (ndrivers != 0) {
6544 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
6545 union spoolss_DriverInfo,
6548 DEBUG(0,("enumprinterdrivers_level1: "
6549 "failed to enlarge driver info buffer!\n"));
6550 result = WERR_NOMEM;
6555 for (i=0; i<ndrivers; i++) {
6556 DEBUGADD(5,("\tdriver: [%s]\n", list[i]));
6557 ZERO_STRUCT(driver);
6558 result = get_a_printer_driver(mem_ctx, &driver, 3, list[i],
6559 architecture, version);
6560 if (!W_ERROR_IS_OK(result)) {
6566 result = fill_printer_driver_info1(info, &info[count+i].info1,
6567 &driver->info3, servername,
6571 result = fill_printer_driver_info2(info, &info[count+i].info2,
6572 &driver->info3, servername);
6575 result = fill_printer_driver_info3(info, &info[count+i].info3,
6576 &driver->info3, servername);
6579 result = fill_printer_driver_info4(info, &info[count+i].info4,
6580 &driver->info3, servername);
6583 result = fill_printer_driver_info5(info, &info[count+i].info5,
6584 &driver->info3, servername);
6587 result = fill_printer_driver_info6(info, &info[count+i].info6,
6588 &driver->info3, servername);
6591 result = WERR_UNKNOWN_LEVEL;
6595 free_a_printer_driver(driver);
6597 if (!W_ERROR_IS_OK(result)) {
6609 if (!W_ERROR_IS_OK(result)) {
6620 /****************************************************************************
6621 Enumerates all printer drivers by level.
6622 ****************************************************************************/
6624 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
6625 const char *servername,
6626 const char *architecture,
6628 union spoolss_DriverInfo **info_p,
6632 WERROR result = WERR_OK;
6634 if (strequal(architecture, "all")) {
6636 for (a=0; archi_table[a].long_archi != NULL; a++) {
6638 union spoolss_DriverInfo *info = NULL;
6641 result = enumprinterdrivers_level_by_architecture(mem_ctx,
6643 archi_table[a].long_archi,
6647 if (!W_ERROR_IS_OK(result)) {
6651 for (i=0; i < count; i++) {
6652 ADD_TO_ARRAY(mem_ctx, union spoolss_DriverInfo,
6653 info[i], info_p, count_p);
6660 return enumprinterdrivers_level_by_architecture(mem_ctx,
6668 /****************************************************************************
6669 Enumerates all printer drivers at level 1.
6670 ****************************************************************************/
6672 static WERROR enumprinterdrivers_level1(TALLOC_CTX *mem_ctx,
6673 const char *servername,
6674 const char *architecture,
6675 union spoolss_DriverInfo **info_p,
6678 return enumprinterdrivers_level(mem_ctx, servername, architecture, 1,
6682 /****************************************************************************
6683 Enumerates all printer drivers at level 2.
6684 ****************************************************************************/
6686 static WERROR enumprinterdrivers_level2(TALLOC_CTX *mem_ctx,
6687 const char *servername,
6688 const char *architecture,
6689 union spoolss_DriverInfo **info_p,
6692 return enumprinterdrivers_level(mem_ctx, servername, architecture, 2,
6696 /****************************************************************************
6697 Enumerates all printer drivers at level 3.
6698 ****************************************************************************/
6700 static WERROR enumprinterdrivers_level3(TALLOC_CTX *mem_ctx,
6701 const char *servername,
6702 const char *architecture,
6703 union spoolss_DriverInfo **info_p,
6706 return enumprinterdrivers_level(mem_ctx, servername, architecture, 3,
6710 /****************************************************************************
6711 Enumerates all printer drivers at level 4.
6712 ****************************************************************************/
6714 static WERROR enumprinterdrivers_level4(TALLOC_CTX *mem_ctx,
6715 const char *servername,
6716 const char *architecture,
6717 union spoolss_DriverInfo **info_p,
6720 return enumprinterdrivers_level(mem_ctx, servername, architecture, 4,
6724 /****************************************************************************
6725 Enumerates all printer drivers at level 5.
6726 ****************************************************************************/
6728 static WERROR enumprinterdrivers_level5(TALLOC_CTX *mem_ctx,
6729 const char *servername,
6730 const char *architecture,
6731 union spoolss_DriverInfo **info_p,
6734 return enumprinterdrivers_level(mem_ctx, servername, architecture, 5,
6738 /****************************************************************************
6739 Enumerates all printer drivers at level 6.
6740 ****************************************************************************/
6742 static WERROR enumprinterdrivers_level6(TALLOC_CTX *mem_ctx,
6743 const char *servername,
6744 const char *architecture,
6745 union spoolss_DriverInfo **info_p,
6748 return enumprinterdrivers_level(mem_ctx, servername, architecture, 6,
6753 /****************************************************************
6754 _spoolss_EnumPrinterDrivers
6755 ****************************************************************/
6757 WERROR _spoolss_EnumPrinterDrivers(pipes_struct *p,
6758 struct spoolss_EnumPrinterDrivers *r)
6760 const char *cservername;
6763 /* that's an [in out] buffer */
6765 if (!r->in.buffer && (r->in.offered != 0)) {
6766 return WERR_INVALID_PARAM;
6769 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
6773 *r->out.info = NULL;
6775 cservername = canon_servername(r->in.server);
6777 if (!is_myname_or_ipaddr(cservername)) {
6778 return WERR_UNKNOWN_PRINTER_DRIVER;
6781 switch (r->in.level) {
6783 result = enumprinterdrivers_level1(p->mem_ctx, cservername,
6785 r->out.info, r->out.count);
6788 result = enumprinterdrivers_level2(p->mem_ctx, cservername,
6790 r->out.info, r->out.count);
6793 result = enumprinterdrivers_level3(p->mem_ctx, cservername,
6795 r->out.info, r->out.count);
6798 result = enumprinterdrivers_level4(p->mem_ctx, cservername,
6800 r->out.info, r->out.count);
6803 result = enumprinterdrivers_level5(p->mem_ctx, cservername,
6805 r->out.info, r->out.count);
6808 result = enumprinterdrivers_level6(p->mem_ctx, cservername,
6810 r->out.info, r->out.count);
6813 return WERR_UNKNOWN_LEVEL;
6816 if (!W_ERROR_IS_OK(result)) {
6820 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6821 spoolss_EnumPrinterDrivers, NULL,
6822 *r->out.info, r->in.level,
6824 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6825 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6827 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6830 /****************************************************************************
6831 ****************************************************************************/
6833 static WERROR fill_form_info_1(TALLOC_CTX *mem_ctx,
6834 struct spoolss_FormInfo1 *r,
6835 const nt_forms_struct *form)
6837 r->form_name = talloc_strdup(mem_ctx, form->name);
6838 W_ERROR_HAVE_NO_MEMORY(r->form_name);
6840 r->flags = form->flag;
6841 r->size.width = form->width;
6842 r->size.height = form->length;
6843 r->area.left = form->left;
6844 r->area.top = form->top;
6845 r->area.right = form->right;
6846 r->area.bottom = form->bottom;
6851 /****************************************************************
6852 spoolss_enumforms_level1
6853 ****************************************************************/
6855 static WERROR spoolss_enumforms_level1(TALLOC_CTX *mem_ctx,
6856 const nt_forms_struct *builtin_forms,
6857 uint32_t num_builtin_forms,
6858 const nt_forms_struct *user_forms,
6859 uint32_t num_user_forms,
6860 union spoolss_FormInfo **info_p,
6863 union spoolss_FormInfo *info;
6864 WERROR result = WERR_OK;
6867 *count = num_builtin_forms + num_user_forms;
6869 info = TALLOC_ARRAY(mem_ctx, union spoolss_FormInfo, *count);
6870 W_ERROR_HAVE_NO_MEMORY(info);
6872 /* construct the list of form structures */
6873 for (i=0; i<num_builtin_forms; i++) {
6874 DEBUGADD(6,("Filling builtin form number [%d]\n",i));
6875 result = fill_form_info_1(info, &info[i].info1,
6877 if (!W_ERROR_IS_OK(result)) {
6882 for (i=0; i<num_user_forms; i++) {
6883 DEBUGADD(6,("Filling user form number [%d]\n",i));
6884 result = fill_form_info_1(info, &info[i+num_builtin_forms].info1,
6886 if (!W_ERROR_IS_OK(result)) {
6892 if (!W_ERROR_IS_OK(result)) {
6903 /****************************************************************
6905 ****************************************************************/
6907 WERROR _spoolss_EnumForms(pipes_struct *p,
6908 struct spoolss_EnumForms *r)
6911 nt_forms_struct *user_forms = NULL;
6912 nt_forms_struct *builtin_forms = NULL;
6913 uint32_t num_user_forms;
6914 uint32_t num_builtin_forms;
6918 *r->out.info = NULL;
6920 /* that's an [in out] buffer */
6922 if (!r->in.buffer && (r->in.offered != 0) ) {
6923 return WERR_INVALID_PARAM;
6926 DEBUG(4,("_spoolss_EnumForms\n"));
6927 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
6928 DEBUGADD(5,("Info level [%d]\n", r->in.level));
6930 num_builtin_forms = get_builtin_ntforms(&builtin_forms);
6931 DEBUGADD(5,("Number of builtin forms [%d]\n", num_builtin_forms));
6932 num_user_forms = get_ntforms(&user_forms);
6933 DEBUGADD(5,("Number of user forms [%d]\n", num_user_forms));
6935 if (num_user_forms + num_builtin_forms == 0) {
6936 SAFE_FREE(builtin_forms);
6937 SAFE_FREE(user_forms);
6938 return WERR_NO_MORE_ITEMS;
6941 switch (r->in.level) {
6943 result = spoolss_enumforms_level1(p->mem_ctx,
6952 result = WERR_UNKNOWN_LEVEL;
6956 SAFE_FREE(user_forms);
6957 SAFE_FREE(builtin_forms);
6959 if (!W_ERROR_IS_OK(result)) {
6963 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6964 spoolss_EnumForms, NULL,
6965 *r->out.info, r->in.level,
6967 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6968 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6970 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6973 /****************************************************************
6974 ****************************************************************/
6976 static WERROR find_form_byname(const char *name,
6977 nt_forms_struct *form)
6979 nt_forms_struct *list = NULL;
6980 int num_forms = 0, i = 0;
6982 if (get_a_builtin_ntform_by_string(name, form)) {
6986 num_forms = get_ntforms(&list);
6987 DEBUGADD(5,("Number of forms [%d]\n", num_forms));
6989 if (num_forms == 0) {
6993 /* Check if the requested name is in the list of form structures */
6994 for (i = 0; i < num_forms; i++) {
6996 DEBUG(4,("checking form %s (want %s)\n", list[i].name, name));
6998 if (strequal(name, list[i].name)) {
6999 DEBUGADD(6,("Found form %s number [%d]\n", name, i));
7011 /****************************************************************
7013 ****************************************************************/
7015 WERROR _spoolss_GetForm(pipes_struct *p,
7016 struct spoolss_GetForm *r)
7019 nt_forms_struct form;
7021 /* that's an [in out] buffer */
7023 if (!r->in.buffer && (r->in.offered != 0)) {
7024 return WERR_INVALID_PARAM;
7027 DEBUG(4,("_spoolss_GetForm\n"));
7028 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7029 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7031 result = find_form_byname(r->in.form_name, &form);
7032 if (!W_ERROR_IS_OK(result)) {
7033 TALLOC_FREE(r->out.info);
7037 switch (r->in.level) {
7039 result = fill_form_info_1(p->mem_ctx,
7040 &r->out.info->info1,
7045 result = WERR_UNKNOWN_LEVEL;
7049 if (!W_ERROR_IS_OK(result)) {
7050 TALLOC_FREE(r->out.info);
7054 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo, NULL,
7055 r->out.info, r->in.level);
7056 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7058 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7061 /****************************************************************************
7062 ****************************************************************************/
7064 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
7065 struct spoolss_PortInfo1 *r,
7068 r->port_name = talloc_strdup(mem_ctx, name);
7069 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7074 /****************************************************************************
7075 TODO: This probably needs distinguish between TCP/IP and Local ports
7077 ****************************************************************************/
7079 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
7080 struct spoolss_PortInfo2 *r,
7083 r->port_name = talloc_strdup(mem_ctx, name);
7084 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7086 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
7087 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
7089 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
7090 W_ERROR_HAVE_NO_MEMORY(r->description);
7092 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
7099 /****************************************************************************
7100 wrapper around the enumer ports command
7101 ****************************************************************************/
7103 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
7105 char *cmd = lp_enumports_cmd();
7106 char **qlines = NULL;
7107 char *command = NULL;
7115 /* if no hook then just fill in the default port */
7118 if (!(qlines = TALLOC_ARRAY( NULL, char*, 2 ))) {
7121 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7122 TALLOC_FREE(qlines);
7129 /* we have a valid enumport command */
7131 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7136 DEBUG(10,("Running [%s]\n", command));
7137 ret = smbrun(command, &fd);
7138 DEBUG(10,("Returned [%d]\n", ret));
7139 TALLOC_FREE(command);
7144 return WERR_ACCESS_DENIED;
7148 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7149 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7159 /****************************************************************************
7161 ****************************************************************************/
7163 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7164 union spoolss_PortInfo **info_p,
7167 union spoolss_PortInfo *info = NULL;
7169 WERROR result = WERR_OK;
7170 char **qlines = NULL;
7173 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7174 if (!W_ERROR_IS_OK(result)) {
7179 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7181 DEBUG(10,("Returning WERR_NOMEM\n"));
7182 result = WERR_NOMEM;
7186 for (i=0; i<numlines; i++) {
7187 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7188 result = fill_port_1(info, &info[i].info1, qlines[i]);
7189 if (!W_ERROR_IS_OK(result)) {
7194 TALLOC_FREE(qlines);
7197 if (!W_ERROR_IS_OK(result)) {
7199 TALLOC_FREE(qlines);
7211 /****************************************************************************
7213 ****************************************************************************/
7215 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7216 union spoolss_PortInfo **info_p,
7219 union spoolss_PortInfo *info = NULL;
7221 WERROR result = WERR_OK;
7222 char **qlines = NULL;
7225 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7226 if (!W_ERROR_IS_OK(result)) {
7231 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7233 DEBUG(10,("Returning WERR_NOMEM\n"));
7234 result = WERR_NOMEM;
7238 for (i=0; i<numlines; i++) {
7239 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7240 result = fill_port_2(info, &info[i].info2, qlines[i]);
7241 if (!W_ERROR_IS_OK(result)) {
7246 TALLOC_FREE(qlines);
7249 if (!W_ERROR_IS_OK(result)) {
7251 TALLOC_FREE(qlines);
7263 /****************************************************************
7265 ****************************************************************/
7267 WERROR _spoolss_EnumPorts(pipes_struct *p,
7268 struct spoolss_EnumPorts *r)
7272 /* that's an [in out] buffer */
7274 if (!r->in.buffer && (r->in.offered != 0)) {
7275 return WERR_INVALID_PARAM;
7278 DEBUG(4,("_spoolss_EnumPorts\n"));
7282 *r->out.info = NULL;
7284 switch (r->in.level) {
7286 result = enumports_level_1(p->mem_ctx, r->out.info,
7290 result = enumports_level_2(p->mem_ctx, r->out.info,
7294 return WERR_UNKNOWN_LEVEL;
7297 if (!W_ERROR_IS_OK(result)) {
7301 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7302 spoolss_EnumPorts, NULL,
7303 *r->out.info, r->in.level,
7305 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7306 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7308 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7311 /****************************************************************************
7312 ****************************************************************************/
7314 static WERROR spoolss_addprinterex_level_2(pipes_struct *p,
7316 struct spoolss_SetPrinterInfoCtr *info_ctr,
7317 struct spoolss_DeviceMode *devmode,
7318 struct security_descriptor *sec_desc,
7319 struct spoolss_UserLevelCtr *user_ctr,
7320 struct policy_handle *handle)
7322 NT_PRINTER_INFO_LEVEL *printer = NULL;
7325 WERROR err = WERR_OK;
7327 if ( !(printer = TALLOC_ZERO_P(NULL, NT_PRINTER_INFO_LEVEL)) ) {
7328 DEBUG(0,("spoolss_addprinterex_level_2: malloc fail.\n"));
7332 /* convert from UNICODE to ASCII - this allocates the info_2 struct inside *printer.*/
7333 if (!convert_printer_info(info_ctr, printer)) {
7334 free_a_printer(&printer, 2);
7338 /* check to see if the printer already exists */
7340 if ((snum = print_queue_snum(printer->info_2->sharename)) != -1) {
7341 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7342 printer->info_2->sharename));
7343 free_a_printer(&printer, 2);
7344 return WERR_PRINTER_ALREADY_EXISTS;
7347 /* FIXME!!! smbd should check to see if the driver is installed before
7348 trying to add a printer like this --jerry */
7350 if (*lp_addprinter_cmd() ) {
7351 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
7353 free_a_printer(&printer,2);
7354 return WERR_ACCESS_DENIED;
7357 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
7358 "smb.conf parameter \"addprinter command\" is defined. This"
7359 "parameter must exist for this call to succeed\n",
7360 printer->info_2->sharename ));
7363 /* use our primary netbios name since get_a_printer() will convert
7364 it to what the client expects on a case by case basis */
7366 slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname(),
7367 printer->info_2->sharename);
7370 if ((snum = print_queue_snum(printer->info_2->sharename)) == -1) {
7371 free_a_printer(&printer,2);
7372 return WERR_ACCESS_DENIED;
7375 /* you must be a printer admin to add a new printer */
7376 if (!print_access_check(p->server_info, snum, PRINTER_ACCESS_ADMINISTER)) {
7377 free_a_printer(&printer,2);
7378 return WERR_ACCESS_DENIED;
7382 * Do sanity check on the requested changes for Samba.
7385 if (!check_printer_ok(printer->info_2, snum)) {
7386 free_a_printer(&printer,2);
7387 return WERR_INVALID_PARAM;
7391 * When a printer is created, the drivername bound to the printer is used
7392 * to lookup previously saved driver initialization info, which is then
7393 * bound to the new printer, simulating what happens in the Windows arch.
7398 set_driver_init(printer, 2);
7402 /* A valid devmode was included, convert and link it
7404 DEBUGADD(10, ("spoolss_addprinterex_level_2: devmode included, converting\n"));
7406 if (!convert_devicemode(printer->info_2->printername, devmode,
7407 &printer->info_2->devmode)) {
7412 /* write the ASCII on disk */
7413 err = mod_a_printer(printer, 2);
7414 if (!W_ERROR_IS_OK(err)) {
7415 free_a_printer(&printer,2);
7419 if (!open_printer_hnd(p, handle, name, PRINTER_ACCESS_ADMINISTER)) {
7420 /* Handle open failed - remove addition. */
7421 del_a_printer(printer->info_2->sharename);
7422 free_a_printer(&printer,2);
7423 ZERO_STRUCTP(handle);
7424 return WERR_ACCESS_DENIED;
7427 update_c_setprinter(false);
7428 free_a_printer(&printer,2);
7433 /****************************************************************
7434 _spoolss_AddPrinterEx
7435 ****************************************************************/
7437 WERROR _spoolss_AddPrinterEx(pipes_struct *p,
7438 struct spoolss_AddPrinterEx *r)
7440 switch (r->in.info_ctr->level) {
7442 /* we don't handle yet */
7443 /* but I know what to do ... */
7444 return WERR_UNKNOWN_LEVEL;
7446 return spoolss_addprinterex_level_2(p, r->in.server,
7448 r->in.devmode_ctr->devmode,
7449 r->in.secdesc_ctr->sd,
7450 r->in.userlevel_ctr,
7453 return WERR_UNKNOWN_LEVEL;
7457 /****************************************************************
7459 ****************************************************************/
7461 WERROR _spoolss_AddPrinter(pipes_struct *p,
7462 struct spoolss_AddPrinter *r)
7464 struct spoolss_AddPrinterEx a;
7465 struct spoolss_UserLevelCtr userlevel_ctr;
7467 ZERO_STRUCT(userlevel_ctr);
7469 userlevel_ctr.level = 1;
7471 a.in.server = r->in.server;
7472 a.in.info_ctr = r->in.info_ctr;
7473 a.in.devmode_ctr = r->in.devmode_ctr;
7474 a.in.secdesc_ctr = r->in.secdesc_ctr;
7475 a.in.userlevel_ctr = &userlevel_ctr;
7476 a.out.handle = r->out.handle;
7478 return _spoolss_AddPrinterEx(p, &a);
7481 /****************************************************************
7482 _spoolss_AddPrinterDriver
7483 ****************************************************************/
7485 WERROR _spoolss_AddPrinterDriver(pipes_struct *p,
7486 struct spoolss_AddPrinterDriver *r)
7488 WERROR err = WERR_OK;
7489 char *driver_name = NULL;
7493 switch (p->hdr_req.opnum) {
7494 case NDR_SPOOLSS_ADDPRINTERDRIVER:
7495 fn = "_spoolss_AddPrinterDriver";
7497 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
7498 fn = "_spoolss_AddPrinterDriverEx";
7501 return WERR_INVALID_PARAM;
7506 if (r->in.info_ctr->level != 3 && r->in.info_ctr->level != 6) {
7507 /* Clever hack from Martin Zielinski <mz@seh.de>
7508 * to allow downgrade from level 8 (Vista).
7510 DEBUG(0,("%s: level %d not yet implemented\n", fn,
7511 r->in.info_ctr->level));
7512 return WERR_UNKNOWN_LEVEL;
7515 DEBUG(5,("Cleaning driver's information\n"));
7516 err = clean_up_driver_struct(p, r->in.info_ctr);
7517 if (!W_ERROR_IS_OK(err))
7520 DEBUG(5,("Moving driver to final destination\n"));
7521 if( !W_ERROR_IS_OK(err = move_driver_to_download_area(p, r->in.info_ctr,
7526 if (add_a_printer_driver(p->mem_ctx, r->in.info_ctr, &driver_name, &version)!=0) {
7527 err = WERR_ACCESS_DENIED;
7532 * I think this is where he DrvUpgradePrinter() hook would be
7533 * be called in a driver's interface DLL on a Windows NT 4.0/2k
7534 * server. Right now, we just need to send ourselves a message
7535 * to update each printer bound to this driver. --jerry
7538 if (!srv_spoolss_drv_upgrade_printer(driver_name)) {
7539 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
7544 * Based on the version (e.g. driver destination dir: 0=9x,2=Nt/2k,3=2k/Xp),
7545 * decide if the driver init data should be deleted. The rules are:
7546 * 1) never delete init data if it is a 9x driver, they don't use it anyway
7547 * 2) delete init data only if there is no 2k/Xp driver
7548 * 3) always delete init data
7549 * The generalized rule is always use init data from the highest order driver.
7550 * It is necessary to follow the driver install by an initialization step to
7551 * finish off this process.
7556 * 9x printer driver - never delete init data
7559 DEBUG(10,("%s: init data not deleted for 9x driver [%s]\n",
7564 * Nt or 2k (compatiblity mode) printer driver - only delete init data if
7565 * there is no 2k/Xp driver init data for this driver name.
7569 union spoolss_DriverInfo *driver1;
7571 if (!W_ERROR_IS_OK(get_a_printer_driver(p->mem_ctx, &driver1, 3, driver_name, "Windows NT x86", 3))) {
7573 * No 2k/Xp driver found, delete init data (if any) for the new Nt driver.
7575 if (!del_driver_init(driver_name))
7576 DEBUG(6,("%s: del_driver_init(%s) Nt failed!\n",
7580 * a 2k/Xp driver was found, don't delete init data because Nt driver will use it.
7582 free_a_printer_driver(driver1);
7583 DEBUG(10,("%s: init data not deleted for Nt driver [%s]\n",
7590 * 2k or Xp printer driver - always delete init data
7593 if (!del_driver_init(driver_name))
7594 DEBUG(6,("%s: del_driver_init(%s) 2k/Xp failed!\n",
7599 DEBUG(0,("%s: invalid level=%d\n", fn,
7600 r->in.info_ctr->level));
7609 /****************************************************************
7610 _spoolss_AddPrinterDriverEx
7611 ****************************************************************/
7613 WERROR _spoolss_AddPrinterDriverEx(pipes_struct *p,
7614 struct spoolss_AddPrinterDriverEx *r)
7616 struct spoolss_AddPrinterDriver a;
7619 * we only support the semantics of AddPrinterDriver()
7620 * i.e. only copy files that are newer than existing ones
7623 if (r->in.flags != APD_COPY_NEW_FILES) {
7624 return WERR_ACCESS_DENIED;
7627 a.in.servername = r->in.servername;
7628 a.in.info_ctr = r->in.info_ctr;
7630 return _spoolss_AddPrinterDriver(p, &a);
7633 /****************************************************************************
7634 ****************************************************************************/
7636 struct _spoolss_paths {
7642 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
7644 static const struct _spoolss_paths spoolss_paths[]= {
7645 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
7646 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
7649 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
7650 const char *servername,
7651 const char *environment,
7655 const char *pservername = NULL;
7656 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
7657 const char *short_archi;
7661 /* environment may be empty */
7662 if (environment && strlen(environment)) {
7663 long_archi = environment;
7666 /* servername may be empty */
7667 if (servername && strlen(servername)) {
7668 pservername = canon_servername(servername);
7670 if (!is_myname_or_ipaddr(pservername)) {
7671 return WERR_INVALID_PARAM;
7675 if (!(short_archi = get_short_archi(long_archi))) {
7676 return WERR_INVALID_ENVIRONMENT;
7679 switch (component) {
7680 case SPOOLSS_PRTPROCS_PATH:
7681 case SPOOLSS_DRIVER_PATH:
7683 *path = talloc_asprintf(mem_ctx,
7686 spoolss_paths[component].share,
7689 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
7690 SPOOLSS_DEFAULT_SERVER_PATH,
7691 spoolss_paths[component].dir,
7696 return WERR_INVALID_PARAM;
7706 /****************************************************************************
7707 ****************************************************************************/
7709 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
7710 const char *servername,
7711 const char *environment,
7712 struct spoolss_DriverDirectoryInfo1 *r)
7717 werr = compose_spoolss_server_path(mem_ctx,
7720 SPOOLSS_DRIVER_PATH,
7722 if (!W_ERROR_IS_OK(werr)) {
7726 DEBUG(4,("printer driver directory: [%s]\n", path));
7728 r->directory_name = path;
7733 /****************************************************************
7734 _spoolss_GetPrinterDriverDirectory
7735 ****************************************************************/
7737 WERROR _spoolss_GetPrinterDriverDirectory(pipes_struct *p,
7738 struct spoolss_GetPrinterDriverDirectory *r)
7742 /* that's an [in out] buffer */
7744 if (!r->in.buffer && (r->in.offered != 0)) {
7745 return WERR_INVALID_PARAM;
7748 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
7753 /* r->in.level is ignored */
7755 werror = getprinterdriverdir_level_1(p->mem_ctx,
7758 &r->out.info->info1);
7759 if (!W_ERROR_IS_OK(werror)) {
7760 TALLOC_FREE(r->out.info);
7764 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo, NULL,
7765 r->out.info, r->in.level);
7766 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7768 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7771 /****************************************************************
7772 _spoolss_EnumPrinterData
7773 ****************************************************************/
7775 WERROR _spoolss_EnumPrinterData(pipes_struct *p,
7776 struct spoolss_EnumPrinterData *r)
7778 NT_PRINTER_INFO_LEVEL *printer = NULL;
7779 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7782 struct regval_blob *val = NULL;
7783 NT_PRINTER_DATA *p_data;
7784 int i, key_index, num_values;
7787 *r->out.value_needed = 0;
7788 *r->out.type = REG_NONE;
7789 *r->out.data_needed = 0;
7791 DEBUG(5,("_spoolss_EnumPrinterData\n"));
7794 DEBUG(2,("_spoolss_EnumPrinterData: Invalid handle (%s:%u:%u).\n",
7795 OUR_HANDLE(r->in.handle)));
7799 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7803 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
7804 if (!W_ERROR_IS_OK(result)) {
7808 p_data = printer->info_2->data;
7809 key_index = lookup_printerkey( p_data, SPOOL_PRINTERDATA_KEY );
7814 * The NT machine wants to know the biggest size of value and data
7816 * cf: MSDN EnumPrinterData remark section
7819 if (!r->in.value_offered && !r->in.data_offered && (key_index != -1)) {
7821 uint32_t biggest_valuesize = 0;
7822 uint32_t biggest_datasize = 0;
7824 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
7826 num_values = regval_ctr_numvals( p_data->keys[key_index].values );
7828 for ( i=0; i<num_values; i++ )
7830 val = regval_ctr_specific_value( p_data->keys[key_index].values, i );
7832 name_length = strlen(val->valuename);
7833 if ( strlen(val->valuename) > biggest_valuesize )
7834 biggest_valuesize = name_length;
7836 if ( val->size > biggest_datasize )
7837 biggest_datasize = val->size;
7839 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
7843 /* the value is an UNICODE string but real_value_size is the length
7844 in bytes including the trailing 0 */
7846 *r->out.value_needed = 2 * (1 + biggest_valuesize);
7847 *r->out.data_needed = biggest_datasize;
7849 DEBUG(6,("final values: [%d], [%d]\n",
7850 *r->out.value_needed, *r->out.data_needed));
7856 * the value len is wrong in NT sp3
7857 * that's the number of bytes not the number of unicode chars
7860 if (key_index != -1) {
7861 val = regval_ctr_specific_value(p_data->keys[key_index].values,
7867 /* out_value should default to "" or else NT4 has
7868 problems unmarshalling the response */
7870 if (r->in.value_offered) {
7871 *r->out.value_needed = 1;
7872 r->out.value_name = talloc_strdup(r, "");
7873 if (!r->out.value_name) {
7874 result = WERR_NOMEM;
7878 r->out.value_name = NULL;
7879 *r->out.value_needed = 0;
7882 /* the data is counted in bytes */
7884 *r->out.data_needed = r->in.data_offered;
7886 result = WERR_NO_MORE_ITEMS;
7890 * - counted in bytes in the request
7891 * - counted in UNICODE chars in the max reply
7892 * - counted in bytes in the real size
7894 * take a pause *before* coding not *during* coding
7898 if (r->in.value_offered) {
7899 r->out.value_name = talloc_strdup(r, regval_name(val));
7900 if (!r->out.value_name) {
7901 result = WERR_NOMEM;
7904 *r->out.value_needed = strlen_m(regval_name(val));
7906 r->out.value_name = NULL;
7907 *r->out.value_needed = 0;
7912 *r->out.type = regval_type(val);
7914 /* data - counted in bytes */
7916 if (r->out.data && regval_size(val)) {
7917 memcpy(r->out.data, regval_data_p(val), regval_size(val));
7920 *r->out.data_needed = regval_size(val);
7924 free_a_printer(&printer, 2);
7928 /****************************************************************
7929 _spoolss_SetPrinterData
7930 ****************************************************************/
7932 WERROR _spoolss_SetPrinterData(pipes_struct *p,
7933 struct spoolss_SetPrinterData *r)
7935 NT_PRINTER_INFO_LEVEL *printer = NULL;
7937 WERROR result = WERR_OK;
7938 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7941 DEBUG(5,("_spoolss_SetPrinterData\n"));
7944 DEBUG(2,("_spoolss_SetPrinterData: Invalid handle (%s:%u:%u).\n",
7945 OUR_HANDLE(r->in.handle)));
7949 if (Printer->printer_type == SPLHND_SERVER) {
7950 DEBUG(10,("_spoolss_SetPrinterData: "
7951 "Not implemented for server handles yet\n"));
7952 return WERR_INVALID_PARAM;
7955 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7960 * Access check : NT returns "access denied" if you make a
7961 * SetPrinterData call without the necessary privildge.
7962 * we were originally returning OK if nothing changed
7963 * which made Win2k issue **a lot** of SetPrinterData
7964 * when connecting to a printer --jerry
7967 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
7968 DEBUG(3,("_spoolss_SetPrinterData: "
7969 "change denied by handle access permissions\n"));
7970 result = WERR_ACCESS_DENIED;
7974 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
7975 if (!W_ERROR_IS_OK(result)) {
7979 result = push_spoolss_PrinterData(p->mem_ctx, &blob,
7980 r->in.type, &r->in.data);
7981 if (!W_ERROR_IS_OK(result)) {
7986 * When client side code sets a magic printer data key, detect it and save
7987 * the current printer data and the magic key's data (its the DEVMODE) for
7988 * future printer/driver initializations.
7990 if ((r->in.type == REG_BINARY) && strequal(r->in.value_name, PHANTOM_DEVMODE_KEY)) {
7991 /* Set devmode and printer initialization info */
7992 result = save_driver_init(printer, 2, blob.data, blob.length);
7994 srv_spoolss_reset_printerdata(printer->info_2->drivername);
7999 result = set_printer_dataex(printer, SPOOL_PRINTERDATA_KEY,
8000 r->in.value_name, r->in.type,
8001 blob.data, blob.length);
8002 if (W_ERROR_IS_OK(result)) {
8003 result = mod_a_printer(printer, 2);
8007 free_a_printer(&printer, 2);
8012 /****************************************************************
8013 _spoolss_ResetPrinter
8014 ****************************************************************/
8016 WERROR _spoolss_ResetPrinter(pipes_struct *p,
8017 struct spoolss_ResetPrinter *r)
8019 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8022 DEBUG(5,("_spoolss_ResetPrinter\n"));
8025 * All we do is to check to see if the handle and queue is valid.
8026 * This call really doesn't mean anything to us because we only
8027 * support RAW printing. --jerry
8031 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8032 OUR_HANDLE(r->in.handle)));
8036 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8040 /* blindly return success */
8044 /****************************************************************
8045 _spoolss_DeletePrinterData
8046 ****************************************************************/
8048 WERROR _spoolss_DeletePrinterData(pipes_struct *p,
8049 struct spoolss_DeletePrinterData *r)
8051 NT_PRINTER_INFO_LEVEL *printer = NULL;
8053 WERROR status = WERR_OK;
8054 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8056 DEBUG(5,("_spoolss_DeletePrinterData\n"));
8059 DEBUG(2,("_spoolss_DeletePrinterData: Invalid handle (%s:%u:%u).\n",
8060 OUR_HANDLE(r->in.handle)));
8064 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8067 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8068 DEBUG(3, ("_spoolss_DeletePrinterData: "
8069 "printer properties change denied by handle\n"));
8070 return WERR_ACCESS_DENIED;
8073 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8074 if (!W_ERROR_IS_OK(status))
8077 if (!r->in.value_name) {
8078 free_a_printer(&printer, 2);
8082 status = delete_printer_dataex( printer, SPOOL_PRINTERDATA_KEY,
8085 if ( W_ERROR_IS_OK(status) )
8086 mod_a_printer( printer, 2 );
8088 free_a_printer(&printer, 2);
8093 /****************************************************************
8095 ****************************************************************/
8097 WERROR _spoolss_AddForm(pipes_struct *p,
8098 struct spoolss_AddForm *r)
8100 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8101 nt_forms_struct tmpForm;
8103 WERROR status = WERR_OK;
8104 NT_PRINTER_INFO_LEVEL *printer = NULL;
8105 SE_PRIV se_printop = SE_PRINT_OPERATOR;
8108 nt_forms_struct *list=NULL;
8109 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8111 DEBUG(5,("_spoolss_AddForm\n"));
8114 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8115 OUR_HANDLE(r->in.handle)));
8120 /* forms can be added on printer of on the print server handle */
8122 if ( Printer->printer_type == SPLHND_PRINTER )
8124 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8127 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8128 if (!W_ERROR_IS_OK(status))
8132 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8133 and not a printer admin, then fail */
8135 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8136 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8137 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8139 p->server_info->ptok,
8140 lp_printer_admin(snum))) {
8141 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
8142 return WERR_ACCESS_DENIED;
8145 /* can't add if builtin */
8147 if (get_a_builtin_ntform_by_string(form->form_name, &tmpForm)) {
8148 status = WERR_FILE_EXISTS;
8152 count = get_ntforms(&list);
8154 if(!add_a_form(&list, form, &count)) {
8155 status = WERR_NOMEM;
8160 write_ntforms(&list, count);
8164 * ChangeID must always be set if this is a printer
8167 if ( Printer->printer_type == SPLHND_PRINTER )
8168 status = mod_a_printer(printer, 2);
8172 free_a_printer(&printer, 2);
8178 /****************************************************************
8180 ****************************************************************/
8182 WERROR _spoolss_DeleteForm(pipes_struct *p,
8183 struct spoolss_DeleteForm *r)
8185 const char *form_name = r->in.form_name;
8186 nt_forms_struct tmpForm;
8188 nt_forms_struct *list=NULL;
8189 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8191 WERROR status = WERR_OK;
8192 NT_PRINTER_INFO_LEVEL *printer = NULL;
8193 SE_PRIV se_printop = SE_PRINT_OPERATOR;
8196 DEBUG(5,("_spoolss_DeleteForm\n"));
8199 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8200 OUR_HANDLE(r->in.handle)));
8204 /* forms can be deleted on printer of on the print server handle */
8206 if ( Printer->printer_type == SPLHND_PRINTER )
8208 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8211 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8212 if (!W_ERROR_IS_OK(status))
8216 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8217 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8218 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8220 p->server_info->ptok,
8221 lp_printer_admin(snum))) {
8222 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8223 return WERR_ACCESS_DENIED;
8227 /* can't delete if builtin */
8229 if (get_a_builtin_ntform_by_string(form_name,&tmpForm)) {
8230 status = WERR_INVALID_PARAM;
8234 count = get_ntforms(&list);
8237 ret = delete_a_form(&list, form_name, &count, &status);
8244 * ChangeID must always be set if this is a printer
8247 if ( Printer->printer_type == SPLHND_PRINTER )
8248 status = mod_a_printer(printer, 2);
8252 free_a_printer(&printer, 2);
8258 /****************************************************************
8260 ****************************************************************/
8262 WERROR _spoolss_SetForm(pipes_struct *p,
8263 struct spoolss_SetForm *r)
8265 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8266 nt_forms_struct tmpForm;
8268 WERROR status = WERR_OK;
8269 NT_PRINTER_INFO_LEVEL *printer = NULL;
8270 SE_PRIV se_printop = SE_PRINT_OPERATOR;
8273 nt_forms_struct *list=NULL;
8274 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8276 DEBUG(5,("_spoolss_SetForm\n"));
8279 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8280 OUR_HANDLE(r->in.handle)));
8284 /* forms can be modified on printer of on the print server handle */
8286 if ( Printer->printer_type == SPLHND_PRINTER )
8288 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8291 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8292 if (!W_ERROR_IS_OK(status))
8296 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8297 and not a printer admin, then fail */
8299 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8300 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8301 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8303 p->server_info->ptok,
8304 lp_printer_admin(snum))) {
8305 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8306 return WERR_ACCESS_DENIED;
8309 /* can't set if builtin */
8310 if (get_a_builtin_ntform_by_string(form->form_name, &tmpForm)) {
8311 status = WERR_INVALID_PARAM;
8315 count = get_ntforms(&list);
8316 update_a_form(&list, form, count);
8318 write_ntforms(&list, count);
8322 * ChangeID must always be set if this is a printer
8325 if ( Printer->printer_type == SPLHND_PRINTER )
8326 status = mod_a_printer(printer, 2);
8331 free_a_printer(&printer, 2);
8337 /****************************************************************************
8338 fill_print_processor1
8339 ****************************************************************************/
8341 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8342 struct spoolss_PrintProcessorInfo1 *r,
8343 const char *print_processor_name)
8345 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8346 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8351 /****************************************************************************
8352 enumprintprocessors level 1.
8353 ****************************************************************************/
8355 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8356 union spoolss_PrintProcessorInfo **info_p,
8359 union spoolss_PrintProcessorInfo *info;
8362 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8363 W_ERROR_HAVE_NO_MEMORY(info);
8367 result = fill_print_processor1(info, &info[0].info1, "winprint");
8368 if (!W_ERROR_IS_OK(result)) {
8373 if (!W_ERROR_IS_OK(result)) {
8384 /****************************************************************
8385 _spoolss_EnumPrintProcessors
8386 ****************************************************************/
8388 WERROR _spoolss_EnumPrintProcessors(pipes_struct *p,
8389 struct spoolss_EnumPrintProcessors *r)
8393 /* that's an [in out] buffer */
8395 if (!r->in.buffer && (r->in.offered != 0)) {
8396 return WERR_INVALID_PARAM;
8399 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8402 * Enumerate the print processors ...
8404 * Just reply with "winprint", to keep NT happy
8405 * and I can use my nice printer checker.
8410 *r->out.info = NULL;
8412 switch (r->in.level) {
8414 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8418 return WERR_UNKNOWN_LEVEL;
8421 if (!W_ERROR_IS_OK(result)) {
8425 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8426 spoolss_EnumPrintProcessors, NULL,
8427 *r->out.info, r->in.level,
8429 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8430 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8432 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8435 /****************************************************************************
8436 fill_printprocdatatype1
8437 ****************************************************************************/
8439 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8440 struct spoolss_PrintProcDataTypesInfo1 *r,
8441 const char *name_array)
8443 r->name_array = talloc_strdup(mem_ctx, name_array);
8444 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8449 /****************************************************************************
8450 enumprintprocdatatypes level 1.
8451 ****************************************************************************/
8453 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8454 union spoolss_PrintProcDataTypesInfo **info_p,
8458 union spoolss_PrintProcDataTypesInfo *info;
8460 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8461 W_ERROR_HAVE_NO_MEMORY(info);
8465 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
8466 if (!W_ERROR_IS_OK(result)) {
8471 if (!W_ERROR_IS_OK(result)) {
8482 /****************************************************************
8483 _spoolss_EnumPrintProcDataTypes
8484 ****************************************************************/
8486 WERROR _spoolss_EnumPrintProcDataTypes(pipes_struct *p,
8487 struct spoolss_EnumPrintProcDataTypes *r)
8491 /* that's an [in out] buffer */
8493 if (!r->in.buffer && (r->in.offered != 0)) {
8494 return WERR_INVALID_PARAM;
8497 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8501 *r->out.info = NULL;
8503 switch (r->in.level) {
8505 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
8509 return WERR_UNKNOWN_LEVEL;
8512 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8513 spoolss_EnumPrintProcDataTypes, NULL,
8514 *r->out.info, r->in.level,
8516 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8517 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8519 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8522 /****************************************************************************
8524 ****************************************************************************/
8526 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
8527 struct spoolss_MonitorInfo1 *r,
8528 const char *monitor_name)
8530 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8531 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8536 /****************************************************************************
8538 ****************************************************************************/
8540 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
8541 struct spoolss_MonitorInfo2 *r,
8542 const char *monitor_name,
8543 const char *environment,
8544 const char *dll_name)
8546 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8547 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8548 r->environment = talloc_strdup(mem_ctx, environment);
8549 W_ERROR_HAVE_NO_MEMORY(r->environment);
8550 r->dll_name = talloc_strdup(mem_ctx, dll_name);
8551 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
8556 /****************************************************************************
8557 enumprintmonitors level 1.
8558 ****************************************************************************/
8560 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
8561 union spoolss_MonitorInfo **info_p,
8564 union spoolss_MonitorInfo *info;
8565 WERROR result = WERR_OK;
8567 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8568 W_ERROR_HAVE_NO_MEMORY(info);
8572 result = fill_monitor_1(info, &info[0].info1,
8574 if (!W_ERROR_IS_OK(result)) {
8578 result = fill_monitor_1(info, &info[1].info1,
8580 if (!W_ERROR_IS_OK(result)) {
8585 if (!W_ERROR_IS_OK(result)) {
8596 /****************************************************************************
8597 enumprintmonitors level 2.
8598 ****************************************************************************/
8600 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
8601 union spoolss_MonitorInfo **info_p,
8604 union spoolss_MonitorInfo *info;
8605 WERROR result = WERR_OK;
8607 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8608 W_ERROR_HAVE_NO_MEMORY(info);
8612 result = fill_monitor_2(info, &info[0].info2,
8614 "Windows NT X86", /* FIXME */
8616 if (!W_ERROR_IS_OK(result)) {
8620 result = fill_monitor_2(info, &info[1].info2,
8622 "Windows NT X86", /* FIXME */
8624 if (!W_ERROR_IS_OK(result)) {
8629 if (!W_ERROR_IS_OK(result)) {
8640 /****************************************************************
8641 _spoolss_EnumMonitors
8642 ****************************************************************/
8644 WERROR _spoolss_EnumMonitors(pipes_struct *p,
8645 struct spoolss_EnumMonitors *r)
8649 /* that's an [in out] buffer */
8651 if (!r->in.buffer && (r->in.offered != 0)) {
8652 return WERR_INVALID_PARAM;
8655 DEBUG(5,("_spoolss_EnumMonitors\n"));
8658 * Enumerate the print monitors ...
8660 * Just reply with "Local Port", to keep NT happy
8661 * and I can use my nice printer checker.
8666 *r->out.info = NULL;
8668 switch (r->in.level) {
8670 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
8674 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
8678 return WERR_UNKNOWN_LEVEL;
8681 if (!W_ERROR_IS_OK(result)) {
8685 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8686 spoolss_EnumMonitors, NULL,
8687 *r->out.info, r->in.level,
8689 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8690 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8692 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8695 /****************************************************************************
8696 ****************************************************************************/
8698 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
8699 const print_queue_struct *queue,
8700 int count, int snum,
8701 const NT_PRINTER_INFO_LEVEL *ntprinter,
8703 struct spoolss_JobInfo1 *r)
8708 for (i=0; i<count && found == false; i++) {
8709 if (queue[i].job == (int)jobid) {
8714 if (found == false) {
8715 /* NT treats not found as bad param... yet another bad choice */
8716 return WERR_INVALID_PARAM;
8719 return fill_job_info1(mem_ctx,
8727 /****************************************************************************
8728 ****************************************************************************/
8730 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
8731 const print_queue_struct *queue,
8732 int count, int snum,
8733 const NT_PRINTER_INFO_LEVEL *ntprinter,
8735 struct spoolss_JobInfo2 *r)
8739 struct spoolss_DeviceMode *devmode;
8740 NT_DEVICEMODE *nt_devmode;
8743 for (i=0; i<count && found == false; i++) {
8744 if (queue[i].job == (int)jobid) {
8749 if (found == false) {
8750 /* NT treats not found as bad param... yet another bad
8752 return WERR_INVALID_PARAM;
8756 * if the print job does not have a DEVMODE associated with it,
8757 * just use the one for the printer. A NULL devicemode is not
8758 * a failure condition
8761 nt_devmode = print_job_devmode(lp_const_servicename(snum), jobid);
8763 devmode = TALLOC_ZERO_P(mem_ctx, struct spoolss_DeviceMode);
8764 W_ERROR_HAVE_NO_MEMORY(devmode);
8765 result = convert_nt_devicemode(devmode, devmode, nt_devmode);
8766 if (!W_ERROR_IS_OK(result)) {
8770 devmode = construct_dev_mode(mem_ctx, lp_const_servicename(snum));
8771 W_ERROR_HAVE_NO_MEMORY(devmode);
8774 return fill_job_info2(mem_ctx,
8783 /****************************************************************
8785 ****************************************************************/
8787 WERROR _spoolss_GetJob(pipes_struct *p,
8788 struct spoolss_GetJob *r)
8790 WERROR result = WERR_OK;
8791 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
8794 print_queue_struct *queue = NULL;
8795 print_status_struct prt_status;
8797 /* that's an [in out] buffer */
8799 if (!r->in.buffer && (r->in.offered != 0)) {
8800 return WERR_INVALID_PARAM;
8803 DEBUG(5,("_spoolss_GetJob\n"));
8807 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8811 result = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum));
8812 if (!W_ERROR_IS_OK(result)) {
8816 count = print_queue_status(snum, &queue, &prt_status);
8818 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
8819 count, prt_status.status, prt_status.message));
8821 switch (r->in.level) {
8823 result = getjob_level_1(p->mem_ctx,
8824 queue, count, snum, ntprinter,
8825 r->in.job_id, &r->out.info->info1);
8828 result = getjob_level_2(p->mem_ctx,
8829 queue, count, snum, ntprinter,
8830 r->in.job_id, &r->out.info->info2);
8833 result = WERR_UNKNOWN_LEVEL;
8838 free_a_printer(&ntprinter, 2);
8840 if (!W_ERROR_IS_OK(result)) {
8841 TALLOC_FREE(r->out.info);
8845 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, NULL,
8846 r->out.info, r->in.level);
8847 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8849 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8852 /****************************************************************
8853 _spoolss_GetPrinterDataEx
8855 From MSDN documentation of GetPrinterDataEx: pass request
8856 to GetPrinterData if key is "PrinterDriverData".
8857 ****************************************************************/
8859 WERROR _spoolss_GetPrinterDataEx(pipes_struct *p,
8860 struct spoolss_GetPrinterDataEx *r)
8863 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8864 struct regval_blob *val = NULL;
8865 NT_PRINTER_INFO_LEVEL *printer = NULL;
8867 WERROR result = WERR_OK;
8869 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
8871 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
8872 r->in.key_name, r->in.value_name));
8874 /* in case of problem, return some default values */
8877 *r->out.type = REG_NONE;
8880 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
8881 OUR_HANDLE(r->in.handle)));
8882 result = WERR_BADFID;
8886 /* Is the handle to a printer or to the server? */
8888 if (Printer->printer_type == SPLHND_SERVER) {
8889 DEBUG(10,("_spoolss_GetPrinterDataEx: "
8890 "Not implemented for server handles yet\n"));
8891 result = WERR_INVALID_PARAM;
8895 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8899 result = get_a_printer(Printer, &printer, 2, lp_servicename(snum));
8900 if (!W_ERROR_IS_OK(result)) {
8904 /* check to see if the keyname is valid */
8905 if (!strlen(r->in.key_name)) {
8906 result = WERR_INVALID_PARAM;
8910 if (lookup_printerkey(printer->info_2->data, r->in.key_name) == -1) {
8911 DEBUG(4,("_spoolss_GetPrinterDataEx: "
8912 "Invalid keyname [%s]\n", r->in.key_name ));
8913 result = WERR_BADFILE;
8917 /* When given a new keyname, we should just create it */
8919 val = get_printer_data(printer->info_2,
8920 r->in.key_name, r->in.value_name);
8922 result = WERR_BADFILE;
8926 *r->out.needed = regval_size(val);
8928 if (*r->out.needed > r->in.offered) {
8929 result = WERR_MORE_DATA;
8933 *r->out.type = regval_type(val);
8935 memcpy(r->out.buffer, regval_data_p(val), regval_size(val));
8939 free_a_printer(&printer, 2);
8945 /****************************************************************
8946 _spoolss_SetPrinterDataEx
8947 ****************************************************************/
8949 WERROR _spoolss_SetPrinterDataEx(pipes_struct *p,
8950 struct spoolss_SetPrinterDataEx *r)
8952 NT_PRINTER_INFO_LEVEL *printer = NULL;
8954 WERROR result = WERR_OK;
8955 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8958 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
8960 /* From MSDN documentation of SetPrinterDataEx: pass request to
8961 SetPrinterData if key is "PrinterDriverData" */
8964 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
8965 OUR_HANDLE(r->in.handle)));
8969 if (Printer->printer_type == SPLHND_SERVER) {
8970 DEBUG(10,("_spoolss_SetPrinterDataEx: "
8971 "Not implemented for server handles yet\n"));
8972 return WERR_INVALID_PARAM;
8975 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8980 * Access check : NT returns "access denied" if you make a
8981 * SetPrinterData call without the necessary privildge.
8982 * we were originally returning OK if nothing changed
8983 * which made Win2k issue **a lot** of SetPrinterData
8984 * when connecting to a printer --jerry
8987 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8988 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
8989 "change denied by handle access permissions\n"));
8990 return WERR_ACCESS_DENIED;
8993 result = get_a_printer(Printer, &printer, 2, lp_servicename(snum));
8994 if (!W_ERROR_IS_OK(result)) {
8998 /* check for OID in valuename */
9000 oid_string = strchr(r->in.value_name, ',');
9006 /* save the registry data */
9008 result = set_printer_dataex(printer, r->in.key_name, r->in.value_name,
9009 r->in.type, r->in.buffer, r->in.offered);
9011 if (W_ERROR_IS_OK(result)) {
9012 /* save the OID if one was specified */
9014 char *str = talloc_asprintf(p->mem_ctx, "%s\\%s",
9015 r->in.key_name, SPOOL_OID_KEY);
9017 result = WERR_NOMEM;
9022 * I'm not checking the status here on purpose. Don't know
9023 * if this is right, but I'm returning the status from the
9024 * previous set_printer_dataex() call. I have no idea if
9025 * this is right. --jerry
9028 set_printer_dataex(printer, str, r->in.value_name,
9029 REG_SZ, (uint8_t *)oid_string,
9030 strlen(oid_string)+1);
9033 result = mod_a_printer(printer, 2);
9037 free_a_printer(&printer, 2);
9042 /****************************************************************
9043 _spoolss_DeletePrinterDataEx
9044 ****************************************************************/
9046 WERROR _spoolss_DeletePrinterDataEx(pipes_struct *p,
9047 struct spoolss_DeletePrinterDataEx *r)
9049 NT_PRINTER_INFO_LEVEL *printer = NULL;
9051 WERROR status = WERR_OK;
9052 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9054 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9057 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9058 "Invalid handle (%s:%u:%u).\n",
9059 OUR_HANDLE(r->in.handle)));
9063 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
9066 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9067 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9068 "printer properties change denied by handle\n"));
9069 return WERR_ACCESS_DENIED;
9072 if (!r->in.value_name || !r->in.key_name) {
9076 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9077 if (!W_ERROR_IS_OK(status))
9080 status = delete_printer_dataex( printer, r->in.key_name, r->in.value_name );
9082 if ( W_ERROR_IS_OK(status) )
9083 mod_a_printer( printer, 2 );
9085 free_a_printer(&printer, 2);
9090 /****************************************************************
9091 _spoolss_EnumPrinterKey
9092 ****************************************************************/
9094 WERROR _spoolss_EnumPrinterKey(pipes_struct *p,
9095 struct spoolss_EnumPrinterKey *r)
9097 fstring *keynames = NULL;
9099 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9100 NT_PRINTER_DATA *data;
9101 NT_PRINTER_INFO_LEVEL *printer = NULL;
9103 WERROR result = WERR_BADFILE;
9105 const char **array = NULL;
9108 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
9111 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
9112 OUR_HANDLE(r->in.handle)));
9116 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9120 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9121 if (!W_ERROR_IS_OK(result)) {
9125 /* get the list of subkey names */
9127 data = printer->info_2->data;
9129 num_keys = get_printer_subkeys(data, r->in.key_name, &keynames);
9130 if (num_keys == -1) {
9131 result = WERR_BADFILE;
9135 array = talloc_zero_array(r->out.key_buffer, const char *, num_keys + 1);
9137 result = WERR_NOMEM;
9141 for (i=0; i < num_keys; i++) {
9143 DEBUG(10,("_spoolss_EnumPrinterKey: adding keyname: %s\n",
9146 array[i] = talloc_strdup(array, keynames[i]);
9148 result = WERR_NOMEM;
9153 if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
9154 result = WERR_NOMEM;
9158 *r->out.needed = blob.length;
9160 if (r->in.offered < *r->out.needed) {
9161 result = WERR_MORE_DATA;
9164 r->out.key_buffer->string = array;
9168 if (!W_ERROR_IS_OK(result)) {
9170 if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
9175 free_a_printer(&printer, 2);
9176 SAFE_FREE(keynames);
9181 /****************************************************************
9182 _spoolss_DeletePrinterKey
9183 ****************************************************************/
9185 WERROR _spoolss_DeletePrinterKey(pipes_struct *p,
9186 struct spoolss_DeletePrinterKey *r)
9188 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9189 NT_PRINTER_INFO_LEVEL *printer = NULL;
9193 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9196 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9197 OUR_HANDLE(r->in.handle)));
9201 /* if keyname == NULL, return error */
9203 if ( !r->in.key_name )
9204 return WERR_INVALID_PARAM;
9206 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
9209 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9210 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9211 "printer properties change denied by handle\n"));
9212 return WERR_ACCESS_DENIED;
9215 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9216 if (!W_ERROR_IS_OK(status))
9219 /* delete the key and all subneys */
9221 status = delete_all_printer_data( printer->info_2, r->in.key_name );
9223 if ( W_ERROR_IS_OK(status) )
9224 status = mod_a_printer(printer, 2);
9226 free_a_printer( &printer, 2 );
9231 /****************************************************************
9232 ****************************************************************/
9234 static WERROR registry_value_to_printer_enum_value(TALLOC_CTX *mem_ctx,
9235 struct regval_blob *v,
9236 struct spoolss_PrinterEnumValues *r)
9240 r->data = TALLOC_ZERO_P(mem_ctx, union spoolss_PrinterData);
9241 W_ERROR_HAVE_NO_MEMORY(r->data);
9243 r->value_name = talloc_strdup(mem_ctx, regval_name(v));
9244 W_ERROR_HAVE_NO_MEMORY(r->value_name);
9246 r->type = regval_type(v);
9247 r->data_length = regval_size(v);
9249 if (r->data_length) {
9250 DATA_BLOB blob = data_blob_const(regval_data_p(v),
9252 result = pull_spoolss_PrinterData(mem_ctx, &blob,
9255 if (!W_ERROR_IS_OK(result)) {
9263 /****************************************************************
9264 _spoolss_EnumPrinterDataEx
9265 ****************************************************************/
9267 WERROR _spoolss_EnumPrinterDataEx(pipes_struct *p,
9268 struct spoolss_EnumPrinterDataEx *r)
9271 NT_PRINTER_INFO_LEVEL *printer = NULL;
9272 struct spoolss_PrinterEnumValues *info = NULL;
9273 NT_PRINTER_DATA *p_data;
9274 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9280 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9284 *r->out.info = NULL;
9287 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9288 OUR_HANDLE(r->in.handle)));
9293 * first check for a keyname of NULL or "". Win2k seems to send
9294 * this a lot and we should send back WERR_INVALID_PARAM
9295 * no need to spend time looking up the printer in this case.
9299 if (!strlen(r->in.key_name)) {
9300 result = WERR_INVALID_PARAM;
9304 /* get the printer off of disk */
9306 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9310 ZERO_STRUCT(printer);
9311 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9312 if (!W_ERROR_IS_OK(result)) {
9316 /* now look for a match on the key name */
9318 p_data = printer->info_2->data;
9320 key_index = lookup_printerkey(p_data, r->in.key_name);
9321 if (key_index == -1) {
9322 DEBUG(10,("_spoolss_EnumPrinterDataEx: Unknown keyname [%s]\n",
9324 result = WERR_INVALID_PARAM;
9328 /* allocate the memory for the array of pointers -- if necessary */
9330 count = regval_ctr_numvals(p_data->keys[key_index].values);
9332 result = WERR_OK; /* ??? */
9336 info = TALLOC_ZERO_ARRAY(p->mem_ctx,
9337 struct spoolss_PrinterEnumValues,
9340 DEBUG(0,("_spoolss_EnumPrinterDataEx: talloc() failed\n"));
9341 result = WERR_NOMEM;
9346 * loop through all params and build the array to pass
9347 * back to the client
9350 for (i=0; i < count; i++) {
9352 struct regval_blob *val;
9354 /* lookup the registry value */
9356 val = regval_ctr_specific_value(p_data->keys[key_index].values, i);
9358 DEBUG(10,("retrieved value number [%d] [%s]\n", i, regval_name(val)));
9362 result = registry_value_to_printer_enum_value(info, val, &info[i]);
9363 if (!W_ERROR_IS_OK(result)) {
9368 #if 0 /* FIXME - gd */
9369 /* housekeeping information in the reply */
9371 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9372 * the hand marshalled container size is a multiple
9373 * of 4 bytes for RPC alignment.
9377 needed += 4-(needed % 4);
9380 *r->out.count = count;
9381 *r->out.info = info;
9386 free_a_printer(&printer, 2);
9389 if (!W_ERROR_IS_OK(result)) {
9393 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
9394 spoolss_EnumPrinterDataEx, NULL,
9397 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9398 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
9400 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9403 /****************************************************************************
9404 ****************************************************************************/
9406 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
9407 const char *servername,
9408 const char *environment,
9409 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9414 werr = compose_spoolss_server_path(mem_ctx,
9417 SPOOLSS_PRTPROCS_PATH,
9419 if (!W_ERROR_IS_OK(werr)) {
9423 DEBUG(4,("print processor directory: [%s]\n", path));
9425 r->directory_name = path;
9430 /****************************************************************
9431 _spoolss_GetPrintProcessorDirectory
9432 ****************************************************************/
9434 WERROR _spoolss_GetPrintProcessorDirectory(pipes_struct *p,
9435 struct spoolss_GetPrintProcessorDirectory *r)
9439 /* that's an [in out] buffer */
9441 if (!r->in.buffer && (r->in.offered != 0)) {
9442 return WERR_INVALID_PARAM;
9445 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9450 /* r->in.level is ignored */
9452 /* We always should reply with a local print processor directory so that
9453 * users are not forced to have a [prnproc$] share on the Samba spoolss
9454 * server - Guenther */
9456 result = getprintprocessordirectory_level_1(p->mem_ctx,
9457 NULL, /* r->in.server */
9459 &r->out.info->info1);
9460 if (!W_ERROR_IS_OK(result)) {
9461 TALLOC_FREE(r->out.info);
9465 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo, NULL,
9466 r->out.info, r->in.level);
9467 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9469 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9472 /*******************************************************************
9473 ********************************************************************/
9475 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
9476 const char *dllname)
9478 enum ndr_err_code ndr_err;
9479 struct spoolss_MonitorUi ui;
9481 ui.dll_name = dllname;
9483 ndr_err = ndr_push_struct_blob(buf, mem_ctx, NULL, &ui,
9484 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
9485 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9486 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
9488 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9491 /*******************************************************************
9492 Streams the monitor UI DLL name in UNICODE
9493 *******************************************************************/
9495 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
9496 NT_USER_TOKEN *token, DATA_BLOB *in,
9497 DATA_BLOB *out, uint32_t *needed)
9499 const char *dllname = "tcpmonui.dll";
9501 *needed = (strlen(dllname)+1) * 2;
9503 if (out->length < *needed) {
9504 return WERR_INSUFFICIENT_BUFFER;
9507 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9514 /*******************************************************************
9515 ********************************************************************/
9517 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
9518 struct spoolss_PortData1 *port1,
9519 const DATA_BLOB *buf)
9521 enum ndr_err_code ndr_err;
9522 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, NULL, port1,
9523 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
9524 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9525 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
9527 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9530 /*******************************************************************
9531 ********************************************************************/
9533 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
9534 struct spoolss_PortData2 *port2,
9535 const DATA_BLOB *buf)
9537 enum ndr_err_code ndr_err;
9538 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, NULL, port2,
9539 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
9540 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9541 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
9543 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9546 /*******************************************************************
9547 Create a new TCP/IP port
9548 *******************************************************************/
9550 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
9551 NT_USER_TOKEN *token, DATA_BLOB *in,
9552 DATA_BLOB *out, uint32_t *needed)
9554 struct spoolss_PortData1 port1;
9555 struct spoolss_PortData2 port2;
9556 char *device_uri = NULL;
9559 const char *portname;
9560 const char *hostaddress;
9562 uint32_t port_number;
9565 /* peek for spoolss_PortData version */
9567 if (!in || (in->length < (128 + 4))) {
9568 return WERR_GENERAL_FAILURE;
9571 version = IVAL(in->data, 128);
9577 if (!pull_port_data_1(mem_ctx, &port1, in)) {
9581 portname = port1.portname;
9582 hostaddress = port1.hostaddress;
9583 queue = port1.queue;
9584 protocol = port1.protocol;
9585 port_number = port1.port_number;
9591 if (!pull_port_data_2(mem_ctx, &port2, in)) {
9595 portname = port2.portname;
9596 hostaddress = port2.hostaddress;
9597 queue = port2.queue;
9598 protocol = port2.protocol;
9599 port_number = port2.port_number;
9603 DEBUG(1,("xcvtcp_addport: "
9604 "unknown version of port_data: %d\n", version));
9605 return WERR_UNKNOWN_PORT;
9608 /* create the device URI and call the add_port_hook() */
9611 case PROTOCOL_RAWTCP_TYPE:
9612 device_uri = talloc_asprintf(mem_ctx,
9613 "socket://%s:%d/", hostaddress,
9617 case PROTOCOL_LPR_TYPE:
9618 device_uri = talloc_asprintf(mem_ctx,
9619 "lpr://%s/%s", hostaddress, queue );
9623 return WERR_UNKNOWN_PORT;
9630 return add_port_hook(mem_ctx, token, portname, device_uri);
9633 /*******************************************************************
9634 *******************************************************************/
9636 struct xcv_api_table xcvtcp_cmds[] = {
9637 { "MonitorUI", xcvtcp_monitorui },
9638 { "AddPort", xcvtcp_addport},
9642 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
9643 NT_USER_TOKEN *token, const char *command,
9650 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
9652 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
9653 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
9654 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9657 return WERR_BADFUNC;
9660 /*******************************************************************
9661 *******************************************************************/
9662 #if 0 /* don't support management using the "Local Port" monitor */
9664 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
9665 NT_USER_TOKEN *token, DATA_BLOB *in,
9666 DATA_BLOB *out, uint32_t *needed)
9668 const char *dllname = "localui.dll";
9670 *needed = (strlen(dllname)+1) * 2;
9672 if (out->length < *needed) {
9673 return WERR_INSUFFICIENT_BUFFER;
9676 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9683 /*******************************************************************
9684 *******************************************************************/
9686 struct xcv_api_table xcvlocal_cmds[] = {
9687 { "MonitorUI", xcvlocal_monitorui },
9691 struct xcv_api_table xcvlocal_cmds[] = {
9698 /*******************************************************************
9699 *******************************************************************/
9701 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
9702 NT_USER_TOKEN *token, const char *command,
9703 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
9708 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
9710 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
9711 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
9712 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9714 return WERR_BADFUNC;
9717 /****************************************************************
9719 ****************************************************************/
9721 WERROR _spoolss_XcvData(pipes_struct *p,
9722 struct spoolss_XcvData *r)
9724 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9725 DATA_BLOB out_data = data_blob_null;
9729 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
9730 OUR_HANDLE(r->in.handle)));
9734 /* Has to be a handle to the TCP/IP port monitor */
9736 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
9737 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
9741 /* requires administrative access to the server */
9743 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
9744 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
9745 return WERR_ACCESS_DENIED;
9748 /* Allocate the outgoing buffer */
9750 if (r->in.out_data_size) {
9751 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
9752 if (out_data.data == NULL) {
9757 switch ( Printer->printer_type ) {
9758 case SPLHND_PORTMON_TCP:
9759 werror = process_xcvtcp_command(p->mem_ctx,
9760 p->server_info->ptok,
9761 r->in.function_name,
9762 &r->in.in_data, &out_data,
9765 case SPLHND_PORTMON_LOCAL:
9766 werror = process_xcvlocal_command(p->mem_ctx,
9767 p->server_info->ptok,
9768 r->in.function_name,
9769 &r->in.in_data, &out_data,
9773 werror = WERR_INVALID_PRINT_MONITOR;
9776 if (!W_ERROR_IS_OK(werror)) {
9780 *r->out.status_code = 0;
9782 memcpy(r->out.out_data, out_data.data, out_data.length);
9787 /****************************************************************
9788 _spoolss_AddPrintProcessor
9789 ****************************************************************/
9791 WERROR _spoolss_AddPrintProcessor(pipes_struct *p,
9792 struct spoolss_AddPrintProcessor *r)
9794 /* for now, just indicate success and ignore the add. We'll
9795 automatically set the winprint processor for printer
9796 entries later. Used to debug the LexMark Optra S 1855 PCL
9802 /****************************************************************
9804 ****************************************************************/
9806 WERROR _spoolss_AddPort(pipes_struct *p,
9807 struct spoolss_AddPort *r)
9809 /* do what w2k3 does */
9811 return WERR_NOT_SUPPORTED;
9814 /****************************************************************
9815 _spoolss_GetPrinterDriver
9816 ****************************************************************/
9818 WERROR _spoolss_GetPrinterDriver(pipes_struct *p,
9819 struct spoolss_GetPrinterDriver *r)
9821 p->rng_fault_state = true;
9822 return WERR_NOT_SUPPORTED;
9825 /****************************************************************
9826 _spoolss_ReadPrinter
9827 ****************************************************************/
9829 WERROR _spoolss_ReadPrinter(pipes_struct *p,
9830 struct spoolss_ReadPrinter *r)
9832 p->rng_fault_state = true;
9833 return WERR_NOT_SUPPORTED;
9836 /****************************************************************
9837 _spoolss_WaitForPrinterChange
9838 ****************************************************************/
9840 WERROR _spoolss_WaitForPrinterChange(pipes_struct *p,
9841 struct spoolss_WaitForPrinterChange *r)
9843 p->rng_fault_state = true;
9844 return WERR_NOT_SUPPORTED;
9847 /****************************************************************
9848 _spoolss_ConfigurePort
9849 ****************************************************************/
9851 WERROR _spoolss_ConfigurePort(pipes_struct *p,
9852 struct spoolss_ConfigurePort *r)
9854 p->rng_fault_state = true;
9855 return WERR_NOT_SUPPORTED;
9858 /****************************************************************
9860 ****************************************************************/
9862 WERROR _spoolss_DeletePort(pipes_struct *p,
9863 struct spoolss_DeletePort *r)
9865 p->rng_fault_state = true;
9866 return WERR_NOT_SUPPORTED;
9869 /****************************************************************
9870 _spoolss_CreatePrinterIC
9871 ****************************************************************/
9873 WERROR _spoolss_CreatePrinterIC(pipes_struct *p,
9874 struct spoolss_CreatePrinterIC *r)
9876 p->rng_fault_state = true;
9877 return WERR_NOT_SUPPORTED;
9880 /****************************************************************
9881 _spoolss_PlayGDIScriptOnPrinterIC
9882 ****************************************************************/
9884 WERROR _spoolss_PlayGDIScriptOnPrinterIC(pipes_struct *p,
9885 struct spoolss_PlayGDIScriptOnPrinterIC *r)
9887 p->rng_fault_state = true;
9888 return WERR_NOT_SUPPORTED;
9891 /****************************************************************
9892 _spoolss_DeletePrinterIC
9893 ****************************************************************/
9895 WERROR _spoolss_DeletePrinterIC(pipes_struct *p,
9896 struct spoolss_DeletePrinterIC *r)
9898 p->rng_fault_state = true;
9899 return WERR_NOT_SUPPORTED;
9902 /****************************************************************
9903 _spoolss_AddPrinterConnection
9904 ****************************************************************/
9906 WERROR _spoolss_AddPrinterConnection(pipes_struct *p,
9907 struct spoolss_AddPrinterConnection *r)
9909 p->rng_fault_state = true;
9910 return WERR_NOT_SUPPORTED;
9913 /****************************************************************
9914 _spoolss_DeletePrinterConnection
9915 ****************************************************************/
9917 WERROR _spoolss_DeletePrinterConnection(pipes_struct *p,
9918 struct spoolss_DeletePrinterConnection *r)
9920 p->rng_fault_state = true;
9921 return WERR_NOT_SUPPORTED;
9924 /****************************************************************
9925 _spoolss_PrinterMessageBox
9926 ****************************************************************/
9928 WERROR _spoolss_PrinterMessageBox(pipes_struct *p,
9929 struct spoolss_PrinterMessageBox *r)
9931 p->rng_fault_state = true;
9932 return WERR_NOT_SUPPORTED;
9935 /****************************************************************
9937 ****************************************************************/
9939 WERROR _spoolss_AddMonitor(pipes_struct *p,
9940 struct spoolss_AddMonitor *r)
9942 p->rng_fault_state = true;
9943 return WERR_NOT_SUPPORTED;
9946 /****************************************************************
9947 _spoolss_DeleteMonitor
9948 ****************************************************************/
9950 WERROR _spoolss_DeleteMonitor(pipes_struct *p,
9951 struct spoolss_DeleteMonitor *r)
9953 p->rng_fault_state = true;
9954 return WERR_NOT_SUPPORTED;
9957 /****************************************************************
9958 _spoolss_DeletePrintProcessor
9959 ****************************************************************/
9961 WERROR _spoolss_DeletePrintProcessor(pipes_struct *p,
9962 struct spoolss_DeletePrintProcessor *r)
9964 p->rng_fault_state = true;
9965 return WERR_NOT_SUPPORTED;
9968 /****************************************************************
9969 _spoolss_AddPrintProvidor
9970 ****************************************************************/
9972 WERROR _spoolss_AddPrintProvidor(pipes_struct *p,
9973 struct spoolss_AddPrintProvidor *r)
9975 p->rng_fault_state = true;
9976 return WERR_NOT_SUPPORTED;
9979 /****************************************************************
9980 _spoolss_DeletePrintProvidor
9981 ****************************************************************/
9983 WERROR _spoolss_DeletePrintProvidor(pipes_struct *p,
9984 struct spoolss_DeletePrintProvidor *r)
9986 p->rng_fault_state = true;
9987 return WERR_NOT_SUPPORTED;
9990 /****************************************************************
9991 _spoolss_FindFirstPrinterChangeNotification
9992 ****************************************************************/
9994 WERROR _spoolss_FindFirstPrinterChangeNotification(pipes_struct *p,
9995 struct spoolss_FindFirstPrinterChangeNotification *r)
9997 p->rng_fault_state = true;
9998 return WERR_NOT_SUPPORTED;
10001 /****************************************************************
10002 _spoolss_FindNextPrinterChangeNotification
10003 ****************************************************************/
10005 WERROR _spoolss_FindNextPrinterChangeNotification(pipes_struct *p,
10006 struct spoolss_FindNextPrinterChangeNotification *r)
10008 p->rng_fault_state = true;
10009 return WERR_NOT_SUPPORTED;
10012 /****************************************************************
10013 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10014 ****************************************************************/
10016 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(pipes_struct *p,
10017 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
10019 p->rng_fault_state = true;
10020 return WERR_NOT_SUPPORTED;
10023 /****************************************************************
10024 _spoolss_ReplyOpenPrinter
10025 ****************************************************************/
10027 WERROR _spoolss_ReplyOpenPrinter(pipes_struct *p,
10028 struct spoolss_ReplyOpenPrinter *r)
10030 p->rng_fault_state = true;
10031 return WERR_NOT_SUPPORTED;
10034 /****************************************************************
10035 _spoolss_RouterReplyPrinter
10036 ****************************************************************/
10038 WERROR _spoolss_RouterReplyPrinter(pipes_struct *p,
10039 struct spoolss_RouterReplyPrinter *r)
10041 p->rng_fault_state = true;
10042 return WERR_NOT_SUPPORTED;
10045 /****************************************************************
10046 _spoolss_ReplyClosePrinter
10047 ****************************************************************/
10049 WERROR _spoolss_ReplyClosePrinter(pipes_struct *p,
10050 struct spoolss_ReplyClosePrinter *r)
10052 p->rng_fault_state = true;
10053 return WERR_NOT_SUPPORTED;
10056 /****************************************************************
10058 ****************************************************************/
10060 WERROR _spoolss_AddPortEx(pipes_struct *p,
10061 struct spoolss_AddPortEx *r)
10063 p->rng_fault_state = true;
10064 return WERR_NOT_SUPPORTED;
10067 /****************************************************************
10068 _spoolss_RouterFindFirstPrinterChangeNotification
10069 ****************************************************************/
10071 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(pipes_struct *p,
10072 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
10074 p->rng_fault_state = true;
10075 return WERR_NOT_SUPPORTED;
10078 /****************************************************************
10079 _spoolss_SpoolerInit
10080 ****************************************************************/
10082 WERROR _spoolss_SpoolerInit(pipes_struct *p,
10083 struct spoolss_SpoolerInit *r)
10085 p->rng_fault_state = true;
10086 return WERR_NOT_SUPPORTED;
10089 /****************************************************************
10090 _spoolss_ResetPrinterEx
10091 ****************************************************************/
10093 WERROR _spoolss_ResetPrinterEx(pipes_struct *p,
10094 struct spoolss_ResetPrinterEx *r)
10096 p->rng_fault_state = true;
10097 return WERR_NOT_SUPPORTED;
10100 /****************************************************************
10101 _spoolss_RouterReplyPrinterEx
10102 ****************************************************************/
10104 WERROR _spoolss_RouterReplyPrinterEx(pipes_struct *p,
10105 struct spoolss_RouterReplyPrinterEx *r)
10107 p->rng_fault_state = true;
10108 return WERR_NOT_SUPPORTED;
10111 /****************************************************************
10113 ****************************************************************/
10115 WERROR _spoolss_44(pipes_struct *p,
10116 struct spoolss_44 *r)
10118 p->rng_fault_state = true;
10119 return WERR_NOT_SUPPORTED;
10122 /****************************************************************
10124 ****************************************************************/
10126 WERROR _spoolss_47(pipes_struct *p,
10127 struct spoolss_47 *r)
10129 p->rng_fault_state = true;
10130 return WERR_NOT_SUPPORTED;
10133 /****************************************************************
10135 ****************************************************************/
10137 WERROR _spoolss_4a(pipes_struct *p,
10138 struct spoolss_4a *r)
10140 p->rng_fault_state = true;
10141 return WERR_NOT_SUPPORTED;
10144 /****************************************************************
10146 ****************************************************************/
10148 WERROR _spoolss_4b(pipes_struct *p,
10149 struct spoolss_4b *r)
10151 p->rng_fault_state = true;
10152 return WERR_NOT_SUPPORTED;
10155 /****************************************************************
10157 ****************************************************************/
10159 WERROR _spoolss_4c(pipes_struct *p,
10160 struct spoolss_4c *r)
10162 p->rng_fault_state = true;
10163 return WERR_NOT_SUPPORTED;
10166 /****************************************************************
10168 ****************************************************************/
10170 WERROR _spoolss_53(pipes_struct *p,
10171 struct spoolss_53 *r)
10173 p->rng_fault_state = true;
10174 return WERR_NOT_SUPPORTED;
10177 /****************************************************************
10179 ****************************************************************/
10181 WERROR _spoolss_55(pipes_struct *p,
10182 struct spoolss_55 *r)
10184 p->rng_fault_state = true;
10185 return WERR_NOT_SUPPORTED;
10188 /****************************************************************
10190 ****************************************************************/
10192 WERROR _spoolss_56(pipes_struct *p,
10193 struct spoolss_56 *r)
10195 p->rng_fault_state = true;
10196 return WERR_NOT_SUPPORTED;
10199 /****************************************************************
10201 ****************************************************************/
10203 WERROR _spoolss_57(pipes_struct *p,
10204 struct spoolss_57 *r)
10206 p->rng_fault_state = true;
10207 return WERR_NOT_SUPPORTED;
10210 /****************************************************************
10212 ****************************************************************/
10214 WERROR _spoolss_5a(pipes_struct *p,
10215 struct spoolss_5a *r)
10217 p->rng_fault_state = true;
10218 return WERR_NOT_SUPPORTED;
10221 /****************************************************************
10223 ****************************************************************/
10225 WERROR _spoolss_5b(pipes_struct *p,
10226 struct spoolss_5b *r)
10228 p->rng_fault_state = true;
10229 return WERR_NOT_SUPPORTED;
10232 /****************************************************************
10234 ****************************************************************/
10236 WERROR _spoolss_5c(pipes_struct *p,
10237 struct spoolss_5c *r)
10239 p->rng_fault_state = true;
10240 return WERR_NOT_SUPPORTED;
10243 /****************************************************************
10245 ****************************************************************/
10247 WERROR _spoolss_5d(pipes_struct *p,
10248 struct spoolss_5d *r)
10250 p->rng_fault_state = true;
10251 return WERR_NOT_SUPPORTED;
10254 /****************************************************************
10256 ****************************************************************/
10258 WERROR _spoolss_5e(pipes_struct *p,
10259 struct spoolss_5e *r)
10261 p->rng_fault_state = true;
10262 return WERR_NOT_SUPPORTED;
10265 /****************************************************************
10267 ****************************************************************/
10269 WERROR _spoolss_5f(pipes_struct *p,
10270 struct spoolss_5f *r)
10272 p->rng_fault_state = true;
10273 return WERR_NOT_SUPPORTED;
10276 /****************************************************************
10278 ****************************************************************/
10280 WERROR _spoolss_60(pipes_struct *p,
10281 struct spoolss_60 *r)
10283 p->rng_fault_state = true;
10284 return WERR_NOT_SUPPORTED;
10287 /****************************************************************
10289 ****************************************************************/
10291 WERROR _spoolss_61(pipes_struct *p,
10292 struct spoolss_61 *r)
10294 p->rng_fault_state = true;
10295 return WERR_NOT_SUPPORTED;
10298 /****************************************************************
10300 ****************************************************************/
10302 WERROR _spoolss_62(pipes_struct *p,
10303 struct spoolss_62 *r)
10305 p->rng_fault_state = true;
10306 return WERR_NOT_SUPPORTED;
10309 /****************************************************************
10311 ****************************************************************/
10313 WERROR _spoolss_63(pipes_struct *p,
10314 struct spoolss_63 *r)
10316 p->rng_fault_state = true;
10317 return WERR_NOT_SUPPORTED;
10320 /****************************************************************
10322 ****************************************************************/
10324 WERROR _spoolss_64(pipes_struct *p,
10325 struct spoolss_64 *r)
10327 p->rng_fault_state = true;
10328 return WERR_NOT_SUPPORTED;
10331 /****************************************************************
10333 ****************************************************************/
10335 WERROR _spoolss_65(pipes_struct *p,
10336 struct spoolss_65 *r)
10338 p->rng_fault_state = true;
10339 return WERR_NOT_SUPPORTED;
10342 /****************************************************************
10343 _spoolss_GetCorePrinterDrivers
10344 ****************************************************************/
10346 WERROR _spoolss_GetCorePrinterDrivers(pipes_struct *p,
10347 struct spoolss_GetCorePrinterDrivers *r)
10349 p->rng_fault_state = true;
10350 return WERR_NOT_SUPPORTED;
10353 /****************************************************************
10355 ****************************************************************/
10357 WERROR _spoolss_67(pipes_struct *p,
10358 struct spoolss_67 *r)
10360 p->rng_fault_state = true;
10361 return WERR_NOT_SUPPORTED;
10364 /****************************************************************
10365 _spoolss_GetPrinterDriverPackagePath
10366 ****************************************************************/
10368 WERROR _spoolss_GetPrinterDriverPackagePath(pipes_struct *p,
10369 struct spoolss_GetPrinterDriverPackagePath *r)
10371 p->rng_fault_state = true;
10372 return WERR_NOT_SUPPORTED;
10375 /****************************************************************
10377 ****************************************************************/
10379 WERROR _spoolss_69(pipes_struct *p,
10380 struct spoolss_69 *r)
10382 p->rng_fault_state = true;
10383 return WERR_NOT_SUPPORTED;
10386 /****************************************************************
10388 ****************************************************************/
10390 WERROR _spoolss_6a(pipes_struct *p,
10391 struct spoolss_6a *r)
10393 p->rng_fault_state = true;
10394 return WERR_NOT_SUPPORTED;
10397 /****************************************************************
10399 ****************************************************************/
10401 WERROR _spoolss_6b(pipes_struct *p,
10402 struct spoolss_6b *r)
10404 p->rng_fault_state = true;
10405 return WERR_NOT_SUPPORTED;
10408 /****************************************************************
10410 ****************************************************************/
10412 WERROR _spoolss_6c(pipes_struct *p,
10413 struct spoolss_6c *r)
10415 p->rng_fault_state = true;
10416 return WERR_NOT_SUPPORTED;
10419 /****************************************************************
10421 ****************************************************************/
10423 WERROR _spoolss_6d(pipes_struct *p,
10424 struct spoolss_6d *r)
10426 p->rng_fault_state = true;
10427 return WERR_NOT_SUPPORTED;