Fix coverity #908, #909, uninitialized variable.
[Samba.git] / source3 / rpc_server / srv_spoolss_nt.c
blob9ad509efbb6001746d4054a01d621313f6e7e7dd
1 /*
2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-2000,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
6 * Copyright (C) Jean François Micouleau 1998-2000,
7 * Copyright (C) Jeremy Allison 2001-2002,
8 * Copyright (C) Gerald Carter 2000-2004,
9 * Copyright (C) Tim Potter 2001-2002.
10 * Copyright (C) Guenther Deschner 2009.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <http://www.gnu.org/licenses/>.
26 /* Since the SPOOLSS rpc routines are basically DOS 16-bit calls wrapped
27 up, all the errors returned are DOS errors, not NT status codes. */
29 #include "includes.h"
31 /* macros stolen from s4 spoolss server */
32 #define SPOOLSS_BUFFER_UNION(fn,ic,info,level) \
33 ((info)?ndr_size_##fn(info, level, ic, 0):0)
35 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,ic,info,level,count) \
36 ((info)?ndr_size_##fn##_info(mem_ctx, ic, level, count, info):0)
38 #define SPOOLSS_BUFFER_ARRAY(mem_ctx,fn,ic,info,count) \
39 ((info)?ndr_size_##fn##_info(mem_ctx, ic, count, info):0)
41 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
44 extern userdom_struct current_user_info;
46 #undef DBGC_CLASS
47 #define DBGC_CLASS DBGC_RPC_SRV
49 #ifndef MAX_OPEN_PRINTER_EXS
50 #define MAX_OPEN_PRINTER_EXS 50
51 #endif
53 #define MAGIC_DISPLAY_FREQUENCY 0xfade2bad
54 #define PHANTOM_DEVMODE_KEY "_p_f_a_n_t_0_m_"
56 struct table_node {
57 const char *long_archi;
58 const char *short_archi;
59 int version;
62 static Printer_entry *printers_list;
64 typedef struct _counter_printer_0 {
65 struct _counter_printer_0 *next;
66 struct _counter_printer_0 *prev;
68 int snum;
69 uint32_t counter;
70 } counter_printer_0;
72 static counter_printer_0 *counter_list;
74 static struct rpc_pipe_client *notify_cli_pipe; /* print notify back-channel pipe handle*/
75 static uint32_t smb_connections = 0;
78 /* in printing/nt_printing.c */
80 extern struct standard_mapping printer_std_mapping, printserver_std_mapping;
82 /* API table for Xcv Monitor functions */
84 struct xcv_api_table {
85 const char *name;
86 WERROR(*fn) (TALLOC_CTX *mem_ctx, NT_USER_TOKEN *token, DATA_BLOB *in, DATA_BLOB *out, uint32_t *needed);
89 /********************************************************************
90 * Canonicalize servername.
91 ********************************************************************/
93 static const char *canon_servername(const char *servername)
95 const char *pservername = servername;
96 while (*pservername == '\\') {
97 pservername++;
99 return pservername;
102 /* translate between internal status numbers and NT status numbers */
103 static int nt_printj_status(int v)
105 switch (v) {
106 case LPQ_QUEUED:
107 return 0;
108 case LPQ_PAUSED:
109 return JOB_STATUS_PAUSED;
110 case LPQ_SPOOLING:
111 return JOB_STATUS_SPOOLING;
112 case LPQ_PRINTING:
113 return JOB_STATUS_PRINTING;
114 case LPQ_ERROR:
115 return JOB_STATUS_ERROR;
116 case LPQ_DELETING:
117 return JOB_STATUS_DELETING;
118 case LPQ_OFFLINE:
119 return JOB_STATUS_OFFLINE;
120 case LPQ_PAPEROUT:
121 return JOB_STATUS_PAPEROUT;
122 case LPQ_PRINTED:
123 return JOB_STATUS_PRINTED;
124 case LPQ_DELETED:
125 return JOB_STATUS_DELETED;
126 case LPQ_BLOCKED:
127 return JOB_STATUS_BLOCKED_DEVQ;
128 case LPQ_USER_INTERVENTION:
129 return JOB_STATUS_USER_INTERVENTION;
131 return 0;
134 static int nt_printq_status(int v)
136 switch (v) {
137 case LPQ_PAUSED:
138 return PRINTER_STATUS_PAUSED;
139 case LPQ_QUEUED:
140 case LPQ_SPOOLING:
141 case LPQ_PRINTING:
142 return 0;
144 return 0;
147 /***************************************************************************
148 Disconnect from the client
149 ****************************************************************************/
151 static void srv_spoolss_replycloseprinter(int snum, struct policy_handle *handle)
153 WERROR result;
154 NTSTATUS status;
157 * Tell the specific printing tdb we no longer want messages for this printer
158 * by deregistering our PID.
161 if (!print_notify_deregister_pid(snum))
162 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", lp_const_servicename(snum) ));
164 /* weird if the test succeds !!! */
165 if (smb_connections==0) {
166 DEBUG(0,("srv_spoolss_replycloseprinter:Trying to close non-existant notify backchannel !\n"));
167 return;
170 status = rpccli_spoolss_ReplyClosePrinter(notify_cli_pipe, talloc_tos(),
171 handle,
172 &result);
173 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
174 DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed [%s].\n",
175 win_errstr(result)));
177 /* if it's the last connection, deconnect the IPC$ share */
178 if (smb_connections==1) {
180 cli_shutdown( rpc_pipe_np_smb_conn(notify_cli_pipe) );
181 notify_cli_pipe = NULL; /* The above call shuts downn the pipe also. */
183 messaging_deregister(smbd_messaging_context(),
184 MSG_PRINTER_NOTIFY2, NULL);
186 /* Tell the connections db we're no longer interested in
187 * printer notify messages. */
189 register_message_flags(false, FLAG_MSG_PRINT_NOTIFY);
192 smb_connections--;
195 /****************************************************************************
196 Functions to free a printer entry datastruct.
197 ****************************************************************************/
199 static int printer_entry_destructor(Printer_entry *Printer)
201 if (Printer->notify.client_connected == true) {
202 int snum = -1;
204 if ( Printer->printer_type == SPLHND_SERVER) {
205 snum = -1;
206 srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
207 } else if (Printer->printer_type == SPLHND_PRINTER) {
208 snum = print_queue_snum(Printer->sharename);
209 if (snum != -1)
210 srv_spoolss_replycloseprinter(snum,
211 &Printer->notify.client_hnd);
215 Printer->notify.flags=0;
216 Printer->notify.options=0;
217 Printer->notify.localmachine[0]='\0';
218 Printer->notify.printerlocal=0;
219 TALLOC_FREE(Printer->notify.option);
220 Printer->notify.client_connected = false;
222 free_nt_devicemode( &Printer->nt_devmode );
223 free_a_printer( &Printer->printer_info, 2 );
225 /* Remove from the internal list. */
226 DLIST_REMOVE(printers_list, Printer);
227 return 0;
230 /****************************************************************************
231 find printer index by handle
232 ****************************************************************************/
234 static Printer_entry *find_printer_index_by_hnd(pipes_struct *p,
235 struct policy_handle *hnd)
237 Printer_entry *find_printer = NULL;
239 if(!find_policy_by_hnd(p,hnd,(void **)(void *)&find_printer)) {
240 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
241 return NULL;
244 return find_printer;
247 /****************************************************************************
248 Close printer index by handle.
249 ****************************************************************************/
251 static bool close_printer_handle(pipes_struct *p, struct policy_handle *hnd)
253 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
255 if (!Printer) {
256 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n",
257 OUR_HANDLE(hnd)));
258 return false;
261 close_policy_hnd(p, hnd);
263 return true;
266 /****************************************************************************
267 Delete a printer given a handle.
268 ****************************************************************************/
270 WERROR delete_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *sharename )
272 char *cmd = lp_deleteprinter_cmd();
273 char *command = NULL;
274 int ret;
275 SE_PRIV se_printop = SE_PRINT_OPERATOR;
276 bool is_print_op = false;
278 /* can't fail if we don't try */
280 if ( !*cmd )
281 return WERR_OK;
283 command = talloc_asprintf(ctx,
284 "%s \"%s\"",
285 cmd, sharename);
286 if (!command) {
287 return WERR_NOMEM;
289 if ( token )
290 is_print_op = user_has_privileges( token, &se_printop );
292 DEBUG(10,("Running [%s]\n", command));
294 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
296 if ( is_print_op )
297 become_root();
299 if ( (ret = smbrun(command, NULL)) == 0 ) {
300 /* Tell everyone we updated smb.conf. */
301 message_send_all(smbd_messaging_context(),
302 MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
305 if ( is_print_op )
306 unbecome_root();
308 /********** END SePrintOperatorPrivlege BLOCK **********/
310 DEBUGADD(10,("returned [%d]\n", ret));
312 TALLOC_FREE(command);
314 if (ret != 0)
315 return WERR_BADFID; /* What to return here? */
317 /* go ahead and re-read the services immediately */
318 reload_services(false);
320 if ( lp_servicenumber( sharename ) < 0 )
321 return WERR_ACCESS_DENIED;
323 return WERR_OK;
326 /****************************************************************************
327 Delete a printer given a handle.
328 ****************************************************************************/
330 static WERROR delete_printer_handle(pipes_struct *p, struct policy_handle *hnd)
332 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
334 if (!Printer) {
335 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
336 OUR_HANDLE(hnd)));
337 return WERR_BADFID;
341 * It turns out that Windows allows delete printer on a handle
342 * opened by an admin user, then used on a pipe handle created
343 * by an anonymous user..... but they're working on security.... riiight !
344 * JRA.
347 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
348 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
349 return WERR_ACCESS_DENIED;
352 /* this does not need a become root since the access check has been
353 done on the handle already */
355 if (del_a_printer( Printer->sharename ) != 0) {
356 DEBUG(3,("Error deleting printer %s\n", Printer->sharename));
357 return WERR_BADFID;
360 return delete_printer_hook(p->mem_ctx, p->server_info->ptok,
361 Printer->sharename );
364 /****************************************************************************
365 Return the snum of a printer corresponding to an handle.
366 ****************************************************************************/
368 static bool get_printer_snum(pipes_struct *p, struct policy_handle *hnd,
369 int *number, struct share_params **params)
371 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
373 if (!Printer) {
374 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
375 OUR_HANDLE(hnd)));
376 return false;
379 switch (Printer->printer_type) {
380 case SPLHND_PRINTER:
381 DEBUG(4,("short name:%s\n", Printer->sharename));
382 *number = print_queue_snum(Printer->sharename);
383 return (*number != -1);
384 case SPLHND_SERVER:
385 return false;
386 default:
387 return false;
391 /****************************************************************************
392 Set printer handle type.
393 Check if it's \\server or \\server\printer
394 ****************************************************************************/
396 static bool set_printer_hnd_printertype(Printer_entry *Printer, const char *handlename)
398 DEBUG(3,("Setting printer type=%s\n", handlename));
400 if ( strlen(handlename) < 3 ) {
401 DEBUGADD(4,("A print server must have at least 1 char ! %s\n", handlename));
402 return false;
405 /* it's a print server */
406 if (*handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) {
407 DEBUGADD(4,("Printer is a print server\n"));
408 Printer->printer_type = SPLHND_SERVER;
410 /* it's a printer (set_printer_hnd_name() will handle port monitors */
411 else {
412 DEBUGADD(4,("Printer is a printer\n"));
413 Printer->printer_type = SPLHND_PRINTER;
416 return true;
419 /****************************************************************************
420 Set printer handle name.. Accept names like \\server, \\server\printer,
421 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
422 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
423 XcvDataPort() interface.
424 ****************************************************************************/
426 static bool set_printer_hnd_name(Printer_entry *Printer, const char *handlename)
428 int snum;
429 int n_services=lp_numservices();
430 char *aprinter, *printername;
431 const char *servername;
432 fstring sname;
433 bool found = false;
434 NT_PRINTER_INFO_LEVEL *printer = NULL;
435 WERROR result;
437 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename,
438 (unsigned long)strlen(handlename)));
440 aprinter = CONST_DISCARD(char *, handlename);
441 if ( *handlename == '\\' ) {
442 servername = canon_servername(handlename);
443 if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
444 *aprinter = '\0';
445 aprinter++;
447 } else {
448 servername = global_myname();
451 /* save the servername to fill in replies on this handle */
453 if ( !is_myname_or_ipaddr( servername ) )
454 return false;
456 fstrcpy( Printer->servername, servername );
458 if ( Printer->printer_type == SPLHND_SERVER )
459 return true;
461 if ( Printer->printer_type != SPLHND_PRINTER )
462 return false;
464 DEBUGADD(5, ("searching for [%s]\n", aprinter ));
466 /* check for the Port Monitor Interface */
468 if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
469 Printer->printer_type = SPLHND_PORTMON_TCP;
470 fstrcpy(sname, SPL_XCV_MONITOR_TCPMON);
471 found = true;
473 else if ( strequal( aprinter, SPL_XCV_MONITOR_LOCALMON ) ) {
474 Printer->printer_type = SPLHND_PORTMON_LOCAL;
475 fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON);
476 found = true;
479 /* Search all sharenames first as this is easier than pulling
480 the printer_info_2 off of disk. Don't use find_service() since
481 that calls out to map_username() */
483 /* do another loop to look for printernames */
485 for (snum=0; !found && snum<n_services; snum++) {
487 /* no point going on if this is not a printer */
489 if ( !(lp_snum_ok(snum) && lp_print_ok(snum)) )
490 continue;
492 fstrcpy(sname, lp_servicename(snum));
493 if ( strequal( aprinter, sname ) ) {
494 found = true;
495 break;
498 /* no point looking up the printer object if
499 we aren't allowing printername != sharename */
501 if ( lp_force_printername(snum) )
502 continue;
504 fstrcpy(sname, lp_servicename(snum));
506 printer = NULL;
508 /* This call doesn't fill in the location or comment from
509 * a CUPS server for efficiency with large numbers of printers.
510 * JRA.
513 result = get_a_printer_search( NULL, &printer, 2, sname );
514 if ( !W_ERROR_IS_OK(result) ) {
515 DEBUG(0,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
516 sname, win_errstr(result)));
517 continue;
520 /* printername is always returned as \\server\printername */
521 if ( !(printername = strchr_m(&printer->info_2->printername[2], '\\')) ) {
522 DEBUG(0,("set_printer_hnd_name: info2->printername in wrong format! [%s]\n",
523 printer->info_2->printername));
524 free_a_printer( &printer, 2);
525 continue;
528 printername++;
530 if ( strequal(printername, aprinter) ) {
531 free_a_printer( &printer, 2);
532 found = true;
533 break;
536 DEBUGADD(10, ("printername: %s\n", printername));
538 free_a_printer( &printer, 2);
541 free_a_printer( &printer, 2);
543 if ( !found ) {
544 DEBUGADD(4,("Printer not found\n"));
545 return false;
548 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));
550 fstrcpy(Printer->sharename, sname);
552 return true;
555 /****************************************************************************
556 Find first available printer slot. creates a printer handle for you.
557 ****************************************************************************/
559 static bool open_printer_hnd(pipes_struct *p, struct policy_handle *hnd,
560 const char *name, uint32_t access_granted)
562 Printer_entry *new_printer;
564 DEBUG(10,("open_printer_hnd: name [%s]\n", name));
566 new_printer = TALLOC_ZERO_P(NULL, Printer_entry);
567 if (new_printer == NULL) {
568 return false;
570 talloc_set_destructor(new_printer, printer_entry_destructor);
572 if (!create_policy_hnd(p, hnd, new_printer)) {
573 TALLOC_FREE(new_printer);
574 return false;
577 /* Add to the internal list. */
578 DLIST_ADD(printers_list, new_printer);
580 new_printer->notify.option=NULL;
582 if (!set_printer_hnd_printertype(new_printer, name)) {
583 close_printer_handle(p, hnd);
584 return false;
587 if (!set_printer_hnd_name(new_printer, name)) {
588 close_printer_handle(p, hnd);
589 return false;
592 new_printer->access_granted = access_granted;
594 DEBUG(5, ("%d printer handles active\n",
595 (int)num_pipe_handles(p->pipe_handles)));
597 return true;
600 /***************************************************************************
601 check to see if the client motify handle is monitoring the notification
602 given by (notify_type, notify_field).
603 **************************************************************************/
605 static bool is_monitoring_event_flags(uint32_t flags, uint16_t notify_type,
606 uint16_t notify_field)
608 return true;
611 static bool is_monitoring_event(Printer_entry *p, uint16_t notify_type,
612 uint16_t notify_field)
614 struct spoolss_NotifyOption *option = p->notify.option;
615 uint32_t i, j;
618 * Flags should always be zero when the change notify
619 * is registered by the client's spooler. A user Win32 app
620 * might use the flags though instead of the NOTIFY_OPTION_INFO
621 * --jerry
624 if (!option) {
625 return false;
628 if (p->notify.flags)
629 return is_monitoring_event_flags(
630 p->notify.flags, notify_type, notify_field);
632 for (i = 0; i < option->count; i++) {
634 /* Check match for notify_type */
636 if (option->types[i].type != notify_type)
637 continue;
639 /* Check match for field */
641 for (j = 0; j < option->types[i].count; j++) {
642 if (option->types[i].fields[j].field == notify_field) {
643 return true;
648 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
649 p->servername, p->sharename, notify_type, notify_field));
651 return false;
654 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
655 _data->data.integer[0] = _integer; \
656 _data->data.integer[1] = 0;
659 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
660 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
661 if (!_data->data.string.string) {\
662 _data->data.string.size = 0; \
664 _data->data.string.size = strlen_m_term(_p) * 2;
666 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
667 _data->data.devmode.devmode = _devmode;
669 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _size, _sd) \
670 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
671 if (!_data->data.sd.sd) { \
672 _data->data.sd.sd_size = 0; \
674 _data->data.sd.sd_size = _size;
676 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
677 struct tm *t,
678 const char **pp,
679 uint32_t *plen)
681 struct spoolss_Time st;
682 uint32_t len = 16;
683 char *p;
685 if (!init_systemtime(&st, t)) {
686 return;
689 p = talloc_array(mem_ctx, char, len);
690 if (!p) {
691 return;
695 * Systemtime must be linearized as a set of UINT16's.
696 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
699 SSVAL(p, 0, st.year);
700 SSVAL(p, 2, st.month);
701 SSVAL(p, 4, st.day_of_week);
702 SSVAL(p, 6, st.day);
703 SSVAL(p, 8, st.hour);
704 SSVAL(p, 10, st.minute);
705 SSVAL(p, 12, st.second);
706 SSVAL(p, 14, st.millisecond);
708 *pp = p;
709 *plen = len;
712 /* Convert a notification message to a struct spoolss_Notify */
714 static void notify_one_value(struct spoolss_notify_msg *msg,
715 struct spoolss_Notify *data,
716 TALLOC_CTX *mem_ctx)
718 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, msg->notify.value[0]);
721 static void notify_string(struct spoolss_notify_msg *msg,
722 struct spoolss_Notify *data,
723 TALLOC_CTX *mem_ctx)
725 /* The length of the message includes the trailing \0 */
727 data->data.string.size = msg->len * 2;
728 data->data.string.string = talloc_strdup(mem_ctx, msg->notify.data);
729 if (!data->data.string.string) {
730 data->data.string.size = 0;
731 return;
735 static void notify_system_time(struct spoolss_notify_msg *msg,
736 struct spoolss_Notify *data,
737 TALLOC_CTX *mem_ctx)
739 data->data.string.string = NULL;
740 data->data.string.size = 0;
742 if (msg->len != sizeof(time_t)) {
743 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
744 msg->len));
745 return;
748 init_systemtime_buffer(mem_ctx, gmtime((time_t *)msg->notify.data),
749 &data->data.string.string,
750 &data->data.string.size);
753 struct notify2_message_table {
754 const char *name;
755 void (*fn)(struct spoolss_notify_msg *msg,
756 struct spoolss_Notify *data, TALLOC_CTX *mem_ctx);
759 static struct notify2_message_table printer_notify_table[] = {
760 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string },
761 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string },
762 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string },
763 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string },
764 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string },
765 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string },
766 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string },
767 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL },
768 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string },
769 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string },
770 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL },
771 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string },
772 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
773 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value },
774 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value },
775 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL },
776 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL },
777 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL },
778 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value },
781 static struct notify2_message_table job_notify_table[] = {
782 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL },
783 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL },
784 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL },
785 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string },
786 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL },
787 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL },
788 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL },
789 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL },
790 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL },
791 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL },
792 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value },
793 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL },
794 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
795 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string },
796 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL },
797 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL },
798 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time },
799 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL },
800 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL },
801 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL },
802 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value },
803 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL },
804 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value },
805 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL },
809 /***********************************************************************
810 Allocate talloc context for container object
811 **********************************************************************/
813 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
815 if ( !ctr )
816 return;
818 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
820 return;
823 /***********************************************************************
824 release all allocated memory and zero out structure
825 **********************************************************************/
827 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
829 if ( !ctr )
830 return;
832 if ( ctr->ctx )
833 talloc_destroy(ctr->ctx);
835 ZERO_STRUCTP(ctr);
837 return;
840 /***********************************************************************
841 **********************************************************************/
843 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
845 if ( !ctr )
846 return NULL;
848 return ctr->ctx;
851 /***********************************************************************
852 **********************************************************************/
854 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
856 if ( !ctr || !ctr->msg_groups )
857 return NULL;
859 if ( idx >= ctr->num_groups )
860 return NULL;
862 return &ctr->msg_groups[idx];
866 /***********************************************************************
867 How many groups of change messages do we have ?
868 **********************************************************************/
870 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
872 if ( !ctr )
873 return 0;
875 return ctr->num_groups;
878 /***********************************************************************
879 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
880 **********************************************************************/
882 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
884 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
885 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
886 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
887 int i, new_slot;
889 if ( !ctr || !msg )
890 return 0;
892 /* loop over all groups looking for a matching printer name */
894 for ( i=0; i<ctr->num_groups; i++ ) {
895 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
896 break;
899 /* add a new group? */
901 if ( i == ctr->num_groups ) {
902 ctr->num_groups++;
904 if ( !(groups = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
905 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
906 return 0;
908 ctr->msg_groups = groups;
910 /* clear the new entry and set the printer name */
912 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
913 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
916 /* add the change messages; 'i' is the correct index now regardless */
918 msg_grp = &ctr->msg_groups[i];
920 msg_grp->num_msgs++;
922 if ( !(msg_list = TALLOC_REALLOC_ARRAY( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
923 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
924 return 0;
926 msg_grp->msgs = msg_list;
928 new_slot = msg_grp->num_msgs-1;
929 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
931 /* need to allocate own copy of data */
933 if ( msg->len != 0 )
934 msg_grp->msgs[new_slot].notify.data = (char *)
935 TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len );
937 return ctr->num_groups;
940 /***********************************************************************
941 Send a change notication message on all handles which have a call
942 back registered
943 **********************************************************************/
945 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
947 Printer_entry *p;
948 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
949 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
950 SPOOLSS_NOTIFY_MSG *messages;
951 int sending_msg_count;
953 if ( !msg_group ) {
954 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
955 return;
958 messages = msg_group->msgs;
960 if ( !messages ) {
961 DEBUG(5,("send_notify2_changes() called with no messages!\n"));
962 return;
965 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
967 /* loop over all printers */
969 for (p = printers_list; p; p = p->next) {
970 struct spoolss_Notify *notifies;
971 uint32_t count = 0;
972 uint32_t id;
973 int i;
975 /* Is there notification on this handle? */
977 if ( !p->notify.client_connected )
978 continue;
980 DEBUG(10,("Client connected! [\\\\%s\\%s]\n", p->servername, p->sharename));
982 /* For this printer? Print servers always receive
983 notifications. */
985 if ( ( p->printer_type == SPLHND_PRINTER ) &&
986 ( !strequal(msg_group->printername, p->sharename) ) )
987 continue;
989 DEBUG(10,("Our printer\n"));
991 /* allocate the max entries possible */
993 notifies = TALLOC_ZERO_ARRAY(mem_ctx, struct spoolss_Notify, msg_group->num_msgs);
994 if (!notifies) {
995 return;
998 /* build the array of change notifications */
1000 sending_msg_count = 0;
1002 for ( i=0; i<msg_group->num_msgs; i++ ) {
1003 SPOOLSS_NOTIFY_MSG *msg = &messages[i];
1005 /* Are we monitoring this event? */
1007 if (!is_monitoring_event(p, msg->type, msg->field))
1008 continue;
1010 sending_msg_count++;
1013 DEBUG(10,("process_notify2_message: Sending message type [0x%x] field [0x%2x] for printer [%s]\n",
1014 msg->type, msg->field, p->sharename));
1017 * if the is a printer notification handle and not a job notification
1018 * type, then set the id to 0. Other wise just use what was specified
1019 * in the message.
1021 * When registering change notification on a print server handle
1022 * we always need to send back the id (snum) matching the printer
1023 * for which the change took place. For change notify registered
1024 * on a printer handle, this does not matter and the id should be 0.
1026 * --jerry
1029 if ( ( p->printer_type == SPLHND_PRINTER ) && ( msg->type == PRINTER_NOTIFY_TYPE ) )
1030 id = 0;
1031 else
1032 id = msg->id;
1035 /* Convert unix jobid to smb jobid */
1037 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1038 id = sysjob_to_jobid(msg->id);
1040 if (id == -1) {
1041 DEBUG(3, ("no such unix jobid %d\n", msg->id));
1042 goto done;
1046 construct_info_data( &notifies[count], msg->type, msg->field, id );
1048 switch(msg->type) {
1049 case PRINTER_NOTIFY_TYPE:
1050 if ( printer_notify_table[msg->field].fn )
1051 printer_notify_table[msg->field].fn(msg, &notifies[count], mem_ctx);
1052 break;
1054 case JOB_NOTIFY_TYPE:
1055 if ( job_notify_table[msg->field].fn )
1056 job_notify_table[msg->field].fn(msg, &notifies[count], mem_ctx);
1057 break;
1059 default:
1060 DEBUG(5, ("Unknown notification type %d\n", msg->type));
1061 goto done;
1064 count++;
1067 if ( sending_msg_count ) {
1068 NTSTATUS status;
1069 WERROR werr;
1070 union spoolss_ReplyPrinterInfo info;
1071 struct spoolss_NotifyInfo info0;
1072 uint32_t reply_result;
1074 info0.version = 0x2;
1075 info0.flags = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
1076 info0.count = count;
1077 info0.notifies = notifies;
1079 info.info0 = &info0;
1081 status = rpccli_spoolss_RouterReplyPrinterEx(notify_cli_pipe, mem_ctx,
1082 &p->notify.client_hnd,
1083 p->notify.change, /* color */
1084 p->notify.flags,
1085 &reply_result,
1086 0, /* reply_type, must be 0 */
1087 info,
1088 &werr);
1089 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) {
1090 DEBUG(1,("RouterReplyPrinterEx to client: %s failed: %s\n",
1091 notify_cli_pipe->srv_name_slash,
1092 win_errstr(werr)));
1094 switch (reply_result) {
1095 case 0:
1096 break;
1097 case PRINTER_NOTIFY_INFO_DISCARDED:
1098 case PRINTER_NOTIFY_INFO_DISCARDNOTED:
1099 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
1100 break;
1101 default:
1102 break;
1107 done:
1108 DEBUG(8,("send_notify2_changes: Exit...\n"));
1109 return;
1112 /***********************************************************************
1113 **********************************************************************/
1115 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1118 uint32_t tv_sec, tv_usec;
1119 size_t offset = 0;
1121 /* Unpack message */
1123 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "f",
1124 msg->printer);
1126 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "ddddddd",
1127 &tv_sec, &tv_usec,
1128 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1130 if (msg->len == 0)
1131 tdb_unpack((uint8_t *)buf + offset, len - offset, "dd",
1132 &msg->notify.value[0], &msg->notify.value[1]);
1133 else
1134 tdb_unpack((uint8_t *)buf + offset, len - offset, "B",
1135 &msg->len, &msg->notify.data);
1137 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1138 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1140 tv->tv_sec = tv_sec;
1141 tv->tv_usec = tv_usec;
1143 if (msg->len == 0)
1144 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1145 msg->notify.value[1]));
1146 else
1147 dump_data(3, (uint8_t *)msg->notify.data, msg->len);
1149 return true;
1152 /********************************************************************
1153 Receive a notify2 message list
1154 ********************************************************************/
1156 static void receive_notify2_message_list(struct messaging_context *msg,
1157 void *private_data,
1158 uint32_t msg_type,
1159 struct server_id server_id,
1160 DATA_BLOB *data)
1162 size_t msg_count, i;
1163 char *buf = (char *)data->data;
1164 char *msg_ptr;
1165 size_t msg_len;
1166 SPOOLSS_NOTIFY_MSG notify;
1167 SPOOLSS_NOTIFY_MSG_CTR messages;
1168 int num_groups;
1170 if (data->length < 4) {
1171 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1172 return;
1175 msg_count = IVAL(buf, 0);
1176 msg_ptr = buf + 4;
1178 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1180 if (msg_count == 0) {
1181 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1182 return;
1185 /* initialize the container */
1187 ZERO_STRUCT( messages );
1188 notify_msg_ctr_init( &messages );
1191 * build message groups for each printer identified
1192 * in a change_notify msg. Remember that a PCN message
1193 * includes the handle returned for the srv_spoolss_replyopenprinter()
1194 * call. Therefore messages are grouped according to printer handle.
1197 for ( i=0; i<msg_count; i++ ) {
1198 struct timeval msg_tv;
1200 if (msg_ptr + 4 - buf > data->length) {
1201 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1202 return;
1205 msg_len = IVAL(msg_ptr,0);
1206 msg_ptr += 4;
1208 if (msg_ptr + msg_len - buf > data->length) {
1209 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1210 return;
1213 /* unpack messages */
1215 ZERO_STRUCT( notify );
1216 notify2_unpack_msg( &notify, &msg_tv, msg_ptr, msg_len );
1217 msg_ptr += msg_len;
1219 /* add to correct list in container */
1221 notify_msg_ctr_addmsg( &messages, &notify );
1223 /* free memory that might have been allocated by notify2_unpack_msg() */
1225 if ( notify.len != 0 )
1226 SAFE_FREE( notify.notify.data );
1229 /* process each group of messages */
1231 num_groups = notify_msg_ctr_numgroups( &messages );
1232 for ( i=0; i<num_groups; i++ )
1233 send_notify2_changes( &messages, i );
1236 /* cleanup */
1238 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1239 (uint32_t)msg_count ));
1241 notify_msg_ctr_destroy( &messages );
1243 return;
1246 /********************************************************************
1247 Send a message to ourself about new driver being installed
1248 so we can upgrade the information for each printer bound to this
1249 driver
1250 ********************************************************************/
1252 static bool srv_spoolss_drv_upgrade_printer(const char *drivername)
1254 int len = strlen(drivername);
1256 if (!len)
1257 return false;
1259 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1260 drivername));
1262 messaging_send_buf(smbd_messaging_context(), procid_self(),
1263 MSG_PRINTER_DRVUPGRADE,
1264 (uint8_t *)drivername, len+1);
1266 return true;
1269 /**********************************************************************
1270 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1271 over all printers, upgrading ones as necessary
1272 **********************************************************************/
1274 void do_drv_upgrade_printer(struct messaging_context *msg,
1275 void *private_data,
1276 uint32_t msg_type,
1277 struct server_id server_id,
1278 DATA_BLOB *data)
1280 fstring drivername;
1281 int snum;
1282 int n_services = lp_numservices();
1283 size_t len;
1285 len = MIN(data->length,sizeof(drivername)-1);
1286 strncpy(drivername, (const char *)data->data, len);
1288 DEBUG(10,("do_drv_upgrade_printer: Got message for new driver [%s]\n", drivername ));
1290 /* Iterate the printer list */
1292 for (snum=0; snum<n_services; snum++)
1294 if (lp_snum_ok(snum) && lp_print_ok(snum) )
1296 WERROR result;
1297 NT_PRINTER_INFO_LEVEL *printer = NULL;
1299 result = get_a_printer(NULL, &printer, 2, lp_const_servicename(snum));
1300 if (!W_ERROR_IS_OK(result))
1301 continue;
1303 if (printer && printer->info_2 && !strcmp(drivername, printer->info_2->drivername))
1305 DEBUG(6,("Updating printer [%s]\n", printer->info_2->printername));
1307 /* all we care about currently is the change_id */
1309 result = mod_a_printer(printer, 2);
1310 if (!W_ERROR_IS_OK(result)) {
1311 DEBUG(3,("do_drv_upgrade_printer: mod_a_printer() failed with status [%s]\n",
1312 win_errstr(result)));
1316 free_a_printer(&printer, 2);
1320 /* all done */
1323 /********************************************************************
1324 Update the cache for all printq's with a registered client
1325 connection
1326 ********************************************************************/
1328 void update_monitored_printq_cache( void )
1330 Printer_entry *printer = printers_list;
1331 int snum;
1333 /* loop through all printers and update the cache where
1334 client_connected == true */
1335 while ( printer )
1337 if ( (printer->printer_type == SPLHND_PRINTER)
1338 && printer->notify.client_connected )
1340 snum = print_queue_snum(printer->sharename);
1341 print_queue_status( snum, NULL, NULL );
1344 printer = printer->next;
1347 return;
1349 /********************************************************************
1350 Send a message to ourself about new driver being installed
1351 so we can upgrade the information for each printer bound to this
1352 driver
1353 ********************************************************************/
1355 static bool srv_spoolss_reset_printerdata(char* drivername)
1357 int len = strlen(drivername);
1359 if (!len)
1360 return false;
1362 DEBUG(10,("srv_spoolss_reset_printerdata: Sending message about resetting printerdata [%s]\n",
1363 drivername));
1365 messaging_send_buf(smbd_messaging_context(), procid_self(),
1366 MSG_PRINTERDATA_INIT_RESET,
1367 (uint8_t *)drivername, len+1);
1369 return true;
1372 /**********************************************************************
1373 callback to receive a MSG_PRINTERDATA_INIT_RESET message and interate
1374 over all printers, resetting printer data as neessary
1375 **********************************************************************/
1377 void reset_all_printerdata(struct messaging_context *msg,
1378 void *private_data,
1379 uint32_t msg_type,
1380 struct server_id server_id,
1381 DATA_BLOB *data)
1383 fstring drivername;
1384 int snum;
1385 int n_services = lp_numservices();
1386 size_t len;
1388 len = MIN( data->length, sizeof(drivername)-1 );
1389 strncpy( drivername, (const char *)data->data, len );
1391 DEBUG(10,("reset_all_printerdata: Got message for new driver [%s]\n", drivername ));
1393 /* Iterate the printer list */
1395 for ( snum=0; snum<n_services; snum++ )
1397 if ( lp_snum_ok(snum) && lp_print_ok(snum) )
1399 WERROR result;
1400 NT_PRINTER_INFO_LEVEL *printer = NULL;
1402 result = get_a_printer( NULL, &printer, 2, lp_const_servicename(snum) );
1403 if ( !W_ERROR_IS_OK(result) )
1404 continue;
1407 * if the printer is bound to the driver,
1408 * then reset to the new driver initdata
1411 if ( printer && printer->info_2 && !strcmp(drivername, printer->info_2->drivername) )
1413 DEBUG(6,("reset_all_printerdata: Updating printer [%s]\n", printer->info_2->printername));
1415 if ( !set_driver_init(printer, 2) ) {
1416 DEBUG(5,("reset_all_printerdata: Error resetting printer data for printer [%s], driver [%s]!\n",
1417 printer->info_2->printername, printer->info_2->drivername));
1420 result = mod_a_printer( printer, 2 );
1421 if ( !W_ERROR_IS_OK(result) ) {
1422 DEBUG(3,("reset_all_printerdata: mod_a_printer() failed! (%s)\n",
1423 get_dos_error_msg(result)));
1427 free_a_printer( &printer, 2 );
1431 /* all done */
1433 return;
1436 /****************************************************************
1437 _spoolss_OpenPrinter
1438 ****************************************************************/
1440 WERROR _spoolss_OpenPrinter(pipes_struct *p,
1441 struct spoolss_OpenPrinter *r)
1443 struct spoolss_OpenPrinterEx e;
1444 WERROR werr;
1446 ZERO_STRUCT(e.in.userlevel);
1448 e.in.printername = r->in.printername;
1449 e.in.datatype = r->in.datatype;
1450 e.in.devmode_ctr = r->in.devmode_ctr;
1451 e.in.access_mask = r->in.access_mask;
1452 e.in.level = 0;
1454 e.out.handle = r->out.handle;
1456 werr = _spoolss_OpenPrinterEx(p, &e);
1458 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1459 /* OpenPrinterEx returns this for a bad
1460 * printer name. We must return WERR_INVALID_PRINTER_NAME
1461 * instead.
1463 werr = WERR_INVALID_PRINTER_NAME;
1466 return werr;
1469 /********************************************************************
1470 ********************************************************************/
1472 bool convert_devicemode(const char *printername,
1473 const struct spoolss_DeviceMode *devmode,
1474 NT_DEVICEMODE **pp_nt_devmode)
1476 NT_DEVICEMODE *nt_devmode = *pp_nt_devmode;
1479 * Ensure nt_devmode is a valid pointer
1480 * as we will be overwriting it.
1483 if (nt_devmode == NULL) {
1484 DEBUG(5, ("convert_devicemode: allocating a generic devmode\n"));
1485 if ((nt_devmode = construct_nt_devicemode(printername)) == NULL)
1486 return false;
1489 rpcstr_push(nt_devmode->devicename, devmode->devicename, 31, 0);
1490 rpcstr_push(nt_devmode->formname, devmode->formname, 31, 0);
1492 nt_devmode->specversion = devmode->specversion;
1493 nt_devmode->driverversion = devmode->driverversion;
1494 nt_devmode->size = devmode->size;
1495 nt_devmode->fields = devmode->fields;
1496 nt_devmode->orientation = devmode->orientation;
1497 nt_devmode->papersize = devmode->papersize;
1498 nt_devmode->paperlength = devmode->paperlength;
1499 nt_devmode->paperwidth = devmode->paperwidth;
1500 nt_devmode->scale = devmode->scale;
1501 nt_devmode->copies = devmode->copies;
1502 nt_devmode->defaultsource = devmode->defaultsource;
1503 nt_devmode->printquality = devmode->printquality;
1504 nt_devmode->color = devmode->color;
1505 nt_devmode->duplex = devmode->duplex;
1506 nt_devmode->yresolution = devmode->yresolution;
1507 nt_devmode->ttoption = devmode->ttoption;
1508 nt_devmode->collate = devmode->collate;
1510 nt_devmode->logpixels = devmode->logpixels;
1511 nt_devmode->bitsperpel = devmode->bitsperpel;
1512 nt_devmode->pelswidth = devmode->pelswidth;
1513 nt_devmode->pelsheight = devmode->pelsheight;
1514 nt_devmode->displayflags = devmode->displayflags;
1515 nt_devmode->displayfrequency = devmode->displayfrequency;
1516 nt_devmode->icmmethod = devmode->icmmethod;
1517 nt_devmode->icmintent = devmode->icmintent;
1518 nt_devmode->mediatype = devmode->mediatype;
1519 nt_devmode->dithertype = devmode->dithertype;
1520 nt_devmode->reserved1 = devmode->reserved1;
1521 nt_devmode->reserved2 = devmode->reserved2;
1522 nt_devmode->panningwidth = devmode->panningwidth;
1523 nt_devmode->panningheight = devmode->panningheight;
1526 * Only change private and driverextra if the incoming devmode
1527 * has a new one. JRA.
1530 if ((devmode->__driverextra_length != 0) && (devmode->driverextra_data.data != NULL)) {
1531 SAFE_FREE(nt_devmode->nt_dev_private);
1532 nt_devmode->driverextra = devmode->__driverextra_length;
1533 if((nt_devmode->nt_dev_private = SMB_MALLOC_ARRAY(uint8_t, nt_devmode->driverextra)) == NULL)
1534 return false;
1535 memcpy(nt_devmode->nt_dev_private, devmode->driverextra_data.data, nt_devmode->driverextra);
1538 *pp_nt_devmode = nt_devmode;
1540 return true;
1543 /****************************************************************
1544 _spoolss_OpenPrinterEx
1545 ****************************************************************/
1547 WERROR _spoolss_OpenPrinterEx(pipes_struct *p,
1548 struct spoolss_OpenPrinterEx *r)
1550 int snum;
1551 Printer_entry *Printer=NULL;
1553 if (!r->in.printername) {
1554 return WERR_INVALID_PARAM;
1557 /* some sanity check because you can open a printer or a print server */
1558 /* aka: \\server\printer or \\server */
1560 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1562 if (!open_printer_hnd(p, r->out.handle, r->in.printername, 0)) {
1563 ZERO_STRUCTP(r->out.handle);
1564 return WERR_INVALID_PARAM;
1567 Printer = find_printer_index_by_hnd(p, r->out.handle);
1568 if ( !Printer ) {
1569 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1570 "handle we created for printer %s\n", r->in.printername));
1571 close_printer_handle(p, r->out.handle);
1572 ZERO_STRUCTP(r->out.handle);
1573 return WERR_INVALID_PARAM;
1577 * First case: the user is opening the print server:
1579 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1580 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1582 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1583 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1584 * or if the user is listed in the smb.conf printer admin parameter.
1586 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1587 * client view printer folder, but does not show the MSAPW.
1589 * Note: this test needs code to check access rights here too. Jeremy
1590 * could you look at this?
1592 * Second case: the user is opening a printer:
1593 * NT doesn't let us connect to a printer if the connecting user
1594 * doesn't have print permission.
1596 * Third case: user is opening a Port Monitor
1597 * access checks same as opening a handle to the print server.
1600 switch (Printer->printer_type )
1602 case SPLHND_SERVER:
1603 case SPLHND_PORTMON_TCP:
1604 case SPLHND_PORTMON_LOCAL:
1605 /* Printserver handles use global struct... */
1607 snum = -1;
1609 /* Map standard access rights to object specific access rights */
1611 se_map_standard(&r->in.access_mask,
1612 &printserver_std_mapping);
1614 /* Deny any object specific bits that don't apply to print
1615 servers (i.e printer and job specific bits) */
1617 r->in.access_mask &= SPECIFIC_RIGHTS_MASK;
1619 if (r->in.access_mask &
1620 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1621 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1622 close_printer_handle(p, r->out.handle);
1623 ZERO_STRUCTP(r->out.handle);
1624 return WERR_ACCESS_DENIED;
1627 /* Allow admin access */
1629 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1631 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1633 if (!lp_ms_add_printer_wizard()) {
1634 close_printer_handle(p, r->out.handle);
1635 ZERO_STRUCTP(r->out.handle);
1636 return WERR_ACCESS_DENIED;
1639 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1640 and not a printer admin, then fail */
1642 if ((p->server_info->utok.uid != 0) &&
1643 !user_has_privileges(p->server_info->ptok,
1644 &se_printop ) &&
1645 !token_contains_name_in_list(
1646 uidtoname(p->server_info->utok.uid),
1647 NULL, NULL,
1648 p->server_info->ptok,
1649 lp_printer_admin(snum))) {
1650 close_printer_handle(p, r->out.handle);
1651 ZERO_STRUCTP(r->out.handle);
1652 return WERR_ACCESS_DENIED;
1655 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1657 else
1659 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1662 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1663 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1665 /* We fall through to return WERR_OK */
1666 break;
1668 case SPLHND_PRINTER:
1669 /* NT doesn't let us connect to a printer if the connecting user
1670 doesn't have print permission. */
1672 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1673 close_printer_handle(p, r->out.handle);
1674 ZERO_STRUCTP(r->out.handle);
1675 return WERR_BADFID;
1678 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1680 /* map an empty access mask to the minimum access mask */
1681 if (r->in.access_mask == 0x0)
1682 r->in.access_mask = PRINTER_ACCESS_USE;
1685 * If we are not serving the printer driver for this printer,
1686 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1687 * will keep NT clients happy --jerry
1690 if (lp_use_client_driver(snum)
1691 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1693 r->in.access_mask = PRINTER_ACCESS_USE;
1696 /* check smb.conf parameters and the the sec_desc */
1698 if ( !check_access(get_client_fd(), lp_hostsallow(snum), lp_hostsdeny(snum)) ) {
1699 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1700 ZERO_STRUCTP(r->out.handle);
1701 return WERR_ACCESS_DENIED;
1704 if (!user_ok_token(uidtoname(p->server_info->utok.uid), NULL,
1705 p->server_info->ptok, snum) ||
1706 !print_access_check(p->server_info, snum,
1707 r->in.access_mask)) {
1708 DEBUG(3, ("access DENIED for printer open\n"));
1709 close_printer_handle(p, r->out.handle);
1710 ZERO_STRUCTP(r->out.handle);
1711 return WERR_ACCESS_DENIED;
1714 if ((r->in.access_mask & SPECIFIC_RIGHTS_MASK)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1715 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1716 close_printer_handle(p, r->out.handle);
1717 ZERO_STRUCTP(r->out.handle);
1718 return WERR_ACCESS_DENIED;
1721 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1722 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1723 else
1724 r->in.access_mask = PRINTER_ACCESS_USE;
1726 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1727 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1729 break;
1731 default:
1732 /* sanity check to prevent programmer error */
1733 ZERO_STRUCTP(r->out.handle);
1734 return WERR_BADFID;
1737 Printer->access_granted = r->in.access_mask;
1740 * If the client sent a devmode in the OpenPrinter() call, then
1741 * save it here in case we get a job submission on this handle
1744 if ((Printer->printer_type != SPLHND_SERVER) &&
1745 r->in.devmode_ctr.devmode) {
1746 convert_devicemode(Printer->sharename,
1747 r->in.devmode_ctr.devmode,
1748 &Printer->nt_devmode);
1751 #if 0 /* JERRY -- I'm doubtful this is really effective */
1752 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1753 optimization in Windows 2000 clients --jerry */
1755 if ( (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1756 && (RA_WIN2K == get_remote_arch()) )
1758 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1759 sys_usleep( 500000 );
1761 #endif
1763 return WERR_OK;
1766 /****************************************************************************
1767 ****************************************************************************/
1769 static bool printer_info2_to_nt_printer_info2(struct spoolss_SetPrinterInfo2 *r,
1770 NT_PRINTER_INFO_LEVEL_2 *d)
1772 DEBUG(7,("printer_info2_to_nt_printer_info2\n"));
1774 if (!r || !d) {
1775 return false;
1778 d->attributes = r->attributes;
1779 d->priority = r->priority;
1780 d->default_priority = r->defaultpriority;
1781 d->starttime = r->starttime;
1782 d->untiltime = r->untiltime;
1783 d->status = r->status;
1784 d->cjobs = r->cjobs;
1786 fstrcpy(d->servername, r->servername);
1787 fstrcpy(d->printername, r->printername);
1788 fstrcpy(d->sharename, r->sharename);
1789 fstrcpy(d->portname, r->portname);
1790 fstrcpy(d->drivername, r->drivername);
1791 slprintf(d->comment, sizeof(d->comment)-1, "%s", r->comment);
1792 fstrcpy(d->location, r->location);
1793 fstrcpy(d->sepfile, r->sepfile);
1794 fstrcpy(d->printprocessor, r->printprocessor);
1795 fstrcpy(d->datatype, r->datatype);
1796 fstrcpy(d->parameters, r->parameters);
1798 return true;
1801 /****************************************************************************
1802 ****************************************************************************/
1804 static bool convert_printer_info(struct spoolss_SetPrinterInfoCtr *info_ctr,
1805 NT_PRINTER_INFO_LEVEL *printer)
1807 bool ret;
1809 switch (info_ctr->level) {
1810 case 2:
1811 /* allocate memory if needed. Messy because
1812 convert_printer_info is used to update an existing
1813 printer or build a new one */
1815 if (!printer->info_2) {
1816 printer->info_2 = TALLOC_ZERO_P(printer, NT_PRINTER_INFO_LEVEL_2);
1817 if (!printer->info_2) {
1818 DEBUG(0,("convert_printer_info: "
1819 "talloc() failed!\n"));
1820 return false;
1824 ret = printer_info2_to_nt_printer_info2(info_ctr->info.info2,
1825 printer->info_2);
1826 printer->info_2->setuptime = time(NULL);
1827 return ret;
1830 return false;
1833 /*******************************************************************
1834 ********************************************************************/
1836 static bool string_array_to_fstring_array(const char **sarray, fstring **farray)
1838 int i;
1840 if (!sarray) {
1841 *farray = NULL;
1842 return true;
1845 *farray = SMB_MALLOC_ARRAY(fstring, 1);
1846 if (!*farray) {
1847 return false;
1850 for (i=0; sarray[i] != NULL; i++) {
1851 *farray = SMB_REALLOC_ARRAY(*farray, fstring, i+2);
1852 if (!*farray) {
1853 return false;
1855 fstrcpy((*farray)[i], sarray[i]);
1858 fstrcpy((*farray)[i], "");
1860 return true;
1863 /*******************************************************************
1864 ********************************************************************/
1866 static bool driver_info3_to_nt_driver_info3(struct spoolss_AddDriverInfo3 *r,
1867 NT_PRINTER_DRIVER_INFO_LEVEL_3 **p)
1869 NT_PRINTER_DRIVER_INFO_LEVEL_3 *d;
1871 DEBUG(7,("driver_info3_to_nt_driver_info3: Converting from UNICODE to ASCII\n"));
1873 if (*p == NULL) {
1874 *p = SMB_MALLOC_P(NT_PRINTER_DRIVER_INFO_LEVEL_3);
1875 if (*p == NULL) {
1876 return false;
1878 ZERO_STRUCTP(*p);
1881 d = *p;
1883 d->cversion = r->version;
1885 fstrcpy(d->name, r->driver_name);
1886 fstrcpy(d->environment, r->architecture);
1887 fstrcpy(d->driverpath, r->driver_path);
1888 fstrcpy(d->datafile, r->data_file);
1889 fstrcpy(d->configfile, r->config_file);
1890 fstrcpy(d->helpfile, r->help_file);
1891 fstrcpy(d->monitorname, r->monitor_name);
1892 fstrcpy(d->defaultdatatype, r->default_datatype);
1894 DEBUGADD(8,( "version: %d\n", d->cversion));
1895 DEBUGADD(8,( "name: %s\n", d->name));
1896 DEBUGADD(8,( "environment: %s\n", d->environment));
1897 DEBUGADD(8,( "driverpath: %s\n", d->driverpath));
1898 DEBUGADD(8,( "datafile: %s\n", d->datafile));
1899 DEBUGADD(8,( "configfile: %s\n", d->configfile));
1900 DEBUGADD(8,( "helpfile: %s\n", d->helpfile));
1901 DEBUGADD(8,( "monitorname: %s\n", d->monitorname));
1902 DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
1904 if (r->dependent_files) {
1905 if (!string_array_to_fstring_array(r->dependent_files->string,
1906 &d->dependentfiles)) {
1907 SAFE_FREE(*p);
1908 return false;
1912 return true;
1915 /*******************************************************************
1916 ********************************************************************/
1918 static bool driver_info6_to_nt_driver_info6(struct spoolss_AddDriverInfo6 *r,
1919 NT_PRINTER_DRIVER_INFO_LEVEL_6 **p)
1921 NT_PRINTER_DRIVER_INFO_LEVEL_6 *d;
1923 DEBUG(7,("driver_info6_to_nt_driver_info6: Converting from UNICODE to ASCII\n"));
1925 if (*p == NULL) {
1926 *p = SMB_MALLOC_P(NT_PRINTER_DRIVER_INFO_LEVEL_6);
1927 if (*p == NULL) {
1928 return false;
1930 ZERO_STRUCTP(*p);
1933 d = *p;
1935 d->version = r->version;
1937 fstrcpy(d->name, r->driver_name);
1938 fstrcpy(d->environment, r->architecture);
1939 fstrcpy(d->driverpath, r->driver_path);
1940 fstrcpy(d->datafile, r->data_file);
1941 fstrcpy(d->configfile, r->config_file);
1942 fstrcpy(d->helpfile, r->help_file);
1943 fstrcpy(d->monitorname, r->monitor_name);
1944 fstrcpy(d->defaultdatatype, r->default_datatype);
1946 DEBUGADD(8,( "version: %d\n", d->version));
1947 DEBUGADD(8,( "name: %s\n", d->name));
1948 DEBUGADD(8,( "environment: %s\n", d->environment));
1949 DEBUGADD(8,( "driverpath: %s\n", d->driverpath));
1950 DEBUGADD(8,( "datafile: %s\n", d->datafile));
1951 DEBUGADD(8,( "configfile: %s\n", d->configfile));
1952 DEBUGADD(8,( "helpfile: %s\n", d->helpfile));
1953 DEBUGADD(8,( "monitorname: %s\n", d->monitorname));
1954 DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
1956 if (r->dependent_files) {
1957 if (!string_array_to_fstring_array(r->dependent_files->string,
1958 &d->dependentfiles)) {
1959 goto error;
1963 if (r->previous_names) {
1964 if (!string_array_to_fstring_array(r->previous_names->string,
1965 &d->previousnames)) {
1966 goto error;
1970 return true;
1972 error:
1973 SAFE_FREE(*p);
1974 return false;
1977 /********************************************************************
1978 ********************************************************************/
1980 static bool convert_printer_driver_info(const struct spoolss_AddDriverInfoCtr *r,
1981 NT_PRINTER_DRIVER_INFO_LEVEL *printer,
1982 uint32_t level)
1984 switch (level) {
1985 case 3:
1986 printer->info_3 = NULL;
1987 if (!driver_info3_to_nt_driver_info3(r->info.info3, &printer->info_3)) {
1988 return false;
1990 break;
1991 case 6:
1992 printer->info_6 = NULL;
1993 if (!driver_info6_to_nt_driver_info6(r->info.info6, &printer->info_6)) {
1994 return false;
1996 break;
1997 default:
1998 return false;
2001 return true;
2004 /********************************************************************
2005 * _spoolss_enddocprinter_internal.
2006 ********************************************************************/
2008 static WERROR _spoolss_enddocprinter_internal(pipes_struct *p,
2009 struct policy_handle *handle)
2011 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
2012 int snum;
2014 if (!Printer) {
2015 DEBUG(2,("_spoolss_enddocprinter_internal: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle)));
2016 return WERR_BADFID;
2019 if (!get_printer_snum(p, handle, &snum, NULL))
2020 return WERR_BADFID;
2022 Printer->document_started = false;
2023 print_job_end(snum, Printer->jobid,NORMAL_CLOSE);
2024 /* error codes unhandled so far ... */
2026 return WERR_OK;
2029 /****************************************************************
2030 _spoolss_ClosePrinter
2031 ****************************************************************/
2033 WERROR _spoolss_ClosePrinter(pipes_struct *p,
2034 struct spoolss_ClosePrinter *r)
2036 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
2038 if (Printer && Printer->document_started)
2039 _spoolss_enddocprinter_internal(p, r->in.handle); /* print job was not closed */
2041 if (!close_printer_handle(p, r->in.handle))
2042 return WERR_BADFID;
2044 /* clear the returned printer handle. Observed behavior
2045 from Win2k server. Don't think this really matters.
2046 Previous code just copied the value of the closed
2047 handle. --jerry */
2049 ZERO_STRUCTP(r->out.handle);
2051 return WERR_OK;
2054 /****************************************************************
2055 _spoolss_DeletePrinter
2056 ****************************************************************/
2058 WERROR _spoolss_DeletePrinter(pipes_struct *p,
2059 struct spoolss_DeletePrinter *r)
2061 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
2062 WERROR result;
2064 if (Printer && Printer->document_started)
2065 _spoolss_enddocprinter_internal(p, r->in.handle); /* print job was not closed */
2067 result = delete_printer_handle(p, r->in.handle);
2069 update_c_setprinter(false);
2071 return result;
2074 /*******************************************************************
2075 * static function to lookup the version id corresponding to an
2076 * long architecture string
2077 ******************************************************************/
2079 static int get_version_id(const char *arch)
2081 int i;
2082 struct table_node archi_table[]= {
2084 {"Windows 4.0", "WIN40", 0 },
2085 {"Windows NT x86", "W32X86", 2 },
2086 {"Windows NT R4000", "W32MIPS", 2 },
2087 {"Windows NT Alpha_AXP", "W32ALPHA", 2 },
2088 {"Windows NT PowerPC", "W32PPC", 2 },
2089 {"Windows IA64", "IA64", 3 },
2090 {"Windows x64", "x64", 3 },
2091 {NULL, "", -1 }
2094 for (i=0; archi_table[i].long_archi != NULL; i++)
2096 if (strcmp(arch, archi_table[i].long_archi) == 0)
2097 return (archi_table[i].version);
2100 return -1;
2103 /****************************************************************
2104 _spoolss_DeletePrinterDriver
2105 ****************************************************************/
2107 WERROR _spoolss_DeletePrinterDriver(pipes_struct *p,
2108 struct spoolss_DeletePrinterDriver *r)
2110 NT_PRINTER_DRIVER_INFO_LEVEL info;
2111 NT_PRINTER_DRIVER_INFO_LEVEL info_win2k;
2112 int version;
2113 WERROR status;
2114 WERROR status_win2k = WERR_ACCESS_DENIED;
2115 SE_PRIV se_printop = SE_PRINT_OPERATOR;
2117 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2118 and not a printer admin, then fail */
2120 if ( (p->server_info->utok.uid != 0)
2121 && !user_has_privileges(p->server_info->ptok, &se_printop )
2122 && !token_contains_name_in_list(
2123 uidtoname(p->server_info->utok.uid), NULL,
2124 NULL, p->server_info->ptok,
2125 lp_printer_admin(-1)) )
2127 return WERR_ACCESS_DENIED;
2130 /* check that we have a valid driver name first */
2132 if ((version = get_version_id(r->in.architecture)) == -1)
2133 return WERR_INVALID_ENVIRONMENT;
2135 ZERO_STRUCT(info);
2136 ZERO_STRUCT(info_win2k);
2138 if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, r->in.driver,
2139 r->in.architecture,
2140 version)))
2142 /* try for Win2k driver if "Windows NT x86" */
2144 if ( version == 2 ) {
2145 version = 3;
2146 if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3,
2147 r->in.driver,
2148 r->in.architecture,
2149 version))) {
2150 status = WERR_UNKNOWN_PRINTER_DRIVER;
2151 goto done;
2154 /* otherwise it was a failure */
2155 else {
2156 status = WERR_UNKNOWN_PRINTER_DRIVER;
2157 goto done;
2162 if (printer_driver_in_use(info.info_3)) {
2163 status = WERR_PRINTER_DRIVER_IN_USE;
2164 goto done;
2167 if ( version == 2 )
2169 if (W_ERROR_IS_OK(get_a_printer_driver(&info_win2k, 3,
2170 r->in.driver,
2171 r->in.architecture, 3)))
2173 /* if we get to here, we now have 2 driver info structures to remove */
2174 /* remove the Win2k driver first*/
2176 status_win2k = delete_printer_driver(
2177 p, info_win2k.info_3, 3, false);
2178 free_a_printer_driver( info_win2k, 3 );
2180 /* this should not have failed---if it did, report to client */
2181 if ( !W_ERROR_IS_OK(status_win2k) )
2183 status = status_win2k;
2184 goto done;
2189 status = delete_printer_driver(p, info.info_3, version, false);
2191 /* if at least one of the deletes succeeded return OK */
2193 if ( W_ERROR_IS_OK(status) || W_ERROR_IS_OK(status_win2k) )
2194 status = WERR_OK;
2196 done:
2197 free_a_printer_driver( info, 3 );
2199 return status;
2202 /****************************************************************
2203 _spoolss_DeletePrinterDriverEx
2204 ****************************************************************/
2206 WERROR _spoolss_DeletePrinterDriverEx(pipes_struct *p,
2207 struct spoolss_DeletePrinterDriverEx *r)
2209 NT_PRINTER_DRIVER_INFO_LEVEL info;
2210 NT_PRINTER_DRIVER_INFO_LEVEL info_win2k;
2211 int version;
2212 bool delete_files;
2213 WERROR status;
2214 WERROR status_win2k = WERR_ACCESS_DENIED;
2215 SE_PRIV se_printop = SE_PRINT_OPERATOR;
2217 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2218 and not a printer admin, then fail */
2220 if ( (p->server_info->utok.uid != 0)
2221 && !user_has_privileges(p->server_info->ptok, &se_printop )
2222 && !token_contains_name_in_list(
2223 uidtoname(p->server_info->utok.uid), NULL, NULL,
2224 p->server_info->ptok, lp_printer_admin(-1)) )
2226 return WERR_ACCESS_DENIED;
2229 /* check that we have a valid driver name first */
2230 if ((version = get_version_id(r->in.architecture)) == -1) {
2231 /* this is what NT returns */
2232 return WERR_INVALID_ENVIRONMENT;
2235 if (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
2236 version = r->in.version;
2238 ZERO_STRUCT(info);
2239 ZERO_STRUCT(info_win2k);
2241 status = get_a_printer_driver(&info, 3, r->in.driver,
2242 r->in.architecture, version);
2244 if ( !W_ERROR_IS_OK(status) )
2247 * if the client asked for a specific version,
2248 * or this is something other than Windows NT x86,
2249 * then we've failed
2252 if ( (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
2253 goto done;
2255 /* try for Win2k driver if "Windows NT x86" */
2257 version = 3;
2258 if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, r->in.driver,
2259 r->in.architecture,
2260 version))) {
2261 status = WERR_UNKNOWN_PRINTER_DRIVER;
2262 goto done;
2266 if ( printer_driver_in_use(info.info_3) ) {
2267 status = WERR_PRINTER_DRIVER_IN_USE;
2268 goto done;
2272 * we have a couple of cases to consider.
2273 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
2274 * then the delete should fail if **any** files overlap with
2275 * other drivers
2276 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
2277 * non-overlapping files
2278 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
2279 * is set, the do not delete any files
2280 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2283 delete_files = r->in.delete_flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
2285 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
2287 if ( delete_files && printer_driver_files_in_use(info.info_3) & (r->in.delete_flags & DPD_DELETE_ALL_FILES) ) {
2288 /* no idea of the correct error here */
2289 status = WERR_ACCESS_DENIED;
2290 goto done;
2294 /* also check for W32X86/3 if necessary; maybe we already have? */
2296 if ( (version == 2) && ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
2297 if (W_ERROR_IS_OK(get_a_printer_driver(&info_win2k, 3,
2298 r->in.driver,
2299 r->in.architecture, 3)))
2302 if ( delete_files && printer_driver_files_in_use(info_win2k.info_3) & (r->in.delete_flags & DPD_DELETE_ALL_FILES) ) {
2303 /* no idea of the correct error here */
2304 free_a_printer_driver( info_win2k, 3 );
2305 status = WERR_ACCESS_DENIED;
2306 goto done;
2309 /* if we get to here, we now have 2 driver info structures to remove */
2310 /* remove the Win2k driver first*/
2312 status_win2k = delete_printer_driver(
2313 p, info_win2k.info_3, 3, delete_files);
2314 free_a_printer_driver( info_win2k, 3 );
2316 /* this should not have failed---if it did, report to client */
2318 if ( !W_ERROR_IS_OK(status_win2k) )
2319 goto done;
2323 status = delete_printer_driver(p, info.info_3, version, delete_files);
2325 if ( W_ERROR_IS_OK(status) || W_ERROR_IS_OK(status_win2k) )
2326 status = WERR_OK;
2327 done:
2328 free_a_printer_driver( info, 3 );
2330 return status;
2334 /****************************************************************************
2335 Internal routine for removing printerdata
2336 ***************************************************************************/
2338 static WERROR delete_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char *key, const char *value )
2340 return delete_printer_data( printer->info_2, key, value );
2343 /****************************************************************************
2344 Internal routine for storing printerdata
2345 ***************************************************************************/
2347 WERROR set_printer_dataex(NT_PRINTER_INFO_LEVEL *printer,
2348 const char *key, const char *value,
2349 uint32_t type, uint8_t *data, int real_len)
2351 /* the registry objects enforce uniqueness based on value name */
2353 return add_printer_data( printer->info_2, key, value, type, data, real_len );
2356 /********************************************************************
2357 GetPrinterData on a printer server Handle.
2358 ********************************************************************/
2360 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2361 const char *value,
2362 enum winreg_Type *type,
2363 union spoolss_PrinterData *data)
2365 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2367 if (!StrCaseCmp(value, "W3SvcInstalled")) {
2368 *type = REG_DWORD;
2369 data->value = 0x00;
2370 return WERR_OK;
2373 if (!StrCaseCmp(value, "BeepEnabled")) {
2374 *type = REG_DWORD;
2375 data->value = 0x00;
2376 return WERR_OK;
2379 if (!StrCaseCmp(value, "EventLog")) {
2380 *type = REG_DWORD;
2381 /* formally was 0x1b */
2382 data->value = 0x00;
2383 return WERR_OK;
2386 if (!StrCaseCmp(value, "NetPopup")) {
2387 *type = REG_DWORD;
2388 data->value = 0x00;
2389 return WERR_OK;
2392 if (!StrCaseCmp(value, "MajorVersion")) {
2393 *type = REG_DWORD;
2395 /* Windows NT 4.0 seems to not allow uploading of drivers
2396 to a server that reports 0x3 as the MajorVersion.
2397 need to investigate more how Win2k gets around this .
2398 -- jerry */
2400 if (RA_WINNT == get_remote_arch()) {
2401 data->value = 0x02;
2402 } else {
2403 data->value = 0x03;
2406 return WERR_OK;
2409 if (!StrCaseCmp(value, "MinorVersion")) {
2410 *type = REG_DWORD;
2411 data->value = 0x00;
2412 return WERR_OK;
2415 /* REG_BINARY
2416 * uint32_t size = 0x114
2417 * uint32_t major = 5
2418 * uint32_t minor = [0|1]
2419 * uint32_t build = [2195|2600]
2420 * extra unicode string = e.g. "Service Pack 3"
2422 if (!StrCaseCmp(value, "OSVersion")) {
2423 DATA_BLOB blob;
2424 enum ndr_err_code ndr_err;
2425 struct spoolss_OSVersion os;
2427 os.major = 5; /* Windows 2000 == 5.0 */
2428 os.minor = 0;
2429 os.build = 2195; /* build */
2430 os.extra_string = ""; /* leave extra string empty */
2432 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, NULL, &os,
2433 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2434 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2435 return WERR_GENERAL_FAILURE;
2438 *type = REG_BINARY;
2439 data->binary = blob;
2441 return WERR_OK;
2445 if (!StrCaseCmp(value, "DefaultSpoolDirectory")) {
2446 *type = REG_SZ;
2448 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2449 W_ERROR_HAVE_NO_MEMORY(data->string);
2451 return WERR_OK;
2454 if (!StrCaseCmp(value, "Architecture")) {
2455 *type = REG_SZ;
2457 data->string = talloc_strdup(mem_ctx, "Windows NT x86");
2458 W_ERROR_HAVE_NO_MEMORY(data->string);
2460 return WERR_OK;
2463 if (!StrCaseCmp(value, "DsPresent")) {
2464 *type = REG_DWORD;
2466 /* only show the publish check box if we are a
2467 member of a AD domain */
2469 if (lp_security() == SEC_ADS) {
2470 data->value = 0x01;
2471 } else {
2472 data->value = 0x00;
2474 return WERR_OK;
2477 if (!StrCaseCmp(value, "DNSMachineName")) {
2478 const char *hostname = get_mydnsfullname();
2480 if (!hostname) {
2481 return WERR_BADFILE;
2484 *type = REG_SZ;
2485 data->string = talloc_strdup(mem_ctx, hostname);
2486 W_ERROR_HAVE_NO_MEMORY(data->string);
2488 return WERR_OK;
2491 return WERR_INVALID_PARAM;
2494 /****************************************************************
2495 _spoolss_GetPrinterData
2496 ****************************************************************/
2498 WERROR _spoolss_GetPrinterData(pipes_struct *p,
2499 struct spoolss_GetPrinterData *r)
2501 WERROR result;
2502 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
2503 NT_PRINTER_INFO_LEVEL *printer = NULL;
2504 int snum = 0;
2507 * Reminder: when it's a string, the length is in BYTES
2508 * even if UNICODE is negociated.
2510 * JFM, 4/19/1999
2513 /* in case of problem, return some default values */
2515 *r->out.needed = 0;
2516 *r->out.type = 0;
2518 DEBUG(4,("_spoolss_GetPrinterData\n"));
2520 if (!Printer) {
2521 DEBUG(2,("_spoolss_GetPrinterData: Invalid handle (%s:%u:%u).\n",
2522 OUR_HANDLE(r->in.handle)));
2523 result = WERR_BADFID;
2524 goto done;
2527 if (Printer->printer_type == SPLHND_SERVER) {
2528 result = getprinterdata_printer_server(p->mem_ctx,
2529 r->in.value_name,
2530 r->out.type,
2531 r->out.data);
2532 } else {
2533 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
2534 result = WERR_BADFID;
2535 goto done;
2538 result = get_a_printer(Printer, &printer, 2, lp_servicename(snum));
2539 if (!W_ERROR_IS_OK(result)) {
2540 goto done;
2543 /* XP sends this and wants to change id value from the PRINTER_INFO_0 */
2545 if (strequal(r->in.value_name, "ChangeId")) {
2546 *r->out.type = REG_DWORD;
2547 r->out.data->value = printer->info_2->changeid;
2548 result = WERR_OK;
2549 } else {
2550 REGISTRY_VALUE *v;
2551 DATA_BLOB blob;
2553 v = get_printer_data(printer->info_2,
2554 SPOOL_PRINTERDATA_KEY,
2555 r->in.value_name);
2556 if (!v) {
2557 result = WERR_BADFILE;
2558 goto done;
2561 *r->out.type = v->type;
2563 blob = data_blob_const(v->data_p, v->size);
2565 result = pull_spoolss_PrinterData(p->mem_ctx, &blob,
2566 r->out.data,
2567 *r->out.type);
2571 done:
2572 /* cleanup & exit */
2574 if (printer) {
2575 free_a_printer(&printer, 2);
2578 if (!W_ERROR_IS_OK(result)) {
2579 return result;
2582 *r->out.needed = ndr_size_spoolss_PrinterData(r->out.data, *r->out.type, NULL, 0);
2583 *r->out.type = SPOOLSS_BUFFER_OK(*r->out.type, REG_NONE);
2584 r->out.data = SPOOLSS_BUFFER_OK(r->out.data, r->out.data);
2586 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
2589 /*********************************************************
2590 Connect to the client machine.
2591 **********************************************************/
2593 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2594 struct sockaddr_storage *client_ss, const char *remote_machine)
2596 NTSTATUS ret;
2597 struct cli_state *the_cli;
2598 struct sockaddr_storage rm_addr;
2600 if ( is_zero_addr((struct sockaddr *)client_ss) ) {
2601 if ( !resolve_name( remote_machine, &rm_addr, 0x20) ) {
2602 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2603 return false;
2606 if (ismyaddr((struct sockaddr *)&rm_addr)) {
2607 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n", remote_machine));
2608 return false;
2610 } else {
2611 char addr[INET6_ADDRSTRLEN];
2612 rm_addr = *client_ss;
2613 print_sockaddr(addr, sizeof(addr), &rm_addr);
2614 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2615 addr));
2618 /* setup the connection */
2620 ret = cli_full_connection( &the_cli, global_myname(), remote_machine,
2621 &rm_addr, 0, "IPC$", "IPC",
2622 "", /* username */
2623 "", /* domain */
2624 "", /* password */
2625 0, lp_client_signing(), NULL );
2627 if ( !NT_STATUS_IS_OK( ret ) ) {
2628 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2629 remote_machine ));
2630 return false;
2633 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2634 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2635 cli_shutdown(the_cli);
2636 return false;
2640 * Ok - we have an anonymous connection to the IPC$ share.
2641 * Now start the NT Domain stuff :-).
2644 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2645 if (!NT_STATUS_IS_OK(ret)) {
2646 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2647 remote_machine, nt_errstr(ret)));
2648 cli_shutdown(the_cli);
2649 return false;
2652 return true;
2655 /***************************************************************************
2656 Connect to the client.
2657 ****************************************************************************/
2659 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2660 uint32_t localprinter, uint32_t type,
2661 struct policy_handle *handle,
2662 struct sockaddr_storage *client_ss)
2664 WERROR result;
2665 NTSTATUS status;
2668 * If it's the first connection, contact the client
2669 * and connect to the IPC$ share anonymously
2671 if (smb_connections==0) {
2672 fstring unix_printer;
2674 fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */
2676 if ( !spoolss_connect_to_client( &notify_cli_pipe, client_ss, unix_printer ))
2677 return false;
2679 messaging_register(smbd_messaging_context(), NULL,
2680 MSG_PRINTER_NOTIFY2,
2681 receive_notify2_message_list);
2682 /* Tell the connections db we're now interested in printer
2683 * notify messages. */
2684 register_message_flags(true, FLAG_MSG_PRINT_NOTIFY);
2688 * Tell the specific printing tdb we want messages for this printer
2689 * by registering our PID.
2692 if (!print_notify_register_pid(snum))
2693 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", printer ));
2695 smb_connections++;
2697 status = rpccli_spoolss_ReplyOpenPrinter(notify_cli_pipe, talloc_tos(),
2698 printer,
2699 localprinter,
2700 type,
2702 NULL,
2703 handle,
2704 &result);
2705 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
2706 DEBUG(5,("srv_spoolss_reply_open_printer: Client RPC returned [%s]\n",
2707 win_errstr(result)));
2709 return (W_ERROR_IS_OK(result));
2712 /****************************************************************
2713 ****************************************************************/
2715 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2716 const struct spoolss_NotifyOption *r)
2718 struct spoolss_NotifyOption *option;
2719 uint32_t i,k;
2721 if (!r) {
2722 return NULL;
2725 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2726 if (!option) {
2727 return NULL;
2730 *option = *r;
2732 if (!option->count) {
2733 return option;
2736 option->types = talloc_zero_array(option,
2737 struct spoolss_NotifyOptionType, option->count);
2738 if (!option->types) {
2739 talloc_free(option);
2740 return NULL;
2743 for (i=0; i < option->count; i++) {
2744 option->types[i] = r->types[i];
2746 if (option->types[i].count) {
2747 option->types[i].fields = talloc_zero_array(option,
2748 union spoolss_Field, option->types[i].count);
2749 if (!option->types[i].fields) {
2750 talloc_free(option);
2751 return NULL;
2753 for (k=0; k<option->types[i].count; k++) {
2754 option->types[i].fields[k] =
2755 r->types[i].fields[k];
2760 return option;
2763 /****************************************************************
2764 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2766 * before replying OK: status=0 a rpc call is made to the workstation
2767 * asking ReplyOpenPrinter
2769 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2770 * called from api_spoolss_rffpcnex
2771 ****************************************************************/
2773 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(pipes_struct *p,
2774 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2776 int snum = -1;
2777 struct spoolss_NotifyOption *option = r->in.notify_options;
2778 struct sockaddr_storage client_ss;
2780 /* store the notify value in the printer struct */
2782 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
2784 if (!Printer) {
2785 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2786 "Invalid handle (%s:%u:%u).\n",
2787 OUR_HANDLE(r->in.handle)));
2788 return WERR_BADFID;
2791 Printer->notify.flags = r->in.flags;
2792 Printer->notify.options = r->in.options;
2793 Printer->notify.printerlocal = r->in.printer_local;
2795 TALLOC_FREE(Printer->notify.option);
2796 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2798 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2800 /* Connect to the client machine and send a ReplyOpenPrinter */
2802 if ( Printer->printer_type == SPLHND_SERVER)
2803 snum = -1;
2804 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2805 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2806 return WERR_BADFID;
2808 if (!interpret_string_addr(&client_ss, p->client_address,
2809 AI_NUMERICHOST)) {
2810 return WERR_SERVER_UNAVAILABLE;
2813 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2814 Printer->notify.printerlocal, 1,
2815 &Printer->notify.client_hnd, &client_ss))
2816 return WERR_SERVER_UNAVAILABLE;
2818 Printer->notify.client_connected = true;
2820 return WERR_OK;
2823 /*******************************************************************
2824 * fill a notify_info_data with the servername
2825 ********************************************************************/
2827 void spoolss_notify_server_name(int snum,
2828 struct spoolss_Notify *data,
2829 print_queue_struct *queue,
2830 NT_PRINTER_INFO_LEVEL *printer,
2831 TALLOC_CTX *mem_ctx)
2833 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->servername);
2836 /*******************************************************************
2837 * fill a notify_info_data with the printername (not including the servername).
2838 ********************************************************************/
2840 void spoolss_notify_printer_name(int snum,
2841 struct spoolss_Notify *data,
2842 print_queue_struct *queue,
2843 NT_PRINTER_INFO_LEVEL *printer,
2844 TALLOC_CTX *mem_ctx)
2846 /* the notify name should not contain the \\server\ part */
2847 char *p = strrchr(printer->info_2->printername, '\\');
2849 if (!p) {
2850 p = printer->info_2->printername;
2851 } else {
2852 p++;
2855 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2858 /*******************************************************************
2859 * fill a notify_info_data with the servicename
2860 ********************************************************************/
2862 void spoolss_notify_share_name(int snum,
2863 struct spoolss_Notify *data,
2864 print_queue_struct *queue,
2865 NT_PRINTER_INFO_LEVEL *printer,
2866 TALLOC_CTX *mem_ctx)
2868 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
2871 /*******************************************************************
2872 * fill a notify_info_data with the port name
2873 ********************************************************************/
2875 void spoolss_notify_port_name(int snum,
2876 struct spoolss_Notify *data,
2877 print_queue_struct *queue,
2878 NT_PRINTER_INFO_LEVEL *printer,
2879 TALLOC_CTX *mem_ctx)
2881 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->portname);
2884 /*******************************************************************
2885 * fill a notify_info_data with the printername
2886 * but it doesn't exist, have to see what to do
2887 ********************************************************************/
2889 void spoolss_notify_driver_name(int snum,
2890 struct spoolss_Notify *data,
2891 print_queue_struct *queue,
2892 NT_PRINTER_INFO_LEVEL *printer,
2893 TALLOC_CTX *mem_ctx)
2895 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->drivername);
2898 /*******************************************************************
2899 * fill a notify_info_data with the comment
2900 ********************************************************************/
2902 void spoolss_notify_comment(int snum,
2903 struct spoolss_Notify *data,
2904 print_queue_struct *queue,
2905 NT_PRINTER_INFO_LEVEL *printer,
2906 TALLOC_CTX *mem_ctx)
2908 char *p;
2910 if (*printer->info_2->comment == '\0') {
2911 p = lp_comment(snum);
2912 } else {
2913 p = printer->info_2->comment;
2916 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->comment);
2919 /*******************************************************************
2920 * fill a notify_info_data with the comment
2921 * location = "Room 1, floor 2, building 3"
2922 ********************************************************************/
2924 void spoolss_notify_location(int snum,
2925 struct spoolss_Notify *data,
2926 print_queue_struct *queue,
2927 NT_PRINTER_INFO_LEVEL *printer,
2928 TALLOC_CTX *mem_ctx)
2930 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->location);
2933 /*******************************************************************
2934 * fill a notify_info_data with the device mode
2935 * jfm:xxxx don't to it for know but that's a real problem !!!
2936 ********************************************************************/
2938 static void spoolss_notify_devmode(int snum,
2939 struct spoolss_Notify *data,
2940 print_queue_struct *queue,
2941 NT_PRINTER_INFO_LEVEL *printer,
2942 TALLOC_CTX *mem_ctx)
2944 /* for a dummy implementation we have to zero the fields */
2945 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2948 /*******************************************************************
2949 * fill a notify_info_data with the separator file name
2950 ********************************************************************/
2952 void spoolss_notify_sepfile(int snum,
2953 struct spoolss_Notify *data,
2954 print_queue_struct *queue,
2955 NT_PRINTER_INFO_LEVEL *printer,
2956 TALLOC_CTX *mem_ctx)
2958 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->sepfile);
2961 /*******************************************************************
2962 * fill a notify_info_data with the print processor
2963 * jfm:xxxx return always winprint to indicate we don't do anything to it
2964 ********************************************************************/
2966 void spoolss_notify_print_processor(int snum,
2967 struct spoolss_Notify *data,
2968 print_queue_struct *queue,
2969 NT_PRINTER_INFO_LEVEL *printer,
2970 TALLOC_CTX *mem_ctx)
2972 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->printprocessor);
2975 /*******************************************************************
2976 * fill a notify_info_data with the print processor options
2977 * jfm:xxxx send an empty string
2978 ********************************************************************/
2980 void spoolss_notify_parameters(int snum,
2981 struct spoolss_Notify *data,
2982 print_queue_struct *queue,
2983 NT_PRINTER_INFO_LEVEL *printer,
2984 TALLOC_CTX *mem_ctx)
2986 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->parameters);
2989 /*******************************************************************
2990 * fill a notify_info_data with the data type
2991 * jfm:xxxx always send RAW as data type
2992 ********************************************************************/
2994 void spoolss_notify_datatype(int snum,
2995 struct spoolss_Notify *data,
2996 print_queue_struct *queue,
2997 NT_PRINTER_INFO_LEVEL *printer,
2998 TALLOC_CTX *mem_ctx)
3000 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->datatype);
3003 /*******************************************************************
3004 * fill a notify_info_data with the security descriptor
3005 * jfm:xxxx send an null pointer to say no security desc
3006 * have to implement security before !
3007 ********************************************************************/
3009 static void spoolss_notify_security_desc(int snum,
3010 struct spoolss_Notify *data,
3011 print_queue_struct *queue,
3012 NT_PRINTER_INFO_LEVEL *printer,
3013 TALLOC_CTX *mem_ctx)
3015 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data,
3016 printer->info_2->secdesc_buf->sd_size,
3017 printer->info_2->secdesc_buf->sd);
3020 /*******************************************************************
3021 * fill a notify_info_data with the attributes
3022 * jfm:xxxx a samba printer is always shared
3023 ********************************************************************/
3025 void spoolss_notify_attributes(int snum,
3026 struct spoolss_Notify *data,
3027 print_queue_struct *queue,
3028 NT_PRINTER_INFO_LEVEL *printer,
3029 TALLOC_CTX *mem_ctx)
3031 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->attributes);
3034 /*******************************************************************
3035 * fill a notify_info_data with the priority
3036 ********************************************************************/
3038 static void spoolss_notify_priority(int snum,
3039 struct spoolss_Notify *data,
3040 print_queue_struct *queue,
3041 NT_PRINTER_INFO_LEVEL *printer,
3042 TALLOC_CTX *mem_ctx)
3044 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->priority);
3047 /*******************************************************************
3048 * fill a notify_info_data with the default priority
3049 ********************************************************************/
3051 static void spoolss_notify_default_priority(int snum,
3052 struct spoolss_Notify *data,
3053 print_queue_struct *queue,
3054 NT_PRINTER_INFO_LEVEL *printer,
3055 TALLOC_CTX *mem_ctx)
3057 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->default_priority);
3060 /*******************************************************************
3061 * fill a notify_info_data with the start time
3062 ********************************************************************/
3064 static void spoolss_notify_start_time(int snum,
3065 struct spoolss_Notify *data,
3066 print_queue_struct *queue,
3067 NT_PRINTER_INFO_LEVEL *printer,
3068 TALLOC_CTX *mem_ctx)
3070 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->starttime);
3073 /*******************************************************************
3074 * fill a notify_info_data with the until time
3075 ********************************************************************/
3077 static void spoolss_notify_until_time(int snum,
3078 struct spoolss_Notify *data,
3079 print_queue_struct *queue,
3080 NT_PRINTER_INFO_LEVEL *printer,
3081 TALLOC_CTX *mem_ctx)
3083 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->untiltime);
3086 /*******************************************************************
3087 * fill a notify_info_data with the status
3088 ********************************************************************/
3090 static void spoolss_notify_status(int snum,
3091 struct spoolss_Notify *data,
3092 print_queue_struct *queue,
3093 NT_PRINTER_INFO_LEVEL *printer,
3094 TALLOC_CTX *mem_ctx)
3096 print_status_struct status;
3098 print_queue_length(snum, &status);
3099 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
3102 /*******************************************************************
3103 * fill a notify_info_data with the number of jobs queued
3104 ********************************************************************/
3106 void spoolss_notify_cjobs(int snum,
3107 struct spoolss_Notify *data,
3108 print_queue_struct *queue,
3109 NT_PRINTER_INFO_LEVEL *printer,
3110 TALLOC_CTX *mem_ctx)
3112 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, print_queue_length(snum, NULL));
3115 /*******************************************************************
3116 * fill a notify_info_data with the average ppm
3117 ********************************************************************/
3119 static void spoolss_notify_average_ppm(int snum,
3120 struct spoolss_Notify *data,
3121 print_queue_struct *queue,
3122 NT_PRINTER_INFO_LEVEL *printer,
3123 TALLOC_CTX *mem_ctx)
3125 /* always respond 8 pages per minutes */
3126 /* a little hard ! */
3127 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->averageppm);
3130 /*******************************************************************
3131 * fill a notify_info_data with username
3132 ********************************************************************/
3134 static void spoolss_notify_username(int snum,
3135 struct spoolss_Notify *data,
3136 print_queue_struct *queue,
3137 NT_PRINTER_INFO_LEVEL *printer,
3138 TALLOC_CTX *mem_ctx)
3140 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
3143 /*******************************************************************
3144 * fill a notify_info_data with job status
3145 ********************************************************************/
3147 static void spoolss_notify_job_status(int snum,
3148 struct spoolss_Notify *data,
3149 print_queue_struct *queue,
3150 NT_PRINTER_INFO_LEVEL *printer,
3151 TALLOC_CTX *mem_ctx)
3153 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
3156 /*******************************************************************
3157 * fill a notify_info_data with job name
3158 ********************************************************************/
3160 static void spoolss_notify_job_name(int snum,
3161 struct spoolss_Notify *data,
3162 print_queue_struct *queue,
3163 NT_PRINTER_INFO_LEVEL *printer,
3164 TALLOC_CTX *mem_ctx)
3166 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
3169 /*******************************************************************
3170 * fill a notify_info_data with job status
3171 ********************************************************************/
3173 static void spoolss_notify_job_status_string(int snum,
3174 struct spoolss_Notify *data,
3175 print_queue_struct *queue,
3176 NT_PRINTER_INFO_LEVEL *printer,
3177 TALLOC_CTX *mem_ctx)
3180 * Now we're returning job status codes we just return a "" here. JRA.
3183 const char *p = "";
3185 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3186 p = "unknown";
3188 switch (queue->status) {
3189 case LPQ_QUEUED:
3190 p = "Queued";
3191 break;
3192 case LPQ_PAUSED:
3193 p = ""; /* NT provides the paused string */
3194 break;
3195 case LPQ_SPOOLING:
3196 p = "Spooling";
3197 break;
3198 case LPQ_PRINTING:
3199 p = "Printing";
3200 break;
3202 #endif /* NO LONGER NEEDED. */
3204 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
3207 /*******************************************************************
3208 * fill a notify_info_data with job time
3209 ********************************************************************/
3211 static void spoolss_notify_job_time(int snum,
3212 struct spoolss_Notify *data,
3213 print_queue_struct *queue,
3214 NT_PRINTER_INFO_LEVEL *printer,
3215 TALLOC_CTX *mem_ctx)
3217 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3220 /*******************************************************************
3221 * fill a notify_info_data with job size
3222 ********************************************************************/
3224 static void spoolss_notify_job_size(int snum,
3225 struct spoolss_Notify *data,
3226 print_queue_struct *queue,
3227 NT_PRINTER_INFO_LEVEL *printer,
3228 TALLOC_CTX *mem_ctx)
3230 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
3233 /*******************************************************************
3234 * fill a notify_info_data with page info
3235 ********************************************************************/
3236 static void spoolss_notify_total_pages(int snum,
3237 struct spoolss_Notify *data,
3238 print_queue_struct *queue,
3239 NT_PRINTER_INFO_LEVEL *printer,
3240 TALLOC_CTX *mem_ctx)
3242 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
3245 /*******************************************************************
3246 * fill a notify_info_data with pages printed info.
3247 ********************************************************************/
3248 static void spoolss_notify_pages_printed(int snum,
3249 struct spoolss_Notify *data,
3250 print_queue_struct *queue,
3251 NT_PRINTER_INFO_LEVEL *printer,
3252 TALLOC_CTX *mem_ctx)
3254 /* Add code when back-end tracks this */
3255 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3258 /*******************************************************************
3259 Fill a notify_info_data with job position.
3260 ********************************************************************/
3262 static void spoolss_notify_job_position(int snum,
3263 struct spoolss_Notify *data,
3264 print_queue_struct *queue,
3265 NT_PRINTER_INFO_LEVEL *printer,
3266 TALLOC_CTX *mem_ctx)
3268 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
3271 /*******************************************************************
3272 Fill a notify_info_data with submitted time.
3273 ********************************************************************/
3275 static void spoolss_notify_submitted_time(int snum,
3276 struct spoolss_Notify *data,
3277 print_queue_struct *queue,
3278 NT_PRINTER_INFO_LEVEL *printer,
3279 TALLOC_CTX *mem_ctx)
3281 data->data.string.string = NULL;
3282 data->data.string.size = 0;
3284 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
3285 &data->data.string.string,
3286 &data->data.string.size);
3290 struct s_notify_info_data_table
3292 enum spoolss_NotifyType type;
3293 uint16_t field;
3294 const char *name;
3295 enum spoolss_NotifyTable variable_type;
3296 void (*fn) (int snum, struct spoolss_Notify *data,
3297 print_queue_struct *queue,
3298 NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx);
3301 /* A table describing the various print notification constants and
3302 whether the notification data is a pointer to a variable sized
3303 buffer, a one value uint32_t or a two value uint32_t. */
3305 static const struct s_notify_info_data_table notify_info_data_table[] =
3307 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3308 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3309 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
3310 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3311 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3312 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
3313 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
3314 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3315 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
3316 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3317 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3318 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3319 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
3320 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
3321 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3322 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
3323 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3324 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3325 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
3326 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
3327 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
3328 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
3329 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
3330 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3331 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
3332 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3333 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3334 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3335 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3336 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3337 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3338 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3339 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3340 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3341 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3342 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3343 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
3344 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
3345 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
3346 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
3347 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3348 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
3349 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
3350 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3351 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3352 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
3353 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
3354 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
3355 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
3358 /*******************************************************************
3359 Return the variable_type of info_data structure.
3360 ********************************************************************/
3362 static uint32_t variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3363 uint16_t field)
3365 int i=0;
3367 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3368 if ( (notify_info_data_table[i].type == type) &&
3369 (notify_info_data_table[i].field == field) ) {
3370 return notify_info_data_table[i].variable_type;
3374 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3376 return 0;
3379 /****************************************************************************
3380 ****************************************************************************/
3382 static bool search_notify(enum spoolss_NotifyType type,
3383 uint16_t field,
3384 int *value)
3386 int i;
3388 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3389 if (notify_info_data_table[i].type == type &&
3390 notify_info_data_table[i].field == field &&
3391 notify_info_data_table[i].fn != NULL) {
3392 *value = i;
3393 return true;
3397 return false;
3400 /****************************************************************************
3401 ****************************************************************************/
3403 void construct_info_data(struct spoolss_Notify *info_data,
3404 enum spoolss_NotifyType type,
3405 uint16_t field,
3406 int id)
3408 info_data->type = type;
3409 info_data->field.field = field;
3410 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3411 info_data->job_id = id;
3414 /*******************************************************************
3416 * fill a notify_info struct with info asked
3418 ********************************************************************/
3420 static bool construct_notify_printer_info(Printer_entry *print_hnd,
3421 struct spoolss_NotifyInfo *info,
3422 int snum,
3423 const struct spoolss_NotifyOptionType *option_type,
3424 uint32_t id,
3425 TALLOC_CTX *mem_ctx)
3427 int field_num,j;
3428 enum spoolss_NotifyType type;
3429 uint16_t field;
3431 struct spoolss_Notify *current_data;
3432 NT_PRINTER_INFO_LEVEL *printer = NULL;
3433 print_queue_struct *queue=NULL;
3435 type = option_type->type;
3437 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3438 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3439 option_type->count, lp_servicename(snum)));
3441 if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &printer, 2, lp_const_servicename(snum))))
3442 return false;
3444 for(field_num=0; field_num < option_type->count; field_num++) {
3445 field = option_type->fields[field_num].field;
3447 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3449 if (!search_notify(type, field, &j) )
3450 continue;
3452 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3453 struct spoolss_Notify,
3454 info->count + 1);
3455 if (info->notifies == NULL) {
3456 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3457 free_a_printer(&printer, 2);
3458 return false;
3461 current_data = &info->notifies[info->count];
3463 construct_info_data(current_data, type, field, id);
3465 DEBUG(10,("construct_notify_printer_info: calling [%s] snum=%d printername=[%s])\n",
3466 notify_info_data_table[j].name, snum, printer->info_2->printername ));
3468 notify_info_data_table[j].fn(snum, current_data, queue,
3469 printer, mem_ctx);
3471 info->count++;
3474 free_a_printer(&printer, 2);
3475 return true;
3478 /*******************************************************************
3480 * fill a notify_info struct with info asked
3482 ********************************************************************/
3484 static bool construct_notify_jobs_info(print_queue_struct *queue,
3485 struct spoolss_NotifyInfo *info,
3486 NT_PRINTER_INFO_LEVEL *printer,
3487 int snum,
3488 const struct spoolss_NotifyOptionType *option_type,
3489 uint32_t id,
3490 TALLOC_CTX *mem_ctx)
3492 int field_num,j;
3493 enum spoolss_NotifyType type;
3494 uint16_t field;
3495 struct spoolss_Notify *current_data;
3497 DEBUG(4,("construct_notify_jobs_info\n"));
3499 type = option_type->type;
3501 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3502 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3503 option_type->count));
3505 for(field_num=0; field_num<option_type->count; field_num++) {
3506 field = option_type->fields[field_num].field;
3508 if (!search_notify(type, field, &j) )
3509 continue;
3511 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3512 struct spoolss_Notify,
3513 info->count + 1);
3514 if (info->notifies == NULL) {
3515 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3516 return false;
3519 current_data=&(info->notifies[info->count]);
3521 construct_info_data(current_data, type, field, id);
3522 notify_info_data_table[j].fn(snum, current_data, queue,
3523 printer, mem_ctx);
3524 info->count++;
3527 return true;
3531 * JFM: The enumeration is not that simple, it's even non obvious.
3533 * let's take an example: I want to monitor the PRINTER SERVER for
3534 * the printer's name and the number of jobs currently queued.
3535 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3536 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3538 * I have 3 printers on the back of my server.
3540 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3541 * structures.
3542 * Number Data Id
3543 * 1 printer 1 name 1
3544 * 2 printer 1 cjob 1
3545 * 3 printer 2 name 2
3546 * 4 printer 2 cjob 2
3547 * 5 printer 3 name 3
3548 * 6 printer 3 name 3
3550 * that's the print server case, the printer case is even worse.
3553 /*******************************************************************
3555 * enumerate all printers on the printserver
3556 * fill a notify_info struct with info asked
3558 ********************************************************************/
3560 static WERROR printserver_notify_info(pipes_struct *p,
3561 struct policy_handle *hnd,
3562 struct spoolss_NotifyInfo *info,
3563 TALLOC_CTX *mem_ctx)
3565 int snum;
3566 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3567 int n_services=lp_numservices();
3568 int i;
3569 struct spoolss_NotifyOption *option;
3570 struct spoolss_NotifyOptionType option_type;
3572 DEBUG(4,("printserver_notify_info\n"));
3574 if (!Printer)
3575 return WERR_BADFID;
3577 option = Printer->notify.option;
3579 info->version = 2;
3580 info->notifies = NULL;
3581 info->count = 0;
3583 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3584 sending a ffpcn() request first */
3586 if ( !option )
3587 return WERR_BADFID;
3589 for (i=0; i<option->count; i++) {
3590 option_type = option->types[i];
3592 if (option_type.type != PRINTER_NOTIFY_TYPE)
3593 continue;
3595 for (snum=0; snum<n_services; snum++)
3597 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
3598 construct_notify_printer_info ( Printer, info, snum, &option_type, snum, mem_ctx );
3602 #if 0
3604 * Debugging information, don't delete.
3607 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3608 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3609 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3611 for (i=0; i<info->count; i++) {
3612 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3613 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3614 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3616 #endif
3618 return WERR_OK;
3621 /*******************************************************************
3623 * fill a notify_info struct with info asked
3625 ********************************************************************/
3627 static WERROR printer_notify_info(pipes_struct *p, struct policy_handle *hnd,
3628 struct spoolss_NotifyInfo *info,
3629 TALLOC_CTX *mem_ctx)
3631 int snum;
3632 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3633 int i;
3634 uint32_t id;
3635 struct spoolss_NotifyOption *option;
3636 struct spoolss_NotifyOptionType option_type;
3637 int count,j;
3638 print_queue_struct *queue=NULL;
3639 print_status_struct status;
3641 DEBUG(4,("printer_notify_info\n"));
3643 if (!Printer)
3644 return WERR_BADFID;
3646 option = Printer->notify.option;
3647 id = 0x0;
3649 info->version = 2;
3650 info->notifies = NULL;
3651 info->count = 0;
3653 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3654 sending a ffpcn() request first */
3656 if ( !option )
3657 return WERR_BADFID;
3659 get_printer_snum(p, hnd, &snum, NULL);
3661 for (i=0; i<option->count; i++) {
3662 option_type = option->types[i];
3664 switch (option_type.type) {
3665 case PRINTER_NOTIFY_TYPE:
3666 if(construct_notify_printer_info(Printer, info, snum,
3667 &option_type, id,
3668 mem_ctx))
3669 id--;
3670 break;
3672 case JOB_NOTIFY_TYPE: {
3673 NT_PRINTER_INFO_LEVEL *printer = NULL;
3675 count = print_queue_status(snum, &queue, &status);
3677 if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum))))
3678 goto done;
3680 for (j=0; j<count; j++) {
3681 construct_notify_jobs_info(&queue[j], info,
3682 printer, snum,
3683 &option_type,
3684 queue[j].job,
3685 mem_ctx);
3688 free_a_printer(&printer, 2);
3690 done:
3691 SAFE_FREE(queue);
3692 break;
3698 * Debugging information, don't delete.
3701 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3702 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3703 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3705 for (i=0; i<info->count; i++) {
3706 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3707 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3708 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3711 return WERR_OK;
3714 /****************************************************************
3715 _spoolss_RouterRefreshPrinterChangeNotify
3716 ****************************************************************/
3718 WERROR _spoolss_RouterRefreshPrinterChangeNotify(pipes_struct *p,
3719 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3721 struct spoolss_NotifyInfo *info;
3723 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
3724 WERROR result = WERR_BADFID;
3726 /* we always have a spoolss_NotifyInfo struct */
3727 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3728 if (!info) {
3729 result = WERR_NOMEM;
3730 goto done;
3733 *r->out.info = info;
3735 if (!Printer) {
3736 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3737 "Invalid handle (%s:%u:%u).\n",
3738 OUR_HANDLE(r->in.handle)));
3739 goto done;
3742 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3745 * We are now using the change value, and
3746 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3747 * I don't have a global notification system, I'm sending back all the
3748 * informations even when _NOTHING_ has changed.
3751 /* We need to keep track of the change value to send back in
3752 RRPCN replies otherwise our updates are ignored. */
3754 Printer->notify.fnpcn = true;
3756 if (Printer->notify.client_connected) {
3757 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3758 "Saving change value in request [%x]\n",
3759 r->in.change_low));
3760 Printer->notify.change = r->in.change_low;
3763 /* just ignore the spoolss_NotifyOption */
3765 switch (Printer->printer_type) {
3766 case SPLHND_SERVER:
3767 result = printserver_notify_info(p, r->in.handle,
3768 info, p->mem_ctx);
3769 break;
3771 case SPLHND_PRINTER:
3772 result = printer_notify_info(p, r->in.handle,
3773 info, p->mem_ctx);
3774 break;
3777 Printer->notify.fnpcn = false;
3779 done:
3780 return result;
3783 /********************************************************************
3784 * construct_printer_info_0
3785 * fill a printer_info_0 struct
3786 ********************************************************************/
3788 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3789 const NT_PRINTER_INFO_LEVEL *ntprinter,
3790 struct spoolss_PrinterInfo0 *r,
3791 int snum)
3793 int count;
3794 counter_printer_0 *session_counter;
3795 time_t setuptime;
3796 print_status_struct status;
3798 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
3799 W_ERROR_HAVE_NO_MEMORY(r->printername);
3801 r->servername = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
3802 W_ERROR_HAVE_NO_MEMORY(r->servername);
3804 count = print_queue_length(snum, &status);
3806 /* check if we already have a counter for this printer */
3807 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3808 if (session_counter->snum == snum)
3809 break;
3812 /* it's the first time, add it to the list */
3813 if (session_counter == NULL) {
3814 session_counter = SMB_MALLOC_P(counter_printer_0);
3815 W_ERROR_HAVE_NO_MEMORY(session_counter);
3816 ZERO_STRUCTP(session_counter);
3817 session_counter->snum = snum;
3818 session_counter->counter = 0;
3819 DLIST_ADD(counter_list, session_counter);
3822 /* increment it */
3823 session_counter->counter++;
3825 r->cjobs = count;
3826 r->total_jobs = 0;
3827 r->total_bytes = 0;
3829 setuptime = (time_t)ntprinter->info_2->setuptime;
3831 init_systemtime(&r->time, gmtime(&setuptime));
3833 /* JFM:
3834 * the global_counter should be stored in a TDB as it's common to all the clients
3835 * and should be zeroed on samba startup
3837 r->global_counter = session_counter->counter;
3838 r->total_pages = 0;
3839 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3840 r->version = 0x0005; /* NT 5 */
3841 r->free_build = 0x0893; /* build 2195 */
3842 r->spooling = 0;
3843 r->max_spooling = 0;
3844 r->session_counter = session_counter->counter;
3845 r->num_error_out_of_paper = 0x0;
3846 r->num_error_not_ready = 0x0; /* number of print failure */
3847 r->job_error = 0x0;
3848 r->number_of_processors = 0x1;
3849 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3850 r->high_part_total_bytes = 0x0;
3851 r->change_id = ntprinter->info_2->changeid; /* ChangeID in milliseconds*/
3852 r->last_error = WERR_OK;
3853 r->status = nt_printq_status(status.status);
3854 r->enumerate_network_printers = 0x0;
3855 r->c_setprinter = get_c_setprinter(); /* monotonically increasing sum of delta printer counts */
3856 r->processor_architecture = 0x0;
3857 r->processor_level = 0x6; /* 6 ???*/
3858 r->ref_ic = 0;
3859 r->reserved2 = 0;
3860 r->reserved3 = 0;
3862 return WERR_OK;
3865 /****************************************************************************
3866 Convert an NT_DEVICEMODE to a spoolss_DeviceMode structure. Both pointers
3867 should be valid upon entry
3868 ****************************************************************************/
3870 static WERROR convert_nt_devicemode(TALLOC_CTX *mem_ctx,
3871 struct spoolss_DeviceMode *r,
3872 const NT_DEVICEMODE *ntdevmode)
3874 if (!r || !ntdevmode) {
3875 return WERR_INVALID_PARAM;
3878 r->devicename = talloc_strdup(mem_ctx, ntdevmode->devicename);
3879 W_ERROR_HAVE_NO_MEMORY(r->devicename);
3881 r->specversion = ntdevmode->specversion;
3882 r->driverversion = ntdevmode->driverversion;
3883 r->size = ntdevmode->size;
3884 r->__driverextra_length = ntdevmode->driverextra;
3885 r->fields = ntdevmode->fields;
3887 r->orientation = ntdevmode->orientation;
3888 r->papersize = ntdevmode->papersize;
3889 r->paperlength = ntdevmode->paperlength;
3890 r->paperwidth = ntdevmode->paperwidth;
3891 r->scale = ntdevmode->scale;
3892 r->copies = ntdevmode->copies;
3893 r->defaultsource = ntdevmode->defaultsource;
3894 r->printquality = ntdevmode->printquality;
3895 r->color = ntdevmode->color;
3896 r->duplex = ntdevmode->duplex;
3897 r->yresolution = ntdevmode->yresolution;
3898 r->ttoption = ntdevmode->ttoption;
3899 r->collate = ntdevmode->collate;
3901 r->formname = talloc_strdup(mem_ctx, ntdevmode->formname);
3902 W_ERROR_HAVE_NO_MEMORY(r->formname);
3904 /* all 0 below are values that have not been set in the old parsing/copy
3905 * function, maybe they should... - gd */
3907 r->logpixels = 0;
3908 r->bitsperpel = 0;
3909 r->pelswidth = 0;
3910 r->pelsheight = 0;
3911 r->displayflags = 0;
3912 r->displayfrequency = 0;
3913 r->icmmethod = ntdevmode->icmmethod;
3914 r->icmintent = ntdevmode->icmintent;
3915 r->mediatype = ntdevmode->mediatype;
3916 r->dithertype = ntdevmode->dithertype;
3917 r->reserved1 = 0;
3918 r->reserved2 = 0;
3919 r->panningwidth = 0;
3920 r->panningheight = 0;
3922 if (ntdevmode->nt_dev_private != NULL) {
3923 r->driverextra_data = data_blob_talloc(mem_ctx,
3924 ntdevmode->nt_dev_private,
3925 ntdevmode->driverextra);
3926 W_ERROR_HAVE_NO_MEMORY(r->driverextra_data.data);
3929 return WERR_OK;
3933 /****************************************************************************
3934 Create a spoolss_DeviceMode struct. Returns talloced memory.
3935 ****************************************************************************/
3937 struct spoolss_DeviceMode *construct_dev_mode(TALLOC_CTX *mem_ctx,
3938 const char *servicename)
3940 WERROR result;
3941 NT_PRINTER_INFO_LEVEL *printer = NULL;
3942 struct spoolss_DeviceMode *devmode = NULL;
3944 DEBUG(7,("construct_dev_mode\n"));
3946 DEBUGADD(8,("getting printer characteristics\n"));
3948 if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, servicename)))
3949 return NULL;
3951 if (!printer->info_2->devmode) {
3952 DEBUG(5, ("BONG! There was no device mode!\n"));
3953 goto done;
3956 devmode = TALLOC_ZERO_P(mem_ctx, struct spoolss_DeviceMode);
3957 if (!devmode) {
3958 DEBUG(2,("construct_dev_mode: talloc fail.\n"));
3959 goto done;
3962 DEBUGADD(8,("loading DEVICEMODE\n"));
3964 result = convert_nt_devicemode(mem_ctx, devmode, printer->info_2->devmode);
3965 if (!W_ERROR_IS_OK(result)) {
3966 TALLOC_FREE(devmode);
3969 done:
3970 free_a_printer(&printer,2);
3972 return devmode;
3975 /********************************************************************
3976 * construct_printer_info3
3977 * fill a spoolss_PrinterInfo3 struct
3978 ********************************************************************/
3980 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
3981 const NT_PRINTER_INFO_LEVEL *ntprinter,
3982 struct spoolss_PrinterInfo3 *r,
3983 int snum)
3985 /* These are the components of the SD we are returning. */
3987 if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->sd_size != 0) {
3988 /* don't use talloc_steal() here unless you do a deep steal of all
3989 the SEC_DESC members */
3991 r->secdesc = dup_sec_desc(mem_ctx,
3992 ntprinter->info_2->secdesc_buf->sd);
3993 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
3996 return WERR_OK;
3999 /********************************************************************
4000 * construct_printer_info4
4001 * fill a spoolss_PrinterInfo4 struct
4002 ********************************************************************/
4004 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
4005 const NT_PRINTER_INFO_LEVEL *ntprinter,
4006 struct spoolss_PrinterInfo4 *r,
4007 int snum)
4009 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
4010 W_ERROR_HAVE_NO_MEMORY(r->printername);
4011 r->servername = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
4012 W_ERROR_HAVE_NO_MEMORY(r->servername);
4014 r->attributes = ntprinter->info_2->attributes;
4016 return WERR_OK;
4019 /********************************************************************
4020 * construct_printer_info5
4021 * fill a spoolss_PrinterInfo5 struct
4022 ********************************************************************/
4024 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
4025 const NT_PRINTER_INFO_LEVEL *ntprinter,
4026 struct spoolss_PrinterInfo5 *r,
4027 int snum)
4029 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
4030 W_ERROR_HAVE_NO_MEMORY(r->printername);
4031 r->portname = talloc_strdup(mem_ctx, ntprinter->info_2->portname);
4032 W_ERROR_HAVE_NO_MEMORY(r->portname);
4034 r->attributes = ntprinter->info_2->attributes;
4036 /* these two are not used by NT+ according to MSDN */
4038 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
4039 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
4041 return WERR_OK;
4044 /********************************************************************
4045 * construct_printer_info_6
4046 * fill a spoolss_PrinterInfo6 struct
4047 ********************************************************************/
4049 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
4050 const NT_PRINTER_INFO_LEVEL *ntprinter,
4051 struct spoolss_PrinterInfo6 *r,
4052 int snum)
4054 int count;
4055 print_status_struct status;
4057 count = print_queue_length(snum, &status);
4059 r->status = nt_printq_status(status.status);
4061 return WERR_OK;
4064 /********************************************************************
4065 * construct_printer_info7
4066 * fill a spoolss_PrinterInfo7 struct
4067 ********************************************************************/
4069 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
4070 Printer_entry *print_hnd,
4071 struct spoolss_PrinterInfo7 *r,
4072 int snum)
4074 struct GUID guid;
4076 if (is_printer_published(print_hnd, snum, &guid)) {
4077 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
4078 r->action = DSPRINT_PUBLISH;
4079 } else {
4080 r->guid = talloc_strdup(mem_ctx, "");
4081 r->action = DSPRINT_UNPUBLISH;
4083 W_ERROR_HAVE_NO_MEMORY(r->guid);
4085 return WERR_OK;
4088 /********************************************************************
4089 * construct_printer_info8
4090 * fill a spoolss_PrinterInfo8 struct
4091 ********************************************************************/
4093 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
4094 const NT_PRINTER_INFO_LEVEL *ntprinter,
4095 struct spoolss_DeviceModeInfo *r,
4096 int snum)
4098 struct spoolss_DeviceMode *devmode;
4099 WERROR result;
4101 if (!ntprinter->info_2->devmode) {
4102 r->devmode = NULL;
4103 return WERR_OK;
4106 devmode = TALLOC_ZERO_P(mem_ctx, struct spoolss_DeviceMode);
4107 W_ERROR_HAVE_NO_MEMORY(devmode);
4109 result = convert_nt_devicemode(mem_ctx, devmode, ntprinter->info_2->devmode);
4110 if (!W_ERROR_IS_OK(result)) {
4111 TALLOC_FREE(devmode);
4112 return result;
4115 r->devmode = devmode;
4117 return WERR_OK;
4121 /********************************************************************
4122 * construct_printer_info1
4123 * fill a spoolss_PrinterInfo1 struct
4124 ********************************************************************/
4126 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
4127 const NT_PRINTER_INFO_LEVEL *ntprinter,
4128 uint32_t flags,
4129 struct spoolss_PrinterInfo1 *r,
4130 int snum)
4132 r->flags = flags;
4134 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
4135 ntprinter->info_2->printername,
4136 ntprinter->info_2->drivername,
4137 ntprinter->info_2->location);
4138 W_ERROR_HAVE_NO_MEMORY(r->description);
4140 if (*ntprinter->info_2->comment == '\0') {
4141 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
4142 } else {
4143 r->comment = talloc_strdup(mem_ctx, ntprinter->info_2->comment); /* saved comment */
4145 W_ERROR_HAVE_NO_MEMORY(r->comment);
4147 r->name = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
4148 W_ERROR_HAVE_NO_MEMORY(r->name);
4150 return WERR_OK;
4153 /********************************************************************
4154 * construct_printer_info2
4155 * fill a spoolss_PrinterInfo2 struct
4156 ********************************************************************/
4158 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
4159 const NT_PRINTER_INFO_LEVEL *ntprinter,
4160 struct spoolss_PrinterInfo2 *r,
4161 int snum)
4163 int count;
4165 print_status_struct status;
4167 count = print_queue_length(snum, &status);
4169 r->servername = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
4170 W_ERROR_HAVE_NO_MEMORY(r->servername);
4171 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
4172 W_ERROR_HAVE_NO_MEMORY(r->printername);
4173 r->sharename = talloc_strdup(mem_ctx, lp_servicename(snum));
4174 W_ERROR_HAVE_NO_MEMORY(r->sharename);
4175 r->portname = talloc_strdup(mem_ctx, ntprinter->info_2->portname);
4176 W_ERROR_HAVE_NO_MEMORY(r->portname);
4177 r->drivername = talloc_strdup(mem_ctx, ntprinter->info_2->drivername);
4178 W_ERROR_HAVE_NO_MEMORY(r->drivername);
4180 if (*ntprinter->info_2->comment == '\0') {
4181 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
4182 } else {
4183 r->comment = talloc_strdup(mem_ctx, ntprinter->info_2->comment);
4185 W_ERROR_HAVE_NO_MEMORY(r->comment);
4187 r->location = talloc_strdup(mem_ctx, ntprinter->info_2->location);
4188 W_ERROR_HAVE_NO_MEMORY(r->location);
4189 r->sepfile = talloc_strdup(mem_ctx, ntprinter->info_2->sepfile);
4190 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
4191 r->printprocessor = talloc_strdup(mem_ctx, ntprinter->info_2->printprocessor);
4192 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
4193 r->datatype = talloc_strdup(mem_ctx, ntprinter->info_2->datatype);
4194 W_ERROR_HAVE_NO_MEMORY(r->datatype);
4195 r->parameters = talloc_strdup(mem_ctx, ntprinter->info_2->parameters);
4196 W_ERROR_HAVE_NO_MEMORY(r->parameters);
4198 r->attributes = ntprinter->info_2->attributes;
4200 r->priority = ntprinter->info_2->priority;
4201 r->defaultpriority = ntprinter->info_2->default_priority;
4202 r->starttime = ntprinter->info_2->starttime;
4203 r->untiltime = ntprinter->info_2->untiltime;
4204 r->status = nt_printq_status(status.status);
4205 r->cjobs = count;
4206 r->averageppm = ntprinter->info_2->averageppm;
4208 r->devmode = construct_dev_mode(mem_ctx, lp_const_servicename(snum));
4209 if (!r->devmode) {
4210 DEBUG(8,("Returning NULL Devicemode!\n"));
4213 r->secdesc = NULL;
4215 if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->sd_size != 0) {
4216 /* don't use talloc_steal() here unless you do a deep steal of all
4217 the SEC_DESC members */
4219 r->secdesc = dup_sec_desc(mem_ctx, ntprinter->info_2->secdesc_buf->sd);
4222 return WERR_OK;
4225 /********************************************************************
4226 ********************************************************************/
4228 static bool snum_is_shared_printer(int snum)
4230 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
4233 /********************************************************************
4234 Spoolss_enumprinters.
4235 ********************************************************************/
4237 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
4238 uint32_t level,
4239 uint32_t flags,
4240 union spoolss_PrinterInfo **info_p,
4241 uint32_t *count_p)
4243 int snum;
4244 int n_services = lp_numservices();
4245 union spoolss_PrinterInfo *info = NULL;
4246 uint32_t count = 0;
4247 WERROR result = WERR_OK;
4249 *count_p = 0;
4250 *info_p = NULL;
4252 for (snum = 0; snum < n_services; snum++) {
4254 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
4256 if (!snum_is_shared_printer(snum)) {
4257 continue;
4260 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
4261 lp_servicename(snum), snum));
4263 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4264 union spoolss_PrinterInfo,
4265 count + 1);
4266 if (!info) {
4267 result = WERR_NOMEM;
4268 goto out;
4271 result = get_a_printer(NULL, &ntprinter, 2,
4272 lp_const_servicename(snum));
4273 if (!W_ERROR_IS_OK(result)) {
4274 goto out;
4277 switch (level) {
4278 case 0:
4279 result = construct_printer_info0(info, ntprinter,
4280 &info[count].info0, snum);
4281 break;
4282 case 1:
4283 result = construct_printer_info1(info, ntprinter, flags,
4284 &info[count].info1, snum);
4285 break;
4286 case 2:
4287 result = construct_printer_info2(info, ntprinter,
4288 &info[count].info2, snum);
4289 break;
4290 case 4:
4291 result = construct_printer_info4(info, ntprinter,
4292 &info[count].info4, snum);
4293 break;
4294 case 5:
4295 result = construct_printer_info5(info, ntprinter,
4296 &info[count].info5, snum);
4297 break;
4299 default:
4300 result = WERR_UNKNOWN_LEVEL;
4301 free_a_printer(&ntprinter, 2);
4302 goto out;
4305 free_a_printer(&ntprinter, 2);
4306 if (!W_ERROR_IS_OK(result)) {
4307 goto out;
4310 count++;
4313 *count_p = count;
4314 *info_p = info;
4316 out:
4317 if (!W_ERROR_IS_OK(result)) {
4318 TALLOC_FREE(info);
4319 return result;
4322 *info_p = info;
4324 return WERR_OK;
4327 /********************************************************************
4328 * handle enumeration of printers at level 0
4329 ********************************************************************/
4331 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
4332 uint32_t flags,
4333 const char *servername,
4334 union spoolss_PrinterInfo **info,
4335 uint32_t *count)
4337 DEBUG(4,("enum_all_printers_info_0\n"));
4339 return enum_all_printers_info_level(mem_ctx, 0, flags, info, count);
4343 /********************************************************************
4344 ********************************************************************/
4346 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
4347 uint32_t flags,
4348 union spoolss_PrinterInfo **info,
4349 uint32_t *count)
4351 DEBUG(4,("enum_all_printers_info_1\n"));
4353 return enum_all_printers_info_level(mem_ctx, 1, flags, info, count);
4356 /********************************************************************
4357 enum_all_printers_info_1_local.
4358 *********************************************************************/
4360 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
4361 union spoolss_PrinterInfo **info,
4362 uint32_t *count)
4364 DEBUG(4,("enum_all_printers_info_1_local\n"));
4366 return enum_all_printers_info_1(mem_ctx, PRINTER_ENUM_ICON8, info, count);
4369 /********************************************************************
4370 enum_all_printers_info_1_name.
4371 *********************************************************************/
4373 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
4374 const char *name,
4375 union spoolss_PrinterInfo **info,
4376 uint32_t *count)
4378 const char *s = name;
4380 DEBUG(4,("enum_all_printers_info_1_name\n"));
4382 if ((name[0] == '\\') && (name[1] == '\\')) {
4383 s = name + 2;
4386 if (!is_myname_or_ipaddr(s)) {
4387 return WERR_INVALID_NAME;
4390 return enum_all_printers_info_1(mem_ctx, PRINTER_ENUM_ICON8, info, count);
4393 /********************************************************************
4394 enum_all_printers_info_1_network.
4395 *********************************************************************/
4397 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
4398 const char *name,
4399 union spoolss_PrinterInfo **info,
4400 uint32_t *count)
4402 const char *s = name;
4404 DEBUG(4,("enum_all_printers_info_1_network\n"));
4406 /* If we respond to a enum_printers level 1 on our name with flags
4407 set to PRINTER_ENUM_REMOTE with a list of printers then these
4408 printers incorrectly appear in the APW browse list.
4409 Specifically the printers for the server appear at the workgroup
4410 level where all the other servers in the domain are
4411 listed. Windows responds to this call with a
4412 WERR_CAN_NOT_COMPLETE so we should do the same. */
4414 if (name[0] == '\\' && name[1] == '\\') {
4415 s = name + 2;
4418 if (is_myname_or_ipaddr(s)) {
4419 return WERR_CAN_NOT_COMPLETE;
4422 return enum_all_printers_info_1(mem_ctx, PRINTER_ENUM_NAME, info, count);
4425 /********************************************************************
4426 * api_spoolss_enumprinters
4428 * called from api_spoolss_enumprinters (see this to understand)
4429 ********************************************************************/
4431 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
4432 union spoolss_PrinterInfo **info,
4433 uint32_t *count)
4435 DEBUG(4,("enum_all_printers_info_2\n"));
4437 return enum_all_printers_info_level(mem_ctx, 2, 0, info, count);
4440 /********************************************************************
4441 * handle enumeration of printers at level 1
4442 ********************************************************************/
4444 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
4445 uint32_t flags,
4446 const char *name,
4447 union spoolss_PrinterInfo **info,
4448 uint32_t *count)
4450 /* Not all the flags are equals */
4452 if (flags & PRINTER_ENUM_LOCAL) {
4453 return enum_all_printers_info_1_local(mem_ctx, info, count);
4456 if (flags & PRINTER_ENUM_NAME) {
4457 return enum_all_printers_info_1_name(mem_ctx, name, info, count);
4460 if (flags & PRINTER_ENUM_NETWORK) {
4461 return enum_all_printers_info_1_network(mem_ctx, name, info, count);
4464 return WERR_OK; /* NT4sp5 does that */
4467 /********************************************************************
4468 * handle enumeration of printers at level 2
4469 ********************************************************************/
4471 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4472 uint32_t flags,
4473 const char *servername,
4474 union spoolss_PrinterInfo **info,
4475 uint32_t *count)
4477 if (flags & PRINTER_ENUM_LOCAL) {
4478 return enum_all_printers_info_2(mem_ctx, info, count);
4481 if (flags & PRINTER_ENUM_NAME) {
4482 if (!is_myname_or_ipaddr(canon_servername(servername))) {
4483 return WERR_INVALID_NAME;
4486 return enum_all_printers_info_2(mem_ctx, info, count);
4489 if (flags & PRINTER_ENUM_REMOTE) {
4490 return WERR_UNKNOWN_LEVEL;
4493 return WERR_OK;
4496 /********************************************************************
4497 * handle enumeration of printers at level 4
4498 ********************************************************************/
4500 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4501 uint32_t flags,
4502 const char *servername,
4503 union spoolss_PrinterInfo **info,
4504 uint32_t *count)
4506 DEBUG(4,("enum_all_printers_info_4\n"));
4508 return enum_all_printers_info_level(mem_ctx, 4, flags, info, count);
4512 /********************************************************************
4513 * handle enumeration of printers at level 5
4514 ********************************************************************/
4516 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4517 uint32_t flags,
4518 const char *servername,
4519 union spoolss_PrinterInfo **info,
4520 uint32_t *count)
4522 DEBUG(4,("enum_all_printers_info_5\n"));
4524 return enum_all_printers_info_level(mem_ctx, 5, flags, info, count);
4527 /****************************************************************
4528 _spoolss_EnumPrinters
4529 ****************************************************************/
4531 WERROR _spoolss_EnumPrinters(pipes_struct *p,
4532 struct spoolss_EnumPrinters *r)
4534 const char *name;
4535 WERROR result;
4537 /* that's an [in out] buffer */
4539 if (!r->in.buffer && (r->in.offered != 0)) {
4540 return WERR_INVALID_PARAM;
4543 DEBUG(4,("_spoolss_EnumPrinters\n"));
4545 *r->out.needed = 0;
4546 *r->out.count = 0;
4547 *r->out.info = NULL;
4550 * Level 1:
4551 * flags==PRINTER_ENUM_NAME
4552 * if name=="" then enumerates all printers
4553 * if name!="" then enumerate the printer
4554 * flags==PRINTER_ENUM_REMOTE
4555 * name is NULL, enumerate printers
4556 * Level 2: name!="" enumerates printers, name can't be NULL
4557 * Level 3: doesn't exist
4558 * Level 4: does a local registry lookup
4559 * Level 5: same as Level 2
4562 name = talloc_strdup_upper(p->mem_ctx, r->in.server);
4563 W_ERROR_HAVE_NO_MEMORY(name);
4565 switch (r->in.level) {
4566 case 0:
4567 result = enumprinters_level0(p->mem_ctx, r->in.flags, name,
4568 r->out.info, r->out.count);
4569 break;
4570 case 1:
4571 result = enumprinters_level1(p->mem_ctx, r->in.flags, name,
4572 r->out.info, r->out.count);
4573 break;
4574 case 2:
4575 result = enumprinters_level2(p->mem_ctx, r->in.flags, name,
4576 r->out.info, r->out.count);
4577 break;
4578 case 4:
4579 result = enumprinters_level4(p->mem_ctx, r->in.flags, name,
4580 r->out.info, r->out.count);
4581 break;
4582 case 5:
4583 result = enumprinters_level5(p->mem_ctx, r->in.flags, name,
4584 r->out.info, r->out.count);
4585 break;
4586 default:
4587 return WERR_UNKNOWN_LEVEL;
4590 if (!W_ERROR_IS_OK(result)) {
4591 return result;
4594 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4595 spoolss_EnumPrinters, NULL,
4596 *r->out.info, r->in.level,
4597 *r->out.count);
4598 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4599 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4601 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4604 /****************************************************************
4605 _spoolss_GetPrinter
4606 ****************************************************************/
4608 WERROR _spoolss_GetPrinter(pipes_struct *p,
4609 struct spoolss_GetPrinter *r)
4611 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
4612 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
4613 WERROR result = WERR_OK;
4615 int snum;
4617 /* that's an [in out] buffer */
4619 if (!r->in.buffer && (r->in.offered != 0)) {
4620 return WERR_INVALID_PARAM;
4623 *r->out.needed = 0;
4625 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4626 return WERR_BADFID;
4629 result = get_a_printer(Printer, &ntprinter, 2,
4630 lp_const_servicename(snum));
4631 if (!W_ERROR_IS_OK(result)) {
4632 return result;
4635 switch (r->in.level) {
4636 case 0:
4637 result = construct_printer_info0(p->mem_ctx, ntprinter,
4638 &r->out.info->info0, snum);
4639 break;
4640 case 1:
4641 result = construct_printer_info1(p->mem_ctx, ntprinter,
4642 PRINTER_ENUM_ICON8,
4643 &r->out.info->info1, snum);
4644 break;
4645 case 2:
4646 result = construct_printer_info2(p->mem_ctx, ntprinter,
4647 &r->out.info->info2, snum);
4648 break;
4649 case 3:
4650 result = construct_printer_info3(p->mem_ctx, ntprinter,
4651 &r->out.info->info3, snum);
4652 break;
4653 case 4:
4654 result = construct_printer_info4(p->mem_ctx, ntprinter,
4655 &r->out.info->info4, snum);
4656 break;
4657 case 5:
4658 result = construct_printer_info5(p->mem_ctx, ntprinter,
4659 &r->out.info->info5, snum);
4660 break;
4661 case 6:
4662 result = construct_printer_info6(p->mem_ctx, ntprinter,
4663 &r->out.info->info6, snum);
4664 break;
4665 case 7:
4666 result = construct_printer_info7(p->mem_ctx, Printer,
4667 &r->out.info->info7, snum);
4668 break;
4669 case 8:
4670 result = construct_printer_info8(p->mem_ctx, ntprinter,
4671 &r->out.info->info8, snum);
4672 break;
4673 default:
4674 result = WERR_UNKNOWN_LEVEL;
4675 break;
4678 free_a_printer(&ntprinter, 2);
4680 if (!W_ERROR_IS_OK(result)) {
4681 TALLOC_FREE(r->out.info);
4682 return result;
4685 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo, NULL,
4686 r->out.info, r->in.level);
4687 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4689 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4692 /********************************************************************
4693 ********************************************************************/
4695 static const char **string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4696 fstring *fstring_array,
4697 const char *cservername)
4699 int i, num_strings = 0;
4700 const char **array = NULL;
4702 for (i=0; fstring_array && fstring_array[i][0] != '\0'; i++) {
4704 const char *str = talloc_asprintf(mem_ctx, "\\\\%s%s",
4705 cservername, fstring_array[i]);
4706 if (!str) {
4707 TALLOC_FREE(array);
4708 return NULL;
4712 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4713 TALLOC_FREE(array);
4714 return NULL;
4718 if (i > 0) {
4719 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4720 &array, &num_strings);
4723 return array;
4726 /********************************************************************
4727 * fill a spoolss_DriverInfo1 struct
4728 ********************************************************************/
4730 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4731 struct spoolss_DriverInfo1 *r,
4732 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
4733 const char *servername,
4734 const char *architecture)
4736 r->driver_name = talloc_strdup(mem_ctx, driver->info_3->name);
4737 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4739 return WERR_OK;
4742 /********************************************************************
4743 * fill a spoolss_DriverInfo2 struct
4744 ********************************************************************/
4746 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4747 struct spoolss_DriverInfo2 *r,
4748 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
4749 const char *servername)
4752 const char *cservername = canon_servername(servername);
4754 r->version = driver->info_3->cversion;
4756 r->driver_name = talloc_strdup(mem_ctx, driver->info_3->name);
4757 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4758 r->architecture = talloc_strdup(mem_ctx, driver->info_3->environment);
4759 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4761 if (strlen(driver->info_3->driverpath)) {
4762 r->driver_path = talloc_asprintf(mem_ctx, "\\\\%s%s",
4763 cservername, driver->info_3->driverpath);
4764 } else {
4765 r->driver_path = talloc_strdup(mem_ctx, "");
4767 W_ERROR_HAVE_NO_MEMORY(r->driver_path);
4769 if (strlen(driver->info_3->datafile)) {
4770 r->data_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4771 cservername, driver->info_3->datafile);
4772 } else {
4773 r->data_file = talloc_strdup(mem_ctx, "");
4775 W_ERROR_HAVE_NO_MEMORY(r->data_file);
4777 if (strlen(driver->info_3->configfile)) {
4778 r->config_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4779 cservername, driver->info_3->configfile);
4780 } else {
4781 r->config_file = talloc_strdup(mem_ctx, "");
4783 W_ERROR_HAVE_NO_MEMORY(r->config_file);
4785 return WERR_OK;
4788 /********************************************************************
4789 * fill a spoolss_DriverInfo3 struct
4790 ********************************************************************/
4792 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4793 struct spoolss_DriverInfo3 *r,
4794 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
4795 const char *servername)
4797 const char *cservername = canon_servername(servername);
4799 r->version = driver->info_3->cversion;
4801 r->driver_name = talloc_strdup(mem_ctx, driver->info_3->name);
4802 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4803 r->architecture = talloc_strdup(mem_ctx, driver->info_3->environment);
4804 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4806 if (strlen(driver->info_3->driverpath)) {
4807 r->driver_path = talloc_asprintf(mem_ctx, "\\\\%s%s",
4808 cservername, driver->info_3->driverpath);
4809 } else {
4810 r->driver_path = talloc_strdup(mem_ctx, "");
4812 W_ERROR_HAVE_NO_MEMORY(r->driver_path);
4814 if (strlen(driver->info_3->datafile)) {
4815 r->data_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4816 cservername, driver->info_3->datafile);
4817 } else {
4818 r->data_file = talloc_strdup(mem_ctx, "");
4820 W_ERROR_HAVE_NO_MEMORY(r->data_file);
4822 if (strlen(driver->info_3->configfile)) {
4823 r->config_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4824 cservername, driver->info_3->configfile);
4825 } else {
4826 r->config_file = talloc_strdup(mem_ctx, "");
4828 W_ERROR_HAVE_NO_MEMORY(r->config_file);
4830 if (strlen(driver->info_3->helpfile)) {
4831 r->help_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4832 cservername, driver->info_3->helpfile);
4833 } else {
4834 r->help_file = talloc_strdup(mem_ctx, "");
4836 W_ERROR_HAVE_NO_MEMORY(r->help_file);
4838 r->monitor_name = talloc_strdup(mem_ctx, driver->info_3->monitorname);
4839 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
4840 r->default_datatype = talloc_strdup(mem_ctx, driver->info_3->defaultdatatype);
4841 W_ERROR_HAVE_NO_MEMORY(r->default_datatype);
4843 r->dependent_files = string_array_from_driver_info(mem_ctx,
4844 driver->info_3->dependentfiles,
4845 cservername);
4846 return WERR_OK;
4849 /********************************************************************
4850 * fill a spoolss_DriverInfo4 struct
4851 ********************************************************************/
4853 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
4854 struct spoolss_DriverInfo4 *r,
4855 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
4856 const char *servername)
4858 const char *cservername = canon_servername(servername);
4860 r->version = driver->info_3->cversion;
4862 r->driver_name = talloc_strdup(mem_ctx, driver->info_3->name);
4863 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4864 r->architecture = talloc_strdup(mem_ctx, driver->info_3->environment);
4865 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4867 if (strlen(driver->info_3->driverpath)) {
4868 r->driver_path = talloc_asprintf(mem_ctx, "\\\\%s%s",
4869 cservername, driver->info_3->driverpath);
4870 } else {
4871 r->driver_path = talloc_strdup(mem_ctx, "");
4873 W_ERROR_HAVE_NO_MEMORY(r->driver_path);
4875 if (strlen(driver->info_3->datafile)) {
4876 r->data_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4877 cservername, driver->info_3->datafile);
4878 } else {
4879 r->data_file = talloc_strdup(mem_ctx, "");
4881 W_ERROR_HAVE_NO_MEMORY(r->data_file);
4883 if (strlen(driver->info_3->configfile)) {
4884 r->config_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4885 cservername, driver->info_3->configfile);
4886 } else {
4887 r->config_file = talloc_strdup(mem_ctx, "");
4889 W_ERROR_HAVE_NO_MEMORY(r->config_file);
4891 if (strlen(driver->info_3->helpfile)) {
4892 r->help_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4893 cservername, driver->info_3->helpfile);
4894 } else {
4895 r->help_file = talloc_strdup(mem_ctx, "");
4897 W_ERROR_HAVE_NO_MEMORY(r->help_file);
4899 r->dependent_files = string_array_from_driver_info(mem_ctx,
4900 driver->info_3->dependentfiles,
4901 cservername);
4904 r->monitor_name = talloc_strdup(mem_ctx, driver->info_3->monitorname);
4905 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
4906 r->default_datatype = talloc_strdup(mem_ctx, driver->info_3->defaultdatatype);
4907 W_ERROR_HAVE_NO_MEMORY(r->default_datatype);
4909 r->previous_names = string_array_from_driver_info(mem_ctx,
4910 NULL,
4911 cservername);
4913 return WERR_OK;
4916 /********************************************************************
4917 * fill a spoolss_DriverInfo5 struct
4918 ********************************************************************/
4920 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
4921 struct spoolss_DriverInfo5 *r,
4922 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
4923 const char *servername)
4925 const char *cservername = canon_servername(servername);
4927 r->version = driver->info_3->cversion;
4929 r->driver_name = talloc_strdup(mem_ctx, driver->info_3->name);
4930 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4931 r->architecture = talloc_strdup(mem_ctx, driver->info_3->environment);
4932 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4934 if (strlen(driver->info_3->driverpath)) {
4935 r->driver_path = talloc_asprintf(mem_ctx, "\\\\%s%s",
4936 cservername, driver->info_3->driverpath);
4937 } else {
4938 r->driver_path = talloc_strdup(mem_ctx, "");
4940 W_ERROR_HAVE_NO_MEMORY(r->driver_path);
4942 if (strlen(driver->info_3->datafile)) {
4943 r->data_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4944 cservername, driver->info_3->datafile);
4945 } else {
4946 r->data_file = talloc_strdup(mem_ctx, "");
4948 W_ERROR_HAVE_NO_MEMORY(r->data_file);
4950 if (strlen(driver->info_3->configfile)) {
4951 r->config_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4952 cservername, driver->info_3->configfile);
4953 } else {
4954 r->config_file = talloc_strdup(mem_ctx, "");
4956 W_ERROR_HAVE_NO_MEMORY(r->config_file);
4958 r->driver_attributes = 0;
4959 r->config_version = 0;
4960 r->driver_version = 0;
4962 return WERR_OK;
4964 /********************************************************************
4965 * fill a spoolss_DriverInfo6 struct
4966 ********************************************************************/
4968 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
4969 struct spoolss_DriverInfo6 *r,
4970 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
4971 const char *servername)
4973 const char *cservername = canon_servername(servername);
4975 r->version = driver->info_3->cversion;
4977 r->driver_name = talloc_strdup(mem_ctx, driver->info_3->name);
4978 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4979 r->architecture = talloc_strdup(mem_ctx, driver->info_3->environment);
4980 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4982 if (strlen(driver->info_3->driverpath)) {
4983 r->driver_path = talloc_asprintf(mem_ctx, "\\\\%s%s",
4984 cservername, driver->info_3->driverpath);
4985 } else {
4986 r->driver_path = talloc_strdup(mem_ctx, "");
4988 W_ERROR_HAVE_NO_MEMORY(r->driver_path);
4990 if (strlen(driver->info_3->datafile)) {
4991 r->data_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4992 cservername, driver->info_3->datafile);
4993 } else {
4994 r->data_file = talloc_strdup(mem_ctx, "");
4996 W_ERROR_HAVE_NO_MEMORY(r->data_file);
4998 if (strlen(driver->info_3->configfile)) {
4999 r->config_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
5000 cservername, driver->info_3->configfile);
5001 } else {
5002 r->config_file = talloc_strdup(mem_ctx, "");
5004 W_ERROR_HAVE_NO_MEMORY(r->config_file);
5006 if (strlen(driver->info_3->helpfile)) {
5007 r->help_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
5008 cservername, driver->info_3->helpfile);
5009 } else {
5010 r->help_file = talloc_strdup(mem_ctx, "");
5012 W_ERROR_HAVE_NO_MEMORY(r->help_file);
5014 r->monitor_name = talloc_strdup(mem_ctx, driver->info_3->monitorname);
5015 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
5016 r->default_datatype = talloc_strdup(mem_ctx, driver->info_3->defaultdatatype);
5017 W_ERROR_HAVE_NO_MEMORY(r->default_datatype);
5019 r->dependent_files = string_array_from_driver_info(mem_ctx,
5020 driver->info_3->dependentfiles,
5021 cservername);
5022 r->previous_names = string_array_from_driver_info(mem_ctx,
5023 NULL,
5024 cservername);
5026 r->driver_date = 0;
5027 r->driver_version = 0;
5029 r->manufacturer_name = talloc_strdup(mem_ctx, "");
5030 W_ERROR_HAVE_NO_MEMORY(r->manufacturer_name);
5031 r->manufacturer_url = talloc_strdup(mem_ctx, "");
5032 W_ERROR_HAVE_NO_MEMORY(r->manufacturer_url);
5033 r->hardware_id = talloc_strdup(mem_ctx, "");
5034 W_ERROR_HAVE_NO_MEMORY(r->hardware_id);
5035 r->provider = talloc_strdup(mem_ctx, "");
5036 W_ERROR_HAVE_NO_MEMORY(r->provider);
5038 return WERR_OK;
5041 /********************************************************************
5042 ********************************************************************/
5044 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
5045 struct spoolss_DriverFileInfo *r,
5046 const char *cservername,
5047 const char *file_name,
5048 enum spoolss_DriverFileType file_type,
5049 uint32_t file_version)
5051 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
5052 cservername, file_name);
5053 W_ERROR_HAVE_NO_MEMORY(r->file_name);
5054 r->file_type = file_type;
5055 r->file_version = file_version;
5057 return WERR_OK;
5060 /********************************************************************
5061 ********************************************************************/
5063 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
5064 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
5065 const char *cservername,
5066 struct spoolss_DriverFileInfo **info_p,
5067 uint32_t *count_p)
5069 struct spoolss_DriverFileInfo *info = NULL;
5070 uint32_t count = 0;
5071 WERROR result;
5072 uint32_t i;
5074 *info_p = NULL;
5075 *count_p = 0;
5077 if (strlen(driver->info_3->driverpath)) {
5078 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5079 struct spoolss_DriverFileInfo,
5080 count + 1);
5081 W_ERROR_HAVE_NO_MEMORY(info);
5082 result = fill_spoolss_DriverFileInfo(info,
5083 &info[count],
5084 cservername,
5085 driver->info_3->driverpath,
5086 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
5088 W_ERROR_NOT_OK_RETURN(result);
5089 count++;
5092 if (strlen(driver->info_3->configfile)) {
5093 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5094 struct spoolss_DriverFileInfo,
5095 count + 1);
5096 W_ERROR_HAVE_NO_MEMORY(info);
5097 result = fill_spoolss_DriverFileInfo(info,
5098 &info[count],
5099 cservername,
5100 driver->info_3->configfile,
5101 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
5103 W_ERROR_NOT_OK_RETURN(result);
5104 count++;
5107 if (strlen(driver->info_3->datafile)) {
5108 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5109 struct spoolss_DriverFileInfo,
5110 count + 1);
5111 W_ERROR_HAVE_NO_MEMORY(info);
5112 result = fill_spoolss_DriverFileInfo(info,
5113 &info[count],
5114 cservername,
5115 driver->info_3->datafile,
5116 SPOOLSS_DRIVER_FILE_TYPE_DATA,
5118 W_ERROR_NOT_OK_RETURN(result);
5119 count++;
5122 if (strlen(driver->info_3->helpfile)) {
5123 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5124 struct spoolss_DriverFileInfo,
5125 count + 1);
5126 W_ERROR_HAVE_NO_MEMORY(info);
5127 result = fill_spoolss_DriverFileInfo(info,
5128 &info[count],
5129 cservername,
5130 driver->info_3->helpfile,
5131 SPOOLSS_DRIVER_FILE_TYPE_HELP,
5133 W_ERROR_NOT_OK_RETURN(result);
5134 count++;
5137 for (i=0; driver->info_3->dependentfiles[i][0] != '\0'; i++) {
5138 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5139 struct spoolss_DriverFileInfo,
5140 count + 1);
5141 W_ERROR_HAVE_NO_MEMORY(info);
5142 result = fill_spoolss_DriverFileInfo(info,
5143 &info[count],
5144 cservername,
5145 driver->info_3->dependentfiles[i],
5146 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
5148 W_ERROR_NOT_OK_RETURN(result);
5149 count++;
5152 *info_p = info;
5153 *count_p = count;
5155 return WERR_OK;
5158 /********************************************************************
5159 * fill a spoolss_DriverInfo101 sttruct
5160 ********************************************************************/
5162 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
5163 struct spoolss_DriverInfo101 *r,
5164 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
5165 const char *servername)
5167 const char *cservername = canon_servername(servername);
5168 WERROR result;
5170 r->version = driver->info_3->cversion;
5172 r->driver_name = talloc_strdup(mem_ctx, driver->info_3->name);
5173 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5174 r->architecture = talloc_strdup(mem_ctx, driver->info_3->environment);
5175 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5177 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
5178 cservername,
5179 &r->file_info,
5180 &r->file_count);
5181 if (!W_ERROR_IS_OK(result)) {
5182 return result;
5185 r->monitor_name = talloc_strdup(mem_ctx, driver->info_3->monitorname);
5186 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
5188 r->default_datatype = talloc_strdup(mem_ctx, driver->info_3->defaultdatatype);
5189 W_ERROR_HAVE_NO_MEMORY(r->default_datatype);
5191 r->previous_names = string_array_from_driver_info(mem_ctx,
5192 NULL,
5193 cservername);
5194 r->driver_date = 0;
5195 r->driver_version = 0;
5197 r->manufacturer_name = talloc_strdup(mem_ctx, "");
5198 W_ERROR_HAVE_NO_MEMORY(r->manufacturer_name);
5199 r->manufacturer_url = talloc_strdup(mem_ctx, "");
5200 W_ERROR_HAVE_NO_MEMORY(r->manufacturer_url);
5201 r->hardware_id = talloc_strdup(mem_ctx, "");
5202 W_ERROR_HAVE_NO_MEMORY(r->hardware_id);
5203 r->provider = talloc_strdup(mem_ctx, "");
5204 W_ERROR_HAVE_NO_MEMORY(r->provider);
5206 return WERR_OK;
5209 /********************************************************************
5210 * construct_printer_driver_info_1
5211 ********************************************************************/
5213 static WERROR construct_printer_driver_info_1(TALLOC_CTX *mem_ctx,
5214 struct spoolss_DriverInfo1 *r,
5215 int snum,
5216 const char *servername,
5217 const char *architecture,
5218 uint32_t version)
5220 NT_PRINTER_INFO_LEVEL *printer = NULL;
5221 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5222 WERROR result;
5224 ZERO_STRUCT(driver);
5226 if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, lp_const_servicename(snum))))
5227 return WERR_INVALID_PRINTER_NAME;
5229 if (!W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version))) {
5230 free_a_printer(&printer, 2);
5231 return WERR_UNKNOWN_PRINTER_DRIVER;
5234 result = fill_printer_driver_info1(mem_ctx, r, &driver, servername, architecture);
5236 free_a_printer(&printer,2);
5238 return result;
5241 /********************************************************************
5242 * construct_printer_driver_info_2
5243 * fill a printer_info_2 struct
5244 ********************************************************************/
5246 static WERROR construct_printer_driver_info_2(TALLOC_CTX *mem_ctx,
5247 struct spoolss_DriverInfo2 *r,
5248 int snum,
5249 const char *servername,
5250 const char *architecture,
5251 uint32_t version)
5253 NT_PRINTER_INFO_LEVEL *printer = NULL;
5254 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5255 WERROR result;
5257 ZERO_STRUCT(printer);
5258 ZERO_STRUCT(driver);
5260 if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, lp_const_servicename(snum))))
5261 return WERR_INVALID_PRINTER_NAME;
5263 if (!W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version))) {
5264 free_a_printer(&printer, 2);
5265 return WERR_UNKNOWN_PRINTER_DRIVER;
5268 result = fill_printer_driver_info2(mem_ctx, r, &driver, servername);
5270 free_a_printer(&printer,2);
5272 return result;
5275 /********************************************************************
5276 * construct_printer_info_3
5277 * fill a printer_info_3 struct
5278 ********************************************************************/
5280 static WERROR construct_printer_driver_info_3(TALLOC_CTX *mem_ctx,
5281 struct spoolss_DriverInfo3 *r,
5282 int snum,
5283 const char *servername,
5284 const char *architecture,
5285 uint32_t version)
5287 NT_PRINTER_INFO_LEVEL *printer = NULL;
5288 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5289 WERROR status;
5290 ZERO_STRUCT(driver);
5292 status=get_a_printer(NULL, &printer, 2, lp_const_servicename(snum) );
5293 DEBUG(8,("construct_printer_driver_info_3: status: %s\n", win_errstr(status)));
5294 if (!W_ERROR_IS_OK(status))
5295 return WERR_INVALID_PRINTER_NAME;
5297 status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version);
5298 DEBUG(8,("construct_printer_driver_info_3: status: %s\n", win_errstr(status)));
5300 #if 0 /* JERRY */
5303 * I put this code in during testing. Helpful when commenting out the
5304 * support for DRIVER_INFO_6 in regards to win2k. Not needed in general
5305 * as win2k always queries the driver using an infor level of 6.
5306 * I've left it in (but ifdef'd out) because I'll probably
5307 * use it in experimentation again in the future. --jerry 22/01/2002
5310 if (!W_ERROR_IS_OK(status)) {
5312 * Is this a W2k client ?
5314 if (version == 3) {
5315 /* Yes - try again with a WinNT driver. */
5316 version = 2;
5317 status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version);
5318 DEBUG(8,("construct_printer_driver_info_3: status: %s\n", win_errstr(status)));
5320 #endif
5322 if (!W_ERROR_IS_OK(status)) {
5323 free_a_printer(&printer,2);
5324 return WERR_UNKNOWN_PRINTER_DRIVER;
5327 #if 0 /* JERRY */
5329 #endif
5332 status = fill_printer_driver_info3(mem_ctx, r, &driver, servername);
5334 free_a_printer(&printer,2);
5336 return status;
5339 /********************************************************************
5340 * construct_printer_info_6
5341 * fill a printer_info_6 struct
5342 ********************************************************************/
5344 static WERROR construct_printer_driver_info_6(TALLOC_CTX *mem_ctx,
5345 struct spoolss_DriverInfo6 *r,
5346 int snum,
5347 const char *servername,
5348 const char *architecture,
5349 uint32_t version)
5351 NT_PRINTER_INFO_LEVEL *printer = NULL;
5352 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5353 WERROR status;
5355 ZERO_STRUCT(driver);
5357 status=get_a_printer(NULL, &printer, 2, lp_const_servicename(snum) );
5359 DEBUG(8,("construct_printer_driver_info_6: status: %s\n", win_errstr(status)));
5361 if (!W_ERROR_IS_OK(status))
5362 return WERR_INVALID_PRINTER_NAME;
5364 status = get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version);
5366 DEBUG(8,("construct_printer_driver_info_6: status: %s\n", win_errstr(status)));
5368 if (!W_ERROR_IS_OK(status))
5371 * Is this a W2k client ?
5374 if (version < 3) {
5375 free_a_printer(&printer,2);
5376 return WERR_UNKNOWN_PRINTER_DRIVER;
5379 /* Yes - try again with a WinNT driver. */
5380 version = 2;
5381 status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version);
5382 DEBUG(8,("construct_printer_driver_info_6: status: %s\n", win_errstr(status)));
5383 if (!W_ERROR_IS_OK(status)) {
5384 free_a_printer(&printer,2);
5385 return WERR_UNKNOWN_PRINTER_DRIVER;
5389 status = fill_printer_driver_info6(mem_ctx, r, &driver, servername);
5391 free_a_printer(&printer,2);
5392 free_a_printer_driver(driver, 3);
5394 return status;
5397 /********************************************************************
5398 * construct_printer_info_101
5399 * fill a printer_info_101 struct
5400 ********************************************************************/
5402 static WERROR construct_printer_driver_info_101(TALLOC_CTX *mem_ctx,
5403 struct spoolss_DriverInfo101 *r,
5404 int snum,
5405 const char *servername,
5406 const char *architecture,
5407 uint32_t version)
5409 NT_PRINTER_INFO_LEVEL *printer = NULL;
5410 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5411 WERROR result;
5413 ZERO_STRUCT(driver);
5415 result = get_a_printer(NULL, &printer, 2, lp_const_servicename(snum));
5417 DEBUG(8,("construct_printer_driver_info_101: status: %s\n",
5418 win_errstr(result)));
5420 if (!W_ERROR_IS_OK(result)) {
5421 return WERR_INVALID_PRINTER_NAME;
5424 result = get_a_printer_driver(&driver, 3, printer->info_2->drivername,
5425 architecture, version);
5427 DEBUG(8,("construct_printer_driver_info_101: status: %s\n",
5428 win_errstr(result)));
5430 if (!W_ERROR_IS_OK(result)) {
5432 * Is this a W2k client ?
5435 if (version < 3) {
5436 free_a_printer(&printer, 2);
5437 return WERR_UNKNOWN_PRINTER_DRIVER;
5440 /* Yes - try again with a WinNT driver. */
5441 version = 2;
5442 result = get_a_printer_driver(&driver, 3, printer->info_2->drivername,
5443 architecture, version);
5444 DEBUG(8,("construct_printer_driver_info_6: status: %s\n",
5445 win_errstr(result)));
5446 if (!W_ERROR_IS_OK(result)) {
5447 free_a_printer(&printer, 2);
5448 return WERR_UNKNOWN_PRINTER_DRIVER;
5452 result = fill_printer_driver_info101(mem_ctx, r, &driver, servername);
5454 free_a_printer(&printer, 2);
5455 free_a_printer_driver(driver, 3);
5457 return result;
5460 /****************************************************************
5461 _spoolss_GetPrinterDriver2
5462 ****************************************************************/
5464 WERROR _spoolss_GetPrinterDriver2(pipes_struct *p,
5465 struct spoolss_GetPrinterDriver2 *r)
5467 Printer_entry *printer;
5468 WERROR result;
5470 const char *servername;
5471 int snum;
5473 /* that's an [in out] buffer */
5475 if (!r->in.buffer && (r->in.offered != 0)) {
5476 return WERR_INVALID_PARAM;
5479 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5481 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5482 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5483 return WERR_INVALID_PRINTER_NAME;
5486 *r->out.needed = 0;
5487 *r->out.server_major_version = 0;
5488 *r->out.server_minor_version = 0;
5490 servername = get_server_name(printer);
5492 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5493 return WERR_BADFID;
5496 switch (r->in.level) {
5497 case 1:
5498 result = construct_printer_driver_info_1(p->mem_ctx,
5499 &r->out.info->info1,
5500 snum,
5501 servername,
5502 r->in.architecture,
5503 r->in.client_major_version);
5504 break;
5505 case 2:
5506 result = construct_printer_driver_info_2(p->mem_ctx,
5507 &r->out.info->info2,
5508 snum,
5509 servername,
5510 r->in.architecture,
5511 r->in.client_major_version);
5512 break;
5513 case 3:
5514 result = construct_printer_driver_info_3(p->mem_ctx,
5515 &r->out.info->info3,
5516 snum,
5517 servername,
5518 r->in.architecture,
5519 r->in.client_major_version);
5520 break;
5521 case 6:
5522 result = construct_printer_driver_info_6(p->mem_ctx,
5523 &r->out.info->info6,
5524 snum,
5525 servername,
5526 r->in.architecture,
5527 r->in.client_major_version);
5528 break;
5529 case 101:
5530 result = construct_printer_driver_info_101(p->mem_ctx,
5531 &r->out.info->info101,
5532 snum,
5533 servername,
5534 r->in.architecture,
5535 r->in.client_major_version);
5536 break;
5537 default:
5538 result = WERR_UNKNOWN_LEVEL;
5539 break;
5542 if (!W_ERROR_IS_OK(result)) {
5543 TALLOC_FREE(r->out.info);
5544 return result;
5547 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo, NULL,
5548 r->out.info, r->in.level);
5549 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5551 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5555 /****************************************************************
5556 _spoolss_StartPagePrinter
5557 ****************************************************************/
5559 WERROR _spoolss_StartPagePrinter(pipes_struct *p,
5560 struct spoolss_StartPagePrinter *r)
5562 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5564 if (!Printer) {
5565 DEBUG(3,("_spoolss_StartPagePrinter: "
5566 "Error in startpageprinter printer handle\n"));
5567 return WERR_BADFID;
5570 Printer->page_started = true;
5571 return WERR_OK;
5574 /****************************************************************
5575 _spoolss_EndPagePrinter
5576 ****************************************************************/
5578 WERROR _spoolss_EndPagePrinter(pipes_struct *p,
5579 struct spoolss_EndPagePrinter *r)
5581 int snum;
5583 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5585 if (!Printer) {
5586 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5587 OUR_HANDLE(r->in.handle)));
5588 return WERR_BADFID;
5591 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5592 return WERR_BADFID;
5594 Printer->page_started = false;
5595 print_job_endpage(snum, Printer->jobid);
5597 return WERR_OK;
5600 /****************************************************************
5601 _spoolss_StartDocPrinter
5602 ****************************************************************/
5604 WERROR _spoolss_StartDocPrinter(pipes_struct *p,
5605 struct spoolss_StartDocPrinter *r)
5607 struct spoolss_DocumentInfo1 *info_1;
5608 int snum;
5609 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5611 if (!Printer) {
5612 DEBUG(2,("_spoolss_StartDocPrinter: "
5613 "Invalid handle (%s:%u:%u)\n",
5614 OUR_HANDLE(r->in.handle)));
5615 return WERR_BADFID;
5618 if (r->in.level != 1) {
5619 return WERR_UNKNOWN_LEVEL;
5622 info_1 = r->in.info.info1;
5625 * a nice thing with NT is it doesn't listen to what you tell it.
5626 * when asked to send _only_ RAW datas, it tries to send datas
5627 * in EMF format.
5629 * So I add checks like in NT Server ...
5632 if (info_1->datatype) {
5633 if (strcmp(info_1->datatype, "RAW") != 0) {
5634 *r->out.job_id = 0;
5635 return WERR_INVALID_DATATYPE;
5639 /* get the share number of the printer */
5640 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5641 return WERR_BADFID;
5644 Printer->jobid = print_job_start(p->server_info, snum,
5645 info_1->document_name,
5646 Printer->nt_devmode);
5648 /* An error occured in print_job_start() so return an appropriate
5649 NT error code. */
5651 if (Printer->jobid == -1) {
5652 return map_werror_from_unix(errno);
5655 Printer->document_started = true;
5656 *r->out.job_id = Printer->jobid;
5658 return WERR_OK;
5661 /****************************************************************
5662 _spoolss_EndDocPrinter
5663 ****************************************************************/
5665 WERROR _spoolss_EndDocPrinter(pipes_struct *p,
5666 struct spoolss_EndDocPrinter *r)
5668 return _spoolss_enddocprinter_internal(p, r->in.handle);
5671 /****************************************************************
5672 _spoolss_WritePrinter
5673 ****************************************************************/
5675 WERROR _spoolss_WritePrinter(pipes_struct *p,
5676 struct spoolss_WritePrinter *r)
5678 uint32_t buffer_written;
5679 int snum;
5680 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5682 if (!Printer) {
5683 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5684 OUR_HANDLE(r->in.handle)));
5685 *r->out.num_written = r->in._data_size;
5686 return WERR_BADFID;
5689 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5690 return WERR_BADFID;
5692 buffer_written = (uint32_t)print_job_write(snum, Printer->jobid,
5693 (const char *)r->in.data.data,
5694 (SMB_OFF_T)-1,
5695 (size_t)r->in._data_size);
5696 if (buffer_written == (uint32_t)-1) {
5697 *r->out.num_written = 0;
5698 if (errno == ENOSPC)
5699 return WERR_NO_SPOOL_SPACE;
5700 else
5701 return WERR_ACCESS_DENIED;
5704 *r->out.num_written = r->in._data_size;
5706 return WERR_OK;
5709 /********************************************************************
5710 * api_spoolss_getprinter
5711 * called from the spoolss dispatcher
5713 ********************************************************************/
5715 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5716 pipes_struct *p)
5718 int snum;
5719 WERROR errcode = WERR_BADFUNC;
5720 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5722 if (!Printer) {
5723 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5724 OUR_HANDLE(handle)));
5725 return WERR_BADFID;
5728 if (!get_printer_snum(p, handle, &snum, NULL))
5729 return WERR_BADFID;
5731 switch (command) {
5732 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5733 if (print_queue_pause(p->server_info, snum, &errcode)) {
5734 errcode = WERR_OK;
5736 break;
5737 case SPOOLSS_PRINTER_CONTROL_RESUME:
5738 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5739 if (print_queue_resume(p->server_info, snum, &errcode)) {
5740 errcode = WERR_OK;
5742 break;
5743 case SPOOLSS_PRINTER_CONTROL_PURGE:
5744 if (print_queue_purge(p->server_info, snum, &errcode)) {
5745 errcode = WERR_OK;
5747 break;
5748 default:
5749 return WERR_UNKNOWN_LEVEL;
5752 return errcode;
5756 /****************************************************************
5757 _spoolss_AbortPrinter
5758 * From MSDN: "Deletes printer's spool file if printer is configured
5759 * for spooling"
5760 ****************************************************************/
5762 WERROR _spoolss_AbortPrinter(pipes_struct *p,
5763 struct spoolss_AbortPrinter *r)
5765 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5766 int snum;
5767 WERROR errcode = WERR_OK;
5769 if (!Printer) {
5770 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5771 OUR_HANDLE(r->in.handle)));
5772 return WERR_BADFID;
5775 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5776 return WERR_BADFID;
5778 print_job_delete(p->server_info, snum, Printer->jobid, &errcode );
5780 return errcode;
5783 /********************************************************************
5784 * called by spoolss_api_setprinter
5785 * when updating a printer description
5786 ********************************************************************/
5788 static WERROR update_printer_sec(struct policy_handle *handle,
5789 pipes_struct *p, SEC_DESC_BUF *secdesc_ctr)
5791 SEC_DESC_BUF *new_secdesc_ctr = NULL, *old_secdesc_ctr = NULL;
5792 WERROR result;
5793 int snum;
5795 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5797 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
5798 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5799 OUR_HANDLE(handle)));
5801 result = WERR_BADFID;
5802 goto done;
5805 if (!secdesc_ctr) {
5806 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5807 result = WERR_INVALID_PARAM;
5808 goto done;
5811 /* Check the user has permissions to change the security
5812 descriptor. By experimentation with two NT machines, the user
5813 requires Full Access to the printer to change security
5814 information. */
5816 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
5817 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5818 result = WERR_ACCESS_DENIED;
5819 goto done;
5822 /* NT seems to like setting the security descriptor even though
5823 nothing may have actually changed. */
5825 if ( !nt_printing_getsec(p->mem_ctx, Printer->sharename, &old_secdesc_ctr)) {
5826 DEBUG(2,("update_printer_sec: nt_printing_getsec() failed\n"));
5827 result = WERR_BADFID;
5828 goto done;
5831 if (DEBUGLEVEL >= 10) {
5832 SEC_ACL *the_acl;
5833 int i;
5835 the_acl = old_secdesc_ctr->sd->dacl;
5836 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
5837 PRINTERNAME(snum), the_acl->num_aces));
5839 for (i = 0; i < the_acl->num_aces; i++) {
5840 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5841 &the_acl->aces[i].trustee),
5842 the_acl->aces[i].access_mask));
5845 the_acl = secdesc_ctr->sd->dacl;
5847 if (the_acl) {
5848 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
5849 PRINTERNAME(snum), the_acl->num_aces));
5851 for (i = 0; i < the_acl->num_aces; i++) {
5852 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5853 &the_acl->aces[i].trustee),
5854 the_acl->aces[i].access_mask));
5856 } else {
5857 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
5861 new_secdesc_ctr = sec_desc_merge(p->mem_ctx, secdesc_ctr, old_secdesc_ctr);
5862 if (!new_secdesc_ctr) {
5863 result = WERR_NOMEM;
5864 goto done;
5867 if (security_descriptor_equal(new_secdesc_ctr->sd, old_secdesc_ctr->sd)) {
5868 result = WERR_OK;
5869 goto done;
5872 result = nt_printing_setsec(Printer->sharename, new_secdesc_ctr);
5874 done:
5876 return result;
5879 /********************************************************************
5880 Canonicalize printer info from a client
5882 ATTN: It does not matter what we set the servername to hear
5883 since we do the necessary work in get_a_printer() to set it to
5884 the correct value based on what the client sent in the
5885 _spoolss_open_printer_ex().
5886 ********************************************************************/
5888 static bool check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum)
5890 fstring printername;
5891 const char *p;
5893 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
5894 "portname=%s drivername=%s comment=%s location=%s\n",
5895 info->servername, info->printername, info->sharename,
5896 info->portname, info->drivername, info->comment, info->location));
5898 /* we force some elements to "correct" values */
5899 slprintf(info->servername, sizeof(info->servername)-1, "\\\\%s", global_myname());
5900 fstrcpy(info->sharename, lp_servicename(snum));
5902 /* check to see if we allow printername != sharename */
5904 if ( lp_force_printername(snum) ) {
5905 slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s",
5906 global_myname(), info->sharename );
5907 } else {
5909 /* make sure printername is in \\server\printername format */
5911 fstrcpy( printername, info->printername );
5912 p = printername;
5913 if ( printername[0] == '\\' && printername[1] == '\\' ) {
5914 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
5915 p++;
5918 slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s",
5919 global_myname(), p );
5922 info->attributes |= PRINTER_ATTRIBUTE_SAMBA;
5923 info->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
5927 return true;
5930 /****************************************************************************
5931 ****************************************************************************/
5933 WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *portname, const char *uri )
5935 char *cmd = lp_addport_cmd();
5936 char *command = NULL;
5937 int ret;
5938 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5939 bool is_print_op = false;
5941 if ( !*cmd ) {
5942 return WERR_ACCESS_DENIED;
5945 command = talloc_asprintf(ctx,
5946 "%s \"%s\" \"%s\"", cmd, portname, uri );
5947 if (!command) {
5948 return WERR_NOMEM;
5951 if ( token )
5952 is_print_op = user_has_privileges( token, &se_printop );
5954 DEBUG(10,("Running [%s]\n", command));
5956 /********* BEGIN SePrintOperatorPrivilege **********/
5958 if ( is_print_op )
5959 become_root();
5961 ret = smbrun(command, NULL);
5963 if ( is_print_op )
5964 unbecome_root();
5966 /********* END SePrintOperatorPrivilege **********/
5968 DEBUGADD(10,("returned [%d]\n", ret));
5970 TALLOC_FREE(command);
5972 if ( ret != 0 ) {
5973 return WERR_ACCESS_DENIED;
5976 return WERR_OK;
5979 /****************************************************************************
5980 ****************************************************************************/
5982 bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer)
5984 char *cmd = lp_addprinter_cmd();
5985 char **qlines;
5986 char *command = NULL;
5987 int numlines;
5988 int ret;
5989 int fd;
5990 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5991 bool is_print_op = false;
5992 char *remote_machine = talloc_strdup(ctx, "%m");
5994 if (!remote_machine) {
5995 return false;
5997 remote_machine = talloc_sub_basic(ctx,
5998 current_user_info.smb_name,
5999 current_user_info.domain,
6000 remote_machine);
6001 if (!remote_machine) {
6002 return false;
6005 command = talloc_asprintf(ctx,
6006 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
6007 cmd, printer->info_2->printername, printer->info_2->sharename,
6008 printer->info_2->portname, printer->info_2->drivername,
6009 printer->info_2->location, printer->info_2->comment, remote_machine);
6010 if (!command) {
6011 return false;
6014 if ( token )
6015 is_print_op = user_has_privileges( token, &se_printop );
6017 DEBUG(10,("Running [%s]\n", command));
6019 /********* BEGIN SePrintOperatorPrivilege **********/
6021 if ( is_print_op )
6022 become_root();
6024 if ( (ret = smbrun(command, &fd)) == 0 ) {
6025 /* Tell everyone we updated smb.conf. */
6026 message_send_all(smbd_messaging_context(),
6027 MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
6030 if ( is_print_op )
6031 unbecome_root();
6033 /********* END SePrintOperatorPrivilege **********/
6035 DEBUGADD(10,("returned [%d]\n", ret));
6037 TALLOC_FREE(command);
6038 TALLOC_FREE(remote_machine);
6040 if ( ret != 0 ) {
6041 if (fd != -1)
6042 close(fd);
6043 return false;
6046 /* reload our services immediately */
6047 reload_services(false);
6049 numlines = 0;
6050 /* Get lines and convert them back to dos-codepage */
6051 qlines = fd_lines_load(fd, &numlines, 0, NULL);
6052 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
6053 close(fd);
6055 /* Set the portname to what the script says the portname should be. */
6056 /* but don't require anything to be return from the script exit a good error code */
6058 if (numlines) {
6059 /* Set the portname to what the script says the portname should be. */
6060 strncpy(printer->info_2->portname, qlines[0], sizeof(printer->info_2->portname));
6061 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
6064 TALLOC_FREE(qlines);
6065 return true;
6069 /********************************************************************
6070 * Called by spoolss_api_setprinter
6071 * when updating a printer description.
6072 ********************************************************************/
6074 static WERROR update_printer(pipes_struct *p, struct policy_handle *handle,
6075 struct spoolss_SetPrinterInfoCtr *info_ctr,
6076 struct spoolss_DeviceMode *devmode)
6078 int snum;
6079 NT_PRINTER_INFO_LEVEL *printer = NULL, *old_printer = NULL;
6080 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
6081 WERROR result;
6082 UNISTR2 buffer;
6083 fstring asc_buffer;
6085 DEBUG(8,("update_printer\n"));
6087 result = WERR_OK;
6089 if (!Printer) {
6090 result = WERR_BADFID;
6091 goto done;
6094 if (!get_printer_snum(p, handle, &snum, NULL)) {
6095 result = WERR_BADFID;
6096 goto done;
6099 if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum))) ||
6100 (!W_ERROR_IS_OK(get_a_printer(Printer, &old_printer, 2, lp_const_servicename(snum))))) {
6101 result = WERR_BADFID;
6102 goto done;
6105 DEBUGADD(8,("Converting info_2 struct\n"));
6108 * convert_printer_info converts the incoming
6109 * info from the client and overwrites the info
6110 * just read from the tdb in the pointer 'printer'.
6113 if (!convert_printer_info(info_ctr, printer)) {
6114 result = WERR_NOMEM;
6115 goto done;
6118 if (devmode) {
6119 /* we have a valid devmode
6120 convert it and link it*/
6122 DEBUGADD(8,("update_printer: Converting the devicemode struct\n"));
6123 if (!convert_devicemode(printer->info_2->printername, devmode,
6124 &printer->info_2->devmode)) {
6125 result = WERR_NOMEM;
6126 goto done;
6130 /* Do sanity check on the requested changes for Samba */
6132 if (!check_printer_ok(printer->info_2, snum)) {
6133 result = WERR_INVALID_PARAM;
6134 goto done;
6137 /* FIXME!!! If the driver has changed we really should verify that
6138 it is installed before doing much else --jerry */
6140 /* Check calling user has permission to update printer description */
6142 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6143 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6144 result = WERR_ACCESS_DENIED;
6145 goto done;
6148 /* Call addprinter hook */
6149 /* Check changes to see if this is really needed */
6151 if ( *lp_addprinter_cmd()
6152 && (!strequal(printer->info_2->drivername, old_printer->info_2->drivername)
6153 || !strequal(printer->info_2->comment, old_printer->info_2->comment)
6154 || !strequal(printer->info_2->portname, old_printer->info_2->portname)
6155 || !strequal(printer->info_2->location, old_printer->info_2->location)) )
6157 /* add_printer_hook() will call reload_services() */
6159 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
6160 printer) ) {
6161 result = WERR_ACCESS_DENIED;
6162 goto done;
6167 * When a *new* driver is bound to a printer, the drivername is used to
6168 * lookup previously saved driver initialization info, which is then
6169 * bound to the printer, simulating what happens in the Windows arch.
6171 if (!strequal(printer->info_2->drivername, old_printer->info_2->drivername))
6173 if (!set_driver_init(printer, 2))
6175 DEBUG(5,("update_printer: Error restoring driver initialization data for driver [%s]!\n",
6176 printer->info_2->drivername));
6179 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6180 printer->info_2->drivername));
6182 notify_printer_driver(snum, printer->info_2->drivername);
6186 * flag which changes actually occured. This is a small subset of
6187 * all the possible changes. We also have to update things in the
6188 * DsSpooler key.
6191 if (!strequal(printer->info_2->comment, old_printer->info_2->comment)) {
6192 init_unistr2( &buffer, printer->info_2->comment, UNI_STR_TERMINATE);
6193 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "description",
6194 REG_SZ, (uint8_t *)buffer.buffer, buffer.uni_str_len*2 );
6196 notify_printer_comment(snum, printer->info_2->comment);
6199 if (!strequal(printer->info_2->sharename, old_printer->info_2->sharename)) {
6200 init_unistr2( &buffer, printer->info_2->sharename, UNI_STR_TERMINATE);
6201 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "shareName",
6202 REG_SZ, (uint8_t *)buffer.buffer, buffer.uni_str_len*2 );
6204 notify_printer_sharename(snum, printer->info_2->sharename);
6207 if (!strequal(printer->info_2->printername, old_printer->info_2->printername)) {
6208 char *pname;
6210 if ( (pname = strchr_m( printer->info_2->printername+2, '\\' )) != NULL )
6211 pname++;
6212 else
6213 pname = printer->info_2->printername;
6216 init_unistr2( &buffer, pname, UNI_STR_TERMINATE);
6217 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "printerName",
6218 REG_SZ, (uint8_t *)buffer.buffer, buffer.uni_str_len*2 );
6220 notify_printer_printername( snum, pname );
6223 if (!strequal(printer->info_2->portname, old_printer->info_2->portname)) {
6224 init_unistr2( &buffer, printer->info_2->portname, UNI_STR_TERMINATE);
6225 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "portName",
6226 REG_SZ, (uint8_t *)buffer.buffer, buffer.uni_str_len*2 );
6228 notify_printer_port(snum, printer->info_2->portname);
6231 if (!strequal(printer->info_2->location, old_printer->info_2->location)) {
6232 init_unistr2( &buffer, printer->info_2->location, UNI_STR_TERMINATE);
6233 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "location",
6234 REG_SZ, (uint8_t *)buffer.buffer, buffer.uni_str_len*2 );
6236 notify_printer_location(snum, printer->info_2->location);
6239 /* here we need to update some more DsSpooler keys */
6240 /* uNCName, serverName, shortServerName */
6242 init_unistr2( &buffer, global_myname(), UNI_STR_TERMINATE);
6243 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "serverName",
6244 REG_SZ, (uint8_t *)buffer.buffer, buffer.uni_str_len*2 );
6245 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "shortServerName",
6246 REG_SZ, (uint8_t *)buffer.buffer, buffer.uni_str_len*2 );
6248 slprintf( asc_buffer, sizeof(asc_buffer)-1, "\\\\%s\\%s",
6249 global_myname(), printer->info_2->sharename );
6250 init_unistr2( &buffer, asc_buffer, UNI_STR_TERMINATE);
6251 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "uNCName",
6252 REG_SZ, (uint8_t *)buffer.buffer, buffer.uni_str_len*2 );
6254 /* Update printer info */
6255 result = mod_a_printer(printer, 2);
6257 done:
6258 free_a_printer(&printer, 2);
6259 free_a_printer(&old_printer, 2);
6262 return result;
6265 /****************************************************************************
6266 ****************************************************************************/
6267 static WERROR publish_or_unpublish_printer(pipes_struct *p,
6268 struct policy_handle *handle,
6269 struct spoolss_SetPrinterInfo7 *info7)
6271 #ifdef HAVE_ADS
6272 int snum;
6273 Printer_entry *Printer;
6275 if ( lp_security() != SEC_ADS ) {
6276 return WERR_UNKNOWN_LEVEL;
6279 Printer = find_printer_index_by_hnd(p, handle);
6281 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6283 if (!Printer)
6284 return WERR_BADFID;
6286 if (!get_printer_snum(p, handle, &snum, NULL))
6287 return WERR_BADFID;
6289 nt_printer_publish(Printer, snum, info7->action);
6291 return WERR_OK;
6292 #else
6293 return WERR_UNKNOWN_LEVEL;
6294 #endif
6297 /****************************************************************
6298 _spoolss_SetPrinter
6299 ****************************************************************/
6301 WERROR _spoolss_SetPrinter(pipes_struct *p,
6302 struct spoolss_SetPrinter *r)
6304 WERROR result;
6306 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
6308 if (!Printer) {
6309 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6310 OUR_HANDLE(r->in.handle)));
6311 return WERR_BADFID;
6314 /* check the level */
6315 switch (r->in.info_ctr->level) {
6316 case 0:
6317 return control_printer(r->in.handle, r->in.command, p);
6318 case 2:
6319 result = update_printer(p, r->in.handle,
6320 r->in.info_ctr,
6321 r->in.devmode_ctr->devmode);
6322 if (!W_ERROR_IS_OK(result))
6323 return result;
6324 if (r->in.secdesc_ctr->sd)
6325 result = update_printer_sec(r->in.handle, p,
6326 r->in.secdesc_ctr);
6327 return result;
6328 case 3:
6329 return update_printer_sec(r->in.handle, p,
6330 r->in.secdesc_ctr);
6331 case 7:
6332 return publish_or_unpublish_printer(p, r->in.handle,
6333 r->in.info_ctr->info.info7);
6334 default:
6335 return WERR_UNKNOWN_LEVEL;
6339 /****************************************************************
6340 _spoolss_FindClosePrinterNotify
6341 ****************************************************************/
6343 WERROR _spoolss_FindClosePrinterNotify(pipes_struct *p,
6344 struct spoolss_FindClosePrinterNotify *r)
6346 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
6348 if (!Printer) {
6349 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6350 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
6351 return WERR_BADFID;
6354 if (Printer->notify.client_connected == true) {
6355 int snum = -1;
6357 if ( Printer->printer_type == SPLHND_SERVER)
6358 snum = -1;
6359 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
6360 !get_printer_snum(p, r->in.handle, &snum, NULL) )
6361 return WERR_BADFID;
6363 srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
6366 Printer->notify.flags=0;
6367 Printer->notify.options=0;
6368 Printer->notify.localmachine[0]='\0';
6369 Printer->notify.printerlocal=0;
6370 TALLOC_FREE(Printer->notify.option);
6371 Printer->notify.client_connected = false;
6373 return WERR_OK;
6376 /****************************************************************
6377 _spoolss_AddJob
6378 ****************************************************************/
6380 WERROR _spoolss_AddJob(pipes_struct *p,
6381 struct spoolss_AddJob *r)
6383 if (!r->in.buffer && (r->in.offered != 0)) {
6384 return WERR_INVALID_PARAM;
6387 /* this is what a NT server returns for AddJob. AddJob must fail on
6388 * non-local printers */
6390 if (r->in.level != 1) {
6391 return WERR_UNKNOWN_LEVEL;
6394 return WERR_INVALID_PARAM;
6397 /****************************************************************************
6398 fill_job_info1
6399 ****************************************************************************/
6401 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
6402 struct spoolss_JobInfo1 *r,
6403 const print_queue_struct *queue,
6404 int position, int snum,
6405 const NT_PRINTER_INFO_LEVEL *ntprinter)
6407 struct tm *t;
6409 t = gmtime(&queue->time);
6411 r->job_id = queue->job;
6413 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6414 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6415 r->server_name = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
6416 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6417 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6418 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6419 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6420 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6421 r->data_type = talloc_strdup(mem_ctx, "RAW");
6422 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6423 r->text_status = talloc_strdup(mem_ctx, "");
6424 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6426 r->status = nt_printj_status(queue->status);
6427 r->priority = queue->priority;
6428 r->position = position;
6429 r->total_pages = queue->page_count;
6430 r->pages_printed = 0; /* ??? */
6432 init_systemtime(&r->submitted, t);
6434 return WERR_OK;
6437 /****************************************************************************
6438 fill_job_info2
6439 ****************************************************************************/
6441 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
6442 struct spoolss_JobInfo2 *r,
6443 const print_queue_struct *queue,
6444 int position, int snum,
6445 const NT_PRINTER_INFO_LEVEL *ntprinter,
6446 struct spoolss_DeviceMode *devmode)
6448 struct tm *t;
6450 t = gmtime(&queue->time);
6452 r->job_id = queue->job;
6454 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6455 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6456 r->server_name = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
6457 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6458 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6459 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6460 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6461 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6462 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
6463 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
6464 r->data_type = talloc_strdup(mem_ctx, "RAW");
6465 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6466 r->print_processor = talloc_strdup(mem_ctx, "winprint");
6467 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
6468 r->parameters = talloc_strdup(mem_ctx, "");
6469 W_ERROR_HAVE_NO_MEMORY(r->parameters);
6470 r->driver_name = talloc_strdup(mem_ctx, ntprinter->info_2->drivername);
6471 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
6473 r->devmode = devmode;
6475 r->text_status = talloc_strdup(mem_ctx, "");
6476 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6478 r->secdesc = NULL;
6480 r->status = nt_printj_status(queue->status);
6481 r->priority = queue->priority;
6482 r->position = position;
6483 r->start_time = 0;
6484 r->until_time = 0;
6485 r->total_pages = queue->page_count;
6486 r->size = queue->size;
6487 init_systemtime(&r->submitted, t);
6488 r->time = 0;
6489 r->pages_printed = 0; /* ??? */
6491 return WERR_OK;
6494 /****************************************************************************
6495 Enumjobs at level 1.
6496 ****************************************************************************/
6498 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
6499 const print_queue_struct *queue,
6500 uint32_t num_queues, int snum,
6501 const NT_PRINTER_INFO_LEVEL *ntprinter,
6502 union spoolss_JobInfo **info_p,
6503 uint32_t *count)
6505 union spoolss_JobInfo *info;
6506 int i;
6507 WERROR result = WERR_OK;
6509 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6510 W_ERROR_HAVE_NO_MEMORY(info);
6512 *count = num_queues;
6514 for (i=0; i<*count; i++) {
6515 result = fill_job_info1(info,
6516 &info[i].info1,
6517 &queue[i],
6519 snum,
6520 ntprinter);
6521 if (!W_ERROR_IS_OK(result)) {
6522 goto out;
6526 out:
6527 if (!W_ERROR_IS_OK(result)) {
6528 TALLOC_FREE(info);
6529 *count = 0;
6530 return result;
6533 *info_p = info;
6535 return WERR_OK;
6538 /****************************************************************************
6539 Enumjobs at level 2.
6540 ****************************************************************************/
6542 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
6543 const print_queue_struct *queue,
6544 uint32_t num_queues, int snum,
6545 const NT_PRINTER_INFO_LEVEL *ntprinter,
6546 union spoolss_JobInfo **info_p,
6547 uint32_t *count)
6549 union spoolss_JobInfo *info;
6550 int i;
6551 WERROR result = WERR_OK;
6553 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6554 W_ERROR_HAVE_NO_MEMORY(info);
6556 *count = num_queues;
6558 for (i=0; i<*count; i++) {
6560 struct spoolss_DeviceMode *devmode;
6562 devmode = construct_dev_mode(info, lp_const_servicename(snum));
6563 if (!devmode) {
6564 result = WERR_NOMEM;
6565 goto out;
6568 result = fill_job_info2(info,
6569 &info[i].info2,
6570 &queue[i],
6572 snum,
6573 ntprinter,
6574 devmode);
6575 if (!W_ERROR_IS_OK(result)) {
6576 goto out;
6580 out:
6581 if (!W_ERROR_IS_OK(result)) {
6582 TALLOC_FREE(info);
6583 *count = 0;
6584 return result;
6587 *info_p = info;
6589 return WERR_OK;
6592 /****************************************************************
6593 _spoolss_EnumJobs
6594 ****************************************************************/
6596 WERROR _spoolss_EnumJobs(pipes_struct *p,
6597 struct spoolss_EnumJobs *r)
6599 WERROR result;
6600 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
6601 int snum;
6602 print_status_struct prt_status;
6603 print_queue_struct *queue = NULL;
6604 uint32_t count;
6606 /* that's an [in out] buffer */
6608 if (!r->in.buffer && (r->in.offered != 0)) {
6609 return WERR_INVALID_PARAM;
6612 DEBUG(4,("_spoolss_EnumJobs\n"));
6614 *r->out.needed = 0;
6615 *r->out.count = 0;
6616 *r->out.info = NULL;
6618 /* lookup the printer snum and tdb entry */
6620 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6621 return WERR_BADFID;
6624 result = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum));
6625 if (!W_ERROR_IS_OK(result)) {
6626 return result;
6629 count = print_queue_status(snum, &queue, &prt_status);
6630 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
6631 count, prt_status.status, prt_status.message));
6633 if (count == 0) {
6634 SAFE_FREE(queue);
6635 free_a_printer(&ntprinter, 2);
6636 return WERR_OK;
6639 switch (r->in.level) {
6640 case 1:
6641 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
6642 ntprinter, r->out.info, r->out.count);
6643 break;
6644 case 2:
6645 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
6646 ntprinter, r->out.info, r->out.count);
6647 break;
6648 default:
6649 result = WERR_UNKNOWN_LEVEL;
6650 break;
6653 SAFE_FREE(queue);
6654 free_a_printer(&ntprinter, 2);
6656 if (!W_ERROR_IS_OK(result)) {
6657 return result;
6660 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6661 spoolss_EnumJobs, NULL,
6662 *r->out.info, r->in.level,
6663 *r->out.count);
6664 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6665 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6667 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6670 /****************************************************************
6671 _spoolss_ScheduleJob
6672 ****************************************************************/
6674 WERROR _spoolss_ScheduleJob(pipes_struct *p,
6675 struct spoolss_ScheduleJob *r)
6677 return WERR_OK;
6680 /****************************************************************
6681 _spoolss_SetJob
6682 ****************************************************************/
6684 WERROR _spoolss_SetJob(pipes_struct *p,
6685 struct spoolss_SetJob *r)
6687 int snum;
6688 WERROR errcode = WERR_BADFUNC;
6690 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6691 return WERR_BADFID;
6694 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
6695 return WERR_INVALID_PRINTER_NAME;
6698 switch (r->in.command) {
6699 case SPOOLSS_JOB_CONTROL_CANCEL:
6700 case SPOOLSS_JOB_CONTROL_DELETE:
6701 if (print_job_delete(p->server_info, snum, r->in.job_id, &errcode)) {
6702 errcode = WERR_OK;
6704 break;
6705 case SPOOLSS_JOB_CONTROL_PAUSE:
6706 if (print_job_pause(p->server_info, snum, r->in.job_id, &errcode)) {
6707 errcode = WERR_OK;
6709 break;
6710 case SPOOLSS_JOB_CONTROL_RESTART:
6711 case SPOOLSS_JOB_CONTROL_RESUME:
6712 if (print_job_resume(p->server_info, snum, r->in.job_id, &errcode)) {
6713 errcode = WERR_OK;
6715 break;
6716 default:
6717 return WERR_UNKNOWN_LEVEL;
6720 return errcode;
6723 /****************************************************************************
6724 Enumerates all printer drivers by level.
6725 ****************************************************************************/
6727 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
6728 const char *servername,
6729 const char *architecture,
6730 uint32_t level,
6731 union spoolss_DriverInfo **info_p,
6732 uint32_t *count_p)
6734 int i;
6735 int ndrivers;
6736 uint32_t version;
6737 fstring *list = NULL;
6738 NT_PRINTER_DRIVER_INFO_LEVEL driver;
6739 union spoolss_DriverInfo *info = NULL;
6740 uint32_t count = 0;
6741 WERROR result = WERR_OK;
6743 *count_p = 0;
6744 *info_p = NULL;
6746 for (version=0; version<DRIVER_MAX_VERSION; version++) {
6747 list = NULL;
6748 ndrivers = get_ntdrivers(&list, architecture, version);
6749 DEBUGADD(4,("we have:[%d] drivers in environment [%s] and version [%d]\n",
6750 ndrivers, architecture, version));
6752 if (ndrivers == -1) {
6753 result = WERR_NOMEM;
6754 goto out;
6757 if (ndrivers != 0) {
6758 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
6759 union spoolss_DriverInfo,
6760 count + ndrivers);
6761 if (!info) {
6762 DEBUG(0,("enumprinterdrivers_level1: "
6763 "failed to enlarge driver info buffer!\n"));
6764 result = WERR_NOMEM;
6765 goto out;
6769 for (i=0; i<ndrivers; i++) {
6770 DEBUGADD(5,("\tdriver: [%s]\n", list[i]));
6771 ZERO_STRUCT(driver);
6772 result = get_a_printer_driver(&driver, 3, list[i],
6773 architecture, version);
6774 if (!W_ERROR_IS_OK(result)) {
6775 goto out;
6778 switch (level) {
6779 case 1:
6780 result = fill_printer_driver_info1(info, &info[count+i].info1,
6781 &driver, servername,
6782 architecture);
6783 break;
6784 case 2:
6785 result = fill_printer_driver_info2(info, &info[count+i].info2,
6786 &driver, servername);
6787 break;
6788 case 3:
6789 result = fill_printer_driver_info3(info, &info[count+i].info3,
6790 &driver, servername);
6791 break;
6792 case 4:
6793 result = fill_printer_driver_info4(info, &info[count+i].info4,
6794 &driver, servername);
6795 break;
6796 case 5:
6797 result = fill_printer_driver_info5(info, &info[count+i].info5,
6798 &driver, servername);
6799 break;
6800 case 6:
6801 result = fill_printer_driver_info6(info, &info[count+i].info6,
6802 &driver, servername);
6803 break;
6804 default:
6805 result = WERR_UNKNOWN_LEVEL;
6806 break;
6809 if (!W_ERROR_IS_OK(result)) {
6810 free_a_printer_driver(driver, 3);
6811 goto out;
6813 free_a_printer_driver(driver, 3);
6816 count += ndrivers;
6817 SAFE_FREE(list);
6820 out:
6821 SAFE_FREE(list);
6823 if (!W_ERROR_IS_OK(result)) {
6824 TALLOC_FREE(info);
6825 return result;
6828 *info_p = info;
6829 *count_p = count;
6831 return WERR_OK;
6834 /****************************************************************************
6835 Enumerates all printer drivers at level 1.
6836 ****************************************************************************/
6838 static WERROR enumprinterdrivers_level1(TALLOC_CTX *mem_ctx,
6839 const char *servername,
6840 const char *architecture,
6841 union spoolss_DriverInfo **info_p,
6842 uint32_t *count)
6844 return enumprinterdrivers_level(mem_ctx, servername, architecture, 1,
6845 info_p, count);
6848 /****************************************************************************
6849 Enumerates all printer drivers at level 2.
6850 ****************************************************************************/
6852 static WERROR enumprinterdrivers_level2(TALLOC_CTX *mem_ctx,
6853 const char *servername,
6854 const char *architecture,
6855 union spoolss_DriverInfo **info_p,
6856 uint32_t *count)
6858 return enumprinterdrivers_level(mem_ctx, servername, architecture, 2,
6859 info_p, count);
6862 /****************************************************************************
6863 Enumerates all printer drivers at level 3.
6864 ****************************************************************************/
6866 static WERROR enumprinterdrivers_level3(TALLOC_CTX *mem_ctx,
6867 const char *servername,
6868 const char *architecture,
6869 union spoolss_DriverInfo **info_p,
6870 uint32_t *count)
6872 return enumprinterdrivers_level(mem_ctx, servername, architecture, 3,
6873 info_p, count);
6876 /****************************************************************************
6877 Enumerates all printer drivers at level 4.
6878 ****************************************************************************/
6880 static WERROR enumprinterdrivers_level4(TALLOC_CTX *mem_ctx,
6881 const char *servername,
6882 const char *architecture,
6883 union spoolss_DriverInfo **info_p,
6884 uint32_t *count)
6886 return enumprinterdrivers_level(mem_ctx, servername, architecture, 4,
6887 info_p, count);
6890 /****************************************************************************
6891 Enumerates all printer drivers at level 5.
6892 ****************************************************************************/
6894 static WERROR enumprinterdrivers_level5(TALLOC_CTX *mem_ctx,
6895 const char *servername,
6896 const char *architecture,
6897 union spoolss_DriverInfo **info_p,
6898 uint32_t *count)
6900 return enumprinterdrivers_level(mem_ctx, servername, architecture, 5,
6901 info_p, count);
6904 /****************************************************************************
6905 Enumerates all printer drivers at level 6.
6906 ****************************************************************************/
6908 static WERROR enumprinterdrivers_level6(TALLOC_CTX *mem_ctx,
6909 const char *servername,
6910 const char *architecture,
6911 union spoolss_DriverInfo **info_p,
6912 uint32_t *count)
6914 return enumprinterdrivers_level(mem_ctx, servername, architecture, 6,
6915 info_p, count);
6919 /****************************************************************
6920 _spoolss_EnumPrinterDrivers
6921 ****************************************************************/
6923 WERROR _spoolss_EnumPrinterDrivers(pipes_struct *p,
6924 struct spoolss_EnumPrinterDrivers *r)
6926 const char *cservername;
6927 WERROR result;
6929 /* that's an [in out] buffer */
6931 if (!r->in.buffer && (r->in.offered != 0)) {
6932 return WERR_INVALID_PARAM;
6935 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
6937 *r->out.needed = 0;
6938 *r->out.count = 0;
6939 *r->out.info = NULL;
6941 cservername = canon_servername(r->in.server);
6943 if (!is_myname_or_ipaddr(cservername)) {
6944 return WERR_UNKNOWN_PRINTER_DRIVER;
6947 switch (r->in.level) {
6948 case 1:
6949 result = enumprinterdrivers_level1(p->mem_ctx, cservername,
6950 r->in.environment,
6951 r->out.info, r->out.count);
6952 break;
6953 case 2:
6954 result = enumprinterdrivers_level2(p->mem_ctx, cservername,
6955 r->in.environment,
6956 r->out.info, r->out.count);
6957 break;
6958 case 3:
6959 result = enumprinterdrivers_level3(p->mem_ctx, cservername,
6960 r->in.environment,
6961 r->out.info, r->out.count);
6962 break;
6963 case 4:
6964 result = enumprinterdrivers_level4(p->mem_ctx, cservername,
6965 r->in.environment,
6966 r->out.info, r->out.count);
6967 break;
6968 case 5:
6969 result = enumprinterdrivers_level5(p->mem_ctx, cservername,
6970 r->in.environment,
6971 r->out.info, r->out.count);
6972 break;
6973 case 6:
6974 result = enumprinterdrivers_level6(p->mem_ctx, cservername,
6975 r->in.environment,
6976 r->out.info, r->out.count);
6977 break;
6978 default:
6979 return WERR_UNKNOWN_LEVEL;
6982 if (!W_ERROR_IS_OK(result)) {
6983 return result;
6986 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6987 spoolss_EnumPrinterDrivers, NULL,
6988 *r->out.info, r->in.level,
6989 *r->out.count);
6990 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6991 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6993 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6996 /****************************************************************************
6997 ****************************************************************************/
6999 static WERROR fill_form_info_1(TALLOC_CTX *mem_ctx,
7000 struct spoolss_FormInfo1 *r,
7001 const nt_forms_struct *form)
7003 r->form_name = talloc_strdup(mem_ctx, form->name);
7004 W_ERROR_HAVE_NO_MEMORY(r->form_name);
7006 r->flags = form->flag;
7007 r->size.width = form->width;
7008 r->size.height = form->length;
7009 r->area.left = form->left;
7010 r->area.top = form->top;
7011 r->area.right = form->right;
7012 r->area.bottom = form->bottom;
7014 return WERR_OK;
7017 /****************************************************************
7018 spoolss_enumforms_level1
7019 ****************************************************************/
7021 static WERROR spoolss_enumforms_level1(TALLOC_CTX *mem_ctx,
7022 const nt_forms_struct *builtin_forms,
7023 uint32_t num_builtin_forms,
7024 const nt_forms_struct *user_forms,
7025 uint32_t num_user_forms,
7026 union spoolss_FormInfo **info_p,
7027 uint32_t *count)
7029 union spoolss_FormInfo *info;
7030 WERROR result = WERR_OK;
7031 int i;
7033 *count = num_builtin_forms + num_user_forms;
7035 info = TALLOC_ARRAY(mem_ctx, union spoolss_FormInfo, *count);
7036 W_ERROR_HAVE_NO_MEMORY(info);
7038 /* construct the list of form structures */
7039 for (i=0; i<num_builtin_forms; i++) {
7040 DEBUGADD(6,("Filling form number [%d]\n",i));
7041 result = fill_form_info_1(info, &info[i].info1,
7042 &builtin_forms[i]);
7043 if (!W_ERROR_IS_OK(result)) {
7044 goto out;
7048 for (; i<num_user_forms; i++) {
7049 DEBUGADD(6,("Filling form number [%d]\n",i));
7050 result = fill_form_info_1(info, &info[i].info1,
7051 &user_forms[i-num_builtin_forms]);
7052 if (!W_ERROR_IS_OK(result)) {
7053 goto out;
7057 out:
7058 if (!W_ERROR_IS_OK(result)) {
7059 TALLOC_FREE(info);
7060 *count = 0;
7061 return result;
7064 *info_p = info;
7066 return WERR_OK;
7069 /****************************************************************
7070 _spoolss_EnumForms
7071 ****************************************************************/
7073 WERROR _spoolss_EnumForms(pipes_struct *p,
7074 struct spoolss_EnumForms *r)
7076 WERROR result;
7077 nt_forms_struct *user_forms = NULL;
7078 nt_forms_struct *builtin_forms = NULL;
7079 uint32_t num_user_forms;
7080 uint32_t num_builtin_forms;
7082 *r->out.count = 0;
7083 *r->out.needed = 0;
7084 *r->out.info = NULL;
7086 /* that's an [in out] buffer */
7088 if (!r->in.buffer && (r->in.offered != 0) ) {
7089 return WERR_INVALID_PARAM;
7092 DEBUG(4,("_spoolss_EnumForms\n"));
7093 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7094 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7096 num_builtin_forms = get_builtin_ntforms(&builtin_forms);
7097 DEBUGADD(5,("Number of builtin forms [%d]\n", num_builtin_forms));
7098 num_user_forms = get_ntforms(&user_forms);
7099 DEBUGADD(5,("Number of user forms [%d]\n", num_user_forms));
7101 if (num_user_forms + num_builtin_forms == 0) {
7102 SAFE_FREE(builtin_forms);
7103 SAFE_FREE(user_forms);
7104 return WERR_NO_MORE_ITEMS;
7107 switch (r->in.level) {
7108 case 1:
7109 result = spoolss_enumforms_level1(p->mem_ctx,
7110 builtin_forms,
7111 num_builtin_forms,
7112 user_forms,
7113 num_user_forms,
7114 r->out.info,
7115 r->out.count);
7116 break;
7117 default:
7118 result = WERR_UNKNOWN_LEVEL;
7119 break;
7122 SAFE_FREE(user_forms);
7123 SAFE_FREE(builtin_forms);
7125 if (!W_ERROR_IS_OK(result)) {
7126 return result;
7129 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7130 spoolss_EnumForms, NULL,
7131 *r->out.info, r->in.level,
7132 *r->out.count);
7133 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7134 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7136 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7139 /****************************************************************
7140 ****************************************************************/
7142 static WERROR find_form_byname(const char *name,
7143 nt_forms_struct *form)
7145 nt_forms_struct *list = NULL;
7146 int num_forms = 0, i = 0;
7148 if (get_a_builtin_ntform_by_string(name, form)) {
7149 return WERR_OK;
7152 num_forms = get_ntforms(&list);
7153 DEBUGADD(5,("Number of forms [%d]\n", num_forms));
7155 if (num_forms == 0) {
7156 return WERR_BADFID;
7159 /* Check if the requested name is in the list of form structures */
7160 for (i = 0; i < num_forms; i++) {
7162 DEBUG(4,("checking form %s (want %s)\n", list[i].name, name));
7164 if (strequal(name, list[i].name)) {
7165 DEBUGADD(6,("Found form %s number [%d]\n", name, i));
7166 *form = list[i];
7167 SAFE_FREE(list);
7168 return WERR_OK;
7172 SAFE_FREE(list);
7174 return WERR_BADFID;
7177 /****************************************************************
7178 _spoolss_GetForm
7179 ****************************************************************/
7181 WERROR _spoolss_GetForm(pipes_struct *p,
7182 struct spoolss_GetForm *r)
7184 WERROR result;
7185 nt_forms_struct form;
7187 /* that's an [in out] buffer */
7189 if (!r->in.buffer && (r->in.offered != 0)) {
7190 return WERR_INVALID_PARAM;
7193 DEBUG(4,("_spoolss_GetForm\n"));
7194 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7195 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7197 result = find_form_byname(r->in.form_name, &form);
7198 if (!W_ERROR_IS_OK(result)) {
7199 TALLOC_FREE(r->out.info);
7200 return result;
7203 switch (r->in.level) {
7204 case 1:
7205 result = fill_form_info_1(p->mem_ctx,
7206 &r->out.info->info1,
7207 &form);
7208 break;
7210 default:
7211 result = WERR_UNKNOWN_LEVEL;
7212 break;
7215 if (!W_ERROR_IS_OK(result)) {
7216 TALLOC_FREE(r->out.info);
7217 return result;
7220 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo, NULL,
7221 r->out.info, r->in.level);
7222 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7224 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7227 /****************************************************************************
7228 ****************************************************************************/
7230 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
7231 struct spoolss_PortInfo1 *r,
7232 const char *name)
7234 r->port_name = talloc_strdup(mem_ctx, name);
7235 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7237 return WERR_OK;
7240 /****************************************************************************
7241 TODO: This probably needs distinguish between TCP/IP and Local ports
7242 somehow.
7243 ****************************************************************************/
7245 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
7246 struct spoolss_PortInfo2 *r,
7247 const char *name)
7249 r->port_name = talloc_strdup(mem_ctx, name);
7250 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7252 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
7253 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
7255 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
7256 W_ERROR_HAVE_NO_MEMORY(r->description);
7258 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
7259 r->reserved = 0;
7261 return WERR_OK;
7265 /****************************************************************************
7266 wrapper around the enumer ports command
7267 ****************************************************************************/
7269 WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines )
7271 char *cmd = lp_enumports_cmd();
7272 char **qlines = NULL;
7273 char *command = NULL;
7274 int numlines;
7275 int ret;
7276 int fd;
7278 *count = 0;
7279 *lines = NULL;
7281 /* if no hook then just fill in the default port */
7283 if ( !*cmd ) {
7284 if (!(qlines = TALLOC_ARRAY( NULL, char*, 2 ))) {
7285 return WERR_NOMEM;
7287 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7288 TALLOC_FREE(qlines);
7289 return WERR_NOMEM;
7291 qlines[1] = NULL;
7292 numlines = 1;
7294 else {
7295 /* we have a valid enumport command */
7297 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7298 if (!command) {
7299 return WERR_NOMEM;
7302 DEBUG(10,("Running [%s]\n", command));
7303 ret = smbrun(command, &fd);
7304 DEBUG(10,("Returned [%d]\n", ret));
7305 TALLOC_FREE(command);
7306 if (ret != 0) {
7307 if (fd != -1) {
7308 close(fd);
7310 return WERR_ACCESS_DENIED;
7313 numlines = 0;
7314 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7315 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7316 close(fd);
7319 *count = numlines;
7320 *lines = qlines;
7322 return WERR_OK;
7325 /****************************************************************************
7326 enumports level 1.
7327 ****************************************************************************/
7329 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7330 union spoolss_PortInfo **info_p,
7331 uint32_t *count)
7333 union spoolss_PortInfo *info = NULL;
7334 int i=0;
7335 WERROR result = WERR_OK;
7336 char **qlines = NULL;
7337 int numlines = 0;
7339 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7340 if (!W_ERROR_IS_OK(result)) {
7341 goto out;
7344 if (numlines) {
7345 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7346 if (!info) {
7347 DEBUG(10,("Returning WERR_NOMEM\n"));
7348 result = WERR_NOMEM;
7349 goto out;
7352 for (i=0; i<numlines; i++) {
7353 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7354 result = fill_port_1(info, &info[i].info1, qlines[i]);
7355 if (!W_ERROR_IS_OK(result)) {
7356 goto out;
7360 TALLOC_FREE(qlines);
7362 out:
7363 if (!W_ERROR_IS_OK(result)) {
7364 TALLOC_FREE(info);
7365 TALLOC_FREE(qlines);
7366 *count = 0;
7367 *info_p = NULL;
7368 return result;
7371 *info_p = info;
7372 *count = numlines;
7374 return WERR_OK;
7377 /****************************************************************************
7378 enumports level 2.
7379 ****************************************************************************/
7381 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7382 union spoolss_PortInfo **info_p,
7383 uint32_t *count)
7385 union spoolss_PortInfo *info = NULL;
7386 int i=0;
7387 WERROR result = WERR_OK;
7388 char **qlines = NULL;
7389 int numlines = 0;
7391 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7392 if (!W_ERROR_IS_OK(result)) {
7393 goto out;
7396 if (numlines) {
7397 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7398 if (!info) {
7399 DEBUG(10,("Returning WERR_NOMEM\n"));
7400 result = WERR_NOMEM;
7401 goto out;
7404 for (i=0; i<numlines; i++) {
7405 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7406 result = fill_port_2(info, &info[i].info2, qlines[i]);
7407 if (!W_ERROR_IS_OK(result)) {
7408 goto out;
7412 TALLOC_FREE(qlines);
7414 out:
7415 if (!W_ERROR_IS_OK(result)) {
7416 TALLOC_FREE(info);
7417 TALLOC_FREE(qlines);
7418 *count = 0;
7419 *info_p = NULL;
7420 return result;
7423 *info_p = info;
7424 *count = numlines;
7426 return WERR_OK;
7429 /****************************************************************
7430 _spoolss_EnumPorts
7431 ****************************************************************/
7433 WERROR _spoolss_EnumPorts(pipes_struct *p,
7434 struct spoolss_EnumPorts *r)
7436 WERROR result;
7438 /* that's an [in out] buffer */
7440 if (!r->in.buffer && (r->in.offered != 0)) {
7441 return WERR_INVALID_PARAM;
7444 DEBUG(4,("_spoolss_EnumPorts\n"));
7446 *r->out.count = 0;
7447 *r->out.needed = 0;
7448 *r->out.info = NULL;
7450 switch (r->in.level) {
7451 case 1:
7452 result = enumports_level_1(p->mem_ctx, r->out.info,
7453 r->out.count);
7454 break;
7455 case 2:
7456 result = enumports_level_2(p->mem_ctx, r->out.info,
7457 r->out.count);
7458 break;
7459 default:
7460 return WERR_UNKNOWN_LEVEL;
7463 if (!W_ERROR_IS_OK(result)) {
7464 return result;
7467 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7468 spoolss_EnumPorts, NULL,
7469 *r->out.info, r->in.level,
7470 *r->out.count);
7471 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7472 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7474 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7477 /****************************************************************************
7478 ****************************************************************************/
7480 static WERROR spoolss_addprinterex_level_2(pipes_struct *p,
7481 const char *server,
7482 struct spoolss_SetPrinterInfoCtr *info_ctr,
7483 struct spoolss_DeviceMode *devmode,
7484 struct security_descriptor *sec_desc,
7485 struct spoolss_UserLevelCtr *user_ctr,
7486 struct policy_handle *handle)
7488 NT_PRINTER_INFO_LEVEL *printer = NULL;
7489 fstring name;
7490 int snum;
7491 WERROR err = WERR_OK;
7493 if ( !(printer = TALLOC_ZERO_P(NULL, NT_PRINTER_INFO_LEVEL)) ) {
7494 DEBUG(0,("spoolss_addprinterex_level_2: malloc fail.\n"));
7495 return WERR_NOMEM;
7498 /* convert from UNICODE to ASCII - this allocates the info_2 struct inside *printer.*/
7499 if (!convert_printer_info(info_ctr, printer)) {
7500 free_a_printer(&printer, 2);
7501 return WERR_NOMEM;
7504 /* check to see if the printer already exists */
7506 if ((snum = print_queue_snum(printer->info_2->sharename)) != -1) {
7507 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7508 printer->info_2->sharename));
7509 free_a_printer(&printer, 2);
7510 return WERR_PRINTER_ALREADY_EXISTS;
7513 /* FIXME!!! smbd should check to see if the driver is installed before
7514 trying to add a printer like this --jerry */
7516 if (*lp_addprinter_cmd() ) {
7517 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
7518 printer) ) {
7519 free_a_printer(&printer,2);
7520 return WERR_ACCESS_DENIED;
7522 } else {
7523 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
7524 "smb.conf parameter \"addprinter command\" is defined. This"
7525 "parameter must exist for this call to succeed\n",
7526 printer->info_2->sharename ));
7529 /* use our primary netbios name since get_a_printer() will convert
7530 it to what the client expects on a case by case basis */
7532 slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname(),
7533 printer->info_2->sharename);
7536 if ((snum = print_queue_snum(printer->info_2->sharename)) == -1) {
7537 free_a_printer(&printer,2);
7538 return WERR_ACCESS_DENIED;
7541 /* you must be a printer admin to add a new printer */
7542 if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) {
7543 free_a_printer(&printer,2);
7544 return WERR_ACCESS_DENIED;
7548 * Do sanity check on the requested changes for Samba.
7551 if (!check_printer_ok(printer->info_2, snum)) {
7552 free_a_printer(&printer,2);
7553 return WERR_INVALID_PARAM;
7557 * When a printer is created, the drivername bound to the printer is used
7558 * to lookup previously saved driver initialization info, which is then
7559 * bound to the new printer, simulating what happens in the Windows arch.
7562 if (!devmode)
7564 set_driver_init(printer, 2);
7566 else
7568 /* A valid devmode was included, convert and link it
7570 DEBUGADD(10, ("spoolss_addprinterex_level_2: devmode included, converting\n"));
7572 if (!convert_devicemode(printer->info_2->printername, devmode,
7573 &printer->info_2->devmode)) {
7574 return WERR_NOMEM;
7578 /* write the ASCII on disk */
7579 err = mod_a_printer(printer, 2);
7580 if (!W_ERROR_IS_OK(err)) {
7581 free_a_printer(&printer,2);
7582 return err;
7585 if (!open_printer_hnd(p, handle, name, PRINTER_ACCESS_ADMINISTER)) {
7586 /* Handle open failed - remove addition. */
7587 del_a_printer(printer->info_2->sharename);
7588 free_a_printer(&printer,2);
7589 ZERO_STRUCTP(handle);
7590 return WERR_ACCESS_DENIED;
7593 update_c_setprinter(false);
7594 free_a_printer(&printer,2);
7596 return WERR_OK;
7599 /****************************************************************
7600 _spoolss_AddPrinterEx
7601 ****************************************************************/
7603 WERROR _spoolss_AddPrinterEx(pipes_struct *p,
7604 struct spoolss_AddPrinterEx *r)
7606 switch (r->in.info_ctr->level) {
7607 case 1:
7608 /* we don't handle yet */
7609 /* but I know what to do ... */
7610 return WERR_UNKNOWN_LEVEL;
7611 case 2:
7612 return spoolss_addprinterex_level_2(p, r->in.server,
7613 r->in.info_ctr,
7614 r->in.devmode_ctr->devmode,
7615 r->in.secdesc_ctr->sd,
7616 r->in.userlevel_ctr,
7617 r->out.handle);
7618 default:
7619 return WERR_UNKNOWN_LEVEL;
7623 /****************************************************************
7624 _spoolss_AddPrinterDriver
7625 ****************************************************************/
7627 WERROR _spoolss_AddPrinterDriver(pipes_struct *p,
7628 struct spoolss_AddPrinterDriver *r)
7630 uint32_t level = r->in.info_ctr->level;
7631 struct spoolss_AddDriverInfoCtr *info = r->in.info_ctr;
7632 WERROR err = WERR_OK;
7633 NT_PRINTER_DRIVER_INFO_LEVEL driver;
7634 const char *driver_name = NULL;
7635 uint32_t version;
7636 const char *fn;
7638 switch (p->hdr_req.opnum) {
7639 case NDR_SPOOLSS_ADDPRINTERDRIVER:
7640 fn = "_spoolss_AddPrinterDriver";
7641 break;
7642 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
7643 fn = "_spoolss_AddPrinterDriverEx";
7644 break;
7645 default:
7646 return WERR_INVALID_PARAM;
7650 /* FIXME */
7651 if (level != 3 && level != 6) {
7652 /* Clever hack from Martin Zielinski <mz@seh.de>
7653 * to allow downgrade from level 8 (Vista).
7655 DEBUG(0,("%s: level %d not yet implemented\n", fn, level));
7656 return WERR_UNKNOWN_LEVEL;
7659 ZERO_STRUCT(driver);
7661 if (!convert_printer_driver_info(info, &driver, level)) {
7662 err = WERR_NOMEM;
7663 goto done;
7666 DEBUG(5,("Cleaning driver's information\n"));
7667 err = clean_up_driver_struct(p, driver, level);
7668 if (!W_ERROR_IS_OK(err))
7669 goto done;
7671 DEBUG(5,("Moving driver to final destination\n"));
7672 if( !W_ERROR_IS_OK(err = move_driver_to_download_area(p, driver, level,
7673 &err)) ) {
7674 goto done;
7677 if (add_a_printer_driver(driver, level)!=0) {
7678 err = WERR_ACCESS_DENIED;
7679 goto done;
7682 switch(level) {
7683 case 3:
7684 driver_name = driver.info_3->name ? driver.info_3->name : "";
7685 break;
7686 case 6:
7687 driver_name = driver.info_6->name ? driver.info_6->name : "";
7688 break;
7692 * I think this is where he DrvUpgradePrinter() hook would be
7693 * be called in a driver's interface DLL on a Windows NT 4.0/2k
7694 * server. Right now, we just need to send ourselves a message
7695 * to update each printer bound to this driver. --jerry
7698 if (!srv_spoolss_drv_upgrade_printer(driver_name)) {
7699 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
7700 fn, driver_name));
7704 * Based on the version (e.g. driver destination dir: 0=9x,2=Nt/2k,3=2k/Xp),
7705 * decide if the driver init data should be deleted. The rules are:
7706 * 1) never delete init data if it is a 9x driver, they don't use it anyway
7707 * 2) delete init data only if there is no 2k/Xp driver
7708 * 3) always delete init data
7709 * The generalized rule is always use init data from the highest order driver.
7710 * It is necessary to follow the driver install by an initialization step to
7711 * finish off this process.
7713 if (level == 3)
7714 version = driver.info_3->cversion;
7715 else if (level == 6)
7716 version = driver.info_6->version;
7717 else
7718 version = -1;
7719 switch (version) {
7721 * 9x printer driver - never delete init data
7723 case 0:
7724 DEBUG(10,("%s: init data not deleted for 9x driver [%s]\n",
7725 fn, driver_name));
7726 break;
7729 * Nt or 2k (compatiblity mode) printer driver - only delete init data if
7730 * there is no 2k/Xp driver init data for this driver name.
7732 case 2:
7734 NT_PRINTER_DRIVER_INFO_LEVEL driver1;
7736 if (!W_ERROR_IS_OK(get_a_printer_driver(&driver1, 3, driver_name, "Windows NT x86", 3))) {
7738 * No 2k/Xp driver found, delete init data (if any) for the new Nt driver.
7740 if (!del_driver_init(driver_name))
7741 DEBUG(6,("%s: del_driver_init(%s) Nt failed!\n",
7742 fn, driver_name));
7743 } else {
7745 * a 2k/Xp driver was found, don't delete init data because Nt driver will use it.
7747 free_a_printer_driver(driver1,3);
7748 DEBUG(10,("%s: init data not deleted for Nt driver [%s]\n",
7749 fn, driver_name));
7752 break;
7755 * 2k or Xp printer driver - always delete init data
7757 case 3:
7758 if (!del_driver_init(driver_name))
7759 DEBUG(6,("%s: del_driver_init(%s) 2k/Xp failed!\n",
7760 fn, driver_name));
7761 break;
7763 default:
7764 DEBUG(0,("%s: invalid level=%d\n", fn, level));
7765 break;
7769 done:
7770 free_a_printer_driver(driver, level);
7771 return err;
7774 /****************************************************************
7775 _spoolss_AddPrinterDriverEx
7776 ****************************************************************/
7778 WERROR _spoolss_AddPrinterDriverEx(pipes_struct *p,
7779 struct spoolss_AddPrinterDriverEx *r)
7781 struct spoolss_AddPrinterDriver a;
7784 * we only support the semantics of AddPrinterDriver()
7785 * i.e. only copy files that are newer than existing ones
7788 if (r->in.flags != APD_COPY_NEW_FILES) {
7789 return WERR_ACCESS_DENIED;
7792 a.in.servername = r->in.servername;
7793 a.in.info_ctr = r->in.info_ctr;
7795 return _spoolss_AddPrinterDriver(p, &a);
7798 /****************************************************************************
7799 ****************************************************************************/
7801 struct _spoolss_paths {
7802 int type;
7803 const char *share;
7804 const char *dir;
7807 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
7809 static const struct _spoolss_paths spoolss_paths[]= {
7810 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
7811 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
7814 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
7815 const char *servername,
7816 const char *environment,
7817 int component,
7818 char **path)
7820 const char *pservername = NULL;
7821 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
7822 const char *short_archi;
7824 *path = NULL;
7826 /* environment may be empty */
7827 if (environment && strlen(environment)) {
7828 long_archi = environment;
7831 /* servername may be empty */
7832 if (servername && strlen(servername)) {
7833 pservername = canon_servername(servername);
7835 if (!is_myname_or_ipaddr(pservername)) {
7836 return WERR_INVALID_PARAM;
7840 if (!(short_archi = get_short_archi(long_archi))) {
7841 return WERR_INVALID_ENVIRONMENT;
7844 switch (component) {
7845 case SPOOLSS_PRTPROCS_PATH:
7846 case SPOOLSS_DRIVER_PATH:
7847 if (pservername) {
7848 *path = talloc_asprintf(mem_ctx,
7849 "\\\\%s\\%s\\%s",
7850 pservername,
7851 spoolss_paths[component].share,
7852 short_archi);
7853 } else {
7854 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
7855 SPOOLSS_DEFAULT_SERVER_PATH,
7856 spoolss_paths[component].dir,
7857 short_archi);
7859 break;
7860 default:
7861 return WERR_INVALID_PARAM;
7864 if (!*path) {
7865 return WERR_NOMEM;
7868 return WERR_OK;
7871 /****************************************************************************
7872 ****************************************************************************/
7874 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
7875 const char *servername,
7876 const char *environment,
7877 struct spoolss_DriverDirectoryInfo1 *r)
7879 WERROR werr;
7880 char *path = NULL;
7882 werr = compose_spoolss_server_path(mem_ctx,
7883 servername,
7884 environment,
7885 SPOOLSS_DRIVER_PATH,
7886 &path);
7887 if (!W_ERROR_IS_OK(werr)) {
7888 return werr;
7891 DEBUG(4,("printer driver directory: [%s]\n", path));
7893 r->directory_name = path;
7895 return WERR_OK;
7898 /****************************************************************
7899 _spoolss_GetPrinterDriverDirectory
7900 ****************************************************************/
7902 WERROR _spoolss_GetPrinterDriverDirectory(pipes_struct *p,
7903 struct spoolss_GetPrinterDriverDirectory *r)
7905 WERROR werror;
7907 /* that's an [in out] buffer */
7909 if (!r->in.buffer && (r->in.offered != 0)) {
7910 return WERR_INVALID_PARAM;
7913 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
7914 r->in.level));
7916 *r->out.needed = 0;
7918 /* r->in.level is ignored */
7920 werror = getprinterdriverdir_level_1(p->mem_ctx,
7921 r->in.server,
7922 r->in.environment,
7923 &r->out.info->info1);
7924 if (!W_ERROR_IS_OK(werror)) {
7925 TALLOC_FREE(r->out.info);
7926 return werror;
7929 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo, NULL,
7930 r->out.info, r->in.level);
7931 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7933 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7936 /****************************************************************
7937 _spoolss_EnumPrinterData
7938 ****************************************************************/
7940 WERROR _spoolss_EnumPrinterData(pipes_struct *p,
7941 struct spoolss_EnumPrinterData *r)
7943 NT_PRINTER_INFO_LEVEL *printer = NULL;
7944 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7945 int snum;
7946 WERROR result;
7947 REGISTRY_VALUE *val = NULL;
7948 NT_PRINTER_DATA *p_data;
7949 int i, key_index, num_values;
7950 int name_length;
7952 *r->out.value_needed = 0;
7953 *r->out.type = REG_NONE;
7954 *r->out.data_needed = 0;
7956 DEBUG(5,("_spoolss_EnumPrinterData\n"));
7958 if (!Printer) {
7959 DEBUG(2,("_spoolss_EnumPrinterData: Invalid handle (%s:%u:%u).\n",
7960 OUR_HANDLE(r->in.handle)));
7961 return WERR_BADFID;
7964 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7965 return WERR_BADFID;
7968 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
7969 if (!W_ERROR_IS_OK(result)) {
7970 return result;
7973 p_data = printer->info_2->data;
7974 key_index = lookup_printerkey( p_data, SPOOL_PRINTERDATA_KEY );
7976 result = WERR_OK;
7979 * The NT machine wants to know the biggest size of value and data
7981 * cf: MSDN EnumPrinterData remark section
7984 if (!r->in.value_offered && !r->in.data_offered && (key_index != -1)) {
7986 uint32_t biggest_valuesize = 0;
7987 uint32_t biggest_datasize = 0;
7989 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
7991 num_values = regval_ctr_numvals( p_data->keys[key_index].values );
7993 for ( i=0; i<num_values; i++ )
7995 val = regval_ctr_specific_value( p_data->keys[key_index].values, i );
7997 name_length = strlen(val->valuename);
7998 if ( strlen(val->valuename) > biggest_valuesize )
7999 biggest_valuesize = name_length;
8001 if ( val->size > biggest_datasize )
8002 biggest_datasize = val->size;
8004 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
8005 biggest_datasize));
8008 /* the value is an UNICODE string but real_value_size is the length
8009 in bytes including the trailing 0 */
8011 *r->out.value_needed = 2 * (1 + biggest_valuesize);
8012 *r->out.data_needed = biggest_datasize;
8014 DEBUG(6,("final values: [%d], [%d]\n",
8015 *r->out.value_needed, *r->out.data_needed));
8017 goto done;
8021 * the value len is wrong in NT sp3
8022 * that's the number of bytes not the number of unicode chars
8025 if (key_index != -1) {
8026 val = regval_ctr_specific_value(p_data->keys[key_index].values,
8027 r->in.enum_index);
8030 if (!val) {
8032 /* out_value should default to "" or else NT4 has
8033 problems unmarshalling the response */
8035 if (r->in.value_offered) {
8036 *r->out.value_needed = 1;
8037 r->out.value_name = talloc_strdup(r, "");
8038 if (!r->out.value_name) {
8039 result = WERR_NOMEM;
8040 goto done;
8042 } else {
8043 r->out.value_name = NULL;
8044 *r->out.value_needed = 0;
8047 /* the data is counted in bytes */
8049 *r->out.data_needed = r->in.data_offered;
8051 result = WERR_NO_MORE_ITEMS;
8052 } else {
8054 * the value is:
8055 * - counted in bytes in the request
8056 * - counted in UNICODE chars in the max reply
8057 * - counted in bytes in the real size
8059 * take a pause *before* coding not *during* coding
8062 /* name */
8063 if (r->in.value_offered) {
8064 r->out.value_name = talloc_strdup(r, regval_name(val));
8065 if (!r->out.value_name) {
8066 result = WERR_NOMEM;
8067 goto done;
8069 *r->out.value_needed = strlen_m(regval_name(val));
8070 } else {
8071 r->out.value_name = NULL;
8072 *r->out.value_needed = 0;
8075 /* type */
8077 *r->out.type = regval_type(val);
8079 /* data - counted in bytes */
8081 if (r->out.data && regval_size(val)) {
8082 memcpy(r->out.data, regval_data_p(val), regval_size(val));
8085 *r->out.data_needed = regval_size(val);
8088 done:
8089 free_a_printer(&printer, 2);
8090 return result;
8093 /****************************************************************
8094 _spoolss_SetPrinterData
8095 ****************************************************************/
8097 WERROR _spoolss_SetPrinterData(pipes_struct *p,
8098 struct spoolss_SetPrinterData *r)
8100 NT_PRINTER_INFO_LEVEL *printer = NULL;
8101 int snum=0;
8102 WERROR result = WERR_OK;
8103 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8104 DATA_BLOB blob;
8106 DEBUG(5,("_spoolss_SetPrinterData\n"));
8108 if (!Printer) {
8109 DEBUG(2,("_spoolss_SetPrinterData: Invalid handle (%s:%u:%u).\n",
8110 OUR_HANDLE(r->in.handle)));
8111 return WERR_BADFID;
8114 if (Printer->printer_type == SPLHND_SERVER) {
8115 DEBUG(10,("_spoolss_SetPrinterData: "
8116 "Not implemented for server handles yet\n"));
8117 return WERR_INVALID_PARAM;
8120 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8121 return WERR_BADFID;
8125 * Access check : NT returns "access denied" if you make a
8126 * SetPrinterData call without the necessary privildge.
8127 * we were originally returning OK if nothing changed
8128 * which made Win2k issue **a lot** of SetPrinterData
8129 * when connecting to a printer --jerry
8132 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8133 DEBUG(3,("_spoolss_SetPrinterData: "
8134 "change denied by handle access permissions\n"));
8135 result = WERR_ACCESS_DENIED;
8136 goto done;
8139 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8140 if (!W_ERROR_IS_OK(result)) {
8141 return result;
8144 result = push_spoolss_PrinterData(p->mem_ctx, &blob,
8145 r->in.type, &r->in.data);
8146 if (!W_ERROR_IS_OK(result)) {
8147 goto done;
8151 * When client side code sets a magic printer data key, detect it and save
8152 * the current printer data and the magic key's data (its the DEVMODE) for
8153 * future printer/driver initializations.
8155 if ((r->in.type == REG_BINARY) && strequal(r->in.value_name, PHANTOM_DEVMODE_KEY)) {
8156 /* Set devmode and printer initialization info */
8157 result = save_driver_init(printer, 2, blob.data, blob.length);
8159 srv_spoolss_reset_printerdata(printer->info_2->drivername);
8161 goto done;
8164 result = set_printer_dataex(printer, SPOOL_PRINTERDATA_KEY,
8165 r->in.value_name, r->in.type,
8166 blob.data, blob.length);
8167 if (W_ERROR_IS_OK(result)) {
8168 result = mod_a_printer(printer, 2);
8171 done:
8172 free_a_printer(&printer, 2);
8174 return result;
8177 /****************************************************************
8178 _spoolss_ResetPrinter
8179 ****************************************************************/
8181 WERROR _spoolss_ResetPrinter(pipes_struct *p,
8182 struct spoolss_ResetPrinter *r)
8184 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8185 int snum;
8187 DEBUG(5,("_spoolss_ResetPrinter\n"));
8190 * All we do is to check to see if the handle and queue is valid.
8191 * This call really doesn't mean anything to us because we only
8192 * support RAW printing. --jerry
8195 if (!Printer) {
8196 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8197 OUR_HANDLE(r->in.handle)));
8198 return WERR_BADFID;
8201 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8202 return WERR_BADFID;
8205 /* blindly return success */
8206 return WERR_OK;
8209 /****************************************************************
8210 _spoolss_DeletePrinterData
8211 ****************************************************************/
8213 WERROR _spoolss_DeletePrinterData(pipes_struct *p,
8214 struct spoolss_DeletePrinterData *r)
8216 NT_PRINTER_INFO_LEVEL *printer = NULL;
8217 int snum=0;
8218 WERROR status = WERR_OK;
8219 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8221 DEBUG(5,("_spoolss_DeletePrinterData\n"));
8223 if (!Printer) {
8224 DEBUG(2,("_spoolss_DeletePrinterData: Invalid handle (%s:%u:%u).\n",
8225 OUR_HANDLE(r->in.handle)));
8226 return WERR_BADFID;
8229 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8230 return WERR_BADFID;
8232 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8233 DEBUG(3, ("_spoolss_DeletePrinterData: "
8234 "printer properties change denied by handle\n"));
8235 return WERR_ACCESS_DENIED;
8238 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8239 if (!W_ERROR_IS_OK(status))
8240 return status;
8242 if (!r->in.value_name) {
8243 free_a_printer(&printer, 2);
8244 return WERR_NOMEM;
8247 status = delete_printer_dataex( printer, SPOOL_PRINTERDATA_KEY,
8248 r->in.value_name );
8250 if ( W_ERROR_IS_OK(status) )
8251 mod_a_printer( printer, 2 );
8253 free_a_printer(&printer, 2);
8255 return status;
8258 /****************************************************************
8259 _spoolss_AddForm
8260 ****************************************************************/
8262 WERROR _spoolss_AddForm(pipes_struct *p,
8263 struct spoolss_AddForm *r)
8265 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8266 nt_forms_struct tmpForm;
8267 int snum = -1;
8268 WERROR status = WERR_OK;
8269 NT_PRINTER_INFO_LEVEL *printer = NULL;
8270 SE_PRIV se_printop = SE_PRINT_OPERATOR;
8272 int count=0;
8273 nt_forms_struct *list=NULL;
8274 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8276 DEBUG(5,("_spoolss_AddForm\n"));
8278 if (!Printer) {
8279 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8280 OUR_HANDLE(r->in.handle)));
8281 return WERR_BADFID;
8285 /* forms can be added on printer of on the print server handle */
8287 if ( Printer->printer_type == SPLHND_PRINTER )
8289 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8290 return WERR_BADFID;
8292 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8293 if (!W_ERROR_IS_OK(status))
8294 goto done;
8297 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8298 and not a printer admin, then fail */
8300 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8301 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8302 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8303 NULL, NULL,
8304 p->server_info->ptok,
8305 lp_printer_admin(snum))) {
8306 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
8307 return WERR_ACCESS_DENIED;
8310 /* can't add if builtin */
8312 if (get_a_builtin_ntform_by_string(form->form_name, &tmpForm)) {
8313 status = WERR_FILE_EXISTS;
8314 goto done;
8317 count = get_ntforms(&list);
8319 if(!add_a_form(&list, form, &count)) {
8320 status = WERR_NOMEM;
8321 goto done;
8324 become_root();
8325 write_ntforms(&list, count);
8326 unbecome_root();
8329 * ChangeID must always be set if this is a printer
8332 if ( Printer->printer_type == SPLHND_PRINTER )
8333 status = mod_a_printer(printer, 2);
8335 done:
8336 if ( printer )
8337 free_a_printer(&printer, 2);
8338 SAFE_FREE(list);
8340 return status;
8343 /****************************************************************
8344 _spoolss_DeleteForm
8345 ****************************************************************/
8347 WERROR _spoolss_DeleteForm(pipes_struct *p,
8348 struct spoolss_DeleteForm *r)
8350 const char *form_name = r->in.form_name;
8351 nt_forms_struct tmpForm;
8352 int count=0;
8353 nt_forms_struct *list=NULL;
8354 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8355 int snum = -1;
8356 WERROR status = WERR_OK;
8357 NT_PRINTER_INFO_LEVEL *printer = NULL;
8358 SE_PRIV se_printop = SE_PRINT_OPERATOR;
8359 bool ret = false;
8361 DEBUG(5,("_spoolss_DeleteForm\n"));
8363 if (!Printer) {
8364 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8365 OUR_HANDLE(r->in.handle)));
8366 return WERR_BADFID;
8369 /* forms can be deleted on printer of on the print server handle */
8371 if ( Printer->printer_type == SPLHND_PRINTER )
8373 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8374 return WERR_BADFID;
8376 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8377 if (!W_ERROR_IS_OK(status))
8378 goto done;
8381 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8382 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8383 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8384 NULL, NULL,
8385 p->server_info->ptok,
8386 lp_printer_admin(snum))) {
8387 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8388 return WERR_ACCESS_DENIED;
8392 /* can't delete if builtin */
8394 if (get_a_builtin_ntform_by_string(form_name,&tmpForm)) {
8395 status = WERR_INVALID_PARAM;
8396 goto done;
8399 count = get_ntforms(&list);
8401 become_root();
8402 ret = delete_a_form(&list, form_name, &count, &status);
8403 unbecome_root();
8404 if (ret == false) {
8405 goto done;
8409 * ChangeID must always be set if this is a printer
8412 if ( Printer->printer_type == SPLHND_PRINTER )
8413 status = mod_a_printer(printer, 2);
8415 done:
8416 if ( printer )
8417 free_a_printer(&printer, 2);
8418 SAFE_FREE(list);
8420 return status;
8423 /****************************************************************
8424 _spoolss_SetForm
8425 ****************************************************************/
8427 WERROR _spoolss_SetForm(pipes_struct *p,
8428 struct spoolss_SetForm *r)
8430 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8431 nt_forms_struct tmpForm;
8432 int snum = -1;
8433 WERROR status = WERR_OK;
8434 NT_PRINTER_INFO_LEVEL *printer = NULL;
8435 SE_PRIV se_printop = SE_PRINT_OPERATOR;
8437 int count=0;
8438 nt_forms_struct *list=NULL;
8439 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8441 DEBUG(5,("_spoolss_SetForm\n"));
8443 if (!Printer) {
8444 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8445 OUR_HANDLE(r->in.handle)));
8446 return WERR_BADFID;
8449 /* forms can be modified on printer of on the print server handle */
8451 if ( Printer->printer_type == SPLHND_PRINTER )
8453 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8454 return WERR_BADFID;
8456 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8457 if (!W_ERROR_IS_OK(status))
8458 goto done;
8461 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8462 and not a printer admin, then fail */
8464 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8465 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8466 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8467 NULL, NULL,
8468 p->server_info->ptok,
8469 lp_printer_admin(snum))) {
8470 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8471 return WERR_ACCESS_DENIED;
8474 /* can't set if builtin */
8475 if (get_a_builtin_ntform_by_string(form->form_name, &tmpForm)) {
8476 status = WERR_INVALID_PARAM;
8477 goto done;
8480 count = get_ntforms(&list);
8481 update_a_form(&list, form, count);
8482 become_root();
8483 write_ntforms(&list, count);
8484 unbecome_root();
8487 * ChangeID must always be set if this is a printer
8490 if ( Printer->printer_type == SPLHND_PRINTER )
8491 status = mod_a_printer(printer, 2);
8494 done:
8495 if ( printer )
8496 free_a_printer(&printer, 2);
8497 SAFE_FREE(list);
8499 return status;
8502 /****************************************************************************
8503 fill_print_processor1
8504 ****************************************************************************/
8506 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8507 struct spoolss_PrintProcessorInfo1 *r,
8508 const char *print_processor_name)
8510 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8511 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8513 return WERR_OK;
8516 /****************************************************************************
8517 enumprintprocessors level 1.
8518 ****************************************************************************/
8520 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8521 union spoolss_PrintProcessorInfo **info_p,
8522 uint32_t *count)
8524 union spoolss_PrintProcessorInfo *info;
8525 WERROR result;
8527 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8528 W_ERROR_HAVE_NO_MEMORY(info);
8530 *count = 1;
8532 result = fill_print_processor1(info, &info[0].info1, "winprint");
8533 if (!W_ERROR_IS_OK(result)) {
8534 goto out;
8537 out:
8538 if (!W_ERROR_IS_OK(result)) {
8539 TALLOC_FREE(info);
8540 *count = 0;
8541 return result;
8544 *info_p = info;
8546 return WERR_OK;
8549 /****************************************************************
8550 _spoolss_EnumPrintProcessors
8551 ****************************************************************/
8553 WERROR _spoolss_EnumPrintProcessors(pipes_struct *p,
8554 struct spoolss_EnumPrintProcessors *r)
8556 WERROR result;
8558 /* that's an [in out] buffer */
8560 if (!r->in.buffer && (r->in.offered != 0)) {
8561 return WERR_INVALID_PARAM;
8564 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8567 * Enumerate the print processors ...
8569 * Just reply with "winprint", to keep NT happy
8570 * and I can use my nice printer checker.
8573 *r->out.count = 0;
8574 *r->out.needed = 0;
8575 *r->out.info = NULL;
8577 switch (r->in.level) {
8578 case 1:
8579 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8580 r->out.count);
8581 break;
8582 default:
8583 return WERR_UNKNOWN_LEVEL;
8586 if (!W_ERROR_IS_OK(result)) {
8587 return result;
8590 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8591 spoolss_EnumPrintProcessors, NULL,
8592 *r->out.info, r->in.level,
8593 *r->out.count);
8594 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8595 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8597 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8600 /****************************************************************************
8601 fill_printprocdatatype1
8602 ****************************************************************************/
8604 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8605 struct spoolss_PrintProcDataTypesInfo1 *r,
8606 const char *name_array)
8608 r->name_array = talloc_strdup(mem_ctx, name_array);
8609 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8611 return WERR_OK;
8614 /****************************************************************************
8615 enumprintprocdatatypes level 1.
8616 ****************************************************************************/
8618 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8619 union spoolss_PrintProcDataTypesInfo **info_p,
8620 uint32_t *count)
8622 WERROR result;
8623 union spoolss_PrintProcDataTypesInfo *info;
8625 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8626 W_ERROR_HAVE_NO_MEMORY(info);
8628 *count = 1;
8630 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
8631 if (!W_ERROR_IS_OK(result)) {
8632 goto out;
8635 out:
8636 if (!W_ERROR_IS_OK(result)) {
8637 TALLOC_FREE(info);
8638 *count = 0;
8639 return result;
8642 *info_p = info;
8644 return WERR_OK;
8647 /****************************************************************
8648 _spoolss_EnumPrintProcDataTypes
8649 ****************************************************************/
8651 WERROR _spoolss_EnumPrintProcDataTypes(pipes_struct *p,
8652 struct spoolss_EnumPrintProcDataTypes *r)
8654 WERROR result;
8656 /* that's an [in out] buffer */
8658 if (!r->in.buffer && (r->in.offered != 0)) {
8659 return WERR_INVALID_PARAM;
8662 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8664 *r->out.count = 0;
8665 *r->out.needed = 0;
8666 *r->out.info = NULL;
8668 switch (r->in.level) {
8669 case 1:
8670 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
8671 r->out.count);
8672 break;
8673 default:
8674 return WERR_UNKNOWN_LEVEL;
8677 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8678 spoolss_EnumPrintProcDataTypes, NULL,
8679 *r->out.info, r->in.level,
8680 *r->out.count);
8681 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8682 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8684 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8687 /****************************************************************************
8688 fill_monitor_1
8689 ****************************************************************************/
8691 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
8692 struct spoolss_MonitorInfo1 *r,
8693 const char *monitor_name)
8695 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8696 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8698 return WERR_OK;
8701 /****************************************************************************
8702 fill_monitor_2
8703 ****************************************************************************/
8705 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
8706 struct spoolss_MonitorInfo2 *r,
8707 const char *monitor_name,
8708 const char *environment,
8709 const char *dll_name)
8711 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8712 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8713 r->environment = talloc_strdup(mem_ctx, environment);
8714 W_ERROR_HAVE_NO_MEMORY(r->environment);
8715 r->dll_name = talloc_strdup(mem_ctx, dll_name);
8716 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
8718 return WERR_OK;
8721 /****************************************************************************
8722 enumprintmonitors level 1.
8723 ****************************************************************************/
8725 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
8726 union spoolss_MonitorInfo **info_p,
8727 uint32_t *count)
8729 union spoolss_MonitorInfo *info;
8730 WERROR result = WERR_OK;
8732 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8733 W_ERROR_HAVE_NO_MEMORY(info);
8735 *count = 2;
8737 result = fill_monitor_1(info, &info[0].info1,
8738 SPL_LOCAL_PORT);
8739 if (!W_ERROR_IS_OK(result)) {
8740 goto out;
8743 result = fill_monitor_1(info, &info[1].info1,
8744 SPL_TCPIP_PORT);
8745 if (!W_ERROR_IS_OK(result)) {
8746 goto out;
8749 out:
8750 if (!W_ERROR_IS_OK(result)) {
8751 TALLOC_FREE(info);
8752 *count = 0;
8753 return result;
8756 *info_p = info;
8758 return WERR_OK;
8761 /****************************************************************************
8762 enumprintmonitors level 2.
8763 ****************************************************************************/
8765 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
8766 union spoolss_MonitorInfo **info_p,
8767 uint32_t *count)
8769 union spoolss_MonitorInfo *info;
8770 WERROR result = WERR_OK;
8772 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8773 W_ERROR_HAVE_NO_MEMORY(info);
8775 *count = 2;
8777 result = fill_monitor_2(info, &info[0].info2,
8778 SPL_LOCAL_PORT,
8779 "Windows NT X86", /* FIXME */
8780 "localmon.dll");
8781 if (!W_ERROR_IS_OK(result)) {
8782 goto out;
8785 result = fill_monitor_2(info, &info[1].info2,
8786 SPL_TCPIP_PORT,
8787 "Windows NT X86", /* FIXME */
8788 "tcpmon.dll");
8789 if (!W_ERROR_IS_OK(result)) {
8790 goto out;
8793 out:
8794 if (!W_ERROR_IS_OK(result)) {
8795 TALLOC_FREE(info);
8796 *count = 0;
8797 return result;
8800 *info_p = info;
8802 return WERR_OK;
8805 /****************************************************************
8806 _spoolss_EnumMonitors
8807 ****************************************************************/
8809 WERROR _spoolss_EnumMonitors(pipes_struct *p,
8810 struct spoolss_EnumMonitors *r)
8812 WERROR result;
8814 /* that's an [in out] buffer */
8816 if (!r->in.buffer && (r->in.offered != 0)) {
8817 return WERR_INVALID_PARAM;
8820 DEBUG(5,("_spoolss_EnumMonitors\n"));
8823 * Enumerate the print monitors ...
8825 * Just reply with "Local Port", to keep NT happy
8826 * and I can use my nice printer checker.
8829 *r->out.count = 0;
8830 *r->out.needed = 0;
8831 *r->out.info = NULL;
8833 switch (r->in.level) {
8834 case 1:
8835 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
8836 r->out.count);
8837 break;
8838 case 2:
8839 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
8840 r->out.count);
8841 break;
8842 default:
8843 return WERR_UNKNOWN_LEVEL;
8846 if (!W_ERROR_IS_OK(result)) {
8847 return result;
8850 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8851 spoolss_EnumMonitors, NULL,
8852 *r->out.info, r->in.level,
8853 *r->out.count);
8854 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8855 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8857 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8860 /****************************************************************************
8861 ****************************************************************************/
8863 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
8864 const print_queue_struct *queue,
8865 int count, int snum,
8866 const NT_PRINTER_INFO_LEVEL *ntprinter,
8867 uint32_t jobid,
8868 struct spoolss_JobInfo1 *r)
8870 int i = 0;
8871 bool found = false;
8873 for (i=0; i<count && found == false; i++) {
8874 if (queue[i].job == (int)jobid) {
8875 found = true;
8879 if (found == false) {
8880 /* NT treats not found as bad param... yet another bad choice */
8881 return WERR_INVALID_PARAM;
8884 return fill_job_info1(mem_ctx,
8886 &queue[i-1],
8888 snum,
8889 ntprinter);
8892 /****************************************************************************
8893 ****************************************************************************/
8895 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
8896 const print_queue_struct *queue,
8897 int count, int snum,
8898 const NT_PRINTER_INFO_LEVEL *ntprinter,
8899 uint32_t jobid,
8900 struct spoolss_JobInfo2 *r)
8902 int i = 0;
8903 bool found = false;
8904 struct spoolss_DeviceMode *devmode;
8905 NT_DEVICEMODE *nt_devmode;
8906 WERROR result;
8908 for (i=0; i<count && found == false; i++) {
8909 if (queue[i].job == (int)jobid) {
8910 found = true;
8914 if (found == false) {
8915 /* NT treats not found as bad param... yet another bad
8916 choice */
8917 return WERR_INVALID_PARAM;
8921 * if the print job does not have a DEVMODE associated with it,
8922 * just use the one for the printer. A NULL devicemode is not
8923 * a failure condition
8926 nt_devmode = print_job_devmode(lp_const_servicename(snum), jobid);
8927 if (nt_devmode) {
8928 devmode = TALLOC_ZERO_P(mem_ctx, struct spoolss_DeviceMode);
8929 W_ERROR_HAVE_NO_MEMORY(devmode);
8930 result = convert_nt_devicemode(devmode, devmode, nt_devmode);
8931 if (!W_ERROR_IS_OK(result)) {
8932 return result;
8934 } else {
8935 devmode = construct_dev_mode(mem_ctx, lp_const_servicename(snum));
8936 W_ERROR_HAVE_NO_MEMORY(devmode);
8939 return fill_job_info2(mem_ctx,
8941 &queue[i-1],
8943 snum,
8944 ntprinter,
8945 devmode);
8948 /****************************************************************
8949 _spoolss_GetJob
8950 ****************************************************************/
8952 WERROR _spoolss_GetJob(pipes_struct *p,
8953 struct spoolss_GetJob *r)
8955 WERROR result = WERR_OK;
8956 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
8957 int snum;
8958 int count;
8959 print_queue_struct *queue = NULL;
8960 print_status_struct prt_status;
8962 /* that's an [in out] buffer */
8964 if (!r->in.buffer && (r->in.offered != 0)) {
8965 return WERR_INVALID_PARAM;
8968 DEBUG(5,("_spoolss_GetJob\n"));
8970 *r->out.needed = 0;
8972 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8973 return WERR_BADFID;
8976 result = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum));
8977 if (!W_ERROR_IS_OK(result)) {
8978 return result;
8981 count = print_queue_status(snum, &queue, &prt_status);
8983 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
8984 count, prt_status.status, prt_status.message));
8986 switch (r->in.level) {
8987 case 1:
8988 result = getjob_level_1(p->mem_ctx,
8989 queue, count, snum, ntprinter,
8990 r->in.job_id, &r->out.info->info1);
8991 break;
8992 case 2:
8993 result = getjob_level_2(p->mem_ctx,
8994 queue, count, snum, ntprinter,
8995 r->in.job_id, &r->out.info->info2);
8996 break;
8997 default:
8998 result = WERR_UNKNOWN_LEVEL;
8999 break;
9002 SAFE_FREE(queue);
9003 free_a_printer(&ntprinter, 2);
9005 if (!W_ERROR_IS_OK(result)) {
9006 TALLOC_FREE(r->out.info);
9007 return result;
9010 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, NULL,
9011 r->out.info, r->in.level);
9012 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9014 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9017 /****************************************************************
9018 _spoolss_GetPrinterDataEx
9020 From MSDN documentation of GetPrinterDataEx: pass request
9021 to GetPrinterData if key is "PrinterDriverData".
9022 ****************************************************************/
9024 WERROR _spoolss_GetPrinterDataEx(pipes_struct *p,
9025 struct spoolss_GetPrinterDataEx *r)
9028 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9029 REGISTRY_VALUE *val = NULL;
9030 NT_PRINTER_INFO_LEVEL *printer = NULL;
9031 int snum = 0;
9032 WERROR result = WERR_OK;
9034 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
9036 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
9037 r->in.key_name, r->in.value_name));
9039 /* in case of problem, return some default values */
9041 *r->out.needed = 0;
9042 *r->out.type = REG_NONE;
9044 if (!Printer) {
9045 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9046 OUR_HANDLE(r->in.handle)));
9047 result = WERR_BADFID;
9048 goto done;
9051 /* Is the handle to a printer or to the server? */
9053 if (Printer->printer_type == SPLHND_SERVER) {
9054 DEBUG(10,("_spoolss_GetPrinterDataEx: "
9055 "Not implemented for server handles yet\n"));
9056 result = WERR_INVALID_PARAM;
9057 goto done;
9060 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9061 return WERR_BADFID;
9064 result = get_a_printer(Printer, &printer, 2, lp_servicename(snum));
9065 if (!W_ERROR_IS_OK(result)) {
9066 goto done;
9069 /* check to see if the keyname is valid */
9070 if (!strlen(r->in.key_name)) {
9071 result = WERR_INVALID_PARAM;
9072 goto done;
9075 if (lookup_printerkey(printer->info_2->data, r->in.key_name) == -1) {
9076 DEBUG(4,("_spoolss_GetPrinterDataEx: "
9077 "Invalid keyname [%s]\n", r->in.key_name ));
9078 result = WERR_BADFILE;
9079 goto done;
9082 /* When given a new keyname, we should just create it */
9084 val = get_printer_data(printer->info_2,
9085 r->in.key_name, r->in.value_name);
9086 if (!val) {
9087 result = WERR_BADFILE;
9088 goto done;
9091 *r->out.needed = regval_size(val);
9093 if (*r->out.needed > r->in.offered) {
9094 result = WERR_MORE_DATA;
9095 goto done;
9098 *r->out.type = regval_type(val);
9100 memcpy(r->out.buffer, regval_data_p(val), regval_size(val));
9102 done:
9103 if (printer) {
9104 free_a_printer(&printer, 2);
9107 return result;
9110 /****************************************************************
9111 _spoolss_SetPrinterDataEx
9112 ****************************************************************/
9114 WERROR _spoolss_SetPrinterDataEx(pipes_struct *p,
9115 struct spoolss_SetPrinterDataEx *r)
9117 NT_PRINTER_INFO_LEVEL *printer = NULL;
9118 int snum = 0;
9119 WERROR result = WERR_OK;
9120 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9121 char *oid_string;
9123 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
9125 /* From MSDN documentation of SetPrinterDataEx: pass request to
9126 SetPrinterData if key is "PrinterDriverData" */
9128 if (!Printer) {
9129 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9130 OUR_HANDLE(r->in.handle)));
9131 return WERR_BADFID;
9134 if (Printer->printer_type == SPLHND_SERVER) {
9135 DEBUG(10,("_spoolss_SetPrinterDataEx: "
9136 "Not implemented for server handles yet\n"));
9137 return WERR_INVALID_PARAM;
9140 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9141 return WERR_BADFID;
9145 * Access check : NT returns "access denied" if you make a
9146 * SetPrinterData call without the necessary privildge.
9147 * we were originally returning OK if nothing changed
9148 * which made Win2k issue **a lot** of SetPrinterData
9149 * when connecting to a printer --jerry
9152 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9153 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
9154 "change denied by handle access permissions\n"));
9155 return WERR_ACCESS_DENIED;
9158 result = get_a_printer(Printer, &printer, 2, lp_servicename(snum));
9159 if (!W_ERROR_IS_OK(result)) {
9160 return result;
9163 /* check for OID in valuename */
9165 oid_string = strchr(r->in.value_name, ',');
9166 if (oid_string) {
9167 *oid_string = '\0';
9168 oid_string++;
9171 /* save the registry data */
9173 result = set_printer_dataex(printer, r->in.key_name, r->in.value_name,
9174 r->in.type, r->in.buffer, r->in.offered);
9176 if (W_ERROR_IS_OK(result)) {
9177 /* save the OID if one was specified */
9178 if (oid_string) {
9179 char *str = talloc_asprintf(p->mem_ctx, "%s\\%s",
9180 r->in.key_name, SPOOL_OID_KEY);
9181 if (!str) {
9182 result = WERR_NOMEM;
9183 goto done;
9187 * I'm not checking the status here on purpose. Don't know
9188 * if this is right, but I'm returning the status from the
9189 * previous set_printer_dataex() call. I have no idea if
9190 * this is right. --jerry
9193 set_printer_dataex(printer, str, r->in.value_name,
9194 REG_SZ, (uint8_t *)oid_string,
9195 strlen(oid_string)+1);
9198 result = mod_a_printer(printer, 2);
9201 done:
9202 free_a_printer(&printer, 2);
9204 return result;
9207 /****************************************************************
9208 _spoolss_DeletePrinterDataEx
9209 ****************************************************************/
9211 WERROR _spoolss_DeletePrinterDataEx(pipes_struct *p,
9212 struct spoolss_DeletePrinterDataEx *r)
9214 NT_PRINTER_INFO_LEVEL *printer = NULL;
9215 int snum=0;
9216 WERROR status = WERR_OK;
9217 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9219 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9221 if (!Printer) {
9222 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9223 "Invalid handle (%s:%u:%u).\n",
9224 OUR_HANDLE(r->in.handle)));
9225 return WERR_BADFID;
9228 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
9229 return WERR_BADFID;
9231 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9232 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9233 "printer properties change denied by handle\n"));
9234 return WERR_ACCESS_DENIED;
9237 if (!r->in.value_name || !r->in.key_name) {
9238 return WERR_NOMEM;
9241 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9242 if (!W_ERROR_IS_OK(status))
9243 return status;
9245 status = delete_printer_dataex( printer, r->in.key_name, r->in.value_name );
9247 if ( W_ERROR_IS_OK(status) )
9248 mod_a_printer( printer, 2 );
9250 free_a_printer(&printer, 2);
9252 return status;
9255 /****************************************************************
9256 _spoolss_EnumPrinterKey
9257 ****************************************************************/
9259 WERROR _spoolss_EnumPrinterKey(pipes_struct *p,
9260 struct spoolss_EnumPrinterKey *r)
9262 fstring *keynames = NULL;
9263 int num_keys;
9264 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9265 NT_PRINTER_DATA *data;
9266 NT_PRINTER_INFO_LEVEL *printer = NULL;
9267 int snum = 0;
9268 WERROR result = WERR_BADFILE;
9269 int i;
9270 const char **array = NULL;
9273 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
9275 if (!Printer) {
9276 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
9277 OUR_HANDLE(r->in.handle)));
9278 return WERR_BADFID;
9281 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9282 return WERR_BADFID;
9285 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9286 if (!W_ERROR_IS_OK(result)) {
9287 return result;
9290 /* get the list of subkey names */
9292 data = printer->info_2->data;
9294 num_keys = get_printer_subkeys(data, r->in.key_name, &keynames);
9295 if (num_keys == -1) {
9296 result = WERR_BADFILE;
9297 goto done;
9300 *r->out.needed = 4;
9302 array = talloc_zero_array(r->out.key_buffer, const char *, num_keys + 1);
9303 if (!array) {
9304 result = WERR_NOMEM;
9305 goto done;
9308 for (i=0; i < num_keys; i++) {
9309 array[i] = talloc_strdup(array, keynames[i]);
9310 if (!array[i]) {
9311 result = WERR_NOMEM;
9312 goto done;
9315 *r->out.needed += strlen_m_term(keynames[i]) * 2;
9318 if (r->in.offered < *r->out.needed) {
9319 result = WERR_MORE_DATA;
9320 goto done;
9323 result = WERR_OK;
9325 *r->out.key_buffer = array;
9327 done:
9328 if (!W_ERROR_IS_OK(result)) {
9329 TALLOC_FREE(array);
9330 ZERO_STRUCTP(r->out.key_buffer);
9333 free_a_printer(&printer, 2);
9334 SAFE_FREE(keynames);
9336 return result;
9339 /****************************************************************
9340 _spoolss_DeletePrinterKey
9341 ****************************************************************/
9343 WERROR _spoolss_DeletePrinterKey(pipes_struct *p,
9344 struct spoolss_DeletePrinterKey *r)
9346 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9347 NT_PRINTER_INFO_LEVEL *printer = NULL;
9348 int snum=0;
9349 WERROR status;
9351 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9353 if (!Printer) {
9354 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9355 OUR_HANDLE(r->in.handle)));
9356 return WERR_BADFID;
9359 /* if keyname == NULL, return error */
9361 if ( !r->in.key_name )
9362 return WERR_INVALID_PARAM;
9364 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
9365 return WERR_BADFID;
9367 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9368 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9369 "printer properties change denied by handle\n"));
9370 return WERR_ACCESS_DENIED;
9373 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9374 if (!W_ERROR_IS_OK(status))
9375 return status;
9377 /* delete the key and all subneys */
9379 status = delete_all_printer_data( printer->info_2, r->in.key_name );
9381 if ( W_ERROR_IS_OK(status) )
9382 status = mod_a_printer(printer, 2);
9384 free_a_printer( &printer, 2 );
9386 return status;
9389 /****************************************************************
9390 ****************************************************************/
9392 static WERROR registry_value_to_printer_enum_value(TALLOC_CTX *mem_ctx,
9393 REGISTRY_VALUE *v,
9394 struct spoolss_PrinterEnumValues *r)
9396 WERROR result;
9398 r->data = TALLOC_ZERO_P(mem_ctx, union spoolss_PrinterData);
9399 W_ERROR_HAVE_NO_MEMORY(r->data);
9401 r->value_name = talloc_strdup(mem_ctx, regval_name(v));
9402 W_ERROR_HAVE_NO_MEMORY(r->value_name);
9404 r->type = regval_type(v);
9405 r->data_length = regval_size(v);
9407 if (r->data_length) {
9408 DATA_BLOB blob = data_blob_const(regval_data_p(v),
9409 regval_size(v));
9410 result = pull_spoolss_PrinterData(mem_ctx, &blob,
9411 r->data,
9412 r->type);
9413 if (!W_ERROR_IS_OK(result)) {
9414 return result;
9418 return WERR_OK;
9421 /****************************************************************
9422 _spoolss_EnumPrinterDataEx
9423 ****************************************************************/
9425 WERROR _spoolss_EnumPrinterDataEx(pipes_struct *p,
9426 struct spoolss_EnumPrinterDataEx *r)
9428 uint32_t count = 0;
9429 NT_PRINTER_INFO_LEVEL *printer = NULL;
9430 struct spoolss_PrinterEnumValues *info = NULL;
9431 NT_PRINTER_DATA *p_data;
9432 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9433 int snum;
9434 WERROR result;
9435 int key_index;
9436 int i;
9438 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9440 *r->out.count = 0;
9441 *r->out.needed = 0;
9442 *r->out.info = NULL;
9444 if (!Printer) {
9445 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9446 OUR_HANDLE(r->in.handle)));
9447 return WERR_BADFID;
9451 * first check for a keyname of NULL or "". Win2k seems to send
9452 * this a lot and we should send back WERR_INVALID_PARAM
9453 * no need to spend time looking up the printer in this case.
9454 * --jerry
9457 if (!strlen(r->in.key_name)) {
9458 result = WERR_INVALID_PARAM;
9459 goto done;
9462 /* get the printer off of disk */
9464 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9465 return WERR_BADFID;
9468 ZERO_STRUCT(printer);
9469 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9470 if (!W_ERROR_IS_OK(result)) {
9471 return result;
9474 /* now look for a match on the key name */
9476 p_data = printer->info_2->data;
9478 key_index = lookup_printerkey(p_data, r->in.key_name);
9479 if (key_index == -1) {
9480 DEBUG(10,("_spoolss_EnumPrinterDataEx: Unknown keyname [%s]\n",
9481 r->in.key_name));
9482 result = WERR_INVALID_PARAM;
9483 goto done;
9486 /* allocate the memory for the array of pointers -- if necessary */
9488 count = regval_ctr_numvals(p_data->keys[key_index].values);
9489 if (!count) {
9490 result = WERR_OK; /* ??? */
9491 goto done;
9494 info = TALLOC_ZERO_ARRAY(p->mem_ctx,
9495 struct spoolss_PrinterEnumValues,
9496 count);
9497 if (!info) {
9498 DEBUG(0,("_spoolss_EnumPrinterDataEx: talloc() failed\n"));
9499 result = WERR_NOMEM;
9500 goto done;
9504 * loop through all params and build the array to pass
9505 * back to the client
9508 for (i=0; i < count; i++) {
9510 REGISTRY_VALUE *val;
9512 /* lookup the registry value */
9514 val = regval_ctr_specific_value(p_data->keys[key_index].values, i);
9516 DEBUG(10,("retrieved value number [%d] [%s]\n", i, regval_name(val)));
9518 /* copy the data */
9520 result = registry_value_to_printer_enum_value(info, val, &info[i]);
9521 if (!W_ERROR_IS_OK(result)) {
9522 goto done;
9526 #if 0 /* FIXME - gd */
9527 /* housekeeping information in the reply */
9529 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9530 * the hand marshalled container size is a multiple
9531 * of 4 bytes for RPC alignment.
9534 if (needed % 4) {
9535 needed += 4-(needed % 4);
9537 #endif
9538 *r->out.count = count;
9539 *r->out.info = info;
9541 done:
9543 if (printer) {
9544 free_a_printer(&printer, 2);
9547 if (!W_ERROR_IS_OK(result)) {
9548 return result;
9551 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
9552 spoolss_EnumPrinterDataEx, NULL,
9553 *r->out.info,
9554 *r->out.count);
9555 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9556 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
9558 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9561 /****************************************************************************
9562 ****************************************************************************/
9564 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
9565 const char *servername,
9566 const char *environment,
9567 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9569 WERROR werr;
9570 char *path = NULL;
9572 werr = compose_spoolss_server_path(mem_ctx,
9573 servername,
9574 environment,
9575 SPOOLSS_PRTPROCS_PATH,
9576 &path);
9577 if (!W_ERROR_IS_OK(werr)) {
9578 return werr;
9581 DEBUG(4,("print processor directory: [%s]\n", path));
9583 r->directory_name = path;
9585 return WERR_OK;
9588 /****************************************************************
9589 _spoolss_GetPrintProcessorDirectory
9590 ****************************************************************/
9592 WERROR _spoolss_GetPrintProcessorDirectory(pipes_struct *p,
9593 struct spoolss_GetPrintProcessorDirectory *r)
9595 WERROR result;
9597 /* that's an [in out] buffer */
9599 if (!r->in.buffer && (r->in.offered != 0)) {
9600 return WERR_INVALID_PARAM;
9603 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9604 r->in.level));
9606 *r->out.needed = 0;
9608 /* r->in.level is ignored */
9610 result = getprintprocessordirectory_level_1(p->mem_ctx,
9611 r->in.server,
9612 r->in.environment,
9613 &r->out.info->info1);
9614 if (!W_ERROR_IS_OK(result)) {
9615 TALLOC_FREE(r->out.info);
9616 return result;
9619 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo, NULL,
9620 r->out.info, r->in.level);
9621 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9623 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9626 /*******************************************************************
9627 ********************************************************************/
9629 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
9630 const char *dllname)
9632 enum ndr_err_code ndr_err;
9633 struct spoolss_MonitorUi ui;
9635 ui.dll_name = dllname;
9637 ndr_err = ndr_push_struct_blob(buf, mem_ctx, NULL, &ui,
9638 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
9639 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9640 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
9642 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9645 /*******************************************************************
9646 Streams the monitor UI DLL name in UNICODE
9647 *******************************************************************/
9649 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
9650 NT_USER_TOKEN *token, DATA_BLOB *in,
9651 DATA_BLOB *out, uint32_t *needed)
9653 const char *dllname = "tcpmonui.dll";
9655 *needed = (strlen(dllname)+1) * 2;
9657 if (out->length < *needed) {
9658 return WERR_INSUFFICIENT_BUFFER;
9661 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9662 return WERR_NOMEM;
9665 return WERR_OK;
9668 /*******************************************************************
9669 ********************************************************************/
9671 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
9672 struct spoolss_PortData1 *port1,
9673 const DATA_BLOB *buf)
9675 enum ndr_err_code ndr_err;
9676 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, NULL, port1,
9677 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
9678 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9679 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
9681 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9684 /*******************************************************************
9685 ********************************************************************/
9687 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
9688 struct spoolss_PortData2 *port2,
9689 const DATA_BLOB *buf)
9691 enum ndr_err_code ndr_err;
9692 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, NULL, port2,
9693 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
9694 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9695 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
9697 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9700 /*******************************************************************
9701 Create a new TCP/IP port
9702 *******************************************************************/
9704 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
9705 NT_USER_TOKEN *token, DATA_BLOB *in,
9706 DATA_BLOB *out, uint32_t *needed)
9708 struct spoolss_PortData1 port1;
9709 struct spoolss_PortData2 port2;
9710 char *device_uri = NULL;
9711 uint32_t version;
9713 const char *portname;
9714 const char *hostaddress;
9715 const char *queue;
9716 uint32_t port_number;
9717 uint32_t protocol;
9719 /* peek for spoolss_PortData version */
9721 if (!in || (in->length < (128 + 4))) {
9722 return WERR_GENERAL_FAILURE;
9725 version = IVAL(in->data, 128);
9727 switch (version) {
9728 case 1:
9729 ZERO_STRUCT(port1);
9731 if (!pull_port_data_1(mem_ctx, &port1, in)) {
9732 return WERR_NOMEM;
9735 portname = port1.portname;
9736 hostaddress = port1.hostaddress;
9737 queue = port1.queue;
9738 protocol = port1.protocol;
9739 port_number = port1.port_number;
9741 break;
9742 case 2:
9743 ZERO_STRUCT(port2);
9745 if (!pull_port_data_2(mem_ctx, &port2, in)) {
9746 return WERR_NOMEM;
9749 portname = port2.portname;
9750 hostaddress = port2.hostaddress;
9751 queue = port2.queue;
9752 protocol = port2.protocol;
9753 port_number = port2.port_number;
9755 break;
9756 default:
9757 DEBUG(1,("xcvtcp_addport: "
9758 "unknown version of port_data: %d\n", version));
9759 return WERR_UNKNOWN_PORT;
9762 /* create the device URI and call the add_port_hook() */
9764 switch (protocol) {
9765 case PROTOCOL_RAWTCP_TYPE:
9766 device_uri = talloc_asprintf(mem_ctx,
9767 "socket://%s:%d/", hostaddress,
9768 port_number);
9769 break;
9771 case PROTOCOL_LPR_TYPE:
9772 device_uri = talloc_asprintf(mem_ctx,
9773 "lpr://%s/%s", hostaddress, queue );
9774 break;
9776 default:
9777 return WERR_UNKNOWN_PORT;
9780 if (!device_uri) {
9781 return WERR_NOMEM;
9784 return add_port_hook(mem_ctx, token, portname, device_uri);
9787 /*******************************************************************
9788 *******************************************************************/
9790 struct xcv_api_table xcvtcp_cmds[] = {
9791 { "MonitorUI", xcvtcp_monitorui },
9792 { "AddPort", xcvtcp_addport},
9793 { NULL, NULL }
9796 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
9797 NT_USER_TOKEN *token, const char *command,
9798 DATA_BLOB *inbuf,
9799 DATA_BLOB *outbuf,
9800 uint32_t *needed )
9802 int i;
9804 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
9806 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
9807 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
9808 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9811 return WERR_BADFUNC;
9814 /*******************************************************************
9815 *******************************************************************/
9816 #if 0 /* don't support management using the "Local Port" monitor */
9818 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
9819 NT_USER_TOKEN *token, DATA_BLOB *in,
9820 DATA_BLOB *out, uint32_t *needed)
9822 const char *dllname = "localui.dll";
9824 *needed = (strlen(dllname)+1) * 2;
9826 if (out->length < *needed) {
9827 return WERR_INSUFFICIENT_BUFFER;
9830 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9831 return WERR_NOMEM;
9834 return WERR_OK;
9837 /*******************************************************************
9838 *******************************************************************/
9840 struct xcv_api_table xcvlocal_cmds[] = {
9841 { "MonitorUI", xcvlocal_monitorui },
9842 { NULL, NULL }
9844 #else
9845 struct xcv_api_table xcvlocal_cmds[] = {
9846 { NULL, NULL }
9848 #endif
9852 /*******************************************************************
9853 *******************************************************************/
9855 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
9856 NT_USER_TOKEN *token, const char *command,
9857 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
9858 uint32_t *needed)
9860 int i;
9862 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
9864 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
9865 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
9866 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9868 return WERR_BADFUNC;
9871 /****************************************************************
9872 _spoolss_XcvData
9873 ****************************************************************/
9875 WERROR _spoolss_XcvData(pipes_struct *p,
9876 struct spoolss_XcvData *r)
9878 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9879 DATA_BLOB out_data = data_blob_null;
9880 WERROR werror;
9882 if (!Printer) {
9883 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
9884 OUR_HANDLE(r->in.handle)));
9885 return WERR_BADFID;
9888 /* Has to be a handle to the TCP/IP port monitor */
9890 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
9891 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
9892 return WERR_BADFID;
9895 /* requires administrative access to the server */
9897 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
9898 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
9899 return WERR_ACCESS_DENIED;
9902 /* Allocate the outgoing buffer */
9904 if (r->in.out_data_size) {
9905 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
9906 if (out_data.data == NULL) {
9907 return WERR_NOMEM;
9911 switch ( Printer->printer_type ) {
9912 case SPLHND_PORTMON_TCP:
9913 werror = process_xcvtcp_command(p->mem_ctx,
9914 p->server_info->ptok,
9915 r->in.function_name,
9916 &r->in.in_data, &out_data,
9917 r->out.needed);
9918 break;
9919 case SPLHND_PORTMON_LOCAL:
9920 werror = process_xcvlocal_command(p->mem_ctx,
9921 p->server_info->ptok,
9922 r->in.function_name,
9923 &r->in.in_data, &out_data,
9924 r->out.needed);
9925 break;
9926 default:
9927 werror = WERR_INVALID_PRINT_MONITOR;
9930 if (!W_ERROR_IS_OK(werror)) {
9931 return werror;
9934 *r->out.status_code = 0;
9936 memcpy(r->out.out_data, out_data.data, out_data.length);
9938 return WERR_OK;
9941 /****************************************************************
9942 _spoolss_AddPrintProcessor
9943 ****************************************************************/
9945 WERROR _spoolss_AddPrintProcessor(pipes_struct *p,
9946 struct spoolss_AddPrintProcessor *r)
9948 /* for now, just indicate success and ignore the add. We'll
9949 automatically set the winprint processor for printer
9950 entries later. Used to debug the LexMark Optra S 1855 PCL
9951 driver --jerry */
9953 return WERR_OK;
9956 /****************************************************************
9957 _spoolss_AddPort
9958 ****************************************************************/
9960 WERROR _spoolss_AddPort(pipes_struct *p,
9961 struct spoolss_AddPort *r)
9963 /* do what w2k3 does */
9965 return WERR_NOT_SUPPORTED;
9968 /****************************************************************
9969 _spoolss_AddPrinter
9970 ****************************************************************/
9972 WERROR _spoolss_AddPrinter(pipes_struct *p,
9973 struct spoolss_AddPrinter *r)
9975 p->rng_fault_state = true;
9976 return WERR_NOT_SUPPORTED;
9979 /****************************************************************
9980 _spoolss_GetPrinterDriver
9981 ****************************************************************/
9983 WERROR _spoolss_GetPrinterDriver(pipes_struct *p,
9984 struct spoolss_GetPrinterDriver *r)
9986 p->rng_fault_state = true;
9987 return WERR_NOT_SUPPORTED;
9990 /****************************************************************
9991 _spoolss_ReadPrinter
9992 ****************************************************************/
9994 WERROR _spoolss_ReadPrinter(pipes_struct *p,
9995 struct spoolss_ReadPrinter *r)
9997 p->rng_fault_state = true;
9998 return WERR_NOT_SUPPORTED;
10001 /****************************************************************
10002 _spoolss_WaitForPrinterChange
10003 ****************************************************************/
10005 WERROR _spoolss_WaitForPrinterChange(pipes_struct *p,
10006 struct spoolss_WaitForPrinterChange *r)
10008 p->rng_fault_state = true;
10009 return WERR_NOT_SUPPORTED;
10012 /****************************************************************
10013 _spoolss_ConfigurePort
10014 ****************************************************************/
10016 WERROR _spoolss_ConfigurePort(pipes_struct *p,
10017 struct spoolss_ConfigurePort *r)
10019 p->rng_fault_state = true;
10020 return WERR_NOT_SUPPORTED;
10023 /****************************************************************
10024 _spoolss_DeletePort
10025 ****************************************************************/
10027 WERROR _spoolss_DeletePort(pipes_struct *p,
10028 struct spoolss_DeletePort *r)
10030 p->rng_fault_state = true;
10031 return WERR_NOT_SUPPORTED;
10034 /****************************************************************
10035 _spoolss_CreatePrinterIC
10036 ****************************************************************/
10038 WERROR _spoolss_CreatePrinterIC(pipes_struct *p,
10039 struct spoolss_CreatePrinterIC *r)
10041 p->rng_fault_state = true;
10042 return WERR_NOT_SUPPORTED;
10045 /****************************************************************
10046 _spoolss_PlayGDIScriptOnPrinterIC
10047 ****************************************************************/
10049 WERROR _spoolss_PlayGDIScriptOnPrinterIC(pipes_struct *p,
10050 struct spoolss_PlayGDIScriptOnPrinterIC *r)
10052 p->rng_fault_state = true;
10053 return WERR_NOT_SUPPORTED;
10056 /****************************************************************
10057 _spoolss_DeletePrinterIC
10058 ****************************************************************/
10060 WERROR _spoolss_DeletePrinterIC(pipes_struct *p,
10061 struct spoolss_DeletePrinterIC *r)
10063 p->rng_fault_state = true;
10064 return WERR_NOT_SUPPORTED;
10067 /****************************************************************
10068 _spoolss_AddPrinterConnection
10069 ****************************************************************/
10071 WERROR _spoolss_AddPrinterConnection(pipes_struct *p,
10072 struct spoolss_AddPrinterConnection *r)
10074 p->rng_fault_state = true;
10075 return WERR_NOT_SUPPORTED;
10078 /****************************************************************
10079 _spoolss_DeletePrinterConnection
10080 ****************************************************************/
10082 WERROR _spoolss_DeletePrinterConnection(pipes_struct *p,
10083 struct spoolss_DeletePrinterConnection *r)
10085 p->rng_fault_state = true;
10086 return WERR_NOT_SUPPORTED;
10089 /****************************************************************
10090 _spoolss_PrinterMessageBox
10091 ****************************************************************/
10093 WERROR _spoolss_PrinterMessageBox(pipes_struct *p,
10094 struct spoolss_PrinterMessageBox *r)
10096 p->rng_fault_state = true;
10097 return WERR_NOT_SUPPORTED;
10100 /****************************************************************
10101 _spoolss_AddMonitor
10102 ****************************************************************/
10104 WERROR _spoolss_AddMonitor(pipes_struct *p,
10105 struct spoolss_AddMonitor *r)
10107 p->rng_fault_state = true;
10108 return WERR_NOT_SUPPORTED;
10111 /****************************************************************
10112 _spoolss_DeleteMonitor
10113 ****************************************************************/
10115 WERROR _spoolss_DeleteMonitor(pipes_struct *p,
10116 struct spoolss_DeleteMonitor *r)
10118 p->rng_fault_state = true;
10119 return WERR_NOT_SUPPORTED;
10122 /****************************************************************
10123 _spoolss_DeletePrintProcessor
10124 ****************************************************************/
10126 WERROR _spoolss_DeletePrintProcessor(pipes_struct *p,
10127 struct spoolss_DeletePrintProcessor *r)
10129 p->rng_fault_state = true;
10130 return WERR_NOT_SUPPORTED;
10133 /****************************************************************
10134 _spoolss_AddPrintProvidor
10135 ****************************************************************/
10137 WERROR _spoolss_AddPrintProvidor(pipes_struct *p,
10138 struct spoolss_AddPrintProvidor *r)
10140 p->rng_fault_state = true;
10141 return WERR_NOT_SUPPORTED;
10144 /****************************************************************
10145 _spoolss_DeletePrintProvidor
10146 ****************************************************************/
10148 WERROR _spoolss_DeletePrintProvidor(pipes_struct *p,
10149 struct spoolss_DeletePrintProvidor *r)
10151 p->rng_fault_state = true;
10152 return WERR_NOT_SUPPORTED;
10155 /****************************************************************
10156 _spoolss_FindFirstPrinterChangeNotification
10157 ****************************************************************/
10159 WERROR _spoolss_FindFirstPrinterChangeNotification(pipes_struct *p,
10160 struct spoolss_FindFirstPrinterChangeNotification *r)
10162 p->rng_fault_state = true;
10163 return WERR_NOT_SUPPORTED;
10166 /****************************************************************
10167 _spoolss_FindNextPrinterChangeNotification
10168 ****************************************************************/
10170 WERROR _spoolss_FindNextPrinterChangeNotification(pipes_struct *p,
10171 struct spoolss_FindNextPrinterChangeNotification *r)
10173 p->rng_fault_state = true;
10174 return WERR_NOT_SUPPORTED;
10177 /****************************************************************
10178 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10179 ****************************************************************/
10181 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(pipes_struct *p,
10182 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
10184 p->rng_fault_state = true;
10185 return WERR_NOT_SUPPORTED;
10188 /****************************************************************
10189 _spoolss_ReplyOpenPrinter
10190 ****************************************************************/
10192 WERROR _spoolss_ReplyOpenPrinter(pipes_struct *p,
10193 struct spoolss_ReplyOpenPrinter *r)
10195 p->rng_fault_state = true;
10196 return WERR_NOT_SUPPORTED;
10199 /****************************************************************
10200 _spoolss_RouterReplyPrinter
10201 ****************************************************************/
10203 WERROR _spoolss_RouterReplyPrinter(pipes_struct *p,
10204 struct spoolss_RouterReplyPrinter *r)
10206 p->rng_fault_state = true;
10207 return WERR_NOT_SUPPORTED;
10210 /****************************************************************
10211 _spoolss_ReplyClosePrinter
10212 ****************************************************************/
10214 WERROR _spoolss_ReplyClosePrinter(pipes_struct *p,
10215 struct spoolss_ReplyClosePrinter *r)
10217 p->rng_fault_state = true;
10218 return WERR_NOT_SUPPORTED;
10221 /****************************************************************
10222 _spoolss_AddPortEx
10223 ****************************************************************/
10225 WERROR _spoolss_AddPortEx(pipes_struct *p,
10226 struct spoolss_AddPortEx *r)
10228 p->rng_fault_state = true;
10229 return WERR_NOT_SUPPORTED;
10232 /****************************************************************
10233 _spoolss_RouterFindFirstPrinterChangeNotification
10234 ****************************************************************/
10236 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(pipes_struct *p,
10237 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
10239 p->rng_fault_state = true;
10240 return WERR_NOT_SUPPORTED;
10243 /****************************************************************
10244 _spoolss_SpoolerInit
10245 ****************************************************************/
10247 WERROR _spoolss_SpoolerInit(pipes_struct *p,
10248 struct spoolss_SpoolerInit *r)
10250 p->rng_fault_state = true;
10251 return WERR_NOT_SUPPORTED;
10254 /****************************************************************
10255 _spoolss_ResetPrinterEx
10256 ****************************************************************/
10258 WERROR _spoolss_ResetPrinterEx(pipes_struct *p,
10259 struct spoolss_ResetPrinterEx *r)
10261 p->rng_fault_state = true;
10262 return WERR_NOT_SUPPORTED;
10265 /****************************************************************
10266 _spoolss_RouterReplyPrinterEx
10267 ****************************************************************/
10269 WERROR _spoolss_RouterReplyPrinterEx(pipes_struct *p,
10270 struct spoolss_RouterReplyPrinterEx *r)
10272 p->rng_fault_state = true;
10273 return WERR_NOT_SUPPORTED;
10276 /****************************************************************
10277 _spoolss_44
10278 ****************************************************************/
10280 WERROR _spoolss_44(pipes_struct *p,
10281 struct spoolss_44 *r)
10283 p->rng_fault_state = true;
10284 return WERR_NOT_SUPPORTED;
10287 /****************************************************************
10288 _spoolss_47
10289 ****************************************************************/
10291 WERROR _spoolss_47(pipes_struct *p,
10292 struct spoolss_47 *r)
10294 p->rng_fault_state = true;
10295 return WERR_NOT_SUPPORTED;
10298 /****************************************************************
10299 _spoolss_4a
10300 ****************************************************************/
10302 WERROR _spoolss_4a(pipes_struct *p,
10303 struct spoolss_4a *r)
10305 p->rng_fault_state = true;
10306 return WERR_NOT_SUPPORTED;
10309 /****************************************************************
10310 _spoolss_4b
10311 ****************************************************************/
10313 WERROR _spoolss_4b(pipes_struct *p,
10314 struct spoolss_4b *r)
10316 p->rng_fault_state = true;
10317 return WERR_NOT_SUPPORTED;
10320 /****************************************************************
10321 _spoolss_4c
10322 ****************************************************************/
10324 WERROR _spoolss_4c(pipes_struct *p,
10325 struct spoolss_4c *r)
10327 p->rng_fault_state = true;
10328 return WERR_NOT_SUPPORTED;
10331 /****************************************************************
10332 _spoolss_53
10333 ****************************************************************/
10335 WERROR _spoolss_53(pipes_struct *p,
10336 struct spoolss_53 *r)
10338 p->rng_fault_state = true;
10339 return WERR_NOT_SUPPORTED;
10342 /****************************************************************
10343 _spoolss_55
10344 ****************************************************************/
10346 WERROR _spoolss_55(pipes_struct *p,
10347 struct spoolss_55 *r)
10349 p->rng_fault_state = true;
10350 return WERR_NOT_SUPPORTED;
10353 /****************************************************************
10354 _spoolss_56
10355 ****************************************************************/
10357 WERROR _spoolss_56(pipes_struct *p,
10358 struct spoolss_56 *r)
10360 p->rng_fault_state = true;
10361 return WERR_NOT_SUPPORTED;
10364 /****************************************************************
10365 _spoolss_57
10366 ****************************************************************/
10368 WERROR _spoolss_57(pipes_struct *p,
10369 struct spoolss_57 *r)
10371 p->rng_fault_state = true;
10372 return WERR_NOT_SUPPORTED;
10375 /****************************************************************
10376 _spoolss_5a
10377 ****************************************************************/
10379 WERROR _spoolss_5a(pipes_struct *p,
10380 struct spoolss_5a *r)
10382 p->rng_fault_state = true;
10383 return WERR_NOT_SUPPORTED;
10386 /****************************************************************
10387 _spoolss_5b
10388 ****************************************************************/
10390 WERROR _spoolss_5b(pipes_struct *p,
10391 struct spoolss_5b *r)
10393 p->rng_fault_state = true;
10394 return WERR_NOT_SUPPORTED;
10397 /****************************************************************
10398 _spoolss_5c
10399 ****************************************************************/
10401 WERROR _spoolss_5c(pipes_struct *p,
10402 struct spoolss_5c *r)
10404 p->rng_fault_state = true;
10405 return WERR_NOT_SUPPORTED;
10408 /****************************************************************
10409 _spoolss_5d
10410 ****************************************************************/
10412 WERROR _spoolss_5d(pipes_struct *p,
10413 struct spoolss_5d *r)
10415 p->rng_fault_state = true;
10416 return WERR_NOT_SUPPORTED;
10419 /****************************************************************
10420 _spoolss_5e
10421 ****************************************************************/
10423 WERROR _spoolss_5e(pipes_struct *p,
10424 struct spoolss_5e *r)
10426 p->rng_fault_state = true;
10427 return WERR_NOT_SUPPORTED;
10430 /****************************************************************
10431 _spoolss_5f
10432 ****************************************************************/
10434 WERROR _spoolss_5f(pipes_struct *p,
10435 struct spoolss_5f *r)
10437 p->rng_fault_state = true;
10438 return WERR_NOT_SUPPORTED;