s3-spoolss: cleanup _spoolss_SetPrinterDataEx a little.
[Samba.git] / source3 / rpc_server / srv_spoolss_nt.c
blob9cde7d2e010d7c8abe486e63d0a6e87cf7f0cde8
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.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <http://www.gnu.org/licenses/>.
25 /* Since the SPOOLSS rpc routines are basically DOS 16-bit calls wrapped
26 up, all the errors returned are DOS errors, not NT status codes. */
28 #include "includes.h"
30 /* macros stolen from s4 spoolss server */
31 #define SPOOLSS_BUFFER_UNION(fn,ic,info,level) \
32 ((info)?ndr_size_##fn(info, level, ic, 0):0)
34 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,ic,info,level,count) \
35 ((info)?ndr_size_##fn##_info(mem_ctx, ic, level, count, info):0)
37 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
40 extern userdom_struct current_user_info;
42 #undef DBGC_CLASS
43 #define DBGC_CLASS DBGC_RPC_SRV
45 #ifndef MAX_OPEN_PRINTER_EXS
46 #define MAX_OPEN_PRINTER_EXS 50
47 #endif
49 #define MAGIC_DISPLAY_FREQUENCY 0xfade2bad
50 #define PHANTOM_DEVMODE_KEY "_p_f_a_n_t_0_m_"
52 struct table_node {
53 const char *long_archi;
54 const char *short_archi;
55 int version;
58 static Printer_entry *printers_list;
60 typedef struct _counter_printer_0 {
61 struct _counter_printer_0 *next;
62 struct _counter_printer_0 *prev;
64 int snum;
65 uint32 counter;
66 } counter_printer_0;
68 static counter_printer_0 *counter_list;
70 static struct rpc_pipe_client *notify_cli_pipe; /* print notify back-channel pipe handle*/
71 static uint32 smb_connections=0;
74 /* in printing/nt_printing.c */
76 extern struct standard_mapping printer_std_mapping, printserver_std_mapping;
78 /* API table for Xcv Monitor functions */
80 struct xcv_api_table {
81 const char *name;
82 WERROR(*fn) (TALLOC_CTX *mem_ctx, NT_USER_TOKEN *token, DATA_BLOB *in, DATA_BLOB *out, uint32_t *needed);
85 /********************************************************************
86 * Canonicalize servername.
87 ********************************************************************/
89 static const char *canon_servername(const char *servername)
91 const char *pservername = servername;
92 while (*pservername == '\\') {
93 pservername++;
95 return pservername;
98 /* translate between internal status numbers and NT status numbers */
99 static int nt_printj_status(int v)
101 switch (v) {
102 case LPQ_QUEUED:
103 return 0;
104 case LPQ_PAUSED:
105 return JOB_STATUS_PAUSED;
106 case LPQ_SPOOLING:
107 return JOB_STATUS_SPOOLING;
108 case LPQ_PRINTING:
109 return JOB_STATUS_PRINTING;
110 case LPQ_ERROR:
111 return JOB_STATUS_ERROR;
112 case LPQ_DELETING:
113 return JOB_STATUS_DELETING;
114 case LPQ_OFFLINE:
115 return JOB_STATUS_OFFLINE;
116 case LPQ_PAPEROUT:
117 return JOB_STATUS_PAPEROUT;
118 case LPQ_PRINTED:
119 return JOB_STATUS_PRINTED;
120 case LPQ_DELETED:
121 return JOB_STATUS_DELETED;
122 case LPQ_BLOCKED:
123 return JOB_STATUS_BLOCKED_DEVQ;
124 case LPQ_USER_INTERVENTION:
125 return JOB_STATUS_USER_INTERVENTION;
127 return 0;
130 static int nt_printq_status(int v)
132 switch (v) {
133 case LPQ_PAUSED:
134 return PRINTER_STATUS_PAUSED;
135 case LPQ_QUEUED:
136 case LPQ_SPOOLING:
137 case LPQ_PRINTING:
138 return 0;
140 return 0;
143 /***************************************************************************
144 Disconnect from the client
145 ****************************************************************************/
147 static void srv_spoolss_replycloseprinter(int snum, POLICY_HND *handle)
149 WERROR result;
150 NTSTATUS status;
153 * Tell the specific printing tdb we no longer want messages for this printer
154 * by deregistering our PID.
157 if (!print_notify_deregister_pid(snum))
158 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", lp_const_servicename(snum) ));
160 /* weird if the test succeds !!! */
161 if (smb_connections==0) {
162 DEBUG(0,("srv_spoolss_replycloseprinter:Trying to close non-existant notify backchannel !\n"));
163 return;
166 status = rpccli_spoolss_ReplyClosePrinter(notify_cli_pipe, talloc_tos(),
167 handle,
168 &result);
169 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
170 DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed [%s].\n",
171 win_errstr(result)));
173 /* if it's the last connection, deconnect the IPC$ share */
174 if (smb_connections==1) {
176 cli_shutdown( rpc_pipe_np_smb_conn(notify_cli_pipe) );
177 notify_cli_pipe = NULL; /* The above call shuts downn the pipe also. */
179 messaging_deregister(smbd_messaging_context(),
180 MSG_PRINTER_NOTIFY2, NULL);
182 /* Tell the connections db we're no longer interested in
183 * printer notify messages. */
185 register_message_flags( False, FLAG_MSG_PRINT_NOTIFY );
188 smb_connections--;
191 /****************************************************************************
192 Functions to free a printer entry datastruct.
193 ****************************************************************************/
195 static int printer_entry_destructor(Printer_entry *Printer)
197 if (Printer->notify.client_connected==True) {
198 int snum = -1;
200 if ( Printer->printer_type == SPLHND_SERVER) {
201 snum = -1;
202 srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
203 } else if (Printer->printer_type == SPLHND_PRINTER) {
204 snum = print_queue_snum(Printer->sharename);
205 if (snum != -1)
206 srv_spoolss_replycloseprinter(snum,
207 &Printer->notify.client_hnd);
211 Printer->notify.flags=0;
212 Printer->notify.options=0;
213 Printer->notify.localmachine[0]='\0';
214 Printer->notify.printerlocal=0;
215 TALLOC_FREE(Printer->notify.option);
216 Printer->notify.client_connected=False;
218 free_nt_devicemode( &Printer->nt_devmode );
219 free_a_printer( &Printer->printer_info, 2 );
221 /* Remove from the internal list. */
222 DLIST_REMOVE(printers_list, Printer);
223 return 0;
226 /****************************************************************************
227 find printer index by handle
228 ****************************************************************************/
230 static Printer_entry *find_printer_index_by_hnd(pipes_struct *p, POLICY_HND *hnd)
232 Printer_entry *find_printer = NULL;
234 if(!find_policy_by_hnd(p,hnd,(void **)(void *)&find_printer)) {
235 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
236 return NULL;
239 return find_printer;
242 /****************************************************************************
243 Close printer index by handle.
244 ****************************************************************************/
246 static bool close_printer_handle(pipes_struct *p, POLICY_HND *hnd)
248 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
250 if (!Printer) {
251 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(hnd)));
252 return False;
255 close_policy_hnd(p, hnd);
257 return True;
260 /****************************************************************************
261 Delete a printer given a handle.
262 ****************************************************************************/
264 WERROR delete_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *sharename )
266 char *cmd = lp_deleteprinter_cmd();
267 char *command = NULL;
268 int ret;
269 SE_PRIV se_printop = SE_PRINT_OPERATOR;
270 bool is_print_op = False;
272 /* can't fail if we don't try */
274 if ( !*cmd )
275 return WERR_OK;
277 command = talloc_asprintf(ctx,
278 "%s \"%s\"",
279 cmd, sharename);
280 if (!command) {
281 return WERR_NOMEM;
283 if ( token )
284 is_print_op = user_has_privileges( token, &se_printop );
286 DEBUG(10,("Running [%s]\n", command));
288 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
290 if ( is_print_op )
291 become_root();
293 if ( (ret = smbrun(command, NULL)) == 0 ) {
294 /* Tell everyone we updated smb.conf. */
295 message_send_all(smbd_messaging_context(),
296 MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
299 if ( is_print_op )
300 unbecome_root();
302 /********** END SePrintOperatorPrivlege BLOCK **********/
304 DEBUGADD(10,("returned [%d]\n", ret));
306 TALLOC_FREE(command);
308 if (ret != 0)
309 return WERR_BADFID; /* What to return here? */
311 /* go ahead and re-read the services immediately */
312 reload_services( False );
314 if ( lp_servicenumber( sharename ) < 0 )
315 return WERR_ACCESS_DENIED;
317 return WERR_OK;
320 /****************************************************************************
321 Delete a printer given a handle.
322 ****************************************************************************/
324 static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd)
326 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
328 if (!Printer) {
329 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(hnd)));
330 return WERR_BADFID;
334 * It turns out that Windows allows delete printer on a handle
335 * opened by an admin user, then used on a pipe handle created
336 * by an anonymous user..... but they're working on security.... riiight !
337 * JRA.
340 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
341 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
342 return WERR_ACCESS_DENIED;
345 /* this does not need a become root since the access check has been
346 done on the handle already */
348 if (del_a_printer( Printer->sharename ) != 0) {
349 DEBUG(3,("Error deleting printer %s\n", Printer->sharename));
350 return WERR_BADFID;
353 return delete_printer_hook(p->mem_ctx, p->server_info->ptok,
354 Printer->sharename );
357 /****************************************************************************
358 Return the snum of a printer corresponding to an handle.
359 ****************************************************************************/
361 static bool get_printer_snum(pipes_struct *p, POLICY_HND *hnd, int *number,
362 struct share_params **params)
364 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
366 if (!Printer) {
367 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(hnd)));
368 return False;
371 switch (Printer->printer_type) {
372 case SPLHND_PRINTER:
373 DEBUG(4,("short name:%s\n", Printer->sharename));
374 *number = print_queue_snum(Printer->sharename);
375 return (*number != -1);
376 case SPLHND_SERVER:
377 return False;
378 default:
379 return False;
383 /****************************************************************************
384 Set printer handle type.
385 Check if it's \\server or \\server\printer
386 ****************************************************************************/
388 static bool set_printer_hnd_printertype(Printer_entry *Printer, char *handlename)
390 DEBUG(3,("Setting printer type=%s\n", handlename));
392 if ( strlen(handlename) < 3 ) {
393 DEBUGADD(4,("A print server must have at least 1 char ! %s\n", handlename));
394 return False;
397 /* it's a print server */
398 if (*handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) {
399 DEBUGADD(4,("Printer is a print server\n"));
400 Printer->printer_type = SPLHND_SERVER;
402 /* it's a printer (set_printer_hnd_name() will handle port monitors */
403 else {
404 DEBUGADD(4,("Printer is a printer\n"));
405 Printer->printer_type = SPLHND_PRINTER;
408 return True;
411 /****************************************************************************
412 Set printer handle name.. Accept names like \\server, \\server\printer,
413 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
414 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
415 XcvDataPort() interface.
416 ****************************************************************************/
418 static bool set_printer_hnd_name(Printer_entry *Printer, char *handlename)
420 int snum;
421 int n_services=lp_numservices();
422 char *aprinter, *printername;
423 const char *servername;
424 fstring sname;
425 bool found=False;
426 NT_PRINTER_INFO_LEVEL *printer = NULL;
427 WERROR result;
429 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename, (unsigned long)strlen(handlename)));
431 aprinter = handlename;
432 if ( *handlename == '\\' ) {
433 servername = canon_servername(handlename);
434 if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
435 *aprinter = '\0';
436 aprinter++;
438 } else {
439 servername = "";
442 /* save the servername to fill in replies on this handle */
444 if ( !is_myname_or_ipaddr( servername ) )
445 return False;
447 fstrcpy( Printer->servername, servername );
449 if ( Printer->printer_type == SPLHND_SERVER )
450 return True;
452 if ( Printer->printer_type != SPLHND_PRINTER )
453 return False;
455 DEBUGADD(5, ("searching for [%s]\n", aprinter ));
457 /* check for the Port Monitor Interface */
459 if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
460 Printer->printer_type = SPLHND_PORTMON_TCP;
461 fstrcpy(sname, SPL_XCV_MONITOR_TCPMON);
462 found = True;
464 else if ( strequal( aprinter, SPL_XCV_MONITOR_LOCALMON ) ) {
465 Printer->printer_type = SPLHND_PORTMON_LOCAL;
466 fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON);
467 found = True;
470 /* Search all sharenames first as this is easier than pulling
471 the printer_info_2 off of disk. Don't use find_service() since
472 that calls out to map_username() */
474 /* do another loop to look for printernames */
476 for (snum=0; !found && snum<n_services; snum++) {
478 /* no point going on if this is not a printer */
480 if ( !(lp_snum_ok(snum) && lp_print_ok(snum)) )
481 continue;
483 fstrcpy(sname, lp_servicename(snum));
484 if ( strequal( aprinter, sname ) ) {
485 found = True;
486 break;
489 /* no point looking up the printer object if
490 we aren't allowing printername != sharename */
492 if ( lp_force_printername(snum) )
493 continue;
495 fstrcpy(sname, lp_servicename(snum));
497 printer = NULL;
499 /* This call doesn't fill in the location or comment from
500 * a CUPS server for efficiency with large numbers of printers.
501 * JRA.
504 result = get_a_printer_search( NULL, &printer, 2, sname );
505 if ( !W_ERROR_IS_OK(result) ) {
506 DEBUG(0,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
507 sname, win_errstr(result)));
508 continue;
511 /* printername is always returned as \\server\printername */
512 if ( !(printername = strchr_m(&printer->info_2->printername[2], '\\')) ) {
513 DEBUG(0,("set_printer_hnd_name: info2->printername in wrong format! [%s]\n",
514 printer->info_2->printername));
515 free_a_printer( &printer, 2);
516 continue;
519 printername++;
521 if ( strequal(printername, aprinter) ) {
522 free_a_printer( &printer, 2);
523 found = True;
524 break;
527 DEBUGADD(10, ("printername: %s\n", printername));
529 free_a_printer( &printer, 2);
532 free_a_printer( &printer, 2);
534 if ( !found ) {
535 DEBUGADD(4,("Printer not found\n"));
536 return False;
539 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));
541 fstrcpy(Printer->sharename, sname);
543 return True;
546 /****************************************************************************
547 Find first available printer slot. creates a printer handle for you.
548 ****************************************************************************/
550 static bool open_printer_hnd(pipes_struct *p, POLICY_HND *hnd, char *name, uint32 access_granted)
552 Printer_entry *new_printer;
554 DEBUG(10,("open_printer_hnd: name [%s]\n", name));
556 new_printer = TALLOC_ZERO_P(NULL, Printer_entry);
557 if (new_printer == NULL) {
558 return false;
560 talloc_set_destructor(new_printer, printer_entry_destructor);
562 if (!create_policy_hnd(p, hnd, new_printer)) {
563 TALLOC_FREE(new_printer);
564 return False;
567 /* Add to the internal list. */
568 DLIST_ADD(printers_list, new_printer);
570 new_printer->notify.option=NULL;
572 if (!set_printer_hnd_printertype(new_printer, name)) {
573 close_printer_handle(p, hnd);
574 return False;
577 if (!set_printer_hnd_name(new_printer, name)) {
578 close_printer_handle(p, hnd);
579 return False;
582 new_printer->access_granted = access_granted;
584 DEBUG(5, ("%d printer handles active\n", (int)p->pipe_handles->count ));
586 return True;
589 /***************************************************************************
590 check to see if the client motify handle is monitoring the notification
591 given by (notify_type, notify_field).
592 **************************************************************************/
594 static bool is_monitoring_event_flags(uint32 flags, uint16 notify_type,
595 uint16 notify_field)
597 return True;
600 static bool is_monitoring_event(Printer_entry *p, uint16 notify_type,
601 uint16 notify_field)
603 struct spoolss_NotifyOption *option = p->notify.option;
604 uint32 i, j;
607 * Flags should always be zero when the change notify
608 * is registered by the client's spooler. A user Win32 app
609 * might use the flags though instead of the NOTIFY_OPTION_INFO
610 * --jerry
613 if (!option) {
614 return False;
617 if (p->notify.flags)
618 return is_monitoring_event_flags(
619 p->notify.flags, notify_type, notify_field);
621 for (i = 0; i < option->count; i++) {
623 /* Check match for notify_type */
625 if (option->types[i].type != notify_type)
626 continue;
628 /* Check match for field */
630 for (j = 0; j < option->types[i].count; j++) {
631 if (option->types[i].fields[j] == notify_field) {
632 return True;
637 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
638 p->servername, p->sharename, notify_type, notify_field));
640 return False;
643 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
644 _data->data.integer[0] = _integer; \
645 _data->data.integer[1] = 0;
648 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
649 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
650 if (!_data->data.string.string) {\
651 _data->data.string.size = 0; \
653 _data->data.string.size = strlen_m_term(_p) * 2;
655 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
656 _data->data.devmode.devmode = _devmode;
658 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _size, _sd) \
659 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
660 if (!_data->data.sd.sd) { \
661 _data->data.sd.sd_size = 0; \
663 _data->data.sd.sd_size = _size;
665 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
666 struct tm *t,
667 const char **pp,
668 uint32_t *plen)
670 struct spoolss_Time st;
671 uint32_t len = 16;
672 char *p;
674 if (!init_systemtime(&st, t)) {
675 return;
678 p = talloc_array(mem_ctx, char, len);
679 if (!p) {
680 return;
684 * Systemtime must be linearized as a set of UINT16's.
685 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
688 SSVAL(p, 0, st.year);
689 SSVAL(p, 2, st.month);
690 SSVAL(p, 4, st.day_of_week);
691 SSVAL(p, 6, st.day);
692 SSVAL(p, 8, st.hour);
693 SSVAL(p, 10, st.minute);
694 SSVAL(p, 12, st.second);
695 SSVAL(p, 14, st.millisecond);
697 *pp = p;
698 *plen = len;
701 /* Convert a notification message to a struct spoolss_Notify */
703 static void notify_one_value(struct spoolss_notify_msg *msg,
704 struct spoolss_Notify *data,
705 TALLOC_CTX *mem_ctx)
707 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, msg->notify.value[0]);
710 static void notify_string(struct spoolss_notify_msg *msg,
711 struct spoolss_Notify *data,
712 TALLOC_CTX *mem_ctx)
714 /* The length of the message includes the trailing \0 */
716 data->data.string.size = msg->len * 2;
717 data->data.string.string = talloc_strdup(mem_ctx, msg->notify.data);
718 if (!data->data.string.string) {
719 data->data.string.size = 0;
720 return;
724 static void notify_system_time(struct spoolss_notify_msg *msg,
725 struct spoolss_Notify *data,
726 TALLOC_CTX *mem_ctx)
728 data->data.string.string = NULL;
729 data->data.string.size = 0;
731 if (msg->len != sizeof(time_t)) {
732 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
733 msg->len));
734 return;
737 init_systemtime_buffer(mem_ctx, gmtime((time_t *)msg->notify.data),
738 &data->data.string.string,
739 &data->data.string.size);
742 struct notify2_message_table {
743 const char *name;
744 void (*fn)(struct spoolss_notify_msg *msg,
745 struct spoolss_Notify *data, TALLOC_CTX *mem_ctx);
748 static struct notify2_message_table printer_notify_table[] = {
749 /* 0x00 */ { "PRINTER_NOTIFY_SERVER_NAME", notify_string },
750 /* 0x01 */ { "PRINTER_NOTIFY_PRINTER_NAME", notify_string },
751 /* 0x02 */ { "PRINTER_NOTIFY_SHARE_NAME", notify_string },
752 /* 0x03 */ { "PRINTER_NOTIFY_PORT_NAME", notify_string },
753 /* 0x04 */ { "PRINTER_NOTIFY_DRIVER_NAME", notify_string },
754 /* 0x05 */ { "PRINTER_NOTIFY_COMMENT", notify_string },
755 /* 0x06 */ { "PRINTER_NOTIFY_LOCATION", notify_string },
756 /* 0x07 */ { "PRINTER_NOTIFY_DEVMODE", NULL },
757 /* 0x08 */ { "PRINTER_NOTIFY_SEPFILE", notify_string },
758 /* 0x09 */ { "PRINTER_NOTIFY_PRINT_PROCESSOR", notify_string },
759 /* 0x0a */ { "PRINTER_NOTIFY_PARAMETERS", NULL },
760 /* 0x0b */ { "PRINTER_NOTIFY_DATATYPE", notify_string },
761 /* 0x0c */ { "PRINTER_NOTIFY_SECURITY_DESCRIPTOR", NULL },
762 /* 0x0d */ { "PRINTER_NOTIFY_ATTRIBUTES", notify_one_value },
763 /* 0x0e */ { "PRINTER_NOTIFY_PRIORITY", notify_one_value },
764 /* 0x0f */ { "PRINTER_NOTIFY_DEFAULT_PRIORITY", NULL },
765 /* 0x10 */ { "PRINTER_NOTIFY_START_TIME", NULL },
766 /* 0x11 */ { "PRINTER_NOTIFY_UNTIL_TIME", NULL },
767 /* 0x12 */ { "PRINTER_NOTIFY_STATUS", notify_one_value },
770 static struct notify2_message_table job_notify_table[] = {
771 /* 0x00 */ { "JOB_NOTIFY_PRINTER_NAME", NULL },
772 /* 0x01 */ { "JOB_NOTIFY_MACHINE_NAME", NULL },
773 /* 0x02 */ { "JOB_NOTIFY_PORT_NAME", NULL },
774 /* 0x03 */ { "JOB_NOTIFY_USER_NAME", notify_string },
775 /* 0x04 */ { "JOB_NOTIFY_NOTIFY_NAME", NULL },
776 /* 0x05 */ { "JOB_NOTIFY_DATATYPE", NULL },
777 /* 0x06 */ { "JOB_NOTIFY_PRINT_PROCESSOR", NULL },
778 /* 0x07 */ { "JOB_NOTIFY_PARAMETERS", NULL },
779 /* 0x08 */ { "JOB_NOTIFY_DRIVER_NAME", NULL },
780 /* 0x09 */ { "JOB_NOTIFY_DEVMODE", NULL },
781 /* 0x0a */ { "JOB_NOTIFY_STATUS", notify_one_value },
782 /* 0x0b */ { "JOB_NOTIFY_STATUS_STRING", NULL },
783 /* 0x0c */ { "JOB_NOTIFY_SECURITY_DESCRIPTOR", NULL },
784 /* 0x0d */ { "JOB_NOTIFY_DOCUMENT", notify_string },
785 /* 0x0e */ { "JOB_NOTIFY_PRIORITY", NULL },
786 /* 0x0f */ { "JOB_NOTIFY_POSITION", NULL },
787 /* 0x10 */ { "JOB_NOTIFY_SUBMITTED", notify_system_time },
788 /* 0x11 */ { "JOB_NOTIFY_START_TIME", NULL },
789 /* 0x12 */ { "JOB_NOTIFY_UNTIL_TIME", NULL },
790 /* 0x13 */ { "JOB_NOTIFY_TIME", NULL },
791 /* 0x14 */ { "JOB_NOTIFY_TOTAL_PAGES", notify_one_value },
792 /* 0x15 */ { "JOB_NOTIFY_PAGES_PRINTED", NULL },
793 /* 0x16 */ { "JOB_NOTIFY_TOTAL_BYTES", notify_one_value },
794 /* 0x17 */ { "JOB_NOTIFY_BYTES_PRINTED", NULL },
798 /***********************************************************************
799 Allocate talloc context for container object
800 **********************************************************************/
802 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
804 if ( !ctr )
805 return;
807 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
809 return;
812 /***********************************************************************
813 release all allocated memory and zero out structure
814 **********************************************************************/
816 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
818 if ( !ctr )
819 return;
821 if ( ctr->ctx )
822 talloc_destroy(ctr->ctx);
824 ZERO_STRUCTP(ctr);
826 return;
829 /***********************************************************************
830 **********************************************************************/
832 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
834 if ( !ctr )
835 return NULL;
837 return ctr->ctx;
840 /***********************************************************************
841 **********************************************************************/
843 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx )
845 if ( !ctr || !ctr->msg_groups )
846 return NULL;
848 if ( idx >= ctr->num_groups )
849 return NULL;
851 return &ctr->msg_groups[idx];
855 /***********************************************************************
856 How many groups of change messages do we have ?
857 **********************************************************************/
859 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
861 if ( !ctr )
862 return 0;
864 return ctr->num_groups;
867 /***********************************************************************
868 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
869 **********************************************************************/
871 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
873 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
874 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
875 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
876 int i, new_slot;
878 if ( !ctr || !msg )
879 return 0;
881 /* loop over all groups looking for a matching printer name */
883 for ( i=0; i<ctr->num_groups; i++ ) {
884 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
885 break;
888 /* add a new group? */
890 if ( i == ctr->num_groups ) {
891 ctr->num_groups++;
893 if ( !(groups = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
894 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
895 return 0;
897 ctr->msg_groups = groups;
899 /* clear the new entry and set the printer name */
901 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
902 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
905 /* add the change messages; 'i' is the correct index now regardless */
907 msg_grp = &ctr->msg_groups[i];
909 msg_grp->num_msgs++;
911 if ( !(msg_list = TALLOC_REALLOC_ARRAY( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
912 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
913 return 0;
915 msg_grp->msgs = msg_list;
917 new_slot = msg_grp->num_msgs-1;
918 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
920 /* need to allocate own copy of data */
922 if ( msg->len != 0 )
923 msg_grp->msgs[new_slot].notify.data = (char *)
924 TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len );
926 return ctr->num_groups;
929 /***********************************************************************
930 Send a change notication message on all handles which have a call
931 back registered
932 **********************************************************************/
934 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx )
936 Printer_entry *p;
937 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
938 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
939 SPOOLSS_NOTIFY_MSG *messages;
940 int sending_msg_count;
942 if ( !msg_group ) {
943 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
944 return;
947 messages = msg_group->msgs;
949 if ( !messages ) {
950 DEBUG(5,("send_notify2_changes() called with no messages!\n"));
951 return;
954 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
956 /* loop over all printers */
958 for (p = printers_list; p; p = p->next) {
959 struct spoolss_Notify *notifies;
960 uint32_t count = 0;
961 uint32_t id;
962 int i;
964 /* Is there notification on this handle? */
966 if ( !p->notify.client_connected )
967 continue;
969 DEBUG(10,("Client connected! [\\\\%s\\%s]\n", p->servername, p->sharename));
971 /* For this printer? Print servers always receive
972 notifications. */
974 if ( ( p->printer_type == SPLHND_PRINTER ) &&
975 ( !strequal(msg_group->printername, p->sharename) ) )
976 continue;
978 DEBUG(10,("Our printer\n"));
980 /* allocate the max entries possible */
982 notifies = TALLOC_ZERO_ARRAY(mem_ctx, struct spoolss_Notify, msg_group->num_msgs);
983 if (!notifies) {
984 return;
987 /* build the array of change notifications */
989 sending_msg_count = 0;
991 for ( i=0; i<msg_group->num_msgs; i++ ) {
992 SPOOLSS_NOTIFY_MSG *msg = &messages[i];
994 /* Are we monitoring this event? */
996 if (!is_monitoring_event(p, msg->type, msg->field))
997 continue;
999 sending_msg_count++;
1002 DEBUG(10,("process_notify2_message: Sending message type [0x%x] field [0x%2x] for printer [%s]\n",
1003 msg->type, msg->field, p->sharename));
1006 * if the is a printer notification handle and not a job notification
1007 * type, then set the id to 0. Other wise just use what was specified
1008 * in the message.
1010 * When registering change notification on a print server handle
1011 * we always need to send back the id (snum) matching the printer
1012 * for which the change took place. For change notify registered
1013 * on a printer handle, this does not matter and the id should be 0.
1015 * --jerry
1018 if ( ( p->printer_type == SPLHND_PRINTER ) && ( msg->type == PRINTER_NOTIFY_TYPE ) )
1019 id = 0;
1020 else
1021 id = msg->id;
1024 /* Convert unix jobid to smb jobid */
1026 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1027 id = sysjob_to_jobid(msg->id);
1029 if (id == -1) {
1030 DEBUG(3, ("no such unix jobid %d\n", msg->id));
1031 goto done;
1035 construct_info_data( &notifies[count], msg->type, msg->field, id );
1037 switch(msg->type) {
1038 case PRINTER_NOTIFY_TYPE:
1039 if ( printer_notify_table[msg->field].fn )
1040 printer_notify_table[msg->field].fn(msg, &notifies[count], mem_ctx);
1041 break;
1043 case JOB_NOTIFY_TYPE:
1044 if ( job_notify_table[msg->field].fn )
1045 job_notify_table[msg->field].fn(msg, &notifies[count], mem_ctx);
1046 break;
1048 default:
1049 DEBUG(5, ("Unknown notification type %d\n", msg->type));
1050 goto done;
1053 count++;
1056 if ( sending_msg_count ) {
1057 NTSTATUS status;
1058 WERROR werr;
1059 union spoolss_ReplyPrinterInfo info;
1060 struct spoolss_NotifyInfo info0;
1061 uint32_t reply_result;
1063 info0.version = 0x2;
1064 info0.flags = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
1065 info0.count = count;
1066 info0.notifies = notifies;
1068 info.info0 = &info0;
1070 status = rpccli_spoolss_RouterReplyPrinterEx(notify_cli_pipe, mem_ctx,
1071 &p->notify.client_hnd,
1072 p->notify.change, /* color */
1073 p->notify.flags,
1074 &reply_result,
1075 0, /* reply_type, must be 0 */
1076 info,
1077 &werr);
1078 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) {
1079 DEBUG(1,("RouterReplyPrinterEx to client: %s failed: %s\n",
1080 notify_cli_pipe->srv_name_slash,
1081 win_errstr(werr)));
1083 switch (reply_result) {
1084 case 0:
1085 break;
1086 case PRINTER_NOTIFY_INFO_DISCARDED:
1087 case PRINTER_NOTIFY_INFO_DISCARDNOTED:
1088 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
1089 break;
1090 default:
1091 break;
1096 done:
1097 DEBUG(8,("send_notify2_changes: Exit...\n"));
1098 return;
1101 /***********************************************************************
1102 **********************************************************************/
1104 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1107 uint32 tv_sec, tv_usec;
1108 size_t offset = 0;
1110 /* Unpack message */
1112 offset += tdb_unpack((uint8 *)buf + offset, len - offset, "f",
1113 msg->printer);
1115 offset += tdb_unpack((uint8 *)buf + offset, len - offset, "ddddddd",
1116 &tv_sec, &tv_usec,
1117 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1119 if (msg->len == 0)
1120 tdb_unpack((uint8 *)buf + offset, len - offset, "dd",
1121 &msg->notify.value[0], &msg->notify.value[1]);
1122 else
1123 tdb_unpack((uint8 *)buf + offset, len - offset, "B",
1124 &msg->len, &msg->notify.data);
1126 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1127 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1129 tv->tv_sec = tv_sec;
1130 tv->tv_usec = tv_usec;
1132 if (msg->len == 0)
1133 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1134 msg->notify.value[1]));
1135 else
1136 dump_data(3, (uint8 *)msg->notify.data, msg->len);
1138 return True;
1141 /********************************************************************
1142 Receive a notify2 message list
1143 ********************************************************************/
1145 static void receive_notify2_message_list(struct messaging_context *msg,
1146 void *private_data,
1147 uint32_t msg_type,
1148 struct server_id server_id,
1149 DATA_BLOB *data)
1151 size_t msg_count, i;
1152 char *buf = (char *)data->data;
1153 char *msg_ptr;
1154 size_t msg_len;
1155 SPOOLSS_NOTIFY_MSG notify;
1156 SPOOLSS_NOTIFY_MSG_CTR messages;
1157 int num_groups;
1159 if (data->length < 4) {
1160 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1161 return;
1164 msg_count = IVAL(buf, 0);
1165 msg_ptr = buf + 4;
1167 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1169 if (msg_count == 0) {
1170 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1171 return;
1174 /* initialize the container */
1176 ZERO_STRUCT( messages );
1177 notify_msg_ctr_init( &messages );
1180 * build message groups for each printer identified
1181 * in a change_notify msg. Remember that a PCN message
1182 * includes the handle returned for the srv_spoolss_replyopenprinter()
1183 * call. Therefore messages are grouped according to printer handle.
1186 for ( i=0; i<msg_count; i++ ) {
1187 struct timeval msg_tv;
1189 if (msg_ptr + 4 - buf > data->length) {
1190 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1191 return;
1194 msg_len = IVAL(msg_ptr,0);
1195 msg_ptr += 4;
1197 if (msg_ptr + msg_len - buf > data->length) {
1198 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1199 return;
1202 /* unpack messages */
1204 ZERO_STRUCT( notify );
1205 notify2_unpack_msg( &notify, &msg_tv, msg_ptr, msg_len );
1206 msg_ptr += msg_len;
1208 /* add to correct list in container */
1210 notify_msg_ctr_addmsg( &messages, &notify );
1212 /* free memory that might have been allocated by notify2_unpack_msg() */
1214 if ( notify.len != 0 )
1215 SAFE_FREE( notify.notify.data );
1218 /* process each group of messages */
1220 num_groups = notify_msg_ctr_numgroups( &messages );
1221 for ( i=0; i<num_groups; i++ )
1222 send_notify2_changes( &messages, i );
1225 /* cleanup */
1227 DEBUG(10,("receive_notify2_message_list: processed %u messages\n", (uint32)msg_count ));
1229 notify_msg_ctr_destroy( &messages );
1231 return;
1234 /********************************************************************
1235 Send a message to ourself about new driver being installed
1236 so we can upgrade the information for each printer bound to this
1237 driver
1238 ********************************************************************/
1240 static bool srv_spoolss_drv_upgrade_printer(char* drivername)
1242 int len = strlen(drivername);
1244 if (!len)
1245 return False;
1247 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1248 drivername));
1250 messaging_send_buf(smbd_messaging_context(), procid_self(),
1251 MSG_PRINTER_DRVUPGRADE,
1252 (uint8 *)drivername, len+1);
1254 return True;
1257 /**********************************************************************
1258 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1259 over all printers, upgrading ones as necessary
1260 **********************************************************************/
1262 void do_drv_upgrade_printer(struct messaging_context *msg,
1263 void *private_data,
1264 uint32_t msg_type,
1265 struct server_id server_id,
1266 DATA_BLOB *data)
1268 fstring drivername;
1269 int snum;
1270 int n_services = lp_numservices();
1271 size_t len;
1273 len = MIN(data->length,sizeof(drivername)-1);
1274 strncpy(drivername, (const char *)data->data, len);
1276 DEBUG(10,("do_drv_upgrade_printer: Got message for new driver [%s]\n", drivername ));
1278 /* Iterate the printer list */
1280 for (snum=0; snum<n_services; snum++)
1282 if (lp_snum_ok(snum) && lp_print_ok(snum) )
1284 WERROR result;
1285 NT_PRINTER_INFO_LEVEL *printer = NULL;
1287 result = get_a_printer(NULL, &printer, 2, lp_const_servicename(snum));
1288 if (!W_ERROR_IS_OK(result))
1289 continue;
1291 if (printer && printer->info_2 && !strcmp(drivername, printer->info_2->drivername))
1293 DEBUG(6,("Updating printer [%s]\n", printer->info_2->printername));
1295 /* all we care about currently is the change_id */
1297 result = mod_a_printer(printer, 2);
1298 if (!W_ERROR_IS_OK(result)) {
1299 DEBUG(3,("do_drv_upgrade_printer: mod_a_printer() failed with status [%s]\n",
1300 win_errstr(result)));
1304 free_a_printer(&printer, 2);
1308 /* all done */
1311 /********************************************************************
1312 Update the cache for all printq's with a registered client
1313 connection
1314 ********************************************************************/
1316 void update_monitored_printq_cache( void )
1318 Printer_entry *printer = printers_list;
1319 int snum;
1321 /* loop through all printers and update the cache where
1322 client_connected == True */
1323 while ( printer )
1325 if ( (printer->printer_type == SPLHND_PRINTER)
1326 && printer->notify.client_connected )
1328 snum = print_queue_snum(printer->sharename);
1329 print_queue_status( snum, NULL, NULL );
1332 printer = printer->next;
1335 return;
1337 /********************************************************************
1338 Send a message to ourself about new driver being installed
1339 so we can upgrade the information for each printer bound to this
1340 driver
1341 ********************************************************************/
1343 static bool srv_spoolss_reset_printerdata(char* drivername)
1345 int len = strlen(drivername);
1347 if (!len)
1348 return False;
1350 DEBUG(10,("srv_spoolss_reset_printerdata: Sending message about resetting printerdata [%s]\n",
1351 drivername));
1353 messaging_send_buf(smbd_messaging_context(), procid_self(),
1354 MSG_PRINTERDATA_INIT_RESET,
1355 (uint8 *)drivername, len+1);
1357 return True;
1360 /**********************************************************************
1361 callback to receive a MSG_PRINTERDATA_INIT_RESET message and interate
1362 over all printers, resetting printer data as neessary
1363 **********************************************************************/
1365 void reset_all_printerdata(struct messaging_context *msg,
1366 void *private_data,
1367 uint32_t msg_type,
1368 struct server_id server_id,
1369 DATA_BLOB *data)
1371 fstring drivername;
1372 int snum;
1373 int n_services = lp_numservices();
1374 size_t len;
1376 len = MIN( data->length, sizeof(drivername)-1 );
1377 strncpy( drivername, (const char *)data->data, len );
1379 DEBUG(10,("reset_all_printerdata: Got message for new driver [%s]\n", drivername ));
1381 /* Iterate the printer list */
1383 for ( snum=0; snum<n_services; snum++ )
1385 if ( lp_snum_ok(snum) && lp_print_ok(snum) )
1387 WERROR result;
1388 NT_PRINTER_INFO_LEVEL *printer = NULL;
1390 result = get_a_printer( NULL, &printer, 2, lp_const_servicename(snum) );
1391 if ( !W_ERROR_IS_OK(result) )
1392 continue;
1395 * if the printer is bound to the driver,
1396 * then reset to the new driver initdata
1399 if ( printer && printer->info_2 && !strcmp(drivername, printer->info_2->drivername) )
1401 DEBUG(6,("reset_all_printerdata: Updating printer [%s]\n", printer->info_2->printername));
1403 if ( !set_driver_init(printer, 2) ) {
1404 DEBUG(5,("reset_all_printerdata: Error resetting printer data for printer [%s], driver [%s]!\n",
1405 printer->info_2->printername, printer->info_2->drivername));
1408 result = mod_a_printer( printer, 2 );
1409 if ( !W_ERROR_IS_OK(result) ) {
1410 DEBUG(3,("reset_all_printerdata: mod_a_printer() failed! (%s)\n",
1411 get_dos_error_msg(result)));
1415 free_a_printer( &printer, 2 );
1419 /* all done */
1421 return;
1424 /****************************************************************
1425 _spoolss_OpenPrinter
1426 ****************************************************************/
1428 WERROR _spoolss_OpenPrinter(pipes_struct *p,
1429 struct spoolss_OpenPrinter *r)
1431 struct spoolss_OpenPrinterEx e;
1432 WERROR werr;
1434 ZERO_STRUCT(e.in.userlevel);
1436 e.in.printername = r->in.printername;
1437 e.in.datatype = r->in.datatype;
1438 e.in.devmode_ctr = r->in.devmode_ctr;
1439 e.in.access_mask = r->in.access_mask;
1440 e.in.level = 0;
1442 e.out.handle = r->out.handle;
1444 werr = _spoolss_OpenPrinterEx(p, &e);
1446 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1447 /* OpenPrinterEx returns this for a bad
1448 * printer name. We must return WERR_INVALID_PRINTER_NAME
1449 * instead.
1451 werr = WERR_INVALID_PRINTER_NAME;
1454 return werr;
1457 /********************************************************************
1458 FIXME: temporary convert_devicemode_new function
1459 ********************************************************************/
1461 static bool convert_devicemode_new(const char *printername,
1462 struct spoolss_DeviceMode *devmode,
1463 NT_DEVICEMODE **pp_nt_devmode)
1465 NT_DEVICEMODE *nt_devmode = *pp_nt_devmode;
1468 * Ensure nt_devmode is a valid pointer
1469 * as we will be overwriting it.
1472 if (nt_devmode == NULL) {
1473 DEBUG(5, ("convert_devicemode_new: allocating a generic devmode\n"));
1474 if ((nt_devmode = construct_nt_devicemode(printername)) == NULL)
1475 return false;
1478 rpcstr_push(nt_devmode->devicename, devmode->devicename, 31, 0);
1479 rpcstr_push(nt_devmode->formname, devmode->formname, 31, 0);
1481 nt_devmode->specversion = devmode->specversion;
1482 nt_devmode->driverversion = devmode->driverversion;
1483 nt_devmode->size = devmode->size;
1484 nt_devmode->fields = devmode->fields;
1485 nt_devmode->orientation = devmode->orientation;
1486 nt_devmode->papersize = devmode->papersize;
1487 nt_devmode->paperlength = devmode->paperlength;
1488 nt_devmode->paperwidth = devmode->paperwidth;
1489 nt_devmode->scale = devmode->scale;
1490 nt_devmode->copies = devmode->copies;
1491 nt_devmode->defaultsource = devmode->defaultsource;
1492 nt_devmode->printquality = devmode->printquality;
1493 nt_devmode->color = devmode->color;
1494 nt_devmode->duplex = devmode->duplex;
1495 nt_devmode->yresolution = devmode->yresolution;
1496 nt_devmode->ttoption = devmode->ttoption;
1497 nt_devmode->collate = devmode->collate;
1499 nt_devmode->logpixels = devmode->logpixels;
1500 nt_devmode->bitsperpel = devmode->bitsperpel;
1501 nt_devmode->pelswidth = devmode->pelswidth;
1502 nt_devmode->pelsheight = devmode->pelsheight;
1503 nt_devmode->displayflags = devmode->displayflags;
1504 nt_devmode->displayfrequency = devmode->displayfrequency;
1505 nt_devmode->icmmethod = devmode->icmmethod;
1506 nt_devmode->icmintent = devmode->icmintent;
1507 nt_devmode->mediatype = devmode->mediatype;
1508 nt_devmode->dithertype = devmode->dithertype;
1509 nt_devmode->reserved1 = devmode->reserved1;
1510 nt_devmode->reserved2 = devmode->reserved2;
1511 nt_devmode->panningwidth = devmode->panningwidth;
1512 nt_devmode->panningheight = devmode->panningheight;
1515 * Only change private and driverextra if the incoming devmode
1516 * has a new one. JRA.
1519 if ((devmode->__driverextra_length != 0) && (devmode->driverextra_data.data != NULL)) {
1520 SAFE_FREE(nt_devmode->nt_dev_private);
1521 nt_devmode->driverextra = devmode->__driverextra_length;
1522 if((nt_devmode->nt_dev_private=SMB_MALLOC_ARRAY(uint8, nt_devmode->driverextra)) == NULL)
1523 return false;
1524 memcpy(nt_devmode->nt_dev_private, devmode->driverextra_data.data, nt_devmode->driverextra);
1527 *pp_nt_devmode = nt_devmode;
1529 return true;
1532 /****************************************************************
1533 _spoolss_OpenPrinterEx
1534 ****************************************************************/
1536 WERROR _spoolss_OpenPrinterEx(pipes_struct *p,
1537 struct spoolss_OpenPrinterEx *r)
1539 POLICY_HND *handle = r->out.handle;
1540 char *name = CONST_DISCARD(char *, r->in.printername);
1541 int snum;
1542 Printer_entry *Printer=NULL;
1544 if (!name) {
1545 return WERR_INVALID_PARAM;
1548 /* some sanity check because you can open a printer or a print server */
1549 /* aka: \\server\printer or \\server */
1551 DEBUGADD(3,("checking name: %s\n",name));
1553 if (!open_printer_hnd(p, handle, name, 0)) {
1554 ZERO_STRUCTP(r->out.handle);
1555 return WERR_INVALID_PARAM;
1558 Printer=find_printer_index_by_hnd(p, handle);
1559 if ( !Printer ) {
1560 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1561 "handle we created for printer %s\n", name ));
1562 close_printer_handle(p,handle);
1563 ZERO_STRUCTP(r->out.handle);
1564 return WERR_INVALID_PARAM;
1568 * First case: the user is opening the print server:
1570 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1571 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1573 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1574 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1575 * or if the user is listed in the smb.conf printer admin parameter.
1577 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1578 * client view printer folder, but does not show the MSAPW.
1580 * Note: this test needs code to check access rights here too. Jeremy
1581 * could you look at this?
1583 * Second case: the user is opening a printer:
1584 * NT doesn't let us connect to a printer if the connecting user
1585 * doesn't have print permission.
1587 * Third case: user is opening a Port Monitor
1588 * access checks same as opening a handle to the print server.
1591 switch (Printer->printer_type )
1593 case SPLHND_SERVER:
1594 case SPLHND_PORTMON_TCP:
1595 case SPLHND_PORTMON_LOCAL:
1596 /* Printserver handles use global struct... */
1598 snum = -1;
1600 /* Map standard access rights to object specific access rights */
1602 se_map_standard(&r->in.access_mask,
1603 &printserver_std_mapping);
1605 /* Deny any object specific bits that don't apply to print
1606 servers (i.e printer and job specific bits) */
1608 r->in.access_mask &= SPECIFIC_RIGHTS_MASK;
1610 if (r->in.access_mask &
1611 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1612 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1613 close_printer_handle(p, handle);
1614 ZERO_STRUCTP(r->out.handle);
1615 return WERR_ACCESS_DENIED;
1618 /* Allow admin access */
1620 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1622 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1624 if (!lp_ms_add_printer_wizard()) {
1625 close_printer_handle(p, handle);
1626 ZERO_STRUCTP(r->out.handle);
1627 return WERR_ACCESS_DENIED;
1630 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1631 and not a printer admin, then fail */
1633 if ((p->server_info->utok.uid != 0) &&
1634 !user_has_privileges(p->server_info->ptok,
1635 &se_printop ) &&
1636 !token_contains_name_in_list(
1637 uidtoname(p->server_info->utok.uid),
1638 NULL, NULL,
1639 p->server_info->ptok,
1640 lp_printer_admin(snum))) {
1641 close_printer_handle(p, handle);
1642 ZERO_STRUCTP(r->out.handle);
1643 return WERR_ACCESS_DENIED;
1646 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1648 else
1650 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1653 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1654 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1656 /* We fall through to return WERR_OK */
1657 break;
1659 case SPLHND_PRINTER:
1660 /* NT doesn't let us connect to a printer if the connecting user
1661 doesn't have print permission. */
1663 if (!get_printer_snum(p, handle, &snum, NULL)) {
1664 close_printer_handle(p, handle);
1665 ZERO_STRUCTP(r->out.handle);
1666 return WERR_BADFID;
1669 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1671 /* map an empty access mask to the minimum access mask */
1672 if (r->in.access_mask == 0x0)
1673 r->in.access_mask = PRINTER_ACCESS_USE;
1676 * If we are not serving the printer driver for this printer,
1677 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1678 * will keep NT clients happy --jerry
1681 if (lp_use_client_driver(snum)
1682 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1684 r->in.access_mask = PRINTER_ACCESS_USE;
1687 /* check smb.conf parameters and the the sec_desc */
1689 if ( !check_access(get_client_fd(), lp_hostsallow(snum), lp_hostsdeny(snum)) ) {
1690 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1691 ZERO_STRUCTP(r->out.handle);
1692 return WERR_ACCESS_DENIED;
1695 if (!user_ok_token(uidtoname(p->server_info->utok.uid), NULL,
1696 p->server_info->ptok, snum) ||
1697 !print_access_check(p->server_info, snum,
1698 r->in.access_mask)) {
1699 DEBUG(3, ("access DENIED for printer open\n"));
1700 close_printer_handle(p, handle);
1701 ZERO_STRUCTP(r->out.handle);
1702 return WERR_ACCESS_DENIED;
1705 if ((r->in.access_mask & SPECIFIC_RIGHTS_MASK)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1706 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1707 close_printer_handle(p, handle);
1708 ZERO_STRUCTP(r->out.handle);
1709 return WERR_ACCESS_DENIED;
1712 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1713 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1714 else
1715 r->in.access_mask = PRINTER_ACCESS_USE;
1717 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1718 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1720 break;
1722 default:
1723 /* sanity check to prevent programmer error */
1724 ZERO_STRUCTP(r->out.handle);
1725 return WERR_BADFID;
1728 Printer->access_granted = r->in.access_mask;
1731 * If the client sent a devmode in the OpenPrinter() call, then
1732 * save it here in case we get a job submission on this handle
1735 if ( (Printer->printer_type != SPLHND_SERVER)
1736 && r->in.devmode_ctr.devmode )
1738 convert_devicemode_new(Printer->sharename,
1739 r->in.devmode_ctr.devmode,
1740 &Printer->nt_devmode);
1743 #if 0 /* JERRY -- I'm doubtful this is really effective */
1744 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1745 optimization in Windows 2000 clients --jerry */
1747 if ( (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1748 && (RA_WIN2K == get_remote_arch()) )
1750 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1751 sys_usleep( 500000 );
1753 #endif
1755 return WERR_OK;
1758 /****************************************************************************
1759 ****************************************************************************/
1761 static bool printer_info2_to_nt_printer_info2(struct spoolss_SetPrinterInfo2 *r,
1762 NT_PRINTER_INFO_LEVEL_2 *d)
1764 DEBUG(7,("printer_info2_to_nt_printer_info2\n"));
1766 if (!r || !d) {
1767 return false;
1770 d->attributes = r->attributes;
1771 d->priority = r->priority;
1772 d->default_priority = r->defaultpriority;
1773 d->starttime = r->starttime;
1774 d->untiltime = r->untiltime;
1775 d->status = r->status;
1776 d->cjobs = r->cjobs;
1778 fstrcpy(d->servername, r->servername);
1779 fstrcpy(d->printername, r->printername);
1780 fstrcpy(d->sharename, r->sharename);
1781 fstrcpy(d->portname, r->portname);
1782 fstrcpy(d->drivername, r->drivername);
1783 slprintf(d->comment, sizeof(d->comment)-1, "%s", r->comment);
1784 fstrcpy(d->location, r->location);
1785 fstrcpy(d->sepfile, r->sepfile);
1786 fstrcpy(d->printprocessor, r->printprocessor);
1787 fstrcpy(d->datatype, r->datatype);
1788 fstrcpy(d->parameters, r->parameters);
1790 return true;
1793 /****************************************************************************
1794 ****************************************************************************/
1796 static bool convert_printer_info_new(struct spoolss_SetPrinterInfoCtr *info_ctr,
1797 NT_PRINTER_INFO_LEVEL *printer)
1799 bool ret;
1801 switch (info_ctr->level) {
1802 case 2:
1803 /* allocate memory if needed. Messy because
1804 convert_printer_info is used to update an existing
1805 printer or build a new one */
1807 if (!printer->info_2) {
1808 printer->info_2 = TALLOC_ZERO_P(printer, NT_PRINTER_INFO_LEVEL_2);
1809 if (!printer->info_2) {
1810 DEBUG(0,("convert_printer_info_new: "
1811 "talloc() failed!\n"));
1812 return false;
1816 ret = printer_info2_to_nt_printer_info2(info_ctr->info.info2,
1817 printer->info_2);
1818 printer->info_2->setuptime = time(NULL);
1819 return ret;
1822 return false;
1825 /*******************************************************************
1826 ********************************************************************/
1828 static bool string_array_to_fstring_array(const char **sarray, fstring **farray)
1830 int i;
1832 if (!sarray) {
1833 *farray = NULL;
1834 return true;
1837 *farray = SMB_MALLOC_ARRAY(fstring, 1);
1838 if (!*farray) {
1839 return false;
1842 for (i=0; sarray[i] != NULL; i++) {
1843 *farray = SMB_REALLOC_ARRAY(*farray, fstring, i+2);
1844 if (!*farray) {
1845 return false;
1847 fstrcpy((*farray)[i], sarray[i]);
1850 fstrcpy((*farray)[i], "");
1852 return true;
1855 /*******************************************************************
1856 ********************************************************************/
1858 static bool driver_info3_to_nt_driver_info3(struct spoolss_AddDriverInfo3 *r,
1859 NT_PRINTER_DRIVER_INFO_LEVEL_3 **p)
1861 NT_PRINTER_DRIVER_INFO_LEVEL_3 *d;
1863 DEBUG(7,("driver_info3_to_nt_driver_info3: Converting from UNICODE to ASCII\n"));
1865 if (*p == NULL) {
1866 *p = SMB_MALLOC_P(NT_PRINTER_DRIVER_INFO_LEVEL_3);
1867 if (*p == NULL) {
1868 return false;
1870 ZERO_STRUCTP(*p);
1873 d = *p;
1875 d->cversion = r->version;
1877 fstrcpy(d->name, r->driver_name);
1878 fstrcpy(d->environment, r->architecture);
1879 fstrcpy(d->driverpath, r->driver_path);
1880 fstrcpy(d->datafile, r->data_file);
1881 fstrcpy(d->configfile, r->config_file);
1882 fstrcpy(d->helpfile, r->help_file);
1883 fstrcpy(d->monitorname, r->monitor_name);
1884 fstrcpy(d->defaultdatatype, r->default_datatype);
1886 DEBUGADD(8,( "version: %d\n", d->cversion));
1887 DEBUGADD(8,( "name: %s\n", d->name));
1888 DEBUGADD(8,( "environment: %s\n", d->environment));
1889 DEBUGADD(8,( "driverpath: %s\n", d->driverpath));
1890 DEBUGADD(8,( "datafile: %s\n", d->datafile));
1891 DEBUGADD(8,( "configfile: %s\n", d->configfile));
1892 DEBUGADD(8,( "helpfile: %s\n", d->helpfile));
1893 DEBUGADD(8,( "monitorname: %s\n", d->monitorname));
1894 DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
1896 if (r->dependent_files) {
1897 if (!string_array_to_fstring_array(r->dependent_files->string,
1898 &d->dependentfiles)) {
1899 SAFE_FREE(*p);
1900 return false;
1904 return true;
1907 /*******************************************************************
1908 ********************************************************************/
1910 static bool driver_info6_to_nt_driver_info6(struct spoolss_AddDriverInfo6 *r,
1911 NT_PRINTER_DRIVER_INFO_LEVEL_6 **p)
1913 NT_PRINTER_DRIVER_INFO_LEVEL_6 *d;
1915 DEBUG(7,("driver_info6_to_nt_driver_info6: Converting from UNICODE to ASCII\n"));
1917 if (*p == NULL) {
1918 *p = SMB_MALLOC_P(NT_PRINTER_DRIVER_INFO_LEVEL_6);
1919 if (*p == NULL) {
1920 return false;
1922 ZERO_STRUCTP(*p);
1925 d = *p;
1927 d->version = r->version;
1929 fstrcpy(d->name, r->driver_name);
1930 fstrcpy(d->environment, r->architecture);
1931 fstrcpy(d->driverpath, r->driver_path);
1932 fstrcpy(d->datafile, r->data_file);
1933 fstrcpy(d->configfile, r->config_file);
1934 fstrcpy(d->helpfile, r->help_file);
1935 fstrcpy(d->monitorname, r->monitor_name);
1936 fstrcpy(d->defaultdatatype, r->default_datatype);
1938 DEBUGADD(8,( "version: %d\n", d->version));
1939 DEBUGADD(8,( "name: %s\n", d->name));
1940 DEBUGADD(8,( "environment: %s\n", d->environment));
1941 DEBUGADD(8,( "driverpath: %s\n", d->driverpath));
1942 DEBUGADD(8,( "datafile: %s\n", d->datafile));
1943 DEBUGADD(8,( "configfile: %s\n", d->configfile));
1944 DEBUGADD(8,( "helpfile: %s\n", d->helpfile));
1945 DEBUGADD(8,( "monitorname: %s\n", d->monitorname));
1946 DEBUGADD(8,( "defaultdatatype: %s\n", d->defaultdatatype));
1948 if (r->dependent_files) {
1949 if (!string_array_to_fstring_array(r->dependent_files->string,
1950 &d->dependentfiles)) {
1951 goto error;
1955 if (r->previous_names) {
1956 if (!string_array_to_fstring_array(r->previous_names->string,
1957 &d->previousnames)) {
1958 goto error;
1962 return true;
1964 error:
1965 SAFE_FREE(*p);
1966 return false;
1969 /********************************************************************
1970 ********************************************************************/
1972 static bool convert_printer_driver_info(const struct spoolss_AddDriverInfoCtr *r,
1973 NT_PRINTER_DRIVER_INFO_LEVEL *printer,
1974 uint32_t level)
1976 switch (level) {
1977 case 3:
1978 printer->info_3 = NULL;
1979 if (!driver_info3_to_nt_driver_info3(r->info.info3, &printer->info_3)) {
1980 return false;
1982 break;
1983 case 6:
1984 printer->info_6 = NULL;
1985 if (!driver_info6_to_nt_driver_info6(r->info.info6, &printer->info_6)) {
1986 return false;
1988 break;
1989 default:
1990 return false;
1993 return true;
1996 bool convert_devicemode(const char *printername, const DEVICEMODE *devmode,
1997 NT_DEVICEMODE **pp_nt_devmode)
1999 NT_DEVICEMODE *nt_devmode = *pp_nt_devmode;
2002 * Ensure nt_devmode is a valid pointer
2003 * as we will be overwriting it.
2006 if (nt_devmode == NULL) {
2007 DEBUG(5, ("convert_devicemode: allocating a generic devmode\n"));
2008 if ((nt_devmode = construct_nt_devicemode(printername)) == NULL)
2009 return False;
2012 rpcstr_pull(nt_devmode->devicename,devmode->devicename.buffer, 31, -1, 0);
2013 rpcstr_pull(nt_devmode->formname,devmode->formname.buffer, 31, -1, 0);
2015 nt_devmode->specversion=devmode->specversion;
2016 nt_devmode->driverversion=devmode->driverversion;
2017 nt_devmode->size=devmode->size;
2018 nt_devmode->fields=devmode->fields;
2019 nt_devmode->orientation=devmode->orientation;
2020 nt_devmode->papersize=devmode->papersize;
2021 nt_devmode->paperlength=devmode->paperlength;
2022 nt_devmode->paperwidth=devmode->paperwidth;
2023 nt_devmode->scale=devmode->scale;
2024 nt_devmode->copies=devmode->copies;
2025 nt_devmode->defaultsource=devmode->defaultsource;
2026 nt_devmode->printquality=devmode->printquality;
2027 nt_devmode->color=devmode->color;
2028 nt_devmode->duplex=devmode->duplex;
2029 nt_devmode->yresolution=devmode->yresolution;
2030 nt_devmode->ttoption=devmode->ttoption;
2031 nt_devmode->collate=devmode->collate;
2033 nt_devmode->logpixels=devmode->logpixels;
2034 nt_devmode->bitsperpel=devmode->bitsperpel;
2035 nt_devmode->pelswidth=devmode->pelswidth;
2036 nt_devmode->pelsheight=devmode->pelsheight;
2037 nt_devmode->displayflags=devmode->displayflags;
2038 nt_devmode->displayfrequency=devmode->displayfrequency;
2039 nt_devmode->icmmethod=devmode->icmmethod;
2040 nt_devmode->icmintent=devmode->icmintent;
2041 nt_devmode->mediatype=devmode->mediatype;
2042 nt_devmode->dithertype=devmode->dithertype;
2043 nt_devmode->reserved1=devmode->reserved1;
2044 nt_devmode->reserved2=devmode->reserved2;
2045 nt_devmode->panningwidth=devmode->panningwidth;
2046 nt_devmode->panningheight=devmode->panningheight;
2049 * Only change private and driverextra if the incoming devmode
2050 * has a new one. JRA.
2053 if ((devmode->driverextra != 0) && (devmode->dev_private != NULL)) {
2054 SAFE_FREE(nt_devmode->nt_dev_private);
2055 nt_devmode->driverextra=devmode->driverextra;
2056 if((nt_devmode->nt_dev_private=SMB_MALLOC_ARRAY(uint8, nt_devmode->driverextra)) == NULL)
2057 return False;
2058 memcpy(nt_devmode->nt_dev_private, devmode->dev_private, nt_devmode->driverextra);
2061 *pp_nt_devmode = nt_devmode;
2063 return True;
2066 /********************************************************************
2067 * _spoolss_enddocprinter_internal.
2068 ********************************************************************/
2070 static WERROR _spoolss_enddocprinter_internal(pipes_struct *p, POLICY_HND *handle)
2072 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
2073 int snum;
2075 if (!Printer) {
2076 DEBUG(2,("_spoolss_enddocprinter_internal: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle)));
2077 return WERR_BADFID;
2080 if (!get_printer_snum(p, handle, &snum, NULL))
2081 return WERR_BADFID;
2083 Printer->document_started=False;
2084 print_job_end(snum, Printer->jobid,NORMAL_CLOSE);
2085 /* error codes unhandled so far ... */
2087 return WERR_OK;
2090 /****************************************************************
2091 _spoolss_ClosePrinter
2092 ****************************************************************/
2094 WERROR _spoolss_ClosePrinter(pipes_struct *p,
2095 struct spoolss_ClosePrinter *r)
2097 POLICY_HND *handle = r->in.handle;
2099 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
2101 if (Printer && Printer->document_started)
2102 _spoolss_enddocprinter_internal(p, handle); /* print job was not closed */
2104 if (!close_printer_handle(p, handle))
2105 return WERR_BADFID;
2107 /* clear the returned printer handle. Observed behavior
2108 from Win2k server. Don't think this really matters.
2109 Previous code just copied the value of the closed
2110 handle. --jerry */
2112 ZERO_STRUCTP(r->out.handle);
2114 return WERR_OK;
2117 /****************************************************************
2118 _spoolss_DeletePrinter
2119 ****************************************************************/
2121 WERROR _spoolss_DeletePrinter(pipes_struct *p,
2122 struct spoolss_DeletePrinter *r)
2124 POLICY_HND *handle = r->in.handle;
2125 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
2126 WERROR result;
2128 if (Printer && Printer->document_started)
2129 _spoolss_enddocprinter_internal(p, handle); /* print job was not closed */
2131 result = delete_printer_handle(p, handle);
2133 update_c_setprinter(False);
2135 return result;
2138 /*******************************************************************
2139 * static function to lookup the version id corresponding to an
2140 * long architecture string
2141 ******************************************************************/
2143 static int get_version_id (char * arch)
2145 int i;
2146 struct table_node archi_table[]= {
2148 {"Windows 4.0", "WIN40", 0 },
2149 {"Windows NT x86", "W32X86", 2 },
2150 {"Windows NT R4000", "W32MIPS", 2 },
2151 {"Windows NT Alpha_AXP", "W32ALPHA", 2 },
2152 {"Windows NT PowerPC", "W32PPC", 2 },
2153 {"Windows IA64", "IA64", 3 },
2154 {"Windows x64", "x64", 3 },
2155 {NULL, "", -1 }
2158 for (i=0; archi_table[i].long_archi != NULL; i++)
2160 if (strcmp(arch, archi_table[i].long_archi) == 0)
2161 return (archi_table[i].version);
2164 return -1;
2167 /****************************************************************
2168 _spoolss_DeletePrinterDriver
2169 ****************************************************************/
2171 WERROR _spoolss_DeletePrinterDriver(pipes_struct *p,
2172 struct spoolss_DeletePrinterDriver *r)
2174 char *driver;
2175 char *arch;
2176 NT_PRINTER_DRIVER_INFO_LEVEL info;
2177 NT_PRINTER_DRIVER_INFO_LEVEL info_win2k;
2178 int version;
2179 WERROR status;
2180 WERROR status_win2k = WERR_ACCESS_DENIED;
2181 SE_PRIV se_printop = SE_PRINT_OPERATOR;
2183 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2184 and not a printer admin, then fail */
2186 if ( (p->server_info->utok.uid != 0)
2187 && !user_has_privileges(p->server_info->ptok, &se_printop )
2188 && !token_contains_name_in_list(
2189 uidtoname(p->server_info->utok.uid), NULL,
2190 NULL, p->server_info->ptok,
2191 lp_printer_admin(-1)) )
2193 return WERR_ACCESS_DENIED;
2196 driver = CONST_DISCARD(char *, r->in.driver);
2197 arch = CONST_DISCARD(char *, r->in.architecture);
2199 /* check that we have a valid driver name first */
2201 if ((version=get_version_id(arch)) == -1)
2202 return WERR_INVALID_ENVIRONMENT;
2204 ZERO_STRUCT(info);
2205 ZERO_STRUCT(info_win2k);
2207 if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, driver, arch, version)))
2209 /* try for Win2k driver if "Windows NT x86" */
2211 if ( version == 2 ) {
2212 version = 3;
2213 if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, driver, arch, version))) {
2214 status = WERR_UNKNOWN_PRINTER_DRIVER;
2215 goto done;
2218 /* otherwise it was a failure */
2219 else {
2220 status = WERR_UNKNOWN_PRINTER_DRIVER;
2221 goto done;
2226 if (printer_driver_in_use(info.info_3)) {
2227 status = WERR_PRINTER_DRIVER_IN_USE;
2228 goto done;
2231 if ( version == 2 )
2233 if (W_ERROR_IS_OK(get_a_printer_driver(&info_win2k, 3, driver, arch, 3)))
2235 /* if we get to here, we now have 2 driver info structures to remove */
2236 /* remove the Win2k driver first*/
2238 status_win2k = delete_printer_driver(
2239 p, info_win2k.info_3, 3, False );
2240 free_a_printer_driver( info_win2k, 3 );
2242 /* this should not have failed---if it did, report to client */
2243 if ( !W_ERROR_IS_OK(status_win2k) )
2245 status = status_win2k;
2246 goto done;
2251 status = delete_printer_driver(p, info.info_3, version, False);
2253 /* if at least one of the deletes succeeded return OK */
2255 if ( W_ERROR_IS_OK(status) || W_ERROR_IS_OK(status_win2k) )
2256 status = WERR_OK;
2258 done:
2259 free_a_printer_driver( info, 3 );
2261 return status;
2264 /****************************************************************
2265 _spoolss_DeletePrinterDriverEx
2266 ****************************************************************/
2268 WERROR _spoolss_DeletePrinterDriverEx(pipes_struct *p,
2269 struct spoolss_DeletePrinterDriverEx *r)
2271 char *driver;
2272 char *arch;
2273 NT_PRINTER_DRIVER_INFO_LEVEL info;
2274 NT_PRINTER_DRIVER_INFO_LEVEL info_win2k;
2275 int version;
2276 uint32_t flags = r->in.delete_flags;
2277 bool delete_files;
2278 WERROR status;
2279 WERROR status_win2k = WERR_ACCESS_DENIED;
2280 SE_PRIV se_printop = SE_PRINT_OPERATOR;
2282 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2283 and not a printer admin, then fail */
2285 if ( (p->server_info->utok.uid != 0)
2286 && !user_has_privileges(p->server_info->ptok, &se_printop )
2287 && !token_contains_name_in_list(
2288 uidtoname(p->server_info->utok.uid), NULL, NULL,
2289 p->server_info->ptok, lp_printer_admin(-1)) )
2291 return WERR_ACCESS_DENIED;
2294 driver = CONST_DISCARD(char *, r->in.driver);
2295 arch = CONST_DISCARD(char *, r->in.architecture);
2297 /* check that we have a valid driver name first */
2298 if ((version=get_version_id(arch)) == -1) {
2299 /* this is what NT returns */
2300 return WERR_INVALID_ENVIRONMENT;
2303 if ( flags & DPD_DELETE_SPECIFIC_VERSION )
2304 version = r->in.version;
2306 ZERO_STRUCT(info);
2307 ZERO_STRUCT(info_win2k);
2309 status = get_a_printer_driver(&info, 3, driver, arch, version);
2311 if ( !W_ERROR_IS_OK(status) )
2314 * if the client asked for a specific version,
2315 * or this is something other than Windows NT x86,
2316 * then we've failed
2319 if ( (flags&DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
2320 goto done;
2322 /* try for Win2k driver if "Windows NT x86" */
2324 version = 3;
2325 if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, driver, arch, version))) {
2326 status = WERR_UNKNOWN_PRINTER_DRIVER;
2327 goto done;
2331 if ( printer_driver_in_use(info.info_3) ) {
2332 status = WERR_PRINTER_DRIVER_IN_USE;
2333 goto done;
2337 * we have a couple of cases to consider.
2338 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
2339 * then the delete should fail if **any** files overlap with
2340 * other drivers
2341 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
2342 * non-overlapping files
2343 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
2344 * is set, the do not delete any files
2345 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2348 delete_files = flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
2350 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
2352 if ( delete_files && printer_driver_files_in_use(info.info_3) & (flags&DPD_DELETE_ALL_FILES) ) {
2353 /* no idea of the correct error here */
2354 status = WERR_ACCESS_DENIED;
2355 goto done;
2359 /* also check for W32X86/3 if necessary; maybe we already have? */
2361 if ( (version == 2) && ((flags&DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
2362 if (W_ERROR_IS_OK(get_a_printer_driver(&info_win2k, 3, driver, arch, 3)))
2365 if ( delete_files && printer_driver_files_in_use(info_win2k.info_3) & (flags&DPD_DELETE_ALL_FILES) ) {
2366 /* no idea of the correct error here */
2367 free_a_printer_driver( info_win2k, 3 );
2368 status = WERR_ACCESS_DENIED;
2369 goto done;
2372 /* if we get to here, we now have 2 driver info structures to remove */
2373 /* remove the Win2k driver first*/
2375 status_win2k = delete_printer_driver(
2376 p, info_win2k.info_3, 3, delete_files);
2377 free_a_printer_driver( info_win2k, 3 );
2379 /* this should not have failed---if it did, report to client */
2381 if ( !W_ERROR_IS_OK(status_win2k) )
2382 goto done;
2386 status = delete_printer_driver(p, info.info_3, version, delete_files);
2388 if ( W_ERROR_IS_OK(status) || W_ERROR_IS_OK(status_win2k) )
2389 status = WERR_OK;
2390 done:
2391 free_a_printer_driver( info, 3 );
2393 return status;
2397 /****************************************************************************
2398 Internal routine for retreiving printerdata
2399 ***************************************************************************/
2401 static WERROR get_printer_dataex( TALLOC_CTX *ctx, NT_PRINTER_INFO_LEVEL *printer,
2402 const char *key, const char *value, uint32 *type, uint8 **data,
2403 uint32 *needed, uint32 in_size )
2405 REGISTRY_VALUE *val;
2406 uint32 size;
2407 int data_len;
2409 if ( !(val = get_printer_data( printer->info_2, key, value)) )
2410 return WERR_BADFILE;
2412 *type = regval_type( val );
2414 DEBUG(5,("get_printer_dataex: allocating %d\n", in_size));
2416 size = regval_size( val );
2418 /* copy the min(in_size, len) */
2420 if ( in_size ) {
2421 data_len = (size > in_size) ? in_size : size*sizeof(uint8);
2423 /* special case for 0 length values */
2424 if ( data_len ) {
2425 if ( (*data = (uint8 *)TALLOC_MEMDUP(ctx, regval_data_p(val), data_len)) == NULL )
2426 return WERR_NOMEM;
2428 else {
2429 if ( (*data = (uint8 *)TALLOC_ZERO(ctx, in_size)) == NULL )
2430 return WERR_NOMEM;
2433 else
2434 *data = NULL;
2436 *needed = size;
2438 DEBUG(5,("get_printer_dataex: copy done\n"));
2440 return WERR_OK;
2443 /****************************************************************************
2444 Internal routine for removing printerdata
2445 ***************************************************************************/
2447 static WERROR delete_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char *key, const char *value )
2449 return delete_printer_data( printer->info_2, key, value );
2452 /****************************************************************************
2453 Internal routine for storing printerdata
2454 ***************************************************************************/
2456 WERROR set_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char *key, const char *value,
2457 uint32 type, uint8 *data, int real_len )
2459 /* the registry objects enforce uniqueness based on value name */
2461 return add_printer_data( printer->info_2, key, value, type, data, real_len );
2464 /********************************************************************
2465 GetPrinterData on a printer server Handle.
2466 ********************************************************************/
2468 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2469 const char *value,
2470 enum winreg_Type *type,
2471 union spoolss_PrinterData *data)
2473 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2475 if (!StrCaseCmp(value, "W3SvcInstalled")) {
2476 *type = REG_DWORD;
2477 data->value = 0x00;
2478 return WERR_OK;
2481 if (!StrCaseCmp(value, "BeepEnabled")) {
2482 *type = REG_DWORD;
2483 data->value = 0x00;
2484 return WERR_OK;
2487 if (!StrCaseCmp(value, "EventLog")) {
2488 *type = REG_DWORD;
2489 /* formally was 0x1b */
2490 data->value = 0x00;
2491 return WERR_OK;
2494 if (!StrCaseCmp(value, "NetPopup")) {
2495 *type = REG_DWORD;
2496 data->value = 0x00;
2497 return WERR_OK;
2500 if (!StrCaseCmp(value, "MajorVersion")) {
2501 *type = REG_DWORD;
2503 /* Windows NT 4.0 seems to not allow uploading of drivers
2504 to a server that reports 0x3 as the MajorVersion.
2505 need to investigate more how Win2k gets around this .
2506 -- jerry */
2508 if (RA_WINNT == get_remote_arch()) {
2509 data->value = 0x02;
2510 } else {
2511 data->value = 0x03;
2514 return WERR_OK;
2517 if (!StrCaseCmp(value, "MinorVersion")) {
2518 *type = REG_DWORD;
2519 data->value = 0x00;
2520 return WERR_OK;
2523 /* REG_BINARY
2524 * uint32 size = 0x114
2525 * uint32 major = 5
2526 * uint32 minor = [0|1]
2527 * uint32 build = [2195|2600]
2528 * extra unicode string = e.g. "Service Pack 3"
2530 if (!StrCaseCmp(value, "OSVersion")) {
2531 DATA_BLOB blob;
2532 enum ndr_err_code ndr_err;
2533 struct spoolss_OSVersion os;
2535 os.major = 5; /* Windows 2000 == 5.0 */
2536 os.minor = 0;
2537 os.build = 2195; /* build */
2538 os.extra_string = ""; /* leave extra string empty */
2540 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, NULL, &os,
2541 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2542 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2543 return WERR_GENERAL_FAILURE;
2546 *type = REG_BINARY;
2547 data->binary = blob;
2549 return WERR_OK;
2553 if (!StrCaseCmp(value, "DefaultSpoolDirectory")) {
2554 *type = REG_SZ;
2556 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2557 W_ERROR_HAVE_NO_MEMORY(data->string);
2559 return WERR_OK;
2562 if (!StrCaseCmp(value, "Architecture")) {
2563 *type = REG_SZ;
2565 data->string = talloc_strdup(mem_ctx, "Windows NT x86");
2566 W_ERROR_HAVE_NO_MEMORY(data->string);
2568 return WERR_OK;
2571 if (!StrCaseCmp(value, "DsPresent")) {
2572 *type = REG_DWORD;
2574 /* only show the publish check box if we are a
2575 member of a AD domain */
2577 if (lp_security() == SEC_ADS) {
2578 data->value = 0x01;
2579 } else {
2580 data->value = 0x00;
2582 return WERR_OK;
2585 if (!StrCaseCmp(value, "DNSMachineName")) {
2586 const char *hostname = get_mydnsfullname();
2588 if (!hostname) {
2589 return WERR_BADFILE;
2592 *type = REG_SZ;
2593 data->string = talloc_strdup(mem_ctx, hostname);
2594 W_ERROR_HAVE_NO_MEMORY(data->string);
2596 return WERR_OK;
2599 return WERR_BADFILE;
2602 /****************************************************************
2603 _spoolss_GetPrinterData
2604 ****************************************************************/
2606 WERROR _spoolss_GetPrinterData(pipes_struct *p,
2607 struct spoolss_GetPrinterData *r)
2609 WERROR result;
2610 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
2611 NT_PRINTER_INFO_LEVEL *printer = NULL;
2612 int snum = 0;
2615 * Reminder: when it's a string, the length is in BYTES
2616 * even if UNICODE is negociated.
2618 * JFM, 4/19/1999
2621 /* in case of problem, return some default values */
2623 *r->out.needed = 0;
2624 *r->out.type = 0;
2626 DEBUG(4,("_spoolss_GetPrinterData\n"));
2628 if (!Printer) {
2629 DEBUG(2,("_spoolss_GetPrinterData: Invalid handle (%s:%u:%u).\n",
2630 OUR_HANDLE(r->in.handle)));
2631 result = WERR_BADFID;
2632 goto done;
2635 if (Printer->printer_type == SPLHND_SERVER) {
2636 result = getprinterdata_printer_server(p->mem_ctx,
2637 r->in.value_name,
2638 r->out.type,
2639 r->out.data);
2640 } else {
2641 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
2642 result = WERR_BADFID;
2643 goto done;
2646 result = get_a_printer(Printer, &printer, 2, lp_servicename(snum));
2647 if (!W_ERROR_IS_OK(result)) {
2648 goto done;
2651 /* XP sends this and wants to change id value from the PRINTER_INFO_0 */
2653 if (strequal(r->in.value_name, "ChangeId")) {
2654 *r->out.type = REG_DWORD;
2655 r->out.data->value = printer->info_2->changeid;
2656 result = WERR_OK;
2657 } else {
2658 REGISTRY_VALUE *v;
2659 DATA_BLOB blob;
2661 v = get_printer_data(printer->info_2,
2662 SPOOL_PRINTERDATA_KEY,
2663 r->in.value_name);
2664 if (!v) {
2665 result = WERR_BADFILE;
2666 goto done;
2669 *r->out.type = v->type;
2671 blob = data_blob_const(v->data_p, v->size);
2673 result = pull_spoolss_PrinterData(p->mem_ctx, &blob,
2674 r->out.data,
2675 *r->out.type);
2679 done:
2680 /* cleanup & exit */
2682 if (printer) {
2683 free_a_printer(&printer, 2);
2686 if (!W_ERROR_IS_OK(result)) {
2687 return result;
2690 *r->out.needed = ndr_size_spoolss_PrinterData(r->out.data, *r->out.type, NULL, 0);
2691 *r->out.type = SPOOLSS_BUFFER_OK(*r->out.type, REG_NONE);
2692 r->out.data = SPOOLSS_BUFFER_OK(r->out.data, r->out.data);
2694 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
2697 /*********************************************************
2698 Connect to the client machine.
2699 **********************************************************/
2701 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2702 struct sockaddr_storage *client_ss, const char *remote_machine)
2704 NTSTATUS ret;
2705 struct cli_state *the_cli;
2706 struct sockaddr_storage rm_addr;
2708 if ( is_zero_addr((struct sockaddr *)client_ss) ) {
2709 if ( !resolve_name( remote_machine, &rm_addr, 0x20) ) {
2710 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2711 return False;
2714 if (ismyaddr((struct sockaddr *)&rm_addr)) {
2715 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n", remote_machine));
2716 return False;
2718 } else {
2719 char addr[INET6_ADDRSTRLEN];
2720 rm_addr = *client_ss;
2721 print_sockaddr(addr, sizeof(addr), &rm_addr);
2722 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2723 addr));
2726 /* setup the connection */
2728 ret = cli_full_connection( &the_cli, global_myname(), remote_machine,
2729 &rm_addr, 0, "IPC$", "IPC",
2730 "", /* username */
2731 "", /* domain */
2732 "", /* password */
2733 0, lp_client_signing(), NULL );
2735 if ( !NT_STATUS_IS_OK( ret ) ) {
2736 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2737 remote_machine ));
2738 return False;
2741 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2742 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2743 cli_shutdown(the_cli);
2744 return False;
2748 * Ok - we have an anonymous connection to the IPC$ share.
2749 * Now start the NT Domain stuff :-).
2752 ret = cli_rpc_pipe_open_noauth(the_cli, &syntax_spoolss, pp_pipe);
2753 if (!NT_STATUS_IS_OK(ret)) {
2754 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2755 remote_machine, nt_errstr(ret)));
2756 cli_shutdown(the_cli);
2757 return False;
2760 return True;
2763 /***************************************************************************
2764 Connect to the client.
2765 ****************************************************************************/
2767 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2768 uint32 localprinter, uint32 type,
2769 POLICY_HND *handle, struct sockaddr_storage *client_ss)
2771 WERROR result;
2772 NTSTATUS status;
2775 * If it's the first connection, contact the client
2776 * and connect to the IPC$ share anonymously
2778 if (smb_connections==0) {
2779 fstring unix_printer;
2781 fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */
2783 if ( !spoolss_connect_to_client( &notify_cli_pipe, client_ss, unix_printer ))
2784 return False;
2786 messaging_register(smbd_messaging_context(), NULL,
2787 MSG_PRINTER_NOTIFY2,
2788 receive_notify2_message_list);
2789 /* Tell the connections db we're now interested in printer
2790 * notify messages. */
2791 register_message_flags( True, FLAG_MSG_PRINT_NOTIFY );
2795 * Tell the specific printing tdb we want messages for this printer
2796 * by registering our PID.
2799 if (!print_notify_register_pid(snum))
2800 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", printer ));
2802 smb_connections++;
2804 status = rpccli_spoolss_ReplyOpenPrinter(notify_cli_pipe, talloc_tos(),
2805 printer,
2806 localprinter,
2807 type,
2809 NULL,
2810 handle,
2811 &result);
2812 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
2813 DEBUG(5,("srv_spoolss_reply_open_printer: Client RPC returned [%s]\n",
2814 win_errstr(result)));
2816 return (W_ERROR_IS_OK(result));
2819 /****************************************************************
2820 ****************************************************************/
2822 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2823 const struct spoolss_NotifyOption *r)
2825 struct spoolss_NotifyOption *option;
2826 uint32_t i,k;
2828 if (!r) {
2829 return NULL;
2832 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2833 if (!option) {
2834 return NULL;
2837 *option = *r;
2839 if (!option->count) {
2840 return option;
2843 option->types = talloc_zero_array(option,
2844 struct spoolss_NotifyOptionType, option->count);
2845 if (!option->types) {
2846 talloc_free(option);
2847 return NULL;
2850 for (i=0; i < option->count; i++) {
2851 option->types[i] = r->types[i];
2853 if (option->types[i].count) {
2854 option->types[i].fields = talloc_zero_array(option,
2855 enum spoolss_Field, option->types[i].count);
2856 if (!option->types[i].fields) {
2857 talloc_free(option);
2858 return NULL;
2860 for (k=0; k<option->types[i].count; k++) {
2861 option->types[i].fields[k] =
2862 r->types[i].fields[k];
2867 return option;
2870 /****************************************************************
2871 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2873 * before replying OK: status=0 a rpc call is made to the workstation
2874 * asking ReplyOpenPrinter
2876 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2877 * called from api_spoolss_rffpcnex
2878 ****************************************************************/
2880 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(pipes_struct *p,
2881 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2883 POLICY_HND *handle = r->in.handle;
2884 int snum = -1;
2885 struct spoolss_NotifyOption *option = r->in.notify_options;
2886 struct sockaddr_storage client_ss;
2888 /* store the notify value in the printer struct */
2890 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
2892 if (!Printer) {
2893 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2894 "Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
2895 return WERR_BADFID;
2898 Printer->notify.flags = r->in.flags;
2899 Printer->notify.options = r->in.options;
2900 Printer->notify.printerlocal = r->in.printer_local;
2902 TALLOC_FREE(Printer->notify.option);
2903 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2905 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2907 /* Connect to the client machine and send a ReplyOpenPrinter */
2909 if ( Printer->printer_type == SPLHND_SERVER)
2910 snum = -1;
2911 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2912 !get_printer_snum(p, handle, &snum, NULL) )
2913 return WERR_BADFID;
2915 if (!interpret_string_addr(&client_ss, p->client_address,
2916 AI_NUMERICHOST)) {
2917 return WERR_SERVER_UNAVAILABLE;
2920 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2921 Printer->notify.printerlocal, 1,
2922 &Printer->notify.client_hnd, &client_ss))
2923 return WERR_SERVER_UNAVAILABLE;
2925 Printer->notify.client_connected=True;
2927 return WERR_OK;
2930 /*******************************************************************
2931 * fill a notify_info_data with the servername
2932 ********************************************************************/
2934 void spoolss_notify_server_name(int snum,
2935 struct spoolss_Notify *data,
2936 print_queue_struct *queue,
2937 NT_PRINTER_INFO_LEVEL *printer,
2938 TALLOC_CTX *mem_ctx)
2940 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->servername);
2943 /*******************************************************************
2944 * fill a notify_info_data with the printername (not including the servername).
2945 ********************************************************************/
2947 void spoolss_notify_printer_name(int snum,
2948 struct spoolss_Notify *data,
2949 print_queue_struct *queue,
2950 NT_PRINTER_INFO_LEVEL *printer,
2951 TALLOC_CTX *mem_ctx)
2953 /* the notify name should not contain the \\server\ part */
2954 char *p = strrchr(printer->info_2->printername, '\\');
2956 if (!p) {
2957 p = printer->info_2->printername;
2958 } else {
2959 p++;
2962 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2965 /*******************************************************************
2966 * fill a notify_info_data with the servicename
2967 ********************************************************************/
2969 void spoolss_notify_share_name(int snum,
2970 struct spoolss_Notify *data,
2971 print_queue_struct *queue,
2972 NT_PRINTER_INFO_LEVEL *printer,
2973 TALLOC_CTX *mem_ctx)
2975 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
2978 /*******************************************************************
2979 * fill a notify_info_data with the port name
2980 ********************************************************************/
2982 void spoolss_notify_port_name(int snum,
2983 struct spoolss_Notify *data,
2984 print_queue_struct *queue,
2985 NT_PRINTER_INFO_LEVEL *printer,
2986 TALLOC_CTX *mem_ctx)
2988 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->portname);
2991 /*******************************************************************
2992 * fill a notify_info_data with the printername
2993 * but it doesn't exist, have to see what to do
2994 ********************************************************************/
2996 void spoolss_notify_driver_name(int snum,
2997 struct spoolss_Notify *data,
2998 print_queue_struct *queue,
2999 NT_PRINTER_INFO_LEVEL *printer,
3000 TALLOC_CTX *mem_ctx)
3002 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->drivername);
3005 /*******************************************************************
3006 * fill a notify_info_data with the comment
3007 ********************************************************************/
3009 void spoolss_notify_comment(int snum,
3010 struct spoolss_Notify *data,
3011 print_queue_struct *queue,
3012 NT_PRINTER_INFO_LEVEL *printer,
3013 TALLOC_CTX *mem_ctx)
3015 char *p;
3017 if (*printer->info_2->comment == '\0') {
3018 p = lp_comment(snum);
3019 } else {
3020 p = printer->info_2->comment;
3023 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->comment);
3026 /*******************************************************************
3027 * fill a notify_info_data with the comment
3028 * location = "Room 1, floor 2, building 3"
3029 ********************************************************************/
3031 void spoolss_notify_location(int snum,
3032 struct spoolss_Notify *data,
3033 print_queue_struct *queue,
3034 NT_PRINTER_INFO_LEVEL *printer,
3035 TALLOC_CTX *mem_ctx)
3037 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->location);
3040 /*******************************************************************
3041 * fill a notify_info_data with the device mode
3042 * jfm:xxxx don't to it for know but that's a real problem !!!
3043 ********************************************************************/
3045 static void spoolss_notify_devmode(int snum,
3046 struct spoolss_Notify *data,
3047 print_queue_struct *queue,
3048 NT_PRINTER_INFO_LEVEL *printer,
3049 TALLOC_CTX *mem_ctx)
3051 /* for a dummy implementation we have to zero the fields */
3052 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
3055 /*******************************************************************
3056 * fill a notify_info_data with the separator file name
3057 ********************************************************************/
3059 void spoolss_notify_sepfile(int snum,
3060 struct spoolss_Notify *data,
3061 print_queue_struct *queue,
3062 NT_PRINTER_INFO_LEVEL *printer,
3063 TALLOC_CTX *mem_ctx)
3065 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->sepfile);
3068 /*******************************************************************
3069 * fill a notify_info_data with the print processor
3070 * jfm:xxxx return always winprint to indicate we don't do anything to it
3071 ********************************************************************/
3073 void spoolss_notify_print_processor(int snum,
3074 struct spoolss_Notify *data,
3075 print_queue_struct *queue,
3076 NT_PRINTER_INFO_LEVEL *printer,
3077 TALLOC_CTX *mem_ctx)
3079 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->printprocessor);
3082 /*******************************************************************
3083 * fill a notify_info_data with the print processor options
3084 * jfm:xxxx send an empty string
3085 ********************************************************************/
3087 void spoolss_notify_parameters(int snum,
3088 struct spoolss_Notify *data,
3089 print_queue_struct *queue,
3090 NT_PRINTER_INFO_LEVEL *printer,
3091 TALLOC_CTX *mem_ctx)
3093 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->parameters);
3096 /*******************************************************************
3097 * fill a notify_info_data with the data type
3098 * jfm:xxxx always send RAW as data type
3099 ********************************************************************/
3101 void spoolss_notify_datatype(int snum,
3102 struct spoolss_Notify *data,
3103 print_queue_struct *queue,
3104 NT_PRINTER_INFO_LEVEL *printer,
3105 TALLOC_CTX *mem_ctx)
3107 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->datatype);
3110 /*******************************************************************
3111 * fill a notify_info_data with the security descriptor
3112 * jfm:xxxx send an null pointer to say no security desc
3113 * have to implement security before !
3114 ********************************************************************/
3116 static void spoolss_notify_security_desc(int snum,
3117 struct spoolss_Notify *data,
3118 print_queue_struct *queue,
3119 NT_PRINTER_INFO_LEVEL *printer,
3120 TALLOC_CTX *mem_ctx)
3122 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data,
3123 printer->info_2->secdesc_buf->sd_size,
3124 printer->info_2->secdesc_buf->sd);
3127 /*******************************************************************
3128 * fill a notify_info_data with the attributes
3129 * jfm:xxxx a samba printer is always shared
3130 ********************************************************************/
3132 void spoolss_notify_attributes(int snum,
3133 struct spoolss_Notify *data,
3134 print_queue_struct *queue,
3135 NT_PRINTER_INFO_LEVEL *printer,
3136 TALLOC_CTX *mem_ctx)
3138 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->attributes);
3141 /*******************************************************************
3142 * fill a notify_info_data with the priority
3143 ********************************************************************/
3145 static void spoolss_notify_priority(int snum,
3146 struct spoolss_Notify *data,
3147 print_queue_struct *queue,
3148 NT_PRINTER_INFO_LEVEL *printer,
3149 TALLOC_CTX *mem_ctx)
3151 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->priority);
3154 /*******************************************************************
3155 * fill a notify_info_data with the default priority
3156 ********************************************************************/
3158 static void spoolss_notify_default_priority(int snum,
3159 struct spoolss_Notify *data,
3160 print_queue_struct *queue,
3161 NT_PRINTER_INFO_LEVEL *printer,
3162 TALLOC_CTX *mem_ctx)
3164 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->default_priority);
3167 /*******************************************************************
3168 * fill a notify_info_data with the start time
3169 ********************************************************************/
3171 static void spoolss_notify_start_time(int snum,
3172 struct spoolss_Notify *data,
3173 print_queue_struct *queue,
3174 NT_PRINTER_INFO_LEVEL *printer,
3175 TALLOC_CTX *mem_ctx)
3177 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->starttime);
3180 /*******************************************************************
3181 * fill a notify_info_data with the until time
3182 ********************************************************************/
3184 static void spoolss_notify_until_time(int snum,
3185 struct spoolss_Notify *data,
3186 print_queue_struct *queue,
3187 NT_PRINTER_INFO_LEVEL *printer,
3188 TALLOC_CTX *mem_ctx)
3190 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->untiltime);
3193 /*******************************************************************
3194 * fill a notify_info_data with the status
3195 ********************************************************************/
3197 static void spoolss_notify_status(int snum,
3198 struct spoolss_Notify *data,
3199 print_queue_struct *queue,
3200 NT_PRINTER_INFO_LEVEL *printer,
3201 TALLOC_CTX *mem_ctx)
3203 print_status_struct status;
3205 print_queue_length(snum, &status);
3206 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
3209 /*******************************************************************
3210 * fill a notify_info_data with the number of jobs queued
3211 ********************************************************************/
3213 void spoolss_notify_cjobs(int snum,
3214 struct spoolss_Notify *data,
3215 print_queue_struct *queue,
3216 NT_PRINTER_INFO_LEVEL *printer,
3217 TALLOC_CTX *mem_ctx)
3219 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, print_queue_length(snum, NULL));
3222 /*******************************************************************
3223 * fill a notify_info_data with the average ppm
3224 ********************************************************************/
3226 static void spoolss_notify_average_ppm(int snum,
3227 struct spoolss_Notify *data,
3228 print_queue_struct *queue,
3229 NT_PRINTER_INFO_LEVEL *printer,
3230 TALLOC_CTX *mem_ctx)
3232 /* always respond 8 pages per minutes */
3233 /* a little hard ! */
3234 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->averageppm);
3237 /*******************************************************************
3238 * fill a notify_info_data with username
3239 ********************************************************************/
3241 static void spoolss_notify_username(int snum,
3242 struct spoolss_Notify *data,
3243 print_queue_struct *queue,
3244 NT_PRINTER_INFO_LEVEL *printer,
3245 TALLOC_CTX *mem_ctx)
3247 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
3250 /*******************************************************************
3251 * fill a notify_info_data with job status
3252 ********************************************************************/
3254 static void spoolss_notify_job_status(int snum,
3255 struct spoolss_Notify *data,
3256 print_queue_struct *queue,
3257 NT_PRINTER_INFO_LEVEL *printer,
3258 TALLOC_CTX *mem_ctx)
3260 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
3263 /*******************************************************************
3264 * fill a notify_info_data with job name
3265 ********************************************************************/
3267 static void spoolss_notify_job_name(int snum,
3268 struct spoolss_Notify *data,
3269 print_queue_struct *queue,
3270 NT_PRINTER_INFO_LEVEL *printer,
3271 TALLOC_CTX *mem_ctx)
3273 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
3276 /*******************************************************************
3277 * fill a notify_info_data with job status
3278 ********************************************************************/
3280 static void spoolss_notify_job_status_string(int snum,
3281 struct spoolss_Notify *data,
3282 print_queue_struct *queue,
3283 NT_PRINTER_INFO_LEVEL *printer,
3284 TALLOC_CTX *mem_ctx)
3287 * Now we're returning job status codes we just return a "" here. JRA.
3290 const char *p = "";
3292 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3293 p = "unknown";
3295 switch (queue->status) {
3296 case LPQ_QUEUED:
3297 p = "Queued";
3298 break;
3299 case LPQ_PAUSED:
3300 p = ""; /* NT provides the paused string */
3301 break;
3302 case LPQ_SPOOLING:
3303 p = "Spooling";
3304 break;
3305 case LPQ_PRINTING:
3306 p = "Printing";
3307 break;
3309 #endif /* NO LONGER NEEDED. */
3311 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
3314 /*******************************************************************
3315 * fill a notify_info_data with job time
3316 ********************************************************************/
3318 static void spoolss_notify_job_time(int snum,
3319 struct spoolss_Notify *data,
3320 print_queue_struct *queue,
3321 NT_PRINTER_INFO_LEVEL *printer,
3322 TALLOC_CTX *mem_ctx)
3324 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3327 /*******************************************************************
3328 * fill a notify_info_data with job size
3329 ********************************************************************/
3331 static void spoolss_notify_job_size(int snum,
3332 struct spoolss_Notify *data,
3333 print_queue_struct *queue,
3334 NT_PRINTER_INFO_LEVEL *printer,
3335 TALLOC_CTX *mem_ctx)
3337 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
3340 /*******************************************************************
3341 * fill a notify_info_data with page info
3342 ********************************************************************/
3343 static void spoolss_notify_total_pages(int snum,
3344 struct spoolss_Notify *data,
3345 print_queue_struct *queue,
3346 NT_PRINTER_INFO_LEVEL *printer,
3347 TALLOC_CTX *mem_ctx)
3349 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
3352 /*******************************************************************
3353 * fill a notify_info_data with pages printed info.
3354 ********************************************************************/
3355 static void spoolss_notify_pages_printed(int snum,
3356 struct spoolss_Notify *data,
3357 print_queue_struct *queue,
3358 NT_PRINTER_INFO_LEVEL *printer,
3359 TALLOC_CTX *mem_ctx)
3361 /* Add code when back-end tracks this */
3362 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3365 /*******************************************************************
3366 Fill a notify_info_data with job position.
3367 ********************************************************************/
3369 static void spoolss_notify_job_position(int snum,
3370 struct spoolss_Notify *data,
3371 print_queue_struct *queue,
3372 NT_PRINTER_INFO_LEVEL *printer,
3373 TALLOC_CTX *mem_ctx)
3375 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
3378 /*******************************************************************
3379 Fill a notify_info_data with submitted time.
3380 ********************************************************************/
3382 static void spoolss_notify_submitted_time(int snum,
3383 struct spoolss_Notify *data,
3384 print_queue_struct *queue,
3385 NT_PRINTER_INFO_LEVEL *printer,
3386 TALLOC_CTX *mem_ctx)
3388 data->data.string.string = NULL;
3389 data->data.string.size = 0;
3391 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
3392 &data->data.string.string,
3393 &data->data.string.size);
3397 struct s_notify_info_data_table
3399 enum spoolss_NotifyType type;
3400 enum spoolss_Field field;
3401 const char *name;
3402 enum spoolss_NotifyTable variable_type;
3403 void (*fn) (int snum, struct spoolss_Notify *data,
3404 print_queue_struct *queue,
3405 NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx);
3408 /* A table describing the various print notification constants and
3409 whether the notification data is a pointer to a variable sized
3410 buffer, a one value uint32 or a two value uint32. */
3412 static const struct s_notify_info_data_table notify_info_data_table[] =
3414 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SERVER_NAME, "PRINTER_NOTIFY_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3415 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINTER_NAME, "PRINTER_NOTIFY_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3416 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SHARE_NAME, "PRINTER_NOTIFY_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
3417 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PORT_NAME, "PRINTER_NOTIFY_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3418 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DRIVER_NAME, "PRINTER_NOTIFY_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3419 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_COMMENT, "PRINTER_NOTIFY_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
3420 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_LOCATION, "PRINTER_NOTIFY_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
3421 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DEVMODE, "PRINTER_NOTIFY_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3422 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SEPFILE, "PRINTER_NOTIFY_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
3423 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINT_PROCESSOR, "PRINTER_NOTIFY_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3424 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PARAMETERS, "PRINTER_NOTIFY_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3425 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DATATYPE, "PRINTER_NOTIFY_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3426 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
3427 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_ATTRIBUTES, "PRINTER_NOTIFY_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
3428 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRIORITY, "PRINTER_NOTIFY_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3429 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DEFAULT_PRIORITY, "PRINTER_NOTIFY_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
3430 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_START_TIME, "PRINTER_NOTIFY_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3431 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_UNTIL_TIME, "PRINTER_NOTIFY_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3432 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_STATUS, "PRINTER_NOTIFY_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
3433 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_STATUS_STRING, "PRINTER_NOTIFY_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
3434 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_CJOBS, "PRINTER_NOTIFY_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
3435 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_AVERAGE_PPM, "PRINTER_NOTIFY_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
3436 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_PAGES, "PRINTER_NOTIFY_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
3437 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PAGES_PRINTED, "PRINTER_NOTIFY_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3438 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_BYTES, "PRINTER_NOTIFY_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
3439 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_BYTES_PRINTED, "PRINTER_NOTIFY_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3440 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINTER_NAME, "JOB_NOTIFY_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3441 { JOB_NOTIFY_TYPE, JOB_NOTIFY_MACHINE_NAME, "JOB_NOTIFY_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3442 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PORT_NAME, "JOB_NOTIFY_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3443 { JOB_NOTIFY_TYPE, JOB_NOTIFY_USER_NAME, "JOB_NOTIFY_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3444 { JOB_NOTIFY_TYPE, JOB_NOTIFY_NOTIFY_NAME, "JOB_NOTIFY_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3445 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DATATYPE, "JOB_NOTIFY_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3446 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINT_PROCESSOR, "JOB_NOTIFY_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3447 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PARAMETERS, "JOB_NOTIFY_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3448 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DRIVER_NAME, "JOB_NOTIFY_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3449 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DEVMODE, "JOB_NOTIFY_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3450 { JOB_NOTIFY_TYPE, JOB_NOTIFY_STATUS, "JOB_NOTIFY_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
3451 { JOB_NOTIFY_TYPE, JOB_NOTIFY_STATUS_STRING, "JOB_NOTIFY_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
3452 { JOB_NOTIFY_TYPE, JOB_NOTIFY_SECURITY_DESCRIPTOR, "JOB_NOTIFY_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
3453 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DOCUMENT, "JOB_NOTIFY_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
3454 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRIORITY, "JOB_NOTIFY_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3455 { JOB_NOTIFY_TYPE, JOB_NOTIFY_POSITION, "JOB_NOTIFY_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
3456 { JOB_NOTIFY_TYPE, JOB_NOTIFY_SUBMITTED, "JOB_NOTIFY_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
3457 { JOB_NOTIFY_TYPE, JOB_NOTIFY_START_TIME, "JOB_NOTIFY_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3458 { JOB_NOTIFY_TYPE, JOB_NOTIFY_UNTIL_TIME, "JOB_NOTIFY_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3459 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TIME, "JOB_NOTIFY_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
3460 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_PAGES, "JOB_NOTIFY_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
3461 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PAGES_PRINTED, "JOB_NOTIFY_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
3462 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_BYTES, "JOB_NOTIFY_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
3465 /*******************************************************************
3466 Return the variable_type of info_data structure.
3467 ********************************************************************/
3469 static uint32_t variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3470 enum spoolss_Field field)
3472 int i=0;
3474 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3475 if ( (notify_info_data_table[i].type == type) &&
3476 (notify_info_data_table[i].field == field) ) {
3477 return notify_info_data_table[i].variable_type;
3481 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3483 return 0;
3486 /****************************************************************************
3487 ****************************************************************************/
3489 static bool search_notify(enum spoolss_NotifyType type,
3490 enum spoolss_Field field,
3491 int *value)
3493 int i;
3495 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3496 if (notify_info_data_table[i].type == type &&
3497 notify_info_data_table[i].field == field &&
3498 notify_info_data_table[i].fn != NULL) {
3499 *value = i;
3500 return True;
3504 return False;
3507 /****************************************************************************
3508 ****************************************************************************/
3510 void construct_info_data(struct spoolss_Notify *info_data,
3511 enum spoolss_NotifyType type,
3512 enum spoolss_Field field,
3513 int id)
3515 info_data->type = type;
3516 info_data->field = field;
3517 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3518 info_data->job_id = id;
3521 /*******************************************************************
3523 * fill a notify_info struct with info asked
3525 ********************************************************************/
3527 static bool construct_notify_printer_info(Printer_entry *print_hnd,
3528 struct spoolss_NotifyInfo *info,
3529 int snum,
3530 const struct spoolss_NotifyOptionType *option_type,
3531 uint32_t id,
3532 TALLOC_CTX *mem_ctx)
3534 int field_num,j;
3535 enum spoolss_NotifyType type;
3536 enum spoolss_Field field;
3538 struct spoolss_Notify *current_data;
3539 NT_PRINTER_INFO_LEVEL *printer = NULL;
3540 print_queue_struct *queue=NULL;
3542 type = option_type->type;
3544 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3545 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3546 option_type->count, lp_servicename(snum)));
3548 if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &printer, 2, lp_const_servicename(snum))))
3549 return False;
3551 for(field_num=0; field_num < option_type->count; field_num++) {
3552 field = option_type->fields[field_num];
3554 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3556 if (!search_notify(type, field, &j) )
3557 continue;
3559 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3560 struct spoolss_Notify,
3561 info->count + 1);
3562 if (info->notifies == NULL) {
3563 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3564 free_a_printer(&printer, 2);
3565 return False;
3568 current_data = &info->notifies[info->count];
3570 construct_info_data(current_data, type, field, id);
3572 DEBUG(10,("construct_notify_printer_info: calling [%s] snum=%d printername=[%s])\n",
3573 notify_info_data_table[j].name, snum, printer->info_2->printername ));
3575 notify_info_data_table[j].fn(snum, current_data, queue,
3576 printer, mem_ctx);
3578 info->count++;
3581 free_a_printer(&printer, 2);
3582 return True;
3585 /*******************************************************************
3587 * fill a notify_info struct with info asked
3589 ********************************************************************/
3591 static bool construct_notify_jobs_info(print_queue_struct *queue,
3592 struct spoolss_NotifyInfo *info,
3593 NT_PRINTER_INFO_LEVEL *printer,
3594 int snum,
3595 const struct spoolss_NotifyOptionType *option_type,
3596 uint32_t id,
3597 TALLOC_CTX *mem_ctx)
3599 int field_num,j;
3600 enum spoolss_NotifyType type;
3601 enum spoolss_Field field;
3602 struct spoolss_Notify *current_data;
3604 DEBUG(4,("construct_notify_jobs_info\n"));
3606 type = option_type->type;
3608 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3609 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3610 option_type->count));
3612 for(field_num=0; field_num<option_type->count; field_num++) {
3613 field = option_type->fields[field_num];
3615 if (!search_notify(type, field, &j) )
3616 continue;
3618 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3619 struct spoolss_Notify,
3620 info->count + 1);
3621 if (info->notifies == NULL) {
3622 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3623 return False;
3626 current_data=&(info->notifies[info->count]);
3628 construct_info_data(current_data, type, field, id);
3629 notify_info_data_table[j].fn(snum, current_data, queue,
3630 printer, mem_ctx);
3631 info->count++;
3634 return True;
3638 * JFM: The enumeration is not that simple, it's even non obvious.
3640 * let's take an example: I want to monitor the PRINTER SERVER for
3641 * the printer's name and the number of jobs currently queued.
3642 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3643 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3645 * I have 3 printers on the back of my server.
3647 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3648 * structures.
3649 * Number Data Id
3650 * 1 printer 1 name 1
3651 * 2 printer 1 cjob 1
3652 * 3 printer 2 name 2
3653 * 4 printer 2 cjob 2
3654 * 5 printer 3 name 3
3655 * 6 printer 3 name 3
3657 * that's the print server case, the printer case is even worse.
3660 /*******************************************************************
3662 * enumerate all printers on the printserver
3663 * fill a notify_info struct with info asked
3665 ********************************************************************/
3667 static WERROR printserver_notify_info(pipes_struct *p, POLICY_HND *hnd,
3668 struct spoolss_NotifyInfo *info,
3669 TALLOC_CTX *mem_ctx)
3671 int snum;
3672 Printer_entry *Printer=find_printer_index_by_hnd(p, hnd);
3673 int n_services=lp_numservices();
3674 int i;
3675 struct spoolss_NotifyOption *option;
3676 struct spoolss_NotifyOptionType option_type;
3678 DEBUG(4,("printserver_notify_info\n"));
3680 if (!Printer)
3681 return WERR_BADFID;
3683 option = Printer->notify.option;
3685 info->version = 2;
3686 info->notifies = NULL;
3687 info->count = 0;
3689 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3690 sending a ffpcn() request first */
3692 if ( !option )
3693 return WERR_BADFID;
3695 for (i=0; i<option->count; i++) {
3696 option_type = option->types[i];
3698 if (option_type.type != PRINTER_NOTIFY_TYPE)
3699 continue;
3701 for (snum=0; snum<n_services; snum++)
3703 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
3704 construct_notify_printer_info ( Printer, info, snum, &option_type, snum, mem_ctx );
3708 #if 0
3710 * Debugging information, don't delete.
3713 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3714 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3715 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3717 for (i=0; i<info->count; i++) {
3718 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3719 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3720 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3722 #endif
3724 return WERR_OK;
3727 /*******************************************************************
3729 * fill a notify_info struct with info asked
3731 ********************************************************************/
3733 static WERROR printer_notify_info(pipes_struct *p, POLICY_HND *hnd, struct spoolss_NotifyInfo *info,
3734 TALLOC_CTX *mem_ctx)
3736 int snum;
3737 Printer_entry *Printer=find_printer_index_by_hnd(p, hnd);
3738 int i;
3739 uint32 id;
3740 struct spoolss_NotifyOption *option;
3741 struct spoolss_NotifyOptionType option_type;
3742 int count,j;
3743 print_queue_struct *queue=NULL;
3744 print_status_struct status;
3746 DEBUG(4,("printer_notify_info\n"));
3748 if (!Printer)
3749 return WERR_BADFID;
3751 option = Printer->notify.option;
3752 id = 0x0;
3754 info->version = 2;
3755 info->notifies = NULL;
3756 info->count = 0;
3758 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3759 sending a ffpcn() request first */
3761 if ( !option )
3762 return WERR_BADFID;
3764 get_printer_snum(p, hnd, &snum, NULL);
3766 for (i=0; i<option->count; i++) {
3767 option_type = option->types[i];
3769 switch (option_type.type) {
3770 case PRINTER_NOTIFY_TYPE:
3771 if(construct_notify_printer_info(Printer, info, snum,
3772 &option_type, id,
3773 mem_ctx))
3774 id--;
3775 break;
3777 case JOB_NOTIFY_TYPE: {
3778 NT_PRINTER_INFO_LEVEL *printer = NULL;
3780 count = print_queue_status(snum, &queue, &status);
3782 if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum))))
3783 goto done;
3785 for (j=0; j<count; j++) {
3786 construct_notify_jobs_info(&queue[j], info,
3787 printer, snum,
3788 &option_type,
3789 queue[j].job,
3790 mem_ctx);
3793 free_a_printer(&printer, 2);
3795 done:
3796 SAFE_FREE(queue);
3797 break;
3803 * Debugging information, don't delete.
3806 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3807 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3808 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3810 for (i=0; i<info->count; i++) {
3811 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3812 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3813 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3816 return WERR_OK;
3819 /****************************************************************
3820 _spoolss_RouterRefreshPrinterChangeNotify
3821 ****************************************************************/
3823 WERROR _spoolss_RouterRefreshPrinterChangeNotify(pipes_struct *p,
3824 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3826 POLICY_HND *handle = r->in.handle;
3827 struct spoolss_NotifyInfo *info;
3829 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
3830 WERROR result = WERR_BADFID;
3832 /* we always have a spoolss_NotifyInfo struct */
3833 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3834 if (!info) {
3835 result = WERR_NOMEM;
3836 goto done;
3839 *r->out.info = info;
3841 if (!Printer) {
3842 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3843 "Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
3844 goto done;
3847 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3850 * We are now using the change value, and
3851 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3852 * I don't have a global notification system, I'm sending back all the
3853 * informations even when _NOTHING_ has changed.
3856 /* We need to keep track of the change value to send back in
3857 RRPCN replies otherwise our updates are ignored. */
3859 Printer->notify.fnpcn = True;
3861 if (Printer->notify.client_connected) {
3862 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3863 "Saving change value in request [%x]\n",
3864 r->in.change_low));
3865 Printer->notify.change = r->in.change_low;
3868 /* just ignore the spoolss_NotifyOption */
3870 switch (Printer->printer_type) {
3871 case SPLHND_SERVER:
3872 result = printserver_notify_info(p, handle, info, p->mem_ctx);
3873 break;
3875 case SPLHND_PRINTER:
3876 result = printer_notify_info(p, handle, info, p->mem_ctx);
3877 break;
3880 Printer->notify.fnpcn = False;
3882 done:
3883 return result;
3886 /********************************************************************
3887 * construct_printer_info_0
3888 * fill a printer_info_0 struct
3889 ********************************************************************/
3891 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3892 const NT_PRINTER_INFO_LEVEL *ntprinter,
3893 struct spoolss_PrinterInfo0 *r,
3894 int snum)
3896 int count;
3897 counter_printer_0 *session_counter;
3898 time_t setuptime;
3899 print_status_struct status;
3901 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
3902 W_ERROR_HAVE_NO_MEMORY(r->printername);
3904 r->servername = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
3905 W_ERROR_HAVE_NO_MEMORY(r->servername);
3907 count = print_queue_length(snum, &status);
3909 /* check if we already have a counter for this printer */
3910 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3911 if (session_counter->snum == snum)
3912 break;
3915 /* it's the first time, add it to the list */
3916 if (session_counter == NULL) {
3917 session_counter = SMB_MALLOC_P(counter_printer_0);
3918 W_ERROR_HAVE_NO_MEMORY(session_counter);
3919 ZERO_STRUCTP(session_counter);
3920 session_counter->snum = snum;
3921 session_counter->counter = 0;
3922 DLIST_ADD(counter_list, session_counter);
3925 /* increment it */
3926 session_counter->counter++;
3928 r->cjobs = count;
3929 r->total_jobs = 0;
3930 r->total_bytes = 0;
3932 setuptime = (time_t)ntprinter->info_2->setuptime;
3934 init_systemtime(&r->time, gmtime(&setuptime));
3936 /* JFM:
3937 * the global_counter should be stored in a TDB as it's common to all the clients
3938 * and should be zeroed on samba startup
3940 r->global_counter = session_counter->counter;
3941 r->total_pages = 0;
3942 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3943 r->version = 0x0005; /* NT 5 */
3944 r->free_build = 0x0893; /* build 2195 */
3945 r->spooling = 0;
3946 r->max_spooling = 0;
3947 r->session_counter = session_counter->counter;
3948 r->num_error_out_of_paper = 0x0;
3949 r->num_error_not_ready = 0x0; /* number of print failure */
3950 r->job_error = 0x0;
3951 r->number_of_processors = 0x1;
3952 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3953 r->high_part_total_bytes = 0x0;
3954 r->change_id = ntprinter->info_2->changeid; /* ChangeID in milliseconds*/
3955 r->last_error = WERR_OK;
3956 r->status = nt_printq_status(status.status);
3957 r->enumerate_network_printers = 0x0;
3958 r->c_setprinter = get_c_setprinter(); /* monotonically increasing sum of delta printer counts */
3959 r->processor_architecture = 0x0;
3960 r->processor_level = 0x6; /* 6 ???*/
3961 r->ref_ic = 0;
3962 r->reserved2 = 0;
3963 r->reserved3 = 0;
3965 return WERR_OK;
3968 /****************************************************************************
3969 Free a DEVMODE struct.
3970 ****************************************************************************/
3972 static void free_dev_mode(DEVICEMODE *dev)
3974 if (dev == NULL)
3975 return;
3977 SAFE_FREE(dev->dev_private);
3978 SAFE_FREE(dev);
3981 /****************************************************************************
3982 Convert an NT_DEVICEMODE to a spoolss_DeviceMode structure. Both pointers
3983 should be valid upon entry
3984 ****************************************************************************/
3986 static WERROR convert_nt_devicemode_new(TALLOC_CTX *mem_ctx,
3987 struct spoolss_DeviceMode *r,
3988 const NT_DEVICEMODE *ntdevmode)
3990 if (!r || !ntdevmode) {
3991 return WERR_INVALID_PARAM;
3994 r->devicename = talloc_strdup(mem_ctx, ntdevmode->devicename);
3995 W_ERROR_HAVE_NO_MEMORY(r->devicename);
3997 r->specversion = ntdevmode->specversion;
3998 r->driverversion = ntdevmode->driverversion;
3999 r->size = ntdevmode->size;
4000 r->__driverextra_length = ntdevmode->driverextra;
4001 r->fields = ntdevmode->fields;
4003 r->orientation = ntdevmode->orientation;
4004 r->papersize = ntdevmode->papersize;
4005 r->paperlength = ntdevmode->paperlength;
4006 r->paperwidth = ntdevmode->paperwidth;
4007 r->scale = ntdevmode->scale;
4008 r->copies = ntdevmode->copies;
4009 r->defaultsource = ntdevmode->defaultsource;
4010 r->printquality = ntdevmode->printquality;
4011 r->color = ntdevmode->color;
4012 r->duplex = ntdevmode->duplex;
4013 r->yresolution = ntdevmode->yresolution;
4014 r->ttoption = ntdevmode->ttoption;
4015 r->collate = ntdevmode->collate;
4017 r->formname = talloc_strdup(mem_ctx, ntdevmode->formname);
4018 W_ERROR_HAVE_NO_MEMORY(r->formname);
4020 /* all 0 below are values that have not been set in the old parsing/copy
4021 * function, maybe they should... - gd */
4023 r->logpixels = 0;
4024 r->bitsperpel = 0;
4025 r->pelswidth = 0;
4026 r->pelsheight = 0;
4027 r->displayflags = 0;
4028 r->displayfrequency = 0;
4029 r->icmmethod = ntdevmode->icmmethod;
4030 r->icmintent = ntdevmode->icmintent;
4031 r->mediatype = ntdevmode->mediatype;
4032 r->dithertype = ntdevmode->dithertype;
4033 r->reserved1 = 0;
4034 r->reserved2 = 0;
4035 r->panningwidth = 0;
4036 r->panningheight = 0;
4038 if (ntdevmode->nt_dev_private != NULL) {
4039 r->driverextra_data = data_blob_talloc(mem_ctx,
4040 ntdevmode->nt_dev_private,
4041 ntdevmode->driverextra);
4042 W_ERROR_HAVE_NO_MEMORY(r->driverextra_data.data);
4045 return WERR_OK;
4049 /****************************************************************************
4050 Convert an NT_DEVICEMODE to a DEVICEMODE structure. Both pointers
4051 should be valid upon entry
4052 ****************************************************************************/
4054 static bool convert_nt_devicemode( DEVICEMODE *devmode, NT_DEVICEMODE *ntdevmode )
4056 if ( !devmode || !ntdevmode )
4057 return False;
4059 init_unistr(&devmode->devicename, ntdevmode->devicename);
4061 init_unistr(&devmode->formname, ntdevmode->formname);
4063 devmode->specversion = ntdevmode->specversion;
4064 devmode->driverversion = ntdevmode->driverversion;
4065 devmode->size = ntdevmode->size;
4066 devmode->driverextra = ntdevmode->driverextra;
4067 devmode->fields = ntdevmode->fields;
4069 devmode->orientation = ntdevmode->orientation;
4070 devmode->papersize = ntdevmode->papersize;
4071 devmode->paperlength = ntdevmode->paperlength;
4072 devmode->paperwidth = ntdevmode->paperwidth;
4073 devmode->scale = ntdevmode->scale;
4074 devmode->copies = ntdevmode->copies;
4075 devmode->defaultsource = ntdevmode->defaultsource;
4076 devmode->printquality = ntdevmode->printquality;
4077 devmode->color = ntdevmode->color;
4078 devmode->duplex = ntdevmode->duplex;
4079 devmode->yresolution = ntdevmode->yresolution;
4080 devmode->ttoption = ntdevmode->ttoption;
4081 devmode->collate = ntdevmode->collate;
4082 devmode->icmmethod = ntdevmode->icmmethod;
4083 devmode->icmintent = ntdevmode->icmintent;
4084 devmode->mediatype = ntdevmode->mediatype;
4085 devmode->dithertype = ntdevmode->dithertype;
4087 if (ntdevmode->nt_dev_private != NULL) {
4088 if ((devmode->dev_private=(uint8 *)memdup(ntdevmode->nt_dev_private, ntdevmode->driverextra)) == NULL)
4089 return False;
4092 return True;
4095 /****************************************************************************
4096 Create a spoolss_DeviceMode struct. Returns talloced memory.
4097 ****************************************************************************/
4099 struct spoolss_DeviceMode *construct_dev_mode_new(TALLOC_CTX *mem_ctx,
4100 const char *servicename)
4102 WERROR result;
4103 NT_PRINTER_INFO_LEVEL *printer = NULL;
4104 struct spoolss_DeviceMode *devmode = NULL;
4106 DEBUG(7,("construct_dev_mode_new\n"));
4108 DEBUGADD(8,("getting printer characteristics\n"));
4110 if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, servicename)))
4111 return NULL;
4113 if (!printer->info_2->devmode) {
4114 DEBUG(5, ("BONG! There was no device mode!\n"));
4115 goto done;
4118 devmode = TALLOC_ZERO_P(mem_ctx, struct spoolss_DeviceMode);
4119 if (!devmode) {
4120 DEBUG(2,("construct_dev_mode_new: talloc fail.\n"));
4121 goto done;
4124 DEBUGADD(8,("loading DEVICEMODE\n"));
4126 result = convert_nt_devicemode_new(mem_ctx, devmode, printer->info_2->devmode);
4127 if (!W_ERROR_IS_OK(result)) {
4128 TALLOC_FREE(devmode);
4131 done:
4132 free_a_printer(&printer,2);
4134 return devmode;
4137 /****************************************************************************
4138 Create a DEVMODE struct. Returns malloced memory.
4139 ****************************************************************************/
4141 DEVICEMODE *construct_dev_mode(const char *servicename)
4143 NT_PRINTER_INFO_LEVEL *printer = NULL;
4144 DEVICEMODE *devmode = NULL;
4146 DEBUG(7,("construct_dev_mode\n"));
4148 DEBUGADD(8,("getting printer characteristics\n"));
4150 if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, servicename)))
4151 return NULL;
4153 if ( !printer->info_2->devmode ) {
4154 DEBUG(5, ("BONG! There was no device mode!\n"));
4155 goto done;
4158 if ((devmode = SMB_MALLOC_P(DEVICEMODE)) == NULL) {
4159 DEBUG(2,("construct_dev_mode: malloc fail.\n"));
4160 goto done;
4163 ZERO_STRUCTP(devmode);
4165 DEBUGADD(8,("loading DEVICEMODE\n"));
4167 if ( !convert_nt_devicemode( devmode, printer->info_2->devmode ) ) {
4168 free_dev_mode( devmode );
4169 devmode = NULL;
4172 done:
4173 free_a_printer(&printer,2);
4175 return devmode;
4178 /********************************************************************
4179 * construct_printer_info3
4180 * fill a spoolss_PrinterInfo3 struct
4181 ********************************************************************/
4183 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
4184 const NT_PRINTER_INFO_LEVEL *ntprinter,
4185 struct spoolss_PrinterInfo3 *r,
4186 int snum)
4188 /* These are the components of the SD we are returning. */
4190 if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->sd_size != 0) {
4191 /* don't use talloc_steal() here unless you do a deep steal of all
4192 the SEC_DESC members */
4194 r->secdesc = dup_sec_desc(mem_ctx,
4195 ntprinter->info_2->secdesc_buf->sd);
4196 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
4199 return WERR_OK;
4202 /********************************************************************
4203 * construct_printer_info4
4204 * fill a spoolss_PrinterInfo4 struct
4205 ********************************************************************/
4207 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
4208 const NT_PRINTER_INFO_LEVEL *ntprinter,
4209 struct spoolss_PrinterInfo4 *r,
4210 int snum)
4212 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
4213 W_ERROR_HAVE_NO_MEMORY(r->printername);
4214 r->servername = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
4215 W_ERROR_HAVE_NO_MEMORY(r->servername);
4217 r->attributes = ntprinter->info_2->attributes;
4219 return WERR_OK;
4222 /********************************************************************
4223 * construct_printer_info5
4224 * fill a spoolss_PrinterInfo5 struct
4225 ********************************************************************/
4227 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
4228 const NT_PRINTER_INFO_LEVEL *ntprinter,
4229 struct spoolss_PrinterInfo5 *r,
4230 int snum)
4232 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
4233 W_ERROR_HAVE_NO_MEMORY(r->printername);
4234 r->portname = talloc_strdup(mem_ctx, ntprinter->info_2->portname);
4235 W_ERROR_HAVE_NO_MEMORY(r->portname);
4237 r->attributes = ntprinter->info_2->attributes;
4239 /* these two are not used by NT+ according to MSDN */
4241 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
4242 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
4244 return WERR_OK;
4247 /********************************************************************
4248 * construct_printer_info_6
4249 * fill a spoolss_PrinterInfo6 struct
4250 ********************************************************************/
4252 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
4253 const NT_PRINTER_INFO_LEVEL *ntprinter,
4254 struct spoolss_PrinterInfo6 *r,
4255 int snum)
4257 int count;
4258 print_status_struct status;
4260 count = print_queue_length(snum, &status);
4262 r->status = nt_printq_status(status.status);
4264 return WERR_OK;
4267 /********************************************************************
4268 * construct_printer_info7
4269 * fill a spoolss_PrinterInfo7 struct
4270 ********************************************************************/
4272 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
4273 Printer_entry *print_hnd,
4274 struct spoolss_PrinterInfo7 *r,
4275 int snum)
4277 struct GUID guid;
4279 if (is_printer_published(print_hnd, snum, &guid)) {
4280 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
4281 r->action = DSPRINT_PUBLISH;
4282 } else {
4283 r->guid = talloc_strdup(mem_ctx, "");
4284 r->action = DSPRINT_UNPUBLISH;
4286 W_ERROR_HAVE_NO_MEMORY(r->guid);
4288 return WERR_OK;
4291 /********************************************************************
4292 * construct_printer_info1
4293 * fill a spoolss_PrinterInfo1 struct
4294 ********************************************************************/
4296 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
4297 const NT_PRINTER_INFO_LEVEL *ntprinter,
4298 uint32_t flags,
4299 struct spoolss_PrinterInfo1 *r,
4300 int snum)
4302 char *chaine = NULL;
4303 r->flags = flags;
4305 if (*ntprinter->info_2->comment == '\0') {
4306 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
4307 chaine = talloc_asprintf(mem_ctx,
4308 "%s,%s,%s", ntprinter->info_2->printername,
4309 ntprinter->info_2->drivername, lp_comment(snum));
4310 } else {
4311 r->comment = talloc_strdup(mem_ctx, ntprinter->info_2->comment); /* saved comment */
4312 chaine = talloc_asprintf(mem_ctx,
4313 "%s,%s,%s", ntprinter->info_2->printername,
4314 ntprinter->info_2->drivername, ntprinter->info_2->comment);
4316 W_ERROR_HAVE_NO_MEMORY(chaine);
4317 W_ERROR_HAVE_NO_MEMORY(r->comment);
4319 r->description = talloc_strdup(mem_ctx, chaine);
4320 W_ERROR_HAVE_NO_MEMORY(r->description);
4321 r->name = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
4322 W_ERROR_HAVE_NO_MEMORY(r->name);
4324 return WERR_OK;
4327 /********************************************************************
4328 * construct_printer_info2
4329 * fill a spoolss_PrinterInfo2 struct
4330 ********************************************************************/
4332 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
4333 const NT_PRINTER_INFO_LEVEL *ntprinter,
4334 struct spoolss_PrinterInfo2 *r,
4335 int snum)
4337 int count;
4339 print_status_struct status;
4341 count = print_queue_length(snum, &status);
4343 r->servername = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
4344 W_ERROR_HAVE_NO_MEMORY(r->servername);
4345 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
4346 W_ERROR_HAVE_NO_MEMORY(r->printername);
4347 r->sharename = talloc_strdup(mem_ctx, lp_servicename(snum));
4348 W_ERROR_HAVE_NO_MEMORY(r->sharename);
4349 r->portname = talloc_strdup(mem_ctx, ntprinter->info_2->portname);
4350 W_ERROR_HAVE_NO_MEMORY(r->portname);
4351 r->drivername = talloc_strdup(mem_ctx, ntprinter->info_2->drivername);
4352 W_ERROR_HAVE_NO_MEMORY(r->drivername);
4354 if (*ntprinter->info_2->comment == '\0') {
4355 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
4356 } else {
4357 r->comment = talloc_strdup(mem_ctx, ntprinter->info_2->comment);
4359 W_ERROR_HAVE_NO_MEMORY(r->comment);
4361 r->location = talloc_strdup(mem_ctx, ntprinter->info_2->location);
4362 W_ERROR_HAVE_NO_MEMORY(r->location);
4363 r->sepfile = talloc_strdup(mem_ctx, ntprinter->info_2->sepfile);
4364 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
4365 r->printprocessor = talloc_strdup(mem_ctx, ntprinter->info_2->printprocessor);
4366 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
4367 r->datatype = talloc_strdup(mem_ctx, ntprinter->info_2->datatype);
4368 W_ERROR_HAVE_NO_MEMORY(r->datatype);
4369 r->parameters = talloc_strdup(mem_ctx, ntprinter->info_2->parameters);
4370 W_ERROR_HAVE_NO_MEMORY(r->parameters);
4372 r->attributes = ntprinter->info_2->attributes;
4374 r->priority = ntprinter->info_2->priority;
4375 r->defaultpriority = ntprinter->info_2->default_priority;
4376 r->starttime = ntprinter->info_2->starttime;
4377 r->untiltime = ntprinter->info_2->untiltime;
4378 r->status = nt_printq_status(status.status);
4379 r->cjobs = count;
4380 r->averageppm = ntprinter->info_2->averageppm;
4382 r->devmode = construct_dev_mode_new(mem_ctx, lp_const_servicename(snum));
4383 if (!r->devmode) {
4384 DEBUG(8,("Returning NULL Devicemode!\n"));
4387 r->secdesc = NULL;
4389 if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->sd_size != 0) {
4390 /* don't use talloc_steal() here unless you do a deep steal of all
4391 the SEC_DESC members */
4393 r->secdesc = dup_sec_desc(mem_ctx, ntprinter->info_2->secdesc_buf->sd);
4396 return WERR_OK;
4399 /********************************************************************
4400 ********************************************************************/
4402 static bool snum_is_shared_printer(int snum)
4404 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
4407 /********************************************************************
4408 Spoolss_enumprinters.
4409 ********************************************************************/
4411 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
4412 uint32_t flags,
4413 union spoolss_PrinterInfo **info_p,
4414 uint32_t *count)
4416 int snum;
4417 int n_services = lp_numservices();
4418 union spoolss_PrinterInfo *info = NULL;
4419 WERROR result = WERR_OK;
4421 DEBUG(4,("enum_all_printers_info_1\n"));
4423 *count = 0;
4425 for (snum=0; snum<n_services; snum++) {
4427 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
4428 struct spoolss_PrinterInfo1 info1;
4430 if (!snum_is_shared_printer(snum)) {
4431 continue;
4434 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum));
4436 result = get_a_printer(NULL, &ntprinter, 2, lp_const_servicename(snum));
4437 if (!W_ERROR_IS_OK(result)) {
4438 continue;
4441 result = construct_printer_info1(info, ntprinter, flags, &info1, snum);
4442 free_a_printer(&ntprinter,2);
4443 if (!W_ERROR_IS_OK(result)) {
4444 continue;
4447 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4448 union spoolss_PrinterInfo,
4449 *count + 1);
4450 if (!info) {
4451 DEBUG(2,("enum_all_printers_info_1: failed to enlarge printers buffer!\n"));
4452 result = WERR_NOMEM;
4453 goto out;
4456 DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_1\n", *count));
4458 info[*count].info1 = info1;
4459 (*count)++;
4462 out:
4463 if (!W_ERROR_IS_OK(result)) {
4464 TALLOC_FREE(info);
4465 *count = 0;
4466 return result;
4469 *info_p = info;
4471 return WERR_OK;
4474 /********************************************************************
4475 enum_all_printers_info_1_local.
4476 *********************************************************************/
4478 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
4479 union spoolss_PrinterInfo **info,
4480 uint32_t *count)
4482 DEBUG(4,("enum_all_printers_info_1_local\n"));
4484 return enum_all_printers_info_1(mem_ctx, PRINTER_ENUM_ICON8, info, count);
4487 /********************************************************************
4488 enum_all_printers_info_1_name.
4489 *********************************************************************/
4491 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
4492 const char *name,
4493 union spoolss_PrinterInfo **info,
4494 uint32_t *count)
4496 const char *s = name;
4498 DEBUG(4,("enum_all_printers_info_1_name\n"));
4500 if ((name[0] == '\\') && (name[1] == '\\')) {
4501 s = name + 2;
4504 if (!is_myname_or_ipaddr(s)) {
4505 return WERR_INVALID_NAME;
4508 return enum_all_printers_info_1(mem_ctx, PRINTER_ENUM_ICON8, info, count);
4511 #if 0 /* JERRY -- disabled for now. Don't think this is used, tested, or correct */
4512 /********************************************************************
4513 enum_all_printers_info_1_remote.
4514 *********************************************************************/
4516 static WERROR enum_all_printers_info_1_remote(fstring name, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4518 PRINTER_INFO_1 *printer;
4519 fstring printername;
4520 fstring desc;
4521 fstring comment;
4522 DEBUG(4,("enum_all_printers_info_1_remote\n"));
4523 WERROR result = WERR_OK;
4525 /* JFM: currently it's more a place holder than anything else.
4526 * In the spooler world there is a notion of server registration.
4527 * the print servers are registered on the PDC (in the same domain)
4529 * We should have a TDB here. The registration is done thru an
4530 * undocumented RPC call.
4533 if((printer=SMB_MALLOC_P(PRINTER_INFO_1)) == NULL)
4534 return WERR_NOMEM;
4536 *returned=1;
4538 slprintf(printername, sizeof(printername)-1,"Windows NT Remote Printers!!\\\\%s", name);
4539 slprintf(desc, sizeof(desc)-1,"%s", name);
4540 slprintf(comment, sizeof(comment)-1, "Logged on Domain");
4542 init_unistr(&printer->description, desc);
4543 init_unistr(&printer->name, printername);
4544 init_unistr(&printer->comment, comment);
4545 printer->flags=PRINTER_ENUM_ICON3|PRINTER_ENUM_CONTAINER;
4547 /* check the required size. */
4548 *needed += spoolss_size_printer_info_1(printer);
4550 if (*needed > offered) {
4551 result = WERR_INSUFFICIENT_BUFFER;
4552 goto out;
4555 if (!rpcbuf_alloc_size(buffer, *needed)) {
4556 result = WERR_NOMEM;
4557 goto out;
4560 /* fill the buffer with the structures */
4561 smb_io_printer_info_1("", buffer, printer, 0);
4563 out:
4564 /* clear memory */
4565 SAFE_FREE(printer);
4567 if ( !W_ERROR_IS_OK(result) )
4568 *returned = 0;
4570 return result;
4573 #endif
4575 /********************************************************************
4576 enum_all_printers_info_1_network.
4577 *********************************************************************/
4579 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
4580 const char *name,
4581 union spoolss_PrinterInfo **info,
4582 uint32_t *count)
4584 const char *s = name;
4586 DEBUG(4,("enum_all_printers_info_1_network\n"));
4588 /* If we respond to a enum_printers level 1 on our name with flags
4589 set to PRINTER_ENUM_REMOTE with a list of printers then these
4590 printers incorrectly appear in the APW browse list.
4591 Specifically the printers for the server appear at the workgroup
4592 level where all the other servers in the domain are
4593 listed. Windows responds to this call with a
4594 WERR_CAN_NOT_COMPLETE so we should do the same. */
4596 if (name[0] == '\\' && name[1] == '\\') {
4597 s = name + 2;
4600 if (is_myname_or_ipaddr(s)) {
4601 return WERR_CAN_NOT_COMPLETE;
4604 return enum_all_printers_info_1(mem_ctx, PRINTER_ENUM_NAME, info, count);
4607 /********************************************************************
4608 * api_spoolss_enumprinters
4610 * called from api_spoolss_enumprinters (see this to understand)
4611 ********************************************************************/
4613 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
4614 union spoolss_PrinterInfo **info_p,
4615 uint32_t *count)
4617 int snum;
4618 int n_services = lp_numservices();
4619 union spoolss_PrinterInfo *info = NULL;
4620 WERROR result = WERR_OK;
4622 *count = 0;
4624 for (snum=0; snum<n_services; snum++) {
4626 struct spoolss_PrinterInfo2 info2;
4627 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
4629 if (!snum_is_shared_printer(snum)) {
4630 continue;
4633 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum));
4635 result = get_a_printer(NULL, &ntprinter, 2, lp_const_servicename(snum));
4636 if (!W_ERROR_IS_OK(result)) {
4637 continue;
4640 result = construct_printer_info2(info, ntprinter, &info2, snum);
4641 free_a_printer(&ntprinter, 2);
4642 if (!W_ERROR_IS_OK(result)) {
4643 continue;
4646 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4647 union spoolss_PrinterInfo,
4648 *count + 1);
4649 if (!info) {
4650 DEBUG(2,("enum_all_printers_info_2: failed to enlarge printers buffer!\n"));
4651 result = WERR_NOMEM;
4652 goto out;
4655 DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_2\n", *count + 1));
4657 info[*count].info2 = info2;
4659 (*count)++;
4662 out:
4663 if (!W_ERROR_IS_OK(result)) {
4664 TALLOC_FREE(info);
4665 *count = 0;
4666 return result;
4669 *info_p = info;
4671 return WERR_OK;
4674 /********************************************************************
4675 * handle enumeration of printers at level 1
4676 ********************************************************************/
4678 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
4679 uint32_t flags,
4680 const char *name,
4681 union spoolss_PrinterInfo **info,
4682 uint32_t *count)
4684 /* Not all the flags are equals */
4686 if (flags & PRINTER_ENUM_LOCAL) {
4687 return enum_all_printers_info_1_local(mem_ctx, info, count);
4690 if (flags & PRINTER_ENUM_NAME) {
4691 return enum_all_printers_info_1_name(mem_ctx, name, info, count);
4694 #if 0 /* JERRY - disabled for now */
4695 if (flags & PRINTER_ENUM_REMOTE) {
4696 return enum_all_printers_info_1_remote(mem_ctx, name, info, count);
4698 #endif
4700 if (flags & PRINTER_ENUM_NETWORK) {
4701 return enum_all_printers_info_1_network(mem_ctx, name, info, count);
4704 return WERR_OK; /* NT4sp5 does that */
4707 /********************************************************************
4708 * handle enumeration of printers at level 2
4709 ********************************************************************/
4711 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4712 uint32_t flags,
4713 const char *servername,
4714 union spoolss_PrinterInfo **info,
4715 uint32_t *count)
4717 if (flags & PRINTER_ENUM_LOCAL) {
4718 return enum_all_printers_info_2(mem_ctx, info, count);
4721 if (flags & PRINTER_ENUM_NAME) {
4722 if (!is_myname_or_ipaddr(canon_servername(servername))) {
4723 return WERR_INVALID_NAME;
4726 return enum_all_printers_info_2(mem_ctx, info, count);
4729 if (flags & PRINTER_ENUM_REMOTE) {
4730 return WERR_UNKNOWN_LEVEL;
4733 return WERR_OK;
4736 /********************************************************************
4737 * handle enumeration of printers at level 5
4738 ********************************************************************/
4740 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4741 uint32_t flags,
4742 const char *servername,
4743 union spoolss_PrinterInfo **info,
4744 uint32_t *count)
4746 /* return enum_all_printers_info_5(mem_ctx, info, offered, needed, count);*/
4747 return WERR_OK;
4750 /****************************************************************
4751 _spoolss_EnumPrinters
4752 ****************************************************************/
4754 WERROR _spoolss_EnumPrinters(pipes_struct *p,
4755 struct spoolss_EnumPrinters *r)
4757 const char *name;
4758 WERROR result;
4760 /* that's an [in out] buffer */
4762 if (!r->in.buffer && (r->in.offered != 0)) {
4763 return WERR_INVALID_PARAM;
4766 DEBUG(4,("_spoolss_EnumPrinters\n"));
4768 *r->out.needed = 0;
4769 *r->out.count = 0;
4770 *r->out.info = NULL;
4773 * Level 1:
4774 * flags==PRINTER_ENUM_NAME
4775 * if name=="" then enumerates all printers
4776 * if name!="" then enumerate the printer
4777 * flags==PRINTER_ENUM_REMOTE
4778 * name is NULL, enumerate printers
4779 * Level 2: name!="" enumerates printers, name can't be NULL
4780 * Level 3: doesn't exist
4781 * Level 4: does a local registry lookup
4782 * Level 5: same as Level 2
4785 name = talloc_strdup_upper(p->mem_ctx, r->in.server);
4786 W_ERROR_HAVE_NO_MEMORY(name);
4788 switch (r->in.level) {
4789 case 1:
4790 result = enumprinters_level1(p->mem_ctx, r->in.flags, name,
4791 r->out.info, r->out.count);
4792 break;
4793 case 2:
4794 result = enumprinters_level2(p->mem_ctx, r->in.flags, name,
4795 r->out.info, r->out.count);
4796 break;
4797 case 5:
4798 result = enumprinters_level5(p->mem_ctx, r->in.flags, name,
4799 r->out.info, r->out.count);
4800 break;
4801 case 3:
4802 case 4:
4803 result = WERR_OK; /* ??? */
4804 break;
4805 default:
4806 return WERR_UNKNOWN_LEVEL;
4809 if (!W_ERROR_IS_OK(result)) {
4810 return result;
4813 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4814 spoolss_EnumPrinters, NULL,
4815 *r->out.info, r->in.level,
4816 *r->out.count);
4817 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4818 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4820 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4823 /****************************************************************
4824 _spoolss_GetPrinter
4825 ****************************************************************/
4827 WERROR _spoolss_GetPrinter(pipes_struct *p,
4828 struct spoolss_GetPrinter *r)
4830 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
4831 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
4832 WERROR result = WERR_OK;
4834 int snum;
4836 /* that's an [in out] buffer */
4838 if (!r->in.buffer && (r->in.offered != 0)) {
4839 return WERR_INVALID_PARAM;
4842 *r->out.needed = 0;
4844 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4845 return WERR_BADFID;
4848 result = get_a_printer(Printer, &ntprinter, 2,
4849 lp_const_servicename(snum));
4850 if (!W_ERROR_IS_OK(result)) {
4851 return result;
4854 switch (r->in.level) {
4855 case 0:
4856 result = construct_printer_info0(p->mem_ctx, ntprinter,
4857 &r->out.info->info0, snum);
4858 break;
4859 case 1:
4860 result = construct_printer_info1(p->mem_ctx, ntprinter,
4861 PRINTER_ENUM_ICON8,
4862 &r->out.info->info1, snum);
4863 break;
4864 case 2:
4865 result = construct_printer_info2(p->mem_ctx, ntprinter,
4866 &r->out.info->info2, snum);
4867 break;
4868 case 3:
4869 result = construct_printer_info3(p->mem_ctx, ntprinter,
4870 &r->out.info->info3, snum);
4871 break;
4872 case 4:
4873 result = construct_printer_info4(p->mem_ctx, ntprinter,
4874 &r->out.info->info4, snum);
4875 break;
4876 case 5:
4877 result = construct_printer_info5(p->mem_ctx, ntprinter,
4878 &r->out.info->info5, snum);
4879 break;
4880 case 6:
4881 result = construct_printer_info6(p->mem_ctx, ntprinter,
4882 &r->out.info->info6, snum);
4883 break;
4884 case 7:
4885 result = construct_printer_info7(p->mem_ctx, Printer,
4886 &r->out.info->info7, snum);
4887 break;
4888 default:
4889 result = WERR_UNKNOWN_LEVEL;
4890 break;
4893 free_a_printer(&ntprinter, 2);
4895 if (!W_ERROR_IS_OK(result)) {
4896 TALLOC_FREE(r->out.info);
4897 return result;
4900 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo, NULL,
4901 r->out.info, r->in.level);
4902 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4904 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4907 /********************************************************************
4908 ********************************************************************/
4910 static const char **string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4911 fstring *fstring_array,
4912 const char *cservername)
4914 int i, num_strings = 0;
4915 const char **array = NULL;
4917 for (i=0; fstring_array && fstring_array[i][0] != '\0'; i++) {
4919 const char *str = talloc_asprintf(mem_ctx, "\\\\%s%s",
4920 cservername, fstring_array[i]);
4921 if (!str) {
4922 TALLOC_FREE(array);
4923 return NULL;
4927 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4928 TALLOC_FREE(array);
4929 return NULL;
4933 if (i > 0) {
4934 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4935 &array, &num_strings);
4938 return array;
4941 /********************************************************************
4942 * fill a spoolss_DriverInfo1 struct
4943 ********************************************************************/
4945 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4946 struct spoolss_DriverInfo1 *r,
4947 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
4948 const char *servername,
4949 const char *architecture)
4951 r->driver_name = talloc_strdup(mem_ctx, driver->info_3->name);
4952 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4954 return WERR_OK;
4957 /********************************************************************
4958 * fill a spoolss_DriverInfo2 struct
4959 ********************************************************************/
4961 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4962 struct spoolss_DriverInfo2 *r,
4963 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
4964 const char *servername)
4967 const char *cservername = canon_servername(servername);
4969 r->version = driver->info_3->cversion;
4971 r->driver_name = talloc_strdup(mem_ctx, driver->info_3->name);
4972 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4973 r->architecture = talloc_strdup(mem_ctx, driver->info_3->environment);
4974 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4976 if (strlen(driver->info_3->driverpath)) {
4977 r->driver_path = talloc_asprintf(mem_ctx, "\\\\%s%s",
4978 cservername, driver->info_3->driverpath);
4979 } else {
4980 r->driver_path = talloc_strdup(mem_ctx, "");
4982 W_ERROR_HAVE_NO_MEMORY(r->driver_path);
4984 if (strlen(driver->info_3->datafile)) {
4985 r->data_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4986 cservername, driver->info_3->datafile);
4987 } else {
4988 r->data_file = talloc_strdup(mem_ctx, "");
4990 W_ERROR_HAVE_NO_MEMORY(r->data_file);
4992 if (strlen(driver->info_3->configfile)) {
4993 r->config_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
4994 cservername, driver->info_3->configfile);
4995 } else {
4996 r->config_file = talloc_strdup(mem_ctx, "");
4998 W_ERROR_HAVE_NO_MEMORY(r->config_file);
5000 return WERR_OK;
5003 /********************************************************************
5004 * fill a spoolss_DriverInfo3 struct
5005 ********************************************************************/
5007 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
5008 struct spoolss_DriverInfo3 *r,
5009 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
5010 const char *servername)
5012 const char *cservername = canon_servername(servername);
5014 r->version = driver->info_3->cversion;
5016 r->driver_name = talloc_strdup(mem_ctx, driver->info_3->name);
5017 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5018 r->architecture = talloc_strdup(mem_ctx, driver->info_3->environment);
5019 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5021 if (strlen(driver->info_3->driverpath)) {
5022 r->driver_path = talloc_asprintf(mem_ctx, "\\\\%s%s",
5023 cservername, driver->info_3->driverpath);
5024 } else {
5025 r->driver_path = talloc_strdup(mem_ctx, "");
5027 W_ERROR_HAVE_NO_MEMORY(r->driver_path);
5029 if (strlen(driver->info_3->datafile)) {
5030 r->data_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
5031 cservername, driver->info_3->datafile);
5032 } else {
5033 r->data_file = talloc_strdup(mem_ctx, "");
5035 W_ERROR_HAVE_NO_MEMORY(r->data_file);
5037 if (strlen(driver->info_3->configfile)) {
5038 r->config_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
5039 cservername, driver->info_3->configfile);
5040 } else {
5041 r->config_file = talloc_strdup(mem_ctx, "");
5043 W_ERROR_HAVE_NO_MEMORY(r->config_file);
5045 if (strlen(driver->info_3->helpfile)) {
5046 r->help_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
5047 cservername, driver->info_3->helpfile);
5048 } else {
5049 r->help_file = talloc_strdup(mem_ctx, "");
5051 W_ERROR_HAVE_NO_MEMORY(r->config_file);
5053 r->monitor_name = talloc_strdup(mem_ctx, driver->info_3->monitorname);
5054 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
5055 r->default_datatype = talloc_strdup(mem_ctx, driver->info_3->defaultdatatype);
5056 W_ERROR_HAVE_NO_MEMORY(r->default_datatype);
5058 r->dependent_files = string_array_from_driver_info(mem_ctx,
5059 driver->info_3->dependentfiles,
5060 cservername);
5061 return WERR_OK;
5064 /********************************************************************
5065 * fill a spoolss_DriverInfo6 struct
5066 ********************************************************************/
5068 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
5069 struct spoolss_DriverInfo6 *r,
5070 const NT_PRINTER_DRIVER_INFO_LEVEL *driver,
5071 const char *servername)
5073 const char *cservername = canon_servername(servername);
5075 r->version = driver->info_3->cversion;
5077 r->driver_name = talloc_strdup(mem_ctx, driver->info_3->name);
5078 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5079 r->architecture = talloc_strdup(mem_ctx, driver->info_3->environment);
5080 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5082 if (strlen(driver->info_3->driverpath)) {
5083 r->driver_path = talloc_asprintf(mem_ctx, "\\\\%s%s",
5084 cservername, driver->info_3->driverpath);
5085 } else {
5086 r->driver_path = talloc_strdup(mem_ctx, "");
5088 W_ERROR_HAVE_NO_MEMORY(r->driver_path);
5090 if (strlen(driver->info_3->datafile)) {
5091 r->data_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
5092 cservername, driver->info_3->datafile);
5093 } else {
5094 r->data_file = talloc_strdup(mem_ctx, "");
5096 W_ERROR_HAVE_NO_MEMORY(r->data_file);
5098 if (strlen(driver->info_3->configfile)) {
5099 r->config_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
5100 cservername, driver->info_3->configfile);
5101 } else {
5102 r->config_file = talloc_strdup(mem_ctx, "");
5104 W_ERROR_HAVE_NO_MEMORY(r->config_file);
5106 if (strlen(driver->info_3->helpfile)) {
5107 r->help_file = talloc_asprintf(mem_ctx, "\\\\%s%s",
5108 cservername, driver->info_3->helpfile);
5109 } else {
5110 r->help_file = talloc_strdup(mem_ctx, "");
5112 W_ERROR_HAVE_NO_MEMORY(r->config_file);
5114 r->monitor_name = talloc_strdup(mem_ctx, driver->info_3->monitorname);
5115 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
5116 r->default_datatype = talloc_strdup(mem_ctx, driver->info_3->defaultdatatype);
5117 W_ERROR_HAVE_NO_MEMORY(r->default_datatype);
5119 r->dependent_files = string_array_from_driver_info(mem_ctx,
5120 driver->info_3->dependentfiles,
5121 cservername);
5122 r->previous_names = string_array_from_driver_info(mem_ctx,
5123 NULL,
5124 cservername);
5126 r->driver_date = 0;
5127 r->driver_version = 0;
5129 r->manufacturer_name = talloc_strdup(mem_ctx, "");
5130 W_ERROR_HAVE_NO_MEMORY(r->manufacturer_name);
5131 r->manufacturer_url = talloc_strdup(mem_ctx, "");
5132 W_ERROR_HAVE_NO_MEMORY(r->manufacturer_url);
5133 r->hardware_id = talloc_strdup(mem_ctx, "");
5134 W_ERROR_HAVE_NO_MEMORY(r->hardware_id);
5135 r->provider = talloc_strdup(mem_ctx, "");
5136 W_ERROR_HAVE_NO_MEMORY(r->provider);
5138 return WERR_OK;
5141 /********************************************************************
5142 * construct_printer_driver_info_1
5143 ********************************************************************/
5145 static WERROR construct_printer_driver_info_1(TALLOC_CTX *mem_ctx,
5146 struct spoolss_DriverInfo1 *r,
5147 int snum,
5148 const char *servername,
5149 const char *architecture,
5150 uint32_t version)
5152 NT_PRINTER_INFO_LEVEL *printer = NULL;
5153 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5154 WERROR result;
5156 ZERO_STRUCT(driver);
5158 if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, lp_const_servicename(snum))))
5159 return WERR_INVALID_PRINTER_NAME;
5161 if (!W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version))) {
5162 free_a_printer(&printer, 2);
5163 return WERR_UNKNOWN_PRINTER_DRIVER;
5166 result = fill_printer_driver_info1(mem_ctx, r, &driver, servername, architecture);
5168 free_a_printer(&printer,2);
5170 return result;
5173 /********************************************************************
5174 * construct_printer_driver_info_2
5175 * fill a printer_info_2 struct
5176 ********************************************************************/
5178 static WERROR construct_printer_driver_info_2(TALLOC_CTX *mem_ctx,
5179 struct spoolss_DriverInfo2 *r,
5180 int snum,
5181 const char *servername,
5182 const char *architecture,
5183 uint32_t version)
5185 NT_PRINTER_INFO_LEVEL *printer = NULL;
5186 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5187 WERROR result;
5189 ZERO_STRUCT(printer);
5190 ZERO_STRUCT(driver);
5192 if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, lp_const_servicename(snum))))
5193 return WERR_INVALID_PRINTER_NAME;
5195 if (!W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version))) {
5196 free_a_printer(&printer, 2);
5197 return WERR_UNKNOWN_PRINTER_DRIVER;
5200 result = fill_printer_driver_info2(mem_ctx, r, &driver, servername);
5202 free_a_printer(&printer,2);
5204 return result;
5207 /********************************************************************
5208 * copy a strings array and convert to UNICODE
5210 * convert an array of ascii string to a UNICODE string
5211 ********************************************************************/
5213 static uint32 init_unistr_array(uint16 **uni_array, fstring *char_array, const char *servername)
5215 int i=0;
5216 int j=0;
5217 const char *v;
5218 char *line = NULL;
5219 TALLOC_CTX *ctx = talloc_tos();
5221 DEBUG(6,("init_unistr_array\n"));
5222 *uni_array=NULL;
5224 while (true) {
5225 if ( !char_array ) {
5226 v = "";
5227 } else {
5228 v = char_array[i];
5229 if (!v)
5230 v = ""; /* hack to handle null lists */
5233 /* hack to allow this to be used in places other than when generating
5234 the list of dependent files */
5236 TALLOC_FREE(line);
5237 if ( servername ) {
5238 line = talloc_asprintf(ctx,
5239 "\\\\%s%s",
5240 canon_servername(servername),
5242 } else {
5243 line = talloc_strdup(ctx, v);
5246 if (!line) {
5247 SAFE_FREE(*uni_array);
5248 return 0;
5250 DEBUGADD(6,("%d:%s:%lu\n", i, line, (unsigned long)strlen(line)));
5252 /* add one extra unit16 for the second terminating NULL */
5254 if ( (*uni_array=SMB_REALLOC_ARRAY(*uni_array, uint16, j+1+strlen(line)+2)) == NULL ) {
5255 DEBUG(2,("init_unistr_array: Realloc error\n" ));
5256 return 0;
5259 if ( !strlen(v) )
5260 break;
5262 j += (rpcstr_push((*uni_array+j), line, sizeof(uint16)*strlen(line)+2, STR_TERMINATE) / sizeof(uint16));
5263 i++;
5266 if (*uni_array) {
5267 /* special case for ""; we need to add both NULL's here */
5268 if (!j)
5269 (*uni_array)[j++]=0x0000;
5270 (*uni_array)[j]=0x0000;
5273 DEBUGADD(6,("last one:done\n"));
5275 /* return size of array in uint16's */
5277 return j+1;
5280 /********************************************************************
5281 * construct_printer_info_3
5282 * fill a printer_info_3 struct
5283 ********************************************************************/
5285 static WERROR construct_printer_driver_info_3(TALLOC_CTX *mem_ctx,
5286 struct spoolss_DriverInfo3 *r,
5287 int snum,
5288 const char *servername,
5289 const char *architecture,
5290 uint32_t version)
5292 NT_PRINTER_INFO_LEVEL *printer = NULL;
5293 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5294 WERROR status;
5295 ZERO_STRUCT(driver);
5297 status=get_a_printer(NULL, &printer, 2, lp_const_servicename(snum) );
5298 DEBUG(8,("construct_printer_driver_info_3: status: %s\n", win_errstr(status)));
5299 if (!W_ERROR_IS_OK(status))
5300 return WERR_INVALID_PRINTER_NAME;
5302 status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version);
5303 DEBUG(8,("construct_printer_driver_info_3: status: %s\n", win_errstr(status)));
5305 #if 0 /* JERRY */
5308 * I put this code in during testing. Helpful when commenting out the
5309 * support for DRIVER_INFO_6 in regards to win2k. Not needed in general
5310 * as win2k always queries the driver using an infor level of 6.
5311 * I've left it in (but ifdef'd out) because I'll probably
5312 * use it in experimentation again in the future. --jerry 22/01/2002
5315 if (!W_ERROR_IS_OK(status)) {
5317 * Is this a W2k client ?
5319 if (version == 3) {
5320 /* Yes - try again with a WinNT driver. */
5321 version = 2;
5322 status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version);
5323 DEBUG(8,("construct_printer_driver_info_3: status: %s\n", win_errstr(status)));
5325 #endif
5327 if (!W_ERROR_IS_OK(status)) {
5328 free_a_printer(&printer,2);
5329 return WERR_UNKNOWN_PRINTER_DRIVER;
5332 #if 0 /* JERRY */
5334 #endif
5337 status = fill_printer_driver_info3(mem_ctx, r, &driver, servername);
5339 free_a_printer(&printer,2);
5341 return status;
5344 /********************************************************************
5345 * construct_printer_info_6
5346 * fill a printer_info_6 struct
5347 ********************************************************************/
5349 static WERROR construct_printer_driver_info_6(TALLOC_CTX *mem_ctx,
5350 struct spoolss_DriverInfo6 *r,
5351 int snum,
5352 const char *servername,
5353 const char *architecture,
5354 uint32_t version)
5356 NT_PRINTER_INFO_LEVEL *printer = NULL;
5357 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5358 WERROR status;
5360 ZERO_STRUCT(driver);
5362 status=get_a_printer(NULL, &printer, 2, lp_const_servicename(snum) );
5364 DEBUG(8,("construct_printer_driver_info_6: status: %s\n", win_errstr(status)));
5366 if (!W_ERROR_IS_OK(status))
5367 return WERR_INVALID_PRINTER_NAME;
5369 status = get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version);
5371 DEBUG(8,("construct_printer_driver_info_6: status: %s\n", win_errstr(status)));
5373 if (!W_ERROR_IS_OK(status))
5376 * Is this a W2k client ?
5379 if (version < 3) {
5380 free_a_printer(&printer,2);
5381 return WERR_UNKNOWN_PRINTER_DRIVER;
5384 /* Yes - try again with a WinNT driver. */
5385 version = 2;
5386 status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version);
5387 DEBUG(8,("construct_printer_driver_info_6: status: %s\n", win_errstr(status)));
5388 if (!W_ERROR_IS_OK(status)) {
5389 free_a_printer(&printer,2);
5390 return WERR_UNKNOWN_PRINTER_DRIVER;
5394 status = fill_printer_driver_info6(mem_ctx, r, &driver, servername);
5396 free_a_printer(&printer,2);
5397 free_a_printer_driver(driver, 3);
5399 return status;
5402 /****************************************************************
5403 _spoolss_GetPrinterDriver2
5404 ****************************************************************/
5406 WERROR _spoolss_GetPrinterDriver2(pipes_struct *p,
5407 struct spoolss_GetPrinterDriver2 *r)
5409 Printer_entry *printer;
5410 WERROR result;
5412 const char *servername;
5413 int snum;
5415 /* that's an [in out] buffer */
5417 if (!r->in.buffer && (r->in.offered != 0)) {
5418 return WERR_INVALID_PARAM;
5421 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5423 if (!(printer = find_printer_index_by_hnd( p, r->in.handle))) {
5424 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5425 return WERR_INVALID_PRINTER_NAME;
5428 *r->out.needed = 0;
5429 *r->out.server_major_version = 0;
5430 *r->out.server_minor_version = 0;
5432 servername = get_server_name(printer);
5434 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5435 return WERR_BADFID;
5438 switch (r->in.level) {
5439 case 1:
5440 result = construct_printer_driver_info_1(p->mem_ctx,
5441 &r->out.info->info1,
5442 snum,
5443 servername,
5444 r->in.architecture,
5445 r->in.client_major_version);
5446 break;
5447 case 2:
5448 result = construct_printer_driver_info_2(p->mem_ctx,
5449 &r->out.info->info2,
5450 snum,
5451 servername,
5452 r->in.architecture,
5453 r->in.client_major_version);
5454 break;
5455 case 3:
5456 result = construct_printer_driver_info_3(p->mem_ctx,
5457 &r->out.info->info3,
5458 snum,
5459 servername,
5460 r->in.architecture,
5461 r->in.client_major_version);
5462 break;
5463 case 6:
5464 result = construct_printer_driver_info_6(p->mem_ctx,
5465 &r->out.info->info6,
5466 snum,
5467 servername,
5468 r->in.architecture,
5469 r->in.client_major_version);
5470 break;
5471 default:
5472 #if 0 /* JERRY */
5473 case 101:
5474 /* apparently this call is the equivalent of
5475 EnumPrinterDataEx() for the DsDriver key */
5476 break;
5477 #endif
5478 result = WERR_UNKNOWN_LEVEL;
5479 break;
5482 if (!W_ERROR_IS_OK(result)) {
5483 TALLOC_FREE(r->out.info);
5484 return result;
5487 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo, NULL,
5488 r->out.info, r->in.level);
5489 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5491 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5495 /****************************************************************
5496 _spoolss_StartPagePrinter
5497 ****************************************************************/
5499 WERROR _spoolss_StartPagePrinter(pipes_struct *p,
5500 struct spoolss_StartPagePrinter *r)
5502 POLICY_HND *handle = r->in.handle;
5504 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5506 if (!Printer) {
5507 DEBUG(3,("_spoolss_StartPagePrinter: "
5508 "Error in startpageprinter printer handle\n"));
5509 return WERR_BADFID;
5512 Printer->page_started=True;
5513 return WERR_OK;
5516 /****************************************************************
5517 _spoolss_EndPagePrinter
5518 ****************************************************************/
5520 WERROR _spoolss_EndPagePrinter(pipes_struct *p,
5521 struct spoolss_EndPagePrinter *r)
5523 POLICY_HND *handle = r->in.handle;
5524 int snum;
5526 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5528 if (!Printer) {
5529 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5530 OUR_HANDLE(handle)));
5531 return WERR_BADFID;
5534 if (!get_printer_snum(p, handle, &snum, NULL))
5535 return WERR_BADFID;
5537 Printer->page_started=False;
5538 print_job_endpage(snum, Printer->jobid);
5540 return WERR_OK;
5543 /****************************************************************
5544 _spoolss_StartDocPrinter
5545 ****************************************************************/
5547 WERROR _spoolss_StartDocPrinter(pipes_struct *p,
5548 struct spoolss_StartDocPrinter *r)
5550 POLICY_HND *handle = r->in.handle;
5551 uint32_t *jobid = r->out.job_id;
5552 struct spoolss_DocumentInfo1 *info_1;
5553 int snum;
5554 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5556 if (!Printer) {
5557 DEBUG(2,("_spoolss_StartDocPrinter: "
5558 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle)));
5559 return WERR_BADFID;
5562 if (r->in.level != 1) {
5563 return WERR_UNKNOWN_LEVEL;
5566 info_1 = r->in.info.info1;
5569 * a nice thing with NT is it doesn't listen to what you tell it.
5570 * when asked to send _only_ RAW datas, it tries to send datas
5571 * in EMF format.
5573 * So I add checks like in NT Server ...
5576 if (info_1->datatype) {
5577 if (strcmp(info_1->datatype, "RAW") != 0) {
5578 (*jobid)=0;
5579 return WERR_INVALID_DATATYPE;
5583 /* get the share number of the printer */
5584 if (!get_printer_snum(p, handle, &snum, NULL)) {
5585 return WERR_BADFID;
5588 Printer->jobid = print_job_start(p->server_info, snum,
5589 info_1->document_name,
5590 Printer->nt_devmode);
5592 /* An error occured in print_job_start() so return an appropriate
5593 NT error code. */
5595 if (Printer->jobid == -1) {
5596 return map_werror_from_unix(errno);
5599 Printer->document_started=True;
5600 (*jobid) = Printer->jobid;
5602 return WERR_OK;
5605 /****************************************************************
5606 _spoolss_EndDocPrinter
5607 ****************************************************************/
5609 WERROR _spoolss_EndDocPrinter(pipes_struct *p,
5610 struct spoolss_EndDocPrinter *r)
5612 POLICY_HND *handle = r->in.handle;
5614 return _spoolss_enddocprinter_internal(p, handle);
5617 /****************************************************************
5618 _spoolss_WritePrinter
5619 ****************************************************************/
5621 WERROR _spoolss_WritePrinter(pipes_struct *p,
5622 struct spoolss_WritePrinter *r)
5624 POLICY_HND *handle = r->in.handle;
5625 uint32 buffer_size = r->in._data_size;
5626 uint8 *buffer = r->in.data.data;
5627 uint32 *buffer_written = &r->in._data_size;
5628 int snum;
5629 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5631 if (!Printer) {
5632 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5633 OUR_HANDLE(handle)));
5634 *r->out.num_written = r->in._data_size;
5635 return WERR_BADFID;
5638 if (!get_printer_snum(p, handle, &snum, NULL))
5639 return WERR_BADFID;
5641 (*buffer_written) = (uint32)print_job_write(snum, Printer->jobid, (const char *)buffer,
5642 (SMB_OFF_T)-1, (size_t)buffer_size);
5643 if (*buffer_written == (uint32)-1) {
5644 *r->out.num_written = 0;
5645 if (errno == ENOSPC)
5646 return WERR_NO_SPOOL_SPACE;
5647 else
5648 return WERR_ACCESS_DENIED;
5651 *r->out.num_written = r->in._data_size;
5653 return WERR_OK;
5656 /********************************************************************
5657 * api_spoolss_getprinter
5658 * called from the spoolss dispatcher
5660 ********************************************************************/
5662 static WERROR control_printer(POLICY_HND *handle, uint32 command,
5663 pipes_struct *p)
5665 int snum;
5666 WERROR errcode = WERR_BADFUNC;
5667 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5669 if (!Printer) {
5670 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle)));
5671 return WERR_BADFID;
5674 if (!get_printer_snum(p, handle, &snum, NULL))
5675 return WERR_BADFID;
5677 switch (command) {
5678 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5679 if (print_queue_pause(p->server_info, snum, &errcode)) {
5680 errcode = WERR_OK;
5682 break;
5683 case SPOOLSS_PRINTER_CONTROL_RESUME:
5684 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5685 if (print_queue_resume(p->server_info, snum, &errcode)) {
5686 errcode = WERR_OK;
5688 break;
5689 case SPOOLSS_PRINTER_CONTROL_PURGE:
5690 if (print_queue_purge(p->server_info, snum, &errcode)) {
5691 errcode = WERR_OK;
5693 break;
5694 default:
5695 return WERR_UNKNOWN_LEVEL;
5698 return errcode;
5702 /****************************************************************
5703 _spoolss_AbortPrinter
5704 * From MSDN: "Deletes printer's spool file if printer is configured
5705 * for spooling"
5706 ****************************************************************/
5708 WERROR _spoolss_AbortPrinter(pipes_struct *p,
5709 struct spoolss_AbortPrinter *r)
5711 POLICY_HND *handle = r->in.handle;
5712 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5713 int snum;
5714 WERROR errcode = WERR_OK;
5716 if (!Printer) {
5717 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5718 OUR_HANDLE(handle)));
5719 return WERR_BADFID;
5722 if (!get_printer_snum(p, handle, &snum, NULL))
5723 return WERR_BADFID;
5725 print_job_delete(p->server_info, snum, Printer->jobid, &errcode );
5727 return errcode;
5730 /********************************************************************
5731 * called by spoolss_api_setprinter
5732 * when updating a printer description
5733 ********************************************************************/
5735 static WERROR update_printer_sec(POLICY_HND *handle,
5736 pipes_struct *p, SEC_DESC_BUF *secdesc_ctr)
5738 SEC_DESC_BUF *new_secdesc_ctr = NULL, *old_secdesc_ctr = NULL;
5739 WERROR result;
5740 int snum;
5742 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5744 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
5745 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5746 OUR_HANDLE(handle)));
5748 result = WERR_BADFID;
5749 goto done;
5752 if (!secdesc_ctr) {
5753 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5754 result = WERR_INVALID_PARAM;
5755 goto done;
5758 /* Check the user has permissions to change the security
5759 descriptor. By experimentation with two NT machines, the user
5760 requires Full Access to the printer to change security
5761 information. */
5763 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
5764 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5765 result = WERR_ACCESS_DENIED;
5766 goto done;
5769 /* NT seems to like setting the security descriptor even though
5770 nothing may have actually changed. */
5772 if ( !nt_printing_getsec(p->mem_ctx, Printer->sharename, &old_secdesc_ctr)) {
5773 DEBUG(2,("update_printer_sec: nt_printing_getsec() failed\n"));
5774 result = WERR_BADFID;
5775 goto done;
5778 if (DEBUGLEVEL >= 10) {
5779 SEC_ACL *the_acl;
5780 int i;
5782 the_acl = old_secdesc_ctr->sd->dacl;
5783 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
5784 PRINTERNAME(snum), the_acl->num_aces));
5786 for (i = 0; i < the_acl->num_aces; i++) {
5787 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5788 &the_acl->aces[i].trustee),
5789 the_acl->aces[i].access_mask));
5792 the_acl = secdesc_ctr->sd->dacl;
5794 if (the_acl) {
5795 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
5796 PRINTERNAME(snum), the_acl->num_aces));
5798 for (i = 0; i < the_acl->num_aces; i++) {
5799 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5800 &the_acl->aces[i].trustee),
5801 the_acl->aces[i].access_mask));
5803 } else {
5804 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
5808 new_secdesc_ctr = sec_desc_merge(p->mem_ctx, secdesc_ctr, old_secdesc_ctr);
5809 if (!new_secdesc_ctr) {
5810 result = WERR_NOMEM;
5811 goto done;
5814 if (sec_desc_equal(new_secdesc_ctr->sd, old_secdesc_ctr->sd)) {
5815 result = WERR_OK;
5816 goto done;
5819 result = nt_printing_setsec(Printer->sharename, new_secdesc_ctr);
5821 done:
5823 return result;
5826 /********************************************************************
5827 Canonicalize printer info from a client
5829 ATTN: It does not matter what we set the servername to hear
5830 since we do the necessary work in get_a_printer() to set it to
5831 the correct value based on what the client sent in the
5832 _spoolss_open_printer_ex().
5833 ********************************************************************/
5835 static bool check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum)
5837 fstring printername;
5838 const char *p;
5840 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
5841 "portname=%s drivername=%s comment=%s location=%s\n",
5842 info->servername, info->printername, info->sharename,
5843 info->portname, info->drivername, info->comment, info->location));
5845 /* we force some elements to "correct" values */
5846 slprintf(info->servername, sizeof(info->servername)-1, "\\\\%s", global_myname());
5847 fstrcpy(info->sharename, lp_servicename(snum));
5849 /* check to see if we allow printername != sharename */
5851 if ( lp_force_printername(snum) ) {
5852 slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s",
5853 global_myname(), info->sharename );
5854 } else {
5856 /* make sure printername is in \\server\printername format */
5858 fstrcpy( printername, info->printername );
5859 p = printername;
5860 if ( printername[0] == '\\' && printername[1] == '\\' ) {
5861 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
5862 p++;
5865 slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s",
5866 global_myname(), p );
5869 info->attributes |= PRINTER_ATTRIBUTE_SAMBA;
5870 info->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
5874 return True;
5877 /****************************************************************************
5878 ****************************************************************************/
5880 WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *portname, const char *uri )
5882 char *cmd = lp_addport_cmd();
5883 char *command = NULL;
5884 int ret;
5885 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5886 bool is_print_op = False;
5888 if ( !*cmd ) {
5889 return WERR_ACCESS_DENIED;
5892 command = talloc_asprintf(ctx,
5893 "%s \"%s\" \"%s\"", cmd, portname, uri );
5894 if (!command) {
5895 return WERR_NOMEM;
5898 if ( token )
5899 is_print_op = user_has_privileges( token, &se_printop );
5901 DEBUG(10,("Running [%s]\n", command));
5903 /********* BEGIN SePrintOperatorPrivilege **********/
5905 if ( is_print_op )
5906 become_root();
5908 ret = smbrun(command, NULL);
5910 if ( is_print_op )
5911 unbecome_root();
5913 /********* END SePrintOperatorPrivilege **********/
5915 DEBUGADD(10,("returned [%d]\n", ret));
5917 TALLOC_FREE(command);
5919 if ( ret != 0 ) {
5920 return WERR_ACCESS_DENIED;
5923 return WERR_OK;
5926 /****************************************************************************
5927 ****************************************************************************/
5929 bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer)
5931 char *cmd = lp_addprinter_cmd();
5932 char **qlines;
5933 char *command = NULL;
5934 int numlines;
5935 int ret;
5936 int fd;
5937 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5938 bool is_print_op = False;
5939 char *remote_machine = talloc_strdup(ctx, "%m");
5941 if (!remote_machine) {
5942 return false;
5944 remote_machine = talloc_sub_basic(ctx,
5945 current_user_info.smb_name,
5946 current_user_info.domain,
5947 remote_machine);
5948 if (!remote_machine) {
5949 return false;
5952 command = talloc_asprintf(ctx,
5953 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
5954 cmd, printer->info_2->printername, printer->info_2->sharename,
5955 printer->info_2->portname, printer->info_2->drivername,
5956 printer->info_2->location, printer->info_2->comment, remote_machine);
5957 if (!command) {
5958 return false;
5961 if ( token )
5962 is_print_op = user_has_privileges( token, &se_printop );
5964 DEBUG(10,("Running [%s]\n", command));
5966 /********* BEGIN SePrintOperatorPrivilege **********/
5968 if ( is_print_op )
5969 become_root();
5971 if ( (ret = smbrun(command, &fd)) == 0 ) {
5972 /* Tell everyone we updated smb.conf. */
5973 message_send_all(smbd_messaging_context(),
5974 MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
5977 if ( is_print_op )
5978 unbecome_root();
5980 /********* END SePrintOperatorPrivilege **********/
5982 DEBUGADD(10,("returned [%d]\n", ret));
5984 TALLOC_FREE(command);
5985 TALLOC_FREE(remote_machine);
5987 if ( ret != 0 ) {
5988 if (fd != -1)
5989 close(fd);
5990 return False;
5993 /* reload our services immediately */
5994 reload_services( False );
5996 numlines = 0;
5997 /* Get lines and convert them back to dos-codepage */
5998 qlines = fd_lines_load(fd, &numlines, 0, NULL);
5999 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
6000 close(fd);
6002 /* Set the portname to what the script says the portname should be. */
6003 /* but don't require anything to be return from the script exit a good error code */
6005 if (numlines) {
6006 /* Set the portname to what the script says the portname should be. */
6007 strncpy(printer->info_2->portname, qlines[0], sizeof(printer->info_2->portname));
6008 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
6011 TALLOC_FREE(qlines);
6012 return True;
6016 /********************************************************************
6017 * Called by spoolss_api_setprinter
6018 * when updating a printer description.
6019 ********************************************************************/
6021 static WERROR update_printer(pipes_struct *p, POLICY_HND *handle,
6022 struct spoolss_SetPrinterInfoCtr *info_ctr,
6023 struct spoolss_DeviceMode *devmode)
6025 int snum;
6026 NT_PRINTER_INFO_LEVEL *printer = NULL, *old_printer = NULL;
6027 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
6028 WERROR result;
6029 UNISTR2 buffer;
6030 fstring asc_buffer;
6032 DEBUG(8,("update_printer\n"));
6034 result = WERR_OK;
6036 if (!Printer) {
6037 result = WERR_BADFID;
6038 goto done;
6041 if (!get_printer_snum(p, handle, &snum, NULL)) {
6042 result = WERR_BADFID;
6043 goto done;
6046 if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum))) ||
6047 (!W_ERROR_IS_OK(get_a_printer(Printer, &old_printer, 2, lp_const_servicename(snum))))) {
6048 result = WERR_BADFID;
6049 goto done;
6052 DEBUGADD(8,("Converting info_2 struct\n"));
6055 * convert_printer_info converts the incoming
6056 * info from the client and overwrites the info
6057 * just read from the tdb in the pointer 'printer'.
6060 if (!convert_printer_info_new(info_ctr, printer)) {
6061 result = WERR_NOMEM;
6062 goto done;
6065 if (devmode) {
6066 /* we have a valid devmode
6067 convert it and link it*/
6069 DEBUGADD(8,("update_printer: Converting the devicemode struct\n"));
6070 if (!convert_devicemode_new(printer->info_2->printername,
6071 devmode,
6072 &printer->info_2->devmode)) {
6073 result = WERR_NOMEM;
6074 goto done;
6078 /* Do sanity check on the requested changes for Samba */
6080 if (!check_printer_ok(printer->info_2, snum)) {
6081 result = WERR_INVALID_PARAM;
6082 goto done;
6085 /* FIXME!!! If the driver has changed we really should verify that
6086 it is installed before doing much else --jerry */
6088 /* Check calling user has permission to update printer description */
6090 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6091 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6092 result = WERR_ACCESS_DENIED;
6093 goto done;
6096 /* Call addprinter hook */
6097 /* Check changes to see if this is really needed */
6099 if ( *lp_addprinter_cmd()
6100 && (!strequal(printer->info_2->drivername, old_printer->info_2->drivername)
6101 || !strequal(printer->info_2->comment, old_printer->info_2->comment)
6102 || !strequal(printer->info_2->portname, old_printer->info_2->portname)
6103 || !strequal(printer->info_2->location, old_printer->info_2->location)) )
6105 /* add_printer_hook() will call reload_services() */
6107 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
6108 printer) ) {
6109 result = WERR_ACCESS_DENIED;
6110 goto done;
6115 * When a *new* driver is bound to a printer, the drivername is used to
6116 * lookup previously saved driver initialization info, which is then
6117 * bound to the printer, simulating what happens in the Windows arch.
6119 if (!strequal(printer->info_2->drivername, old_printer->info_2->drivername))
6121 if (!set_driver_init(printer, 2))
6123 DEBUG(5,("update_printer: Error restoring driver initialization data for driver [%s]!\n",
6124 printer->info_2->drivername));
6127 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6128 printer->info_2->drivername));
6130 notify_printer_driver(snum, printer->info_2->drivername);
6134 * flag which changes actually occured. This is a small subset of
6135 * all the possible changes. We also have to update things in the
6136 * DsSpooler key.
6139 if (!strequal(printer->info_2->comment, old_printer->info_2->comment)) {
6140 init_unistr2( &buffer, printer->info_2->comment, UNI_STR_TERMINATE);
6141 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "description",
6142 REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 );
6144 notify_printer_comment(snum, printer->info_2->comment);
6147 if (!strequal(printer->info_2->sharename, old_printer->info_2->sharename)) {
6148 init_unistr2( &buffer, printer->info_2->sharename, UNI_STR_TERMINATE);
6149 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "shareName",
6150 REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 );
6152 notify_printer_sharename(snum, printer->info_2->sharename);
6155 if (!strequal(printer->info_2->printername, old_printer->info_2->printername)) {
6156 char *pname;
6158 if ( (pname = strchr_m( printer->info_2->printername+2, '\\' )) != NULL )
6159 pname++;
6160 else
6161 pname = printer->info_2->printername;
6164 init_unistr2( &buffer, pname, UNI_STR_TERMINATE);
6165 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "printerName",
6166 REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 );
6168 notify_printer_printername( snum, pname );
6171 if (!strequal(printer->info_2->portname, old_printer->info_2->portname)) {
6172 init_unistr2( &buffer, printer->info_2->portname, UNI_STR_TERMINATE);
6173 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "portName",
6174 REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 );
6176 notify_printer_port(snum, printer->info_2->portname);
6179 if (!strequal(printer->info_2->location, old_printer->info_2->location)) {
6180 init_unistr2( &buffer, printer->info_2->location, UNI_STR_TERMINATE);
6181 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "location",
6182 REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 );
6184 notify_printer_location(snum, printer->info_2->location);
6187 /* here we need to update some more DsSpooler keys */
6188 /* uNCName, serverName, shortServerName */
6190 init_unistr2( &buffer, global_myname(), UNI_STR_TERMINATE);
6191 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "serverName",
6192 REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 );
6193 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "shortServerName",
6194 REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 );
6196 slprintf( asc_buffer, sizeof(asc_buffer)-1, "\\\\%s\\%s",
6197 global_myname(), printer->info_2->sharename );
6198 init_unistr2( &buffer, asc_buffer, UNI_STR_TERMINATE);
6199 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "uNCName",
6200 REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 );
6202 /* Update printer info */
6203 result = mod_a_printer(printer, 2);
6205 done:
6206 free_a_printer(&printer, 2);
6207 free_a_printer(&old_printer, 2);
6210 return result;
6213 /****************************************************************************
6214 ****************************************************************************/
6215 static WERROR publish_or_unpublish_printer(pipes_struct *p, POLICY_HND *handle,
6216 struct spoolss_SetPrinterInfo7 *info7)
6218 #ifdef HAVE_ADS
6219 int snum;
6220 Printer_entry *Printer;
6222 if ( lp_security() != SEC_ADS ) {
6223 return WERR_UNKNOWN_LEVEL;
6226 Printer = find_printer_index_by_hnd(p, handle);
6228 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6230 if (!Printer)
6231 return WERR_BADFID;
6233 if (!get_printer_snum(p, handle, &snum, NULL))
6234 return WERR_BADFID;
6236 nt_printer_publish(Printer, snum, info7->action);
6238 return WERR_OK;
6239 #else
6240 return WERR_UNKNOWN_LEVEL;
6241 #endif
6244 /****************************************************************
6245 _spoolss_SetPrinter
6246 ****************************************************************/
6248 WERROR _spoolss_SetPrinter(pipes_struct *p,
6249 struct spoolss_SetPrinter *r)
6251 POLICY_HND *handle = r->in.handle;
6252 WERROR result;
6254 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
6256 if (!Printer) {
6257 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6258 OUR_HANDLE(handle)));
6259 return WERR_BADFID;
6262 /* check the level */
6263 switch (r->in.info_ctr->level) {
6264 case 0:
6265 return control_printer(handle, r->in.command, p);
6266 case 2:
6267 result = update_printer(p, handle,
6268 r->in.info_ctr,
6269 r->in.devmode_ctr->devmode);
6270 if (!W_ERROR_IS_OK(result))
6271 return result;
6272 if (r->in.secdesc_ctr->sd)
6273 result = update_printer_sec(handle, p,
6274 r->in.secdesc_ctr);
6275 return result;
6276 case 3:
6277 return update_printer_sec(handle, p,
6278 r->in.secdesc_ctr);
6279 case 7:
6280 return publish_or_unpublish_printer(p, handle,
6281 r->in.info_ctr->info.info7);
6282 default:
6283 return WERR_UNKNOWN_LEVEL;
6287 /****************************************************************
6288 _spoolss_FindClosePrinterNotify
6289 ****************************************************************/
6291 WERROR _spoolss_FindClosePrinterNotify(pipes_struct *p,
6292 struct spoolss_FindClosePrinterNotify *r)
6294 POLICY_HND *handle = r->in.handle;
6295 Printer_entry *Printer= find_printer_index_by_hnd(p, handle);
6297 if (!Printer) {
6298 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6299 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle)));
6300 return WERR_BADFID;
6303 if (Printer->notify.client_connected==True) {
6304 int snum = -1;
6306 if ( Printer->printer_type == SPLHND_SERVER)
6307 snum = -1;
6308 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
6309 !get_printer_snum(p, handle, &snum, NULL) )
6310 return WERR_BADFID;
6312 srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
6315 Printer->notify.flags=0;
6316 Printer->notify.options=0;
6317 Printer->notify.localmachine[0]='\0';
6318 Printer->notify.printerlocal=0;
6319 TALLOC_FREE(Printer->notify.option);
6320 Printer->notify.client_connected=False;
6322 return WERR_OK;
6325 /****************************************************************
6326 _spoolss_AddJob
6327 ****************************************************************/
6329 WERROR _spoolss_AddJob(pipes_struct *p,
6330 struct spoolss_AddJob *r)
6332 if (!r->in.buffer && (r->in.offered != 0)) {
6333 return WERR_INVALID_PARAM;
6336 /* this is what a NT server returns for AddJob. AddJob must fail on
6337 * non-local printers */
6339 if (r->in.level != 1) {
6340 return WERR_UNKNOWN_LEVEL;
6343 return WERR_INVALID_PARAM;
6346 /****************************************************************************
6347 fill_job_info1
6348 ****************************************************************************/
6350 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
6351 struct spoolss_JobInfo1 *r,
6352 const print_queue_struct *queue,
6353 int position, int snum,
6354 const NT_PRINTER_INFO_LEVEL *ntprinter)
6356 struct tm *t;
6358 t = gmtime(&queue->time);
6360 r->job_id = queue->job;
6362 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6363 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6364 r->server_name = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
6365 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6366 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6367 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6368 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6369 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6370 r->data_type = talloc_strdup(mem_ctx, "RAW");
6371 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6372 r->text_status = talloc_strdup(mem_ctx, "");
6373 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6375 r->status = nt_printj_status(queue->status);
6376 r->priority = queue->priority;
6377 r->position = position;
6378 r->total_pages = queue->page_count;
6379 r->pages_printed = 0; /* ??? */
6381 init_systemtime(&r->submitted, t);
6383 return WERR_OK;
6386 /****************************************************************************
6387 fill_job_info2
6388 ****************************************************************************/
6390 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
6391 struct spoolss_JobInfo2 *r,
6392 const print_queue_struct *queue,
6393 int position, int snum,
6394 const NT_PRINTER_INFO_LEVEL *ntprinter,
6395 struct spoolss_DeviceMode *devmode)
6397 struct tm *t;
6399 t = gmtime(&queue->time);
6401 r->job_id = queue->job;
6403 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6404 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6405 r->server_name = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
6406 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6407 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6408 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6409 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6410 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6411 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
6412 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
6413 r->data_type = talloc_strdup(mem_ctx, "RAW");
6414 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6415 r->print_processor = talloc_strdup(mem_ctx, "winprint");
6416 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
6417 r->parameters = talloc_strdup(mem_ctx, "");
6418 W_ERROR_HAVE_NO_MEMORY(r->parameters);
6419 r->driver_name = talloc_strdup(mem_ctx, ntprinter->info_2->drivername);
6420 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
6422 r->devmode = devmode;
6424 r->text_status = talloc_strdup(mem_ctx, "");
6425 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6427 r->secdesc = NULL;
6429 r->status = nt_printj_status(queue->status);
6430 r->priority = queue->priority;
6431 r->position = position;
6432 r->start_time = 0;
6433 r->until_time = 0;
6434 r->total_pages = queue->page_count;
6435 r->size = queue->size;
6436 init_systemtime(&r->submitted, t);
6437 r->time = 0;
6438 r->pages_printed = 0; /* ??? */
6440 return WERR_OK;
6443 /****************************************************************************
6444 Enumjobs at level 1.
6445 ****************************************************************************/
6447 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
6448 const print_queue_struct *queue,
6449 uint32_t num_queues, int snum,
6450 const NT_PRINTER_INFO_LEVEL *ntprinter,
6451 union spoolss_JobInfo **info_p,
6452 uint32_t *count)
6454 union spoolss_JobInfo *info;
6455 int i;
6456 WERROR result = WERR_OK;
6458 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6459 W_ERROR_HAVE_NO_MEMORY(info);
6461 *count = num_queues;
6463 for (i=0; i<*count; i++) {
6464 result = fill_job_info1(info,
6465 &info[i].info1,
6466 &queue[i],
6468 snum,
6469 ntprinter);
6470 if (!W_ERROR_IS_OK(result)) {
6471 goto out;
6475 out:
6476 if (!W_ERROR_IS_OK(result)) {
6477 TALLOC_FREE(info);
6478 *count = 0;
6479 return result;
6482 *info_p = info;
6484 return WERR_OK;
6487 /****************************************************************************
6488 Enumjobs at level 2.
6489 ****************************************************************************/
6491 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
6492 const print_queue_struct *queue,
6493 uint32_t num_queues, int snum,
6494 const NT_PRINTER_INFO_LEVEL *ntprinter,
6495 union spoolss_JobInfo **info_p,
6496 uint32_t *count)
6498 union spoolss_JobInfo *info;
6499 int i;
6500 WERROR result = WERR_OK;
6502 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6503 W_ERROR_HAVE_NO_MEMORY(info);
6505 *count = num_queues;
6507 for (i=0; i<*count; i++) {
6509 struct spoolss_DeviceMode *devmode;
6511 devmode = construct_dev_mode_new(info, lp_const_servicename(snum));
6512 if (!devmode) {
6513 result = WERR_NOMEM;
6514 goto out;
6517 result = fill_job_info2(info,
6518 &info[i].info2,
6519 &queue[i],
6521 snum,
6522 ntprinter,
6523 devmode);
6524 if (!W_ERROR_IS_OK(result)) {
6525 goto out;
6529 out:
6530 if (!W_ERROR_IS_OK(result)) {
6531 TALLOC_FREE(info);
6532 *count = 0;
6533 return result;
6536 *info_p = info;
6538 return WERR_OK;
6541 /****************************************************************
6542 _spoolss_EnumJobs
6543 ****************************************************************/
6545 WERROR _spoolss_EnumJobs(pipes_struct *p,
6546 struct spoolss_EnumJobs *r)
6548 WERROR result;
6549 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
6550 int snum;
6551 print_status_struct prt_status;
6552 print_queue_struct *queue = NULL;
6553 uint32_t count;
6555 /* that's an [in out] buffer */
6557 if (!r->in.buffer && (r->in.offered != 0)) {
6558 return WERR_INVALID_PARAM;
6561 DEBUG(4,("_spoolss_EnumJobs\n"));
6563 *r->out.needed = 0;
6564 *r->out.count = 0;
6565 *r->out.info = NULL;
6567 /* lookup the printer snum and tdb entry */
6569 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6570 return WERR_BADFID;
6573 result = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum));
6574 if (!W_ERROR_IS_OK(result)) {
6575 return result;
6578 count = print_queue_status(snum, &queue, &prt_status);
6579 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
6580 count, prt_status.status, prt_status.message));
6582 if (count == 0) {
6583 SAFE_FREE(queue);
6584 free_a_printer(&ntprinter, 2);
6585 return WERR_OK;
6588 switch (r->in.level) {
6589 case 1:
6590 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
6591 ntprinter, r->out.info, r->out.count);
6592 break;
6593 case 2:
6594 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
6595 ntprinter, r->out.info, r->out.count);
6596 break;
6597 default:
6598 result = WERR_UNKNOWN_LEVEL;
6599 break;
6602 SAFE_FREE(queue);
6603 free_a_printer(&ntprinter, 2);
6605 if (!W_ERROR_IS_OK(result)) {
6606 return result;
6609 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6610 spoolss_EnumJobs, NULL,
6611 *r->out.info, r->in.level,
6612 *r->out.count);
6613 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6614 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6616 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6619 /****************************************************************
6620 _spoolss_ScheduleJob
6621 ****************************************************************/
6623 WERROR _spoolss_ScheduleJob(pipes_struct *p,
6624 struct spoolss_ScheduleJob *r)
6626 return WERR_OK;
6629 /****************************************************************
6630 _spoolss_SetJob
6631 ****************************************************************/
6633 WERROR _spoolss_SetJob(pipes_struct *p,
6634 struct spoolss_SetJob *r)
6636 POLICY_HND *handle = r->in.handle;
6637 uint32 jobid = r->in.job_id;
6638 uint32 command = r->in.command;
6640 int snum;
6641 WERROR errcode = WERR_BADFUNC;
6643 if (!get_printer_snum(p, handle, &snum, NULL)) {
6644 return WERR_BADFID;
6647 if (!print_job_exists(lp_const_servicename(snum), jobid)) {
6648 return WERR_INVALID_PRINTER_NAME;
6651 switch (command) {
6652 case SPOOLSS_JOB_CONTROL_CANCEL:
6653 case SPOOLSS_JOB_CONTROL_DELETE:
6654 if (print_job_delete(p->server_info, snum, jobid, &errcode)) {
6655 errcode = WERR_OK;
6657 break;
6658 case SPOOLSS_JOB_CONTROL_PAUSE:
6659 if (print_job_pause(p->server_info, snum, jobid, &errcode)) {
6660 errcode = WERR_OK;
6662 break;
6663 case SPOOLSS_JOB_CONTROL_RESTART:
6664 case SPOOLSS_JOB_CONTROL_RESUME:
6665 if (print_job_resume(p->server_info, snum, jobid, &errcode)) {
6666 errcode = WERR_OK;
6668 break;
6669 default:
6670 return WERR_UNKNOWN_LEVEL;
6673 return errcode;
6676 /****************************************************************************
6677 Enumerates all printer drivers at level 1.
6678 ****************************************************************************/
6680 static WERROR enumprinterdrivers_level1(TALLOC_CTX *mem_ctx,
6681 const char *servername,
6682 const char *architecture,
6683 union spoolss_DriverInfo **info_p,
6684 uint32_t *count)
6686 int i;
6687 int ndrivers;
6688 uint32_t version;
6689 fstring *list = NULL;
6690 NT_PRINTER_DRIVER_INFO_LEVEL driver;
6691 union spoolss_DriverInfo *info = NULL;
6692 WERROR result = WERR_OK;
6694 *count = 0;
6696 for (version=0; version<DRIVER_MAX_VERSION; version++) {
6697 list = NULL;
6698 ndrivers = get_ntdrivers(&list, architecture, version);
6699 DEBUGADD(4,("we have:[%d] drivers in environment [%s] and version [%d]\n",
6700 ndrivers, architecture, version));
6702 if (ndrivers == -1) {
6703 result = WERR_NOMEM;
6704 goto out;
6707 if (ndrivers != 0) {
6708 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
6709 union spoolss_DriverInfo,
6710 *count + ndrivers);
6711 if (!info) {
6712 DEBUG(0,("enumprinterdrivers_level1: "
6713 "failed to enlarge driver info buffer!\n"));
6714 result = WERR_NOMEM;
6715 goto out;
6719 for (i=0; i<ndrivers; i++) {
6720 DEBUGADD(5,("\tdriver: [%s]\n", list[i]));
6721 ZERO_STRUCT(driver);
6722 result = get_a_printer_driver(&driver, 3, list[i],
6723 architecture, version);
6724 if (!W_ERROR_IS_OK(result)) {
6725 goto out;
6727 result = fill_printer_driver_info1(info, &info[*count+i].info1,
6728 &driver, servername,
6729 architecture);
6730 if (!W_ERROR_IS_OK(result)) {
6731 free_a_printer_driver(driver, 3);
6732 goto out;
6734 free_a_printer_driver(driver, 3);
6737 *count += ndrivers;
6738 SAFE_FREE(list);
6741 out:
6742 SAFE_FREE(list);
6744 if (!W_ERROR_IS_OK(result)) {
6745 TALLOC_FREE(info);
6746 *count = 0;
6747 return result;
6750 *info_p = info;
6752 return WERR_OK;
6755 /****************************************************************************
6756 Enumerates all printer drivers at level 2.
6757 ****************************************************************************/
6759 static WERROR enumprinterdrivers_level2(TALLOC_CTX *mem_ctx,
6760 const char *servername,
6761 const char *architecture,
6762 union spoolss_DriverInfo **info_p,
6763 uint32_t *count)
6765 int i;
6766 int ndrivers;
6767 uint32_t version;
6768 fstring *list = NULL;
6769 NT_PRINTER_DRIVER_INFO_LEVEL driver;
6770 union spoolss_DriverInfo *info = NULL;
6771 WERROR result = WERR_OK;
6773 *count = 0;
6775 for (version=0; version<DRIVER_MAX_VERSION; version++) {
6776 list = NULL;
6777 ndrivers = get_ntdrivers(&list, architecture, version);
6778 DEBUGADD(4,("we have:[%d] drivers in environment [%s] and version [%d]\n",
6779 ndrivers, architecture, version));
6781 if (ndrivers == -1) {
6782 result = WERR_NOMEM;
6783 goto out;
6786 if (ndrivers != 0) {
6787 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
6788 union spoolss_DriverInfo,
6789 *count + ndrivers);
6790 if (!info) {
6791 DEBUG(0,("enumprinterdrivers_level2: "
6792 "failed to enlarge driver info buffer!\n"));
6793 result = WERR_NOMEM;
6794 goto out;
6798 for (i=0; i<ndrivers; i++) {
6799 DEBUGADD(5,("\tdriver: [%s]\n", list[i]));
6800 ZERO_STRUCT(driver);
6801 result = get_a_printer_driver(&driver, 3, list[i],
6802 architecture, version);
6803 if (!W_ERROR_IS_OK(result)) {
6804 goto out;
6806 result = fill_printer_driver_info2(info, &info[*count+i].info2,
6807 &driver, servername);
6808 if (!W_ERROR_IS_OK(result)) {
6809 free_a_printer_driver(driver, 3);
6810 goto out;
6812 free_a_printer_driver(driver, 3);
6815 *count += ndrivers;
6816 SAFE_FREE(list);
6819 out:
6820 SAFE_FREE(list);
6822 if (!W_ERROR_IS_OK(result)) {
6823 TALLOC_FREE(info);
6824 *count = 0;
6825 return result;
6828 *info_p = info;
6830 return WERR_OK;
6833 /****************************************************************************
6834 Enumerates all printer drivers at level 3.
6835 ****************************************************************************/
6837 static WERROR enumprinterdrivers_level3(TALLOC_CTX *mem_ctx,
6838 const char *servername,
6839 const char *architecture,
6840 union spoolss_DriverInfo **info_p,
6841 uint32_t *count)
6843 int i;
6844 int ndrivers;
6845 uint32_t version;
6846 fstring *list = NULL;
6847 union spoolss_DriverInfo *info = NULL;
6848 NT_PRINTER_DRIVER_INFO_LEVEL driver;
6849 WERROR result = WERR_OK;
6851 *count = 0;
6853 for (version=0; version<DRIVER_MAX_VERSION; version++) {
6854 list = NULL;
6855 ndrivers = get_ntdrivers(&list, architecture, version);
6856 DEBUGADD(4,("we have:[%d] drivers in environment [%s] and version [%d]\n",
6857 ndrivers, architecture, version));
6859 if (ndrivers == -1) {
6860 result = WERR_NOMEM;
6861 goto out;
6864 if (ndrivers != 0) {
6865 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
6866 union spoolss_DriverInfo,
6867 *count + ndrivers);
6868 if (!info) {
6869 DEBUG(0,("enumprinterdrivers_level3: "
6870 "failed to enlarge driver info buffer!\n"));
6871 result = WERR_NOMEM;
6872 goto out;
6876 for (i=0; i<ndrivers; i++) {
6877 DEBUGADD(5,("\tdriver: [%s]\n", list[i]));
6878 ZERO_STRUCT(driver);
6879 result = get_a_printer_driver(&driver, 3, list[i],
6880 architecture, version);
6881 if (!W_ERROR_IS_OK(result)) {
6882 goto out;
6884 result = fill_printer_driver_info3(info, &info[*count+i].info3,
6885 &driver, servername);
6886 if (!W_ERROR_IS_OK(result)) {
6887 free_a_printer_driver(driver, 3);
6888 goto out;
6891 free_a_printer_driver(driver, 3);
6894 *count += ndrivers;
6895 SAFE_FREE(list);
6898 out:
6899 SAFE_FREE(list);
6901 if (!W_ERROR_IS_OK(result)) {
6902 TALLOC_FREE(info);
6903 *count = 0;
6904 return result;
6907 *info_p = info;
6909 return WERR_OK;
6912 /****************************************************************
6913 _spoolss_EnumPrinterDrivers
6914 ****************************************************************/
6916 WERROR _spoolss_EnumPrinterDrivers(pipes_struct *p,
6917 struct spoolss_EnumPrinterDrivers *r)
6919 const char *cservername;
6920 WERROR result;
6922 /* that's an [in out] buffer */
6924 if (!r->in.buffer && (r->in.offered != 0)) {
6925 return WERR_INVALID_PARAM;
6928 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
6930 *r->out.needed = 0;
6931 *r->out.count = 0;
6932 *r->out.info = NULL;
6934 cservername = canon_servername(r->in.server);
6936 if (!is_myname_or_ipaddr(cservername)) {
6937 return WERR_UNKNOWN_PRINTER_DRIVER;
6940 switch (r->in.level) {
6941 case 1:
6942 result = enumprinterdrivers_level1(p->mem_ctx, cservername,
6943 r->in.environment,
6944 r->out.info, r->out.count);
6945 break;
6946 case 2:
6947 result = enumprinterdrivers_level2(p->mem_ctx, cservername,
6948 r->in.environment,
6949 r->out.info, r->out.count);
6950 break;
6951 case 3:
6952 result = enumprinterdrivers_level3(p->mem_ctx, cservername,
6953 r->in.environment,
6954 r->out.info, r->out.count);
6955 break;
6956 default:
6957 return WERR_UNKNOWN_LEVEL;
6960 if (!W_ERROR_IS_OK(result)) {
6961 return result;
6964 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6965 spoolss_EnumPrinterDrivers, NULL,
6966 *r->out.info, r->in.level,
6967 *r->out.count);
6968 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6969 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6971 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6974 /****************************************************************************
6975 ****************************************************************************/
6977 static WERROR fill_form_info_1(TALLOC_CTX *mem_ctx,
6978 struct spoolss_FormInfo1 *r,
6979 const nt_forms_struct *form)
6981 r->form_name = talloc_strdup(mem_ctx, form->name);
6982 W_ERROR_HAVE_NO_MEMORY(r->form_name);
6984 r->flags = form->flag;
6985 r->size.width = form->width;
6986 r->size.height = form->length;
6987 r->area.left = form->left;
6988 r->area.top = form->top;
6989 r->area.right = form->right;
6990 r->area.bottom = form->bottom;
6992 return WERR_OK;
6995 /****************************************************************
6996 spoolss_enumforms_level1
6997 ****************************************************************/
6999 static WERROR spoolss_enumforms_level1(TALLOC_CTX *mem_ctx,
7000 const nt_forms_struct *builtin_forms,
7001 uint32_t num_builtin_forms,
7002 const nt_forms_struct *user_forms,
7003 uint32_t num_user_forms,
7004 union spoolss_FormInfo **info_p,
7005 uint32_t *count)
7007 union spoolss_FormInfo *info;
7008 WERROR result = WERR_OK;
7009 int i;
7011 *count = num_builtin_forms + num_user_forms;
7013 info = TALLOC_ARRAY(mem_ctx, union spoolss_FormInfo, *count);
7014 W_ERROR_HAVE_NO_MEMORY(info);
7016 /* construct the list of form structures */
7017 for (i=0; i<num_builtin_forms; i++) {
7018 DEBUGADD(6,("Filling form number [%d]\n",i));
7019 result = fill_form_info_1(info, &info[i].info1,
7020 &builtin_forms[i]);
7021 if (!W_ERROR_IS_OK(result)) {
7022 goto out;
7026 for (; i<num_user_forms; i++) {
7027 DEBUGADD(6,("Filling form number [%d]\n",i));
7028 result = fill_form_info_1(info, &info[i].info1,
7029 &user_forms[i-num_builtin_forms]);
7030 if (!W_ERROR_IS_OK(result)) {
7031 goto out;
7035 out:
7036 if (!W_ERROR_IS_OK(result)) {
7037 TALLOC_FREE(info);
7038 *count = 0;
7039 return result;
7042 *info_p = info;
7044 return WERR_OK;
7047 /****************************************************************
7048 _spoolss_EnumForms
7049 ****************************************************************/
7051 WERROR _spoolss_EnumForms(pipes_struct *p,
7052 struct spoolss_EnumForms *r)
7054 WERROR result;
7055 nt_forms_struct *user_forms = NULL;
7056 nt_forms_struct *builtin_forms = NULL;
7057 uint32_t num_user_forms;
7058 uint32_t num_builtin_forms;
7060 *r->out.count = 0;
7061 *r->out.needed = 0;
7062 *r->out.info = NULL;
7064 /* that's an [in out] buffer */
7066 if (!r->in.buffer && (r->in.offered != 0) ) {
7067 return WERR_INVALID_PARAM;
7070 DEBUG(4,("_spoolss_EnumForms\n"));
7071 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7072 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7074 num_builtin_forms = get_builtin_ntforms(&builtin_forms);
7075 DEBUGADD(5,("Number of builtin forms [%d]\n", num_builtin_forms));
7076 num_user_forms = get_ntforms(&user_forms);
7077 DEBUGADD(5,("Number of user forms [%d]\n", num_user_forms));
7079 if (num_user_forms + num_builtin_forms == 0) {
7080 SAFE_FREE(builtin_forms);
7081 SAFE_FREE(user_forms);
7082 return WERR_NO_MORE_ITEMS;
7085 switch (r->in.level) {
7086 case 1:
7087 result = spoolss_enumforms_level1(p->mem_ctx,
7088 builtin_forms,
7089 num_builtin_forms,
7090 user_forms,
7091 num_user_forms,
7092 r->out.info,
7093 r->out.count);
7094 break;
7095 default:
7096 result = WERR_UNKNOWN_LEVEL;
7097 break;
7100 SAFE_FREE(user_forms);
7101 SAFE_FREE(builtin_forms);
7103 if (!W_ERROR_IS_OK(result)) {
7104 return result;
7107 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7108 spoolss_EnumForms, NULL,
7109 *r->out.info, r->in.level,
7110 *r->out.count);
7111 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7112 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7114 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7117 /****************************************************************
7118 ****************************************************************/
7120 static WERROR find_form_byname(const char *name,
7121 nt_forms_struct *form)
7123 nt_forms_struct *list = NULL;
7124 int num_forms = 0, i = 0;
7126 if (get_a_builtin_ntform_by_string(name, form)) {
7127 return WERR_OK;
7130 num_forms = get_ntforms(&list);
7131 DEBUGADD(5,("Number of forms [%d]\n", num_forms));
7133 if (num_forms == 0) {
7134 return WERR_BADFID;
7137 /* Check if the requested name is in the list of form structures */
7138 for (i = 0; i < num_forms; i++) {
7140 DEBUG(4,("checking form %s (want %s)\n", list[i].name, name));
7142 if (strequal(name, list[i].name)) {
7143 DEBUGADD(6,("Found form %s number [%d]\n", name, i));
7144 *form = list[i];
7145 SAFE_FREE(list);
7146 return WERR_OK;
7150 SAFE_FREE(list);
7152 return WERR_BADFID;
7155 /****************************************************************
7156 _spoolss_GetForm
7157 ****************************************************************/
7159 WERROR _spoolss_GetForm(pipes_struct *p,
7160 struct spoolss_GetForm *r)
7162 WERROR result;
7163 nt_forms_struct form;
7165 /* that's an [in out] buffer */
7167 if (!r->in.buffer && (r->in.offered != 0)) {
7168 return WERR_INVALID_PARAM;
7171 DEBUG(4,("_spoolss_GetForm\n"));
7172 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7173 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7175 result = find_form_byname(r->in.form_name, &form);
7176 if (!W_ERROR_IS_OK(result)) {
7177 TALLOC_FREE(r->out.info);
7178 return result;
7181 switch (r->in.level) {
7182 case 1:
7183 result = fill_form_info_1(p->mem_ctx,
7184 &r->out.info->info1,
7185 &form);
7186 break;
7188 default:
7189 result = WERR_UNKNOWN_LEVEL;
7190 break;
7193 if (!W_ERROR_IS_OK(result)) {
7194 TALLOC_FREE(r->out.info);
7195 return result;
7198 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo, NULL,
7199 r->out.info, r->in.level);
7200 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7202 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7205 /****************************************************************************
7206 ****************************************************************************/
7208 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
7209 struct spoolss_PortInfo1 *r,
7210 const char *name)
7212 r->port_name = talloc_strdup(mem_ctx, name);
7213 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7215 return WERR_OK;
7218 /****************************************************************************
7219 TODO: This probably needs distinguish between TCP/IP and Local ports
7220 somehow.
7221 ****************************************************************************/
7223 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
7224 struct spoolss_PortInfo2 *r,
7225 const char *name)
7227 r->port_name = talloc_strdup(mem_ctx, name);
7228 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7230 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
7231 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
7233 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT); /* FIXME */
7234 W_ERROR_HAVE_NO_MEMORY(r->description);
7236 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
7237 r->reserved = 0;
7239 return WERR_OK;
7243 /****************************************************************************
7244 wrapper around the enumer ports command
7245 ****************************************************************************/
7247 WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines )
7249 char *cmd = lp_enumports_cmd();
7250 char **qlines = NULL;
7251 char *command = NULL;
7252 int numlines;
7253 int ret;
7254 int fd;
7256 *count = 0;
7257 *lines = NULL;
7259 /* if no hook then just fill in the default port */
7261 if ( !*cmd ) {
7262 if (!(qlines = TALLOC_ARRAY( NULL, char*, 2 ))) {
7263 return WERR_NOMEM;
7265 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7266 TALLOC_FREE(qlines);
7267 return WERR_NOMEM;
7269 qlines[1] = NULL;
7270 numlines = 1;
7272 else {
7273 /* we have a valid enumport command */
7275 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7276 if (!command) {
7277 return WERR_NOMEM;
7280 DEBUG(10,("Running [%s]\n", command));
7281 ret = smbrun(command, &fd);
7282 DEBUG(10,("Returned [%d]\n", ret));
7283 TALLOC_FREE(command);
7284 if (ret != 0) {
7285 if (fd != -1) {
7286 close(fd);
7288 return WERR_ACCESS_DENIED;
7291 numlines = 0;
7292 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7293 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7294 close(fd);
7297 *count = numlines;
7298 *lines = qlines;
7300 return WERR_OK;
7303 /****************************************************************************
7304 enumports level 1.
7305 ****************************************************************************/
7307 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7308 union spoolss_PortInfo **info_p,
7309 uint32_t *count)
7311 union spoolss_PortInfo *info = NULL;
7312 int i=0;
7313 WERROR result = WERR_OK;
7314 char **qlines = NULL;
7315 int numlines = 0;
7317 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7318 if (!W_ERROR_IS_OK(result)) {
7319 goto out;
7322 if (numlines) {
7323 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7324 if (!info) {
7325 DEBUG(10,("Returning WERR_NOMEM\n"));
7326 result = WERR_NOMEM;
7327 goto out;
7330 for (i=0; i<numlines; i++) {
7331 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7332 result = fill_port_1(info, &info[i].info1, qlines[i]);
7333 if (!W_ERROR_IS_OK(result)) {
7334 goto out;
7338 TALLOC_FREE(qlines);
7340 out:
7341 if (!W_ERROR_IS_OK(result)) {
7342 TALLOC_FREE(info);
7343 TALLOC_FREE(qlines);
7344 *count = 0;
7345 *info_p = NULL;
7346 return result;
7349 *info_p = info;
7350 *count = numlines;
7352 return WERR_OK;
7355 /****************************************************************************
7356 enumports level 2.
7357 ****************************************************************************/
7359 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7360 union spoolss_PortInfo **info_p,
7361 uint32_t *count)
7363 union spoolss_PortInfo *info = NULL;
7364 int i=0;
7365 WERROR result = WERR_OK;
7366 char **qlines = NULL;
7367 int numlines = 0;
7369 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7370 if (!W_ERROR_IS_OK(result)) {
7371 goto out;
7374 if (numlines) {
7375 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7376 if (!info) {
7377 DEBUG(10,("Returning WERR_NOMEM\n"));
7378 result = WERR_NOMEM;
7379 goto out;
7382 for (i=0; i<numlines; i++) {
7383 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7384 result = fill_port_2(info, &info[i].info2, qlines[i]);
7385 if (!W_ERROR_IS_OK(result)) {
7386 goto out;
7390 TALLOC_FREE(qlines);
7392 out:
7393 if (!W_ERROR_IS_OK(result)) {
7394 TALLOC_FREE(info);
7395 TALLOC_FREE(qlines);
7396 *count = 0;
7397 *info_p = NULL;
7398 return result;
7401 *info_p = info;
7402 *count = numlines;
7404 return WERR_OK;
7407 /****************************************************************
7408 _spoolss_EnumPorts
7409 ****************************************************************/
7411 WERROR _spoolss_EnumPorts(pipes_struct *p,
7412 struct spoolss_EnumPorts *r)
7414 WERROR result;
7416 /* that's an [in out] buffer */
7418 if (!r->in.buffer && (r->in.offered != 0)) {
7419 return WERR_INVALID_PARAM;
7422 DEBUG(4,("_spoolss_EnumPorts\n"));
7424 *r->out.count = 0;
7425 *r->out.needed = 0;
7426 *r->out.info = NULL;
7428 switch (r->in.level) {
7429 case 1:
7430 result = enumports_level_1(p->mem_ctx, r->out.info,
7431 r->out.count);
7432 break;
7433 case 2:
7434 result = enumports_level_2(p->mem_ctx, r->out.info,
7435 r->out.count);
7436 break;
7437 default:
7438 return WERR_UNKNOWN_LEVEL;
7441 if (!W_ERROR_IS_OK(result)) {
7442 return result;
7445 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7446 spoolss_EnumPorts, NULL,
7447 *r->out.info, r->in.level,
7448 *r->out.count);
7449 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7450 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7452 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7455 /****************************************************************************
7456 ****************************************************************************/
7458 static WERROR spoolss_addprinterex_level_2(pipes_struct *p,
7459 const char *server,
7460 struct spoolss_SetPrinterInfoCtr *info_ctr,
7461 struct spoolss_DeviceMode *devmode,
7462 struct security_descriptor *sec_desc,
7463 struct spoolss_UserLevelCtr *user_ctr,
7464 POLICY_HND *handle)
7466 NT_PRINTER_INFO_LEVEL *printer = NULL;
7467 fstring name;
7468 int snum;
7469 WERROR err = WERR_OK;
7471 if ( !(printer = TALLOC_ZERO_P(NULL, NT_PRINTER_INFO_LEVEL)) ) {
7472 DEBUG(0,("spoolss_addprinterex_level_2: malloc fail.\n"));
7473 return WERR_NOMEM;
7476 /* convert from UNICODE to ASCII - this allocates the info_2 struct inside *printer.*/
7477 if (!convert_printer_info_new(info_ctr, printer)) {
7478 free_a_printer(&printer, 2);
7479 return WERR_NOMEM;
7482 /* check to see if the printer already exists */
7484 if ((snum = print_queue_snum(printer->info_2->sharename)) != -1) {
7485 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7486 printer->info_2->sharename));
7487 free_a_printer(&printer, 2);
7488 return WERR_PRINTER_ALREADY_EXISTS;
7491 /* FIXME!!! smbd should check to see if the driver is installed before
7492 trying to add a printer like this --jerry */
7494 if (*lp_addprinter_cmd() ) {
7495 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
7496 printer) ) {
7497 free_a_printer(&printer,2);
7498 return WERR_ACCESS_DENIED;
7500 } else {
7501 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
7502 "smb.conf parameter \"addprinter command\" is defined. This"
7503 "parameter must exist for this call to succeed\n",
7504 printer->info_2->sharename ));
7507 /* use our primary netbios name since get_a_printer() will convert
7508 it to what the client expects on a case by case basis */
7510 slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname(),
7511 printer->info_2->sharename);
7514 if ((snum = print_queue_snum(printer->info_2->sharename)) == -1) {
7515 free_a_printer(&printer,2);
7516 return WERR_ACCESS_DENIED;
7519 /* you must be a printer admin to add a new printer */
7520 if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) {
7521 free_a_printer(&printer,2);
7522 return WERR_ACCESS_DENIED;
7526 * Do sanity check on the requested changes for Samba.
7529 if (!check_printer_ok(printer->info_2, snum)) {
7530 free_a_printer(&printer,2);
7531 return WERR_INVALID_PARAM;
7535 * When a printer is created, the drivername bound to the printer is used
7536 * to lookup previously saved driver initialization info, which is then
7537 * bound to the new printer, simulating what happens in the Windows arch.
7540 if (!devmode)
7542 set_driver_init(printer, 2);
7544 else
7546 /* A valid devmode was included, convert and link it
7548 DEBUGADD(10, ("spoolss_addprinterex_level_2: devmode included, converting\n"));
7550 if (!convert_devicemode_new(printer->info_2->printername,
7551 devmode,
7552 &printer->info_2->devmode))
7553 return WERR_NOMEM;
7556 /* write the ASCII on disk */
7557 err = mod_a_printer(printer, 2);
7558 if (!W_ERROR_IS_OK(err)) {
7559 free_a_printer(&printer,2);
7560 return err;
7563 if (!open_printer_hnd(p, handle, name, PRINTER_ACCESS_ADMINISTER)) {
7564 /* Handle open failed - remove addition. */
7565 del_a_printer(printer->info_2->sharename);
7566 free_a_printer(&printer,2);
7567 ZERO_STRUCTP(handle);
7568 return WERR_ACCESS_DENIED;
7571 update_c_setprinter(False);
7572 free_a_printer(&printer,2);
7574 return WERR_OK;
7577 /****************************************************************
7578 _spoolss_AddPrinterEx
7579 ****************************************************************/
7581 WERROR _spoolss_AddPrinterEx(pipes_struct *p,
7582 struct spoolss_AddPrinterEx *r)
7584 switch (r->in.info_ctr->level) {
7585 case 1:
7586 /* we don't handle yet */
7587 /* but I know what to do ... */
7588 return WERR_UNKNOWN_LEVEL;
7589 case 2:
7590 return spoolss_addprinterex_level_2(p, r->in.server,
7591 r->in.info_ctr,
7592 r->in.devmode_ctr->devmode,
7593 r->in.secdesc_ctr->sd,
7594 r->in.userlevel_ctr,
7595 r->out.handle);
7596 default:
7597 return WERR_UNKNOWN_LEVEL;
7601 /****************************************************************
7602 _spoolss_AddPrinterDriver
7603 ****************************************************************/
7605 WERROR _spoolss_AddPrinterDriver(pipes_struct *p,
7606 struct spoolss_AddPrinterDriver *r)
7608 uint32_t level = r->in.info_ctr->level;
7609 struct spoolss_AddDriverInfoCtr *info = r->in.info_ctr;
7610 WERROR err = WERR_OK;
7611 NT_PRINTER_DRIVER_INFO_LEVEL driver;
7612 fstring driver_name;
7613 uint32 version;
7614 const char *fn;
7616 switch (p->hdr_req.opnum) {
7617 case NDR_SPOOLSS_ADDPRINTERDRIVER:
7618 fn = "_spoolss_AddPrinterDriver";
7619 break;
7620 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
7621 fn = "_spoolss_AddPrinterDriverEx";
7622 break;
7623 default:
7624 return WERR_INVALID_PARAM;
7628 /* FIXME */
7629 if (level != 3 && level != 6) {
7630 /* Clever hack from Martin Zielinski <mz@seh.de>
7631 * to allow downgrade from level 8 (Vista).
7633 DEBUG(0,("%s: level %d not yet implemented\n", fn, level));
7634 return WERR_UNKNOWN_LEVEL;
7637 ZERO_STRUCT(driver);
7639 if (!convert_printer_driver_info(info, &driver, level)) {
7640 err = WERR_NOMEM;
7641 goto done;
7644 DEBUG(5,("Cleaning driver's information\n"));
7645 err = clean_up_driver_struct(p, driver, level);
7646 if (!W_ERROR_IS_OK(err))
7647 goto done;
7649 DEBUG(5,("Moving driver to final destination\n"));
7650 if( !W_ERROR_IS_OK(err = move_driver_to_download_area(p, driver, level,
7651 &err)) ) {
7652 goto done;
7655 if (add_a_printer_driver(driver, level)!=0) {
7656 err = WERR_ACCESS_DENIED;
7657 goto done;
7660 switch(level) {
7661 case 3:
7662 fstrcpy(driver_name,
7663 driver.info_3->name ? driver.info_3->name : "");
7664 break;
7665 case 6:
7666 fstrcpy(driver_name,
7667 driver.info_6->name ? driver.info_6->name : "");
7668 break;
7672 * I think this is where he DrvUpgradePrinter() hook would be
7673 * be called in a driver's interface DLL on a Windows NT 4.0/2k
7674 * server. Right now, we just need to send ourselves a message
7675 * to update each printer bound to this driver. --jerry
7678 if (!srv_spoolss_drv_upgrade_printer(driver_name)) {
7679 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
7680 fn, driver_name));
7684 * Based on the version (e.g. driver destination dir: 0=9x,2=Nt/2k,3=2k/Xp),
7685 * decide if the driver init data should be deleted. The rules are:
7686 * 1) never delete init data if it is a 9x driver, they don't use it anyway
7687 * 2) delete init data only if there is no 2k/Xp driver
7688 * 3) always delete init data
7689 * The generalized rule is always use init data from the highest order driver.
7690 * It is necessary to follow the driver install by an initialization step to
7691 * finish off this process.
7693 if (level == 3)
7694 version = driver.info_3->cversion;
7695 else if (level == 6)
7696 version = driver.info_6->version;
7697 else
7698 version = -1;
7699 switch (version) {
7701 * 9x printer driver - never delete init data
7703 case 0:
7704 DEBUG(10,("%s: init data not deleted for 9x driver [%s]\n",
7705 fn, driver_name));
7706 break;
7709 * Nt or 2k (compatiblity mode) printer driver - only delete init data if
7710 * there is no 2k/Xp driver init data for this driver name.
7712 case 2:
7714 NT_PRINTER_DRIVER_INFO_LEVEL driver1;
7716 if (!W_ERROR_IS_OK(get_a_printer_driver(&driver1, 3, driver_name, "Windows NT x86", 3))) {
7718 * No 2k/Xp driver found, delete init data (if any) for the new Nt driver.
7720 if (!del_driver_init(driver_name))
7721 DEBUG(6,("%s: del_driver_init(%s) Nt failed!\n",
7722 fn, driver_name));
7723 } else {
7725 * a 2k/Xp driver was found, don't delete init data because Nt driver will use it.
7727 free_a_printer_driver(driver1,3);
7728 DEBUG(10,("%s: init data not deleted for Nt driver [%s]\n",
7729 fn, driver_name));
7732 break;
7735 * 2k or Xp printer driver - always delete init data
7737 case 3:
7738 if (!del_driver_init(driver_name))
7739 DEBUG(6,("%s: del_driver_init(%s) 2k/Xp failed!\n",
7740 fn, driver_name));
7741 break;
7743 default:
7744 DEBUG(0,("%s: invalid level=%d\n", fn, level));
7745 break;
7749 done:
7750 free_a_printer_driver(driver, level);
7751 return err;
7754 /****************************************************************
7755 _spoolss_AddPrinterDriverEx
7756 ****************************************************************/
7758 WERROR _spoolss_AddPrinterDriverEx(pipes_struct *p,
7759 struct spoolss_AddPrinterDriverEx *r)
7761 struct spoolss_AddPrinterDriver a;
7764 * we only support the semantics of AddPrinterDriver()
7765 * i.e. only copy files that are newer than existing ones
7768 if (r->in.flags != APD_COPY_NEW_FILES) {
7769 return WERR_ACCESS_DENIED;
7772 a.in.servername = r->in.servername;
7773 a.in.info_ctr = r->in.info_ctr;
7775 return _spoolss_AddPrinterDriver(p, &a);
7778 /****************************************************************************
7779 ****************************************************************************/
7781 struct _spoolss_paths {
7782 int type;
7783 const char *share;
7784 const char *dir;
7787 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
7789 static const struct _spoolss_paths spoolss_paths[]= {
7790 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
7791 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
7794 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
7795 const char *servername,
7796 const char *environment,
7797 int component,
7798 char **path)
7800 const char *pservername = NULL;
7801 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
7802 const char *short_archi;
7804 *path = NULL;
7806 /* environment may be empty */
7807 if (environment && strlen(environment)) {
7808 long_archi = environment;
7811 /* servername may be empty */
7812 if (servername && strlen(servername)) {
7813 pservername = canon_servername(servername);
7815 if (!is_myname_or_ipaddr(pservername)) {
7816 return WERR_INVALID_PARAM;
7820 if (!(short_archi = get_short_archi(long_archi))) {
7821 return WERR_INVALID_ENVIRONMENT;
7824 switch (component) {
7825 case SPOOLSS_PRTPROCS_PATH:
7826 case SPOOLSS_DRIVER_PATH:
7827 if (pservername) {
7828 *path = talloc_asprintf(mem_ctx,
7829 "\\\\%s\\%s\\%s",
7830 pservername,
7831 spoolss_paths[component].share,
7832 short_archi);
7833 } else {
7834 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
7835 SPOOLSS_DEFAULT_SERVER_PATH,
7836 spoolss_paths[component].dir,
7837 short_archi);
7839 break;
7840 default:
7841 return WERR_INVALID_PARAM;
7844 if (!*path) {
7845 return WERR_NOMEM;
7848 return WERR_OK;
7851 /****************************************************************************
7852 ****************************************************************************/
7854 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
7855 const char *servername,
7856 const char *environment,
7857 struct spoolss_DriverDirectoryInfo1 *r)
7859 WERROR werr;
7860 char *path = NULL;
7862 werr = compose_spoolss_server_path(mem_ctx,
7863 servername,
7864 environment,
7865 SPOOLSS_DRIVER_PATH,
7866 &path);
7867 if (!W_ERROR_IS_OK(werr)) {
7868 return werr;
7871 DEBUG(4,("printer driver directory: [%s]\n", path));
7873 r->directory_name = path;
7875 return WERR_OK;
7878 /****************************************************************
7879 _spoolss_GetPrinterDriverDirectory
7880 ****************************************************************/
7882 WERROR _spoolss_GetPrinterDriverDirectory(pipes_struct *p,
7883 struct spoolss_GetPrinterDriverDirectory *r)
7885 WERROR werror;
7887 /* that's an [in out] buffer */
7889 if (!r->in.buffer && (r->in.offered != 0)) {
7890 return WERR_INVALID_PARAM;
7893 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
7894 r->in.level));
7896 *r->out.needed = 0;
7898 /* r->in.level is ignored */
7900 werror = getprinterdriverdir_level_1(p->mem_ctx,
7901 r->in.server,
7902 r->in.environment,
7903 &r->out.info->info1);
7904 if (!W_ERROR_IS_OK(werror)) {
7905 TALLOC_FREE(r->out.info);
7906 return werror;
7909 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo, NULL,
7910 r->out.info, r->in.level);
7911 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7913 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7916 /****************************************************************
7917 _spoolss_EnumPrinterData
7918 ****************************************************************/
7920 WERROR _spoolss_EnumPrinterData(pipes_struct *p,
7921 struct spoolss_EnumPrinterData *r)
7923 NT_PRINTER_INFO_LEVEL *printer = NULL;
7924 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7925 int snum;
7926 WERROR result;
7927 REGISTRY_VALUE *val = NULL;
7928 NT_PRINTER_DATA *p_data;
7929 int i, key_index, num_values;
7930 int name_length;
7932 *r->out.value_needed = 0;
7933 *r->out.type = REG_NONE;
7934 *r->out.data_needed = 0;
7936 DEBUG(5,("_spoolss_EnumPrinterData\n"));
7938 if (!Printer) {
7939 DEBUG(2,("_spoolss_EnumPrinterData: Invalid handle (%s:%u:%u).\n",
7940 OUR_HANDLE(r->in.handle)));
7941 return WERR_BADFID;
7944 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7945 return WERR_BADFID;
7948 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
7949 if (!W_ERROR_IS_OK(result)) {
7950 return result;
7953 p_data = printer->info_2->data;
7954 key_index = lookup_printerkey( p_data, SPOOL_PRINTERDATA_KEY );
7956 result = WERR_OK;
7959 * The NT machine wants to know the biggest size of value and data
7961 * cf: MSDN EnumPrinterData remark section
7964 if (!r->in.value_offered && !r->in.data_offered && (key_index != -1)) {
7966 uint32_t biggest_valuesize = 0;
7967 uint32_t biggest_datasize = 0;
7969 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
7971 num_values = regval_ctr_numvals( p_data->keys[key_index].values );
7973 for ( i=0; i<num_values; i++ )
7975 val = regval_ctr_specific_value( p_data->keys[key_index].values, i );
7977 name_length = strlen(val->valuename);
7978 if ( strlen(val->valuename) > biggest_valuesize )
7979 biggest_valuesize = name_length;
7981 if ( val->size > biggest_datasize )
7982 biggest_datasize = val->size;
7984 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
7985 biggest_datasize));
7988 /* the value is an UNICODE string but real_value_size is the length
7989 in bytes including the trailing 0 */
7991 *r->out.value_needed = 2 * (1 + biggest_valuesize);
7992 *r->out.data_needed = biggest_datasize;
7994 DEBUG(6,("final values: [%d], [%d]\n",
7995 *r->out.value_needed, *r->out.data_needed));
7997 goto done;
8001 * the value len is wrong in NT sp3
8002 * that's the number of bytes not the number of unicode chars
8005 if (key_index != -1) {
8006 val = regval_ctr_specific_value(p_data->keys[key_index].values,
8007 r->in.enum_index);
8010 if (!val) {
8012 /* out_value should default to "" or else NT4 has
8013 problems unmarshalling the response */
8015 if (r->in.value_offered) {
8016 *r->out.value_needed = 1;
8017 r->out.value_name = talloc_strdup(r, "");
8018 if (!r->out.value_name) {
8019 result = WERR_NOMEM;
8020 goto done;
8022 } else {
8023 r->out.value_name = NULL;
8024 *r->out.value_needed = 0;
8027 /* the data is counted in bytes */
8029 *r->out.data_needed = r->in.data_offered;
8031 result = WERR_NO_MORE_ITEMS;
8032 } else {
8034 * the value is:
8035 * - counted in bytes in the request
8036 * - counted in UNICODE chars in the max reply
8037 * - counted in bytes in the real size
8039 * take a pause *before* coding not *during* coding
8042 /* name */
8043 if (r->in.value_offered) {
8044 r->out.value_name = talloc_strdup(r, regval_name(val));
8045 if (!r->out.value_name) {
8046 result = WERR_NOMEM;
8047 goto done;
8049 *r->out.value_needed = strlen_m(regval_name(val));
8050 } else {
8051 r->out.value_name = NULL;
8052 *r->out.value_needed = 0;
8055 /* type */
8057 *r->out.type = regval_type(val);
8059 /* data - counted in bytes */
8061 if (r->out.data && regval_size(val)) {
8062 memcpy(r->out.data, regval_data_p(val), regval_size(val));
8065 *r->out.data_needed = regval_size(val);
8068 done:
8069 free_a_printer(&printer, 2);
8070 return result;
8073 /****************************************************************
8074 _spoolss_SetPrinterData
8075 ****************************************************************/
8077 WERROR _spoolss_SetPrinterData(pipes_struct *p,
8078 struct spoolss_SetPrinterData *r)
8080 NT_PRINTER_INFO_LEVEL *printer = NULL;
8081 int snum=0;
8082 WERROR result = WERR_OK;
8083 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8084 DATA_BLOB blob;
8086 DEBUG(5,("_spoolss_SetPrinterData\n"));
8088 if (!Printer) {
8089 DEBUG(2,("_spoolss_SetPrinterData: Invalid handle (%s:%u:%u).\n",
8090 OUR_HANDLE(r->in.handle)));
8091 return WERR_BADFID;
8094 if (Printer->printer_type == SPLHND_SERVER) {
8095 DEBUG(10,("_spoolss_SetPrinterData: "
8096 "Not implemented for server handles yet\n"));
8097 return WERR_INVALID_PARAM;
8100 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8101 return WERR_BADFID;
8105 * Access check : NT returns "access denied" if you make a
8106 * SetPrinterData call without the necessary privildge.
8107 * we were originally returning OK if nothing changed
8108 * which made Win2k issue **a lot** of SetPrinterData
8109 * when connecting to a printer --jerry
8112 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8113 DEBUG(3,("_spoolss_SetPrinterData: "
8114 "change denied by handle access permissions\n"));
8115 result = WERR_ACCESS_DENIED;
8116 goto done;
8119 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8120 if (!W_ERROR_IS_OK(result)) {
8121 return result;
8124 result = push_spoolss_PrinterData(p->mem_ctx, &blob,
8125 r->in.type, &r->in.data);
8126 if (!W_ERROR_IS_OK(result)) {
8127 goto done;
8131 * When client side code sets a magic printer data key, detect it and save
8132 * the current printer data and the magic key's data (its the DEVMODE) for
8133 * future printer/driver initializations.
8135 if ((r->in.type == REG_BINARY) && strequal(r->in.value_name, PHANTOM_DEVMODE_KEY)) {
8136 /* Set devmode and printer initialization info */
8137 result = save_driver_init(printer, 2, blob.data, blob.length);
8139 srv_spoolss_reset_printerdata(printer->info_2->drivername);
8141 goto done;
8144 result = set_printer_dataex(printer, SPOOL_PRINTERDATA_KEY,
8145 r->in.value_name, r->in.type,
8146 blob.data, blob.length);
8147 if (W_ERROR_IS_OK(result)) {
8148 result = mod_a_printer(printer, 2);
8151 done:
8152 free_a_printer(&printer, 2);
8154 return result;
8157 /****************************************************************
8158 _spoolss_ResetPrinter
8159 ****************************************************************/
8161 WERROR _spoolss_ResetPrinter(pipes_struct *p,
8162 struct spoolss_ResetPrinter *r)
8164 POLICY_HND *handle = r->in.handle;
8165 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
8166 int snum;
8168 DEBUG(5,("_spoolss_ResetPrinter\n"));
8171 * All we do is to check to see if the handle and queue is valid.
8172 * This call really doesn't mean anything to us because we only
8173 * support RAW printing. --jerry
8176 if (!Printer) {
8177 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8178 OUR_HANDLE(handle)));
8179 return WERR_BADFID;
8182 if (!get_printer_snum(p,handle, &snum, NULL))
8183 return WERR_BADFID;
8186 /* blindly return success */
8187 return WERR_OK;
8190 /****************************************************************
8191 _spoolss_DeletePrinterData
8192 ****************************************************************/
8194 WERROR _spoolss_DeletePrinterData(pipes_struct *p,
8195 struct spoolss_DeletePrinterData *r)
8197 POLICY_HND *handle = r->in.handle;
8198 NT_PRINTER_INFO_LEVEL *printer = NULL;
8199 int snum=0;
8200 WERROR status = WERR_OK;
8201 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
8203 DEBUG(5,("_spoolss_DeletePrinterData\n"));
8205 if (!Printer) {
8206 DEBUG(2,("_spoolss_DeletePrinterData: Invalid handle (%s:%u:%u).\n",
8207 OUR_HANDLE(handle)));
8208 return WERR_BADFID;
8211 if (!get_printer_snum(p, handle, &snum, NULL))
8212 return WERR_BADFID;
8214 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8215 DEBUG(3, ("_spoolss_DeletePrinterData: "
8216 "printer properties change denied by handle\n"));
8217 return WERR_ACCESS_DENIED;
8220 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8221 if (!W_ERROR_IS_OK(status))
8222 return status;
8224 if (!r->in.value_name) {
8225 free_a_printer(&printer, 2);
8226 return WERR_NOMEM;
8229 status = delete_printer_dataex( printer, SPOOL_PRINTERDATA_KEY,
8230 r->in.value_name );
8232 if ( W_ERROR_IS_OK(status) )
8233 mod_a_printer( printer, 2 );
8235 free_a_printer(&printer, 2);
8237 return status;
8240 /****************************************************************
8241 _spoolss_AddForm
8242 ****************************************************************/
8244 WERROR _spoolss_AddForm(pipes_struct *p,
8245 struct spoolss_AddForm *r)
8247 POLICY_HND *handle = r->in.handle;
8248 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8249 nt_forms_struct tmpForm;
8250 int snum;
8251 WERROR status = WERR_OK;
8252 NT_PRINTER_INFO_LEVEL *printer = NULL;
8254 int count=0;
8255 nt_forms_struct *list=NULL;
8256 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
8258 DEBUG(5,("_spoolss_AddForm\n"));
8260 if (!Printer) {
8261 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8262 OUR_HANDLE(handle)));
8263 return WERR_BADFID;
8267 /* forms can be added on printer of on the print server handle */
8269 if ( Printer->printer_type == SPLHND_PRINTER )
8271 if (!get_printer_snum(p,handle, &snum, NULL))
8272 return WERR_BADFID;
8274 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8275 if (!W_ERROR_IS_OK(status))
8276 goto done;
8279 if ( !(Printer->access_granted & (PRINTER_ACCESS_ADMINISTER|SERVER_ACCESS_ADMINISTER)) ) {
8280 DEBUG(2,("_spoolss_addform: denied by handle permissions.\n"));
8281 status = WERR_ACCESS_DENIED;
8282 goto done;
8285 /* can't add if builtin */
8287 if (get_a_builtin_ntform_by_string(form->form_name, &tmpForm)) {
8288 status = WERR_FILE_EXISTS;
8289 goto done;
8292 count = get_ntforms(&list);
8294 if(!add_a_form(&list, form, &count)) {
8295 status = WERR_NOMEM;
8296 goto done;
8299 write_ntforms(&list, count);
8302 * ChangeID must always be set if this is a printer
8305 if ( Printer->printer_type == SPLHND_PRINTER )
8306 status = mod_a_printer(printer, 2);
8308 done:
8309 if ( printer )
8310 free_a_printer(&printer, 2);
8311 SAFE_FREE(list);
8313 return status;
8316 /****************************************************************
8317 _spoolss_DeleteForm
8318 ****************************************************************/
8320 WERROR _spoolss_DeleteForm(pipes_struct *p,
8321 struct spoolss_DeleteForm *r)
8323 POLICY_HND *handle = r->in.handle;
8324 const char *form_name = r->in.form_name;
8325 nt_forms_struct tmpForm;
8326 int count=0;
8327 nt_forms_struct *list=NULL;
8328 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
8329 int snum;
8330 WERROR status = WERR_OK;
8331 NT_PRINTER_INFO_LEVEL *printer = NULL;
8333 DEBUG(5,("_spoolss_DeleteForm\n"));
8335 if (!Printer) {
8336 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8337 OUR_HANDLE(handle)));
8338 return WERR_BADFID;
8341 /* forms can be deleted on printer of on the print server handle */
8343 if ( Printer->printer_type == SPLHND_PRINTER )
8345 if (!get_printer_snum(p,handle, &snum, NULL))
8346 return WERR_BADFID;
8348 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8349 if (!W_ERROR_IS_OK(status))
8350 goto done;
8353 if ( !(Printer->access_granted & (PRINTER_ACCESS_ADMINISTER|SERVER_ACCESS_ADMINISTER)) ) {
8354 DEBUG(2,("_spoolss_DeleteForm: denied by handle permissions.\n"));
8355 status = WERR_ACCESS_DENIED;
8356 goto done;
8359 /* can't delete if builtin */
8361 if (get_a_builtin_ntform_by_string(form_name,&tmpForm)) {
8362 status = WERR_INVALID_PARAM;
8363 goto done;
8366 count = get_ntforms(&list);
8368 if ( !delete_a_form(&list, form_name, &count, &status ))
8369 goto done;
8372 * ChangeID must always be set if this is a printer
8375 if ( Printer->printer_type == SPLHND_PRINTER )
8376 status = mod_a_printer(printer, 2);
8378 done:
8379 if ( printer )
8380 free_a_printer(&printer, 2);
8381 SAFE_FREE(list);
8383 return status;
8386 /****************************************************************
8387 _spoolss_SetForm
8388 ****************************************************************/
8390 WERROR _spoolss_SetForm(pipes_struct *p,
8391 struct spoolss_SetForm *r)
8393 POLICY_HND *handle = r->in.handle;
8394 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8395 nt_forms_struct tmpForm;
8396 int snum;
8397 WERROR status = WERR_OK;
8398 NT_PRINTER_INFO_LEVEL *printer = NULL;
8400 int count=0;
8401 nt_forms_struct *list=NULL;
8402 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
8404 DEBUG(5,("_spoolss_SetForm\n"));
8406 if (!Printer) {
8407 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8408 OUR_HANDLE(handle)));
8409 return WERR_BADFID;
8412 /* forms can be modified on printer of on the print server handle */
8414 if ( Printer->printer_type == SPLHND_PRINTER )
8416 if (!get_printer_snum(p,handle, &snum, NULL))
8417 return WERR_BADFID;
8419 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8420 if (!W_ERROR_IS_OK(status))
8421 goto done;
8424 if ( !(Printer->access_granted & (PRINTER_ACCESS_ADMINISTER|SERVER_ACCESS_ADMINISTER)) ) {
8425 DEBUG(2,("_spoolss_SetForm: denied by handle permissions\n"));
8426 status = WERR_ACCESS_DENIED;
8427 goto done;
8430 /* can't set if builtin */
8431 if (get_a_builtin_ntform_by_string(form->form_name, &tmpForm)) {
8432 status = WERR_INVALID_PARAM;
8433 goto done;
8436 count = get_ntforms(&list);
8437 update_a_form(&list, form, count);
8438 write_ntforms(&list, count);
8441 * ChangeID must always be set if this is a printer
8444 if ( Printer->printer_type == SPLHND_PRINTER )
8445 status = mod_a_printer(printer, 2);
8448 done:
8449 if ( printer )
8450 free_a_printer(&printer, 2);
8451 SAFE_FREE(list);
8453 return status;
8456 /****************************************************************************
8457 fill_print_processor1
8458 ****************************************************************************/
8460 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8461 struct spoolss_PrintProcessorInfo1 *r,
8462 const char *print_processor_name)
8464 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8465 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8467 return WERR_OK;
8470 /****************************************************************************
8471 enumprintprocessors level 1.
8472 ****************************************************************************/
8474 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8475 union spoolss_PrintProcessorInfo **info_p,
8476 uint32_t *count)
8478 union spoolss_PrintProcessorInfo *info;
8479 WERROR result;
8481 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8482 W_ERROR_HAVE_NO_MEMORY(info);
8484 *count = 1;
8486 result = fill_print_processor1(info, &info[0].info1, "winprint");
8487 if (!W_ERROR_IS_OK(result)) {
8488 goto out;
8491 out:
8492 if (!W_ERROR_IS_OK(result)) {
8493 TALLOC_FREE(info);
8494 *count = 0;
8495 return result;
8498 *info_p = info;
8500 return WERR_OK;
8503 /****************************************************************
8504 _spoolss_EnumPrintProcessors
8505 ****************************************************************/
8507 WERROR _spoolss_EnumPrintProcessors(pipes_struct *p,
8508 struct spoolss_EnumPrintProcessors *r)
8510 WERROR result;
8512 /* that's an [in out] buffer */
8514 if (!r->in.buffer && (r->in.offered != 0)) {
8515 return WERR_INVALID_PARAM;
8518 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8521 * Enumerate the print processors ...
8523 * Just reply with "winprint", to keep NT happy
8524 * and I can use my nice printer checker.
8527 *r->out.count = 0;
8528 *r->out.needed = 0;
8529 *r->out.info = NULL;
8531 switch (r->in.level) {
8532 case 1:
8533 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8534 r->out.count);
8535 break;
8536 default:
8537 return WERR_UNKNOWN_LEVEL;
8540 if (!W_ERROR_IS_OK(result)) {
8541 return result;
8544 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8545 spoolss_EnumPrintProcessors, NULL,
8546 *r->out.info, r->in.level,
8547 *r->out.count);
8548 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8549 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8551 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8554 /****************************************************************************
8555 fill_printprocdatatype1
8556 ****************************************************************************/
8558 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8559 struct spoolss_PrintProcDataTypesInfo1 *r,
8560 const char *name_array)
8562 r->name_array = talloc_strdup(mem_ctx, name_array);
8563 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8565 return WERR_OK;
8568 /****************************************************************************
8569 enumprintprocdatatypes level 1.
8570 ****************************************************************************/
8572 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8573 union spoolss_PrintProcDataTypesInfo **info_p,
8574 uint32_t *count)
8576 WERROR result;
8577 union spoolss_PrintProcDataTypesInfo *info;
8579 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8580 W_ERROR_HAVE_NO_MEMORY(info);
8582 *count = 1;
8584 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
8585 if (!W_ERROR_IS_OK(result)) {
8586 goto out;
8589 out:
8590 if (!W_ERROR_IS_OK(result)) {
8591 TALLOC_FREE(info);
8592 *count = 0;
8593 return result;
8596 *info_p = info;
8598 return WERR_OK;
8601 /****************************************************************
8602 _spoolss_EnumPrintProcDataTypes
8603 ****************************************************************/
8605 WERROR _spoolss_EnumPrintProcDataTypes(pipes_struct *p,
8606 struct spoolss_EnumPrintProcDataTypes *r)
8608 WERROR result;
8610 /* that's an [in out] buffer */
8612 if (!r->in.buffer && (r->in.offered != 0)) {
8613 return WERR_INVALID_PARAM;
8616 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8618 *r->out.count = 0;
8619 *r->out.needed = 0;
8620 *r->out.info = NULL;
8622 switch (r->in.level) {
8623 case 1:
8624 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
8625 r->out.count);
8626 break;
8627 default:
8628 return WERR_UNKNOWN_LEVEL;
8631 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8632 spoolss_EnumPrintProcDataTypes, NULL,
8633 *r->out.info, r->in.level,
8634 *r->out.count);
8635 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8636 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8638 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8641 /****************************************************************************
8642 fill_monitor_1
8643 ****************************************************************************/
8645 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
8646 struct spoolss_MonitorInfo1 *r,
8647 const char *monitor_name)
8649 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8650 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8652 return WERR_OK;
8655 /****************************************************************************
8656 fill_monitor_2
8657 ****************************************************************************/
8659 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
8660 struct spoolss_MonitorInfo2 *r,
8661 const char *monitor_name,
8662 const char *environment,
8663 const char *dll_name)
8665 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8666 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8667 r->environment = talloc_strdup(mem_ctx, environment);
8668 W_ERROR_HAVE_NO_MEMORY(r->environment);
8669 r->dll_name = talloc_strdup(mem_ctx, dll_name);
8670 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
8672 return WERR_OK;
8675 /****************************************************************************
8676 enumprintmonitors level 1.
8677 ****************************************************************************/
8679 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
8680 union spoolss_MonitorInfo **info_p,
8681 uint32_t *count)
8683 union spoolss_MonitorInfo *info;
8684 WERROR result = WERR_OK;
8686 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8687 W_ERROR_HAVE_NO_MEMORY(info);
8689 *count = 2;
8691 result = fill_monitor_1(info, &info[0].info1,
8692 SPL_LOCAL_PORT /* FIXME */);
8693 if (!W_ERROR_IS_OK(result)) {
8694 goto out;
8697 result = fill_monitor_1(info, &info[1].info1,
8698 SPL_TCPIP_PORT /* FIXME */);
8699 if (!W_ERROR_IS_OK(result)) {
8700 goto out;
8703 out:
8704 if (!W_ERROR_IS_OK(result)) {
8705 TALLOC_FREE(info);
8706 *count = 0;
8707 return result;
8710 *info_p = info;
8712 return WERR_OK;
8715 /****************************************************************************
8716 enumprintmonitors level 2.
8717 ****************************************************************************/
8719 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
8720 union spoolss_MonitorInfo **info_p,
8721 uint32_t *count)
8723 union spoolss_MonitorInfo *info;
8724 WERROR result = WERR_OK;
8726 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8727 W_ERROR_HAVE_NO_MEMORY(info);
8729 *count = 2;
8731 result = fill_monitor_2(info, &info[0].info2,
8732 SPL_LOCAL_PORT, /* FIXME */
8733 "Windows NT X86", /* FIXME */
8734 "localmon.dll");
8735 if (!W_ERROR_IS_OK(result)) {
8736 goto out;
8739 result = fill_monitor_2(info, &info[1].info2,
8740 SPL_TCPIP_PORT, /* FIXME */
8741 "Windows NT X86", /* FIXME */
8742 "tcpmon.dll");
8743 if (!W_ERROR_IS_OK(result)) {
8744 goto out;
8747 out:
8748 if (!W_ERROR_IS_OK(result)) {
8749 TALLOC_FREE(info);
8750 *count = 0;
8751 return result;
8754 *info_p = info;
8756 return WERR_OK;
8759 /****************************************************************
8760 _spoolss_EnumMonitors
8761 ****************************************************************/
8763 WERROR _spoolss_EnumMonitors(pipes_struct *p,
8764 struct spoolss_EnumMonitors *r)
8766 WERROR result;
8768 /* that's an [in out] buffer */
8770 if (!r->in.buffer && (r->in.offered != 0)) {
8771 return WERR_INVALID_PARAM;
8774 DEBUG(5,("_spoolss_EnumMonitors\n"));
8777 * Enumerate the print monitors ...
8779 * Just reply with "Local Port", to keep NT happy
8780 * and I can use my nice printer checker.
8783 *r->out.count = 0;
8784 *r->out.needed = 0;
8785 *r->out.info = NULL;
8787 switch (r->in.level) {
8788 case 1:
8789 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
8790 r->out.count);
8791 break;
8792 case 2:
8793 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
8794 r->out.count);
8795 break;
8796 default:
8797 return WERR_UNKNOWN_LEVEL;
8800 if (!W_ERROR_IS_OK(result)) {
8801 return result;
8804 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8805 spoolss_EnumMonitors, NULL,
8806 *r->out.info, r->in.level,
8807 *r->out.count);
8808 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8809 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8811 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8814 /****************************************************************************
8815 ****************************************************************************/
8817 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
8818 const print_queue_struct *queue,
8819 int count, int snum,
8820 const NT_PRINTER_INFO_LEVEL *ntprinter,
8821 uint32_t jobid,
8822 struct spoolss_JobInfo1 *r)
8824 int i = 0;
8825 bool found = false;
8827 for (i=0; i<count && found == false; i++) {
8828 if (queue[i].job == (int)jobid) {
8829 found = true;
8833 if (found == false) {
8834 /* NT treats not found as bad param... yet another bad choice */
8835 return WERR_INVALID_PARAM;
8838 return fill_job_info1(mem_ctx,
8840 &queue[i-1],
8842 snum,
8843 ntprinter);
8846 /****************************************************************************
8847 ****************************************************************************/
8849 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
8850 const print_queue_struct *queue,
8851 int count, int snum,
8852 const NT_PRINTER_INFO_LEVEL *ntprinter,
8853 uint32_t jobid,
8854 struct spoolss_JobInfo2 *r)
8856 int i = 0;
8857 bool found = false;
8858 struct spoolss_DeviceMode *devmode;
8859 NT_DEVICEMODE *nt_devmode;
8860 WERROR result;
8862 for (i=0; i<count && found == false; i++) {
8863 if (queue[i].job == (int)jobid) {
8864 found = true;
8868 if (found == false) {
8869 /* NT treats not found as bad param... yet another bad
8870 choice */
8871 return WERR_INVALID_PARAM;
8875 * if the print job does not have a DEVMODE associated with it,
8876 * just use the one for the printer. A NULL devicemode is not
8877 * a failure condition
8880 nt_devmode = print_job_devmode(lp_const_servicename(snum), jobid);
8881 if (nt_devmode) {
8882 devmode = TALLOC_ZERO_P(mem_ctx, struct spoolss_DeviceMode);
8883 W_ERROR_HAVE_NO_MEMORY(devmode);
8884 result = convert_nt_devicemode_new(devmode, devmode, nt_devmode);
8885 if (!W_ERROR_IS_OK(result)) {
8886 return result;
8888 } else {
8889 devmode = construct_dev_mode_new(mem_ctx, lp_const_servicename(snum));
8890 W_ERROR_HAVE_NO_MEMORY(devmode);
8893 return fill_job_info2(mem_ctx,
8895 &queue[i-1],
8897 snum,
8898 ntprinter,
8899 devmode);
8902 /****************************************************************
8903 _spoolss_GetJob
8904 ****************************************************************/
8906 WERROR _spoolss_GetJob(pipes_struct *p,
8907 struct spoolss_GetJob *r)
8909 WERROR result = WERR_OK;
8910 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
8911 int snum;
8912 int count;
8913 print_queue_struct *queue = NULL;
8914 print_status_struct prt_status;
8916 /* that's an [in out] buffer */
8918 if (!r->in.buffer && (r->in.offered != 0)) {
8919 return WERR_INVALID_PARAM;
8922 DEBUG(5,("_spoolss_GetJob\n"));
8924 *r->out.needed = 0;
8926 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8927 return WERR_BADFID;
8930 result = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum));
8931 if (!W_ERROR_IS_OK(result)) {
8932 return result;
8935 count = print_queue_status(snum, &queue, &prt_status);
8937 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
8938 count, prt_status.status, prt_status.message));
8940 switch (r->in.level) {
8941 case 1:
8942 result = getjob_level_1(p->mem_ctx,
8943 queue, count, snum, ntprinter,
8944 r->in.job_id, &r->out.info->info1);
8945 break;
8946 case 2:
8947 result = getjob_level_2(p->mem_ctx,
8948 queue, count, snum, ntprinter,
8949 r->in.job_id, &r->out.info->info2);
8950 break;
8951 default:
8952 result = WERR_UNKNOWN_LEVEL;
8953 break;
8956 SAFE_FREE(queue);
8957 free_a_printer(&ntprinter, 2);
8959 if (!W_ERROR_IS_OK(result)) {
8960 TALLOC_FREE(r->out.info);
8961 return result;
8964 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, NULL,
8965 r->out.info, r->in.level);
8966 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8968 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8971 /****************************************************************
8972 _spoolss_GetPrinterDataEx
8974 From MSDN documentation of GetPrinterDataEx: pass request
8975 to GetPrinterData if key is "PrinterDriverData".
8976 ****************************************************************/
8978 WERROR _spoolss_GetPrinterDataEx(pipes_struct *p,
8979 struct spoolss_GetPrinterDataEx *r)
8982 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8983 REGISTRY_VALUE *val = NULL;
8984 NT_PRINTER_INFO_LEVEL *printer = NULL;
8985 int snum = 0;
8986 WERROR result = WERR_OK;
8988 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
8990 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
8991 r->in.key_name, r->in.value_name));
8993 /* in case of problem, return some default values */
8995 *r->out.needed = 0;
8996 *r->out.type = REG_NONE;
8998 if (!Printer) {
8999 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9000 OUR_HANDLE(r->in.handle)));
9001 result = WERR_BADFID;
9002 goto done;
9005 /* Is the handle to a printer or to the server? */
9007 if (Printer->printer_type == SPLHND_SERVER) {
9008 DEBUG(10,("_spoolss_GetPrinterDataEx: "
9009 "Not implemented for server handles yet\n"));
9010 result = WERR_INVALID_PARAM;
9011 goto done;
9014 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9015 return WERR_BADFID;
9018 result = get_a_printer(Printer, &printer, 2, lp_servicename(snum));
9019 if (!W_ERROR_IS_OK(result)) {
9020 goto done;
9023 /* check to see if the keyname is valid */
9024 if (!strlen(r->in.key_name)) {
9025 result = WERR_INVALID_PARAM;
9026 goto done;
9029 if (lookup_printerkey(printer->info_2->data, r->in.key_name) == -1) {
9030 DEBUG(4,("_spoolss_GetPrinterDataEx: "
9031 "Invalid keyname [%s]\n", r->in.key_name ));
9032 result = WERR_BADFILE;
9033 goto done;
9036 /* When given a new keyname, we should just create it */
9038 val = get_printer_data(printer->info_2,
9039 r->in.key_name, r->in.value_name);
9040 if (!val) {
9041 result = WERR_BADFILE;
9042 goto done;
9045 *r->out.needed = regval_size(val);
9047 if (*r->out.needed > r->in.offered) {
9048 result = WERR_MORE_DATA;
9049 goto done;
9052 *r->out.type = regval_type(val);
9054 memcpy(r->out.buffer, regval_data_p(val), regval_size(val));
9056 done:
9057 if (printer) {
9058 free_a_printer(&printer, 2);
9061 return result;
9064 /****************************************************************
9065 _spoolss_SetPrinterDataEx
9066 ****************************************************************/
9068 WERROR _spoolss_SetPrinterDataEx(pipes_struct *p,
9069 struct spoolss_SetPrinterDataEx *r)
9071 NT_PRINTER_INFO_LEVEL *printer = NULL;
9072 int snum = 0;
9073 WERROR result = WERR_OK;
9074 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9075 char *oid_string;
9077 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
9079 /* From MSDN documentation of SetPrinterDataEx: pass request to
9080 SetPrinterData if key is "PrinterDriverData" */
9082 if (!Printer) {
9083 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9084 OUR_HANDLE(r->in.handle)));
9085 return WERR_BADFID;
9088 if (Printer->printer_type == SPLHND_SERVER) {
9089 DEBUG(10,("_spoolss_SetPrinterDataEx: "
9090 "Not implemented for server handles yet\n"));
9091 return WERR_INVALID_PARAM;
9094 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9095 return WERR_BADFID;
9099 * Access check : NT returns "access denied" if you make a
9100 * SetPrinterData call without the necessary privildge.
9101 * we were originally returning OK if nothing changed
9102 * which made Win2k issue **a lot** of SetPrinterData
9103 * when connecting to a printer --jerry
9106 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9107 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
9108 "change denied by handle access permissions\n"));
9109 return WERR_ACCESS_DENIED;
9112 result = get_a_printer(Printer, &printer, 2, lp_servicename(snum));
9113 if (!W_ERROR_IS_OK(result)) {
9114 return result;
9117 /* check for OID in valuename */
9119 oid_string = strchr(r->in.value_name, ',');
9120 if (oid_string) {
9121 *oid_string = '\0';
9122 oid_string++;
9125 /* save the registry data */
9127 result = set_printer_dataex(printer, r->in.key_name, r->in.value_name,
9128 r->in.type, r->in.buffer, r->in.offered);
9130 if (W_ERROR_IS_OK(result)) {
9131 /* save the OID if one was specified */
9132 if (oid_string) {
9133 char *str = talloc_asprintf(p->mem_ctx, "%s\\%s",
9134 r->in.key_name, SPOOL_OID_KEY);
9135 if (!str) {
9136 result = WERR_NOMEM;
9137 goto done;
9141 * I'm not checking the status here on purpose. Don't know
9142 * if this is right, but I'm returning the status from the
9143 * previous set_printer_dataex() call. I have no idea if
9144 * this is right. --jerry
9147 set_printer_dataex(printer, str, r->in.value_name,
9148 REG_SZ, (uint8_t *)oid_string,
9149 strlen(oid_string)+1);
9152 result = mod_a_printer(printer, 2);
9155 done:
9156 free_a_printer(&printer, 2);
9158 return result;
9161 /****************************************************************
9162 _spoolss_DeletePrinterDataEx
9163 ****************************************************************/
9165 WERROR _spoolss_DeletePrinterDataEx(pipes_struct *p,
9166 struct spoolss_DeletePrinterDataEx *r)
9168 POLICY_HND *handle = r->in.handle;
9169 NT_PRINTER_INFO_LEVEL *printer = NULL;
9170 int snum=0;
9171 WERROR status = WERR_OK;
9172 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
9174 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9176 if (!Printer) {
9177 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9178 "Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
9179 return WERR_BADFID;
9182 if (!get_printer_snum(p, handle, &snum, NULL))
9183 return WERR_BADFID;
9185 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9186 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9187 "printer properties change denied by handle\n"));
9188 return WERR_ACCESS_DENIED;
9191 if (!r->in.value_name || !r->in.key_name) {
9192 return WERR_NOMEM;
9195 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9196 if (!W_ERROR_IS_OK(status))
9197 return status;
9199 status = delete_printer_dataex( printer, r->in.key_name, r->in.value_name );
9201 if ( W_ERROR_IS_OK(status) )
9202 mod_a_printer( printer, 2 );
9204 free_a_printer(&printer, 2);
9206 return status;
9209 /********************************************************************
9210 * spoolss_enumprinterkey
9211 ********************************************************************/
9214 WERROR _spoolss_enumprinterkey(pipes_struct *p, SPOOL_Q_ENUMPRINTERKEY *q_u, SPOOL_R_ENUMPRINTERKEY *r_u)
9216 fstring key;
9217 fstring *keynames = NULL;
9218 uint16 *enumkeys = NULL;
9219 int num_keys;
9220 int printerkey_len;
9221 POLICY_HND *handle = &q_u->handle;
9222 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
9223 NT_PRINTER_DATA *data;
9224 NT_PRINTER_INFO_LEVEL *printer = NULL;
9225 int snum = 0;
9226 WERROR status = WERR_BADFILE;
9229 DEBUG(4,("_spoolss_enumprinterkey\n"));
9231 if (!Printer) {
9232 DEBUG(2,("_spoolss_enumprinterkey: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
9233 return WERR_BADFID;
9236 if ( !get_printer_snum(p,handle, &snum, NULL) )
9237 return WERR_BADFID;
9239 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9240 if (!W_ERROR_IS_OK(status))
9241 return status;
9243 /* get the list of subkey names */
9245 unistr2_to_ascii(key, &q_u->key, sizeof(key));
9246 data = printer->info_2->data;
9248 num_keys = get_printer_subkeys( data, key, &keynames );
9250 if ( num_keys == -1 ) {
9251 status = WERR_BADFILE;
9252 goto done;
9255 printerkey_len = init_unistr_array( &enumkeys, keynames, NULL );
9257 r_u->needed = printerkey_len*2;
9259 if ( q_u->size < r_u->needed ) {
9260 status = WERR_MORE_DATA;
9261 goto done;
9264 if (!make_spoolss_buffer5(p->mem_ctx, &r_u->keys, printerkey_len, enumkeys)) {
9265 status = WERR_NOMEM;
9266 goto done;
9269 status = WERR_OK;
9271 if ( q_u->size < r_u->needed )
9272 status = WERR_MORE_DATA;
9274 done:
9275 free_a_printer( &printer, 2 );
9276 SAFE_FREE( keynames );
9278 return status;
9281 /****************************************************************
9282 _spoolss_DeletePrinterKey
9283 ****************************************************************/
9285 WERROR _spoolss_DeletePrinterKey(pipes_struct *p,
9286 struct spoolss_DeletePrinterKey *r)
9288 POLICY_HND *handle = r->in.handle;
9289 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
9290 NT_PRINTER_INFO_LEVEL *printer = NULL;
9291 int snum=0;
9292 WERROR status;
9294 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9296 if (!Printer) {
9297 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9298 OUR_HANDLE(handle)));
9299 return WERR_BADFID;
9302 /* if keyname == NULL, return error */
9304 if ( !r->in.key_name )
9305 return WERR_INVALID_PARAM;
9307 if (!get_printer_snum(p, handle, &snum, NULL))
9308 return WERR_BADFID;
9310 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9311 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9312 "printer properties change denied by handle\n"));
9313 return WERR_ACCESS_DENIED;
9316 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9317 if (!W_ERROR_IS_OK(status))
9318 return status;
9320 /* delete the key and all subneys */
9322 status = delete_all_printer_data( printer->info_2, r->in.key_name );
9324 if ( W_ERROR_IS_OK(status) )
9325 status = mod_a_printer(printer, 2);
9327 free_a_printer( &printer, 2 );
9329 return status;
9333 /********************************************************************
9334 * spoolss_enumprinterdataex
9335 ********************************************************************/
9337 WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_u, SPOOL_R_ENUMPRINTERDATAEX *r_u)
9339 POLICY_HND *handle = &q_u->handle;
9340 uint32 in_size = q_u->size;
9341 uint32 num_entries,
9342 needed;
9343 NT_PRINTER_INFO_LEVEL *printer = NULL;
9344 PRINTER_ENUM_VALUES *enum_values = NULL;
9345 NT_PRINTER_DATA *p_data;
9346 fstring key;
9347 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
9348 int snum;
9349 WERROR result;
9350 int key_index;
9351 int i;
9352 REGISTRY_VALUE *val;
9353 char *value_name;
9354 uint32 data_len;
9357 DEBUG(4,("_spoolss_enumprinterdataex\n"));
9359 if (!Printer) {
9360 DEBUG(2,("_spoolss_enumprinterdataex: Invalid handle (%s:%u:%u1<).\n", OUR_HANDLE(handle)));
9361 return WERR_BADFID;
9365 * first check for a keyname of NULL or "". Win2k seems to send
9366 * this a lot and we should send back WERR_INVALID_PARAM
9367 * no need to spend time looking up the printer in this case.
9368 * --jerry
9371 unistr2_to_ascii(key, &q_u->key, sizeof(key));
9372 if ( !strlen(key) ) {
9373 result = WERR_INVALID_PARAM;
9374 goto done;
9377 /* get the printer off of disk */
9379 if (!get_printer_snum(p,handle, &snum, NULL))
9380 return WERR_BADFID;
9382 ZERO_STRUCT(printer);
9383 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9384 if (!W_ERROR_IS_OK(result))
9385 return result;
9387 /* now look for a match on the key name */
9389 p_data = printer->info_2->data;
9391 unistr2_to_ascii(key, &q_u->key, sizeof(key));
9392 if ( (key_index = lookup_printerkey( p_data, key)) == -1 )
9394 DEBUG(10,("_spoolss_enumprinterdataex: Unknown keyname [%s]\n", key));
9395 result = WERR_INVALID_PARAM;
9396 goto done;
9399 result = WERR_OK;
9400 needed = 0;
9402 /* allocate the memory for the array of pointers -- if necessary */
9404 num_entries = regval_ctr_numvals( p_data->keys[key_index].values );
9405 if ( num_entries )
9407 if ( (enum_values=TALLOC_ARRAY(p->mem_ctx, PRINTER_ENUM_VALUES, num_entries)) == NULL )
9409 DEBUG(0,("_spoolss_enumprinterdataex: talloc() failed to allocate memory for [%lu] bytes!\n",
9410 (unsigned long)num_entries*sizeof(PRINTER_ENUM_VALUES)));
9411 result = WERR_NOMEM;
9412 goto done;
9415 memset( enum_values, 0x0, num_entries*sizeof(PRINTER_ENUM_VALUES) );
9419 * loop through all params and build the array to pass
9420 * back to the client
9423 for ( i=0; i<num_entries; i++ )
9425 /* lookup the registry value */
9427 val = regval_ctr_specific_value( p_data->keys[key_index].values, i );
9428 DEBUG(10,("retrieved value number [%d] [%s]\n", i, regval_name(val) ));
9430 /* copy the data */
9432 value_name = regval_name( val );
9433 init_unistr( &enum_values[i].valuename, value_name );
9434 enum_values[i].value_len = (strlen(value_name)+1) * 2;
9435 enum_values[i].type = regval_type( val );
9437 data_len = regval_size( val );
9438 if ( data_len ) {
9439 if ( !(enum_values[i].data = (uint8 *)TALLOC_MEMDUP(p->mem_ctx, regval_data_p(val), data_len)) )
9441 DEBUG(0,("TALLOC_MEMDUP failed to allocate memory [data_len=%d] for data!\n",
9442 data_len ));
9443 result = WERR_NOMEM;
9444 goto done;
9447 enum_values[i].data_len = data_len;
9449 /* keep track of the size of the array in bytes */
9451 needed += spoolss_size_printer_enum_values(&enum_values[i]);
9454 /* housekeeping information in the reply */
9456 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9457 * the hand marshalled container size is a multiple
9458 * of 4 bytes for RPC alignment.
9461 if (needed % 4) {
9462 needed += 4-(needed % 4);
9465 r_u->needed = needed;
9466 r_u->returned = num_entries;
9468 if (needed > in_size) {
9469 result = WERR_MORE_DATA;
9470 goto done;
9473 /* copy data into the reply */
9475 /* mz: Vista x64 returns 0x6f7 (The stub received bad data), if the
9476 response buffer size is != the offered buffer size
9478 r_u->ctr.size = r_u->needed;
9480 r_u->ctr.size = in_size;
9482 r_u->ctr.size_of_array = r_u->returned;
9483 r_u->ctr.values = enum_values;
9485 done:
9486 if ( printer )
9487 free_a_printer(&printer, 2);
9489 return result;
9492 /****************************************************************************
9493 ****************************************************************************/
9495 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
9496 const char *servername,
9497 const char *environment,
9498 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9500 WERROR werr;
9501 char *path = NULL;
9503 werr = compose_spoolss_server_path(mem_ctx,
9504 servername,
9505 environment,
9506 SPOOLSS_PRTPROCS_PATH,
9507 &path);
9508 if (!W_ERROR_IS_OK(werr)) {
9509 return werr;
9512 DEBUG(4,("print processor directory: [%s]\n", path));
9514 r->directory_name = path;
9516 return WERR_OK;
9519 /****************************************************************
9520 _spoolss_GetPrintProcessorDirectory
9521 ****************************************************************/
9523 WERROR _spoolss_GetPrintProcessorDirectory(pipes_struct *p,
9524 struct spoolss_GetPrintProcessorDirectory *r)
9526 WERROR result;
9528 /* that's an [in out] buffer */
9530 if (!r->in.buffer && (r->in.offered != 0)) {
9531 return WERR_INVALID_PARAM;
9534 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9535 r->in.level));
9537 *r->out.needed = 0;
9539 /* r->in.level is ignored */
9541 result = getprintprocessordirectory_level_1(p->mem_ctx,
9542 r->in.server,
9543 r->in.environment,
9544 &r->out.info->info1);
9545 if (!W_ERROR_IS_OK(result)) {
9546 TALLOC_FREE(r->out.info);
9547 return result;
9550 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo, NULL,
9551 r->out.info, r->in.level);
9552 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9554 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9557 /*******************************************************************
9558 ********************************************************************/
9560 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
9561 const char *dllname)
9563 enum ndr_err_code ndr_err;
9564 struct spoolss_MonitorUi ui;
9566 ui.dll_name = dllname;
9568 ndr_err = ndr_push_struct_blob(buf, mem_ctx, NULL, &ui,
9569 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
9570 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9571 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
9573 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9576 /*******************************************************************
9577 Streams the monitor UI DLL name in UNICODE
9578 *******************************************************************/
9580 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
9581 NT_USER_TOKEN *token, DATA_BLOB *in,
9582 DATA_BLOB *out, uint32_t *needed)
9584 const char *dllname = "tcpmonui.dll";
9586 *needed = (strlen(dllname)+1) * 2;
9588 if (out->length < *needed) {
9589 return WERR_INSUFFICIENT_BUFFER;
9592 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9593 return WERR_NOMEM;
9596 return WERR_OK;
9599 /*******************************************************************
9600 ********************************************************************/
9602 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
9603 struct spoolss_PortData1 *port1,
9604 const DATA_BLOB *buf)
9606 enum ndr_err_code ndr_err;
9607 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, NULL, port1,
9608 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
9609 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9610 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
9612 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9615 /*******************************************************************
9616 ********************************************************************/
9618 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
9619 struct spoolss_PortData2 *port2,
9620 const DATA_BLOB *buf)
9622 enum ndr_err_code ndr_err;
9623 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, NULL, port2,
9624 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
9625 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9626 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
9628 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9631 /*******************************************************************
9632 Create a new TCP/IP port
9633 *******************************************************************/
9635 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
9636 NT_USER_TOKEN *token, DATA_BLOB *in,
9637 DATA_BLOB *out, uint32_t *needed)
9639 struct spoolss_PortData1 port1;
9640 struct spoolss_PortData2 port2;
9641 char *device_uri = NULL;
9642 uint32_t version;
9644 const char *portname;
9645 const char *hostaddress;
9646 const char *queue;
9647 uint32_t port_number;
9648 uint32_t protocol;
9650 /* peek for spoolss_PortData version */
9652 if (!in || (in->length < (128 + 4))) {
9653 return WERR_GENERAL_FAILURE;
9656 version = IVAL(in->data, 128);
9658 switch (version) {
9659 case 1:
9660 ZERO_STRUCT(port1);
9662 if (!pull_port_data_1(mem_ctx, &port1, in)) {
9663 return WERR_NOMEM;
9666 portname = port1.portname;
9667 hostaddress = port1.hostaddress;
9668 queue = port1.queue;
9669 protocol = port1.protocol;
9670 port_number = port1.port_number;
9672 break;
9673 case 2:
9674 ZERO_STRUCT(port2);
9676 if (!pull_port_data_2(mem_ctx, &port2, in)) {
9677 return WERR_NOMEM;
9680 portname = port2.portname;
9681 hostaddress = port2.hostaddress;
9682 queue = port2.queue;
9683 protocol = port2.protocol;
9684 port_number = port2.port_number;
9686 break;
9687 default:
9688 DEBUG(1,("xcvtcp_addport: "
9689 "unknown version of port_data: %d\n", version));
9690 return WERR_UNKNOWN_PORT;
9693 /* create the device URI and call the add_port_hook() */
9695 switch (protocol) {
9696 case PROTOCOL_RAWTCP_TYPE:
9697 device_uri = talloc_asprintf(mem_ctx,
9698 "socket://%s:%d/", hostaddress,
9699 port_number);
9700 break;
9702 case PROTOCOL_LPR_TYPE:
9703 device_uri = talloc_asprintf(mem_ctx,
9704 "lpr://%s/%s", hostaddress, queue );
9705 break;
9707 default:
9708 return WERR_UNKNOWN_PORT;
9711 if (!device_uri) {
9712 return WERR_NOMEM;
9715 return add_port_hook(mem_ctx, token, portname, device_uri);
9718 /*******************************************************************
9719 *******************************************************************/
9721 struct xcv_api_table xcvtcp_cmds[] = {
9722 { "MonitorUI", xcvtcp_monitorui },
9723 { "AddPort", xcvtcp_addport},
9724 { NULL, NULL }
9727 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
9728 NT_USER_TOKEN *token, const char *command,
9729 DATA_BLOB *inbuf,
9730 DATA_BLOB *outbuf,
9731 uint32_t *needed )
9733 int i;
9735 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
9737 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
9738 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
9739 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9742 return WERR_BADFUNC;
9745 /*******************************************************************
9746 *******************************************************************/
9747 #if 0 /* don't support management using the "Local Port" monitor */
9749 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
9750 NT_USER_TOKEN *token, DATA_BLOB *in,
9751 DATA_BLOB *out, uint32_t *needed)
9753 const char *dllname = "localui.dll";
9755 *needed = (strlen(dllname)+1) * 2;
9757 if (out->length < *needed) {
9758 return WERR_INSUFFICIENT_BUFFER;
9761 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9762 return WERR_NOMEM;
9765 return WERR_OK;
9768 /*******************************************************************
9769 *******************************************************************/
9771 struct xcv_api_table xcvlocal_cmds[] = {
9772 { "MonitorUI", xcvlocal_monitorui },
9773 { NULL, NULL }
9775 #else
9776 struct xcv_api_table xcvlocal_cmds[] = {
9777 { NULL, NULL }
9779 #endif
9783 /*******************************************************************
9784 *******************************************************************/
9786 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
9787 NT_USER_TOKEN *token, const char *command,
9788 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
9789 uint32_t *needed)
9791 int i;
9793 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
9795 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
9796 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
9797 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9799 return WERR_BADFUNC;
9802 /****************************************************************
9803 _spoolss_XcvData
9804 ****************************************************************/
9806 WERROR _spoolss_XcvData(pipes_struct *p,
9807 struct spoolss_XcvData *r)
9809 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9810 DATA_BLOB out_data = data_blob_null;
9811 WERROR werror;
9813 if (!Printer) {
9814 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
9815 OUR_HANDLE(r->in.handle)));
9816 return WERR_BADFID;
9819 /* Has to be a handle to the TCP/IP port monitor */
9821 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
9822 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
9823 return WERR_BADFID;
9826 /* requires administrative access to the server */
9828 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
9829 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
9830 return WERR_ACCESS_DENIED;
9833 /* Allocate the outgoing buffer */
9835 if (r->in.out_data_size) {
9836 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
9837 if (out_data.data == NULL) {
9838 return WERR_NOMEM;
9842 switch ( Printer->printer_type ) {
9843 case SPLHND_PORTMON_TCP:
9844 werror = process_xcvtcp_command(p->mem_ctx,
9845 p->server_info->ptok,
9846 r->in.function_name,
9847 &r->in.in_data, &out_data,
9848 r->out.needed);
9849 break;
9850 case SPLHND_PORTMON_LOCAL:
9851 werror = process_xcvlocal_command(p->mem_ctx,
9852 p->server_info->ptok,
9853 r->in.function_name,
9854 &r->in.in_data, &out_data,
9855 r->out.needed);
9856 break;
9857 default:
9858 werror = WERR_INVALID_PRINT_MONITOR;
9861 if (!W_ERROR_IS_OK(werror)) {
9862 return werror;
9865 *r->out.status_code = 0;
9867 memcpy(r->out.out_data, out_data.data, out_data.length);
9869 return WERR_OK;
9872 /****************************************************************
9873 _spoolss_AddPrintProcessor
9874 ****************************************************************/
9876 WERROR _spoolss_AddPrintProcessor(pipes_struct *p,
9877 struct spoolss_AddPrintProcessor *r)
9879 /* for now, just indicate success and ignore the add. We'll
9880 automatically set the winprint processor for printer
9881 entries later. Used to debug the LexMark Optra S 1855 PCL
9882 driver --jerry */
9884 return WERR_OK;
9887 /****************************************************************
9888 _spoolss_AddPrinter
9889 ****************************************************************/
9891 WERROR _spoolss_AddPrinter(pipes_struct *p,
9892 struct spoolss_AddPrinter *r)
9894 p->rng_fault_state = true;
9895 return WERR_NOT_SUPPORTED;
9898 /****************************************************************
9899 _spoolss_GetPrinterDriver
9900 ****************************************************************/
9902 WERROR _spoolss_GetPrinterDriver(pipes_struct *p,
9903 struct spoolss_GetPrinterDriver *r)
9905 p->rng_fault_state = true;
9906 return WERR_NOT_SUPPORTED;
9909 /****************************************************************
9910 _spoolss_ReadPrinter
9911 ****************************************************************/
9913 WERROR _spoolss_ReadPrinter(pipes_struct *p,
9914 struct spoolss_ReadPrinter *r)
9916 p->rng_fault_state = true;
9917 return WERR_NOT_SUPPORTED;
9920 /****************************************************************
9921 _spoolss_WaitForPrinterChange
9922 ****************************************************************/
9924 WERROR _spoolss_WaitForPrinterChange(pipes_struct *p,
9925 struct spoolss_WaitForPrinterChange *r)
9927 p->rng_fault_state = true;
9928 return WERR_NOT_SUPPORTED;
9931 /****************************************************************
9932 _spoolss_AddPort
9933 ****************************************************************/
9935 WERROR _spoolss_AddPort(pipes_struct *p,
9936 struct spoolss_AddPort *r)
9938 p->rng_fault_state = true;
9939 return WERR_NOT_SUPPORTED;
9942 /****************************************************************
9943 _spoolss_ConfigurePort
9944 ****************************************************************/
9946 WERROR _spoolss_ConfigurePort(pipes_struct *p,
9947 struct spoolss_ConfigurePort *r)
9949 p->rng_fault_state = true;
9950 return WERR_NOT_SUPPORTED;
9953 /****************************************************************
9954 _spoolss_DeletePort
9955 ****************************************************************/
9957 WERROR _spoolss_DeletePort(pipes_struct *p,
9958 struct spoolss_DeletePort *r)
9960 p->rng_fault_state = true;
9961 return WERR_NOT_SUPPORTED;
9964 /****************************************************************
9965 _spoolss_CreatePrinterIC
9966 ****************************************************************/
9968 WERROR _spoolss_CreatePrinterIC(pipes_struct *p,
9969 struct spoolss_CreatePrinterIC *r)
9971 p->rng_fault_state = true;
9972 return WERR_NOT_SUPPORTED;
9975 /****************************************************************
9976 _spoolss_PlayGDIScriptOnPrinterIC
9977 ****************************************************************/
9979 WERROR _spoolss_PlayGDIScriptOnPrinterIC(pipes_struct *p,
9980 struct spoolss_PlayGDIScriptOnPrinterIC *r)
9982 p->rng_fault_state = true;
9983 return WERR_NOT_SUPPORTED;
9986 /****************************************************************
9987 _spoolss_DeletePrinterIC
9988 ****************************************************************/
9990 WERROR _spoolss_DeletePrinterIC(pipes_struct *p,
9991 struct spoolss_DeletePrinterIC *r)
9993 p->rng_fault_state = true;
9994 return WERR_NOT_SUPPORTED;
9997 /****************************************************************
9998 _spoolss_AddPrinterConnection
9999 ****************************************************************/
10001 WERROR _spoolss_AddPrinterConnection(pipes_struct *p,
10002 struct spoolss_AddPrinterConnection *r)
10004 p->rng_fault_state = true;
10005 return WERR_NOT_SUPPORTED;
10008 /****************************************************************
10009 _spoolss_DeletePrinterConnection
10010 ****************************************************************/
10012 WERROR _spoolss_DeletePrinterConnection(pipes_struct *p,
10013 struct spoolss_DeletePrinterConnection *r)
10015 p->rng_fault_state = true;
10016 return WERR_NOT_SUPPORTED;
10019 /****************************************************************
10020 _spoolss_PrinterMessageBox
10021 ****************************************************************/
10023 WERROR _spoolss_PrinterMessageBox(pipes_struct *p,
10024 struct spoolss_PrinterMessageBox *r)
10026 p->rng_fault_state = true;
10027 return WERR_NOT_SUPPORTED;
10030 /****************************************************************
10031 _spoolss_AddMonitor
10032 ****************************************************************/
10034 WERROR _spoolss_AddMonitor(pipes_struct *p,
10035 struct spoolss_AddMonitor *r)
10037 p->rng_fault_state = true;
10038 return WERR_NOT_SUPPORTED;
10041 /****************************************************************
10042 _spoolss_DeleteMonitor
10043 ****************************************************************/
10045 WERROR _spoolss_DeleteMonitor(pipes_struct *p,
10046 struct spoolss_DeleteMonitor *r)
10048 p->rng_fault_state = true;
10049 return WERR_NOT_SUPPORTED;
10052 /****************************************************************
10053 _spoolss_DeletePrintProcessor
10054 ****************************************************************/
10056 WERROR _spoolss_DeletePrintProcessor(pipes_struct *p,
10057 struct spoolss_DeletePrintProcessor *r)
10059 p->rng_fault_state = true;
10060 return WERR_NOT_SUPPORTED;
10063 /****************************************************************
10064 _spoolss_AddPrintProvidor
10065 ****************************************************************/
10067 WERROR _spoolss_AddPrintProvidor(pipes_struct *p,
10068 struct spoolss_AddPrintProvidor *r)
10070 p->rng_fault_state = true;
10071 return WERR_NOT_SUPPORTED;
10074 /****************************************************************
10075 _spoolss_DeletePrintProvidor
10076 ****************************************************************/
10078 WERROR _spoolss_DeletePrintProvidor(pipes_struct *p,
10079 struct spoolss_DeletePrintProvidor *r)
10081 p->rng_fault_state = true;
10082 return WERR_NOT_SUPPORTED;
10085 /****************************************************************
10086 _spoolss_FindFirstPrinterChangeNotification
10087 ****************************************************************/
10089 WERROR _spoolss_FindFirstPrinterChangeNotification(pipes_struct *p,
10090 struct spoolss_FindFirstPrinterChangeNotification *r)
10092 p->rng_fault_state = true;
10093 return WERR_NOT_SUPPORTED;
10096 /****************************************************************
10097 _spoolss_FindNextPrinterChangeNotification
10098 ****************************************************************/
10100 WERROR _spoolss_FindNextPrinterChangeNotification(pipes_struct *p,
10101 struct spoolss_FindNextPrinterChangeNotification *r)
10103 p->rng_fault_state = true;
10104 return WERR_NOT_SUPPORTED;
10107 /****************************************************************
10108 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10109 ****************************************************************/
10111 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(pipes_struct *p,
10112 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
10114 p->rng_fault_state = true;
10115 return WERR_NOT_SUPPORTED;
10118 /****************************************************************
10119 _spoolss_ReplyOpenPrinter
10120 ****************************************************************/
10122 WERROR _spoolss_ReplyOpenPrinter(pipes_struct *p,
10123 struct spoolss_ReplyOpenPrinter *r)
10125 p->rng_fault_state = true;
10126 return WERR_NOT_SUPPORTED;
10129 /****************************************************************
10130 _spoolss_RouterReplyPrinter
10131 ****************************************************************/
10133 WERROR _spoolss_RouterReplyPrinter(pipes_struct *p,
10134 struct spoolss_RouterReplyPrinter *r)
10136 p->rng_fault_state = true;
10137 return WERR_NOT_SUPPORTED;
10140 /****************************************************************
10141 _spoolss_ReplyClosePrinter
10142 ****************************************************************/
10144 WERROR _spoolss_ReplyClosePrinter(pipes_struct *p,
10145 struct spoolss_ReplyClosePrinter *r)
10147 p->rng_fault_state = true;
10148 return WERR_NOT_SUPPORTED;
10151 /****************************************************************
10152 _spoolss_AddPortEx
10153 ****************************************************************/
10155 WERROR _spoolss_AddPortEx(pipes_struct *p,
10156 struct spoolss_AddPortEx *r)
10158 p->rng_fault_state = true;
10159 return WERR_NOT_SUPPORTED;
10162 /****************************************************************
10163 _spoolss_RouterFindFirstPrinterChangeNotification
10164 ****************************************************************/
10166 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(pipes_struct *p,
10167 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
10169 p->rng_fault_state = true;
10170 return WERR_NOT_SUPPORTED;
10173 /****************************************************************
10174 _spoolss_SpoolerInit
10175 ****************************************************************/
10177 WERROR _spoolss_SpoolerInit(pipes_struct *p,
10178 struct spoolss_SpoolerInit *r)
10180 p->rng_fault_state = true;
10181 return WERR_NOT_SUPPORTED;
10184 /****************************************************************
10185 _spoolss_ResetPrinterEx
10186 ****************************************************************/
10188 WERROR _spoolss_ResetPrinterEx(pipes_struct *p,
10189 struct spoolss_ResetPrinterEx *r)
10191 p->rng_fault_state = true;
10192 return WERR_NOT_SUPPORTED;
10195 /****************************************************************
10196 _spoolss_RouterReplyPrinterEx
10197 ****************************************************************/
10199 WERROR _spoolss_RouterReplyPrinterEx(pipes_struct *p,
10200 struct spoolss_RouterReplyPrinterEx *r)
10202 p->rng_fault_state = true;
10203 return WERR_NOT_SUPPORTED;
10206 /****************************************************************
10207 _spoolss_44
10208 ****************************************************************/
10210 WERROR _spoolss_44(pipes_struct *p,
10211 struct spoolss_44 *r)
10213 p->rng_fault_state = true;
10214 return WERR_NOT_SUPPORTED;
10217 /****************************************************************
10218 _spoolss_47
10219 ****************************************************************/
10221 WERROR _spoolss_47(pipes_struct *p,
10222 struct spoolss_47 *r)
10224 p->rng_fault_state = true;
10225 return WERR_NOT_SUPPORTED;
10228 /****************************************************************
10229 _spoolss_4a
10230 ****************************************************************/
10232 WERROR _spoolss_4a(pipes_struct *p,
10233 struct spoolss_4a *r)
10235 p->rng_fault_state = true;
10236 return WERR_NOT_SUPPORTED;
10239 /****************************************************************
10240 _spoolss_4b
10241 ****************************************************************/
10243 WERROR _spoolss_4b(pipes_struct *p,
10244 struct spoolss_4b *r)
10246 p->rng_fault_state = true;
10247 return WERR_NOT_SUPPORTED;
10250 /****************************************************************
10251 _spoolss_4c
10252 ****************************************************************/
10254 WERROR _spoolss_4c(pipes_struct *p,
10255 struct spoolss_4c *r)
10257 p->rng_fault_state = true;
10258 return WERR_NOT_SUPPORTED;
10261 /****************************************************************
10262 _spoolss_EnumPrinterDataEx
10263 ****************************************************************/
10265 WERROR _spoolss_EnumPrinterDataEx(pipes_struct *p,
10266 struct spoolss_EnumPrinterDataEx *r)
10268 p->rng_fault_state = true;
10269 return WERR_NOT_SUPPORTED;
10272 /****************************************************************
10273 _spoolss_EnumPrinterKey
10274 ****************************************************************/
10276 WERROR _spoolss_EnumPrinterKey(pipes_struct *p,
10277 struct spoolss_EnumPrinterKey *r)
10279 p->rng_fault_state = true;
10280 return WERR_NOT_SUPPORTED;
10283 /****************************************************************
10284 _spoolss_53
10285 ****************************************************************/
10287 WERROR _spoolss_53(pipes_struct *p,
10288 struct spoolss_53 *r)
10290 p->rng_fault_state = true;
10291 return WERR_NOT_SUPPORTED;
10294 /****************************************************************
10295 _spoolss_55
10296 ****************************************************************/
10298 WERROR _spoolss_55(pipes_struct *p,
10299 struct spoolss_55 *r)
10301 p->rng_fault_state = true;
10302 return WERR_NOT_SUPPORTED;
10305 /****************************************************************
10306 _spoolss_56
10307 ****************************************************************/
10309 WERROR _spoolss_56(pipes_struct *p,
10310 struct spoolss_56 *r)
10312 p->rng_fault_state = true;
10313 return WERR_NOT_SUPPORTED;
10316 /****************************************************************
10317 _spoolss_57
10318 ****************************************************************/
10320 WERROR _spoolss_57(pipes_struct *p,
10321 struct spoolss_57 *r)
10323 p->rng_fault_state = true;
10324 return WERR_NOT_SUPPORTED;
10327 /****************************************************************
10328 _spoolss_5a
10329 ****************************************************************/
10331 WERROR _spoolss_5a(pipes_struct *p,
10332 struct spoolss_5a *r)
10334 p->rng_fault_state = true;
10335 return WERR_NOT_SUPPORTED;
10338 /****************************************************************
10339 _spoolss_5b
10340 ****************************************************************/
10342 WERROR _spoolss_5b(pipes_struct *p,
10343 struct spoolss_5b *r)
10345 p->rng_fault_state = true;
10346 return WERR_NOT_SUPPORTED;
10349 /****************************************************************
10350 _spoolss_5c
10351 ****************************************************************/
10353 WERROR _spoolss_5c(pipes_struct *p,
10354 struct spoolss_5c *r)
10356 p->rng_fault_state = true;
10357 return WERR_NOT_SUPPORTED;
10360 /****************************************************************
10361 _spoolss_5d
10362 ****************************************************************/
10364 WERROR _spoolss_5d(pipes_struct *p,
10365 struct spoolss_5d *r)
10367 p->rng_fault_state = true;
10368 return WERR_NOT_SUPPORTED;
10371 /****************************************************************
10372 _spoolss_5e
10373 ****************************************************************/
10375 WERROR _spoolss_5e(pipes_struct *p,
10376 struct spoolss_5e *r)
10378 p->rng_fault_state = true;
10379 return WERR_NOT_SUPPORTED;
10382 /****************************************************************
10383 _spoolss_5f
10384 ****************************************************************/
10386 WERROR _spoolss_5f(pipes_struct *p,
10387 struct spoolss_5f *r)
10389 p->rng_fault_state = true;
10390 return WERR_NOT_SUPPORTED;