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-2010.
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 struct spoolss_DriverInfo8 *info = NULL;
1932 struct spoolss_DriverInfo8 *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, 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)) {
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, 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, 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 struct spoolss_DriverInfo8 *info = NULL;
2030 struct spoolss_DriverInfo8 *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, 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, r->in.driver,
2078 status = WERR_UNKNOWN_PRINTER_DRIVER;
2083 if (printer_driver_in_use(info)) {
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) & (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,
2116 r->in.architecture, 3)))
2119 if (delete_files && printer_driver_files_in_use(info, info_win2k) & (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, 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, 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")) {
2273 data->string = talloc_strdup(mem_ctx,
2274 lp_parm_const_string(GLOBAL_SECTION_SNUM, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_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);
2310 return WERR_INVALID_PARAM;
2313 /****************************************************************
2314 _spoolss_GetPrinterData
2315 ****************************************************************/
2317 WERROR _spoolss_GetPrinterData(pipes_struct *p,
2318 struct spoolss_GetPrinterData *r)
2320 struct spoolss_GetPrinterDataEx r2;
2322 r2.in.handle = r->in.handle;
2323 r2.in.key_name = "PrinterDriverData";
2324 r2.in.value_name = r->in.value_name;
2325 r2.in.offered = r->in.offered;
2326 r2.out.type = r->out.type;
2327 r2.out.data = r->out.data;
2328 r2.out.needed = r->out.needed;
2330 return _spoolss_GetPrinterDataEx(p, &r2);
2333 /*********************************************************
2334 Connect to the client machine.
2335 **********************************************************/
2337 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2338 struct sockaddr_storage *client_ss, const char *remote_machine)
2341 struct cli_state *the_cli;
2342 struct sockaddr_storage rm_addr;
2343 char addr[INET6_ADDRSTRLEN];
2345 if ( is_zero_addr((struct sockaddr *)client_ss) ) {
2346 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2348 if ( !resolve_name( remote_machine, &rm_addr, 0x20, false) ) {
2349 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2352 print_sockaddr(addr, sizeof(addr), &rm_addr);
2354 rm_addr = *client_ss;
2355 print_sockaddr(addr, sizeof(addr), &rm_addr);
2356 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2360 if (ismyaddr((struct sockaddr *)&rm_addr)) {
2361 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2366 /* setup the connection */
2367 ret = cli_full_connection( &the_cli, global_myname(), remote_machine,
2368 &rm_addr, 0, "IPC$", "IPC",
2372 0, lp_client_signing(), NULL );
2374 if ( !NT_STATUS_IS_OK( ret ) ) {
2375 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2380 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2381 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2382 cli_shutdown(the_cli);
2387 * Ok - we have an anonymous connection to the IPC$ share.
2388 * Now start the NT Domain stuff :-).
2391 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2392 if (!NT_STATUS_IS_OK(ret)) {
2393 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2394 remote_machine, nt_errstr(ret)));
2395 cli_shutdown(the_cli);
2402 /***************************************************************************
2403 Connect to the client.
2404 ****************************************************************************/
2406 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2407 uint32_t localprinter, uint32_t type,
2408 struct policy_handle *handle,
2409 struct sockaddr_storage *client_ss)
2415 * If it's the first connection, contact the client
2416 * and connect to the IPC$ share anonymously
2418 if (smb_connections==0) {
2419 fstring unix_printer;
2421 fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */
2423 if ( !spoolss_connect_to_client( ¬ify_cli_pipe, client_ss, unix_printer ))
2426 messaging_register(smbd_messaging_context(), NULL,
2427 MSG_PRINTER_NOTIFY2,
2428 receive_notify2_message_list);
2429 /* Tell the connections db we're now interested in printer
2430 * notify messages. */
2431 register_message_flags(true, FLAG_MSG_PRINT_NOTIFY);
2435 * Tell the specific printing tdb we want messages for this printer
2436 * by registering our PID.
2439 if (!print_notify_register_pid(snum))
2440 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", printer ));
2444 status = rpccli_spoolss_ReplyOpenPrinter(notify_cli_pipe, talloc_tos(),
2452 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
2453 DEBUG(5,("srv_spoolss_reply_open_printer: Client RPC returned [%s]\n",
2454 win_errstr(result)));
2456 return (W_ERROR_IS_OK(result));
2459 /****************************************************************
2460 ****************************************************************/
2462 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2463 const struct spoolss_NotifyOption *r)
2465 struct spoolss_NotifyOption *option;
2472 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2479 if (!option->count) {
2483 option->types = talloc_zero_array(option,
2484 struct spoolss_NotifyOptionType, option->count);
2485 if (!option->types) {
2486 talloc_free(option);
2490 for (i=0; i < option->count; i++) {
2491 option->types[i] = r->types[i];
2493 if (option->types[i].count) {
2494 option->types[i].fields = talloc_zero_array(option,
2495 union spoolss_Field, option->types[i].count);
2496 if (!option->types[i].fields) {
2497 talloc_free(option);
2500 for (k=0; k<option->types[i].count; k++) {
2501 option->types[i].fields[k] =
2502 r->types[i].fields[k];
2510 /****************************************************************
2511 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2513 * before replying OK: status=0 a rpc call is made to the workstation
2514 * asking ReplyOpenPrinter
2516 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2517 * called from api_spoolss_rffpcnex
2518 ****************************************************************/
2520 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(pipes_struct *p,
2521 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2524 struct spoolss_NotifyOption *option = r->in.notify_options;
2525 struct sockaddr_storage client_ss;
2527 /* store the notify value in the printer struct */
2529 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
2532 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2533 "Invalid handle (%s:%u:%u).\n",
2534 OUR_HANDLE(r->in.handle)));
2538 Printer->notify.flags = r->in.flags;
2539 Printer->notify.options = r->in.options;
2540 Printer->notify.printerlocal = r->in.printer_local;
2542 TALLOC_FREE(Printer->notify.option);
2543 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2545 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2547 /* Connect to the client machine and send a ReplyOpenPrinter */
2549 if ( Printer->printer_type == SPLHND_SERVER)
2551 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2552 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2555 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2556 "client_address is %s\n", p->client_address));
2558 if (!interpret_string_addr(&client_ss, p->client_address,
2560 return WERR_SERVER_UNAVAILABLE;
2563 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2564 Printer->notify.printerlocal, 1,
2565 &Printer->notify.client_hnd, &client_ss))
2566 return WERR_SERVER_UNAVAILABLE;
2568 Printer->notify.client_connected = true;
2573 /*******************************************************************
2574 * fill a notify_info_data with the servername
2575 ********************************************************************/
2577 void spoolss_notify_server_name(int snum,
2578 struct spoolss_Notify *data,
2579 print_queue_struct *queue,
2580 NT_PRINTER_INFO_LEVEL *printer,
2581 TALLOC_CTX *mem_ctx)
2583 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->servername);
2586 /*******************************************************************
2587 * fill a notify_info_data with the printername (not including the servername).
2588 ********************************************************************/
2590 void spoolss_notify_printer_name(int snum,
2591 struct spoolss_Notify *data,
2592 print_queue_struct *queue,
2593 NT_PRINTER_INFO_LEVEL *printer,
2594 TALLOC_CTX *mem_ctx)
2596 /* the notify name should not contain the \\server\ part */
2597 char *p = strrchr(printer->info_2->printername, '\\');
2600 p = printer->info_2->printername;
2605 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2608 /*******************************************************************
2609 * fill a notify_info_data with the servicename
2610 ********************************************************************/
2612 void spoolss_notify_share_name(int snum,
2613 struct spoolss_Notify *data,
2614 print_queue_struct *queue,
2615 NT_PRINTER_INFO_LEVEL *printer,
2616 TALLOC_CTX *mem_ctx)
2618 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
2621 /*******************************************************************
2622 * fill a notify_info_data with the port name
2623 ********************************************************************/
2625 void spoolss_notify_port_name(int snum,
2626 struct spoolss_Notify *data,
2627 print_queue_struct *queue,
2628 NT_PRINTER_INFO_LEVEL *printer,
2629 TALLOC_CTX *mem_ctx)
2631 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->portname);
2634 /*******************************************************************
2635 * fill a notify_info_data with the printername
2636 * but it doesn't exist, have to see what to do
2637 ********************************************************************/
2639 void spoolss_notify_driver_name(int snum,
2640 struct spoolss_Notify *data,
2641 print_queue_struct *queue,
2642 NT_PRINTER_INFO_LEVEL *printer,
2643 TALLOC_CTX *mem_ctx)
2645 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->drivername);
2648 /*******************************************************************
2649 * fill a notify_info_data with the comment
2650 ********************************************************************/
2652 void spoolss_notify_comment(int snum,
2653 struct spoolss_Notify *data,
2654 print_queue_struct *queue,
2655 NT_PRINTER_INFO_LEVEL *printer,
2656 TALLOC_CTX *mem_ctx)
2660 if (*printer->info_2->comment == '\0') {
2661 p = lp_comment(snum);
2663 p = printer->info_2->comment;
2666 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->comment);
2669 /*******************************************************************
2670 * fill a notify_info_data with the comment
2671 * location = "Room 1, floor 2, building 3"
2672 ********************************************************************/
2674 void spoolss_notify_location(int snum,
2675 struct spoolss_Notify *data,
2676 print_queue_struct *queue,
2677 NT_PRINTER_INFO_LEVEL *printer,
2678 TALLOC_CTX *mem_ctx)
2680 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->location);
2683 /*******************************************************************
2684 * fill a notify_info_data with the device mode
2685 * jfm:xxxx don't to it for know but that's a real problem !!!
2686 ********************************************************************/
2688 static void spoolss_notify_devmode(int snum,
2689 struct spoolss_Notify *data,
2690 print_queue_struct *queue,
2691 NT_PRINTER_INFO_LEVEL *printer,
2692 TALLOC_CTX *mem_ctx)
2694 /* for a dummy implementation we have to zero the fields */
2695 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2698 /*******************************************************************
2699 * fill a notify_info_data with the separator file name
2700 ********************************************************************/
2702 void spoolss_notify_sepfile(int snum,
2703 struct spoolss_Notify *data,
2704 print_queue_struct *queue,
2705 NT_PRINTER_INFO_LEVEL *printer,
2706 TALLOC_CTX *mem_ctx)
2708 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->sepfile);
2711 /*******************************************************************
2712 * fill a notify_info_data with the print processor
2713 * jfm:xxxx return always winprint to indicate we don't do anything to it
2714 ********************************************************************/
2716 void spoolss_notify_print_processor(int snum,
2717 struct spoolss_Notify *data,
2718 print_queue_struct *queue,
2719 NT_PRINTER_INFO_LEVEL *printer,
2720 TALLOC_CTX *mem_ctx)
2722 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->printprocessor);
2725 /*******************************************************************
2726 * fill a notify_info_data with the print processor options
2727 * jfm:xxxx send an empty string
2728 ********************************************************************/
2730 void spoolss_notify_parameters(int snum,
2731 struct spoolss_Notify *data,
2732 print_queue_struct *queue,
2733 NT_PRINTER_INFO_LEVEL *printer,
2734 TALLOC_CTX *mem_ctx)
2736 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->parameters);
2739 /*******************************************************************
2740 * fill a notify_info_data with the data type
2741 * jfm:xxxx always send RAW as data type
2742 ********************************************************************/
2744 void spoolss_notify_datatype(int snum,
2745 struct spoolss_Notify *data,
2746 print_queue_struct *queue,
2747 NT_PRINTER_INFO_LEVEL *printer,
2748 TALLOC_CTX *mem_ctx)
2750 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->datatype);
2753 /*******************************************************************
2754 * fill a notify_info_data with the security descriptor
2755 * jfm:xxxx send an null pointer to say no security desc
2756 * have to implement security before !
2757 ********************************************************************/
2759 static void spoolss_notify_security_desc(int snum,
2760 struct spoolss_Notify *data,
2761 print_queue_struct *queue,
2762 NT_PRINTER_INFO_LEVEL *printer,
2763 TALLOC_CTX *mem_ctx)
2765 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data,
2766 printer->info_2->secdesc_buf->sd_size,
2767 printer->info_2->secdesc_buf->sd);
2770 /*******************************************************************
2771 * fill a notify_info_data with the attributes
2772 * jfm:xxxx a samba printer is always shared
2773 ********************************************************************/
2775 void spoolss_notify_attributes(int snum,
2776 struct spoolss_Notify *data,
2777 print_queue_struct *queue,
2778 NT_PRINTER_INFO_LEVEL *printer,
2779 TALLOC_CTX *mem_ctx)
2781 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->attributes);
2784 /*******************************************************************
2785 * fill a notify_info_data with the priority
2786 ********************************************************************/
2788 static void spoolss_notify_priority(int snum,
2789 struct spoolss_Notify *data,
2790 print_queue_struct *queue,
2791 NT_PRINTER_INFO_LEVEL *printer,
2792 TALLOC_CTX *mem_ctx)
2794 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->priority);
2797 /*******************************************************************
2798 * fill a notify_info_data with the default priority
2799 ********************************************************************/
2801 static void spoolss_notify_default_priority(int snum,
2802 struct spoolss_Notify *data,
2803 print_queue_struct *queue,
2804 NT_PRINTER_INFO_LEVEL *printer,
2805 TALLOC_CTX *mem_ctx)
2807 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->default_priority);
2810 /*******************************************************************
2811 * fill a notify_info_data with the start time
2812 ********************************************************************/
2814 static void spoolss_notify_start_time(int snum,
2815 struct spoolss_Notify *data,
2816 print_queue_struct *queue,
2817 NT_PRINTER_INFO_LEVEL *printer,
2818 TALLOC_CTX *mem_ctx)
2820 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->starttime);
2823 /*******************************************************************
2824 * fill a notify_info_data with the until time
2825 ********************************************************************/
2827 static void spoolss_notify_until_time(int snum,
2828 struct spoolss_Notify *data,
2829 print_queue_struct *queue,
2830 NT_PRINTER_INFO_LEVEL *printer,
2831 TALLOC_CTX *mem_ctx)
2833 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->untiltime);
2836 /*******************************************************************
2837 * fill a notify_info_data with the status
2838 ********************************************************************/
2840 static void spoolss_notify_status(int snum,
2841 struct spoolss_Notify *data,
2842 print_queue_struct *queue,
2843 NT_PRINTER_INFO_LEVEL *printer,
2844 TALLOC_CTX *mem_ctx)
2846 print_status_struct status;
2848 print_queue_length(snum, &status);
2849 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
2852 /*******************************************************************
2853 * fill a notify_info_data with the number of jobs queued
2854 ********************************************************************/
2856 void spoolss_notify_cjobs(int snum,
2857 struct spoolss_Notify *data,
2858 print_queue_struct *queue,
2859 NT_PRINTER_INFO_LEVEL *printer,
2860 TALLOC_CTX *mem_ctx)
2862 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, print_queue_length(snum, NULL));
2865 /*******************************************************************
2866 * fill a notify_info_data with the average ppm
2867 ********************************************************************/
2869 static void spoolss_notify_average_ppm(int snum,
2870 struct spoolss_Notify *data,
2871 print_queue_struct *queue,
2872 NT_PRINTER_INFO_LEVEL *printer,
2873 TALLOC_CTX *mem_ctx)
2875 /* always respond 8 pages per minutes */
2876 /* a little hard ! */
2877 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->averageppm);
2880 /*******************************************************************
2881 * fill a notify_info_data with username
2882 ********************************************************************/
2884 static void spoolss_notify_username(int snum,
2885 struct spoolss_Notify *data,
2886 print_queue_struct *queue,
2887 NT_PRINTER_INFO_LEVEL *printer,
2888 TALLOC_CTX *mem_ctx)
2890 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
2893 /*******************************************************************
2894 * fill a notify_info_data with job status
2895 ********************************************************************/
2897 static void spoolss_notify_job_status(int snum,
2898 struct spoolss_Notify *data,
2899 print_queue_struct *queue,
2900 NT_PRINTER_INFO_LEVEL *printer,
2901 TALLOC_CTX *mem_ctx)
2903 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
2906 /*******************************************************************
2907 * fill a notify_info_data with job name
2908 ********************************************************************/
2910 static void spoolss_notify_job_name(int snum,
2911 struct spoolss_Notify *data,
2912 print_queue_struct *queue,
2913 NT_PRINTER_INFO_LEVEL *printer,
2914 TALLOC_CTX *mem_ctx)
2916 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
2919 /*******************************************************************
2920 * fill a notify_info_data with job status
2921 ********************************************************************/
2923 static void spoolss_notify_job_status_string(int snum,
2924 struct spoolss_Notify *data,
2925 print_queue_struct *queue,
2926 NT_PRINTER_INFO_LEVEL *printer,
2927 TALLOC_CTX *mem_ctx)
2930 * Now we're returning job status codes we just return a "" here. JRA.
2935 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
2938 switch (queue->status) {
2943 p = ""; /* NT provides the paused string */
2952 #endif /* NO LONGER NEEDED. */
2954 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2957 /*******************************************************************
2958 * fill a notify_info_data with job time
2959 ********************************************************************/
2961 static void spoolss_notify_job_time(int snum,
2962 struct spoolss_Notify *data,
2963 print_queue_struct *queue,
2964 NT_PRINTER_INFO_LEVEL *printer,
2965 TALLOC_CTX *mem_ctx)
2967 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
2970 /*******************************************************************
2971 * fill a notify_info_data with job size
2972 ********************************************************************/
2974 static void spoolss_notify_job_size(int snum,
2975 struct spoolss_Notify *data,
2976 print_queue_struct *queue,
2977 NT_PRINTER_INFO_LEVEL *printer,
2978 TALLOC_CTX *mem_ctx)
2980 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
2983 /*******************************************************************
2984 * fill a notify_info_data with page info
2985 ********************************************************************/
2986 static void spoolss_notify_total_pages(int snum,
2987 struct spoolss_Notify *data,
2988 print_queue_struct *queue,
2989 NT_PRINTER_INFO_LEVEL *printer,
2990 TALLOC_CTX *mem_ctx)
2992 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
2995 /*******************************************************************
2996 * fill a notify_info_data with pages printed info.
2997 ********************************************************************/
2998 static void spoolss_notify_pages_printed(int snum,
2999 struct spoolss_Notify *data,
3000 print_queue_struct *queue,
3001 NT_PRINTER_INFO_LEVEL *printer,
3002 TALLOC_CTX *mem_ctx)
3004 /* Add code when back-end tracks this */
3005 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3008 /*******************************************************************
3009 Fill a notify_info_data with job position.
3010 ********************************************************************/
3012 static void spoolss_notify_job_position(int snum,
3013 struct spoolss_Notify *data,
3014 print_queue_struct *queue,
3015 NT_PRINTER_INFO_LEVEL *printer,
3016 TALLOC_CTX *mem_ctx)
3018 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
3021 /*******************************************************************
3022 Fill a notify_info_data with submitted time.
3023 ********************************************************************/
3025 static void spoolss_notify_submitted_time(int snum,
3026 struct spoolss_Notify *data,
3027 print_queue_struct *queue,
3028 NT_PRINTER_INFO_LEVEL *printer,
3029 TALLOC_CTX *mem_ctx)
3031 data->data.string.string = NULL;
3032 data->data.string.size = 0;
3034 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
3035 &data->data.string.string,
3036 &data->data.string.size);
3040 struct s_notify_info_data_table
3042 enum spoolss_NotifyType type;
3045 enum spoolss_NotifyTable variable_type;
3046 void (*fn) (int snum, struct spoolss_Notify *data,
3047 print_queue_struct *queue,
3048 NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx);
3051 /* A table describing the various print notification constants and
3052 whether the notification data is a pointer to a variable sized
3053 buffer, a one value uint32_t or a two value uint32_t. */
3055 static const struct s_notify_info_data_table notify_info_data_table[] =
3057 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3058 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3059 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
3060 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3061 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3062 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
3063 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
3064 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3065 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
3066 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3067 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3068 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3069 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
3070 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
3071 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3072 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
3073 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3074 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3075 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
3076 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
3077 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
3078 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
3079 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
3080 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3081 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
3082 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3083 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3084 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3085 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3086 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3087 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3088 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3089 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3090 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3091 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3092 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3093 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
3094 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
3095 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
3096 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
3097 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3098 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
3099 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
3100 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3101 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3102 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
3103 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
3104 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
3105 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
3108 /*******************************************************************
3109 Return the variable_type of info_data structure.
3110 ********************************************************************/
3112 static uint32_t variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3117 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3118 if ( (notify_info_data_table[i].type == type) &&
3119 (notify_info_data_table[i].field == field) ) {
3120 return notify_info_data_table[i].variable_type;
3124 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3129 /****************************************************************************
3130 ****************************************************************************/
3132 static bool search_notify(enum spoolss_NotifyType type,
3138 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3139 if (notify_info_data_table[i].type == type &&
3140 notify_info_data_table[i].field == field &&
3141 notify_info_data_table[i].fn != NULL) {
3150 /****************************************************************************
3151 ****************************************************************************/
3153 void construct_info_data(struct spoolss_Notify *info_data,
3154 enum spoolss_NotifyType type,
3158 info_data->type = type;
3159 info_data->field.field = field;
3160 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3161 info_data->job_id = id;
3164 /*******************************************************************
3166 * fill a notify_info struct with info asked
3168 ********************************************************************/
3170 static bool construct_notify_printer_info(Printer_entry *print_hnd,
3171 struct spoolss_NotifyInfo *info,
3173 const struct spoolss_NotifyOptionType *option_type,
3175 TALLOC_CTX *mem_ctx)
3178 enum spoolss_NotifyType type;
3181 struct spoolss_Notify *current_data;
3182 NT_PRINTER_INFO_LEVEL *printer = NULL;
3183 print_queue_struct *queue=NULL;
3185 type = option_type->type;
3187 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3188 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3189 option_type->count, lp_servicename(snum)));
3191 if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &printer, 2, lp_const_servicename(snum))))
3194 for(field_num=0; field_num < option_type->count; field_num++) {
3195 field = option_type->fields[field_num].field;
3197 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3199 if (!search_notify(type, field, &j) )
3202 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3203 struct spoolss_Notify,
3205 if (info->notifies == NULL) {
3206 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3207 free_a_printer(&printer, 2);
3211 current_data = &info->notifies[info->count];
3213 construct_info_data(current_data, type, field, id);
3215 DEBUG(10,("construct_notify_printer_info: calling [%s] snum=%d printername=[%s])\n",
3216 notify_info_data_table[j].name, snum, printer->info_2->printername ));
3218 notify_info_data_table[j].fn(snum, current_data, queue,
3224 free_a_printer(&printer, 2);
3228 /*******************************************************************
3230 * fill a notify_info struct with info asked
3232 ********************************************************************/
3234 static bool construct_notify_jobs_info(print_queue_struct *queue,
3235 struct spoolss_NotifyInfo *info,
3236 NT_PRINTER_INFO_LEVEL *printer,
3238 const struct spoolss_NotifyOptionType *option_type,
3240 TALLOC_CTX *mem_ctx)
3243 enum spoolss_NotifyType type;
3245 struct spoolss_Notify *current_data;
3247 DEBUG(4,("construct_notify_jobs_info\n"));
3249 type = option_type->type;
3251 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3252 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3253 option_type->count));
3255 for(field_num=0; field_num<option_type->count; field_num++) {
3256 field = option_type->fields[field_num].field;
3258 if (!search_notify(type, field, &j) )
3261 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3262 struct spoolss_Notify,
3264 if (info->notifies == NULL) {
3265 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3269 current_data=&(info->notifies[info->count]);
3271 construct_info_data(current_data, type, field, id);
3272 notify_info_data_table[j].fn(snum, current_data, queue,
3281 * JFM: The enumeration is not that simple, it's even non obvious.
3283 * let's take an example: I want to monitor the PRINTER SERVER for
3284 * the printer's name and the number of jobs currently queued.
3285 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3286 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3288 * I have 3 printers on the back of my server.
3290 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3293 * 1 printer 1 name 1
3294 * 2 printer 1 cjob 1
3295 * 3 printer 2 name 2
3296 * 4 printer 2 cjob 2
3297 * 5 printer 3 name 3
3298 * 6 printer 3 name 3
3300 * that's the print server case, the printer case is even worse.
3303 /*******************************************************************
3305 * enumerate all printers on the printserver
3306 * fill a notify_info struct with info asked
3308 ********************************************************************/
3310 static WERROR printserver_notify_info(pipes_struct *p,
3311 struct policy_handle *hnd,
3312 struct spoolss_NotifyInfo *info,
3313 TALLOC_CTX *mem_ctx)
3316 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3317 int n_services=lp_numservices();
3319 struct spoolss_NotifyOption *option;
3320 struct spoolss_NotifyOptionType option_type;
3322 DEBUG(4,("printserver_notify_info\n"));
3327 option = Printer->notify.option;
3330 info->notifies = NULL;
3333 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3334 sending a ffpcn() request first */
3339 for (i=0; i<option->count; i++) {
3340 option_type = option->types[i];
3342 if (option_type.type != PRINTER_NOTIFY_TYPE)
3345 for (snum=0; snum<n_services; snum++)
3347 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
3348 construct_notify_printer_info ( Printer, info, snum, &option_type, snum, mem_ctx );
3354 * Debugging information, don't delete.
3357 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3358 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3359 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3361 for (i=0; i<info->count; i++) {
3362 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3363 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3364 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3371 /*******************************************************************
3373 * fill a notify_info struct with info asked
3375 ********************************************************************/
3377 static WERROR printer_notify_info(pipes_struct *p, struct policy_handle *hnd,
3378 struct spoolss_NotifyInfo *info,
3379 TALLOC_CTX *mem_ctx)
3382 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3385 struct spoolss_NotifyOption *option;
3386 struct spoolss_NotifyOptionType option_type;
3388 print_queue_struct *queue=NULL;
3389 print_status_struct status;
3391 DEBUG(4,("printer_notify_info\n"));
3396 option = Printer->notify.option;
3400 info->notifies = NULL;
3403 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3404 sending a ffpcn() request first */
3409 get_printer_snum(p, hnd, &snum, NULL);
3411 for (i=0; i<option->count; i++) {
3412 option_type = option->types[i];
3414 switch (option_type.type) {
3415 case PRINTER_NOTIFY_TYPE:
3416 if(construct_notify_printer_info(Printer, info, snum,
3422 case JOB_NOTIFY_TYPE: {
3423 NT_PRINTER_INFO_LEVEL *printer = NULL;
3425 count = print_queue_status(snum, &queue, &status);
3427 if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum))))
3430 for (j=0; j<count; j++) {
3431 construct_notify_jobs_info(&queue[j], info,
3438 free_a_printer(&printer, 2);
3448 * Debugging information, don't delete.
3451 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3452 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3453 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3455 for (i=0; i<info->count; i++) {
3456 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3457 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3458 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3464 /****************************************************************
3465 _spoolss_RouterRefreshPrinterChangeNotify
3466 ****************************************************************/
3468 WERROR _spoolss_RouterRefreshPrinterChangeNotify(pipes_struct *p,
3469 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3471 struct spoolss_NotifyInfo *info;
3473 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
3474 WERROR result = WERR_BADFID;
3476 /* we always have a spoolss_NotifyInfo struct */
3477 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3479 result = WERR_NOMEM;
3483 *r->out.info = info;
3486 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3487 "Invalid handle (%s:%u:%u).\n",
3488 OUR_HANDLE(r->in.handle)));
3492 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3495 * We are now using the change value, and
3496 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3497 * I don't have a global notification system, I'm sending back all the
3498 * informations even when _NOTHING_ has changed.
3501 /* We need to keep track of the change value to send back in
3502 RRPCN replies otherwise our updates are ignored. */
3504 Printer->notify.fnpcn = true;
3506 if (Printer->notify.client_connected) {
3507 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3508 "Saving change value in request [%x]\n",
3510 Printer->notify.change = r->in.change_low;
3513 /* just ignore the spoolss_NotifyOption */
3515 switch (Printer->printer_type) {
3517 result = printserver_notify_info(p, r->in.handle,
3521 case SPLHND_PRINTER:
3522 result = printer_notify_info(p, r->in.handle,
3527 Printer->notify.fnpcn = false;
3533 /********************************************************************
3534 * construct_printer_info_0
3535 * fill a printer_info_0 struct
3536 ********************************************************************/
3538 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3539 const NT_PRINTER_INFO_LEVEL *ntprinter,
3540 struct spoolss_PrinterInfo0 *r,
3544 counter_printer_0 *session_counter;
3546 print_status_struct status;
3548 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
3549 W_ERROR_HAVE_NO_MEMORY(r->printername);
3551 r->servername = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
3552 W_ERROR_HAVE_NO_MEMORY(r->servername);
3554 count = print_queue_length(snum, &status);
3556 /* check if we already have a counter for this printer */
3557 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3558 if (session_counter->snum == snum)
3562 /* it's the first time, add it to the list */
3563 if (session_counter == NULL) {
3564 session_counter = SMB_MALLOC_P(counter_printer_0);
3565 W_ERROR_HAVE_NO_MEMORY(session_counter);
3566 ZERO_STRUCTP(session_counter);
3567 session_counter->snum = snum;
3568 session_counter->counter = 0;
3569 DLIST_ADD(counter_list, session_counter);
3573 session_counter->counter++;
3579 setuptime = (time_t)ntprinter->info_2->setuptime;
3581 init_systemtime(&r->time, gmtime(&setuptime));
3584 * the global_counter should be stored in a TDB as it's common to all the clients
3585 * and should be zeroed on samba startup
3587 r->global_counter = session_counter->counter;
3589 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3590 r->version = 0x0005; /* NT 5 */
3591 r->free_build = 0x0893; /* build 2195 */
3593 r->max_spooling = 0;
3594 r->session_counter = session_counter->counter;
3595 r->num_error_out_of_paper = 0x0;
3596 r->num_error_not_ready = 0x0; /* number of print failure */
3598 r->number_of_processors = 0x1;
3599 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3600 r->high_part_total_bytes = 0x0;
3601 r->change_id = ntprinter->info_2->changeid; /* ChangeID in milliseconds*/
3602 r->last_error = WERR_OK;
3603 r->status = nt_printq_status(status.status);
3604 r->enumerate_network_printers = 0x0;
3605 r->c_setprinter = get_c_setprinter(); /* monotonically increasing sum of delta printer counts */
3606 r->processor_architecture = 0x0;
3607 r->processor_level = 0x6; /* 6 ???*/
3615 /****************************************************************************
3616 Convert an NT_DEVICEMODE to a spoolss_DeviceMode structure. Both pointers
3617 should be valid upon entry
3618 ****************************************************************************/
3620 static WERROR convert_nt_devicemode(TALLOC_CTX *mem_ctx,
3621 struct spoolss_DeviceMode *r,
3622 const NT_DEVICEMODE *ntdevmode)
3624 if (!r || !ntdevmode) {
3625 return WERR_INVALID_PARAM;
3628 r->devicename = talloc_strdup(mem_ctx, ntdevmode->devicename);
3629 W_ERROR_HAVE_NO_MEMORY(r->devicename);
3631 r->specversion = ntdevmode->specversion;
3632 r->driverversion = ntdevmode->driverversion;
3633 r->size = ntdevmode->size;
3634 r->__driverextra_length = ntdevmode->driverextra;
3635 r->fields = ntdevmode->fields;
3637 r->orientation = ntdevmode->orientation;
3638 r->papersize = ntdevmode->papersize;
3639 r->paperlength = ntdevmode->paperlength;
3640 r->paperwidth = ntdevmode->paperwidth;
3641 r->scale = ntdevmode->scale;
3642 r->copies = ntdevmode->copies;
3643 r->defaultsource = ntdevmode->defaultsource;
3644 r->printquality = ntdevmode->printquality;
3645 r->color = ntdevmode->color;
3646 r->duplex = ntdevmode->duplex;
3647 r->yresolution = ntdevmode->yresolution;
3648 r->ttoption = ntdevmode->ttoption;
3649 r->collate = ntdevmode->collate;
3651 r->formname = talloc_strdup(mem_ctx, ntdevmode->formname);
3652 W_ERROR_HAVE_NO_MEMORY(r->formname);
3654 /* all 0 below are values that have not been set in the old parsing/copy
3655 * function, maybe they should... - gd */
3661 r->displayflags = 0;
3662 r->displayfrequency = 0;
3663 r->icmmethod = ntdevmode->icmmethod;
3664 r->icmintent = ntdevmode->icmintent;
3665 r->mediatype = ntdevmode->mediatype;
3666 r->dithertype = ntdevmode->dithertype;
3669 r->panningwidth = 0;
3670 r->panningheight = 0;
3672 if (ntdevmode->nt_dev_private != NULL) {
3673 r->driverextra_data = data_blob_talloc(mem_ctx,
3674 ntdevmode->nt_dev_private,
3675 ntdevmode->driverextra);
3676 W_ERROR_HAVE_NO_MEMORY(r->driverextra_data.data);
3683 /****************************************************************************
3684 Create a spoolss_DeviceMode struct. Returns talloced memory.
3685 ****************************************************************************/
3687 struct spoolss_DeviceMode *construct_dev_mode(TALLOC_CTX *mem_ctx,
3688 const char *servicename)
3691 NT_PRINTER_INFO_LEVEL *printer = NULL;
3692 struct spoolss_DeviceMode *devmode = NULL;
3694 DEBUG(7,("construct_dev_mode\n"));
3696 DEBUGADD(8,("getting printer characteristics\n"));
3698 if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, servicename)))
3701 if (!printer->info_2->devmode) {
3702 DEBUG(5, ("BONG! There was no device mode!\n"));
3706 devmode = TALLOC_ZERO_P(mem_ctx, struct spoolss_DeviceMode);
3708 DEBUG(2,("construct_dev_mode: talloc fail.\n"));
3712 DEBUGADD(8,("loading DEVICEMODE\n"));
3714 result = convert_nt_devicemode(mem_ctx, devmode, printer->info_2->devmode);
3715 if (!W_ERROR_IS_OK(result)) {
3716 TALLOC_FREE(devmode);
3720 free_a_printer(&printer,2);
3725 /********************************************************************
3726 * construct_printer_info1
3727 * fill a spoolss_PrinterInfo1 struct
3728 ********************************************************************/
3730 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
3731 const NT_PRINTER_INFO_LEVEL *ntprinter,
3733 struct spoolss_PrinterInfo1 *r,
3738 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
3739 ntprinter->info_2->printername,
3740 ntprinter->info_2->drivername,
3741 ntprinter->info_2->location);
3742 W_ERROR_HAVE_NO_MEMORY(r->description);
3744 if (*ntprinter->info_2->comment == '\0') {
3745 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3747 r->comment = talloc_strdup(mem_ctx, ntprinter->info_2->comment); /* saved comment */
3749 W_ERROR_HAVE_NO_MEMORY(r->comment);
3751 r->name = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
3752 W_ERROR_HAVE_NO_MEMORY(r->name);
3757 /********************************************************************
3758 * construct_printer_info2
3759 * fill a spoolss_PrinterInfo2 struct
3760 ********************************************************************/
3762 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
3763 const NT_PRINTER_INFO_LEVEL *ntprinter,
3764 struct spoolss_PrinterInfo2 *r,
3769 print_status_struct status;
3771 count = print_queue_length(snum, &status);
3773 r->servername = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
3774 W_ERROR_HAVE_NO_MEMORY(r->servername);
3775 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
3776 W_ERROR_HAVE_NO_MEMORY(r->printername);
3777 r->sharename = talloc_strdup(mem_ctx, lp_servicename(snum));
3778 W_ERROR_HAVE_NO_MEMORY(r->sharename);
3779 r->portname = talloc_strdup(mem_ctx, ntprinter->info_2->portname);
3780 W_ERROR_HAVE_NO_MEMORY(r->portname);
3781 r->drivername = talloc_strdup(mem_ctx, ntprinter->info_2->drivername);
3782 W_ERROR_HAVE_NO_MEMORY(r->drivername);
3784 if (*ntprinter->info_2->comment == '\0') {
3785 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3787 r->comment = talloc_strdup(mem_ctx, ntprinter->info_2->comment);
3789 W_ERROR_HAVE_NO_MEMORY(r->comment);
3791 r->location = talloc_strdup(mem_ctx, ntprinter->info_2->location);
3792 W_ERROR_HAVE_NO_MEMORY(r->location);
3793 r->sepfile = talloc_strdup(mem_ctx, ntprinter->info_2->sepfile);
3794 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
3795 r->printprocessor = talloc_strdup(mem_ctx, ntprinter->info_2->printprocessor);
3796 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
3797 r->datatype = talloc_strdup(mem_ctx, ntprinter->info_2->datatype);
3798 W_ERROR_HAVE_NO_MEMORY(r->datatype);
3799 r->parameters = talloc_strdup(mem_ctx, ntprinter->info_2->parameters);
3800 W_ERROR_HAVE_NO_MEMORY(r->parameters);
3802 r->attributes = ntprinter->info_2->attributes;
3804 r->priority = ntprinter->info_2->priority;
3805 r->defaultpriority = ntprinter->info_2->default_priority;
3806 r->starttime = ntprinter->info_2->starttime;
3807 r->untiltime = ntprinter->info_2->untiltime;
3808 r->status = nt_printq_status(status.status);
3810 r->averageppm = ntprinter->info_2->averageppm;
3812 r->devmode = construct_dev_mode(mem_ctx, lp_const_servicename(snum));
3814 DEBUG(8,("Returning NULL Devicemode!\n"));
3819 if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->sd_size != 0) {
3820 /* don't use talloc_steal() here unless you do a deep steal of all
3821 the SEC_DESC members */
3823 r->secdesc = dup_sec_desc(mem_ctx, ntprinter->info_2->secdesc_buf->sd);
3829 /********************************************************************
3830 * construct_printer_info3
3831 * fill a spoolss_PrinterInfo3 struct
3832 ********************************************************************/
3834 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
3835 const NT_PRINTER_INFO_LEVEL *ntprinter,
3836 struct spoolss_PrinterInfo3 *r,
3839 /* These are the components of the SD we are returning. */
3841 if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->sd_size != 0) {
3842 /* don't use talloc_steal() here unless you do a deep steal of all
3843 the SEC_DESC members */
3845 r->secdesc = dup_sec_desc(mem_ctx,
3846 ntprinter->info_2->secdesc_buf->sd);
3847 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
3853 /********************************************************************
3854 * construct_printer_info4
3855 * fill a spoolss_PrinterInfo4 struct
3856 ********************************************************************/
3858 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
3859 const NT_PRINTER_INFO_LEVEL *ntprinter,
3860 struct spoolss_PrinterInfo4 *r,
3863 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
3864 W_ERROR_HAVE_NO_MEMORY(r->printername);
3865 r->servername = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
3866 W_ERROR_HAVE_NO_MEMORY(r->servername);
3868 r->attributes = ntprinter->info_2->attributes;
3873 /********************************************************************
3874 * construct_printer_info5
3875 * fill a spoolss_PrinterInfo5 struct
3876 ********************************************************************/
3878 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
3879 const NT_PRINTER_INFO_LEVEL *ntprinter,
3880 struct spoolss_PrinterInfo5 *r,
3883 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
3884 W_ERROR_HAVE_NO_MEMORY(r->printername);
3885 r->portname = talloc_strdup(mem_ctx, ntprinter->info_2->portname);
3886 W_ERROR_HAVE_NO_MEMORY(r->portname);
3888 r->attributes = ntprinter->info_2->attributes;
3890 /* these two are not used by NT+ according to MSDN */
3892 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
3893 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
3898 /********************************************************************
3899 * construct_printer_info_6
3900 * fill a spoolss_PrinterInfo6 struct
3901 ********************************************************************/
3903 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
3904 const NT_PRINTER_INFO_LEVEL *ntprinter,
3905 struct spoolss_PrinterInfo6 *r,
3909 print_status_struct status;
3911 count = print_queue_length(snum, &status);
3913 r->status = nt_printq_status(status.status);
3918 /********************************************************************
3919 * construct_printer_info7
3920 * fill a spoolss_PrinterInfo7 struct
3921 ********************************************************************/
3923 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
3924 Printer_entry *print_hnd,
3925 struct spoolss_PrinterInfo7 *r,
3930 if (is_printer_published(print_hnd, snum, &guid)) {
3931 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
3932 r->action = DSPRINT_PUBLISH;
3934 r->guid = talloc_strdup(mem_ctx, "");
3935 r->action = DSPRINT_UNPUBLISH;
3937 W_ERROR_HAVE_NO_MEMORY(r->guid);
3942 /********************************************************************
3943 * construct_printer_info8
3944 * fill a spoolss_PrinterInfo8 struct
3945 ********************************************************************/
3947 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
3948 const NT_PRINTER_INFO_LEVEL *ntprinter,
3949 struct spoolss_DeviceModeInfo *r,
3952 r->devmode = construct_dev_mode(mem_ctx, lp_const_servicename(snum));
3954 DEBUG(8,("Returning NULL Devicemode!\n"));
3961 /********************************************************************
3962 ********************************************************************/
3964 static bool snum_is_shared_printer(int snum)
3966 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
3969 /********************************************************************
3970 Spoolss_enumprinters.
3971 ********************************************************************/
3973 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
3976 union spoolss_PrinterInfo **info_p,
3980 int n_services = lp_numservices();
3981 union spoolss_PrinterInfo *info = NULL;
3983 WERROR result = WERR_OK;
3988 for (snum = 0; snum < n_services; snum++) {
3990 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
3992 if (!snum_is_shared_printer(snum)) {
3996 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
3997 lp_servicename(snum), snum));
3999 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4000 union spoolss_PrinterInfo,
4003 result = WERR_NOMEM;
4007 result = get_a_printer(NULL, &ntprinter, 2,
4008 lp_const_servicename(snum));
4009 if (!W_ERROR_IS_OK(result)) {
4015 result = construct_printer_info0(info, ntprinter,
4016 &info[count].info0, snum);
4019 result = construct_printer_info1(info, ntprinter, flags,
4020 &info[count].info1, snum);
4023 result = construct_printer_info2(info, ntprinter,
4024 &info[count].info2, snum);
4027 result = construct_printer_info4(info, ntprinter,
4028 &info[count].info4, snum);
4031 result = construct_printer_info5(info, ntprinter,
4032 &info[count].info5, snum);
4036 result = WERR_UNKNOWN_LEVEL;
4037 free_a_printer(&ntprinter, 2);
4041 free_a_printer(&ntprinter, 2);
4042 if (!W_ERROR_IS_OK(result)) {
4053 if (!W_ERROR_IS_OK(result)) {
4063 /********************************************************************
4064 * handle enumeration of printers at level 0
4065 ********************************************************************/
4067 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
4069 const char *servername,
4070 union spoolss_PrinterInfo **info,
4073 DEBUG(4,("enum_all_printers_info_0\n"));
4075 return enum_all_printers_info_level(mem_ctx, 0, flags, info, count);
4079 /********************************************************************
4080 ********************************************************************/
4082 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
4084 union spoolss_PrinterInfo **info,
4087 DEBUG(4,("enum_all_printers_info_1\n"));
4089 return enum_all_printers_info_level(mem_ctx, 1, flags, info, count);
4092 /********************************************************************
4093 enum_all_printers_info_1_local.
4094 *********************************************************************/
4096 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
4097 union spoolss_PrinterInfo **info,
4100 DEBUG(4,("enum_all_printers_info_1_local\n"));
4102 return enum_all_printers_info_1(mem_ctx, PRINTER_ENUM_ICON8, info, count);
4105 /********************************************************************
4106 enum_all_printers_info_1_name.
4107 *********************************************************************/
4109 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
4111 union spoolss_PrinterInfo **info,
4114 const char *s = name;
4116 DEBUG(4,("enum_all_printers_info_1_name\n"));
4118 if ((name[0] == '\\') && (name[1] == '\\')) {
4122 if (!is_myname_or_ipaddr(s)) {
4123 return WERR_INVALID_NAME;
4126 return enum_all_printers_info_1(mem_ctx, PRINTER_ENUM_ICON8, info, count);
4129 /********************************************************************
4130 enum_all_printers_info_1_network.
4131 *********************************************************************/
4133 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
4135 union spoolss_PrinterInfo **info,
4138 const char *s = name;
4140 DEBUG(4,("enum_all_printers_info_1_network\n"));
4142 /* If we respond to a enum_printers level 1 on our name with flags
4143 set to PRINTER_ENUM_REMOTE with a list of printers then these
4144 printers incorrectly appear in the APW browse list.
4145 Specifically the printers for the server appear at the workgroup
4146 level where all the other servers in the domain are
4147 listed. Windows responds to this call with a
4148 WERR_CAN_NOT_COMPLETE so we should do the same. */
4150 if (name[0] == '\\' && name[1] == '\\') {
4154 if (is_myname_or_ipaddr(s)) {
4155 return WERR_CAN_NOT_COMPLETE;
4158 return enum_all_printers_info_1(mem_ctx, PRINTER_ENUM_NAME, info, count);
4161 /********************************************************************
4162 * api_spoolss_enumprinters
4164 * called from api_spoolss_enumprinters (see this to understand)
4165 ********************************************************************/
4167 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
4168 union spoolss_PrinterInfo **info,
4171 DEBUG(4,("enum_all_printers_info_2\n"));
4173 return enum_all_printers_info_level(mem_ctx, 2, 0, info, count);
4176 /********************************************************************
4177 * handle enumeration of printers at level 1
4178 ********************************************************************/
4180 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
4183 union spoolss_PrinterInfo **info,
4186 /* Not all the flags are equals */
4188 if (flags & PRINTER_ENUM_LOCAL) {
4189 return enum_all_printers_info_1_local(mem_ctx, info, count);
4192 if (flags & PRINTER_ENUM_NAME) {
4193 return enum_all_printers_info_1_name(mem_ctx, name, info, count);
4196 if (flags & PRINTER_ENUM_NETWORK) {
4197 return enum_all_printers_info_1_network(mem_ctx, name, info, count);
4200 return WERR_OK; /* NT4sp5 does that */
4203 /********************************************************************
4204 * handle enumeration of printers at level 2
4205 ********************************************************************/
4207 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4209 const char *servername,
4210 union spoolss_PrinterInfo **info,
4213 if (flags & PRINTER_ENUM_LOCAL) {
4214 return enum_all_printers_info_2(mem_ctx, info, count);
4217 if (flags & PRINTER_ENUM_NAME) {
4218 if (!is_myname_or_ipaddr(canon_servername(servername))) {
4219 return WERR_INVALID_NAME;
4222 return enum_all_printers_info_2(mem_ctx, info, count);
4225 if (flags & PRINTER_ENUM_REMOTE) {
4226 return WERR_UNKNOWN_LEVEL;
4232 /********************************************************************
4233 * handle enumeration of printers at level 4
4234 ********************************************************************/
4236 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4238 const char *servername,
4239 union spoolss_PrinterInfo **info,
4242 DEBUG(4,("enum_all_printers_info_4\n"));
4244 return enum_all_printers_info_level(mem_ctx, 4, flags, info, count);
4248 /********************************************************************
4249 * handle enumeration of printers at level 5
4250 ********************************************************************/
4252 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4254 const char *servername,
4255 union spoolss_PrinterInfo **info,
4258 DEBUG(4,("enum_all_printers_info_5\n"));
4260 return enum_all_printers_info_level(mem_ctx, 5, flags, info, count);
4263 /****************************************************************
4264 _spoolss_EnumPrinters
4265 ****************************************************************/
4267 WERROR _spoolss_EnumPrinters(pipes_struct *p,
4268 struct spoolss_EnumPrinters *r)
4270 const char *name = NULL;
4273 /* that's an [in out] buffer */
4275 if (!r->in.buffer && (r->in.offered != 0)) {
4276 return WERR_INVALID_PARAM;
4279 DEBUG(4,("_spoolss_EnumPrinters\n"));
4283 *r->out.info = NULL;
4287 * flags==PRINTER_ENUM_NAME
4288 * if name=="" then enumerates all printers
4289 * if name!="" then enumerate the printer
4290 * flags==PRINTER_ENUM_REMOTE
4291 * name is NULL, enumerate printers
4292 * Level 2: name!="" enumerates printers, name can't be NULL
4293 * Level 3: doesn't exist
4294 * Level 4: does a local registry lookup
4295 * Level 5: same as Level 2
4299 name = talloc_strdup_upper(p->mem_ctx, r->in.server);
4300 W_ERROR_HAVE_NO_MEMORY(name);
4303 switch (r->in.level) {
4305 result = enumprinters_level0(p->mem_ctx, r->in.flags, name,
4306 r->out.info, r->out.count);
4309 result = enumprinters_level1(p->mem_ctx, r->in.flags, name,
4310 r->out.info, r->out.count);
4313 result = enumprinters_level2(p->mem_ctx, r->in.flags, name,
4314 r->out.info, r->out.count);
4317 result = enumprinters_level4(p->mem_ctx, r->in.flags, name,
4318 r->out.info, r->out.count);
4321 result = enumprinters_level5(p->mem_ctx, r->in.flags, name,
4322 r->out.info, r->out.count);
4325 return WERR_UNKNOWN_LEVEL;
4328 if (!W_ERROR_IS_OK(result)) {
4332 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4333 spoolss_EnumPrinters, NULL,
4334 *r->out.info, r->in.level,
4336 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4337 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4339 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4342 /****************************************************************
4344 ****************************************************************/
4346 WERROR _spoolss_GetPrinter(pipes_struct *p,
4347 struct spoolss_GetPrinter *r)
4349 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
4350 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
4351 WERROR result = WERR_OK;
4355 /* that's an [in out] buffer */
4357 if (!r->in.buffer && (r->in.offered != 0)) {
4358 return WERR_INVALID_PARAM;
4363 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4367 result = get_a_printer(Printer, &ntprinter, 2,
4368 lp_const_servicename(snum));
4369 if (!W_ERROR_IS_OK(result)) {
4373 switch (r->in.level) {
4375 result = construct_printer_info0(p->mem_ctx, ntprinter,
4376 &r->out.info->info0, snum);
4379 result = construct_printer_info1(p->mem_ctx, ntprinter,
4381 &r->out.info->info1, snum);
4384 result = construct_printer_info2(p->mem_ctx, ntprinter,
4385 &r->out.info->info2, snum);
4388 result = construct_printer_info3(p->mem_ctx, ntprinter,
4389 &r->out.info->info3, snum);
4392 result = construct_printer_info4(p->mem_ctx, ntprinter,
4393 &r->out.info->info4, snum);
4396 result = construct_printer_info5(p->mem_ctx, ntprinter,
4397 &r->out.info->info5, snum);
4400 result = construct_printer_info6(p->mem_ctx, ntprinter,
4401 &r->out.info->info6, snum);
4404 result = construct_printer_info7(p->mem_ctx, Printer,
4405 &r->out.info->info7, snum);
4408 result = construct_printer_info8(p->mem_ctx, ntprinter,
4409 &r->out.info->info8, snum);
4412 result = WERR_UNKNOWN_LEVEL;
4416 free_a_printer(&ntprinter, 2);
4418 if (!W_ERROR_IS_OK(result)) {
4419 TALLOC_FREE(r->out.info);
4423 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo, NULL,
4424 r->out.info, r->in.level);
4425 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4427 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4430 /********************************************************************
4431 ********************************************************************/
4433 static const char **string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4434 const char **string_array,
4435 const char *cservername)
4437 int i, num_strings = 0;
4438 const char **array = NULL;
4440 if (!string_array) {
4444 for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
4446 const char *str = talloc_asprintf(mem_ctx, "\\\\%s%s",
4447 cservername, string_array[i]);
4454 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4461 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4462 &array, &num_strings);
4468 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4470 if (in && strlen(in)) { \
4471 out = talloc_strdup(mem_ctx, in); \
4472 W_ERROR_HAVE_NO_MEMORY(out); \
4478 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, in, out) \
4480 if (in && strlen(in)) { \
4481 out = talloc_asprintf(mem_ctx, "\\\\%s%s", server, in); \
4483 out = talloc_strdup(mem_ctx, ""); \
4485 W_ERROR_HAVE_NO_MEMORY(out); \
4488 /********************************************************************
4489 * fill a spoolss_DriverInfo1 struct
4490 ********************************************************************/
4492 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4493 struct spoolss_DriverInfo1 *r,
4494 const struct spoolss_DriverInfo8 *driver,
4495 const char *servername)
4497 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4498 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4503 /********************************************************************
4504 * fill a spoolss_DriverInfo2 struct
4505 ********************************************************************/
4507 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4508 struct spoolss_DriverInfo2 *r,
4509 const struct spoolss_DriverInfo8 *driver,
4510 const char *servername)
4513 const char *cservername = canon_servername(servername);
4515 r->version = driver->version;
4517 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4518 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4519 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4520 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4522 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4523 driver->driver_path,
4526 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4530 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4531 driver->config_file,
4537 /********************************************************************
4538 * fill a spoolss_DriverInfo3 struct
4539 ********************************************************************/
4541 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4542 struct spoolss_DriverInfo3 *r,
4543 const struct spoolss_DriverInfo8 *driver,
4544 const char *servername)
4546 const char *cservername = canon_servername(servername);
4548 r->version = driver->version;
4550 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4551 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4552 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4553 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4555 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4556 driver->driver_path,
4559 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4563 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4564 driver->config_file,
4567 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4571 FILL_DRIVER_STRING(mem_ctx,
4572 driver->monitor_name,
4575 FILL_DRIVER_STRING(mem_ctx,
4576 driver->default_datatype,
4577 r->default_datatype);
4579 r->dependent_files = string_array_from_driver_info(mem_ctx,
4580 driver->dependent_files,
4585 /********************************************************************
4586 * fill a spoolss_DriverInfo4 struct
4587 ********************************************************************/
4589 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
4590 struct spoolss_DriverInfo4 *r,
4591 const struct spoolss_DriverInfo8 *driver,
4592 const char *servername)
4594 const char *cservername = canon_servername(servername);
4596 r->version = driver->version;
4598 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4599 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4600 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4601 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4603 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4604 driver->driver_path,
4607 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4611 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4612 driver->config_file,
4615 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4619 r->dependent_files = string_array_from_driver_info(mem_ctx,
4620 driver->dependent_files,
4623 FILL_DRIVER_STRING(mem_ctx,
4624 driver->monitor_name,
4627 FILL_DRIVER_STRING(mem_ctx,
4628 driver->default_datatype,
4629 r->default_datatype);
4631 r->previous_names = string_array_from_driver_info(mem_ctx,
4632 driver->previous_names,
4638 /********************************************************************
4639 * fill a spoolss_DriverInfo5 struct
4640 ********************************************************************/
4642 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
4643 struct spoolss_DriverInfo5 *r,
4644 const struct spoolss_DriverInfo8 *driver,
4645 const char *servername)
4647 const char *cservername = canon_servername(servername);
4649 r->version = driver->version;
4651 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4652 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4653 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4654 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4656 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4657 driver->driver_path,
4660 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4664 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4665 driver->config_file,
4668 r->driver_attributes = 0;
4669 r->config_version = 0;
4670 r->driver_version = 0;
4674 /********************************************************************
4675 * fill a spoolss_DriverInfo6 struct
4676 ********************************************************************/
4678 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
4679 struct spoolss_DriverInfo6 *r,
4680 const struct spoolss_DriverInfo8 *driver,
4681 const char *servername)
4683 const char *cservername = canon_servername(servername);
4685 r->version = driver->version;
4687 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4688 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4689 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4690 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4692 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4693 driver->driver_path,
4696 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4700 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4701 driver->config_file,
4704 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4708 FILL_DRIVER_STRING(mem_ctx,
4709 driver->monitor_name,
4712 FILL_DRIVER_STRING(mem_ctx,
4713 driver->default_datatype,
4714 r->default_datatype);
4716 r->dependent_files = string_array_from_driver_info(mem_ctx,
4717 driver->dependent_files,
4719 r->previous_names = string_array_from_driver_info(mem_ctx,
4720 driver->previous_names,
4723 r->driver_date = driver->driver_date;
4724 r->driver_version = driver->driver_version;
4726 FILL_DRIVER_STRING(mem_ctx,
4727 driver->manufacturer_name,
4728 r->manufacturer_name);
4729 FILL_DRIVER_STRING(mem_ctx,
4730 driver->manufacturer_url,
4731 r->manufacturer_url);
4732 FILL_DRIVER_STRING(mem_ctx,
4733 driver->hardware_id,
4735 FILL_DRIVER_STRING(mem_ctx,
4742 /********************************************************************
4743 * fill a spoolss_DriverInfo8 struct
4744 ********************************************************************/
4746 static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
4747 struct spoolss_DriverInfo8 *r,
4748 const struct spoolss_DriverInfo8 *driver,
4749 const char *servername)
4751 const char *cservername = canon_servername(servername);
4753 r->version = driver->version;
4755 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4756 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4757 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4758 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4760 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4761 driver->driver_path,
4764 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4768 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4769 driver->config_file,
4772 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4776 FILL_DRIVER_STRING(mem_ctx,
4777 driver->monitor_name,
4780 FILL_DRIVER_STRING(mem_ctx,
4781 driver->default_datatype,
4782 r->default_datatype);
4784 r->dependent_files = string_array_from_driver_info(mem_ctx,
4785 driver->dependent_files,
4787 r->previous_names = string_array_from_driver_info(mem_ctx,
4788 driver->previous_names,
4791 r->driver_date = driver->driver_date;
4792 r->driver_version = driver->driver_version;
4794 FILL_DRIVER_STRING(mem_ctx,
4795 driver->manufacturer_name,
4796 r->manufacturer_name);
4797 FILL_DRIVER_STRING(mem_ctx,
4798 driver->manufacturer_url,
4799 r->manufacturer_url);
4800 FILL_DRIVER_STRING(mem_ctx,
4801 driver->hardware_id,
4803 FILL_DRIVER_STRING(mem_ctx,
4807 FILL_DRIVER_STRING(mem_ctx,
4808 driver->print_processor,
4809 r->print_processor);
4810 FILL_DRIVER_STRING(mem_ctx,
4811 driver->vendor_setup,
4814 r->color_profiles = string_array_from_driver_info(mem_ctx,
4815 driver->color_profiles,
4818 FILL_DRIVER_STRING(mem_ctx,
4822 r->printer_driver_attributes = driver->printer_driver_attributes;
4824 r->core_driver_dependencies = string_array_from_driver_info(mem_ctx,
4825 driver->core_driver_dependencies,
4828 r->min_inbox_driver_ver_date = driver->min_inbox_driver_ver_date;
4829 r->min_inbox_driver_ver_version = driver->min_inbox_driver_ver_version;
4834 #if 0 /* disabled until marshalling issues are resolved - gd */
4835 /********************************************************************
4836 ********************************************************************/
4838 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
4839 struct spoolss_DriverFileInfo *r,
4840 const char *cservername,
4841 const char *file_name,
4842 enum spoolss_DriverFileType file_type,
4843 uint32_t file_version)
4845 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
4846 cservername, file_name);
4847 W_ERROR_HAVE_NO_MEMORY(r->file_name);
4848 r->file_type = file_type;
4849 r->file_version = file_version;
4854 /********************************************************************
4855 ********************************************************************/
4857 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
4858 const struct spoolss_DriverInfo8 *driver,
4859 const char *cservername,
4860 struct spoolss_DriverFileInfo **info_p,
4863 struct spoolss_DriverFileInfo *info = NULL;
4871 if (strlen(driver->driver_path)) {
4872 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4873 struct spoolss_DriverFileInfo,
4875 W_ERROR_HAVE_NO_MEMORY(info);
4876 result = fill_spoolss_DriverFileInfo(info,
4879 driver->driver_path,
4880 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
4882 W_ERROR_NOT_OK_RETURN(result);
4886 if (strlen(driver->config_file)) {
4887 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4888 struct spoolss_DriverFileInfo,
4890 W_ERROR_HAVE_NO_MEMORY(info);
4891 result = fill_spoolss_DriverFileInfo(info,
4894 driver->config_file,
4895 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
4897 W_ERROR_NOT_OK_RETURN(result);
4901 if (strlen(driver->data_file)) {
4902 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4903 struct spoolss_DriverFileInfo,
4905 W_ERROR_HAVE_NO_MEMORY(info);
4906 result = fill_spoolss_DriverFileInfo(info,
4910 SPOOLSS_DRIVER_FILE_TYPE_DATA,
4912 W_ERROR_NOT_OK_RETURN(result);
4916 if (strlen(driver->help_file)) {
4917 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4918 struct spoolss_DriverFileInfo,
4920 W_ERROR_HAVE_NO_MEMORY(info);
4921 result = fill_spoolss_DriverFileInfo(info,
4925 SPOOLSS_DRIVER_FILE_TYPE_HELP,
4927 W_ERROR_NOT_OK_RETURN(result);
4931 for (i=0; driver->dependent_files[i] && driver->dependent_files[i][0] != '\0'; i++) {
4932 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4933 struct spoolss_DriverFileInfo,
4935 W_ERROR_HAVE_NO_MEMORY(info);
4936 result = fill_spoolss_DriverFileInfo(info,
4939 driver->dependent_files[i],
4940 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
4942 W_ERROR_NOT_OK_RETURN(result);
4952 /********************************************************************
4953 * fill a spoolss_DriverInfo101 struct
4954 ********************************************************************/
4956 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
4957 struct spoolss_DriverInfo101 *r,
4958 const struct spoolss_DriverInfo8 *driver,
4959 const char *servername)
4961 const char *cservername = canon_servername(servername);
4964 r->version = driver->version;
4966 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4967 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4968 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4969 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4971 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
4975 if (!W_ERROR_IS_OK(result)) {
4979 FILL_DRIVER_STRING(mem_ctx,
4980 driver->monitor_name,
4983 FILL_DRIVER_STRING(mem_ctx,
4984 driver->default_datatype,
4985 r->default_datatype);
4987 r->previous_names = string_array_from_driver_info(mem_ctx,
4988 driver->previous_names,
4990 r->driver_date = driver->driver_date;
4991 r->driver_version = driver->driver_version;
4993 FILL_DRIVER_STRING(mem_ctx,
4994 driver->manufacturer_name,
4995 r->manufacturer_name);
4996 FILL_DRIVER_STRING(mem_ctx,
4997 driver->manufacturer_url,
4998 r->manufacturer_url);
4999 FILL_DRIVER_STRING(mem_ctx,
5000 driver->hardware_id,
5002 FILL_DRIVER_STRING(mem_ctx,
5009 /********************************************************************
5010 ********************************************************************/
5012 static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
5014 union spoolss_DriverInfo *r,
5016 const char *servername,
5017 const char *architecture,
5020 NT_PRINTER_INFO_LEVEL *printer = NULL;
5021 struct spoolss_DriverInfo8 *driver;
5024 result = get_a_printer(NULL, &printer, 2, lp_const_servicename(snum));
5026 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5027 win_errstr(result)));
5029 if (!W_ERROR_IS_OK(result)) {
5030 return WERR_INVALID_PRINTER_NAME;
5033 result = get_a_printer_driver(mem_ctx, &driver, printer->info_2->drivername,
5034 architecture, version);
5036 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5037 win_errstr(result)));
5039 if (!W_ERROR_IS_OK(result)) {
5041 * Is this a W2k client ?
5045 free_a_printer(&printer, 2);
5046 return WERR_UNKNOWN_PRINTER_DRIVER;
5049 /* Yes - try again with a WinNT driver. */
5051 result = get_a_printer_driver(mem_ctx, &driver, printer->info_2->drivername,
5052 architecture, version);
5053 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5054 win_errstr(result)));
5055 if (!W_ERROR_IS_OK(result)) {
5056 free_a_printer(&printer, 2);
5057 return WERR_UNKNOWN_PRINTER_DRIVER;
5063 result = fill_printer_driver_info1(mem_ctx, &r->info1, driver, servername);
5066 result = fill_printer_driver_info2(mem_ctx, &r->info2, driver, servername);
5069 result = fill_printer_driver_info3(mem_ctx, &r->info3, driver, servername);
5072 result = fill_printer_driver_info4(mem_ctx, &r->info4, driver, servername);
5075 result = fill_printer_driver_info5(mem_ctx, &r->info5, driver, servername);
5078 result = fill_printer_driver_info6(mem_ctx, &r->info6, driver, servername);
5081 result = fill_printer_driver_info8(mem_ctx, &r->info8, driver, servername);
5083 #if 0 /* disabled until marshalling issues are resolved - gd */
5085 result = fill_printer_driver_info101(mem_ctx, &r->info101, driver, servername);
5089 result = WERR_UNKNOWN_LEVEL;
5093 free_a_printer(&printer, 2);
5094 free_a_printer_driver(driver);
5099 /****************************************************************
5100 _spoolss_GetPrinterDriver2
5101 ****************************************************************/
5103 WERROR _spoolss_GetPrinterDriver2(pipes_struct *p,
5104 struct spoolss_GetPrinterDriver2 *r)
5106 Printer_entry *printer;
5109 const char *servername;
5112 /* that's an [in out] buffer */
5114 if (!r->in.buffer && (r->in.offered != 0)) {
5115 return WERR_INVALID_PARAM;
5118 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5120 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5121 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5122 return WERR_INVALID_PRINTER_NAME;
5126 *r->out.server_major_version = 0;
5127 *r->out.server_minor_version = 0;
5129 servername = get_server_name(printer);
5131 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5135 result = construct_printer_driver_info_level(p->mem_ctx, r->in.level,
5139 r->in.client_major_version);
5140 if (!W_ERROR_IS_OK(result)) {
5141 TALLOC_FREE(r->out.info);
5145 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo, NULL,
5146 r->out.info, r->in.level);
5147 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5149 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5153 /****************************************************************
5154 _spoolss_StartPagePrinter
5155 ****************************************************************/
5157 WERROR _spoolss_StartPagePrinter(pipes_struct *p,
5158 struct spoolss_StartPagePrinter *r)
5160 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5163 DEBUG(3,("_spoolss_StartPagePrinter: "
5164 "Error in startpageprinter printer handle\n"));
5168 Printer->page_started = true;
5172 /****************************************************************
5173 _spoolss_EndPagePrinter
5174 ****************************************************************/
5176 WERROR _spoolss_EndPagePrinter(pipes_struct *p,
5177 struct spoolss_EndPagePrinter *r)
5181 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5184 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5185 OUR_HANDLE(r->in.handle)));
5189 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5192 Printer->page_started = false;
5193 print_job_endpage(snum, Printer->jobid);
5198 /****************************************************************
5199 _spoolss_StartDocPrinter
5200 ****************************************************************/
5202 WERROR _spoolss_StartDocPrinter(pipes_struct *p,
5203 struct spoolss_StartDocPrinter *r)
5205 struct spoolss_DocumentInfo1 *info_1;
5207 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5210 DEBUG(2,("_spoolss_StartDocPrinter: "
5211 "Invalid handle (%s:%u:%u)\n",
5212 OUR_HANDLE(r->in.handle)));
5216 if (r->in.level != 1) {
5217 return WERR_UNKNOWN_LEVEL;
5220 info_1 = r->in.info.info1;
5223 * a nice thing with NT is it doesn't listen to what you tell it.
5224 * when asked to send _only_ RAW datas, it tries to send datas
5227 * So I add checks like in NT Server ...
5230 if (info_1->datatype) {
5231 if (strcmp(info_1->datatype, "RAW") != 0) {
5233 return WERR_INVALID_DATATYPE;
5237 /* get the share number of the printer */
5238 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5242 Printer->jobid = print_job_start(p->server_info, snum,
5243 info_1->document_name,
5244 Printer->nt_devmode);
5246 /* An error occured in print_job_start() so return an appropriate
5249 if (Printer->jobid == -1) {
5250 return map_werror_from_unix(errno);
5253 Printer->document_started = true;
5254 *r->out.job_id = Printer->jobid;
5259 /****************************************************************
5260 _spoolss_EndDocPrinter
5261 ****************************************************************/
5263 WERROR _spoolss_EndDocPrinter(pipes_struct *p,
5264 struct spoolss_EndDocPrinter *r)
5266 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5270 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5271 OUR_HANDLE(r->in.handle)));
5275 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5279 Printer->document_started = false;
5280 print_job_end(snum, Printer->jobid, NORMAL_CLOSE);
5281 /* error codes unhandled so far ... */
5286 /****************************************************************
5287 _spoolss_WritePrinter
5288 ****************************************************************/
5290 WERROR _spoolss_WritePrinter(pipes_struct *p,
5291 struct spoolss_WritePrinter *r)
5293 uint32_t buffer_written;
5295 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5298 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5299 OUR_HANDLE(r->in.handle)));
5300 *r->out.num_written = r->in._data_size;
5304 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5307 buffer_written = (uint32_t)print_job_write(snum, Printer->jobid,
5308 (const char *)r->in.data.data,
5310 (size_t)r->in._data_size);
5311 if (buffer_written == (uint32_t)-1) {
5312 *r->out.num_written = 0;
5313 if (errno == ENOSPC)
5314 return WERR_NO_SPOOL_SPACE;
5316 return WERR_ACCESS_DENIED;
5319 *r->out.num_written = r->in._data_size;
5324 /********************************************************************
5325 * api_spoolss_getprinter
5326 * called from the spoolss dispatcher
5328 ********************************************************************/
5330 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5334 WERROR errcode = WERR_BADFUNC;
5335 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5338 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5339 OUR_HANDLE(handle)));
5343 if (!get_printer_snum(p, handle, &snum, NULL))
5347 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5348 errcode = print_queue_pause(p->server_info, snum);
5350 case SPOOLSS_PRINTER_CONTROL_RESUME:
5351 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5352 errcode = print_queue_resume(p->server_info, snum);
5354 case SPOOLSS_PRINTER_CONTROL_PURGE:
5355 errcode = print_queue_purge(p->server_info, snum);
5358 return WERR_UNKNOWN_LEVEL;
5365 /****************************************************************
5366 _spoolss_AbortPrinter
5367 * From MSDN: "Deletes printer's spool file if printer is configured
5369 ****************************************************************/
5371 WERROR _spoolss_AbortPrinter(pipes_struct *p,
5372 struct spoolss_AbortPrinter *r)
5374 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5376 WERROR errcode = WERR_OK;
5379 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5380 OUR_HANDLE(r->in.handle)));
5384 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5387 print_job_delete(p->server_info, snum, Printer->jobid, &errcode );
5392 /********************************************************************
5393 * called by spoolss_api_setprinter
5394 * when updating a printer description
5395 ********************************************************************/
5397 static WERROR update_printer_sec(struct policy_handle *handle,
5398 pipes_struct *p, SEC_DESC_BUF *secdesc_ctr)
5400 SEC_DESC_BUF *new_secdesc_ctr = NULL, *old_secdesc_ctr = NULL;
5404 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5406 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
5407 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5408 OUR_HANDLE(handle)));
5410 result = WERR_BADFID;
5415 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5416 result = WERR_INVALID_PARAM;
5420 /* Check the user has permissions to change the security
5421 descriptor. By experimentation with two NT machines, the user
5422 requires Full Access to the printer to change security
5425 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
5426 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5427 result = WERR_ACCESS_DENIED;
5431 /* NT seems to like setting the security descriptor even though
5432 nothing may have actually changed. */
5434 if ( !nt_printing_getsec(p->mem_ctx, Printer->sharename, &old_secdesc_ctr)) {
5435 DEBUG(2,("update_printer_sec: nt_printing_getsec() failed\n"));
5436 result = WERR_BADFID;
5440 if (DEBUGLEVEL >= 10) {
5444 the_acl = old_secdesc_ctr->sd->dacl;
5445 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
5446 PRINTERNAME(snum), the_acl->num_aces));
5448 for (i = 0; i < the_acl->num_aces; i++) {
5449 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5450 &the_acl->aces[i].trustee),
5451 the_acl->aces[i].access_mask));
5454 the_acl = secdesc_ctr->sd->dacl;
5457 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
5458 PRINTERNAME(snum), the_acl->num_aces));
5460 for (i = 0; i < the_acl->num_aces; i++) {
5461 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5462 &the_acl->aces[i].trustee),
5463 the_acl->aces[i].access_mask));
5466 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
5470 new_secdesc_ctr = sec_desc_merge(p->mem_ctx, secdesc_ctr, old_secdesc_ctr);
5471 if (!new_secdesc_ctr) {
5472 result = WERR_NOMEM;
5476 if (security_descriptor_equal(new_secdesc_ctr->sd, old_secdesc_ctr->sd)) {
5481 result = nt_printing_setsec(Printer->sharename, new_secdesc_ctr);
5488 /********************************************************************
5489 Canonicalize printer info from a client
5491 ATTN: It does not matter what we set the servername to hear
5492 since we do the necessary work in get_a_printer() to set it to
5493 the correct value based on what the client sent in the
5494 _spoolss_open_printer_ex().
5495 ********************************************************************/
5497 static bool check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum)
5499 fstring printername;
5502 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
5503 "portname=%s drivername=%s comment=%s location=%s\n",
5504 info->servername, info->printername, info->sharename,
5505 info->portname, info->drivername, info->comment, info->location));
5507 /* we force some elements to "correct" values */
5508 slprintf(info->servername, sizeof(info->servername)-1, "\\\\%s", global_myname());
5509 fstrcpy(info->sharename, lp_servicename(snum));
5511 /* check to see if we allow printername != sharename */
5513 if ( lp_force_printername(snum) ) {
5514 slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s",
5515 global_myname(), info->sharename );
5518 /* make sure printername is in \\server\printername format */
5520 fstrcpy( printername, info->printername );
5522 if ( printername[0] == '\\' && printername[1] == '\\' ) {
5523 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
5527 slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s",
5528 global_myname(), p );
5531 info->attributes |= PRINTER_ATTRIBUTE_SAMBA;
5532 info->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
5539 /****************************************************************************
5540 ****************************************************************************/
5542 static WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *portname, const char *uri)
5544 char *cmd = lp_addport_cmd();
5545 char *command = NULL;
5547 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5548 bool is_print_op = false;
5551 return WERR_ACCESS_DENIED;
5554 command = talloc_asprintf(ctx,
5555 "%s \"%s\" \"%s\"", cmd, portname, uri );
5561 is_print_op = user_has_privileges( token, &se_printop );
5563 DEBUG(10,("Running [%s]\n", command));
5565 /********* BEGIN SePrintOperatorPrivilege **********/
5570 ret = smbrun(command, NULL);
5575 /********* END SePrintOperatorPrivilege **********/
5577 DEBUGADD(10,("returned [%d]\n", ret));
5579 TALLOC_FREE(command);
5582 return WERR_ACCESS_DENIED;
5588 /****************************************************************************
5589 ****************************************************************************/
5591 bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer)
5593 char *cmd = lp_addprinter_cmd();
5595 char *command = NULL;
5599 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5600 bool is_print_op = false;
5601 char *remote_machine = talloc_strdup(ctx, "%m");
5603 if (!remote_machine) {
5606 remote_machine = talloc_sub_basic(ctx,
5607 current_user_info.smb_name,
5608 current_user_info.domain,
5610 if (!remote_machine) {
5614 command = talloc_asprintf(ctx,
5615 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
5616 cmd, printer->info_2->printername, printer->info_2->sharename,
5617 printer->info_2->portname, printer->info_2->drivername,
5618 printer->info_2->location, printer->info_2->comment, remote_machine);
5624 is_print_op = user_has_privileges( token, &se_printop );
5626 DEBUG(10,("Running [%s]\n", command));
5628 /********* BEGIN SePrintOperatorPrivilege **********/
5633 if ( (ret = smbrun(command, &fd)) == 0 ) {
5634 /* Tell everyone we updated smb.conf. */
5635 message_send_all(smbd_messaging_context(),
5636 MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
5642 /********* END SePrintOperatorPrivilege **********/
5644 DEBUGADD(10,("returned [%d]\n", ret));
5646 TALLOC_FREE(command);
5647 TALLOC_FREE(remote_machine);
5655 /* reload our services immediately */
5657 reload_services(false);
5661 /* Get lines and convert them back to dos-codepage */
5662 qlines = fd_lines_load(fd, &numlines, 0, NULL);
5663 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
5666 /* Set the portname to what the script says the portname should be. */
5667 /* but don't require anything to be return from the script exit a good error code */
5670 /* Set the portname to what the script says the portname should be. */
5671 strncpy(printer->info_2->portname, qlines[0], sizeof(printer->info_2->portname));
5672 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
5675 TALLOC_FREE(qlines);
5680 /********************************************************************
5681 * Called by spoolss_api_setprinter
5682 * when updating a printer description.
5683 ********************************************************************/
5685 static WERROR update_printer(pipes_struct *p, struct policy_handle *handle,
5686 struct spoolss_SetPrinterInfoCtr *info_ctr,
5687 struct spoolss_DeviceMode *devmode)
5690 NT_PRINTER_INFO_LEVEL *printer = NULL, *old_printer = NULL;
5691 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5696 DEBUG(8,("update_printer\n"));
5701 result = WERR_BADFID;
5705 if (!get_printer_snum(p, handle, &snum, NULL)) {
5706 result = WERR_BADFID;
5710 if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum))) ||
5711 (!W_ERROR_IS_OK(get_a_printer(Printer, &old_printer, 2, lp_const_servicename(snum))))) {
5712 result = WERR_BADFID;
5716 DEBUGADD(8,("Converting info_2 struct\n"));
5719 * convert_printer_info converts the incoming
5720 * info from the client and overwrites the info
5721 * just read from the tdb in the pointer 'printer'.
5724 if (!convert_printer_info(info_ctr, printer)) {
5725 result = WERR_NOMEM;
5730 /* we have a valid devmode
5731 convert it and link it*/
5733 DEBUGADD(8,("update_printer: Converting the devicemode struct\n"));
5734 if (!convert_devicemode(printer->info_2->printername, devmode,
5735 &printer->info_2->devmode)) {
5736 result = WERR_NOMEM;
5741 /* Do sanity check on the requested changes for Samba */
5743 if (!check_printer_ok(printer->info_2, snum)) {
5744 result = WERR_INVALID_PARAM;
5748 /* FIXME!!! If the driver has changed we really should verify that
5749 it is installed before doing much else --jerry */
5751 /* Check calling user has permission to update printer description */
5753 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
5754 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
5755 result = WERR_ACCESS_DENIED;
5759 /* Call addprinter hook */
5760 /* Check changes to see if this is really needed */
5762 if ( *lp_addprinter_cmd()
5763 && (!strequal(printer->info_2->drivername, old_printer->info_2->drivername)
5764 || !strequal(printer->info_2->comment, old_printer->info_2->comment)
5765 || !strequal(printer->info_2->portname, old_printer->info_2->portname)
5766 || !strequal(printer->info_2->location, old_printer->info_2->location)) )
5768 /* add_printer_hook() will call reload_services() */
5770 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
5772 result = WERR_ACCESS_DENIED;
5778 * When a *new* driver is bound to a printer, the drivername is used to
5779 * lookup previously saved driver initialization info, which is then
5780 * bound to the printer, simulating what happens in the Windows arch.
5782 if (!strequal(printer->info_2->drivername, old_printer->info_2->drivername))
5784 if (!set_driver_init(printer, 2))
5786 DEBUG(5,("update_printer: Error restoring driver initialization data for driver [%s]!\n",
5787 printer->info_2->drivername));
5790 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
5791 printer->info_2->drivername));
5793 notify_printer_driver(snum, printer->info_2->drivername);
5797 * flag which changes actually occured. This is a small subset of
5798 * all the possible changes. We also have to update things in the
5802 if (!strequal(printer->info_2->comment, old_printer->info_2->comment)) {
5803 push_reg_sz(talloc_tos(), &buffer, printer->info_2->comment);
5804 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "description",
5805 REG_SZ, buffer.data, buffer.length);
5807 notify_printer_comment(snum, printer->info_2->comment);
5810 if (!strequal(printer->info_2->sharename, old_printer->info_2->sharename)) {
5811 push_reg_sz(talloc_tos(), &buffer, printer->info_2->sharename);
5812 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "shareName",
5813 REG_SZ, buffer.data, buffer.length);
5815 notify_printer_sharename(snum, printer->info_2->sharename);
5818 if (!strequal(printer->info_2->printername, old_printer->info_2->printername)) {
5821 if ( (pname = strchr_m( printer->info_2->printername+2, '\\' )) != NULL )
5824 pname = printer->info_2->printername;
5827 push_reg_sz(talloc_tos(), &buffer, pname);
5828 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "printerName",
5829 REG_SZ, buffer.data, buffer.length);
5831 notify_printer_printername( snum, pname );
5834 if (!strequal(printer->info_2->portname, old_printer->info_2->portname)) {
5835 push_reg_sz(talloc_tos(), &buffer, printer->info_2->portname);
5836 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "portName",
5837 REG_SZ, buffer.data, buffer.length);
5839 notify_printer_port(snum, printer->info_2->portname);
5842 if (!strequal(printer->info_2->location, old_printer->info_2->location)) {
5843 push_reg_sz(talloc_tos(), &buffer, printer->info_2->location);
5844 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "location",
5845 REG_SZ, buffer.data, buffer.length);
5847 notify_printer_location(snum, printer->info_2->location);
5850 /* here we need to update some more DsSpooler keys */
5851 /* uNCName, serverName, shortServerName */
5853 push_reg_sz(talloc_tos(), &buffer, global_myname());
5854 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "serverName",
5855 REG_SZ, buffer.data, buffer.length);
5856 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "shortServerName",
5857 REG_SZ, buffer.data, buffer.length);
5859 slprintf( asc_buffer, sizeof(asc_buffer)-1, "\\\\%s\\%s",
5860 global_myname(), printer->info_2->sharename );
5861 push_reg_sz(talloc_tos(), &buffer, asc_buffer);
5862 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "uNCName",
5863 REG_SZ, buffer.data, buffer.length);
5865 /* Update printer info */
5866 result = mod_a_printer(printer, 2);
5869 free_a_printer(&printer, 2);
5870 free_a_printer(&old_printer, 2);
5876 /****************************************************************************
5877 ****************************************************************************/
5878 static WERROR publish_or_unpublish_printer(pipes_struct *p,
5879 struct policy_handle *handle,
5880 struct spoolss_SetPrinterInfo7 *info7)
5884 Printer_entry *Printer;
5886 if ( lp_security() != SEC_ADS ) {
5887 return WERR_UNKNOWN_LEVEL;
5890 Printer = find_printer_index_by_hnd(p, handle);
5892 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
5897 if (!get_printer_snum(p, handle, &snum, NULL))
5900 nt_printer_publish(Printer, snum, info7->action);
5904 return WERR_UNKNOWN_LEVEL;
5908 /********************************************************************
5909 ********************************************************************/
5911 static WERROR update_printer_devmode(pipes_struct *p, struct policy_handle *handle,
5912 struct spoolss_DeviceMode *devmode)
5915 NT_PRINTER_INFO_LEVEL *printer = NULL;
5916 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5919 DEBUG(8,("update_printer_devmode\n"));
5924 result = WERR_BADFID;
5928 if (!get_printer_snum(p, handle, &snum, NULL)) {
5929 result = WERR_BADFID;
5933 if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)))) {
5934 result = WERR_BADFID;
5939 /* we have a valid devmode
5940 convert it and link it*/
5942 DEBUGADD(8,("update_printer: Converting the devicemode struct\n"));
5943 if (!convert_devicemode(printer->info_2->printername, devmode,
5944 &printer->info_2->devmode)) {
5945 result = WERR_NOMEM;
5950 /* Check calling user has permission to update printer description */
5952 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
5953 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
5954 result = WERR_ACCESS_DENIED;
5959 /* Update printer info */
5960 result = mod_a_printer(printer, 2);
5963 free_a_printer(&printer, 2);
5969 /****************************************************************
5971 ****************************************************************/
5973 WERROR _spoolss_SetPrinter(pipes_struct *p,
5974 struct spoolss_SetPrinter *r)
5978 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5981 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
5982 OUR_HANDLE(r->in.handle)));
5986 /* check the level */
5987 switch (r->in.info_ctr->level) {
5989 return control_printer(r->in.handle, r->in.command, p);
5991 result = update_printer(p, r->in.handle,
5993 r->in.devmode_ctr->devmode);
5994 if (!W_ERROR_IS_OK(result))
5996 if (r->in.secdesc_ctr->sd)
5997 result = update_printer_sec(r->in.handle, p,
6001 return update_printer_sec(r->in.handle, p,
6004 return publish_or_unpublish_printer(p, r->in.handle,
6005 r->in.info_ctr->info.info7);
6007 return update_printer_devmode(p, r->in.handle,
6008 r->in.devmode_ctr->devmode);
6010 return WERR_UNKNOWN_LEVEL;
6014 /****************************************************************
6015 _spoolss_FindClosePrinterNotify
6016 ****************************************************************/
6018 WERROR _spoolss_FindClosePrinterNotify(pipes_struct *p,
6019 struct spoolss_FindClosePrinterNotify *r)
6021 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
6024 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6025 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
6029 if (Printer->notify.client_connected == true) {
6032 if ( Printer->printer_type == SPLHND_SERVER)
6034 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
6035 !get_printer_snum(p, r->in.handle, &snum, NULL) )
6038 srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
6041 Printer->notify.flags=0;
6042 Printer->notify.options=0;
6043 Printer->notify.localmachine[0]='\0';
6044 Printer->notify.printerlocal=0;
6045 TALLOC_FREE(Printer->notify.option);
6046 Printer->notify.client_connected = false;
6051 /****************************************************************
6053 ****************************************************************/
6055 WERROR _spoolss_AddJob(pipes_struct *p,
6056 struct spoolss_AddJob *r)
6058 if (!r->in.buffer && (r->in.offered != 0)) {
6059 return WERR_INVALID_PARAM;
6062 /* this is what a NT server returns for AddJob. AddJob must fail on
6063 * non-local printers */
6065 if (r->in.level != 1) {
6066 return WERR_UNKNOWN_LEVEL;
6069 return WERR_INVALID_PARAM;
6072 /****************************************************************************
6074 ****************************************************************************/
6076 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
6077 struct spoolss_JobInfo1 *r,
6078 const print_queue_struct *queue,
6079 int position, int snum,
6080 const NT_PRINTER_INFO_LEVEL *ntprinter)
6084 t = gmtime(&queue->time);
6086 r->job_id = queue->job;
6088 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6089 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6090 r->server_name = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
6091 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6092 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6093 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6094 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6095 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6096 r->data_type = talloc_strdup(mem_ctx, "RAW");
6097 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6098 r->text_status = talloc_strdup(mem_ctx, "");
6099 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6101 r->status = nt_printj_status(queue->status);
6102 r->priority = queue->priority;
6103 r->position = position;
6104 r->total_pages = queue->page_count;
6105 r->pages_printed = 0; /* ??? */
6107 init_systemtime(&r->submitted, t);
6112 /****************************************************************************
6114 ****************************************************************************/
6116 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
6117 struct spoolss_JobInfo2 *r,
6118 const print_queue_struct *queue,
6119 int position, int snum,
6120 const NT_PRINTER_INFO_LEVEL *ntprinter,
6121 struct spoolss_DeviceMode *devmode)
6125 t = gmtime(&queue->time);
6127 r->job_id = queue->job;
6129 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6130 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6131 r->server_name = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
6132 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6133 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6134 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6135 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6136 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6137 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
6138 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
6139 r->data_type = talloc_strdup(mem_ctx, "RAW");
6140 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6141 r->print_processor = talloc_strdup(mem_ctx, "winprint");
6142 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
6143 r->parameters = talloc_strdup(mem_ctx, "");
6144 W_ERROR_HAVE_NO_MEMORY(r->parameters);
6145 r->driver_name = talloc_strdup(mem_ctx, ntprinter->info_2->drivername);
6146 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
6148 r->devmode = devmode;
6150 r->text_status = talloc_strdup(mem_ctx, "");
6151 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6155 r->status = nt_printj_status(queue->status);
6156 r->priority = queue->priority;
6157 r->position = position;
6160 r->total_pages = queue->page_count;
6161 r->size = queue->size;
6162 init_systemtime(&r->submitted, t);
6164 r->pages_printed = 0; /* ??? */
6169 /****************************************************************************
6171 ****************************************************************************/
6173 static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
6174 struct spoolss_JobInfo3 *r,
6175 const print_queue_struct *queue,
6176 const print_queue_struct *next_queue,
6177 int position, int snum,
6178 const NT_PRINTER_INFO_LEVEL *ntprinter)
6180 r->job_id = queue->job;
6183 r->next_job_id = next_queue->job;
6190 /****************************************************************************
6191 Enumjobs at level 1.
6192 ****************************************************************************/
6194 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
6195 const print_queue_struct *queue,
6196 uint32_t num_queues, int snum,
6197 const NT_PRINTER_INFO_LEVEL *ntprinter,
6198 union spoolss_JobInfo **info_p,
6201 union spoolss_JobInfo *info;
6203 WERROR result = WERR_OK;
6205 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6206 W_ERROR_HAVE_NO_MEMORY(info);
6208 *count = num_queues;
6210 for (i=0; i<*count; i++) {
6211 result = fill_job_info1(info,
6217 if (!W_ERROR_IS_OK(result)) {
6223 if (!W_ERROR_IS_OK(result)) {
6234 /****************************************************************************
6235 Enumjobs at level 2.
6236 ****************************************************************************/
6238 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
6239 const print_queue_struct *queue,
6240 uint32_t num_queues, int snum,
6241 const NT_PRINTER_INFO_LEVEL *ntprinter,
6242 union spoolss_JobInfo **info_p,
6245 union spoolss_JobInfo *info;
6247 WERROR result = WERR_OK;
6249 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6250 W_ERROR_HAVE_NO_MEMORY(info);
6252 *count = num_queues;
6254 for (i=0; i<*count; i++) {
6256 struct spoolss_DeviceMode *devmode;
6258 devmode = construct_dev_mode(info, lp_const_servicename(snum));
6260 result = WERR_NOMEM;
6264 result = fill_job_info2(info,
6271 if (!W_ERROR_IS_OK(result)) {
6277 if (!W_ERROR_IS_OK(result)) {
6288 /****************************************************************************
6289 Enumjobs at level 3.
6290 ****************************************************************************/
6292 static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
6293 const print_queue_struct *queue,
6294 uint32_t num_queues, int snum,
6295 const NT_PRINTER_INFO_LEVEL *ntprinter,
6296 union spoolss_JobInfo **info_p,
6299 union spoolss_JobInfo *info;
6301 WERROR result = WERR_OK;
6303 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6304 W_ERROR_HAVE_NO_MEMORY(info);
6306 *count = num_queues;
6308 for (i=0; i<*count; i++) {
6309 const print_queue_struct *next_queue = NULL;
6312 next_queue = &queue[i+1];
6315 result = fill_job_info3(info,
6322 if (!W_ERROR_IS_OK(result)) {
6328 if (!W_ERROR_IS_OK(result)) {
6339 /****************************************************************
6341 ****************************************************************/
6343 WERROR _spoolss_EnumJobs(pipes_struct *p,
6344 struct spoolss_EnumJobs *r)
6347 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
6349 print_status_struct prt_status;
6350 print_queue_struct *queue = NULL;
6353 /* that's an [in out] buffer */
6355 if (!r->in.buffer && (r->in.offered != 0)) {
6356 return WERR_INVALID_PARAM;
6359 DEBUG(4,("_spoolss_EnumJobs\n"));
6363 *r->out.info = NULL;
6365 /* lookup the printer snum and tdb entry */
6367 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6371 result = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum));
6372 if (!W_ERROR_IS_OK(result)) {
6376 count = print_queue_status(snum, &queue, &prt_status);
6377 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
6378 count, prt_status.status, prt_status.message));
6382 free_a_printer(&ntprinter, 2);
6386 switch (r->in.level) {
6388 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
6389 ntprinter, r->out.info, r->out.count);
6392 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
6393 ntprinter, r->out.info, r->out.count);
6396 result = enumjobs_level3(p->mem_ctx, queue, count, snum,
6397 ntprinter, r->out.info, r->out.count);
6400 result = WERR_UNKNOWN_LEVEL;
6405 free_a_printer(&ntprinter, 2);
6407 if (!W_ERROR_IS_OK(result)) {
6411 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6412 spoolss_EnumJobs, NULL,
6413 *r->out.info, r->in.level,
6415 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6416 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6418 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6421 /****************************************************************
6422 _spoolss_ScheduleJob
6423 ****************************************************************/
6425 WERROR _spoolss_ScheduleJob(pipes_struct *p,
6426 struct spoolss_ScheduleJob *r)
6431 /****************************************************************
6433 ****************************************************************/
6435 WERROR _spoolss_SetJob(pipes_struct *p,
6436 struct spoolss_SetJob *r)
6439 WERROR errcode = WERR_BADFUNC;
6441 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6445 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
6446 return WERR_INVALID_PRINTER_NAME;
6449 switch (r->in.command) {
6450 case SPOOLSS_JOB_CONTROL_CANCEL:
6451 case SPOOLSS_JOB_CONTROL_DELETE:
6452 if (print_job_delete(p->server_info, snum, r->in.job_id, &errcode)) {
6456 case SPOOLSS_JOB_CONTROL_PAUSE:
6457 if (print_job_pause(p->server_info, snum, r->in.job_id, &errcode)) {
6461 case SPOOLSS_JOB_CONTROL_RESTART:
6462 case SPOOLSS_JOB_CONTROL_RESUME:
6463 if (print_job_resume(p->server_info, snum, r->in.job_id, &errcode)) {
6468 return WERR_UNKNOWN_LEVEL;
6474 /****************************************************************************
6475 Enumerates all printer drivers by level and architecture.
6476 ****************************************************************************/
6478 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
6479 const char *servername,
6480 const char *architecture,
6482 union spoolss_DriverInfo **info_p,
6488 fstring *list = NULL;
6489 struct spoolss_DriverInfo8 *driver;
6490 union spoolss_DriverInfo *info = NULL;
6492 WERROR result = WERR_OK;
6497 for (version=0; version<DRIVER_MAX_VERSION; version++) {
6499 ndrivers = get_ntdrivers(&list, architecture, version);
6500 DEBUGADD(4,("we have:[%d] drivers in environment [%s] and version [%d]\n",
6501 ndrivers, architecture, version));
6503 if (ndrivers == -1) {
6504 result = WERR_NOMEM;
6508 if (ndrivers != 0) {
6509 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
6510 union spoolss_DriverInfo,
6513 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
6514 "failed to enlarge driver info buffer!\n"));
6515 result = WERR_NOMEM;
6520 for (i=0; i<ndrivers; i++) {
6521 DEBUGADD(5,("\tdriver: [%s]\n", list[i]));
6522 ZERO_STRUCT(driver);
6523 result = get_a_printer_driver(mem_ctx, &driver, list[i],
6524 architecture, version);
6525 if (!W_ERROR_IS_OK(result)) {
6531 result = fill_printer_driver_info1(info, &info[count+i].info1,
6532 driver, servername);
6535 result = fill_printer_driver_info2(info, &info[count+i].info2,
6536 driver, servername);
6539 result = fill_printer_driver_info3(info, &info[count+i].info3,
6540 driver, servername);
6543 result = fill_printer_driver_info4(info, &info[count+i].info4,
6544 driver, servername);
6547 result = fill_printer_driver_info5(info, &info[count+i].info5,
6548 driver, servername);
6551 result = fill_printer_driver_info6(info, &info[count+i].info6,
6552 driver, servername);
6555 result = fill_printer_driver_info8(info, &info[count+i].info8,
6556 driver, servername);
6559 result = WERR_UNKNOWN_LEVEL;
6563 free_a_printer_driver(driver);
6565 if (!W_ERROR_IS_OK(result)) {
6577 if (!W_ERROR_IS_OK(result)) {
6588 /****************************************************************************
6589 Enumerates all printer drivers by level.
6590 ****************************************************************************/
6592 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
6593 const char *servername,
6594 const char *architecture,
6596 union spoolss_DriverInfo **info_p,
6600 WERROR result = WERR_OK;
6602 if (strequal(architecture, SPOOLSS_ARCHITECTURE_ALL)) {
6604 for (a=0; archi_table[a].long_archi != NULL; a++) {
6606 union spoolss_DriverInfo *info = NULL;
6609 result = enumprinterdrivers_level_by_architecture(mem_ctx,
6611 archi_table[a].long_archi,
6615 if (!W_ERROR_IS_OK(result)) {
6619 for (i=0; i < count; i++) {
6620 ADD_TO_ARRAY(mem_ctx, union spoolss_DriverInfo,
6621 info[i], info_p, count_p);
6628 return enumprinterdrivers_level_by_architecture(mem_ctx,
6636 /****************************************************************
6637 _spoolss_EnumPrinterDrivers
6638 ****************************************************************/
6640 WERROR _spoolss_EnumPrinterDrivers(pipes_struct *p,
6641 struct spoolss_EnumPrinterDrivers *r)
6643 const char *cservername;
6646 /* that's an [in out] buffer */
6648 if (!r->in.buffer && (r->in.offered != 0)) {
6649 return WERR_INVALID_PARAM;
6652 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
6656 *r->out.info = NULL;
6658 cservername = canon_servername(r->in.server);
6660 if (!is_myname_or_ipaddr(cservername)) {
6661 return WERR_UNKNOWN_PRINTER_DRIVER;
6664 result = enumprinterdrivers_level(p->mem_ctx, cservername,
6669 if (!W_ERROR_IS_OK(result)) {
6673 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6674 spoolss_EnumPrinterDrivers, NULL,
6675 *r->out.info, r->in.level,
6677 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6678 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6680 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6683 /****************************************************************************
6684 ****************************************************************************/
6686 static WERROR fill_form_info_1(TALLOC_CTX *mem_ctx,
6687 struct spoolss_FormInfo1 *r,
6688 const nt_forms_struct *form)
6690 r->form_name = talloc_strdup(mem_ctx, form->name);
6691 W_ERROR_HAVE_NO_MEMORY(r->form_name);
6693 r->flags = form->flag;
6694 r->size.width = form->width;
6695 r->size.height = form->length;
6696 r->area.left = form->left;
6697 r->area.top = form->top;
6698 r->area.right = form->right;
6699 r->area.bottom = form->bottom;
6704 /****************************************************************
6705 spoolss_enumforms_level1
6706 ****************************************************************/
6708 static WERROR spoolss_enumforms_level1(TALLOC_CTX *mem_ctx,
6709 const nt_forms_struct *builtin_forms,
6710 uint32_t num_builtin_forms,
6711 const nt_forms_struct *user_forms,
6712 uint32_t num_user_forms,
6713 union spoolss_FormInfo **info_p,
6716 union spoolss_FormInfo *info;
6717 WERROR result = WERR_OK;
6720 *count = num_builtin_forms + num_user_forms;
6722 info = TALLOC_ARRAY(mem_ctx, union spoolss_FormInfo, *count);
6723 W_ERROR_HAVE_NO_MEMORY(info);
6725 /* construct the list of form structures */
6726 for (i=0; i<num_builtin_forms; i++) {
6727 DEBUGADD(6,("Filling builtin form number [%d]\n",i));
6728 result = fill_form_info_1(info, &info[i].info1,
6730 if (!W_ERROR_IS_OK(result)) {
6735 for (i=0; i<num_user_forms; i++) {
6736 DEBUGADD(6,("Filling user form number [%d]\n",i));
6737 result = fill_form_info_1(info, &info[i+num_builtin_forms].info1,
6739 if (!W_ERROR_IS_OK(result)) {
6745 if (!W_ERROR_IS_OK(result)) {
6756 /****************************************************************
6758 ****************************************************************/
6760 WERROR _spoolss_EnumForms(pipes_struct *p,
6761 struct spoolss_EnumForms *r)
6764 nt_forms_struct *user_forms = NULL;
6765 nt_forms_struct *builtin_forms = NULL;
6766 uint32_t num_user_forms;
6767 uint32_t num_builtin_forms;
6771 *r->out.info = NULL;
6773 /* that's an [in out] buffer */
6775 if (!r->in.buffer && (r->in.offered != 0) ) {
6776 return WERR_INVALID_PARAM;
6779 DEBUG(4,("_spoolss_EnumForms\n"));
6780 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
6781 DEBUGADD(5,("Info level [%d]\n", r->in.level));
6783 num_builtin_forms = get_builtin_ntforms(&builtin_forms);
6784 DEBUGADD(5,("Number of builtin forms [%d]\n", num_builtin_forms));
6785 num_user_forms = get_ntforms(&user_forms);
6786 DEBUGADD(5,("Number of user forms [%d]\n", num_user_forms));
6788 if (num_user_forms + num_builtin_forms == 0) {
6789 SAFE_FREE(builtin_forms);
6790 SAFE_FREE(user_forms);
6791 return WERR_NO_MORE_ITEMS;
6794 switch (r->in.level) {
6796 result = spoolss_enumforms_level1(p->mem_ctx,
6805 result = WERR_UNKNOWN_LEVEL;
6809 SAFE_FREE(user_forms);
6810 SAFE_FREE(builtin_forms);
6812 if (!W_ERROR_IS_OK(result)) {
6816 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6817 spoolss_EnumForms, NULL,
6818 *r->out.info, r->in.level,
6820 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6821 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6823 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6826 /****************************************************************
6827 ****************************************************************/
6829 static WERROR find_form_byname(const char *name,
6830 nt_forms_struct *form)
6832 nt_forms_struct *list = NULL;
6833 int num_forms = 0, i = 0;
6835 if (get_a_builtin_ntform_by_string(name, form)) {
6839 num_forms = get_ntforms(&list);
6840 DEBUGADD(5,("Number of forms [%d]\n", num_forms));
6842 if (num_forms == 0) {
6846 /* Check if the requested name is in the list of form structures */
6847 for (i = 0; i < num_forms; i++) {
6849 DEBUG(4,("checking form %s (want %s)\n", list[i].name, name));
6851 if (strequal(name, list[i].name)) {
6852 DEBUGADD(6,("Found form %s number [%d]\n", name, i));
6864 /****************************************************************
6866 ****************************************************************/
6868 WERROR _spoolss_GetForm(pipes_struct *p,
6869 struct spoolss_GetForm *r)
6872 nt_forms_struct form;
6874 /* that's an [in out] buffer */
6876 if (!r->in.buffer && (r->in.offered != 0)) {
6877 return WERR_INVALID_PARAM;
6880 DEBUG(4,("_spoolss_GetForm\n"));
6881 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
6882 DEBUGADD(5,("Info level [%d]\n", r->in.level));
6884 result = find_form_byname(r->in.form_name, &form);
6885 if (!W_ERROR_IS_OK(result)) {
6886 TALLOC_FREE(r->out.info);
6890 switch (r->in.level) {
6892 result = fill_form_info_1(p->mem_ctx,
6893 &r->out.info->info1,
6898 result = WERR_UNKNOWN_LEVEL;
6902 if (!W_ERROR_IS_OK(result)) {
6903 TALLOC_FREE(r->out.info);
6907 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo, NULL,
6908 r->out.info, r->in.level);
6909 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
6911 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6914 /****************************************************************************
6915 ****************************************************************************/
6917 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
6918 struct spoolss_PortInfo1 *r,
6921 r->port_name = talloc_strdup(mem_ctx, name);
6922 W_ERROR_HAVE_NO_MEMORY(r->port_name);
6927 /****************************************************************************
6928 TODO: This probably needs distinguish between TCP/IP and Local ports
6930 ****************************************************************************/
6932 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
6933 struct spoolss_PortInfo2 *r,
6936 r->port_name = talloc_strdup(mem_ctx, name);
6937 W_ERROR_HAVE_NO_MEMORY(r->port_name);
6939 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
6940 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
6942 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
6943 W_ERROR_HAVE_NO_MEMORY(r->description);
6945 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
6952 /****************************************************************************
6953 wrapper around the enumer ports command
6954 ****************************************************************************/
6956 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
6958 char *cmd = lp_enumports_cmd();
6959 char **qlines = NULL;
6960 char *command = NULL;
6968 /* if no hook then just fill in the default port */
6971 if (!(qlines = TALLOC_ARRAY( NULL, char*, 2 ))) {
6974 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
6975 TALLOC_FREE(qlines);
6982 /* we have a valid enumport command */
6984 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
6989 DEBUG(10,("Running [%s]\n", command));
6990 ret = smbrun(command, &fd);
6991 DEBUG(10,("Returned [%d]\n", ret));
6992 TALLOC_FREE(command);
6997 return WERR_ACCESS_DENIED;
7001 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7002 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7012 /****************************************************************************
7014 ****************************************************************************/
7016 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7017 union spoolss_PortInfo **info_p,
7020 union spoolss_PortInfo *info = NULL;
7022 WERROR result = WERR_OK;
7023 char **qlines = NULL;
7026 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7027 if (!W_ERROR_IS_OK(result)) {
7032 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7034 DEBUG(10,("Returning WERR_NOMEM\n"));
7035 result = WERR_NOMEM;
7039 for (i=0; i<numlines; i++) {
7040 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7041 result = fill_port_1(info, &info[i].info1, qlines[i]);
7042 if (!W_ERROR_IS_OK(result)) {
7047 TALLOC_FREE(qlines);
7050 if (!W_ERROR_IS_OK(result)) {
7052 TALLOC_FREE(qlines);
7064 /****************************************************************************
7066 ****************************************************************************/
7068 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7069 union spoolss_PortInfo **info_p,
7072 union spoolss_PortInfo *info = NULL;
7074 WERROR result = WERR_OK;
7075 char **qlines = NULL;
7078 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7079 if (!W_ERROR_IS_OK(result)) {
7084 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7086 DEBUG(10,("Returning WERR_NOMEM\n"));
7087 result = WERR_NOMEM;
7091 for (i=0; i<numlines; i++) {
7092 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7093 result = fill_port_2(info, &info[i].info2, qlines[i]);
7094 if (!W_ERROR_IS_OK(result)) {
7099 TALLOC_FREE(qlines);
7102 if (!W_ERROR_IS_OK(result)) {
7104 TALLOC_FREE(qlines);
7116 /****************************************************************
7118 ****************************************************************/
7120 WERROR _spoolss_EnumPorts(pipes_struct *p,
7121 struct spoolss_EnumPorts *r)
7125 /* that's an [in out] buffer */
7127 if (!r->in.buffer && (r->in.offered != 0)) {
7128 return WERR_INVALID_PARAM;
7131 DEBUG(4,("_spoolss_EnumPorts\n"));
7135 *r->out.info = NULL;
7137 switch (r->in.level) {
7139 result = enumports_level_1(p->mem_ctx, r->out.info,
7143 result = enumports_level_2(p->mem_ctx, r->out.info,
7147 return WERR_UNKNOWN_LEVEL;
7150 if (!W_ERROR_IS_OK(result)) {
7154 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7155 spoolss_EnumPorts, NULL,
7156 *r->out.info, r->in.level,
7158 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7159 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7161 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7164 /****************************************************************************
7165 ****************************************************************************/
7167 static WERROR spoolss_addprinterex_level_2(pipes_struct *p,
7169 struct spoolss_SetPrinterInfoCtr *info_ctr,
7170 struct spoolss_DeviceMode *devmode,
7171 struct security_descriptor *sec_desc,
7172 struct spoolss_UserLevelCtr *user_ctr,
7173 struct policy_handle *handle)
7175 NT_PRINTER_INFO_LEVEL *printer = NULL;
7178 WERROR err = WERR_OK;
7180 if ( !(printer = TALLOC_ZERO_P(NULL, NT_PRINTER_INFO_LEVEL)) ) {
7181 DEBUG(0,("spoolss_addprinterex_level_2: malloc fail.\n"));
7185 /* convert from UNICODE to ASCII - this allocates the info_2 struct inside *printer.*/
7186 if (!convert_printer_info(info_ctr, printer)) {
7187 free_a_printer(&printer, 2);
7191 /* samba does not have a concept of local, non-shared printers yet, so
7192 * make sure we always setup sharename - gd */
7193 if ((printer->info_2->sharename[0] == '\0') && (printer->info_2->printername != '\0')) {
7194 DEBUG(5, ("spoolss_addprinterex_level_2: "
7195 "no sharename has been set, setting printername %s as sharename\n",
7196 printer->info_2->printername));
7197 fstrcpy(printer->info_2->sharename, printer->info_2->printername);
7200 /* check to see if the printer already exists */
7202 if ((snum = print_queue_snum(printer->info_2->sharename)) != -1) {
7203 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7204 printer->info_2->sharename));
7205 free_a_printer(&printer, 2);
7206 return WERR_PRINTER_ALREADY_EXISTS;
7209 if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
7210 if ((snum = print_queue_snum(printer->info_2->printername)) != -1) {
7211 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7212 printer->info_2->printername));
7213 free_a_printer(&printer, 2);
7214 return WERR_PRINTER_ALREADY_EXISTS;
7218 /* validate printer info struct */
7219 if (!info_ctr->info.info2->printername ||
7220 strlen(info_ctr->info.info2->printername) == 0) {
7221 free_a_printer(&printer,2);
7222 return WERR_INVALID_PRINTER_NAME;
7224 if (!info_ctr->info.info2->portname ||
7225 strlen(info_ctr->info.info2->portname) == 0) {
7226 free_a_printer(&printer,2);
7227 return WERR_UNKNOWN_PORT;
7229 if (!info_ctr->info.info2->drivername ||
7230 strlen(info_ctr->info.info2->drivername) == 0) {
7231 free_a_printer(&printer,2);
7232 return WERR_UNKNOWN_PRINTER_DRIVER;
7234 if (!info_ctr->info.info2->printprocessor ||
7235 strlen(info_ctr->info.info2->printprocessor) == 0) {
7236 free_a_printer(&printer,2);
7237 return WERR_UNKNOWN_PRINTPROCESSOR;
7240 /* FIXME!!! smbd should check to see if the driver is installed before
7241 trying to add a printer like this --jerry */
7243 if (*lp_addprinter_cmd() ) {
7244 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
7246 free_a_printer(&printer,2);
7247 return WERR_ACCESS_DENIED;
7250 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
7251 "smb.conf parameter \"addprinter command\" is defined. This"
7252 "parameter must exist for this call to succeed\n",
7253 printer->info_2->sharename ));
7256 /* use our primary netbios name since get_a_printer() will convert
7257 it to what the client expects on a case by case basis */
7259 slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname(),
7260 printer->info_2->sharename);
7263 if ((snum = print_queue_snum(printer->info_2->sharename)) == -1) {
7264 free_a_printer(&printer,2);
7265 return WERR_ACCESS_DENIED;
7268 /* you must be a printer admin to add a new printer */
7269 if (!print_access_check(p->server_info, snum, PRINTER_ACCESS_ADMINISTER)) {
7270 free_a_printer(&printer,2);
7271 return WERR_ACCESS_DENIED;
7275 * Do sanity check on the requested changes for Samba.
7278 if (!check_printer_ok(printer->info_2, snum)) {
7279 free_a_printer(&printer,2);
7280 return WERR_INVALID_PARAM;
7284 * When a printer is created, the drivername bound to the printer is used
7285 * to lookup previously saved driver initialization info, which is then
7286 * bound to the new printer, simulating what happens in the Windows arch.
7291 set_driver_init(printer, 2);
7295 /* A valid devmode was included, convert and link it
7297 DEBUGADD(10, ("spoolss_addprinterex_level_2: devmode included, converting\n"));
7299 if (!convert_devicemode(printer->info_2->printername, devmode,
7300 &printer->info_2->devmode)) {
7305 /* write the ASCII on disk */
7306 err = mod_a_printer(printer, 2);
7307 if (!W_ERROR_IS_OK(err)) {
7308 free_a_printer(&printer,2);
7312 if (!open_printer_hnd(p, handle, name, PRINTER_ACCESS_ADMINISTER)) {
7313 /* Handle open failed - remove addition. */
7314 del_a_printer(printer->info_2->sharename);
7315 free_a_printer(&printer,2);
7316 ZERO_STRUCTP(handle);
7317 return WERR_ACCESS_DENIED;
7320 update_c_setprinter(false);
7321 free_a_printer(&printer,2);
7326 /****************************************************************
7327 _spoolss_AddPrinterEx
7328 ****************************************************************/
7330 WERROR _spoolss_AddPrinterEx(pipes_struct *p,
7331 struct spoolss_AddPrinterEx *r)
7333 switch (r->in.info_ctr->level) {
7335 /* we don't handle yet */
7336 /* but I know what to do ... */
7337 return WERR_UNKNOWN_LEVEL;
7339 return spoolss_addprinterex_level_2(p, r->in.server,
7341 r->in.devmode_ctr->devmode,
7342 r->in.secdesc_ctr->sd,
7343 r->in.userlevel_ctr,
7346 return WERR_UNKNOWN_LEVEL;
7350 /****************************************************************
7352 ****************************************************************/
7354 WERROR _spoolss_AddPrinter(pipes_struct *p,
7355 struct spoolss_AddPrinter *r)
7357 struct spoolss_AddPrinterEx a;
7358 struct spoolss_UserLevelCtr userlevel_ctr;
7360 ZERO_STRUCT(userlevel_ctr);
7362 userlevel_ctr.level = 1;
7364 a.in.server = r->in.server;
7365 a.in.info_ctr = r->in.info_ctr;
7366 a.in.devmode_ctr = r->in.devmode_ctr;
7367 a.in.secdesc_ctr = r->in.secdesc_ctr;
7368 a.in.userlevel_ctr = &userlevel_ctr;
7369 a.out.handle = r->out.handle;
7371 return _spoolss_AddPrinterEx(p, &a);
7374 /****************************************************************
7375 _spoolss_AddPrinterDriver
7376 ****************************************************************/
7378 WERROR _spoolss_AddPrinterDriver(pipes_struct *p,
7379 struct spoolss_AddPrinterDriver *r)
7381 WERROR err = WERR_OK;
7382 char *driver_name = NULL;
7386 switch (p->hdr_req.opnum) {
7387 case NDR_SPOOLSS_ADDPRINTERDRIVER:
7388 fn = "_spoolss_AddPrinterDriver";
7390 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
7391 fn = "_spoolss_AddPrinterDriverEx";
7394 return WERR_INVALID_PARAM;
7399 if (r->in.info_ctr->level != 3 && r->in.info_ctr->level != 6) {
7400 /* Clever hack from Martin Zielinski <mz@seh.de>
7401 * to allow downgrade from level 8 (Vista).
7403 DEBUG(0,("%s: level %d not yet implemented\n", fn,
7404 r->in.info_ctr->level));
7405 return WERR_UNKNOWN_LEVEL;
7408 DEBUG(5,("Cleaning driver's information\n"));
7409 err = clean_up_driver_struct(p, r->in.info_ctr);
7410 if (!W_ERROR_IS_OK(err))
7413 DEBUG(5,("Moving driver to final destination\n"));
7414 if( !W_ERROR_IS_OK(err = move_driver_to_download_area(p, r->in.info_ctr,
7419 if (add_a_printer_driver(p->mem_ctx, r->in.info_ctr, &driver_name, &version)!=0) {
7420 err = WERR_ACCESS_DENIED;
7425 * I think this is where he DrvUpgradePrinter() hook would be
7426 * be called in a driver's interface DLL on a Windows NT 4.0/2k
7427 * server. Right now, we just need to send ourselves a message
7428 * to update each printer bound to this driver. --jerry
7431 if (!srv_spoolss_drv_upgrade_printer(driver_name)) {
7432 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
7437 * Based on the version (e.g. driver destination dir: 0=9x,2=Nt/2k,3=2k/Xp),
7438 * decide if the driver init data should be deleted. The rules are:
7439 * 1) never delete init data if it is a 9x driver, they don't use it anyway
7440 * 2) delete init data only if there is no 2k/Xp driver
7441 * 3) always delete init data
7442 * The generalized rule is always use init data from the highest order driver.
7443 * It is necessary to follow the driver install by an initialization step to
7444 * finish off this process.
7449 * 9x printer driver - never delete init data
7452 DEBUG(10,("%s: init data not deleted for 9x driver [%s]\n",
7457 * Nt or 2k (compatiblity mode) printer driver - only delete init data if
7458 * there is no 2k/Xp driver init data for this driver name.
7462 struct spoolss_DriverInfo8 *driver1;
7464 if (!W_ERROR_IS_OK(get_a_printer_driver(p->mem_ctx, &driver1, driver_name, "Windows NT x86", 3))) {
7466 * No 2k/Xp driver found, delete init data (if any) for the new Nt driver.
7468 if (!del_driver_init(driver_name))
7469 DEBUG(6,("%s: del_driver_init(%s) Nt failed!\n",
7473 * a 2k/Xp driver was found, don't delete init data because Nt driver will use it.
7475 free_a_printer_driver(driver1);
7476 DEBUG(10,("%s: init data not deleted for Nt driver [%s]\n",
7483 * 2k or Xp printer driver - always delete init data
7486 if (!del_driver_init(driver_name))
7487 DEBUG(6,("%s: del_driver_init(%s) 2k/Xp failed!\n",
7492 DEBUG(0,("%s: invalid level=%d\n", fn,
7493 r->in.info_ctr->level));
7502 /****************************************************************
7503 _spoolss_AddPrinterDriverEx
7504 ****************************************************************/
7506 WERROR _spoolss_AddPrinterDriverEx(pipes_struct *p,
7507 struct spoolss_AddPrinterDriverEx *r)
7509 struct spoolss_AddPrinterDriver a;
7512 * we only support the semantics of AddPrinterDriver()
7513 * i.e. only copy files that are newer than existing ones
7516 if (r->in.flags != APD_COPY_NEW_FILES) {
7517 return WERR_ACCESS_DENIED;
7520 a.in.servername = r->in.servername;
7521 a.in.info_ctr = r->in.info_ctr;
7523 return _spoolss_AddPrinterDriver(p, &a);
7526 /****************************************************************************
7527 ****************************************************************************/
7529 struct _spoolss_paths {
7535 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
7537 static const struct _spoolss_paths spoolss_paths[]= {
7538 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
7539 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
7542 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
7543 const char *servername,
7544 const char *environment,
7548 const char *pservername = NULL;
7549 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
7550 const char *short_archi;
7554 /* environment may be empty */
7555 if (environment && strlen(environment)) {
7556 long_archi = environment;
7559 /* servername may be empty */
7560 if (servername && strlen(servername)) {
7561 pservername = canon_servername(servername);
7563 if (!is_myname_or_ipaddr(pservername)) {
7564 return WERR_INVALID_PARAM;
7568 if (!(short_archi = get_short_archi(long_archi))) {
7569 return WERR_INVALID_ENVIRONMENT;
7572 switch (component) {
7573 case SPOOLSS_PRTPROCS_PATH:
7574 case SPOOLSS_DRIVER_PATH:
7576 *path = talloc_asprintf(mem_ctx,
7579 spoolss_paths[component].share,
7582 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
7583 SPOOLSS_DEFAULT_SERVER_PATH,
7584 spoolss_paths[component].dir,
7589 return WERR_INVALID_PARAM;
7599 /****************************************************************************
7600 ****************************************************************************/
7602 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
7603 const char *servername,
7604 const char *environment,
7605 struct spoolss_DriverDirectoryInfo1 *r)
7610 werr = compose_spoolss_server_path(mem_ctx,
7613 SPOOLSS_DRIVER_PATH,
7615 if (!W_ERROR_IS_OK(werr)) {
7619 DEBUG(4,("printer driver directory: [%s]\n", path));
7621 r->directory_name = path;
7626 /****************************************************************
7627 _spoolss_GetPrinterDriverDirectory
7628 ****************************************************************/
7630 WERROR _spoolss_GetPrinterDriverDirectory(pipes_struct *p,
7631 struct spoolss_GetPrinterDriverDirectory *r)
7635 /* that's an [in out] buffer */
7637 if (!r->in.buffer && (r->in.offered != 0)) {
7638 return WERR_INVALID_PARAM;
7641 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
7646 /* r->in.level is ignored */
7648 werror = getprinterdriverdir_level_1(p->mem_ctx,
7651 &r->out.info->info1);
7652 if (!W_ERROR_IS_OK(werror)) {
7653 TALLOC_FREE(r->out.info);
7657 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo, NULL,
7658 r->out.info, r->in.level);
7659 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7661 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7664 /****************************************************************
7665 _spoolss_EnumPrinterData
7666 ****************************************************************/
7668 WERROR _spoolss_EnumPrinterData(pipes_struct *p,
7669 struct spoolss_EnumPrinterData *r)
7671 NT_PRINTER_INFO_LEVEL *printer = NULL;
7672 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7675 struct regval_blob *val = NULL;
7676 NT_PRINTER_DATA *p_data;
7677 int i, key_index, num_values;
7680 *r->out.value_needed = 0;
7681 *r->out.type = REG_NONE;
7682 *r->out.data_needed = 0;
7684 DEBUG(5,("_spoolss_EnumPrinterData\n"));
7687 DEBUG(2,("_spoolss_EnumPrinterData: Invalid handle (%s:%u:%u).\n",
7688 OUR_HANDLE(r->in.handle)));
7692 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7696 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
7697 if (!W_ERROR_IS_OK(result)) {
7701 p_data = printer->info_2->data;
7702 key_index = lookup_printerkey( p_data, SPOOL_PRINTERDATA_KEY );
7707 * The NT machine wants to know the biggest size of value and data
7709 * cf: MSDN EnumPrinterData remark section
7712 if (!r->in.value_offered && !r->in.data_offered && (key_index != -1)) {
7714 uint32_t biggest_valuesize = 0;
7715 uint32_t biggest_datasize = 0;
7717 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
7719 num_values = regval_ctr_numvals( p_data->keys[key_index].values );
7721 for ( i=0; i<num_values; i++ )
7723 val = regval_ctr_specific_value( p_data->keys[key_index].values, i );
7725 name_length = strlen(val->valuename);
7726 if ( strlen(val->valuename) > biggest_valuesize )
7727 biggest_valuesize = name_length;
7729 if ( val->size > biggest_datasize )
7730 biggest_datasize = val->size;
7732 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
7736 /* the value is an UNICODE string but real_value_size is the length
7737 in bytes including the trailing 0 */
7739 *r->out.value_needed = 2 * (1 + biggest_valuesize);
7740 *r->out.data_needed = biggest_datasize;
7742 DEBUG(6,("final values: [%d], [%d]\n",
7743 *r->out.value_needed, *r->out.data_needed));
7749 * the value len is wrong in NT sp3
7750 * that's the number of bytes not the number of unicode chars
7753 if (key_index != -1) {
7754 val = regval_ctr_specific_value(p_data->keys[key_index].values,
7760 /* out_value should default to "" or else NT4 has
7761 problems unmarshalling the response */
7763 if (r->in.value_offered) {
7764 *r->out.value_needed = 1;
7765 r->out.value_name = talloc_strdup(r, "");
7766 if (!r->out.value_name) {
7767 result = WERR_NOMEM;
7771 r->out.value_name = NULL;
7772 *r->out.value_needed = 0;
7775 /* the data is counted in bytes */
7777 *r->out.data_needed = r->in.data_offered;
7779 result = WERR_NO_MORE_ITEMS;
7783 * - counted in bytes in the request
7784 * - counted in UNICODE chars in the max reply
7785 * - counted in bytes in the real size
7787 * take a pause *before* coding not *during* coding
7791 if (r->in.value_offered) {
7792 r->out.value_name = talloc_strdup(r, regval_name(val));
7793 if (!r->out.value_name) {
7794 result = WERR_NOMEM;
7797 *r->out.value_needed = strlen_m(regval_name(val));
7799 r->out.value_name = NULL;
7800 *r->out.value_needed = 0;
7805 *r->out.type = regval_type(val);
7807 /* data - counted in bytes */
7810 * See the section "Dynamically Typed Query Parameters"
7814 if (r->out.data && regval_data_p(val) &&
7815 regval_size(val) && r->in.data_offered) {
7816 memcpy(r->out.data, regval_data_p(val),
7817 MIN(regval_size(val),r->in.data_offered));
7820 *r->out.data_needed = regval_size(val);
7824 free_a_printer(&printer, 2);
7828 /****************************************************************
7829 _spoolss_SetPrinterData
7830 ****************************************************************/
7832 WERROR _spoolss_SetPrinterData(pipes_struct *p,
7833 struct spoolss_SetPrinterData *r)
7835 struct spoolss_SetPrinterDataEx r2;
7837 r2.in.handle = r->in.handle;
7838 r2.in.key_name = "PrinterDriverData";
7839 r2.in.value_name = r->in.value_name;
7840 r2.in.type = r->in.type;
7841 r2.in.data = r->in.data;
7842 r2.in._offered = r->in._offered;
7844 return _spoolss_SetPrinterDataEx(p, &r2);
7847 /****************************************************************
7848 _spoolss_ResetPrinter
7849 ****************************************************************/
7851 WERROR _spoolss_ResetPrinter(pipes_struct *p,
7852 struct spoolss_ResetPrinter *r)
7854 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7857 DEBUG(5,("_spoolss_ResetPrinter\n"));
7860 * All we do is to check to see if the handle and queue is valid.
7861 * This call really doesn't mean anything to us because we only
7862 * support RAW printing. --jerry
7866 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
7867 OUR_HANDLE(r->in.handle)));
7871 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
7875 /* blindly return success */
7879 /****************************************************************
7880 _spoolss_DeletePrinterData
7881 ****************************************************************/
7883 WERROR _spoolss_DeletePrinterData(pipes_struct *p,
7884 struct spoolss_DeletePrinterData *r)
7886 struct spoolss_DeletePrinterDataEx r2;
7888 r2.in.handle = r->in.handle;
7889 r2.in.key_name = "PrinterDriverData";
7890 r2.in.value_name = r->in.value_name;
7892 return _spoolss_DeletePrinterDataEx(p, &r2);
7895 /****************************************************************
7897 ****************************************************************/
7899 WERROR _spoolss_AddForm(pipes_struct *p,
7900 struct spoolss_AddForm *r)
7902 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
7903 nt_forms_struct tmpForm;
7905 WERROR status = WERR_OK;
7906 NT_PRINTER_INFO_LEVEL *printer = NULL;
7907 SE_PRIV se_printop = SE_PRINT_OPERATOR;
7910 nt_forms_struct *list=NULL;
7911 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7913 DEBUG(5,("_spoolss_AddForm\n"));
7916 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
7917 OUR_HANDLE(r->in.handle)));
7922 /* forms can be added on printer of on the print server handle */
7924 if ( Printer->printer_type == SPLHND_PRINTER )
7926 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
7929 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
7930 if (!W_ERROR_IS_OK(status))
7934 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
7935 and not a printer admin, then fail */
7937 if ((p->server_info->utok.uid != sec_initial_uid()) &&
7938 !user_has_privileges(p->server_info->ptok, &se_printop) &&
7939 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
7941 p->server_info->ptok,
7942 lp_printer_admin(snum))) {
7943 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
7944 return WERR_ACCESS_DENIED;
7947 /* can't add if builtin */
7949 if (get_a_builtin_ntform_by_string(form->form_name, &tmpForm)) {
7950 status = WERR_FILE_EXISTS;
7954 count = get_ntforms(&list);
7956 if(!add_a_form(&list, form, &count)) {
7957 status = WERR_NOMEM;
7962 write_ntforms(&list, count);
7966 * ChangeID must always be set if this is a printer
7969 if ( Printer->printer_type == SPLHND_PRINTER )
7970 status = mod_a_printer(printer, 2);
7974 free_a_printer(&printer, 2);
7980 /****************************************************************
7982 ****************************************************************/
7984 WERROR _spoolss_DeleteForm(pipes_struct *p,
7985 struct spoolss_DeleteForm *r)
7987 const char *form_name = r->in.form_name;
7988 nt_forms_struct tmpForm;
7990 nt_forms_struct *list=NULL;
7991 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7993 WERROR status = WERR_OK;
7994 NT_PRINTER_INFO_LEVEL *printer = NULL;
7995 SE_PRIV se_printop = SE_PRINT_OPERATOR;
7998 DEBUG(5,("_spoolss_DeleteForm\n"));
8001 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8002 OUR_HANDLE(r->in.handle)));
8006 /* forms can be deleted on printer of on the print server handle */
8008 if ( Printer->printer_type == SPLHND_PRINTER )
8010 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8013 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8014 if (!W_ERROR_IS_OK(status))
8018 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8019 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8020 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8022 p->server_info->ptok,
8023 lp_printer_admin(snum))) {
8024 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8025 return WERR_ACCESS_DENIED;
8029 /* can't delete if builtin */
8031 if (get_a_builtin_ntform_by_string(form_name,&tmpForm)) {
8032 status = WERR_INVALID_PARAM;
8036 count = get_ntforms(&list);
8039 ret = delete_a_form(&list, form_name, &count, &status);
8046 * ChangeID must always be set if this is a printer
8049 if ( Printer->printer_type == SPLHND_PRINTER )
8050 status = mod_a_printer(printer, 2);
8054 free_a_printer(&printer, 2);
8060 /****************************************************************
8062 ****************************************************************/
8064 WERROR _spoolss_SetForm(pipes_struct *p,
8065 struct spoolss_SetForm *r)
8067 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8068 nt_forms_struct tmpForm;
8070 WERROR status = WERR_OK;
8071 NT_PRINTER_INFO_LEVEL *printer = NULL;
8072 SE_PRIV se_printop = SE_PRINT_OPERATOR;
8075 nt_forms_struct *list=NULL;
8076 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8078 DEBUG(5,("_spoolss_SetForm\n"));
8081 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8082 OUR_HANDLE(r->in.handle)));
8086 /* forms can be modified on printer of on the print server handle */
8088 if ( Printer->printer_type == SPLHND_PRINTER )
8090 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8093 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8094 if (!W_ERROR_IS_OK(status))
8098 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8099 and not a printer admin, then fail */
8101 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8102 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8103 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8105 p->server_info->ptok,
8106 lp_printer_admin(snum))) {
8107 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8108 return WERR_ACCESS_DENIED;
8111 /* can't set if builtin */
8112 if (get_a_builtin_ntform_by_string(form->form_name, &tmpForm)) {
8113 status = WERR_INVALID_PARAM;
8117 count = get_ntforms(&list);
8118 update_a_form(&list, form, count);
8120 write_ntforms(&list, count);
8124 * ChangeID must always be set if this is a printer
8127 if ( Printer->printer_type == SPLHND_PRINTER )
8128 status = mod_a_printer(printer, 2);
8133 free_a_printer(&printer, 2);
8139 /****************************************************************************
8140 fill_print_processor1
8141 ****************************************************************************/
8143 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8144 struct spoolss_PrintProcessorInfo1 *r,
8145 const char *print_processor_name)
8147 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8148 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8153 /****************************************************************************
8154 enumprintprocessors level 1.
8155 ****************************************************************************/
8157 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8158 union spoolss_PrintProcessorInfo **info_p,
8161 union spoolss_PrintProcessorInfo *info;
8164 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8165 W_ERROR_HAVE_NO_MEMORY(info);
8169 result = fill_print_processor1(info, &info[0].info1, "winprint");
8170 if (!W_ERROR_IS_OK(result)) {
8175 if (!W_ERROR_IS_OK(result)) {
8186 /****************************************************************
8187 _spoolss_EnumPrintProcessors
8188 ****************************************************************/
8190 WERROR _spoolss_EnumPrintProcessors(pipes_struct *p,
8191 struct spoolss_EnumPrintProcessors *r)
8195 /* that's an [in out] buffer */
8197 if (!r->in.buffer && (r->in.offered != 0)) {
8198 return WERR_INVALID_PARAM;
8201 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8204 * Enumerate the print processors ...
8206 * Just reply with "winprint", to keep NT happy
8207 * and I can use my nice printer checker.
8212 *r->out.info = NULL;
8214 switch (r->in.level) {
8216 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8220 return WERR_UNKNOWN_LEVEL;
8223 if (!W_ERROR_IS_OK(result)) {
8227 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8228 spoolss_EnumPrintProcessors, NULL,
8229 *r->out.info, r->in.level,
8231 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8232 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8234 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8237 /****************************************************************************
8238 fill_printprocdatatype1
8239 ****************************************************************************/
8241 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8242 struct spoolss_PrintProcDataTypesInfo1 *r,
8243 const char *name_array)
8245 r->name_array = talloc_strdup(mem_ctx, name_array);
8246 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8251 /****************************************************************************
8252 enumprintprocdatatypes level 1.
8253 ****************************************************************************/
8255 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8256 union spoolss_PrintProcDataTypesInfo **info_p,
8260 union spoolss_PrintProcDataTypesInfo *info;
8262 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8263 W_ERROR_HAVE_NO_MEMORY(info);
8267 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
8268 if (!W_ERROR_IS_OK(result)) {
8273 if (!W_ERROR_IS_OK(result)) {
8284 /****************************************************************
8285 _spoolss_EnumPrintProcDataTypes
8286 ****************************************************************/
8288 WERROR _spoolss_EnumPrintProcDataTypes(pipes_struct *p,
8289 struct spoolss_EnumPrintProcDataTypes *r)
8293 /* that's an [in out] buffer */
8295 if (!r->in.buffer && (r->in.offered != 0)) {
8296 return WERR_INVALID_PARAM;
8299 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8303 *r->out.info = NULL;
8305 switch (r->in.level) {
8307 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
8311 return WERR_UNKNOWN_LEVEL;
8314 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8315 spoolss_EnumPrintProcDataTypes, NULL,
8316 *r->out.info, r->in.level,
8318 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8319 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8321 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8324 /****************************************************************************
8326 ****************************************************************************/
8328 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
8329 struct spoolss_MonitorInfo1 *r,
8330 const char *monitor_name)
8332 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8333 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8338 /****************************************************************************
8340 ****************************************************************************/
8342 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
8343 struct spoolss_MonitorInfo2 *r,
8344 const char *monitor_name,
8345 const char *environment,
8346 const char *dll_name)
8348 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8349 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8350 r->environment = talloc_strdup(mem_ctx, environment);
8351 W_ERROR_HAVE_NO_MEMORY(r->environment);
8352 r->dll_name = talloc_strdup(mem_ctx, dll_name);
8353 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
8358 /****************************************************************************
8359 enumprintmonitors level 1.
8360 ****************************************************************************/
8362 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
8363 union spoolss_MonitorInfo **info_p,
8366 union spoolss_MonitorInfo *info;
8367 WERROR result = WERR_OK;
8369 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8370 W_ERROR_HAVE_NO_MEMORY(info);
8374 result = fill_monitor_1(info, &info[0].info1,
8376 if (!W_ERROR_IS_OK(result)) {
8380 result = fill_monitor_1(info, &info[1].info1,
8382 if (!W_ERROR_IS_OK(result)) {
8387 if (!W_ERROR_IS_OK(result)) {
8398 /****************************************************************************
8399 enumprintmonitors level 2.
8400 ****************************************************************************/
8402 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
8403 union spoolss_MonitorInfo **info_p,
8406 union spoolss_MonitorInfo *info;
8407 WERROR result = WERR_OK;
8409 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8410 W_ERROR_HAVE_NO_MEMORY(info);
8414 result = fill_monitor_2(info, &info[0].info2,
8416 "Windows NT X86", /* FIXME */
8418 if (!W_ERROR_IS_OK(result)) {
8422 result = fill_monitor_2(info, &info[1].info2,
8424 "Windows NT X86", /* FIXME */
8426 if (!W_ERROR_IS_OK(result)) {
8431 if (!W_ERROR_IS_OK(result)) {
8442 /****************************************************************
8443 _spoolss_EnumMonitors
8444 ****************************************************************/
8446 WERROR _spoolss_EnumMonitors(pipes_struct *p,
8447 struct spoolss_EnumMonitors *r)
8451 /* that's an [in out] buffer */
8453 if (!r->in.buffer && (r->in.offered != 0)) {
8454 return WERR_INVALID_PARAM;
8457 DEBUG(5,("_spoolss_EnumMonitors\n"));
8460 * Enumerate the print monitors ...
8462 * Just reply with "Local Port", to keep NT happy
8463 * and I can use my nice printer checker.
8468 *r->out.info = NULL;
8470 switch (r->in.level) {
8472 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
8476 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
8480 return WERR_UNKNOWN_LEVEL;
8483 if (!W_ERROR_IS_OK(result)) {
8487 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8488 spoolss_EnumMonitors, NULL,
8489 *r->out.info, r->in.level,
8491 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8492 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8494 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8497 /****************************************************************************
8498 ****************************************************************************/
8500 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
8501 const print_queue_struct *queue,
8502 int count, int snum,
8503 const NT_PRINTER_INFO_LEVEL *ntprinter,
8505 struct spoolss_JobInfo1 *r)
8510 for (i=0; i<count && found == false; i++) {
8511 if (queue[i].job == (int)jobid) {
8516 if (found == false) {
8517 /* NT treats not found as bad param... yet another bad choice */
8518 return WERR_INVALID_PARAM;
8521 return fill_job_info1(mem_ctx,
8529 /****************************************************************************
8530 ****************************************************************************/
8532 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
8533 const print_queue_struct *queue,
8534 int count, int snum,
8535 const NT_PRINTER_INFO_LEVEL *ntprinter,
8537 struct spoolss_JobInfo2 *r)
8541 struct spoolss_DeviceMode *devmode;
8542 NT_DEVICEMODE *nt_devmode;
8545 for (i=0; i<count && found == false; i++) {
8546 if (queue[i].job == (int)jobid) {
8551 if (found == false) {
8552 /* NT treats not found as bad param... yet another bad
8554 return WERR_INVALID_PARAM;
8558 * if the print job does not have a DEVMODE associated with it,
8559 * just use the one for the printer. A NULL devicemode is not
8560 * a failure condition
8563 nt_devmode = print_job_devmode(lp_const_servicename(snum), jobid);
8565 devmode = TALLOC_ZERO_P(mem_ctx, struct spoolss_DeviceMode);
8566 W_ERROR_HAVE_NO_MEMORY(devmode);
8567 result = convert_nt_devicemode(devmode, devmode, nt_devmode);
8568 if (!W_ERROR_IS_OK(result)) {
8572 devmode = construct_dev_mode(mem_ctx, lp_const_servicename(snum));
8573 W_ERROR_HAVE_NO_MEMORY(devmode);
8576 return fill_job_info2(mem_ctx,
8585 /****************************************************************
8587 ****************************************************************/
8589 WERROR _spoolss_GetJob(pipes_struct *p,
8590 struct spoolss_GetJob *r)
8592 WERROR result = WERR_OK;
8593 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
8596 print_queue_struct *queue = NULL;
8597 print_status_struct prt_status;
8599 /* that's an [in out] buffer */
8601 if (!r->in.buffer && (r->in.offered != 0)) {
8602 return WERR_INVALID_PARAM;
8605 DEBUG(5,("_spoolss_GetJob\n"));
8609 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8613 result = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum));
8614 if (!W_ERROR_IS_OK(result)) {
8618 count = print_queue_status(snum, &queue, &prt_status);
8620 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
8621 count, prt_status.status, prt_status.message));
8623 switch (r->in.level) {
8625 result = getjob_level_1(p->mem_ctx,
8626 queue, count, snum, ntprinter,
8627 r->in.job_id, &r->out.info->info1);
8630 result = getjob_level_2(p->mem_ctx,
8631 queue, count, snum, ntprinter,
8632 r->in.job_id, &r->out.info->info2);
8635 result = WERR_UNKNOWN_LEVEL;
8640 free_a_printer(&ntprinter, 2);
8642 if (!W_ERROR_IS_OK(result)) {
8643 TALLOC_FREE(r->out.info);
8647 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, NULL,
8648 r->out.info, r->in.level);
8649 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8651 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8654 /****************************************************************
8655 _spoolss_GetPrinterDataEx
8656 ****************************************************************/
8658 WERROR _spoolss_GetPrinterDataEx(pipes_struct *p,
8659 struct spoolss_GetPrinterDataEx *r)
8662 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8663 struct regval_blob *val = NULL;
8664 NT_PRINTER_INFO_LEVEL *printer = NULL;
8666 WERROR result = WERR_OK;
8669 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
8671 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
8672 r->in.key_name, r->in.value_name));
8674 /* in case of problem, return some default values */
8677 *r->out.type = REG_NONE;
8680 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
8681 OUR_HANDLE(r->in.handle)));
8682 result = WERR_BADFID;
8686 /* Is the handle to a printer or to the server? */
8688 if (Printer->printer_type == SPLHND_SERVER) {
8690 result = getprinterdata_printer_server(p->mem_ctx,
8697 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8698 result = WERR_BADFID;
8702 result = get_a_printer(Printer, &printer, 2, lp_servicename(snum));
8703 if (!W_ERROR_IS_OK(result)) {
8707 /* check to see if the keyname is valid */
8708 if (!strlen(r->in.key_name)) {
8709 result = WERR_INVALID_PARAM;
8713 /* XP sends this and wants to change id value from the PRINTER_INFO_0 */
8715 if (strequal(r->in.key_name, SPOOL_PRINTERDATA_KEY) &&
8716 strequal(r->in.value_name, "ChangeId")) {
8717 *r->out.type = REG_DWORD;
8719 r->out.data->value = printer->info_2->changeid;
8724 if (lookup_printerkey(printer->info_2->data, r->in.key_name) == -1) {
8725 DEBUG(4,("_spoolss_GetPrinterDataEx: "
8726 "Invalid keyname [%s]\n", r->in.key_name ));
8727 result = WERR_BADFILE;
8731 val = get_printer_data(printer->info_2,
8732 r->in.key_name, r->in.value_name);
8734 result = WERR_BADFILE;
8738 *r->out.needed = regval_size(val);
8739 *r->out.type = regval_type(val);
8741 blob = data_blob_const(regval_data_p(val), regval_size(val));
8743 result = pull_spoolss_PrinterData(p->mem_ctx, &blob,
8749 free_a_printer(&printer, 2);
8752 if (!W_ERROR_IS_OK(result)) {
8756 *r->out.needed = ndr_size_spoolss_PrinterData(r->out.data, *r->out.type, NULL, 0);
8757 *r->out.type = SPOOLSS_BUFFER_OK(*r->out.type, REG_NONE);
8758 r->out.data = SPOOLSS_BUFFER_OK(r->out.data, r->out.data);
8760 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
8763 /****************************************************************
8764 _spoolss_SetPrinterDataEx
8765 ****************************************************************/
8767 WERROR _spoolss_SetPrinterDataEx(pipes_struct *p,
8768 struct spoolss_SetPrinterDataEx *r)
8770 NT_PRINTER_INFO_LEVEL *printer = NULL;
8772 WERROR result = WERR_OK;
8773 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8777 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
8779 /* From MSDN documentation of SetPrinterDataEx: pass request to
8780 SetPrinterData if key is "PrinterDriverData" */
8783 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
8784 OUR_HANDLE(r->in.handle)));
8788 if (Printer->printer_type == SPLHND_SERVER) {
8789 DEBUG(10,("_spoolss_SetPrinterDataEx: "
8790 "Not implemented for server handles yet\n"));
8791 return WERR_INVALID_PARAM;
8794 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8799 * Access check : NT returns "access denied" if you make a
8800 * SetPrinterData call without the necessary privildge.
8801 * we were originally returning OK if nothing changed
8802 * which made Win2k issue **a lot** of SetPrinterData
8803 * when connecting to a printer --jerry
8806 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8807 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
8808 "change denied by handle access permissions\n"));
8809 return WERR_ACCESS_DENIED;
8812 result = get_a_printer(Printer, &printer, 2, lp_servicename(snum));
8813 if (!W_ERROR_IS_OK(result)) {
8817 /* check for OID in valuename */
8819 oid_string = strchr(r->in.value_name, ',');
8825 result = push_spoolss_PrinterData(p->mem_ctx, &blob,
8826 r->in.type, &r->in.data);
8827 if (!W_ERROR_IS_OK(result)) {
8832 * When client side code sets a magic printer data key, detect it and save
8833 * the current printer data and the magic key's data (its the DEVMODE) for
8834 * future printer/driver initializations.
8836 if ((r->in.type == REG_BINARY) && strequal(r->in.value_name, PHANTOM_DEVMODE_KEY)) {
8837 /* Set devmode and printer initialization info */
8838 result = save_driver_init(printer, 2, blob.data, blob.length);
8840 srv_spoolss_reset_printerdata(printer->info_2->drivername);
8845 /* save the registry data */
8847 result = set_printer_dataex(printer, r->in.key_name, r->in.value_name,
8848 r->in.type, blob.data, blob.length);
8850 if (W_ERROR_IS_OK(result)) {
8851 /* save the OID if one was specified */
8853 char *str = talloc_asprintf(p->mem_ctx, "%s\\%s",
8854 r->in.key_name, SPOOL_OID_KEY);
8856 result = WERR_NOMEM;
8861 * I'm not checking the status here on purpose. Don't know
8862 * if this is right, but I'm returning the status from the
8863 * previous set_printer_dataex() call. I have no idea if
8864 * this is right. --jerry
8867 set_printer_dataex(printer, str, r->in.value_name,
8868 REG_SZ, (uint8_t *)oid_string,
8869 strlen(oid_string)+1);
8872 result = mod_a_printer(printer, 2);
8876 free_a_printer(&printer, 2);
8881 /****************************************************************
8882 _spoolss_DeletePrinterDataEx
8883 ****************************************************************/
8885 WERROR _spoolss_DeletePrinterDataEx(pipes_struct *p,
8886 struct spoolss_DeletePrinterDataEx *r)
8888 NT_PRINTER_INFO_LEVEL *printer = NULL;
8890 WERROR status = WERR_OK;
8891 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8893 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
8896 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
8897 "Invalid handle (%s:%u:%u).\n",
8898 OUR_HANDLE(r->in.handle)));
8902 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8905 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8906 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
8907 "printer properties change denied by handle\n"));
8908 return WERR_ACCESS_DENIED;
8911 if (!r->in.value_name || !r->in.key_name) {
8915 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8916 if (!W_ERROR_IS_OK(status))
8919 status = delete_printer_dataex( printer, r->in.key_name, r->in.value_name );
8921 if ( W_ERROR_IS_OK(status) )
8922 mod_a_printer( printer, 2 );
8924 free_a_printer(&printer, 2);
8929 /****************************************************************
8930 _spoolss_EnumPrinterKey
8931 ****************************************************************/
8933 WERROR _spoolss_EnumPrinterKey(pipes_struct *p,
8934 struct spoolss_EnumPrinterKey *r)
8936 fstring *keynames = NULL;
8938 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8939 NT_PRINTER_DATA *data;
8940 NT_PRINTER_INFO_LEVEL *printer = NULL;
8942 WERROR result = WERR_BADFILE;
8944 const char **array = NULL;
8947 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
8950 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
8951 OUR_HANDLE(r->in.handle)));
8955 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8959 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8960 if (!W_ERROR_IS_OK(result)) {
8964 /* get the list of subkey names */
8966 data = printer->info_2->data;
8968 num_keys = get_printer_subkeys(data, r->in.key_name, &keynames);
8969 if (num_keys == -1) {
8970 result = WERR_BADFILE;
8974 array = talloc_zero_array(r->out.key_buffer, const char *, num_keys + 2);
8976 result = WERR_NOMEM;
8981 array[0] = talloc_strdup(array, "");
8983 result = WERR_NOMEM;
8988 for (i=0; i < num_keys; i++) {
8990 DEBUG(10,("_spoolss_EnumPrinterKey: adding keyname: %s\n",
8993 array[i] = talloc_strdup(array, keynames[i]);
8995 result = WERR_NOMEM;
9000 if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
9001 result = WERR_NOMEM;
9005 *r->out._ndr_size = r->in.offered / 2;
9006 *r->out.needed = blob.length;
9008 if (r->in.offered < *r->out.needed) {
9009 result = WERR_MORE_DATA;
9012 r->out.key_buffer->string_array = array;
9016 if (!W_ERROR_IS_OK(result)) {
9018 if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
9023 free_a_printer(&printer, 2);
9024 SAFE_FREE(keynames);
9029 /****************************************************************
9030 _spoolss_DeletePrinterKey
9031 ****************************************************************/
9033 WERROR _spoolss_DeletePrinterKey(pipes_struct *p,
9034 struct spoolss_DeletePrinterKey *r)
9036 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9037 NT_PRINTER_INFO_LEVEL *printer = NULL;
9041 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9044 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9045 OUR_HANDLE(r->in.handle)));
9049 /* if keyname == NULL, return error */
9051 if ( !r->in.key_name )
9052 return WERR_INVALID_PARAM;
9054 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
9057 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9058 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9059 "printer properties change denied by handle\n"));
9060 return WERR_ACCESS_DENIED;
9063 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9064 if (!W_ERROR_IS_OK(status))
9067 /* delete the key and all subneys */
9069 status = delete_all_printer_data( printer->info_2, r->in.key_name );
9071 if ( W_ERROR_IS_OK(status) )
9072 status = mod_a_printer(printer, 2);
9074 free_a_printer( &printer, 2 );
9079 /****************************************************************
9080 ****************************************************************/
9082 static WERROR registry_value_to_printer_enum_value(TALLOC_CTX *mem_ctx,
9083 struct regval_blob *v,
9084 struct spoolss_PrinterEnumValues *r)
9088 r->data = TALLOC_ZERO_P(mem_ctx, union spoolss_PrinterData);
9089 W_ERROR_HAVE_NO_MEMORY(r->data);
9091 r->value_name = talloc_strdup(mem_ctx, regval_name(v));
9092 W_ERROR_HAVE_NO_MEMORY(r->value_name);
9094 r->type = regval_type(v);
9095 r->data_length = regval_size(v);
9097 if (r->data_length) {
9098 DATA_BLOB blob = data_blob_const(regval_data_p(v),
9100 result = pull_spoolss_PrinterData(mem_ctx, &blob,
9103 if (!W_ERROR_IS_OK(result)) {
9111 /****************************************************************
9112 _spoolss_EnumPrinterDataEx
9113 ****************************************************************/
9115 WERROR _spoolss_EnumPrinterDataEx(pipes_struct *p,
9116 struct spoolss_EnumPrinterDataEx *r)
9119 NT_PRINTER_INFO_LEVEL *printer = NULL;
9120 struct spoolss_PrinterEnumValues *info = NULL;
9121 NT_PRINTER_DATA *p_data;
9122 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9128 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9132 *r->out.info = NULL;
9135 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9136 OUR_HANDLE(r->in.handle)));
9141 * first check for a keyname of NULL or "". Win2k seems to send
9142 * this a lot and we should send back WERR_INVALID_PARAM
9143 * no need to spend time looking up the printer in this case.
9147 if (!strlen(r->in.key_name)) {
9148 result = WERR_INVALID_PARAM;
9152 /* get the printer off of disk */
9154 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9158 ZERO_STRUCT(printer);
9159 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9160 if (!W_ERROR_IS_OK(result)) {
9164 /* now look for a match on the key name */
9166 p_data = printer->info_2->data;
9168 key_index = lookup_printerkey(p_data, r->in.key_name);
9169 if (key_index == -1) {
9170 DEBUG(10,("_spoolss_EnumPrinterDataEx: Unknown keyname [%s]\n",
9172 result = WERR_INVALID_PARAM;
9176 /* allocate the memory for the array of pointers -- if necessary */
9178 count = regval_ctr_numvals(p_data->keys[key_index].values);
9180 result = WERR_OK; /* ??? */
9184 info = TALLOC_ZERO_ARRAY(p->mem_ctx,
9185 struct spoolss_PrinterEnumValues,
9188 DEBUG(0,("_spoolss_EnumPrinterDataEx: talloc() failed\n"));
9189 result = WERR_NOMEM;
9194 * loop through all params and build the array to pass
9195 * back to the client
9198 for (i=0; i < count; i++) {
9200 struct regval_blob *val;
9202 /* lookup the registry value */
9204 val = regval_ctr_specific_value(p_data->keys[key_index].values, i);
9206 DEBUG(10,("retrieved value number [%d] [%s]\n", i, regval_name(val)));
9210 result = registry_value_to_printer_enum_value(info, val, &info[i]);
9211 if (!W_ERROR_IS_OK(result)) {
9216 #if 0 /* FIXME - gd */
9217 /* housekeeping information in the reply */
9219 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9220 * the hand marshalled container size is a multiple
9221 * of 4 bytes for RPC alignment.
9225 needed += 4-(needed % 4);
9228 *r->out.count = count;
9229 *r->out.info = info;
9234 free_a_printer(&printer, 2);
9237 if (!W_ERROR_IS_OK(result)) {
9241 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
9242 spoolss_EnumPrinterDataEx, NULL,
9245 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9246 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
9248 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9251 /****************************************************************************
9252 ****************************************************************************/
9254 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
9255 const char *servername,
9256 const char *environment,
9257 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9262 werr = compose_spoolss_server_path(mem_ctx,
9265 SPOOLSS_PRTPROCS_PATH,
9267 if (!W_ERROR_IS_OK(werr)) {
9271 DEBUG(4,("print processor directory: [%s]\n", path));
9273 r->directory_name = path;
9278 /****************************************************************
9279 _spoolss_GetPrintProcessorDirectory
9280 ****************************************************************/
9282 WERROR _spoolss_GetPrintProcessorDirectory(pipes_struct *p,
9283 struct spoolss_GetPrintProcessorDirectory *r)
9287 /* that's an [in out] buffer */
9289 if (!r->in.buffer && (r->in.offered != 0)) {
9290 return WERR_INVALID_PARAM;
9293 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9298 /* r->in.level is ignored */
9300 /* We always should reply with a local print processor directory so that
9301 * users are not forced to have a [prnproc$] share on the Samba spoolss
9302 * server - Guenther */
9304 result = getprintprocessordirectory_level_1(p->mem_ctx,
9305 NULL, /* r->in.server */
9307 &r->out.info->info1);
9308 if (!W_ERROR_IS_OK(result)) {
9309 TALLOC_FREE(r->out.info);
9313 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo, NULL,
9314 r->out.info, r->in.level);
9315 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9317 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9320 /*******************************************************************
9321 ********************************************************************/
9323 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
9324 const char *dllname)
9326 enum ndr_err_code ndr_err;
9327 struct spoolss_MonitorUi ui;
9329 ui.dll_name = dllname;
9331 ndr_err = ndr_push_struct_blob(buf, mem_ctx, NULL, &ui,
9332 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
9333 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9334 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
9336 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9339 /*******************************************************************
9340 Streams the monitor UI DLL name in UNICODE
9341 *******************************************************************/
9343 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
9344 NT_USER_TOKEN *token, DATA_BLOB *in,
9345 DATA_BLOB *out, uint32_t *needed)
9347 const char *dllname = "tcpmonui.dll";
9349 *needed = (strlen(dllname)+1) * 2;
9351 if (out->length < *needed) {
9352 return WERR_INSUFFICIENT_BUFFER;
9355 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9362 /*******************************************************************
9363 ********************************************************************/
9365 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
9366 struct spoolss_PortData1 *port1,
9367 const DATA_BLOB *buf)
9369 enum ndr_err_code ndr_err;
9370 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, NULL, port1,
9371 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
9372 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9373 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
9375 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9378 /*******************************************************************
9379 ********************************************************************/
9381 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
9382 struct spoolss_PortData2 *port2,
9383 const DATA_BLOB *buf)
9385 enum ndr_err_code ndr_err;
9386 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, NULL, port2,
9387 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
9388 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9389 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
9391 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9394 /*******************************************************************
9395 Create a new TCP/IP port
9396 *******************************************************************/
9398 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
9399 NT_USER_TOKEN *token, DATA_BLOB *in,
9400 DATA_BLOB *out, uint32_t *needed)
9402 struct spoolss_PortData1 port1;
9403 struct spoolss_PortData2 port2;
9404 char *device_uri = NULL;
9407 const char *portname;
9408 const char *hostaddress;
9410 uint32_t port_number;
9413 /* peek for spoolss_PortData version */
9415 if (!in || (in->length < (128 + 4))) {
9416 return WERR_GENERAL_FAILURE;
9419 version = IVAL(in->data, 128);
9425 if (!pull_port_data_1(mem_ctx, &port1, in)) {
9429 portname = port1.portname;
9430 hostaddress = port1.hostaddress;
9431 queue = port1.queue;
9432 protocol = port1.protocol;
9433 port_number = port1.port_number;
9439 if (!pull_port_data_2(mem_ctx, &port2, in)) {
9443 portname = port2.portname;
9444 hostaddress = port2.hostaddress;
9445 queue = port2.queue;
9446 protocol = port2.protocol;
9447 port_number = port2.port_number;
9451 DEBUG(1,("xcvtcp_addport: "
9452 "unknown version of port_data: %d\n", version));
9453 return WERR_UNKNOWN_PORT;
9456 /* create the device URI and call the add_port_hook() */
9459 case PROTOCOL_RAWTCP_TYPE:
9460 device_uri = talloc_asprintf(mem_ctx,
9461 "socket://%s:%d/", hostaddress,
9465 case PROTOCOL_LPR_TYPE:
9466 device_uri = talloc_asprintf(mem_ctx,
9467 "lpr://%s/%s", hostaddress, queue );
9471 return WERR_UNKNOWN_PORT;
9478 return add_port_hook(mem_ctx, token, portname, device_uri);
9481 /*******************************************************************
9482 *******************************************************************/
9484 struct xcv_api_table xcvtcp_cmds[] = {
9485 { "MonitorUI", xcvtcp_monitorui },
9486 { "AddPort", xcvtcp_addport},
9490 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
9491 NT_USER_TOKEN *token, const char *command,
9498 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
9500 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
9501 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
9502 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9505 return WERR_BADFUNC;
9508 /*******************************************************************
9509 *******************************************************************/
9510 #if 0 /* don't support management using the "Local Port" monitor */
9512 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
9513 NT_USER_TOKEN *token, DATA_BLOB *in,
9514 DATA_BLOB *out, uint32_t *needed)
9516 const char *dllname = "localui.dll";
9518 *needed = (strlen(dllname)+1) * 2;
9520 if (out->length < *needed) {
9521 return WERR_INSUFFICIENT_BUFFER;
9524 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9531 /*******************************************************************
9532 *******************************************************************/
9534 struct xcv_api_table xcvlocal_cmds[] = {
9535 { "MonitorUI", xcvlocal_monitorui },
9539 struct xcv_api_table xcvlocal_cmds[] = {
9546 /*******************************************************************
9547 *******************************************************************/
9549 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
9550 NT_USER_TOKEN *token, const char *command,
9551 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
9556 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
9558 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
9559 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
9560 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9562 return WERR_BADFUNC;
9565 /****************************************************************
9567 ****************************************************************/
9569 WERROR _spoolss_XcvData(pipes_struct *p,
9570 struct spoolss_XcvData *r)
9572 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9573 DATA_BLOB out_data = data_blob_null;
9577 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
9578 OUR_HANDLE(r->in.handle)));
9582 /* Has to be a handle to the TCP/IP port monitor */
9584 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
9585 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
9589 /* requires administrative access to the server */
9591 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
9592 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
9593 return WERR_ACCESS_DENIED;
9596 /* Allocate the outgoing buffer */
9598 if (r->in.out_data_size) {
9599 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
9600 if (out_data.data == NULL) {
9605 switch ( Printer->printer_type ) {
9606 case SPLHND_PORTMON_TCP:
9607 werror = process_xcvtcp_command(p->mem_ctx,
9608 p->server_info->ptok,
9609 r->in.function_name,
9610 &r->in.in_data, &out_data,
9613 case SPLHND_PORTMON_LOCAL:
9614 werror = process_xcvlocal_command(p->mem_ctx,
9615 p->server_info->ptok,
9616 r->in.function_name,
9617 &r->in.in_data, &out_data,
9621 werror = WERR_INVALID_PRINT_MONITOR;
9624 if (!W_ERROR_IS_OK(werror)) {
9628 *r->out.status_code = 0;
9630 if (r->out.out_data && out_data.data && r->in.out_data_size && out_data.length) {
9631 memcpy(r->out.out_data, out_data.data,
9632 MIN(r->in.out_data_size, out_data.length));
9638 /****************************************************************
9639 _spoolss_AddPrintProcessor
9640 ****************************************************************/
9642 WERROR _spoolss_AddPrintProcessor(pipes_struct *p,
9643 struct spoolss_AddPrintProcessor *r)
9645 /* for now, just indicate success and ignore the add. We'll
9646 automatically set the winprint processor for printer
9647 entries later. Used to debug the LexMark Optra S 1855 PCL
9653 /****************************************************************
9655 ****************************************************************/
9657 WERROR _spoolss_AddPort(pipes_struct *p,
9658 struct spoolss_AddPort *r)
9660 /* do what w2k3 does */
9662 return WERR_NOT_SUPPORTED;
9665 /****************************************************************
9666 _spoolss_GetPrinterDriver
9667 ****************************************************************/
9669 WERROR _spoolss_GetPrinterDriver(pipes_struct *p,
9670 struct spoolss_GetPrinterDriver *r)
9672 p->rng_fault_state = true;
9673 return WERR_NOT_SUPPORTED;
9676 /****************************************************************
9677 _spoolss_ReadPrinter
9678 ****************************************************************/
9680 WERROR _spoolss_ReadPrinter(pipes_struct *p,
9681 struct spoolss_ReadPrinter *r)
9683 p->rng_fault_state = true;
9684 return WERR_NOT_SUPPORTED;
9687 /****************************************************************
9688 _spoolss_WaitForPrinterChange
9689 ****************************************************************/
9691 WERROR _spoolss_WaitForPrinterChange(pipes_struct *p,
9692 struct spoolss_WaitForPrinterChange *r)
9694 p->rng_fault_state = true;
9695 return WERR_NOT_SUPPORTED;
9698 /****************************************************************
9699 _spoolss_ConfigurePort
9700 ****************************************************************/
9702 WERROR _spoolss_ConfigurePort(pipes_struct *p,
9703 struct spoolss_ConfigurePort *r)
9705 p->rng_fault_state = true;
9706 return WERR_NOT_SUPPORTED;
9709 /****************************************************************
9711 ****************************************************************/
9713 WERROR _spoolss_DeletePort(pipes_struct *p,
9714 struct spoolss_DeletePort *r)
9716 p->rng_fault_state = true;
9717 return WERR_NOT_SUPPORTED;
9720 /****************************************************************
9721 _spoolss_CreatePrinterIC
9722 ****************************************************************/
9724 WERROR _spoolss_CreatePrinterIC(pipes_struct *p,
9725 struct spoolss_CreatePrinterIC *r)
9727 p->rng_fault_state = true;
9728 return WERR_NOT_SUPPORTED;
9731 /****************************************************************
9732 _spoolss_PlayGDIScriptOnPrinterIC
9733 ****************************************************************/
9735 WERROR _spoolss_PlayGDIScriptOnPrinterIC(pipes_struct *p,
9736 struct spoolss_PlayGDIScriptOnPrinterIC *r)
9738 p->rng_fault_state = true;
9739 return WERR_NOT_SUPPORTED;
9742 /****************************************************************
9743 _spoolss_DeletePrinterIC
9744 ****************************************************************/
9746 WERROR _spoolss_DeletePrinterIC(pipes_struct *p,
9747 struct spoolss_DeletePrinterIC *r)
9749 p->rng_fault_state = true;
9750 return WERR_NOT_SUPPORTED;
9753 /****************************************************************
9754 _spoolss_AddPrinterConnection
9755 ****************************************************************/
9757 WERROR _spoolss_AddPrinterConnection(pipes_struct *p,
9758 struct spoolss_AddPrinterConnection *r)
9760 p->rng_fault_state = true;
9761 return WERR_NOT_SUPPORTED;
9764 /****************************************************************
9765 _spoolss_DeletePrinterConnection
9766 ****************************************************************/
9768 WERROR _spoolss_DeletePrinterConnection(pipes_struct *p,
9769 struct spoolss_DeletePrinterConnection *r)
9771 p->rng_fault_state = true;
9772 return WERR_NOT_SUPPORTED;
9775 /****************************************************************
9776 _spoolss_PrinterMessageBox
9777 ****************************************************************/
9779 WERROR _spoolss_PrinterMessageBox(pipes_struct *p,
9780 struct spoolss_PrinterMessageBox *r)
9782 p->rng_fault_state = true;
9783 return WERR_NOT_SUPPORTED;
9786 /****************************************************************
9788 ****************************************************************/
9790 WERROR _spoolss_AddMonitor(pipes_struct *p,
9791 struct spoolss_AddMonitor *r)
9793 p->rng_fault_state = true;
9794 return WERR_NOT_SUPPORTED;
9797 /****************************************************************
9798 _spoolss_DeleteMonitor
9799 ****************************************************************/
9801 WERROR _spoolss_DeleteMonitor(pipes_struct *p,
9802 struct spoolss_DeleteMonitor *r)
9804 p->rng_fault_state = true;
9805 return WERR_NOT_SUPPORTED;
9808 /****************************************************************
9809 _spoolss_DeletePrintProcessor
9810 ****************************************************************/
9812 WERROR _spoolss_DeletePrintProcessor(pipes_struct *p,
9813 struct spoolss_DeletePrintProcessor *r)
9815 p->rng_fault_state = true;
9816 return WERR_NOT_SUPPORTED;
9819 /****************************************************************
9820 _spoolss_AddPrintProvidor
9821 ****************************************************************/
9823 WERROR _spoolss_AddPrintProvidor(pipes_struct *p,
9824 struct spoolss_AddPrintProvidor *r)
9826 p->rng_fault_state = true;
9827 return WERR_NOT_SUPPORTED;
9830 /****************************************************************
9831 _spoolss_DeletePrintProvidor
9832 ****************************************************************/
9834 WERROR _spoolss_DeletePrintProvidor(pipes_struct *p,
9835 struct spoolss_DeletePrintProvidor *r)
9837 p->rng_fault_state = true;
9838 return WERR_NOT_SUPPORTED;
9841 /****************************************************************
9842 _spoolss_FindFirstPrinterChangeNotification
9843 ****************************************************************/
9845 WERROR _spoolss_FindFirstPrinterChangeNotification(pipes_struct *p,
9846 struct spoolss_FindFirstPrinterChangeNotification *r)
9848 p->rng_fault_state = true;
9849 return WERR_NOT_SUPPORTED;
9852 /****************************************************************
9853 _spoolss_FindNextPrinterChangeNotification
9854 ****************************************************************/
9856 WERROR _spoolss_FindNextPrinterChangeNotification(pipes_struct *p,
9857 struct spoolss_FindNextPrinterChangeNotification *r)
9859 p->rng_fault_state = true;
9860 return WERR_NOT_SUPPORTED;
9863 /****************************************************************
9864 _spoolss_RouterFindFirstPrinterChangeNotificationOld
9865 ****************************************************************/
9867 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(pipes_struct *p,
9868 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
9870 p->rng_fault_state = true;
9871 return WERR_NOT_SUPPORTED;
9874 /****************************************************************
9875 _spoolss_ReplyOpenPrinter
9876 ****************************************************************/
9878 WERROR _spoolss_ReplyOpenPrinter(pipes_struct *p,
9879 struct spoolss_ReplyOpenPrinter *r)
9881 p->rng_fault_state = true;
9882 return WERR_NOT_SUPPORTED;
9885 /****************************************************************
9886 _spoolss_RouterReplyPrinter
9887 ****************************************************************/
9889 WERROR _spoolss_RouterReplyPrinter(pipes_struct *p,
9890 struct spoolss_RouterReplyPrinter *r)
9892 p->rng_fault_state = true;
9893 return WERR_NOT_SUPPORTED;
9896 /****************************************************************
9897 _spoolss_ReplyClosePrinter
9898 ****************************************************************/
9900 WERROR _spoolss_ReplyClosePrinter(pipes_struct *p,
9901 struct spoolss_ReplyClosePrinter *r)
9903 p->rng_fault_state = true;
9904 return WERR_NOT_SUPPORTED;
9907 /****************************************************************
9909 ****************************************************************/
9911 WERROR _spoolss_AddPortEx(pipes_struct *p,
9912 struct spoolss_AddPortEx *r)
9914 p->rng_fault_state = true;
9915 return WERR_NOT_SUPPORTED;
9918 /****************************************************************
9919 _spoolss_RouterFindFirstPrinterChangeNotification
9920 ****************************************************************/
9922 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(pipes_struct *p,
9923 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
9925 p->rng_fault_state = true;
9926 return WERR_NOT_SUPPORTED;
9929 /****************************************************************
9930 _spoolss_SpoolerInit
9931 ****************************************************************/
9933 WERROR _spoolss_SpoolerInit(pipes_struct *p,
9934 struct spoolss_SpoolerInit *r)
9936 p->rng_fault_state = true;
9937 return WERR_NOT_SUPPORTED;
9940 /****************************************************************
9941 _spoolss_ResetPrinterEx
9942 ****************************************************************/
9944 WERROR _spoolss_ResetPrinterEx(pipes_struct *p,
9945 struct spoolss_ResetPrinterEx *r)
9947 p->rng_fault_state = true;
9948 return WERR_NOT_SUPPORTED;
9951 /****************************************************************
9952 _spoolss_RouterReplyPrinterEx
9953 ****************************************************************/
9955 WERROR _spoolss_RouterReplyPrinterEx(pipes_struct *p,
9956 struct spoolss_RouterReplyPrinterEx *r)
9958 p->rng_fault_state = true;
9959 return WERR_NOT_SUPPORTED;
9962 /****************************************************************
9964 ****************************************************************/
9966 WERROR _spoolss_44(pipes_struct *p,
9967 struct spoolss_44 *r)
9969 p->rng_fault_state = true;
9970 return WERR_NOT_SUPPORTED;
9973 /****************************************************************
9975 ****************************************************************/
9977 WERROR _spoolss_47(pipes_struct *p,
9978 struct spoolss_47 *r)
9980 p->rng_fault_state = true;
9981 return WERR_NOT_SUPPORTED;
9984 /****************************************************************
9986 ****************************************************************/
9988 WERROR _spoolss_4a(pipes_struct *p,
9989 struct spoolss_4a *r)
9991 p->rng_fault_state = true;
9992 return WERR_NOT_SUPPORTED;
9995 /****************************************************************
9997 ****************************************************************/
9999 WERROR _spoolss_4b(pipes_struct *p,
10000 struct spoolss_4b *r)
10002 p->rng_fault_state = true;
10003 return WERR_NOT_SUPPORTED;
10006 /****************************************************************
10008 ****************************************************************/
10010 WERROR _spoolss_4c(pipes_struct *p,
10011 struct spoolss_4c *r)
10013 p->rng_fault_state = true;
10014 return WERR_NOT_SUPPORTED;
10017 /****************************************************************
10019 ****************************************************************/
10021 WERROR _spoolss_53(pipes_struct *p,
10022 struct spoolss_53 *r)
10024 p->rng_fault_state = true;
10025 return WERR_NOT_SUPPORTED;
10028 /****************************************************************
10030 ****************************************************************/
10032 WERROR _spoolss_55(pipes_struct *p,
10033 struct spoolss_55 *r)
10035 p->rng_fault_state = true;
10036 return WERR_NOT_SUPPORTED;
10039 /****************************************************************
10041 ****************************************************************/
10043 WERROR _spoolss_56(pipes_struct *p,
10044 struct spoolss_56 *r)
10046 p->rng_fault_state = true;
10047 return WERR_NOT_SUPPORTED;
10050 /****************************************************************
10052 ****************************************************************/
10054 WERROR _spoolss_57(pipes_struct *p,
10055 struct spoolss_57 *r)
10057 p->rng_fault_state = true;
10058 return WERR_NOT_SUPPORTED;
10061 /****************************************************************
10063 ****************************************************************/
10065 WERROR _spoolss_5a(pipes_struct *p,
10066 struct spoolss_5a *r)
10068 p->rng_fault_state = true;
10069 return WERR_NOT_SUPPORTED;
10072 /****************************************************************
10074 ****************************************************************/
10076 WERROR _spoolss_5b(pipes_struct *p,
10077 struct spoolss_5b *r)
10079 p->rng_fault_state = true;
10080 return WERR_NOT_SUPPORTED;
10083 /****************************************************************
10085 ****************************************************************/
10087 WERROR _spoolss_5c(pipes_struct *p,
10088 struct spoolss_5c *r)
10090 p->rng_fault_state = true;
10091 return WERR_NOT_SUPPORTED;
10094 /****************************************************************
10096 ****************************************************************/
10098 WERROR _spoolss_5d(pipes_struct *p,
10099 struct spoolss_5d *r)
10101 p->rng_fault_state = true;
10102 return WERR_NOT_SUPPORTED;
10105 /****************************************************************
10107 ****************************************************************/
10109 WERROR _spoolss_5e(pipes_struct *p,
10110 struct spoolss_5e *r)
10112 p->rng_fault_state = true;
10113 return WERR_NOT_SUPPORTED;
10116 /****************************************************************
10118 ****************************************************************/
10120 WERROR _spoolss_5f(pipes_struct *p,
10121 struct spoolss_5f *r)
10123 p->rng_fault_state = true;
10124 return WERR_NOT_SUPPORTED;
10127 /****************************************************************
10129 ****************************************************************/
10131 WERROR _spoolss_60(pipes_struct *p,
10132 struct spoolss_60 *r)
10134 p->rng_fault_state = true;
10135 return WERR_NOT_SUPPORTED;
10138 /****************************************************************
10140 ****************************************************************/
10142 WERROR _spoolss_61(pipes_struct *p,
10143 struct spoolss_61 *r)
10145 p->rng_fault_state = true;
10146 return WERR_NOT_SUPPORTED;
10149 /****************************************************************
10151 ****************************************************************/
10153 WERROR _spoolss_62(pipes_struct *p,
10154 struct spoolss_62 *r)
10156 p->rng_fault_state = true;
10157 return WERR_NOT_SUPPORTED;
10160 /****************************************************************
10162 ****************************************************************/
10164 WERROR _spoolss_63(pipes_struct *p,
10165 struct spoolss_63 *r)
10167 p->rng_fault_state = true;
10168 return WERR_NOT_SUPPORTED;
10171 /****************************************************************
10173 ****************************************************************/
10175 WERROR _spoolss_64(pipes_struct *p,
10176 struct spoolss_64 *r)
10178 p->rng_fault_state = true;
10179 return WERR_NOT_SUPPORTED;
10182 /****************************************************************
10184 ****************************************************************/
10186 WERROR _spoolss_65(pipes_struct *p,
10187 struct spoolss_65 *r)
10189 p->rng_fault_state = true;
10190 return WERR_NOT_SUPPORTED;
10193 /****************************************************************
10194 _spoolss_GetCorePrinterDrivers
10195 ****************************************************************/
10197 WERROR _spoolss_GetCorePrinterDrivers(pipes_struct *p,
10198 struct spoolss_GetCorePrinterDrivers *r)
10200 p->rng_fault_state = true;
10201 return WERR_NOT_SUPPORTED;
10204 /****************************************************************
10206 ****************************************************************/
10208 WERROR _spoolss_67(pipes_struct *p,
10209 struct spoolss_67 *r)
10211 p->rng_fault_state = true;
10212 return WERR_NOT_SUPPORTED;
10215 /****************************************************************
10216 _spoolss_GetPrinterDriverPackagePath
10217 ****************************************************************/
10219 WERROR _spoolss_GetPrinterDriverPackagePath(pipes_struct *p,
10220 struct spoolss_GetPrinterDriverPackagePath *r)
10222 p->rng_fault_state = true;
10223 return WERR_NOT_SUPPORTED;
10226 /****************************************************************
10228 ****************************************************************/
10230 WERROR _spoolss_69(pipes_struct *p,
10231 struct spoolss_69 *r)
10233 p->rng_fault_state = true;
10234 return WERR_NOT_SUPPORTED;
10237 /****************************************************************
10239 ****************************************************************/
10241 WERROR _spoolss_6a(pipes_struct *p,
10242 struct spoolss_6a *r)
10244 p->rng_fault_state = true;
10245 return WERR_NOT_SUPPORTED;
10248 /****************************************************************
10250 ****************************************************************/
10252 WERROR _spoolss_6b(pipes_struct *p,
10253 struct spoolss_6b *r)
10255 p->rng_fault_state = true;
10256 return WERR_NOT_SUPPORTED;
10259 /****************************************************************
10261 ****************************************************************/
10263 WERROR _spoolss_6c(pipes_struct *p,
10264 struct spoolss_6c *r)
10266 p->rng_fault_state = true;
10267 return WERR_NOT_SUPPORTED;
10270 /****************************************************************
10272 ****************************************************************/
10274 WERROR _spoolss_6d(pipes_struct *p,
10275 struct spoolss_6d *r)
10277 p->rng_fault_state = true;
10278 return WERR_NOT_SUPPORTED;