Implement rename/move in SMB2 from Windows7.
[Samba.git] / source3 / rpc_server / srv_spoolss_nt.c
blobb978a5cc0478a061c76f2c97bc97aa105a2321c8
1 /*
2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-2000,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
6 * Copyright (C) Jean François Micouleau 1998-2000,
7 * Copyright (C) Jeremy Allison 2001-2002,
8 * Copyright (C) Gerald Carter 2000-2004,
9 * Copyright (C) Tim Potter 2001-2002.
10 * Copyright (C) Guenther Deschner 2009-2010.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <http://www.gnu.org/licenses/>.
26 /* Since the SPOOLSS rpc routines are basically DOS 16-bit calls wrapped
27 up, all the errors returned are DOS errors, not NT status codes. */
29 #include "includes.h"
30 #include "../librpc/gen_ndr/srv_spoolss.h"
31 #include "../librpc/gen_ndr/cli_spoolss.h"
33 /* macros stolen from s4 spoolss server */
34 #define SPOOLSS_BUFFER_UNION(fn,ic,info,level) \
35 ((info)?ndr_size_##fn(info, level, ic, 0):0)
37 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,ic,info,level,count) \
38 ((info)?ndr_size_##fn##_info(mem_ctx, ic, level, count, info):0)
40 #define SPOOLSS_BUFFER_ARRAY(mem_ctx,fn,ic,info,count) \
41 ((info)?ndr_size_##fn##_info(mem_ctx, ic, count, info):0)
43 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
46 extern userdom_struct current_user_info;
48 #undef DBGC_CLASS
49 #define DBGC_CLASS DBGC_RPC_SRV
51 #ifndef MAX_OPEN_PRINTER_EXS
52 #define MAX_OPEN_PRINTER_EXS 50
53 #endif
55 #define MAGIC_DISPLAY_FREQUENCY 0xfade2bad
56 #define PHANTOM_DEVMODE_KEY "_p_f_a_n_t_0_m_"
58 static Printer_entry *printers_list;
60 typedef struct _counter_printer_0 {
61 struct _counter_printer_0 *next;
62 struct _counter_printer_0 *prev;
64 int snum;
65 uint32_t 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_t smb_connections = 0;
74 /* in printing/nt_printing.c */
76 extern struct standard_mapping printer_std_mapping, printserver_std_mapping;
78 /* API table for Xcv Monitor functions */
80 struct xcv_api_table {
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, struct policy_handle *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,
231 struct policy_handle *hnd)
233 Printer_entry *find_printer = NULL;
235 if(!find_policy_by_hnd(p,hnd,(void **)(void *)&find_printer)) {
236 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
237 return NULL;
240 return find_printer;
243 /****************************************************************************
244 Close printer index by handle.
245 ****************************************************************************/
247 static bool close_printer_handle(pipes_struct *p, struct policy_handle *hnd)
249 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
251 if (!Printer) {
252 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n",
253 OUR_HANDLE(hnd)));
254 return false;
257 close_policy_hnd(p, hnd);
259 return true;
262 /****************************************************************************
263 Delete a printer given a handle.
264 ****************************************************************************/
266 static WERROR delete_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *sharename)
268 char *cmd = lp_deleteprinter_cmd();
269 char *command = NULL;
270 int ret;
271 SE_PRIV se_printop = SE_PRINT_OPERATOR;
272 bool is_print_op = false;
274 /* can't fail if we don't try */
276 if ( !*cmd )
277 return WERR_OK;
279 command = talloc_asprintf(ctx,
280 "%s \"%s\"",
281 cmd, sharename);
282 if (!command) {
283 return WERR_NOMEM;
285 if ( token )
286 is_print_op = user_has_privileges( token, &se_printop );
288 DEBUG(10,("Running [%s]\n", command));
290 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
292 if ( is_print_op )
293 become_root();
295 if ( (ret = smbrun(command, NULL)) == 0 ) {
296 /* Tell everyone we updated smb.conf. */
297 message_send_all(smbd_messaging_context(),
298 MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
301 if ( is_print_op )
302 unbecome_root();
304 /********** END SePrintOperatorPrivlege BLOCK **********/
306 DEBUGADD(10,("returned [%d]\n", ret));
308 TALLOC_FREE(command);
310 if (ret != 0)
311 return WERR_BADFID; /* What to return here? */
313 /* go ahead and re-read the services immediately */
314 become_root();
315 reload_services(false);
316 unbecome_root();
318 if ( lp_servicenumber( sharename ) > 0 )
319 return WERR_ACCESS_DENIED;
321 return WERR_OK;
324 /****************************************************************************
325 Delete a printer given a handle.
326 ****************************************************************************/
328 static WERROR delete_printer_handle(pipes_struct *p, struct policy_handle *hnd)
330 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
332 if (!Printer) {
333 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
334 OUR_HANDLE(hnd)));
335 return WERR_BADFID;
339 * It turns out that Windows allows delete printer on a handle
340 * opened by an admin user, then used on a pipe handle created
341 * by an anonymous user..... but they're working on security.... riiight !
342 * JRA.
345 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
346 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
347 return WERR_ACCESS_DENIED;
350 /* this does not need a become root since the access check has been
351 done on the handle already */
353 if (del_a_printer( Printer->sharename ) != 0) {
354 DEBUG(3,("Error deleting printer %s\n", Printer->sharename));
355 return WERR_BADFID;
358 return delete_printer_hook(p->mem_ctx, p->server_info->ptok,
359 Printer->sharename );
362 /****************************************************************************
363 Return the snum of a printer corresponding to an handle.
364 ****************************************************************************/
366 static bool get_printer_snum(pipes_struct *p, struct policy_handle *hnd,
367 int *number, struct share_params **params)
369 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
371 if (!Printer) {
372 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
373 OUR_HANDLE(hnd)));
374 return false;
377 switch (Printer->printer_type) {
378 case SPLHND_PRINTER:
379 DEBUG(4,("short name:%s\n", Printer->sharename));
380 *number = print_queue_snum(Printer->sharename);
381 return (*number != -1);
382 case SPLHND_SERVER:
383 return false;
384 default:
385 return false;
389 /****************************************************************************
390 Set printer handle type.
391 Check if it's \\server or \\server\printer
392 ****************************************************************************/
394 static bool set_printer_hnd_printertype(Printer_entry *Printer, const char *handlename)
396 DEBUG(3,("Setting printer type=%s\n", handlename));
398 if ( strlen(handlename) < 3 ) {
399 DEBUGADD(4,("A print server must have at least 1 char ! %s\n", handlename));
400 return false;
403 /* it's a print server */
404 if (*handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) {
405 DEBUGADD(4,("Printer is a print server\n"));
406 Printer->printer_type = SPLHND_SERVER;
408 /* it's a printer (set_printer_hnd_name() will handle port monitors */
409 else {
410 DEBUGADD(4,("Printer is a printer\n"));
411 Printer->printer_type = SPLHND_PRINTER;
414 return true;
417 /****************************************************************************
418 Set printer handle name.. Accept names like \\server, \\server\printer,
419 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
420 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
421 XcvDataPort() interface.
422 ****************************************************************************/
424 static bool set_printer_hnd_name(Printer_entry *Printer, const char *handlename)
426 int snum;
427 int n_services=lp_numservices();
428 char *aprinter, *printername;
429 const char *servername;
430 fstring sname;
431 bool found = false;
432 NT_PRINTER_INFO_LEVEL *printer = NULL;
433 WERROR result;
435 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename,
436 (unsigned long)strlen(handlename)));
438 aprinter = CONST_DISCARD(char *, handlename);
439 if ( *handlename == '\\' ) {
440 servername = canon_servername(handlename);
441 if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
442 *aprinter = '\0';
443 aprinter++;
445 } else {
446 servername = global_myname();
449 /* save the servername to fill in replies on this handle */
451 if ( !is_myname_or_ipaddr( servername ) )
452 return false;
454 fstrcpy( Printer->servername, servername );
456 if ( Printer->printer_type == SPLHND_SERVER )
457 return true;
459 if ( Printer->printer_type != SPLHND_PRINTER )
460 return false;
462 DEBUGADD(5, ("searching for [%s]\n", aprinter ));
464 /* check for the Port Monitor Interface */
466 if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
467 Printer->printer_type = SPLHND_PORTMON_TCP;
468 fstrcpy(sname, SPL_XCV_MONITOR_TCPMON);
469 found = true;
471 else if ( strequal( aprinter, SPL_XCV_MONITOR_LOCALMON ) ) {
472 Printer->printer_type = SPLHND_PORTMON_LOCAL;
473 fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON);
474 found = true;
477 /* Search all sharenames first as this is easier than pulling
478 the printer_info_2 off of disk. Don't use find_service() since
479 that calls out to map_username() */
481 /* do another loop to look for printernames */
483 for (snum=0; !found && snum<n_services; snum++) {
485 /* no point going on if this is not a printer */
487 if ( !(lp_snum_ok(snum) && lp_print_ok(snum)) )
488 continue;
490 fstrcpy(sname, lp_servicename(snum));
491 if ( strequal( aprinter, sname ) ) {
492 found = true;
493 break;
496 /* no point looking up the printer object if
497 we aren't allowing printername != sharename */
499 if ( lp_force_printername(snum) )
500 continue;
502 fstrcpy(sname, lp_servicename(snum));
504 printer = NULL;
506 /* This call doesn't fill in the location or comment from
507 * a CUPS server for efficiency with large numbers of printers.
508 * JRA.
511 result = get_a_printer_search( NULL, &printer, 2, sname );
512 if ( !W_ERROR_IS_OK(result) ) {
513 DEBUG(0,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
514 sname, win_errstr(result)));
515 continue;
518 /* printername is always returned as \\server\printername */
519 if ( !(printername = strchr_m(&printer->info_2->printername[2], '\\')) ) {
520 DEBUG(0,("set_printer_hnd_name: info2->printername in wrong format! [%s]\n",
521 printer->info_2->printername));
522 free_a_printer( &printer, 2);
523 continue;
526 printername++;
528 if ( strequal(printername, aprinter) ) {
529 free_a_printer( &printer, 2);
530 found = true;
531 break;
534 DEBUGADD(10, ("printername: %s\n", printername));
536 free_a_printer( &printer, 2);
539 free_a_printer( &printer, 2);
541 if ( !found ) {
542 DEBUGADD(4,("Printer not found\n"));
543 return false;
546 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));
548 fstrcpy(Printer->sharename, sname);
550 return true;
553 /****************************************************************************
554 Find first available printer slot. creates a printer handle for you.
555 ****************************************************************************/
557 static bool open_printer_hnd(pipes_struct *p, struct policy_handle *hnd,
558 const char *name, uint32_t access_granted)
560 Printer_entry *new_printer;
562 DEBUG(10,("open_printer_hnd: name [%s]\n", name));
564 new_printer = TALLOC_ZERO_P(NULL, Printer_entry);
565 if (new_printer == NULL) {
566 return false;
568 talloc_set_destructor(new_printer, printer_entry_destructor);
570 if (!create_policy_hnd(p, hnd, new_printer)) {
571 TALLOC_FREE(new_printer);
572 return false;
575 /* Add to the internal list. */
576 DLIST_ADD(printers_list, new_printer);
578 new_printer->notify.option=NULL;
580 if (!set_printer_hnd_printertype(new_printer, name)) {
581 close_printer_handle(p, hnd);
582 return false;
585 if (!set_printer_hnd_name(new_printer, name)) {
586 close_printer_handle(p, hnd);
587 return false;
590 new_printer->access_granted = access_granted;
592 DEBUG(5, ("%d printer handles active\n",
593 (int)num_pipe_handles(p->pipe_handles)));
595 return true;
598 /***************************************************************************
599 check to see if the client motify handle is monitoring the notification
600 given by (notify_type, notify_field).
601 **************************************************************************/
603 static bool is_monitoring_event_flags(uint32_t flags, uint16_t notify_type,
604 uint16_t notify_field)
606 return true;
609 static bool is_monitoring_event(Printer_entry *p, uint16_t notify_type,
610 uint16_t notify_field)
612 struct spoolss_NotifyOption *option = p->notify.option;
613 uint32_t i, j;
616 * Flags should always be zero when the change notify
617 * is registered by the client's spooler. A user Win32 app
618 * might use the flags though instead of the NOTIFY_OPTION_INFO
619 * --jerry
622 if (!option) {
623 return false;
626 if (p->notify.flags)
627 return is_monitoring_event_flags(
628 p->notify.flags, notify_type, notify_field);
630 for (i = 0; i < option->count; i++) {
632 /* Check match for notify_type */
634 if (option->types[i].type != notify_type)
635 continue;
637 /* Check match for field */
639 for (j = 0; j < option->types[i].count; j++) {
640 if (option->types[i].fields[j].field == notify_field) {
641 return true;
646 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
647 p->servername, p->sharename, notify_type, notify_field));
649 return false;
652 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
653 _data->data.integer[0] = _integer; \
654 _data->data.integer[1] = 0;
657 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
658 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
659 if (!_data->data.string.string) {\
660 _data->data.string.size = 0; \
662 _data->data.string.size = strlen_m_term(_p) * 2;
664 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
665 _data->data.devmode.devmode = _devmode;
667 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _size, _sd) \
668 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
669 if (!_data->data.sd.sd) { \
670 _data->data.sd.sd_size = 0; \
672 _data->data.sd.sd_size = _size;
674 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
675 struct tm *t,
676 const char **pp,
677 uint32_t *plen)
679 struct spoolss_Time st;
680 uint32_t len = 16;
681 char *p;
683 if (!init_systemtime(&st, t)) {
684 return;
687 p = talloc_array(mem_ctx, char, len);
688 if (!p) {
689 return;
693 * Systemtime must be linearized as a set of UINT16's.
694 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
697 SSVAL(p, 0, st.year);
698 SSVAL(p, 2, st.month);
699 SSVAL(p, 4, st.day_of_week);
700 SSVAL(p, 6, st.day);
701 SSVAL(p, 8, st.hour);
702 SSVAL(p, 10, st.minute);
703 SSVAL(p, 12, st.second);
704 SSVAL(p, 14, st.millisecond);
706 *pp = p;
707 *plen = len;
710 /* Convert a notification message to a struct spoolss_Notify */
712 static void notify_one_value(struct spoolss_notify_msg *msg,
713 struct spoolss_Notify *data,
714 TALLOC_CTX *mem_ctx)
716 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, msg->notify.value[0]);
719 static void notify_string(struct spoolss_notify_msg *msg,
720 struct spoolss_Notify *data,
721 TALLOC_CTX *mem_ctx)
723 /* The length of the message includes the trailing \0 */
725 data->data.string.size = msg->len * 2;
726 data->data.string.string = talloc_strdup(mem_ctx, msg->notify.data);
727 if (!data->data.string.string) {
728 data->data.string.size = 0;
729 return;
733 static void notify_system_time(struct spoolss_notify_msg *msg,
734 struct spoolss_Notify *data,
735 TALLOC_CTX *mem_ctx)
737 data->data.string.string = NULL;
738 data->data.string.size = 0;
740 if (msg->len != sizeof(time_t)) {
741 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
742 msg->len));
743 return;
746 init_systemtime_buffer(mem_ctx, gmtime((time_t *)msg->notify.data),
747 &data->data.string.string,
748 &data->data.string.size);
751 struct notify2_message_table {
752 const char *name;
753 void (*fn)(struct spoolss_notify_msg *msg,
754 struct spoolss_Notify *data, TALLOC_CTX *mem_ctx);
757 static struct notify2_message_table printer_notify_table[] = {
758 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string },
759 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string },
760 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string },
761 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string },
762 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string },
763 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string },
764 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string },
765 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL },
766 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string },
767 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string },
768 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL },
769 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string },
770 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
771 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value },
772 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value },
773 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL },
774 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL },
775 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL },
776 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value },
779 static struct notify2_message_table job_notify_table[] = {
780 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL },
781 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL },
782 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL },
783 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string },
784 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL },
785 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL },
786 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL },
787 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL },
788 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL },
789 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL },
790 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value },
791 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL },
792 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
793 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string },
794 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL },
795 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL },
796 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time },
797 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL },
798 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL },
799 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL },
800 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value },
801 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL },
802 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value },
803 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL },
807 /***********************************************************************
808 Allocate talloc context for container object
809 **********************************************************************/
811 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
813 if ( !ctr )
814 return;
816 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
818 return;
821 /***********************************************************************
822 release all allocated memory and zero out structure
823 **********************************************************************/
825 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
827 if ( !ctr )
828 return;
830 if ( ctr->ctx )
831 talloc_destroy(ctr->ctx);
833 ZERO_STRUCTP(ctr);
835 return;
838 /***********************************************************************
839 **********************************************************************/
841 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
843 if ( !ctr )
844 return NULL;
846 return ctr->ctx;
849 /***********************************************************************
850 **********************************************************************/
852 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
854 if ( !ctr || !ctr->msg_groups )
855 return NULL;
857 if ( idx >= ctr->num_groups )
858 return NULL;
860 return &ctr->msg_groups[idx];
864 /***********************************************************************
865 How many groups of change messages do we have ?
866 **********************************************************************/
868 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
870 if ( !ctr )
871 return 0;
873 return ctr->num_groups;
876 /***********************************************************************
877 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
878 **********************************************************************/
880 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
882 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
883 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
884 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
885 int i, new_slot;
887 if ( !ctr || !msg )
888 return 0;
890 /* loop over all groups looking for a matching printer name */
892 for ( i=0; i<ctr->num_groups; i++ ) {
893 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
894 break;
897 /* add a new group? */
899 if ( i == ctr->num_groups ) {
900 ctr->num_groups++;
902 if ( !(groups = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
903 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
904 return 0;
906 ctr->msg_groups = groups;
908 /* clear the new entry and set the printer name */
910 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
911 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
914 /* add the change messages; 'i' is the correct index now regardless */
916 msg_grp = &ctr->msg_groups[i];
918 msg_grp->num_msgs++;
920 if ( !(msg_list = TALLOC_REALLOC_ARRAY( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
921 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
922 return 0;
924 msg_grp->msgs = msg_list;
926 new_slot = msg_grp->num_msgs-1;
927 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
929 /* need to allocate own copy of data */
931 if ( msg->len != 0 )
932 msg_grp->msgs[new_slot].notify.data = (char *)
933 TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len );
935 return ctr->num_groups;
938 /***********************************************************************
939 Send a change notication message on all handles which have a call
940 back registered
941 **********************************************************************/
943 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
945 Printer_entry *p;
946 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
947 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
948 SPOOLSS_NOTIFY_MSG *messages;
949 int sending_msg_count;
951 if ( !msg_group ) {
952 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
953 return;
956 messages = msg_group->msgs;
958 if ( !messages ) {
959 DEBUG(5,("send_notify2_changes() called with no messages!\n"));
960 return;
963 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
965 /* loop over all printers */
967 for (p = printers_list; p; p = p->next) {
968 struct spoolss_Notify *notifies;
969 uint32_t count = 0;
970 uint32_t id;
971 int i;
973 /* Is there notification on this handle? */
975 if ( !p->notify.client_connected )
976 continue;
978 DEBUG(10,("Client connected! [\\\\%s\\%s]\n", p->servername, p->sharename));
980 /* For this printer? Print servers always receive
981 notifications. */
983 if ( ( p->printer_type == SPLHND_PRINTER ) &&
984 ( !strequal(msg_group->printername, p->sharename) ) )
985 continue;
987 DEBUG(10,("Our printer\n"));
989 /* allocate the max entries possible */
991 notifies = TALLOC_ZERO_ARRAY(mem_ctx, struct spoolss_Notify, msg_group->num_msgs);
992 if (!notifies) {
993 return;
996 /* build the array of change notifications */
998 sending_msg_count = 0;
1000 for ( i=0; i<msg_group->num_msgs; i++ ) {
1001 SPOOLSS_NOTIFY_MSG *msg = &messages[i];
1003 /* Are we monitoring this event? */
1005 if (!is_monitoring_event(p, msg->type, msg->field))
1006 continue;
1008 sending_msg_count++;
1011 DEBUG(10,("process_notify2_message: Sending message type [0x%x] field [0x%2x] for printer [%s]\n",
1012 msg->type, msg->field, p->sharename));
1015 * if the is a printer notification handle and not a job notification
1016 * type, then set the id to 0. Other wise just use what was specified
1017 * in the message.
1019 * When registering change notification on a print server handle
1020 * we always need to send back the id (snum) matching the printer
1021 * for which the change took place. For change notify registered
1022 * on a printer handle, this does not matter and the id should be 0.
1024 * --jerry
1027 if ( ( p->printer_type == SPLHND_PRINTER ) && ( msg->type == PRINTER_NOTIFY_TYPE ) )
1028 id = 0;
1029 else
1030 id = msg->id;
1033 /* Convert unix jobid to smb jobid */
1035 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1036 id = sysjob_to_jobid(msg->id);
1038 if (id == -1) {
1039 DEBUG(3, ("no such unix jobid %d\n", msg->id));
1040 goto done;
1044 construct_info_data( &notifies[count], msg->type, msg->field, id );
1046 switch(msg->type) {
1047 case PRINTER_NOTIFY_TYPE:
1048 if ( printer_notify_table[msg->field].fn )
1049 printer_notify_table[msg->field].fn(msg, &notifies[count], mem_ctx);
1050 break;
1052 case JOB_NOTIFY_TYPE:
1053 if ( job_notify_table[msg->field].fn )
1054 job_notify_table[msg->field].fn(msg, &notifies[count], mem_ctx);
1055 break;
1057 default:
1058 DEBUG(5, ("Unknown notification type %d\n", msg->type));
1059 goto done;
1062 count++;
1065 if ( sending_msg_count ) {
1066 NTSTATUS status;
1067 WERROR werr;
1068 union spoolss_ReplyPrinterInfo info;
1069 struct spoolss_NotifyInfo info0;
1070 uint32_t reply_result;
1072 info0.version = 0x2;
1073 info0.flags = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
1074 info0.count = count;
1075 info0.notifies = notifies;
1077 info.info0 = &info0;
1079 status = rpccli_spoolss_RouterReplyPrinterEx(notify_cli_pipe, mem_ctx,
1080 &p->notify.client_hnd,
1081 p->notify.change, /* color */
1082 p->notify.flags,
1083 &reply_result,
1084 0, /* reply_type, must be 0 */
1085 info,
1086 &werr);
1087 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) {
1088 DEBUG(1,("RouterReplyPrinterEx to client: %s failed: %s\n",
1089 notify_cli_pipe->srv_name_slash,
1090 win_errstr(werr)));
1092 switch (reply_result) {
1093 case 0:
1094 break;
1095 case PRINTER_NOTIFY_INFO_DISCARDED:
1096 case PRINTER_NOTIFY_INFO_DISCARDNOTED:
1097 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
1098 break;
1099 default:
1100 break;
1105 done:
1106 DEBUG(8,("send_notify2_changes: Exit...\n"));
1107 return;
1110 /***********************************************************************
1111 **********************************************************************/
1113 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1116 uint32_t tv_sec, tv_usec;
1117 size_t offset = 0;
1119 /* Unpack message */
1121 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "f",
1122 msg->printer);
1124 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "ddddddd",
1125 &tv_sec, &tv_usec,
1126 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1128 if (msg->len == 0)
1129 tdb_unpack((uint8_t *)buf + offset, len - offset, "dd",
1130 &msg->notify.value[0], &msg->notify.value[1]);
1131 else
1132 tdb_unpack((uint8_t *)buf + offset, len - offset, "B",
1133 &msg->len, &msg->notify.data);
1135 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1136 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1138 tv->tv_sec = tv_sec;
1139 tv->tv_usec = tv_usec;
1141 if (msg->len == 0)
1142 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1143 msg->notify.value[1]));
1144 else
1145 dump_data(3, (uint8_t *)msg->notify.data, msg->len);
1147 return true;
1150 /********************************************************************
1151 Receive a notify2 message list
1152 ********************************************************************/
1154 static void receive_notify2_message_list(struct messaging_context *msg,
1155 void *private_data,
1156 uint32_t msg_type,
1157 struct server_id server_id,
1158 DATA_BLOB *data)
1160 size_t msg_count, i;
1161 char *buf = (char *)data->data;
1162 char *msg_ptr;
1163 size_t msg_len;
1164 SPOOLSS_NOTIFY_MSG notify;
1165 SPOOLSS_NOTIFY_MSG_CTR messages;
1166 int num_groups;
1168 if (data->length < 4) {
1169 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1170 return;
1173 msg_count = IVAL(buf, 0);
1174 msg_ptr = buf + 4;
1176 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1178 if (msg_count == 0) {
1179 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1180 return;
1183 /* initialize the container */
1185 ZERO_STRUCT( messages );
1186 notify_msg_ctr_init( &messages );
1189 * build message groups for each printer identified
1190 * in a change_notify msg. Remember that a PCN message
1191 * includes the handle returned for the srv_spoolss_replyopenprinter()
1192 * call. Therefore messages are grouped according to printer handle.
1195 for ( i=0; i<msg_count; i++ ) {
1196 struct timeval msg_tv;
1198 if (msg_ptr + 4 - buf > data->length) {
1199 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1200 return;
1203 msg_len = IVAL(msg_ptr,0);
1204 msg_ptr += 4;
1206 if (msg_ptr + msg_len - buf > data->length) {
1207 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1208 return;
1211 /* unpack messages */
1213 ZERO_STRUCT( notify );
1214 notify2_unpack_msg( &notify, &msg_tv, msg_ptr, msg_len );
1215 msg_ptr += msg_len;
1217 /* add to correct list in container */
1219 notify_msg_ctr_addmsg( &messages, &notify );
1221 /* free memory that might have been allocated by notify2_unpack_msg() */
1223 if ( notify.len != 0 )
1224 SAFE_FREE( notify.notify.data );
1227 /* process each group of messages */
1229 num_groups = notify_msg_ctr_numgroups( &messages );
1230 for ( i=0; i<num_groups; i++ )
1231 send_notify2_changes( &messages, i );
1234 /* cleanup */
1236 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1237 (uint32_t)msg_count ));
1239 notify_msg_ctr_destroy( &messages );
1241 return;
1244 /********************************************************************
1245 Send a message to ourself about new driver being installed
1246 so we can upgrade the information for each printer bound to this
1247 driver
1248 ********************************************************************/
1250 static bool srv_spoolss_drv_upgrade_printer(const char *drivername)
1252 int len = strlen(drivername);
1254 if (!len)
1255 return false;
1257 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1258 drivername));
1260 messaging_send_buf(smbd_messaging_context(), procid_self(),
1261 MSG_PRINTER_DRVUPGRADE,
1262 (uint8_t *)drivername, len+1);
1264 return true;
1267 /**********************************************************************
1268 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1269 over all printers, upgrading ones as necessary
1270 **********************************************************************/
1272 void do_drv_upgrade_printer(struct messaging_context *msg,
1273 void *private_data,
1274 uint32_t msg_type,
1275 struct server_id server_id,
1276 DATA_BLOB *data)
1278 fstring drivername;
1279 int snum;
1280 int n_services = lp_numservices();
1281 size_t len;
1283 len = MIN(data->length,sizeof(drivername)-1);
1284 strncpy(drivername, (const char *)data->data, len);
1286 DEBUG(10,("do_drv_upgrade_printer: Got message for new driver [%s]\n", drivername ));
1288 /* Iterate the printer list */
1290 for (snum=0; snum<n_services; snum++)
1292 if (lp_snum_ok(snum) && lp_print_ok(snum) )
1294 WERROR result;
1295 NT_PRINTER_INFO_LEVEL *printer = NULL;
1297 result = get_a_printer(NULL, &printer, 2, lp_const_servicename(snum));
1298 if (!W_ERROR_IS_OK(result))
1299 continue;
1301 if (printer && printer->info_2 && !strcmp(drivername, printer->info_2->drivername))
1303 DEBUG(6,("Updating printer [%s]\n", printer->info_2->printername));
1305 /* all we care about currently is the change_id */
1307 result = mod_a_printer(printer, 2);
1308 if (!W_ERROR_IS_OK(result)) {
1309 DEBUG(3,("do_drv_upgrade_printer: mod_a_printer() failed with status [%s]\n",
1310 win_errstr(result)));
1314 free_a_printer(&printer, 2);
1318 /* all done */
1321 /********************************************************************
1322 Update the cache for all printq's with a registered client
1323 connection
1324 ********************************************************************/
1326 void update_monitored_printq_cache( void )
1328 Printer_entry *printer = printers_list;
1329 int snum;
1331 /* loop through all printers and update the cache where
1332 client_connected == true */
1333 while ( printer )
1335 if ( (printer->printer_type == SPLHND_PRINTER)
1336 && printer->notify.client_connected )
1338 snum = print_queue_snum(printer->sharename);
1339 print_queue_status( snum, NULL, NULL );
1342 printer = printer->next;
1345 return;
1347 /********************************************************************
1348 Send a message to ourself about new driver being installed
1349 so we can upgrade the information for each printer bound to this
1350 driver
1351 ********************************************************************/
1353 static bool srv_spoolss_reset_printerdata(char* drivername)
1355 int len = strlen(drivername);
1357 if (!len)
1358 return false;
1360 DEBUG(10,("srv_spoolss_reset_printerdata: Sending message about resetting printerdata [%s]\n",
1361 drivername));
1363 messaging_send_buf(smbd_messaging_context(), procid_self(),
1364 MSG_PRINTERDATA_INIT_RESET,
1365 (uint8_t *)drivername, len+1);
1367 return true;
1370 /**********************************************************************
1371 callback to receive a MSG_PRINTERDATA_INIT_RESET message and interate
1372 over all printers, resetting printer data as neessary
1373 **********************************************************************/
1375 void reset_all_printerdata(struct messaging_context *msg,
1376 void *private_data,
1377 uint32_t msg_type,
1378 struct server_id server_id,
1379 DATA_BLOB *data)
1381 fstring drivername;
1382 int snum;
1383 int n_services = lp_numservices();
1384 size_t len;
1386 len = MIN( data->length, sizeof(drivername)-1 );
1387 strncpy( drivername, (const char *)data->data, len );
1389 DEBUG(10,("reset_all_printerdata: Got message for new driver [%s]\n", drivername ));
1391 /* Iterate the printer list */
1393 for ( snum=0; snum<n_services; snum++ )
1395 if ( lp_snum_ok(snum) && lp_print_ok(snum) )
1397 WERROR result;
1398 NT_PRINTER_INFO_LEVEL *printer = NULL;
1400 result = get_a_printer( NULL, &printer, 2, lp_const_servicename(snum) );
1401 if ( !W_ERROR_IS_OK(result) )
1402 continue;
1405 * if the printer is bound to the driver,
1406 * then reset to the new driver initdata
1409 if ( printer && printer->info_2 && !strcmp(drivername, printer->info_2->drivername) )
1411 DEBUG(6,("reset_all_printerdata: Updating printer [%s]\n", printer->info_2->printername));
1413 if ( !set_driver_init(printer, 2) ) {
1414 DEBUG(5,("reset_all_printerdata: Error resetting printer data for printer [%s], driver [%s]!\n",
1415 printer->info_2->printername, printer->info_2->drivername));
1418 result = mod_a_printer( printer, 2 );
1419 if ( !W_ERROR_IS_OK(result) ) {
1420 DEBUG(3,("reset_all_printerdata: mod_a_printer() failed! (%s)\n",
1421 get_dos_error_msg(result)));
1425 free_a_printer( &printer, 2 );
1429 /* all done */
1431 return;
1434 /****************************************************************
1435 _spoolss_OpenPrinter
1436 ****************************************************************/
1438 WERROR _spoolss_OpenPrinter(pipes_struct *p,
1439 struct spoolss_OpenPrinter *r)
1441 struct spoolss_OpenPrinterEx e;
1442 WERROR werr;
1444 ZERO_STRUCT(e.in.userlevel);
1446 e.in.printername = r->in.printername;
1447 e.in.datatype = r->in.datatype;
1448 e.in.devmode_ctr = r->in.devmode_ctr;
1449 e.in.access_mask = r->in.access_mask;
1450 e.in.level = 0;
1452 e.out.handle = r->out.handle;
1454 werr = _spoolss_OpenPrinterEx(p, &e);
1456 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1457 /* OpenPrinterEx returns this for a bad
1458 * printer name. We must return WERR_INVALID_PRINTER_NAME
1459 * instead.
1461 werr = WERR_INVALID_PRINTER_NAME;
1464 return werr;
1467 /********************************************************************
1468 ********************************************************************/
1470 bool convert_devicemode(const char *printername,
1471 const struct spoolss_DeviceMode *devmode,
1472 NT_DEVICEMODE **pp_nt_devmode)
1474 NT_DEVICEMODE *nt_devmode = *pp_nt_devmode;
1477 * Ensure nt_devmode is a valid pointer
1478 * as we will be overwriting it.
1481 if (nt_devmode == NULL) {
1482 DEBUG(5, ("convert_devicemode: allocating a generic devmode\n"));
1483 if ((nt_devmode = construct_nt_devicemode(printername)) == NULL)
1484 return false;
1487 fstrcpy(nt_devmode->devicename, devmode->devicename);
1488 fstrcpy(nt_devmode->formname, devmode->formname);
1490 nt_devmode->devicename[31] = '\0';
1491 nt_devmode->formname[31] = '\0';
1493 nt_devmode->specversion = devmode->specversion;
1494 nt_devmode->driverversion = devmode->driverversion;
1495 nt_devmode->size = devmode->size;
1496 nt_devmode->fields = devmode->fields;
1497 nt_devmode->orientation = devmode->orientation;
1498 nt_devmode->papersize = devmode->papersize;
1499 nt_devmode->paperlength = devmode->paperlength;
1500 nt_devmode->paperwidth = devmode->paperwidth;
1501 nt_devmode->scale = devmode->scale;
1502 nt_devmode->copies = devmode->copies;
1503 nt_devmode->defaultsource = devmode->defaultsource;
1504 nt_devmode->printquality = devmode->printquality;
1505 nt_devmode->color = devmode->color;
1506 nt_devmode->duplex = devmode->duplex;
1507 nt_devmode->yresolution = devmode->yresolution;
1508 nt_devmode->ttoption = devmode->ttoption;
1509 nt_devmode->collate = devmode->collate;
1511 nt_devmode->logpixels = devmode->logpixels;
1512 nt_devmode->bitsperpel = devmode->bitsperpel;
1513 nt_devmode->pelswidth = devmode->pelswidth;
1514 nt_devmode->pelsheight = devmode->pelsheight;
1515 nt_devmode->displayflags = devmode->displayflags;
1516 nt_devmode->displayfrequency = devmode->displayfrequency;
1517 nt_devmode->icmmethod = devmode->icmmethod;
1518 nt_devmode->icmintent = devmode->icmintent;
1519 nt_devmode->mediatype = devmode->mediatype;
1520 nt_devmode->dithertype = devmode->dithertype;
1521 nt_devmode->reserved1 = devmode->reserved1;
1522 nt_devmode->reserved2 = devmode->reserved2;
1523 nt_devmode->panningwidth = devmode->panningwidth;
1524 nt_devmode->panningheight = devmode->panningheight;
1527 * Only change private and driverextra if the incoming devmode
1528 * has a new one. JRA.
1531 if ((devmode->__driverextra_length != 0) && (devmode->driverextra_data.data != NULL)) {
1532 SAFE_FREE(nt_devmode->nt_dev_private);
1533 nt_devmode->driverextra = devmode->__driverextra_length;
1534 if((nt_devmode->nt_dev_private = SMB_MALLOC_ARRAY(uint8_t, nt_devmode->driverextra)) == NULL)
1535 return false;
1536 memcpy(nt_devmode->nt_dev_private, devmode->driverextra_data.data, nt_devmode->driverextra);
1539 *pp_nt_devmode = nt_devmode;
1541 return true;
1544 /****************************************************************
1545 _spoolss_OpenPrinterEx
1546 ****************************************************************/
1548 WERROR _spoolss_OpenPrinterEx(pipes_struct *p,
1549 struct spoolss_OpenPrinterEx *r)
1551 int snum;
1552 Printer_entry *Printer=NULL;
1554 if (!r->in.printername) {
1555 return WERR_INVALID_PARAM;
1558 /* some sanity check because you can open a printer or a print server */
1559 /* aka: \\server\printer or \\server */
1561 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1563 if (!open_printer_hnd(p, r->out.handle, r->in.printername, 0)) {
1564 ZERO_STRUCTP(r->out.handle);
1565 return WERR_INVALID_PARAM;
1568 Printer = find_printer_index_by_hnd(p, r->out.handle);
1569 if ( !Printer ) {
1570 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1571 "handle we created for printer %s\n", r->in.printername));
1572 close_printer_handle(p, r->out.handle);
1573 ZERO_STRUCTP(r->out.handle);
1574 return WERR_INVALID_PARAM;
1578 * First case: the user is opening the print server:
1580 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1581 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1583 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1584 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1585 * or if the user is listed in the smb.conf printer admin parameter.
1587 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1588 * client view printer folder, but does not show the MSAPW.
1590 * Note: this test needs code to check access rights here too. Jeremy
1591 * could you look at this?
1593 * Second case: the user is opening a printer:
1594 * NT doesn't let us connect to a printer if the connecting user
1595 * doesn't have print permission.
1597 * Third case: user is opening a Port Monitor
1598 * access checks same as opening a handle to the print server.
1601 switch (Printer->printer_type )
1603 case SPLHND_SERVER:
1604 case SPLHND_PORTMON_TCP:
1605 case SPLHND_PORTMON_LOCAL:
1606 /* Printserver handles use global struct... */
1608 snum = -1;
1610 /* Map standard access rights to object specific access rights */
1612 se_map_standard(&r->in.access_mask,
1613 &printserver_std_mapping);
1615 /* Deny any object specific bits that don't apply to print
1616 servers (i.e printer and job specific bits) */
1618 r->in.access_mask &= SPECIFIC_RIGHTS_MASK;
1620 if (r->in.access_mask &
1621 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1622 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1623 close_printer_handle(p, r->out.handle);
1624 ZERO_STRUCTP(r->out.handle);
1625 return WERR_ACCESS_DENIED;
1628 /* Allow admin access */
1630 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1632 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1634 if (!lp_ms_add_printer_wizard()) {
1635 close_printer_handle(p, r->out.handle);
1636 ZERO_STRUCTP(r->out.handle);
1637 return WERR_ACCESS_DENIED;
1640 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1641 and not a printer admin, then fail */
1643 if ((p->server_info->utok.uid != sec_initial_uid()) &&
1644 !user_has_privileges(p->server_info->ptok,
1645 &se_printop ) &&
1646 !token_contains_name_in_list(
1647 uidtoname(p->server_info->utok.uid),
1648 NULL, NULL,
1649 p->server_info->ptok,
1650 lp_printer_admin(snum))) {
1651 close_printer_handle(p, r->out.handle);
1652 ZERO_STRUCTP(r->out.handle);
1653 return WERR_ACCESS_DENIED;
1656 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1658 else
1660 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1663 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1664 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1666 /* We fall through to return WERR_OK */
1667 break;
1669 case SPLHND_PRINTER:
1670 /* NT doesn't let us connect to a printer if the connecting user
1671 doesn't have print permission. */
1673 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1674 close_printer_handle(p, r->out.handle);
1675 ZERO_STRUCTP(r->out.handle);
1676 return WERR_BADFID;
1679 if (r->in.access_mask == SEC_FLAG_MAXIMUM_ALLOWED) {
1680 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1683 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1685 /* map an empty access mask to the minimum access mask */
1686 if (r->in.access_mask == 0x0)
1687 r->in.access_mask = PRINTER_ACCESS_USE;
1690 * If we are not serving the printer driver for this printer,
1691 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1692 * will keep NT clients happy --jerry
1695 if (lp_use_client_driver(snum)
1696 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1698 r->in.access_mask = PRINTER_ACCESS_USE;
1701 /* check smb.conf parameters and the the sec_desc */
1703 if ( !check_access(get_client_fd(), lp_hostsallow(snum), lp_hostsdeny(snum)) ) {
1704 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1705 ZERO_STRUCTP(r->out.handle);
1706 return WERR_ACCESS_DENIED;
1709 if (!user_ok_token(uidtoname(p->server_info->utok.uid), NULL,
1710 p->server_info->ptok, snum) ||
1711 !print_access_check(p->server_info, snum,
1712 r->in.access_mask)) {
1713 DEBUG(3, ("access DENIED for printer open\n"));
1714 close_printer_handle(p, r->out.handle);
1715 ZERO_STRUCTP(r->out.handle);
1716 return WERR_ACCESS_DENIED;
1719 if ((r->in.access_mask & SPECIFIC_RIGHTS_MASK)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1720 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1721 close_printer_handle(p, r->out.handle);
1722 ZERO_STRUCTP(r->out.handle);
1723 return WERR_ACCESS_DENIED;
1726 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1727 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1728 else
1729 r->in.access_mask = PRINTER_ACCESS_USE;
1731 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1732 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1734 break;
1736 default:
1737 /* sanity check to prevent programmer error */
1738 ZERO_STRUCTP(r->out.handle);
1739 return WERR_BADFID;
1742 Printer->access_granted = r->in.access_mask;
1745 * If the client sent a devmode in the OpenPrinter() call, then
1746 * save it here in case we get a job submission on this handle
1749 if ((Printer->printer_type != SPLHND_SERVER) &&
1750 r->in.devmode_ctr.devmode) {
1751 convert_devicemode(Printer->sharename,
1752 r->in.devmode_ctr.devmode,
1753 &Printer->nt_devmode);
1756 #if 0 /* JERRY -- I'm doubtful this is really effective */
1757 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1758 optimization in Windows 2000 clients --jerry */
1760 if ( (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1761 && (RA_WIN2K == get_remote_arch()) )
1763 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1764 sys_usleep( 500000 );
1766 #endif
1768 return WERR_OK;
1771 /****************************************************************************
1772 ****************************************************************************/
1774 static bool printer_info2_to_nt_printer_info2(struct spoolss_SetPrinterInfo2 *r,
1775 NT_PRINTER_INFO_LEVEL_2 *d)
1777 DEBUG(7,("printer_info2_to_nt_printer_info2\n"));
1779 if (!r || !d) {
1780 return false;
1783 d->attributes = r->attributes;
1784 d->priority = r->priority;
1785 d->default_priority = r->defaultpriority;
1786 d->starttime = r->starttime;
1787 d->untiltime = r->untiltime;
1788 d->status = r->status;
1789 d->cjobs = r->cjobs;
1791 fstrcpy(d->servername, r->servername);
1792 fstrcpy(d->printername, r->printername);
1793 fstrcpy(d->sharename, r->sharename);
1794 fstrcpy(d->portname, r->portname);
1795 fstrcpy(d->drivername, r->drivername);
1796 slprintf(d->comment, sizeof(d->comment)-1, "%s", r->comment);
1797 fstrcpy(d->location, r->location);
1798 fstrcpy(d->sepfile, r->sepfile);
1799 fstrcpy(d->printprocessor, r->printprocessor);
1800 fstrcpy(d->datatype, r->datatype);
1801 fstrcpy(d->parameters, r->parameters);
1803 return true;
1806 /****************************************************************************
1807 ****************************************************************************/
1809 static bool convert_printer_info(struct spoolss_SetPrinterInfoCtr *info_ctr,
1810 NT_PRINTER_INFO_LEVEL *printer)
1812 bool ret;
1814 switch (info_ctr->level) {
1815 case 2:
1816 /* allocate memory if needed. Messy because
1817 convert_printer_info is used to update an existing
1818 printer or build a new one */
1820 if (!printer->info_2) {
1821 printer->info_2 = TALLOC_ZERO_P(printer, NT_PRINTER_INFO_LEVEL_2);
1822 if (!printer->info_2) {
1823 DEBUG(0,("convert_printer_info: "
1824 "talloc() failed!\n"));
1825 return false;
1829 ret = printer_info2_to_nt_printer_info2(info_ctr->info.info2,
1830 printer->info_2);
1831 printer->info_2->setuptime = time(NULL);
1832 return ret;
1835 return false;
1838 /****************************************************************
1839 _spoolss_ClosePrinter
1840 ****************************************************************/
1842 WERROR _spoolss_ClosePrinter(pipes_struct *p,
1843 struct spoolss_ClosePrinter *r)
1845 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
1847 if (Printer && Printer->document_started) {
1848 struct spoolss_EndDocPrinter e;
1850 e.in.handle = r->in.handle;
1852 _spoolss_EndDocPrinter(p, &e);
1855 if (!close_printer_handle(p, r->in.handle))
1856 return WERR_BADFID;
1858 /* clear the returned printer handle. Observed behavior
1859 from Win2k server. Don't think this really matters.
1860 Previous code just copied the value of the closed
1861 handle. --jerry */
1863 ZERO_STRUCTP(r->out.handle);
1865 return WERR_OK;
1868 /****************************************************************
1869 _spoolss_DeletePrinter
1870 ****************************************************************/
1872 WERROR _spoolss_DeletePrinter(pipes_struct *p,
1873 struct spoolss_DeletePrinter *r)
1875 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
1876 WERROR result;
1878 if (Printer && Printer->document_started) {
1879 struct spoolss_EndDocPrinter e;
1881 e.in.handle = r->in.handle;
1883 _spoolss_EndDocPrinter(p, &e);
1886 result = delete_printer_handle(p, r->in.handle);
1888 update_c_setprinter(false);
1890 return result;
1893 /*******************************************************************
1894 * static function to lookup the version id corresponding to an
1895 * long architecture string
1896 ******************************************************************/
1898 static const struct print_architecture_table_node archi_table[]= {
1900 {"Windows 4.0", SPL_ARCH_WIN40, 0 },
1901 {"Windows NT x86", SPL_ARCH_W32X86, 2 },
1902 {"Windows NT R4000", SPL_ARCH_W32MIPS, 2 },
1903 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA, 2 },
1904 {"Windows NT PowerPC", SPL_ARCH_W32PPC, 2 },
1905 {"Windows IA64", SPL_ARCH_IA64, 3 },
1906 {"Windows x64", SPL_ARCH_X64, 3 },
1907 {NULL, "", -1 }
1910 static int get_version_id(const char *arch)
1912 int i;
1914 for (i=0; archi_table[i].long_archi != NULL; i++)
1916 if (strcmp(arch, archi_table[i].long_archi) == 0)
1917 return (archi_table[i].version);
1920 return -1;
1923 /****************************************************************
1924 _spoolss_DeletePrinterDriver
1925 ****************************************************************/
1927 WERROR _spoolss_DeletePrinterDriver(pipes_struct *p,
1928 struct spoolss_DeletePrinterDriver *r)
1931 struct spoolss_DriverInfo8 *info = NULL;
1932 struct spoolss_DriverInfo8 *info_win2k = NULL;
1933 int version;
1934 WERROR status;
1935 WERROR status_win2k = WERR_ACCESS_DENIED;
1936 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1938 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1939 and not a printer admin, then fail */
1941 if ( (p->server_info->utok.uid != sec_initial_uid())
1942 && !user_has_privileges(p->server_info->ptok, &se_printop )
1943 && !token_contains_name_in_list(
1944 uidtoname(p->server_info->utok.uid), NULL,
1945 NULL, p->server_info->ptok,
1946 lp_printer_admin(-1)) )
1948 return WERR_ACCESS_DENIED;
1951 /* check that we have a valid driver name first */
1953 if ((version = get_version_id(r->in.architecture)) == -1)
1954 return WERR_INVALID_ENVIRONMENT;
1956 if (!W_ERROR_IS_OK(get_a_printer_driver(p->mem_ctx, &info, r->in.driver,
1957 r->in.architecture,
1958 version)))
1960 /* try for Win2k driver if "Windows NT x86" */
1962 if ( version == 2 ) {
1963 version = 3;
1964 if (!W_ERROR_IS_OK(get_a_printer_driver(p->mem_ctx,
1965 &info,
1966 r->in.driver,
1967 r->in.architecture,
1968 version))) {
1969 status = WERR_UNKNOWN_PRINTER_DRIVER;
1970 goto done;
1973 /* otherwise it was a failure */
1974 else {
1975 status = WERR_UNKNOWN_PRINTER_DRIVER;
1976 goto done;
1981 if (printer_driver_in_use(info)) {
1982 status = WERR_PRINTER_DRIVER_IN_USE;
1983 goto done;
1986 if ( version == 2 )
1988 if (W_ERROR_IS_OK(get_a_printer_driver(p->mem_ctx,
1989 &info_win2k,
1990 r->in.driver,
1991 r->in.architecture, 3)))
1993 /* if we get to here, we now have 2 driver info structures to remove */
1994 /* remove the Win2k driver first*/
1996 status_win2k = delete_printer_driver(
1997 p, info_win2k, 3, false);
1998 free_a_printer_driver(info_win2k);
2000 /* this should not have failed---if it did, report to client */
2001 if ( !W_ERROR_IS_OK(status_win2k) )
2003 status = status_win2k;
2004 goto done;
2009 status = delete_printer_driver(p, info, version, false);
2011 /* if at least one of the deletes succeeded return OK */
2013 if ( W_ERROR_IS_OK(status) || W_ERROR_IS_OK(status_win2k) )
2014 status = WERR_OK;
2016 done:
2017 free_a_printer_driver(info);
2019 return status;
2022 /****************************************************************
2023 _spoolss_DeletePrinterDriverEx
2024 ****************************************************************/
2026 WERROR _spoolss_DeletePrinterDriverEx(pipes_struct *p,
2027 struct spoolss_DeletePrinterDriverEx *r)
2029 struct spoolss_DriverInfo8 *info = NULL;
2030 struct spoolss_DriverInfo8 *info_win2k = NULL;
2031 int version;
2032 bool delete_files;
2033 WERROR status;
2034 WERROR status_win2k = WERR_ACCESS_DENIED;
2035 SE_PRIV se_printop = SE_PRINT_OPERATOR;
2037 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2038 and not a printer admin, then fail */
2040 if ( (p->server_info->utok.uid != sec_initial_uid())
2041 && !user_has_privileges(p->server_info->ptok, &se_printop )
2042 && !token_contains_name_in_list(
2043 uidtoname(p->server_info->utok.uid), NULL, NULL,
2044 p->server_info->ptok, lp_printer_admin(-1)) )
2046 return WERR_ACCESS_DENIED;
2049 /* check that we have a valid driver name first */
2050 if ((version = get_version_id(r->in.architecture)) == -1) {
2051 /* this is what NT returns */
2052 return WERR_INVALID_ENVIRONMENT;
2055 if (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
2056 version = r->in.version;
2058 status = get_a_printer_driver(p->mem_ctx, &info, r->in.driver,
2059 r->in.architecture, version);
2061 if ( !W_ERROR_IS_OK(status) )
2064 * if the client asked for a specific version,
2065 * or this is something other than Windows NT x86,
2066 * then we've failed
2069 if ( (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
2070 goto done;
2072 /* try for Win2k driver if "Windows NT x86" */
2074 version = 3;
2075 if (!W_ERROR_IS_OK(get_a_printer_driver(p->mem_ctx, &info, r->in.driver,
2076 r->in.architecture,
2077 version))) {
2078 status = WERR_UNKNOWN_PRINTER_DRIVER;
2079 goto done;
2083 if (printer_driver_in_use(info)) {
2084 status = WERR_PRINTER_DRIVER_IN_USE;
2085 goto done;
2089 * we have a couple of cases to consider.
2090 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
2091 * then the delete should fail if **any** files overlap with
2092 * other drivers
2093 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
2094 * non-overlapping files
2095 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
2096 * is set, the do not delete any files
2097 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2100 delete_files = r->in.delete_flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
2102 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
2104 if (delete_files && printer_driver_files_in_use(info, info) & (r->in.delete_flags & DPD_DELETE_ALL_FILES)) {
2105 /* no idea of the correct error here */
2106 status = WERR_ACCESS_DENIED;
2107 goto done;
2111 /* also check for W32X86/3 if necessary; maybe we already have? */
2113 if ( (version == 2) && ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
2114 if (W_ERROR_IS_OK(get_a_printer_driver(p->mem_ctx, &info_win2k,
2115 r->in.driver,
2116 r->in.architecture, 3)))
2119 if (delete_files && printer_driver_files_in_use(info, info_win2k) & (r->in.delete_flags & DPD_DELETE_ALL_FILES) ) {
2120 /* no idea of the correct error here */
2121 free_a_printer_driver(info_win2k);
2122 status = WERR_ACCESS_DENIED;
2123 goto done;
2126 /* if we get to here, we now have 2 driver info structures to remove */
2127 /* remove the Win2k driver first*/
2129 status_win2k = delete_printer_driver(
2130 p, info_win2k, 3, delete_files);
2131 free_a_printer_driver(info_win2k);
2133 /* this should not have failed---if it did, report to client */
2135 if ( !W_ERROR_IS_OK(status_win2k) )
2136 goto done;
2140 status = delete_printer_driver(p, info, version, delete_files);
2142 if ( W_ERROR_IS_OK(status) || W_ERROR_IS_OK(status_win2k) )
2143 status = WERR_OK;
2144 done:
2145 free_a_printer_driver(info);
2147 return status;
2151 /****************************************************************************
2152 Internal routine for removing printerdata
2153 ***************************************************************************/
2155 static WERROR delete_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char *key, const char *value )
2157 return delete_printer_data( printer->info_2, key, value );
2160 /****************************************************************************
2161 Internal routine for storing printerdata
2162 ***************************************************************************/
2164 WERROR set_printer_dataex(NT_PRINTER_INFO_LEVEL *printer,
2165 const char *key, const char *value,
2166 uint32_t type, uint8_t *data, int real_len)
2168 /* the registry objects enforce uniqueness based on value name */
2170 return add_printer_data( printer->info_2, key, value, type, data, real_len );
2173 /********************************************************************
2174 GetPrinterData on a printer server Handle.
2175 ********************************************************************/
2177 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2178 const char *value,
2179 enum winreg_Type *type,
2180 union spoolss_PrinterData *data)
2182 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2184 if (!StrCaseCmp(value, "W3SvcInstalled")) {
2185 *type = REG_DWORD;
2186 data->value = 0x00;
2187 return WERR_OK;
2190 if (!StrCaseCmp(value, "BeepEnabled")) {
2191 *type = REG_DWORD;
2192 data->value = 0x00;
2193 return WERR_OK;
2196 if (!StrCaseCmp(value, "EventLog")) {
2197 *type = REG_DWORD;
2198 /* formally was 0x1b */
2199 data->value = 0x00;
2200 return WERR_OK;
2203 if (!StrCaseCmp(value, "NetPopup")) {
2204 *type = REG_DWORD;
2205 data->value = 0x00;
2206 return WERR_OK;
2209 if (!StrCaseCmp(value, "MajorVersion")) {
2210 *type = REG_DWORD;
2212 /* Windows NT 4.0 seems to not allow uploading of drivers
2213 to a server that reports 0x3 as the MajorVersion.
2214 need to investigate more how Win2k gets around this .
2215 -- jerry */
2217 if (RA_WINNT == get_remote_arch()) {
2218 data->value = 0x02;
2219 } else {
2220 data->value = 0x03;
2223 return WERR_OK;
2226 if (!StrCaseCmp(value, "MinorVersion")) {
2227 *type = REG_DWORD;
2228 data->value = 0x00;
2229 return WERR_OK;
2232 /* REG_BINARY
2233 * uint32_t size = 0x114
2234 * uint32_t major = 5
2235 * uint32_t minor = [0|1]
2236 * uint32_t build = [2195|2600]
2237 * extra unicode string = e.g. "Service Pack 3"
2239 if (!StrCaseCmp(value, "OSVersion")) {
2240 DATA_BLOB blob;
2241 enum ndr_err_code ndr_err;
2242 struct spoolss_OSVersion os;
2244 os.major = 5; /* Windows 2000 == 5.0 */
2245 os.minor = 0;
2246 os.build = 2195; /* build */
2247 os.extra_string = ""; /* leave extra string empty */
2249 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, NULL, &os,
2250 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2251 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2252 return WERR_GENERAL_FAILURE;
2255 *type = REG_BINARY;
2256 data->binary = blob;
2258 return WERR_OK;
2262 if (!StrCaseCmp(value, "DefaultSpoolDirectory")) {
2263 *type = REG_SZ;
2265 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2266 W_ERROR_HAVE_NO_MEMORY(data->string);
2268 return WERR_OK;
2271 if (!StrCaseCmp(value, "Architecture")) {
2272 *type = REG_SZ;
2273 data->string = talloc_strdup(mem_ctx,
2274 lp_parm_const_string(GLOBAL_SECTION_SNUM, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86));
2275 W_ERROR_HAVE_NO_MEMORY(data->string);
2277 return WERR_OK;
2280 if (!StrCaseCmp(value, "DsPresent")) {
2281 *type = REG_DWORD;
2283 /* only show the publish check box if we are a
2284 member of a AD domain */
2286 if (lp_security() == SEC_ADS) {
2287 data->value = 0x01;
2288 } else {
2289 data->value = 0x00;
2291 return WERR_OK;
2294 if (!StrCaseCmp(value, "DNSMachineName")) {
2295 const char *hostname = get_mydnsfullname();
2297 if (!hostname) {
2298 return WERR_BADFILE;
2301 *type = REG_SZ;
2302 data->string = talloc_strdup(mem_ctx, hostname);
2303 W_ERROR_HAVE_NO_MEMORY(data->string);
2305 return WERR_OK;
2308 *type = REG_NONE;
2310 return WERR_INVALID_PARAM;
2313 /****************************************************************
2314 _spoolss_GetPrinterData
2315 ****************************************************************/
2317 WERROR _spoolss_GetPrinterData(pipes_struct *p,
2318 struct spoolss_GetPrinterData *r)
2320 struct spoolss_GetPrinterDataEx r2;
2322 r2.in.handle = r->in.handle;
2323 r2.in.key_name = "PrinterDriverData";
2324 r2.in.value_name = r->in.value_name;
2325 r2.in.offered = r->in.offered;
2326 r2.out.type = r->out.type;
2327 r2.out.data = r->out.data;
2328 r2.out.needed = r->out.needed;
2330 return _spoolss_GetPrinterDataEx(p, &r2);
2333 /*********************************************************
2334 Connect to the client machine.
2335 **********************************************************/
2337 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2338 struct sockaddr_storage *client_ss, const char *remote_machine)
2340 NTSTATUS ret;
2341 struct cli_state *the_cli;
2342 struct sockaddr_storage rm_addr;
2343 char addr[INET6_ADDRSTRLEN];
2345 if ( is_zero_addr((struct sockaddr *)client_ss) ) {
2346 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2347 remote_machine));
2348 if ( !resolve_name( remote_machine, &rm_addr, 0x20, false) ) {
2349 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2350 return false;
2352 print_sockaddr(addr, sizeof(addr), &rm_addr);
2353 } else {
2354 rm_addr = *client_ss;
2355 print_sockaddr(addr, sizeof(addr), &rm_addr);
2356 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2357 addr));
2360 if (ismyaddr((struct sockaddr *)&rm_addr)) {
2361 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2362 addr));
2363 return false;
2366 /* setup the connection */
2367 ret = cli_full_connection( &the_cli, global_myname(), remote_machine,
2368 &rm_addr, 0, "IPC$", "IPC",
2369 "", /* username */
2370 "", /* domain */
2371 "", /* password */
2372 0, lp_client_signing(), NULL );
2374 if ( !NT_STATUS_IS_OK( ret ) ) {
2375 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2376 remote_machine ));
2377 return false;
2380 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2381 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2382 cli_shutdown(the_cli);
2383 return false;
2387 * Ok - we have an anonymous connection to the IPC$ share.
2388 * Now start the NT Domain stuff :-).
2391 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2392 if (!NT_STATUS_IS_OK(ret)) {
2393 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2394 remote_machine, nt_errstr(ret)));
2395 cli_shutdown(the_cli);
2396 return false;
2399 return true;
2402 /***************************************************************************
2403 Connect to the client.
2404 ****************************************************************************/
2406 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2407 uint32_t localprinter, uint32_t type,
2408 struct policy_handle *handle,
2409 struct sockaddr_storage *client_ss)
2411 WERROR result;
2412 NTSTATUS status;
2415 * If it's the first connection, contact the client
2416 * and connect to the IPC$ share anonymously
2418 if (smb_connections==0) {
2419 fstring unix_printer;
2421 fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */
2423 if ( !spoolss_connect_to_client( &notify_cli_pipe, client_ss, unix_printer ))
2424 return false;
2426 messaging_register(smbd_messaging_context(), NULL,
2427 MSG_PRINTER_NOTIFY2,
2428 receive_notify2_message_list);
2429 /* Tell the connections db we're now interested in printer
2430 * notify messages. */
2431 register_message_flags(true, FLAG_MSG_PRINT_NOTIFY);
2435 * Tell the specific printing tdb we want messages for this printer
2436 * by registering our PID.
2439 if (!print_notify_register_pid(snum))
2440 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", printer ));
2442 smb_connections++;
2444 status = rpccli_spoolss_ReplyOpenPrinter(notify_cli_pipe, talloc_tos(),
2445 printer,
2446 localprinter,
2447 type,
2449 NULL,
2450 handle,
2451 &result);
2452 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
2453 DEBUG(5,("srv_spoolss_reply_open_printer: Client RPC returned [%s]\n",
2454 win_errstr(result)));
2456 return (W_ERROR_IS_OK(result));
2459 /****************************************************************
2460 ****************************************************************/
2462 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2463 const struct spoolss_NotifyOption *r)
2465 struct spoolss_NotifyOption *option;
2466 uint32_t i,k;
2468 if (!r) {
2469 return NULL;
2472 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2473 if (!option) {
2474 return NULL;
2477 *option = *r;
2479 if (!option->count) {
2480 return option;
2483 option->types = talloc_zero_array(option,
2484 struct spoolss_NotifyOptionType, option->count);
2485 if (!option->types) {
2486 talloc_free(option);
2487 return NULL;
2490 for (i=0; i < option->count; i++) {
2491 option->types[i] = r->types[i];
2493 if (option->types[i].count) {
2494 option->types[i].fields = talloc_zero_array(option,
2495 union spoolss_Field, option->types[i].count);
2496 if (!option->types[i].fields) {
2497 talloc_free(option);
2498 return NULL;
2500 for (k=0; k<option->types[i].count; k++) {
2501 option->types[i].fields[k] =
2502 r->types[i].fields[k];
2507 return option;
2510 /****************************************************************
2511 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2513 * before replying OK: status=0 a rpc call is made to the workstation
2514 * asking ReplyOpenPrinter
2516 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2517 * called from api_spoolss_rffpcnex
2518 ****************************************************************/
2520 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(pipes_struct *p,
2521 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2523 int snum = -1;
2524 struct spoolss_NotifyOption *option = r->in.notify_options;
2525 struct sockaddr_storage client_ss;
2527 /* store the notify value in the printer struct */
2529 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
2531 if (!Printer) {
2532 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2533 "Invalid handle (%s:%u:%u).\n",
2534 OUR_HANDLE(r->in.handle)));
2535 return WERR_BADFID;
2538 Printer->notify.flags = r->in.flags;
2539 Printer->notify.options = r->in.options;
2540 Printer->notify.printerlocal = r->in.printer_local;
2542 TALLOC_FREE(Printer->notify.option);
2543 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2545 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2547 /* Connect to the client machine and send a ReplyOpenPrinter */
2549 if ( Printer->printer_type == SPLHND_SERVER)
2550 snum = -1;
2551 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2552 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2553 return WERR_BADFID;
2555 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2556 "client_address is %s\n", p->client_address));
2558 if (!interpret_string_addr(&client_ss, p->client_address,
2559 AI_NUMERICHOST)) {
2560 return WERR_SERVER_UNAVAILABLE;
2563 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2564 Printer->notify.printerlocal, 1,
2565 &Printer->notify.client_hnd, &client_ss))
2566 return WERR_SERVER_UNAVAILABLE;
2568 Printer->notify.client_connected = true;
2570 return WERR_OK;
2573 /*******************************************************************
2574 * fill a notify_info_data with the servername
2575 ********************************************************************/
2577 void spoolss_notify_server_name(int snum,
2578 struct spoolss_Notify *data,
2579 print_queue_struct *queue,
2580 NT_PRINTER_INFO_LEVEL *printer,
2581 TALLOC_CTX *mem_ctx)
2583 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->servername);
2586 /*******************************************************************
2587 * fill a notify_info_data with the printername (not including the servername).
2588 ********************************************************************/
2590 void spoolss_notify_printer_name(int snum,
2591 struct spoolss_Notify *data,
2592 print_queue_struct *queue,
2593 NT_PRINTER_INFO_LEVEL *printer,
2594 TALLOC_CTX *mem_ctx)
2596 /* the notify name should not contain the \\server\ part */
2597 char *p = strrchr(printer->info_2->printername, '\\');
2599 if (!p) {
2600 p = printer->info_2->printername;
2601 } else {
2602 p++;
2605 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2608 /*******************************************************************
2609 * fill a notify_info_data with the servicename
2610 ********************************************************************/
2612 void spoolss_notify_share_name(int snum,
2613 struct spoolss_Notify *data,
2614 print_queue_struct *queue,
2615 NT_PRINTER_INFO_LEVEL *printer,
2616 TALLOC_CTX *mem_ctx)
2618 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
2621 /*******************************************************************
2622 * fill a notify_info_data with the port name
2623 ********************************************************************/
2625 void spoolss_notify_port_name(int snum,
2626 struct spoolss_Notify *data,
2627 print_queue_struct *queue,
2628 NT_PRINTER_INFO_LEVEL *printer,
2629 TALLOC_CTX *mem_ctx)
2631 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->portname);
2634 /*******************************************************************
2635 * fill a notify_info_data with the printername
2636 * but it doesn't exist, have to see what to do
2637 ********************************************************************/
2639 void spoolss_notify_driver_name(int snum,
2640 struct spoolss_Notify *data,
2641 print_queue_struct *queue,
2642 NT_PRINTER_INFO_LEVEL *printer,
2643 TALLOC_CTX *mem_ctx)
2645 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->drivername);
2648 /*******************************************************************
2649 * fill a notify_info_data with the comment
2650 ********************************************************************/
2652 void spoolss_notify_comment(int snum,
2653 struct spoolss_Notify *data,
2654 print_queue_struct *queue,
2655 NT_PRINTER_INFO_LEVEL *printer,
2656 TALLOC_CTX *mem_ctx)
2658 char *p;
2660 if (*printer->info_2->comment == '\0') {
2661 p = lp_comment(snum);
2662 } else {
2663 p = printer->info_2->comment;
2666 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->comment);
2669 /*******************************************************************
2670 * fill a notify_info_data with the comment
2671 * location = "Room 1, floor 2, building 3"
2672 ********************************************************************/
2674 void spoolss_notify_location(int snum,
2675 struct spoolss_Notify *data,
2676 print_queue_struct *queue,
2677 NT_PRINTER_INFO_LEVEL *printer,
2678 TALLOC_CTX *mem_ctx)
2680 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->location);
2683 /*******************************************************************
2684 * fill a notify_info_data with the device mode
2685 * jfm:xxxx don't to it for know but that's a real problem !!!
2686 ********************************************************************/
2688 static void spoolss_notify_devmode(int snum,
2689 struct spoolss_Notify *data,
2690 print_queue_struct *queue,
2691 NT_PRINTER_INFO_LEVEL *printer,
2692 TALLOC_CTX *mem_ctx)
2694 /* for a dummy implementation we have to zero the fields */
2695 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2698 /*******************************************************************
2699 * fill a notify_info_data with the separator file name
2700 ********************************************************************/
2702 void spoolss_notify_sepfile(int snum,
2703 struct spoolss_Notify *data,
2704 print_queue_struct *queue,
2705 NT_PRINTER_INFO_LEVEL *printer,
2706 TALLOC_CTX *mem_ctx)
2708 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->sepfile);
2711 /*******************************************************************
2712 * fill a notify_info_data with the print processor
2713 * jfm:xxxx return always winprint to indicate we don't do anything to it
2714 ********************************************************************/
2716 void spoolss_notify_print_processor(int snum,
2717 struct spoolss_Notify *data,
2718 print_queue_struct *queue,
2719 NT_PRINTER_INFO_LEVEL *printer,
2720 TALLOC_CTX *mem_ctx)
2722 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->printprocessor);
2725 /*******************************************************************
2726 * fill a notify_info_data with the print processor options
2727 * jfm:xxxx send an empty string
2728 ********************************************************************/
2730 void spoolss_notify_parameters(int snum,
2731 struct spoolss_Notify *data,
2732 print_queue_struct *queue,
2733 NT_PRINTER_INFO_LEVEL *printer,
2734 TALLOC_CTX *mem_ctx)
2736 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->parameters);
2739 /*******************************************************************
2740 * fill a notify_info_data with the data type
2741 * jfm:xxxx always send RAW as data type
2742 ********************************************************************/
2744 void spoolss_notify_datatype(int snum,
2745 struct spoolss_Notify *data,
2746 print_queue_struct *queue,
2747 NT_PRINTER_INFO_LEVEL *printer,
2748 TALLOC_CTX *mem_ctx)
2750 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->datatype);
2753 /*******************************************************************
2754 * fill a notify_info_data with the security descriptor
2755 * jfm:xxxx send an null pointer to say no security desc
2756 * have to implement security before !
2757 ********************************************************************/
2759 static void spoolss_notify_security_desc(int snum,
2760 struct spoolss_Notify *data,
2761 print_queue_struct *queue,
2762 NT_PRINTER_INFO_LEVEL *printer,
2763 TALLOC_CTX *mem_ctx)
2765 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data,
2766 printer->info_2->secdesc_buf->sd_size,
2767 printer->info_2->secdesc_buf->sd);
2770 /*******************************************************************
2771 * fill a notify_info_data with the attributes
2772 * jfm:xxxx a samba printer is always shared
2773 ********************************************************************/
2775 void spoolss_notify_attributes(int snum,
2776 struct spoolss_Notify *data,
2777 print_queue_struct *queue,
2778 NT_PRINTER_INFO_LEVEL *printer,
2779 TALLOC_CTX *mem_ctx)
2781 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->attributes);
2784 /*******************************************************************
2785 * fill a notify_info_data with the priority
2786 ********************************************************************/
2788 static void spoolss_notify_priority(int snum,
2789 struct spoolss_Notify *data,
2790 print_queue_struct *queue,
2791 NT_PRINTER_INFO_LEVEL *printer,
2792 TALLOC_CTX *mem_ctx)
2794 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->priority);
2797 /*******************************************************************
2798 * fill a notify_info_data with the default priority
2799 ********************************************************************/
2801 static void spoolss_notify_default_priority(int snum,
2802 struct spoolss_Notify *data,
2803 print_queue_struct *queue,
2804 NT_PRINTER_INFO_LEVEL *printer,
2805 TALLOC_CTX *mem_ctx)
2807 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->default_priority);
2810 /*******************************************************************
2811 * fill a notify_info_data with the start time
2812 ********************************************************************/
2814 static void spoolss_notify_start_time(int snum,
2815 struct spoolss_Notify *data,
2816 print_queue_struct *queue,
2817 NT_PRINTER_INFO_LEVEL *printer,
2818 TALLOC_CTX *mem_ctx)
2820 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->starttime);
2823 /*******************************************************************
2824 * fill a notify_info_data with the until time
2825 ********************************************************************/
2827 static void spoolss_notify_until_time(int snum,
2828 struct spoolss_Notify *data,
2829 print_queue_struct *queue,
2830 NT_PRINTER_INFO_LEVEL *printer,
2831 TALLOC_CTX *mem_ctx)
2833 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->untiltime);
2836 /*******************************************************************
2837 * fill a notify_info_data with the status
2838 ********************************************************************/
2840 static void spoolss_notify_status(int snum,
2841 struct spoolss_Notify *data,
2842 print_queue_struct *queue,
2843 NT_PRINTER_INFO_LEVEL *printer,
2844 TALLOC_CTX *mem_ctx)
2846 print_status_struct status;
2848 print_queue_length(snum, &status);
2849 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
2852 /*******************************************************************
2853 * fill a notify_info_data with the number of jobs queued
2854 ********************************************************************/
2856 void spoolss_notify_cjobs(int snum,
2857 struct spoolss_Notify *data,
2858 print_queue_struct *queue,
2859 NT_PRINTER_INFO_LEVEL *printer,
2860 TALLOC_CTX *mem_ctx)
2862 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, print_queue_length(snum, NULL));
2865 /*******************************************************************
2866 * fill a notify_info_data with the average ppm
2867 ********************************************************************/
2869 static void spoolss_notify_average_ppm(int snum,
2870 struct spoolss_Notify *data,
2871 print_queue_struct *queue,
2872 NT_PRINTER_INFO_LEVEL *printer,
2873 TALLOC_CTX *mem_ctx)
2875 /* always respond 8 pages per minutes */
2876 /* a little hard ! */
2877 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->averageppm);
2880 /*******************************************************************
2881 * fill a notify_info_data with username
2882 ********************************************************************/
2884 static void spoolss_notify_username(int snum,
2885 struct spoolss_Notify *data,
2886 print_queue_struct *queue,
2887 NT_PRINTER_INFO_LEVEL *printer,
2888 TALLOC_CTX *mem_ctx)
2890 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
2893 /*******************************************************************
2894 * fill a notify_info_data with job status
2895 ********************************************************************/
2897 static void spoolss_notify_job_status(int snum,
2898 struct spoolss_Notify *data,
2899 print_queue_struct *queue,
2900 NT_PRINTER_INFO_LEVEL *printer,
2901 TALLOC_CTX *mem_ctx)
2903 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
2906 /*******************************************************************
2907 * fill a notify_info_data with job name
2908 ********************************************************************/
2910 static void spoolss_notify_job_name(int snum,
2911 struct spoolss_Notify *data,
2912 print_queue_struct *queue,
2913 NT_PRINTER_INFO_LEVEL *printer,
2914 TALLOC_CTX *mem_ctx)
2916 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
2919 /*******************************************************************
2920 * fill a notify_info_data with job status
2921 ********************************************************************/
2923 static void spoolss_notify_job_status_string(int snum,
2924 struct spoolss_Notify *data,
2925 print_queue_struct *queue,
2926 NT_PRINTER_INFO_LEVEL *printer,
2927 TALLOC_CTX *mem_ctx)
2930 * Now we're returning job status codes we just return a "" here. JRA.
2933 const char *p = "";
2935 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
2936 p = "unknown";
2938 switch (queue->status) {
2939 case LPQ_QUEUED:
2940 p = "Queued";
2941 break;
2942 case LPQ_PAUSED:
2943 p = ""; /* NT provides the paused string */
2944 break;
2945 case LPQ_SPOOLING:
2946 p = "Spooling";
2947 break;
2948 case LPQ_PRINTING:
2949 p = "Printing";
2950 break;
2952 #endif /* NO LONGER NEEDED. */
2954 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2957 /*******************************************************************
2958 * fill a notify_info_data with job time
2959 ********************************************************************/
2961 static void spoolss_notify_job_time(int snum,
2962 struct spoolss_Notify *data,
2963 print_queue_struct *queue,
2964 NT_PRINTER_INFO_LEVEL *printer,
2965 TALLOC_CTX *mem_ctx)
2967 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
2970 /*******************************************************************
2971 * fill a notify_info_data with job size
2972 ********************************************************************/
2974 static void spoolss_notify_job_size(int snum,
2975 struct spoolss_Notify *data,
2976 print_queue_struct *queue,
2977 NT_PRINTER_INFO_LEVEL *printer,
2978 TALLOC_CTX *mem_ctx)
2980 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
2983 /*******************************************************************
2984 * fill a notify_info_data with page info
2985 ********************************************************************/
2986 static void spoolss_notify_total_pages(int snum,
2987 struct spoolss_Notify *data,
2988 print_queue_struct *queue,
2989 NT_PRINTER_INFO_LEVEL *printer,
2990 TALLOC_CTX *mem_ctx)
2992 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
2995 /*******************************************************************
2996 * fill a notify_info_data with pages printed info.
2997 ********************************************************************/
2998 static void spoolss_notify_pages_printed(int snum,
2999 struct spoolss_Notify *data,
3000 print_queue_struct *queue,
3001 NT_PRINTER_INFO_LEVEL *printer,
3002 TALLOC_CTX *mem_ctx)
3004 /* Add code when back-end tracks this */
3005 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3008 /*******************************************************************
3009 Fill a notify_info_data with job position.
3010 ********************************************************************/
3012 static void spoolss_notify_job_position(int snum,
3013 struct spoolss_Notify *data,
3014 print_queue_struct *queue,
3015 NT_PRINTER_INFO_LEVEL *printer,
3016 TALLOC_CTX *mem_ctx)
3018 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
3021 /*******************************************************************
3022 Fill a notify_info_data with submitted time.
3023 ********************************************************************/
3025 static void spoolss_notify_submitted_time(int snum,
3026 struct spoolss_Notify *data,
3027 print_queue_struct *queue,
3028 NT_PRINTER_INFO_LEVEL *printer,
3029 TALLOC_CTX *mem_ctx)
3031 data->data.string.string = NULL;
3032 data->data.string.size = 0;
3034 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
3035 &data->data.string.string,
3036 &data->data.string.size);
3040 struct s_notify_info_data_table
3042 enum spoolss_NotifyType type;
3043 uint16_t field;
3044 const char *name;
3045 enum spoolss_NotifyTable variable_type;
3046 void (*fn) (int snum, struct spoolss_Notify *data,
3047 print_queue_struct *queue,
3048 NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx);
3051 /* A table describing the various print notification constants and
3052 whether the notification data is a pointer to a variable sized
3053 buffer, a one value uint32_t or a two value uint32_t. */
3055 static const struct s_notify_info_data_table notify_info_data_table[] =
3057 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3058 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3059 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
3060 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3061 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3062 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
3063 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
3064 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3065 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
3066 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3067 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3068 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3069 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
3070 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
3071 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3072 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
3073 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3074 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3075 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
3076 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
3077 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
3078 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
3079 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
3080 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3081 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
3082 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3083 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3084 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3085 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3086 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3087 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3088 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3089 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3090 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3091 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3092 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3093 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
3094 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
3095 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
3096 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
3097 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3098 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
3099 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
3100 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3101 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3102 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
3103 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
3104 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
3105 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
3108 /*******************************************************************
3109 Return the variable_type of info_data structure.
3110 ********************************************************************/
3112 static uint32_t variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3113 uint16_t field)
3115 int i=0;
3117 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3118 if ( (notify_info_data_table[i].type == type) &&
3119 (notify_info_data_table[i].field == field) ) {
3120 return notify_info_data_table[i].variable_type;
3124 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3126 return 0;
3129 /****************************************************************************
3130 ****************************************************************************/
3132 static bool search_notify(enum spoolss_NotifyType type,
3133 uint16_t field,
3134 int *value)
3136 int i;
3138 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3139 if (notify_info_data_table[i].type == type &&
3140 notify_info_data_table[i].field == field &&
3141 notify_info_data_table[i].fn != NULL) {
3142 *value = i;
3143 return true;
3147 return false;
3150 /****************************************************************************
3151 ****************************************************************************/
3153 void construct_info_data(struct spoolss_Notify *info_data,
3154 enum spoolss_NotifyType type,
3155 uint16_t field,
3156 int id)
3158 info_data->type = type;
3159 info_data->field.field = field;
3160 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3161 info_data->job_id = id;
3164 /*******************************************************************
3166 * fill a notify_info struct with info asked
3168 ********************************************************************/
3170 static bool construct_notify_printer_info(Printer_entry *print_hnd,
3171 struct spoolss_NotifyInfo *info,
3172 int snum,
3173 const struct spoolss_NotifyOptionType *option_type,
3174 uint32_t id,
3175 TALLOC_CTX *mem_ctx)
3177 int field_num,j;
3178 enum spoolss_NotifyType type;
3179 uint16_t field;
3181 struct spoolss_Notify *current_data;
3182 NT_PRINTER_INFO_LEVEL *printer = NULL;
3183 print_queue_struct *queue=NULL;
3185 type = option_type->type;
3187 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3188 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3189 option_type->count, lp_servicename(snum)));
3191 if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &printer, 2, lp_const_servicename(snum))))
3192 return false;
3194 for(field_num=0; field_num < option_type->count; field_num++) {
3195 field = option_type->fields[field_num].field;
3197 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3199 if (!search_notify(type, field, &j) )
3200 continue;
3202 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3203 struct spoolss_Notify,
3204 info->count + 1);
3205 if (info->notifies == NULL) {
3206 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3207 free_a_printer(&printer, 2);
3208 return false;
3211 current_data = &info->notifies[info->count];
3213 construct_info_data(current_data, type, field, id);
3215 DEBUG(10,("construct_notify_printer_info: calling [%s] snum=%d printername=[%s])\n",
3216 notify_info_data_table[j].name, snum, printer->info_2->printername ));
3218 notify_info_data_table[j].fn(snum, current_data, queue,
3219 printer, mem_ctx);
3221 info->count++;
3224 free_a_printer(&printer, 2);
3225 return true;
3228 /*******************************************************************
3230 * fill a notify_info struct with info asked
3232 ********************************************************************/
3234 static bool construct_notify_jobs_info(print_queue_struct *queue,
3235 struct spoolss_NotifyInfo *info,
3236 NT_PRINTER_INFO_LEVEL *printer,
3237 int snum,
3238 const struct spoolss_NotifyOptionType *option_type,
3239 uint32_t id,
3240 TALLOC_CTX *mem_ctx)
3242 int field_num,j;
3243 enum spoolss_NotifyType type;
3244 uint16_t field;
3245 struct spoolss_Notify *current_data;
3247 DEBUG(4,("construct_notify_jobs_info\n"));
3249 type = option_type->type;
3251 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3252 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3253 option_type->count));
3255 for(field_num=0; field_num<option_type->count; field_num++) {
3256 field = option_type->fields[field_num].field;
3258 if (!search_notify(type, field, &j) )
3259 continue;
3261 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3262 struct spoolss_Notify,
3263 info->count + 1);
3264 if (info->notifies == NULL) {
3265 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3266 return false;
3269 current_data=&(info->notifies[info->count]);
3271 construct_info_data(current_data, type, field, id);
3272 notify_info_data_table[j].fn(snum, current_data, queue,
3273 printer, mem_ctx);
3274 info->count++;
3277 return true;
3281 * JFM: The enumeration is not that simple, it's even non obvious.
3283 * let's take an example: I want to monitor the PRINTER SERVER for
3284 * the printer's name and the number of jobs currently queued.
3285 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3286 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3288 * I have 3 printers on the back of my server.
3290 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3291 * structures.
3292 * Number Data Id
3293 * 1 printer 1 name 1
3294 * 2 printer 1 cjob 1
3295 * 3 printer 2 name 2
3296 * 4 printer 2 cjob 2
3297 * 5 printer 3 name 3
3298 * 6 printer 3 name 3
3300 * that's the print server case, the printer case is even worse.
3303 /*******************************************************************
3305 * enumerate all printers on the printserver
3306 * fill a notify_info struct with info asked
3308 ********************************************************************/
3310 static WERROR printserver_notify_info(pipes_struct *p,
3311 struct policy_handle *hnd,
3312 struct spoolss_NotifyInfo *info,
3313 TALLOC_CTX *mem_ctx)
3315 int snum;
3316 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3317 int n_services=lp_numservices();
3318 int i;
3319 struct spoolss_NotifyOption *option;
3320 struct spoolss_NotifyOptionType option_type;
3322 DEBUG(4,("printserver_notify_info\n"));
3324 if (!Printer)
3325 return WERR_BADFID;
3327 option = Printer->notify.option;
3329 info->version = 2;
3330 info->notifies = NULL;
3331 info->count = 0;
3333 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3334 sending a ffpcn() request first */
3336 if ( !option )
3337 return WERR_BADFID;
3339 for (i=0; i<option->count; i++) {
3340 option_type = option->types[i];
3342 if (option_type.type != PRINTER_NOTIFY_TYPE)
3343 continue;
3345 for (snum=0; snum<n_services; snum++)
3347 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
3348 construct_notify_printer_info ( Printer, info, snum, &option_type, snum, mem_ctx );
3352 #if 0
3354 * Debugging information, don't delete.
3357 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3358 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3359 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3361 for (i=0; i<info->count; i++) {
3362 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3363 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3364 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3366 #endif
3368 return WERR_OK;
3371 /*******************************************************************
3373 * fill a notify_info struct with info asked
3375 ********************************************************************/
3377 static WERROR printer_notify_info(pipes_struct *p, struct policy_handle *hnd,
3378 struct spoolss_NotifyInfo *info,
3379 TALLOC_CTX *mem_ctx)
3381 int snum;
3382 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
3383 int i;
3384 uint32_t id;
3385 struct spoolss_NotifyOption *option;
3386 struct spoolss_NotifyOptionType option_type;
3387 int count,j;
3388 print_queue_struct *queue=NULL;
3389 print_status_struct status;
3391 DEBUG(4,("printer_notify_info\n"));
3393 if (!Printer)
3394 return WERR_BADFID;
3396 option = Printer->notify.option;
3397 id = 0x0;
3399 info->version = 2;
3400 info->notifies = NULL;
3401 info->count = 0;
3403 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3404 sending a ffpcn() request first */
3406 if ( !option )
3407 return WERR_BADFID;
3409 get_printer_snum(p, hnd, &snum, NULL);
3411 for (i=0; i<option->count; i++) {
3412 option_type = option->types[i];
3414 switch (option_type.type) {
3415 case PRINTER_NOTIFY_TYPE:
3416 if(construct_notify_printer_info(Printer, info, snum,
3417 &option_type, id,
3418 mem_ctx))
3419 id--;
3420 break;
3422 case JOB_NOTIFY_TYPE: {
3423 NT_PRINTER_INFO_LEVEL *printer = NULL;
3425 count = print_queue_status(snum, &queue, &status);
3427 if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum))))
3428 goto done;
3430 for (j=0; j<count; j++) {
3431 construct_notify_jobs_info(&queue[j], info,
3432 printer, snum,
3433 &option_type,
3434 queue[j].job,
3435 mem_ctx);
3438 free_a_printer(&printer, 2);
3440 done:
3441 SAFE_FREE(queue);
3442 break;
3448 * Debugging information, don't delete.
3451 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3452 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3453 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3455 for (i=0; i<info->count; i++) {
3456 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3457 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3458 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3461 return WERR_OK;
3464 /****************************************************************
3465 _spoolss_RouterRefreshPrinterChangeNotify
3466 ****************************************************************/
3468 WERROR _spoolss_RouterRefreshPrinterChangeNotify(pipes_struct *p,
3469 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3471 struct spoolss_NotifyInfo *info;
3473 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
3474 WERROR result = WERR_BADFID;
3476 /* we always have a spoolss_NotifyInfo struct */
3477 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3478 if (!info) {
3479 result = WERR_NOMEM;
3480 goto done;
3483 *r->out.info = info;
3485 if (!Printer) {
3486 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3487 "Invalid handle (%s:%u:%u).\n",
3488 OUR_HANDLE(r->in.handle)));
3489 goto done;
3492 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3495 * We are now using the change value, and
3496 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3497 * I don't have a global notification system, I'm sending back all the
3498 * informations even when _NOTHING_ has changed.
3501 /* We need to keep track of the change value to send back in
3502 RRPCN replies otherwise our updates are ignored. */
3504 Printer->notify.fnpcn = true;
3506 if (Printer->notify.client_connected) {
3507 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3508 "Saving change value in request [%x]\n",
3509 r->in.change_low));
3510 Printer->notify.change = r->in.change_low;
3513 /* just ignore the spoolss_NotifyOption */
3515 switch (Printer->printer_type) {
3516 case SPLHND_SERVER:
3517 result = printserver_notify_info(p, r->in.handle,
3518 info, p->mem_ctx);
3519 break;
3521 case SPLHND_PRINTER:
3522 result = printer_notify_info(p, r->in.handle,
3523 info, p->mem_ctx);
3524 break;
3527 Printer->notify.fnpcn = false;
3529 done:
3530 return result;
3533 /********************************************************************
3534 * construct_printer_info_0
3535 * fill a printer_info_0 struct
3536 ********************************************************************/
3538 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3539 const NT_PRINTER_INFO_LEVEL *ntprinter,
3540 struct spoolss_PrinterInfo0 *r,
3541 int snum)
3543 int count;
3544 counter_printer_0 *session_counter;
3545 time_t setuptime;
3546 print_status_struct status;
3548 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
3549 W_ERROR_HAVE_NO_MEMORY(r->printername);
3551 r->servername = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
3552 W_ERROR_HAVE_NO_MEMORY(r->servername);
3554 count = print_queue_length(snum, &status);
3556 /* check if we already have a counter for this printer */
3557 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3558 if (session_counter->snum == snum)
3559 break;
3562 /* it's the first time, add it to the list */
3563 if (session_counter == NULL) {
3564 session_counter = SMB_MALLOC_P(counter_printer_0);
3565 W_ERROR_HAVE_NO_MEMORY(session_counter);
3566 ZERO_STRUCTP(session_counter);
3567 session_counter->snum = snum;
3568 session_counter->counter = 0;
3569 DLIST_ADD(counter_list, session_counter);
3572 /* increment it */
3573 session_counter->counter++;
3575 r->cjobs = count;
3576 r->total_jobs = 0;
3577 r->total_bytes = 0;
3579 setuptime = (time_t)ntprinter->info_2->setuptime;
3581 init_systemtime(&r->time, gmtime(&setuptime));
3583 /* JFM:
3584 * the global_counter should be stored in a TDB as it's common to all the clients
3585 * and should be zeroed on samba startup
3587 r->global_counter = session_counter->counter;
3588 r->total_pages = 0;
3589 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3590 r->version = 0x0005; /* NT 5 */
3591 r->free_build = 0x0893; /* build 2195 */
3592 r->spooling = 0;
3593 r->max_spooling = 0;
3594 r->session_counter = session_counter->counter;
3595 r->num_error_out_of_paper = 0x0;
3596 r->num_error_not_ready = 0x0; /* number of print failure */
3597 r->job_error = 0x0;
3598 r->number_of_processors = 0x1;
3599 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3600 r->high_part_total_bytes = 0x0;
3601 r->change_id = ntprinter->info_2->changeid; /* ChangeID in milliseconds*/
3602 r->last_error = WERR_OK;
3603 r->status = nt_printq_status(status.status);
3604 r->enumerate_network_printers = 0x0;
3605 r->c_setprinter = get_c_setprinter(); /* monotonically increasing sum of delta printer counts */
3606 r->processor_architecture = 0x0;
3607 r->processor_level = 0x6; /* 6 ???*/
3608 r->ref_ic = 0;
3609 r->reserved2 = 0;
3610 r->reserved3 = 0;
3612 return WERR_OK;
3615 /****************************************************************************
3616 Convert an NT_DEVICEMODE to a spoolss_DeviceMode structure. Both pointers
3617 should be valid upon entry
3618 ****************************************************************************/
3620 static WERROR convert_nt_devicemode(TALLOC_CTX *mem_ctx,
3621 struct spoolss_DeviceMode *r,
3622 const NT_DEVICEMODE *ntdevmode)
3624 if (!r || !ntdevmode) {
3625 return WERR_INVALID_PARAM;
3628 r->devicename = talloc_strdup(mem_ctx, ntdevmode->devicename);
3629 W_ERROR_HAVE_NO_MEMORY(r->devicename);
3631 r->specversion = ntdevmode->specversion;
3632 r->driverversion = ntdevmode->driverversion;
3633 r->size = ntdevmode->size;
3634 r->__driverextra_length = ntdevmode->driverextra;
3635 r->fields = ntdevmode->fields;
3637 r->orientation = ntdevmode->orientation;
3638 r->papersize = ntdevmode->papersize;
3639 r->paperlength = ntdevmode->paperlength;
3640 r->paperwidth = ntdevmode->paperwidth;
3641 r->scale = ntdevmode->scale;
3642 r->copies = ntdevmode->copies;
3643 r->defaultsource = ntdevmode->defaultsource;
3644 r->printquality = ntdevmode->printquality;
3645 r->color = ntdevmode->color;
3646 r->duplex = ntdevmode->duplex;
3647 r->yresolution = ntdevmode->yresolution;
3648 r->ttoption = ntdevmode->ttoption;
3649 r->collate = ntdevmode->collate;
3651 r->formname = talloc_strdup(mem_ctx, ntdevmode->formname);
3652 W_ERROR_HAVE_NO_MEMORY(r->formname);
3654 r->logpixels = ntdevmode->logpixels;
3655 r->bitsperpel = ntdevmode->bitsperpel;
3656 r->pelswidth = ntdevmode->pelswidth;
3657 r->pelsheight = ntdevmode->pelsheight;
3658 r->displayflags = ntdevmode->displayflags;
3659 r->displayfrequency = ntdevmode->displayfrequency;
3660 r->icmmethod = ntdevmode->icmmethod;
3661 r->icmintent = ntdevmode->icmintent;
3662 r->mediatype = ntdevmode->mediatype;
3663 r->dithertype = ntdevmode->dithertype;
3664 r->reserved1 = ntdevmode->reserved1;
3665 r->reserved2 = ntdevmode->reserved2;
3666 r->panningwidth = ntdevmode->panningwidth;
3667 r->panningheight = ntdevmode->panningheight;
3669 if (ntdevmode->nt_dev_private != NULL) {
3670 r->driverextra_data = data_blob_talloc(mem_ctx,
3671 ntdevmode->nt_dev_private,
3672 ntdevmode->driverextra);
3673 W_ERROR_HAVE_NO_MEMORY(r->driverextra_data.data);
3676 return WERR_OK;
3680 /****************************************************************************
3681 Create a spoolss_DeviceMode struct. Returns talloced memory.
3682 ****************************************************************************/
3684 struct spoolss_DeviceMode *construct_dev_mode(TALLOC_CTX *mem_ctx,
3685 const char *servicename)
3687 WERROR result;
3688 NT_PRINTER_INFO_LEVEL *printer = NULL;
3689 struct spoolss_DeviceMode *devmode = NULL;
3691 DEBUG(7,("construct_dev_mode\n"));
3693 DEBUGADD(8,("getting printer characteristics\n"));
3695 if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, servicename)))
3696 return NULL;
3698 if (!printer->info_2->devmode) {
3699 DEBUG(5, ("BONG! There was no device mode!\n"));
3700 goto done;
3703 devmode = TALLOC_ZERO_P(mem_ctx, struct spoolss_DeviceMode);
3704 if (!devmode) {
3705 DEBUG(2,("construct_dev_mode: talloc fail.\n"));
3706 goto done;
3709 DEBUGADD(8,("loading DEVICEMODE\n"));
3711 result = convert_nt_devicemode(mem_ctx, devmode, printer->info_2->devmode);
3712 if (!W_ERROR_IS_OK(result)) {
3713 TALLOC_FREE(devmode);
3716 done:
3717 free_a_printer(&printer,2);
3719 return devmode;
3722 /********************************************************************
3723 * construct_printer_info1
3724 * fill a spoolss_PrinterInfo1 struct
3725 ********************************************************************/
3727 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
3728 const NT_PRINTER_INFO_LEVEL *ntprinter,
3729 uint32_t flags,
3730 struct spoolss_PrinterInfo1 *r,
3731 int snum)
3733 r->flags = flags;
3735 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
3736 ntprinter->info_2->printername,
3737 ntprinter->info_2->drivername,
3738 ntprinter->info_2->location);
3739 W_ERROR_HAVE_NO_MEMORY(r->description);
3741 if (*ntprinter->info_2->comment == '\0') {
3742 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3743 } else {
3744 r->comment = talloc_strdup(mem_ctx, ntprinter->info_2->comment); /* saved comment */
3746 W_ERROR_HAVE_NO_MEMORY(r->comment);
3748 r->name = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
3749 W_ERROR_HAVE_NO_MEMORY(r->name);
3751 return WERR_OK;
3754 /********************************************************************
3755 * construct_printer_info2
3756 * fill a spoolss_PrinterInfo2 struct
3757 ********************************************************************/
3759 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
3760 const NT_PRINTER_INFO_LEVEL *ntprinter,
3761 struct spoolss_PrinterInfo2 *r,
3762 int snum)
3764 int count;
3766 print_status_struct status;
3768 count = print_queue_length(snum, &status);
3770 r->servername = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
3771 W_ERROR_HAVE_NO_MEMORY(r->servername);
3772 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
3773 W_ERROR_HAVE_NO_MEMORY(r->printername);
3774 r->sharename = talloc_strdup(mem_ctx, lp_servicename(snum));
3775 W_ERROR_HAVE_NO_MEMORY(r->sharename);
3776 r->portname = talloc_strdup(mem_ctx, ntprinter->info_2->portname);
3777 W_ERROR_HAVE_NO_MEMORY(r->portname);
3778 r->drivername = talloc_strdup(mem_ctx, ntprinter->info_2->drivername);
3779 W_ERROR_HAVE_NO_MEMORY(r->drivername);
3781 if (*ntprinter->info_2->comment == '\0') {
3782 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3783 } else {
3784 r->comment = talloc_strdup(mem_ctx, ntprinter->info_2->comment);
3786 W_ERROR_HAVE_NO_MEMORY(r->comment);
3788 r->location = talloc_strdup(mem_ctx, ntprinter->info_2->location);
3789 W_ERROR_HAVE_NO_MEMORY(r->location);
3790 r->sepfile = talloc_strdup(mem_ctx, ntprinter->info_2->sepfile);
3791 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
3792 r->printprocessor = talloc_strdup(mem_ctx, ntprinter->info_2->printprocessor);
3793 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
3794 r->datatype = talloc_strdup(mem_ctx, ntprinter->info_2->datatype);
3795 W_ERROR_HAVE_NO_MEMORY(r->datatype);
3796 r->parameters = talloc_strdup(mem_ctx, ntprinter->info_2->parameters);
3797 W_ERROR_HAVE_NO_MEMORY(r->parameters);
3799 r->attributes = ntprinter->info_2->attributes;
3801 r->priority = ntprinter->info_2->priority;
3802 r->defaultpriority = ntprinter->info_2->default_priority;
3803 r->starttime = ntprinter->info_2->starttime;
3804 r->untiltime = ntprinter->info_2->untiltime;
3805 r->status = nt_printq_status(status.status);
3806 r->cjobs = count;
3807 r->averageppm = ntprinter->info_2->averageppm;
3809 r->devmode = construct_dev_mode(mem_ctx, lp_const_servicename(snum));
3810 if (!r->devmode) {
3811 DEBUG(8,("Returning NULL Devicemode!\n"));
3814 r->secdesc = NULL;
3816 if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->sd_size != 0) {
3817 /* don't use talloc_steal() here unless you do a deep steal of all
3818 the SEC_DESC members */
3820 r->secdesc = dup_sec_desc(mem_ctx, ntprinter->info_2->secdesc_buf->sd);
3823 return WERR_OK;
3826 /********************************************************************
3827 * construct_printer_info3
3828 * fill a spoolss_PrinterInfo3 struct
3829 ********************************************************************/
3831 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
3832 const NT_PRINTER_INFO_LEVEL *ntprinter,
3833 struct spoolss_PrinterInfo3 *r,
3834 int snum)
3836 /* These are the components of the SD we are returning. */
3838 if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->sd_size != 0) {
3839 /* don't use talloc_steal() here unless you do a deep steal of all
3840 the SEC_DESC members */
3842 r->secdesc = dup_sec_desc(mem_ctx,
3843 ntprinter->info_2->secdesc_buf->sd);
3844 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
3847 return WERR_OK;
3850 /********************************************************************
3851 * construct_printer_info4
3852 * fill a spoolss_PrinterInfo4 struct
3853 ********************************************************************/
3855 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
3856 const NT_PRINTER_INFO_LEVEL *ntprinter,
3857 struct spoolss_PrinterInfo4 *r,
3858 int snum)
3860 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
3861 W_ERROR_HAVE_NO_MEMORY(r->printername);
3862 r->servername = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
3863 W_ERROR_HAVE_NO_MEMORY(r->servername);
3865 r->attributes = ntprinter->info_2->attributes;
3867 return WERR_OK;
3870 /********************************************************************
3871 * construct_printer_info5
3872 * fill a spoolss_PrinterInfo5 struct
3873 ********************************************************************/
3875 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
3876 const NT_PRINTER_INFO_LEVEL *ntprinter,
3877 struct spoolss_PrinterInfo5 *r,
3878 int snum)
3880 r->printername = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
3881 W_ERROR_HAVE_NO_MEMORY(r->printername);
3882 r->portname = talloc_strdup(mem_ctx, ntprinter->info_2->portname);
3883 W_ERROR_HAVE_NO_MEMORY(r->portname);
3885 r->attributes = ntprinter->info_2->attributes;
3887 /* these two are not used by NT+ according to MSDN */
3889 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
3890 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
3892 return WERR_OK;
3895 /********************************************************************
3896 * construct_printer_info_6
3897 * fill a spoolss_PrinterInfo6 struct
3898 ********************************************************************/
3900 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
3901 const NT_PRINTER_INFO_LEVEL *ntprinter,
3902 struct spoolss_PrinterInfo6 *r,
3903 int snum)
3905 int count;
3906 print_status_struct status;
3908 count = print_queue_length(snum, &status);
3910 r->status = nt_printq_status(status.status);
3912 return WERR_OK;
3915 /********************************************************************
3916 * construct_printer_info7
3917 * fill a spoolss_PrinterInfo7 struct
3918 ********************************************************************/
3920 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
3921 Printer_entry *print_hnd,
3922 struct spoolss_PrinterInfo7 *r,
3923 int snum)
3925 struct GUID guid;
3927 if (is_printer_published(print_hnd, snum, &guid)) {
3928 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
3929 r->action = DSPRINT_PUBLISH;
3930 } else {
3931 r->guid = talloc_strdup(mem_ctx, "");
3932 r->action = DSPRINT_UNPUBLISH;
3934 W_ERROR_HAVE_NO_MEMORY(r->guid);
3936 return WERR_OK;
3939 /********************************************************************
3940 * construct_printer_info8
3941 * fill a spoolss_PrinterInfo8 struct
3942 ********************************************************************/
3944 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
3945 const NT_PRINTER_INFO_LEVEL *ntprinter,
3946 struct spoolss_DeviceModeInfo *r,
3947 int snum)
3949 r->devmode = construct_dev_mode(mem_ctx, lp_const_servicename(snum));
3950 if (!r->devmode) {
3951 DEBUG(8,("Returning NULL Devicemode!\n"));
3954 return WERR_OK;
3958 /********************************************************************
3959 ********************************************************************/
3961 static bool snum_is_shared_printer(int snum)
3963 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
3966 /********************************************************************
3967 Spoolss_enumprinters.
3968 ********************************************************************/
3970 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
3971 uint32_t level,
3972 uint32_t flags,
3973 union spoolss_PrinterInfo **info_p,
3974 uint32_t *count_p)
3976 int snum;
3977 int n_services = lp_numservices();
3978 union spoolss_PrinterInfo *info = NULL;
3979 uint32_t count = 0;
3980 WERROR result = WERR_OK;
3982 *count_p = 0;
3983 *info_p = NULL;
3985 for (snum = 0; snum < n_services; snum++) {
3987 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
3989 if (!snum_is_shared_printer(snum)) {
3990 continue;
3993 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
3994 lp_servicename(snum), snum));
3996 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
3997 union spoolss_PrinterInfo,
3998 count + 1);
3999 if (!info) {
4000 result = WERR_NOMEM;
4001 goto out;
4004 result = get_a_printer(NULL, &ntprinter, 2,
4005 lp_const_servicename(snum));
4006 if (!W_ERROR_IS_OK(result)) {
4007 goto out;
4010 switch (level) {
4011 case 0:
4012 result = construct_printer_info0(info, ntprinter,
4013 &info[count].info0, snum);
4014 break;
4015 case 1:
4016 result = construct_printer_info1(info, ntprinter, flags,
4017 &info[count].info1, snum);
4018 break;
4019 case 2:
4020 result = construct_printer_info2(info, ntprinter,
4021 &info[count].info2, snum);
4022 break;
4023 case 4:
4024 result = construct_printer_info4(info, ntprinter,
4025 &info[count].info4, snum);
4026 break;
4027 case 5:
4028 result = construct_printer_info5(info, ntprinter,
4029 &info[count].info5, snum);
4030 break;
4032 default:
4033 result = WERR_UNKNOWN_LEVEL;
4034 free_a_printer(&ntprinter, 2);
4035 goto out;
4038 free_a_printer(&ntprinter, 2);
4039 if (!W_ERROR_IS_OK(result)) {
4040 goto out;
4043 count++;
4046 *count_p = count;
4047 *info_p = info;
4049 out:
4050 if (!W_ERROR_IS_OK(result)) {
4051 TALLOC_FREE(info);
4052 return result;
4055 *info_p = info;
4057 return WERR_OK;
4060 /********************************************************************
4061 * handle enumeration of printers at level 0
4062 ********************************************************************/
4064 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
4065 uint32_t flags,
4066 const char *servername,
4067 union spoolss_PrinterInfo **info,
4068 uint32_t *count)
4070 DEBUG(4,("enum_all_printers_info_0\n"));
4072 return enum_all_printers_info_level(mem_ctx, 0, flags, info, count);
4076 /********************************************************************
4077 ********************************************************************/
4079 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
4080 uint32_t flags,
4081 union spoolss_PrinterInfo **info,
4082 uint32_t *count)
4084 DEBUG(4,("enum_all_printers_info_1\n"));
4086 return enum_all_printers_info_level(mem_ctx, 1, flags, info, count);
4089 /********************************************************************
4090 enum_all_printers_info_1_local.
4091 *********************************************************************/
4093 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
4094 union spoolss_PrinterInfo **info,
4095 uint32_t *count)
4097 DEBUG(4,("enum_all_printers_info_1_local\n"));
4099 return enum_all_printers_info_1(mem_ctx, PRINTER_ENUM_ICON8, info, count);
4102 /********************************************************************
4103 enum_all_printers_info_1_name.
4104 *********************************************************************/
4106 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
4107 const char *name,
4108 union spoolss_PrinterInfo **info,
4109 uint32_t *count)
4111 const char *s = name;
4113 DEBUG(4,("enum_all_printers_info_1_name\n"));
4115 if ((name[0] == '\\') && (name[1] == '\\')) {
4116 s = name + 2;
4119 if (!is_myname_or_ipaddr(s)) {
4120 return WERR_INVALID_NAME;
4123 return enum_all_printers_info_1(mem_ctx, PRINTER_ENUM_ICON8, info, count);
4126 /********************************************************************
4127 enum_all_printers_info_1_network.
4128 *********************************************************************/
4130 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
4131 const char *name,
4132 union spoolss_PrinterInfo **info,
4133 uint32_t *count)
4135 const char *s = name;
4137 DEBUG(4,("enum_all_printers_info_1_network\n"));
4139 /* If we respond to a enum_printers level 1 on our name with flags
4140 set to PRINTER_ENUM_REMOTE with a list of printers then these
4141 printers incorrectly appear in the APW browse list.
4142 Specifically the printers for the server appear at the workgroup
4143 level where all the other servers in the domain are
4144 listed. Windows responds to this call with a
4145 WERR_CAN_NOT_COMPLETE so we should do the same. */
4147 if (name[0] == '\\' && name[1] == '\\') {
4148 s = name + 2;
4151 if (is_myname_or_ipaddr(s)) {
4152 return WERR_CAN_NOT_COMPLETE;
4155 return enum_all_printers_info_1(mem_ctx, PRINTER_ENUM_NAME, info, count);
4158 /********************************************************************
4159 * api_spoolss_enumprinters
4161 * called from api_spoolss_enumprinters (see this to understand)
4162 ********************************************************************/
4164 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
4165 union spoolss_PrinterInfo **info,
4166 uint32_t *count)
4168 DEBUG(4,("enum_all_printers_info_2\n"));
4170 return enum_all_printers_info_level(mem_ctx, 2, 0, info, count);
4173 /********************************************************************
4174 * handle enumeration of printers at level 1
4175 ********************************************************************/
4177 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
4178 uint32_t flags,
4179 const char *name,
4180 union spoolss_PrinterInfo **info,
4181 uint32_t *count)
4183 /* Not all the flags are equals */
4185 if (flags & PRINTER_ENUM_LOCAL) {
4186 return enum_all_printers_info_1_local(mem_ctx, info, count);
4189 if (flags & PRINTER_ENUM_NAME) {
4190 return enum_all_printers_info_1_name(mem_ctx, name, info, count);
4193 if (flags & PRINTER_ENUM_NETWORK) {
4194 return enum_all_printers_info_1_network(mem_ctx, name, info, count);
4197 return WERR_OK; /* NT4sp5 does that */
4200 /********************************************************************
4201 * handle enumeration of printers at level 2
4202 ********************************************************************/
4204 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4205 uint32_t flags,
4206 const char *servername,
4207 union spoolss_PrinterInfo **info,
4208 uint32_t *count)
4210 if (flags & PRINTER_ENUM_LOCAL) {
4211 return enum_all_printers_info_2(mem_ctx, info, count);
4214 if (flags & PRINTER_ENUM_NAME) {
4215 if (!is_myname_or_ipaddr(canon_servername(servername))) {
4216 return WERR_INVALID_NAME;
4219 return enum_all_printers_info_2(mem_ctx, info, count);
4222 if (flags & PRINTER_ENUM_REMOTE) {
4223 return WERR_UNKNOWN_LEVEL;
4226 return WERR_OK;
4229 /********************************************************************
4230 * handle enumeration of printers at level 4
4231 ********************************************************************/
4233 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4234 uint32_t flags,
4235 const char *servername,
4236 union spoolss_PrinterInfo **info,
4237 uint32_t *count)
4239 DEBUG(4,("enum_all_printers_info_4\n"));
4241 return enum_all_printers_info_level(mem_ctx, 4, flags, info, count);
4245 /********************************************************************
4246 * handle enumeration of printers at level 5
4247 ********************************************************************/
4249 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4250 uint32_t flags,
4251 const char *servername,
4252 union spoolss_PrinterInfo **info,
4253 uint32_t *count)
4255 DEBUG(4,("enum_all_printers_info_5\n"));
4257 return enum_all_printers_info_level(mem_ctx, 5, flags, info, count);
4260 /****************************************************************
4261 _spoolss_EnumPrinters
4262 ****************************************************************/
4264 WERROR _spoolss_EnumPrinters(pipes_struct *p,
4265 struct spoolss_EnumPrinters *r)
4267 const char *name = NULL;
4268 WERROR result;
4270 /* that's an [in out] buffer */
4272 if (!r->in.buffer && (r->in.offered != 0)) {
4273 return WERR_INVALID_PARAM;
4276 DEBUG(4,("_spoolss_EnumPrinters\n"));
4278 *r->out.needed = 0;
4279 *r->out.count = 0;
4280 *r->out.info = NULL;
4283 * Level 1:
4284 * flags==PRINTER_ENUM_NAME
4285 * if name=="" then enumerates all printers
4286 * if name!="" then enumerate the printer
4287 * flags==PRINTER_ENUM_REMOTE
4288 * name is NULL, enumerate printers
4289 * Level 2: name!="" enumerates printers, name can't be NULL
4290 * Level 3: doesn't exist
4291 * Level 4: does a local registry lookup
4292 * Level 5: same as Level 2
4295 if (r->in.server) {
4296 name = talloc_strdup_upper(p->mem_ctx, r->in.server);
4297 W_ERROR_HAVE_NO_MEMORY(name);
4300 switch (r->in.level) {
4301 case 0:
4302 result = enumprinters_level0(p->mem_ctx, r->in.flags, name,
4303 r->out.info, r->out.count);
4304 break;
4305 case 1:
4306 result = enumprinters_level1(p->mem_ctx, r->in.flags, name,
4307 r->out.info, r->out.count);
4308 break;
4309 case 2:
4310 result = enumprinters_level2(p->mem_ctx, r->in.flags, name,
4311 r->out.info, r->out.count);
4312 break;
4313 case 4:
4314 result = enumprinters_level4(p->mem_ctx, r->in.flags, name,
4315 r->out.info, r->out.count);
4316 break;
4317 case 5:
4318 result = enumprinters_level5(p->mem_ctx, r->in.flags, name,
4319 r->out.info, r->out.count);
4320 break;
4321 default:
4322 return WERR_UNKNOWN_LEVEL;
4325 if (!W_ERROR_IS_OK(result)) {
4326 return result;
4329 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4330 spoolss_EnumPrinters, NULL,
4331 *r->out.info, r->in.level,
4332 *r->out.count);
4333 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4334 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4336 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4339 /****************************************************************
4340 _spoolss_GetPrinter
4341 ****************************************************************/
4343 WERROR _spoolss_GetPrinter(pipes_struct *p,
4344 struct spoolss_GetPrinter *r)
4346 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
4347 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
4348 WERROR result = WERR_OK;
4350 int snum;
4352 /* that's an [in out] buffer */
4354 if (!r->in.buffer && (r->in.offered != 0)) {
4355 return WERR_INVALID_PARAM;
4358 *r->out.needed = 0;
4360 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4361 return WERR_BADFID;
4364 result = get_a_printer(Printer, &ntprinter, 2,
4365 lp_const_servicename(snum));
4366 if (!W_ERROR_IS_OK(result)) {
4367 return result;
4370 switch (r->in.level) {
4371 case 0:
4372 result = construct_printer_info0(p->mem_ctx, ntprinter,
4373 &r->out.info->info0, snum);
4374 break;
4375 case 1:
4376 result = construct_printer_info1(p->mem_ctx, ntprinter,
4377 PRINTER_ENUM_ICON8,
4378 &r->out.info->info1, snum);
4379 break;
4380 case 2:
4381 result = construct_printer_info2(p->mem_ctx, ntprinter,
4382 &r->out.info->info2, snum);
4383 break;
4384 case 3:
4385 result = construct_printer_info3(p->mem_ctx, ntprinter,
4386 &r->out.info->info3, snum);
4387 break;
4388 case 4:
4389 result = construct_printer_info4(p->mem_ctx, ntprinter,
4390 &r->out.info->info4, snum);
4391 break;
4392 case 5:
4393 result = construct_printer_info5(p->mem_ctx, ntprinter,
4394 &r->out.info->info5, snum);
4395 break;
4396 case 6:
4397 result = construct_printer_info6(p->mem_ctx, ntprinter,
4398 &r->out.info->info6, snum);
4399 break;
4400 case 7:
4401 result = construct_printer_info7(p->mem_ctx, Printer,
4402 &r->out.info->info7, snum);
4403 break;
4404 case 8:
4405 result = construct_printer_info8(p->mem_ctx, ntprinter,
4406 &r->out.info->info8, snum);
4407 break;
4408 default:
4409 result = WERR_UNKNOWN_LEVEL;
4410 break;
4413 free_a_printer(&ntprinter, 2);
4415 if (!W_ERROR_IS_OK(result)) {
4416 TALLOC_FREE(r->out.info);
4417 return result;
4420 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo, NULL,
4421 r->out.info, r->in.level);
4422 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4424 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4427 /********************************************************************
4428 ********************************************************************/
4430 static const char **string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4431 const char **string_array,
4432 const char *cservername)
4434 int i, num_strings = 0;
4435 const char **array = NULL;
4437 if (!string_array) {
4438 return NULL;
4441 for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
4443 const char *str = talloc_asprintf(mem_ctx, "\\\\%s%s",
4444 cservername, string_array[i]);
4445 if (!str) {
4446 TALLOC_FREE(array);
4447 return NULL;
4451 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4452 TALLOC_FREE(array);
4453 return NULL;
4457 if (i > 0) {
4458 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4459 &array, &num_strings);
4462 return array;
4465 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4466 do { \
4467 if (in && strlen(in)) { \
4468 out = talloc_strdup(mem_ctx, in); \
4469 W_ERROR_HAVE_NO_MEMORY(out); \
4470 } else { \
4471 out = NULL; \
4473 } while (0);
4475 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, in, out) \
4476 do { \
4477 if (in && strlen(in)) { \
4478 out = talloc_asprintf(mem_ctx, "\\\\%s%s", server, in); \
4479 } else { \
4480 out = talloc_strdup(mem_ctx, ""); \
4482 W_ERROR_HAVE_NO_MEMORY(out); \
4483 } while (0);
4485 /********************************************************************
4486 * fill a spoolss_DriverInfo1 struct
4487 ********************************************************************/
4489 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4490 struct spoolss_DriverInfo1 *r,
4491 const struct spoolss_DriverInfo8 *driver,
4492 const char *servername)
4494 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4495 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4497 return WERR_OK;
4500 /********************************************************************
4501 * fill a spoolss_DriverInfo2 struct
4502 ********************************************************************/
4504 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4505 struct spoolss_DriverInfo2 *r,
4506 const struct spoolss_DriverInfo8 *driver,
4507 const char *servername)
4510 const char *cservername = canon_servername(servername);
4512 r->version = driver->version;
4514 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4515 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4516 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4517 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4519 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4520 driver->driver_path,
4521 r->driver_path);
4523 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4524 driver->data_file,
4525 r->data_file);
4527 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4528 driver->config_file,
4529 r->config_file);
4531 return WERR_OK;
4534 /********************************************************************
4535 * fill a spoolss_DriverInfo3 struct
4536 ********************************************************************/
4538 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4539 struct spoolss_DriverInfo3 *r,
4540 const struct spoolss_DriverInfo8 *driver,
4541 const char *servername)
4543 const char *cservername = canon_servername(servername);
4545 r->version = driver->version;
4547 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4548 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4549 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4550 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4552 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4553 driver->driver_path,
4554 r->driver_path);
4556 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4557 driver->data_file,
4558 r->data_file);
4560 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4561 driver->config_file,
4562 r->config_file);
4564 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4565 driver->help_file,
4566 r->help_file);
4568 FILL_DRIVER_STRING(mem_ctx,
4569 driver->monitor_name,
4570 r->monitor_name);
4572 FILL_DRIVER_STRING(mem_ctx,
4573 driver->default_datatype,
4574 r->default_datatype);
4576 r->dependent_files = string_array_from_driver_info(mem_ctx,
4577 driver->dependent_files,
4578 cservername);
4579 return WERR_OK;
4582 /********************************************************************
4583 * fill a spoolss_DriverInfo4 struct
4584 ********************************************************************/
4586 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
4587 struct spoolss_DriverInfo4 *r,
4588 const struct spoolss_DriverInfo8 *driver,
4589 const char *servername)
4591 const char *cservername = canon_servername(servername);
4593 r->version = driver->version;
4595 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4596 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4597 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4598 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4600 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4601 driver->driver_path,
4602 r->driver_path);
4604 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4605 driver->data_file,
4606 r->data_file);
4608 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4609 driver->config_file,
4610 r->config_file);
4612 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4613 driver->help_file,
4614 r->help_file);
4616 r->dependent_files = string_array_from_driver_info(mem_ctx,
4617 driver->dependent_files,
4618 cservername);
4620 FILL_DRIVER_STRING(mem_ctx,
4621 driver->monitor_name,
4622 r->monitor_name);
4624 FILL_DRIVER_STRING(mem_ctx,
4625 driver->default_datatype,
4626 r->default_datatype);
4628 r->previous_names = string_array_from_driver_info(mem_ctx,
4629 driver->previous_names,
4630 cservername);
4632 return WERR_OK;
4635 /********************************************************************
4636 * fill a spoolss_DriverInfo5 struct
4637 ********************************************************************/
4639 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
4640 struct spoolss_DriverInfo5 *r,
4641 const struct spoolss_DriverInfo8 *driver,
4642 const char *servername)
4644 const char *cservername = canon_servername(servername);
4646 r->version = driver->version;
4648 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4649 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4650 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4651 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4653 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4654 driver->driver_path,
4655 r->driver_path);
4657 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4658 driver->data_file,
4659 r->data_file);
4661 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4662 driver->config_file,
4663 r->config_file);
4665 r->driver_attributes = 0;
4666 r->config_version = 0;
4667 r->driver_version = 0;
4669 return WERR_OK;
4671 /********************************************************************
4672 * fill a spoolss_DriverInfo6 struct
4673 ********************************************************************/
4675 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
4676 struct spoolss_DriverInfo6 *r,
4677 const struct spoolss_DriverInfo8 *driver,
4678 const char *servername)
4680 const char *cservername = canon_servername(servername);
4682 r->version = driver->version;
4684 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4685 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4686 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4687 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4689 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4690 driver->driver_path,
4691 r->driver_path);
4693 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4694 driver->data_file,
4695 r->data_file);
4697 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4698 driver->config_file,
4699 r->config_file);
4701 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4702 driver->help_file,
4703 r->help_file);
4705 FILL_DRIVER_STRING(mem_ctx,
4706 driver->monitor_name,
4707 r->monitor_name);
4709 FILL_DRIVER_STRING(mem_ctx,
4710 driver->default_datatype,
4711 r->default_datatype);
4713 r->dependent_files = string_array_from_driver_info(mem_ctx,
4714 driver->dependent_files,
4715 cservername);
4716 r->previous_names = string_array_from_driver_info(mem_ctx,
4717 driver->previous_names,
4718 cservername);
4720 r->driver_date = driver->driver_date;
4721 r->driver_version = driver->driver_version;
4723 FILL_DRIVER_STRING(mem_ctx,
4724 driver->manufacturer_name,
4725 r->manufacturer_name);
4726 FILL_DRIVER_STRING(mem_ctx,
4727 driver->manufacturer_url,
4728 r->manufacturer_url);
4729 FILL_DRIVER_STRING(mem_ctx,
4730 driver->hardware_id,
4731 r->hardware_id);
4732 FILL_DRIVER_STRING(mem_ctx,
4733 driver->provider,
4734 r->provider);
4736 return WERR_OK;
4739 /********************************************************************
4740 * fill a spoolss_DriverInfo8 struct
4741 ********************************************************************/
4743 static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
4744 struct spoolss_DriverInfo8 *r,
4745 const struct spoolss_DriverInfo8 *driver,
4746 const char *servername)
4748 const char *cservername = canon_servername(servername);
4750 r->version = driver->version;
4752 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4753 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4754 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4755 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4757 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4758 driver->driver_path,
4759 r->driver_path);
4761 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4762 driver->data_file,
4763 r->data_file);
4765 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4766 driver->config_file,
4767 r->config_file);
4769 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4770 driver->help_file,
4771 r->help_file);
4773 FILL_DRIVER_STRING(mem_ctx,
4774 driver->monitor_name,
4775 r->monitor_name);
4777 FILL_DRIVER_STRING(mem_ctx,
4778 driver->default_datatype,
4779 r->default_datatype);
4781 r->dependent_files = string_array_from_driver_info(mem_ctx,
4782 driver->dependent_files,
4783 cservername);
4784 r->previous_names = string_array_from_driver_info(mem_ctx,
4785 driver->previous_names,
4786 cservername);
4788 r->driver_date = driver->driver_date;
4789 r->driver_version = driver->driver_version;
4791 FILL_DRIVER_STRING(mem_ctx,
4792 driver->manufacturer_name,
4793 r->manufacturer_name);
4794 FILL_DRIVER_STRING(mem_ctx,
4795 driver->manufacturer_url,
4796 r->manufacturer_url);
4797 FILL_DRIVER_STRING(mem_ctx,
4798 driver->hardware_id,
4799 r->hardware_id);
4800 FILL_DRIVER_STRING(mem_ctx,
4801 driver->provider,
4802 r->provider);
4804 FILL_DRIVER_STRING(mem_ctx,
4805 driver->print_processor,
4806 r->print_processor);
4807 FILL_DRIVER_STRING(mem_ctx,
4808 driver->vendor_setup,
4809 r->vendor_setup);
4811 r->color_profiles = string_array_from_driver_info(mem_ctx,
4812 driver->color_profiles,
4813 cservername);
4815 FILL_DRIVER_STRING(mem_ctx,
4816 driver->inf_path,
4817 r->inf_path);
4819 r->printer_driver_attributes = driver->printer_driver_attributes;
4821 r->core_driver_dependencies = string_array_from_driver_info(mem_ctx,
4822 driver->core_driver_dependencies,
4823 cservername);
4825 r->min_inbox_driver_ver_date = driver->min_inbox_driver_ver_date;
4826 r->min_inbox_driver_ver_version = driver->min_inbox_driver_ver_version;
4828 return WERR_OK;
4831 #if 0 /* disabled until marshalling issues are resolved - gd */
4832 /********************************************************************
4833 ********************************************************************/
4835 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
4836 struct spoolss_DriverFileInfo *r,
4837 const char *cservername,
4838 const char *file_name,
4839 enum spoolss_DriverFileType file_type,
4840 uint32_t file_version)
4842 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
4843 cservername, file_name);
4844 W_ERROR_HAVE_NO_MEMORY(r->file_name);
4845 r->file_type = file_type;
4846 r->file_version = file_version;
4848 return WERR_OK;
4851 /********************************************************************
4852 ********************************************************************/
4854 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
4855 const struct spoolss_DriverInfo8 *driver,
4856 const char *cservername,
4857 struct spoolss_DriverFileInfo **info_p,
4858 uint32_t *count_p)
4860 struct spoolss_DriverFileInfo *info = NULL;
4861 uint32_t count = 0;
4862 WERROR result;
4863 uint32_t i;
4865 *info_p = NULL;
4866 *count_p = 0;
4868 if (strlen(driver->driver_path)) {
4869 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4870 struct spoolss_DriverFileInfo,
4871 count + 1);
4872 W_ERROR_HAVE_NO_MEMORY(info);
4873 result = fill_spoolss_DriverFileInfo(info,
4874 &info[count],
4875 cservername,
4876 driver->driver_path,
4877 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
4879 W_ERROR_NOT_OK_RETURN(result);
4880 count++;
4883 if (strlen(driver->config_file)) {
4884 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4885 struct spoolss_DriverFileInfo,
4886 count + 1);
4887 W_ERROR_HAVE_NO_MEMORY(info);
4888 result = fill_spoolss_DriverFileInfo(info,
4889 &info[count],
4890 cservername,
4891 driver->config_file,
4892 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
4894 W_ERROR_NOT_OK_RETURN(result);
4895 count++;
4898 if (strlen(driver->data_file)) {
4899 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4900 struct spoolss_DriverFileInfo,
4901 count + 1);
4902 W_ERROR_HAVE_NO_MEMORY(info);
4903 result = fill_spoolss_DriverFileInfo(info,
4904 &info[count],
4905 cservername,
4906 driver->data_file,
4907 SPOOLSS_DRIVER_FILE_TYPE_DATA,
4909 W_ERROR_NOT_OK_RETURN(result);
4910 count++;
4913 if (strlen(driver->help_file)) {
4914 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4915 struct spoolss_DriverFileInfo,
4916 count + 1);
4917 W_ERROR_HAVE_NO_MEMORY(info);
4918 result = fill_spoolss_DriverFileInfo(info,
4919 &info[count],
4920 cservername,
4921 driver->help_file,
4922 SPOOLSS_DRIVER_FILE_TYPE_HELP,
4924 W_ERROR_NOT_OK_RETURN(result);
4925 count++;
4928 for (i=0; driver->dependent_files[i] && driver->dependent_files[i][0] != '\0'; i++) {
4929 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4930 struct spoolss_DriverFileInfo,
4931 count + 1);
4932 W_ERROR_HAVE_NO_MEMORY(info);
4933 result = fill_spoolss_DriverFileInfo(info,
4934 &info[count],
4935 cservername,
4936 driver->dependent_files[i],
4937 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
4939 W_ERROR_NOT_OK_RETURN(result);
4940 count++;
4943 *info_p = info;
4944 *count_p = count;
4946 return WERR_OK;
4949 /********************************************************************
4950 * fill a spoolss_DriverInfo101 struct
4951 ********************************************************************/
4953 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
4954 struct spoolss_DriverInfo101 *r,
4955 const struct spoolss_DriverInfo8 *driver,
4956 const char *servername)
4958 const char *cservername = canon_servername(servername);
4959 WERROR result;
4961 r->version = driver->version;
4963 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4964 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4965 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4966 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4968 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
4969 cservername,
4970 &r->file_info,
4971 &r->file_count);
4972 if (!W_ERROR_IS_OK(result)) {
4973 return result;
4976 FILL_DRIVER_STRING(mem_ctx,
4977 driver->monitor_name,
4978 r->monitor_name);
4980 FILL_DRIVER_STRING(mem_ctx,
4981 driver->default_datatype,
4982 r->default_datatype);
4984 r->previous_names = string_array_from_driver_info(mem_ctx,
4985 driver->previous_names,
4986 cservername);
4987 r->driver_date = driver->driver_date;
4988 r->driver_version = driver->driver_version;
4990 FILL_DRIVER_STRING(mem_ctx,
4991 driver->manufacturer_name,
4992 r->manufacturer_name);
4993 FILL_DRIVER_STRING(mem_ctx,
4994 driver->manufacturer_url,
4995 r->manufacturer_url);
4996 FILL_DRIVER_STRING(mem_ctx,
4997 driver->hardware_id,
4998 r->hardware_id);
4999 FILL_DRIVER_STRING(mem_ctx,
5000 driver->provider,
5001 r->provider);
5003 return WERR_OK;
5005 #endif
5006 /********************************************************************
5007 ********************************************************************/
5009 static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
5010 uint32_t level,
5011 union spoolss_DriverInfo *r,
5012 int snum,
5013 const char *servername,
5014 const char *architecture,
5015 uint32_t version)
5017 NT_PRINTER_INFO_LEVEL *printer = NULL;
5018 struct spoolss_DriverInfo8 *driver;
5019 WERROR result;
5021 result = get_a_printer(NULL, &printer, 2, lp_const_servicename(snum));
5023 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5024 win_errstr(result)));
5026 if (!W_ERROR_IS_OK(result)) {
5027 return WERR_INVALID_PRINTER_NAME;
5030 result = get_a_printer_driver(mem_ctx, &driver, printer->info_2->drivername,
5031 architecture, version);
5033 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5034 win_errstr(result)));
5036 if (!W_ERROR_IS_OK(result)) {
5038 * Is this a W2k client ?
5041 if (version < 3) {
5042 free_a_printer(&printer, 2);
5043 return WERR_UNKNOWN_PRINTER_DRIVER;
5046 /* Yes - try again with a WinNT driver. */
5047 version = 2;
5048 result = get_a_printer_driver(mem_ctx, &driver, printer->info_2->drivername,
5049 architecture, version);
5050 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5051 win_errstr(result)));
5052 if (!W_ERROR_IS_OK(result)) {
5053 free_a_printer(&printer, 2);
5054 return WERR_UNKNOWN_PRINTER_DRIVER;
5058 switch (level) {
5059 case 1:
5060 result = fill_printer_driver_info1(mem_ctx, &r->info1, driver, servername);
5061 break;
5062 case 2:
5063 result = fill_printer_driver_info2(mem_ctx, &r->info2, driver, servername);
5064 break;
5065 case 3:
5066 result = fill_printer_driver_info3(mem_ctx, &r->info3, driver, servername);
5067 break;
5068 case 4:
5069 result = fill_printer_driver_info4(mem_ctx, &r->info4, driver, servername);
5070 break;
5071 case 5:
5072 result = fill_printer_driver_info5(mem_ctx, &r->info5, driver, servername);
5073 break;
5074 case 6:
5075 result = fill_printer_driver_info6(mem_ctx, &r->info6, driver, servername);
5076 break;
5077 case 8:
5078 result = fill_printer_driver_info8(mem_ctx, &r->info8, driver, servername);
5079 break;
5080 #if 0 /* disabled until marshalling issues are resolved - gd */
5081 case 101:
5082 result = fill_printer_driver_info101(mem_ctx, &r->info101, driver, servername);
5083 break;
5084 #endif
5085 default:
5086 result = WERR_UNKNOWN_LEVEL;
5087 break;
5090 free_a_printer(&printer, 2);
5091 free_a_printer_driver(driver);
5093 return result;
5096 /****************************************************************
5097 _spoolss_GetPrinterDriver2
5098 ****************************************************************/
5100 WERROR _spoolss_GetPrinterDriver2(pipes_struct *p,
5101 struct spoolss_GetPrinterDriver2 *r)
5103 Printer_entry *printer;
5104 WERROR result;
5106 const char *servername;
5107 int snum;
5109 /* that's an [in out] buffer */
5111 if (!r->in.buffer && (r->in.offered != 0)) {
5112 return WERR_INVALID_PARAM;
5115 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5117 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5118 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5119 return WERR_INVALID_PRINTER_NAME;
5122 *r->out.needed = 0;
5123 *r->out.server_major_version = 0;
5124 *r->out.server_minor_version = 0;
5126 servername = get_server_name(printer);
5128 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5129 return WERR_BADFID;
5132 result = construct_printer_driver_info_level(p->mem_ctx, r->in.level,
5133 r->out.info, snum,
5134 servername,
5135 r->in.architecture,
5136 r->in.client_major_version);
5137 if (!W_ERROR_IS_OK(result)) {
5138 TALLOC_FREE(r->out.info);
5139 return result;
5142 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo, NULL,
5143 r->out.info, r->in.level);
5144 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5146 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5150 /****************************************************************
5151 _spoolss_StartPagePrinter
5152 ****************************************************************/
5154 WERROR _spoolss_StartPagePrinter(pipes_struct *p,
5155 struct spoolss_StartPagePrinter *r)
5157 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5159 if (!Printer) {
5160 DEBUG(3,("_spoolss_StartPagePrinter: "
5161 "Error in startpageprinter printer handle\n"));
5162 return WERR_BADFID;
5165 Printer->page_started = true;
5166 return WERR_OK;
5169 /****************************************************************
5170 _spoolss_EndPagePrinter
5171 ****************************************************************/
5173 WERROR _spoolss_EndPagePrinter(pipes_struct *p,
5174 struct spoolss_EndPagePrinter *r)
5176 int snum;
5178 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5180 if (!Printer) {
5181 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5182 OUR_HANDLE(r->in.handle)));
5183 return WERR_BADFID;
5186 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5187 return WERR_BADFID;
5189 Printer->page_started = false;
5190 print_job_endpage(snum, Printer->jobid);
5192 return WERR_OK;
5195 /****************************************************************
5196 _spoolss_StartDocPrinter
5197 ****************************************************************/
5199 WERROR _spoolss_StartDocPrinter(pipes_struct *p,
5200 struct spoolss_StartDocPrinter *r)
5202 struct spoolss_DocumentInfo1 *info_1;
5203 int snum;
5204 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5206 if (!Printer) {
5207 DEBUG(2,("_spoolss_StartDocPrinter: "
5208 "Invalid handle (%s:%u:%u)\n",
5209 OUR_HANDLE(r->in.handle)));
5210 return WERR_BADFID;
5213 if (r->in.level != 1) {
5214 return WERR_UNKNOWN_LEVEL;
5217 info_1 = r->in.info.info1;
5220 * a nice thing with NT is it doesn't listen to what you tell it.
5221 * when asked to send _only_ RAW datas, it tries to send datas
5222 * in EMF format.
5224 * So I add checks like in NT Server ...
5227 if (info_1->datatype) {
5228 if (strcmp(info_1->datatype, "RAW") != 0) {
5229 *r->out.job_id = 0;
5230 return WERR_INVALID_DATATYPE;
5234 /* get the share number of the printer */
5235 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5236 return WERR_BADFID;
5239 Printer->jobid = print_job_start(p->server_info, snum,
5240 info_1->document_name,
5241 Printer->nt_devmode);
5243 /* An error occured in print_job_start() so return an appropriate
5244 NT error code. */
5246 if (Printer->jobid == -1) {
5247 return map_werror_from_unix(errno);
5250 Printer->document_started = true;
5251 *r->out.job_id = Printer->jobid;
5253 return WERR_OK;
5256 /****************************************************************
5257 _spoolss_EndDocPrinter
5258 ****************************************************************/
5260 WERROR _spoolss_EndDocPrinter(pipes_struct *p,
5261 struct spoolss_EndDocPrinter *r)
5263 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5264 int snum;
5266 if (!Printer) {
5267 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5268 OUR_HANDLE(r->in.handle)));
5269 return WERR_BADFID;
5272 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5273 return WERR_BADFID;
5276 Printer->document_started = false;
5277 print_job_end(snum, Printer->jobid, NORMAL_CLOSE);
5278 /* error codes unhandled so far ... */
5280 return WERR_OK;
5283 /****************************************************************
5284 _spoolss_WritePrinter
5285 ****************************************************************/
5287 WERROR _spoolss_WritePrinter(pipes_struct *p,
5288 struct spoolss_WritePrinter *r)
5290 uint32_t buffer_written;
5291 int snum;
5292 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5294 if (!Printer) {
5295 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5296 OUR_HANDLE(r->in.handle)));
5297 *r->out.num_written = r->in._data_size;
5298 return WERR_BADFID;
5301 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5302 return WERR_BADFID;
5304 buffer_written = (uint32_t)print_job_write(snum, Printer->jobid,
5305 (const char *)r->in.data.data,
5306 (SMB_OFF_T)-1,
5307 (size_t)r->in._data_size);
5308 if (buffer_written == (uint32_t)-1) {
5309 *r->out.num_written = 0;
5310 if (errno == ENOSPC)
5311 return WERR_NO_SPOOL_SPACE;
5312 else
5313 return WERR_ACCESS_DENIED;
5316 *r->out.num_written = r->in._data_size;
5318 return WERR_OK;
5321 /********************************************************************
5322 * api_spoolss_getprinter
5323 * called from the spoolss dispatcher
5325 ********************************************************************/
5327 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5328 pipes_struct *p)
5330 int snum;
5331 WERROR errcode = WERR_BADFUNC;
5332 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5334 if (!Printer) {
5335 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5336 OUR_HANDLE(handle)));
5337 return WERR_BADFID;
5340 if (!get_printer_snum(p, handle, &snum, NULL))
5341 return WERR_BADFID;
5343 switch (command) {
5344 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5345 errcode = print_queue_pause(p->server_info, snum);
5346 break;
5347 case SPOOLSS_PRINTER_CONTROL_RESUME:
5348 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5349 errcode = print_queue_resume(p->server_info, snum);
5350 break;
5351 case SPOOLSS_PRINTER_CONTROL_PURGE:
5352 errcode = print_queue_purge(p->server_info, snum);
5353 break;
5354 default:
5355 return WERR_UNKNOWN_LEVEL;
5358 return errcode;
5362 /****************************************************************
5363 _spoolss_AbortPrinter
5364 * From MSDN: "Deletes printer's spool file if printer is configured
5365 * for spooling"
5366 ****************************************************************/
5368 WERROR _spoolss_AbortPrinter(pipes_struct *p,
5369 struct spoolss_AbortPrinter *r)
5371 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5372 int snum;
5373 WERROR errcode = WERR_OK;
5375 if (!Printer) {
5376 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5377 OUR_HANDLE(r->in.handle)));
5378 return WERR_BADFID;
5381 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5382 return WERR_BADFID;
5384 print_job_delete(p->server_info, snum, Printer->jobid, &errcode );
5386 return errcode;
5389 /********************************************************************
5390 * called by spoolss_api_setprinter
5391 * when updating a printer description
5392 ********************************************************************/
5394 static WERROR update_printer_sec(struct policy_handle *handle,
5395 pipes_struct *p, SEC_DESC_BUF *secdesc_ctr)
5397 SEC_DESC_BUF *new_secdesc_ctr = NULL, *old_secdesc_ctr = NULL;
5398 WERROR result;
5399 int snum;
5401 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5403 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
5404 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5405 OUR_HANDLE(handle)));
5407 result = WERR_BADFID;
5408 goto done;
5411 if (!secdesc_ctr) {
5412 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5413 result = WERR_INVALID_PARAM;
5414 goto done;
5417 /* Check the user has permissions to change the security
5418 descriptor. By experimentation with two NT machines, the user
5419 requires Full Access to the printer to change security
5420 information. */
5422 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
5423 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5424 result = WERR_ACCESS_DENIED;
5425 goto done;
5428 /* NT seems to like setting the security descriptor even though
5429 nothing may have actually changed. */
5431 if ( !nt_printing_getsec(p->mem_ctx, Printer->sharename, &old_secdesc_ctr)) {
5432 DEBUG(2,("update_printer_sec: nt_printing_getsec() failed\n"));
5433 result = WERR_BADFID;
5434 goto done;
5437 if (DEBUGLEVEL >= 10) {
5438 SEC_ACL *the_acl;
5439 int i;
5441 the_acl = old_secdesc_ctr->sd->dacl;
5442 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
5443 PRINTERNAME(snum), the_acl->num_aces));
5445 for (i = 0; i < the_acl->num_aces; i++) {
5446 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5447 &the_acl->aces[i].trustee),
5448 the_acl->aces[i].access_mask));
5451 the_acl = secdesc_ctr->sd->dacl;
5453 if (the_acl) {
5454 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
5455 PRINTERNAME(snum), the_acl->num_aces));
5457 for (i = 0; i < the_acl->num_aces; i++) {
5458 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5459 &the_acl->aces[i].trustee),
5460 the_acl->aces[i].access_mask));
5462 } else {
5463 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
5467 new_secdesc_ctr = sec_desc_merge(p->mem_ctx, secdesc_ctr, old_secdesc_ctr);
5468 if (!new_secdesc_ctr) {
5469 result = WERR_NOMEM;
5470 goto done;
5473 if (security_descriptor_equal(new_secdesc_ctr->sd, old_secdesc_ctr->sd)) {
5474 result = WERR_OK;
5475 goto done;
5478 result = nt_printing_setsec(Printer->sharename, new_secdesc_ctr);
5480 done:
5482 return result;
5485 /********************************************************************
5486 Canonicalize printer info from a client
5488 ATTN: It does not matter what we set the servername to hear
5489 since we do the necessary work in get_a_printer() to set it to
5490 the correct value based on what the client sent in the
5491 _spoolss_open_printer_ex().
5492 ********************************************************************/
5494 static bool check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum)
5496 fstring printername;
5497 const char *p;
5499 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
5500 "portname=%s drivername=%s comment=%s location=%s\n",
5501 info->servername, info->printername, info->sharename,
5502 info->portname, info->drivername, info->comment, info->location));
5504 /* we force some elements to "correct" values */
5505 slprintf(info->servername, sizeof(info->servername)-1, "\\\\%s", global_myname());
5506 fstrcpy(info->sharename, lp_servicename(snum));
5508 /* check to see if we allow printername != sharename */
5510 if ( lp_force_printername(snum) ) {
5511 slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s",
5512 global_myname(), info->sharename );
5513 } else {
5515 /* make sure printername is in \\server\printername format */
5517 fstrcpy( printername, info->printername );
5518 p = printername;
5519 if ( printername[0] == '\\' && printername[1] == '\\' ) {
5520 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
5521 p++;
5524 slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s",
5525 global_myname(), p );
5528 info->attributes |= PRINTER_ATTRIBUTE_SAMBA;
5529 info->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
5533 return true;
5536 /****************************************************************************
5537 ****************************************************************************/
5539 static WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *portname, const char *uri)
5541 char *cmd = lp_addport_cmd();
5542 char *command = NULL;
5543 int ret;
5544 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5545 bool is_print_op = false;
5547 if ( !*cmd ) {
5548 return WERR_ACCESS_DENIED;
5551 command = talloc_asprintf(ctx,
5552 "%s \"%s\" \"%s\"", cmd, portname, uri );
5553 if (!command) {
5554 return WERR_NOMEM;
5557 if ( token )
5558 is_print_op = user_has_privileges( token, &se_printop );
5560 DEBUG(10,("Running [%s]\n", command));
5562 /********* BEGIN SePrintOperatorPrivilege **********/
5564 if ( is_print_op )
5565 become_root();
5567 ret = smbrun(command, NULL);
5569 if ( is_print_op )
5570 unbecome_root();
5572 /********* END SePrintOperatorPrivilege **********/
5574 DEBUGADD(10,("returned [%d]\n", ret));
5576 TALLOC_FREE(command);
5578 if ( ret != 0 ) {
5579 return WERR_ACCESS_DENIED;
5582 return WERR_OK;
5585 /****************************************************************************
5586 ****************************************************************************/
5588 bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer)
5590 char *cmd = lp_addprinter_cmd();
5591 char **qlines;
5592 char *command = NULL;
5593 int numlines;
5594 int ret;
5595 int fd;
5596 SE_PRIV se_printop = SE_PRINT_OPERATOR;
5597 bool is_print_op = false;
5598 char *remote_machine = talloc_strdup(ctx, "%m");
5600 if (!remote_machine) {
5601 return false;
5603 remote_machine = talloc_sub_basic(ctx,
5604 current_user_info.smb_name,
5605 current_user_info.domain,
5606 remote_machine);
5607 if (!remote_machine) {
5608 return false;
5611 command = talloc_asprintf(ctx,
5612 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
5613 cmd, printer->info_2->printername, printer->info_2->sharename,
5614 printer->info_2->portname, printer->info_2->drivername,
5615 printer->info_2->location, printer->info_2->comment, remote_machine);
5616 if (!command) {
5617 return false;
5620 if ( token )
5621 is_print_op = user_has_privileges( token, &se_printop );
5623 DEBUG(10,("Running [%s]\n", command));
5625 /********* BEGIN SePrintOperatorPrivilege **********/
5627 if ( is_print_op )
5628 become_root();
5630 if ( (ret = smbrun(command, &fd)) == 0 ) {
5631 /* Tell everyone we updated smb.conf. */
5632 message_send_all(smbd_messaging_context(),
5633 MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
5636 if ( is_print_op )
5637 unbecome_root();
5639 /********* END SePrintOperatorPrivilege **********/
5641 DEBUGADD(10,("returned [%d]\n", ret));
5643 TALLOC_FREE(command);
5644 TALLOC_FREE(remote_machine);
5646 if ( ret != 0 ) {
5647 if (fd != -1)
5648 close(fd);
5649 return false;
5652 /* reload our services immediately */
5653 become_root();
5654 reload_services(false);
5655 unbecome_root();
5657 numlines = 0;
5658 /* Get lines and convert them back to dos-codepage */
5659 qlines = fd_lines_load(fd, &numlines, 0, NULL);
5660 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
5661 close(fd);
5663 /* Set the portname to what the script says the portname should be. */
5664 /* but don't require anything to be return from the script exit a good error code */
5666 if (numlines) {
5667 /* Set the portname to what the script says the portname should be. */
5668 strncpy(printer->info_2->portname, qlines[0], sizeof(printer->info_2->portname));
5669 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
5672 TALLOC_FREE(qlines);
5673 return true;
5677 /********************************************************************
5678 * Called by spoolss_api_setprinter
5679 * when updating a printer description.
5680 ********************************************************************/
5682 static WERROR update_printer(pipes_struct *p, struct policy_handle *handle,
5683 struct spoolss_SetPrinterInfoCtr *info_ctr,
5684 struct spoolss_DeviceMode *devmode)
5686 int snum;
5687 NT_PRINTER_INFO_LEVEL *printer = NULL, *old_printer = NULL;
5688 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5689 WERROR result;
5690 DATA_BLOB buffer;
5691 fstring asc_buffer;
5693 DEBUG(8,("update_printer\n"));
5695 result = WERR_OK;
5697 if (!Printer) {
5698 result = WERR_BADFID;
5699 goto done;
5702 if (!get_printer_snum(p, handle, &snum, NULL)) {
5703 result = WERR_BADFID;
5704 goto done;
5707 if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum))) ||
5708 (!W_ERROR_IS_OK(get_a_printer(Printer, &old_printer, 2, lp_const_servicename(snum))))) {
5709 result = WERR_BADFID;
5710 goto done;
5713 DEBUGADD(8,("Converting info_2 struct\n"));
5716 * convert_printer_info converts the incoming
5717 * info from the client and overwrites the info
5718 * just read from the tdb in the pointer 'printer'.
5721 if (!convert_printer_info(info_ctr, printer)) {
5722 result = WERR_NOMEM;
5723 goto done;
5726 if (devmode) {
5727 /* we have a valid devmode
5728 convert it and link it*/
5730 DEBUGADD(8,("update_printer: Converting the devicemode struct\n"));
5731 if (!convert_devicemode(printer->info_2->printername, devmode,
5732 &printer->info_2->devmode)) {
5733 result = WERR_NOMEM;
5734 goto done;
5738 /* Do sanity check on the requested changes for Samba */
5740 if (!check_printer_ok(printer->info_2, snum)) {
5741 result = WERR_INVALID_PARAM;
5742 goto done;
5745 /* FIXME!!! If the driver has changed we really should verify that
5746 it is installed before doing much else --jerry */
5748 /* Check calling user has permission to update printer description */
5750 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
5751 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
5752 result = WERR_ACCESS_DENIED;
5753 goto done;
5756 /* Call addprinter hook */
5757 /* Check changes to see if this is really needed */
5759 if ( *lp_addprinter_cmd()
5760 && (!strequal(printer->info_2->drivername, old_printer->info_2->drivername)
5761 || !strequal(printer->info_2->comment, old_printer->info_2->comment)
5762 || !strequal(printer->info_2->portname, old_printer->info_2->portname)
5763 || !strequal(printer->info_2->location, old_printer->info_2->location)) )
5765 /* add_printer_hook() will call reload_services() */
5767 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
5768 printer) ) {
5769 result = WERR_ACCESS_DENIED;
5770 goto done;
5775 * When a *new* driver is bound to a printer, the drivername is used to
5776 * lookup previously saved driver initialization info, which is then
5777 * bound to the printer, simulating what happens in the Windows arch.
5779 if (!strequal(printer->info_2->drivername, old_printer->info_2->drivername))
5781 if (!set_driver_init(printer, 2))
5783 DEBUG(5,("update_printer: Error restoring driver initialization data for driver [%s]!\n",
5784 printer->info_2->drivername));
5787 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
5788 printer->info_2->drivername));
5790 notify_printer_driver(snum, printer->info_2->drivername);
5794 * flag which changes actually occured. This is a small subset of
5795 * all the possible changes. We also have to update things in the
5796 * DsSpooler key.
5799 if (!strequal(printer->info_2->comment, old_printer->info_2->comment)) {
5800 push_reg_sz(talloc_tos(), &buffer, printer->info_2->comment);
5801 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "description",
5802 REG_SZ, buffer.data, buffer.length);
5804 notify_printer_comment(snum, printer->info_2->comment);
5807 if (!strequal(printer->info_2->sharename, old_printer->info_2->sharename)) {
5808 push_reg_sz(talloc_tos(), &buffer, printer->info_2->sharename);
5809 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "shareName",
5810 REG_SZ, buffer.data, buffer.length);
5812 notify_printer_sharename(snum, printer->info_2->sharename);
5815 if (!strequal(printer->info_2->printername, old_printer->info_2->printername)) {
5816 char *pname;
5818 if ( (pname = strchr_m( printer->info_2->printername+2, '\\' )) != NULL )
5819 pname++;
5820 else
5821 pname = printer->info_2->printername;
5824 push_reg_sz(talloc_tos(), &buffer, pname);
5825 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "printerName",
5826 REG_SZ, buffer.data, buffer.length);
5828 notify_printer_printername( snum, pname );
5831 if (!strequal(printer->info_2->portname, old_printer->info_2->portname)) {
5832 push_reg_sz(talloc_tos(), &buffer, printer->info_2->portname);
5833 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "portName",
5834 REG_SZ, buffer.data, buffer.length);
5836 notify_printer_port(snum, printer->info_2->portname);
5839 if (!strequal(printer->info_2->location, old_printer->info_2->location)) {
5840 push_reg_sz(talloc_tos(), &buffer, printer->info_2->location);
5841 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "location",
5842 REG_SZ, buffer.data, buffer.length);
5844 notify_printer_location(snum, printer->info_2->location);
5847 /* here we need to update some more DsSpooler keys */
5848 /* uNCName, serverName, shortServerName */
5850 push_reg_sz(talloc_tos(), &buffer, global_myname());
5851 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "serverName",
5852 REG_SZ, buffer.data, buffer.length);
5853 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "shortServerName",
5854 REG_SZ, buffer.data, buffer.length);
5856 slprintf( asc_buffer, sizeof(asc_buffer)-1, "\\\\%s\\%s",
5857 global_myname(), printer->info_2->sharename );
5858 push_reg_sz(talloc_tos(), &buffer, asc_buffer);
5859 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "uNCName",
5860 REG_SZ, buffer.data, buffer.length);
5862 /* Update printer info */
5863 result = mod_a_printer(printer, 2);
5865 done:
5866 free_a_printer(&printer, 2);
5867 free_a_printer(&old_printer, 2);
5870 return result;
5873 /****************************************************************************
5874 ****************************************************************************/
5875 static WERROR publish_or_unpublish_printer(pipes_struct *p,
5876 struct policy_handle *handle,
5877 struct spoolss_SetPrinterInfo7 *info7)
5879 #ifdef HAVE_ADS
5880 int snum;
5881 Printer_entry *Printer;
5883 if ( lp_security() != SEC_ADS ) {
5884 return WERR_UNKNOWN_LEVEL;
5887 Printer = find_printer_index_by_hnd(p, handle);
5889 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
5891 if (!Printer)
5892 return WERR_BADFID;
5894 if (!get_printer_snum(p, handle, &snum, NULL))
5895 return WERR_BADFID;
5897 nt_printer_publish(Printer, snum, info7->action);
5899 return WERR_OK;
5900 #else
5901 return WERR_UNKNOWN_LEVEL;
5902 #endif
5905 /********************************************************************
5906 ********************************************************************/
5908 static WERROR update_printer_devmode(pipes_struct *p, struct policy_handle *handle,
5909 struct spoolss_DeviceMode *devmode)
5911 int snum;
5912 NT_PRINTER_INFO_LEVEL *printer = NULL;
5913 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5914 WERROR result;
5916 DEBUG(8,("update_printer_devmode\n"));
5918 result = WERR_OK;
5920 if (!Printer) {
5921 result = WERR_BADFID;
5922 goto done;
5925 if (!get_printer_snum(p, handle, &snum, NULL)) {
5926 result = WERR_BADFID;
5927 goto done;
5930 if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)))) {
5931 result = WERR_BADFID;
5932 goto done;
5935 if (devmode) {
5936 /* we have a valid devmode
5937 convert it and link it*/
5939 DEBUGADD(8,("update_printer: Converting the devicemode struct\n"));
5940 if (!convert_devicemode(printer->info_2->printername, devmode,
5941 &printer->info_2->devmode)) {
5942 result = WERR_NOMEM;
5943 goto done;
5947 /* Check calling user has permission to update printer description */
5949 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
5950 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
5951 result = WERR_ACCESS_DENIED;
5952 goto done;
5956 /* Update printer info */
5957 result = mod_a_printer(printer, 2);
5959 done:
5960 free_a_printer(&printer, 2);
5962 return result;
5966 /****************************************************************
5967 _spoolss_SetPrinter
5968 ****************************************************************/
5970 WERROR _spoolss_SetPrinter(pipes_struct *p,
5971 struct spoolss_SetPrinter *r)
5973 WERROR result;
5975 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
5977 if (!Printer) {
5978 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
5979 OUR_HANDLE(r->in.handle)));
5980 return WERR_BADFID;
5983 /* check the level */
5984 switch (r->in.info_ctr->level) {
5985 case 0:
5986 return control_printer(r->in.handle, r->in.command, p);
5987 case 2:
5988 result = update_printer(p, r->in.handle,
5989 r->in.info_ctr,
5990 r->in.devmode_ctr->devmode);
5991 if (!W_ERROR_IS_OK(result))
5992 return result;
5993 if (r->in.secdesc_ctr->sd)
5994 result = update_printer_sec(r->in.handle, p,
5995 r->in.secdesc_ctr);
5996 return result;
5997 case 3:
5998 return update_printer_sec(r->in.handle, p,
5999 r->in.secdesc_ctr);
6000 case 7:
6001 return publish_or_unpublish_printer(p, r->in.handle,
6002 r->in.info_ctr->info.info7);
6003 case 8:
6004 return update_printer_devmode(p, r->in.handle,
6005 r->in.devmode_ctr->devmode);
6006 default:
6007 return WERR_UNKNOWN_LEVEL;
6011 /****************************************************************
6012 _spoolss_FindClosePrinterNotify
6013 ****************************************************************/
6015 WERROR _spoolss_FindClosePrinterNotify(pipes_struct *p,
6016 struct spoolss_FindClosePrinterNotify *r)
6018 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
6020 if (!Printer) {
6021 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6022 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
6023 return WERR_BADFID;
6026 if (Printer->notify.client_connected == true) {
6027 int snum = -1;
6029 if ( Printer->printer_type == SPLHND_SERVER)
6030 snum = -1;
6031 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
6032 !get_printer_snum(p, r->in.handle, &snum, NULL) )
6033 return WERR_BADFID;
6035 srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
6038 Printer->notify.flags=0;
6039 Printer->notify.options=0;
6040 Printer->notify.localmachine[0]='\0';
6041 Printer->notify.printerlocal=0;
6042 TALLOC_FREE(Printer->notify.option);
6043 Printer->notify.client_connected = false;
6045 return WERR_OK;
6048 /****************************************************************
6049 _spoolss_AddJob
6050 ****************************************************************/
6052 WERROR _spoolss_AddJob(pipes_struct *p,
6053 struct spoolss_AddJob *r)
6055 if (!r->in.buffer && (r->in.offered != 0)) {
6056 return WERR_INVALID_PARAM;
6059 /* this is what a NT server returns for AddJob. AddJob must fail on
6060 * non-local printers */
6062 if (r->in.level != 1) {
6063 return WERR_UNKNOWN_LEVEL;
6066 return WERR_INVALID_PARAM;
6069 /****************************************************************************
6070 fill_job_info1
6071 ****************************************************************************/
6073 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
6074 struct spoolss_JobInfo1 *r,
6075 const print_queue_struct *queue,
6076 int position, int snum,
6077 const NT_PRINTER_INFO_LEVEL *ntprinter)
6079 struct tm *t;
6081 t = gmtime(&queue->time);
6083 r->job_id = queue->job;
6085 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6086 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6087 r->server_name = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
6088 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6089 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6090 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6091 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6092 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6093 r->data_type = talloc_strdup(mem_ctx, "RAW");
6094 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6095 r->text_status = talloc_strdup(mem_ctx, "");
6096 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6098 r->status = nt_printj_status(queue->status);
6099 r->priority = queue->priority;
6100 r->position = position;
6101 r->total_pages = queue->page_count;
6102 r->pages_printed = 0; /* ??? */
6104 init_systemtime(&r->submitted, t);
6106 return WERR_OK;
6109 /****************************************************************************
6110 fill_job_info2
6111 ****************************************************************************/
6113 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
6114 struct spoolss_JobInfo2 *r,
6115 const print_queue_struct *queue,
6116 int position, int snum,
6117 const NT_PRINTER_INFO_LEVEL *ntprinter,
6118 struct spoolss_DeviceMode *devmode)
6120 struct tm *t;
6122 t = gmtime(&queue->time);
6124 r->job_id = queue->job;
6126 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6127 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6128 r->server_name = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
6129 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6130 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6131 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6132 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6133 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6134 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
6135 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
6136 r->data_type = talloc_strdup(mem_ctx, "RAW");
6137 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6138 r->print_processor = talloc_strdup(mem_ctx, "winprint");
6139 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
6140 r->parameters = talloc_strdup(mem_ctx, "");
6141 W_ERROR_HAVE_NO_MEMORY(r->parameters);
6142 r->driver_name = talloc_strdup(mem_ctx, ntprinter->info_2->drivername);
6143 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
6145 r->devmode = devmode;
6147 r->text_status = talloc_strdup(mem_ctx, "");
6148 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6150 r->secdesc = NULL;
6152 r->status = nt_printj_status(queue->status);
6153 r->priority = queue->priority;
6154 r->position = position;
6155 r->start_time = 0;
6156 r->until_time = 0;
6157 r->total_pages = queue->page_count;
6158 r->size = queue->size;
6159 init_systemtime(&r->submitted, t);
6160 r->time = 0;
6161 r->pages_printed = 0; /* ??? */
6163 return WERR_OK;
6166 /****************************************************************************
6167 fill_job_info3
6168 ****************************************************************************/
6170 static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
6171 struct spoolss_JobInfo3 *r,
6172 const print_queue_struct *queue,
6173 const print_queue_struct *next_queue,
6174 int position, int snum,
6175 const NT_PRINTER_INFO_LEVEL *ntprinter)
6177 r->job_id = queue->job;
6178 r->next_job_id = 0;
6179 if (next_queue) {
6180 r->next_job_id = next_queue->job;
6182 r->reserved = 0;
6184 return WERR_OK;
6187 /****************************************************************************
6188 Enumjobs at level 1.
6189 ****************************************************************************/
6191 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
6192 const print_queue_struct *queue,
6193 uint32_t num_queues, int snum,
6194 const NT_PRINTER_INFO_LEVEL *ntprinter,
6195 union spoolss_JobInfo **info_p,
6196 uint32_t *count)
6198 union spoolss_JobInfo *info;
6199 int i;
6200 WERROR result = WERR_OK;
6202 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6203 W_ERROR_HAVE_NO_MEMORY(info);
6205 *count = num_queues;
6207 for (i=0; i<*count; i++) {
6208 result = fill_job_info1(info,
6209 &info[i].info1,
6210 &queue[i],
6212 snum,
6213 ntprinter);
6214 if (!W_ERROR_IS_OK(result)) {
6215 goto out;
6219 out:
6220 if (!W_ERROR_IS_OK(result)) {
6221 TALLOC_FREE(info);
6222 *count = 0;
6223 return result;
6226 *info_p = info;
6228 return WERR_OK;
6231 /****************************************************************************
6232 Enumjobs at level 2.
6233 ****************************************************************************/
6235 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
6236 const print_queue_struct *queue,
6237 uint32_t num_queues, int snum,
6238 const NT_PRINTER_INFO_LEVEL *ntprinter,
6239 union spoolss_JobInfo **info_p,
6240 uint32_t *count)
6242 union spoolss_JobInfo *info;
6243 int i;
6244 WERROR result = WERR_OK;
6246 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6247 W_ERROR_HAVE_NO_MEMORY(info);
6249 *count = num_queues;
6251 for (i=0; i<*count; i++) {
6253 struct spoolss_DeviceMode *devmode;
6255 devmode = construct_dev_mode(info, lp_const_servicename(snum));
6256 if (!devmode) {
6257 result = WERR_NOMEM;
6258 goto out;
6261 result = fill_job_info2(info,
6262 &info[i].info2,
6263 &queue[i],
6265 snum,
6266 ntprinter,
6267 devmode);
6268 if (!W_ERROR_IS_OK(result)) {
6269 goto out;
6273 out:
6274 if (!W_ERROR_IS_OK(result)) {
6275 TALLOC_FREE(info);
6276 *count = 0;
6277 return result;
6280 *info_p = info;
6282 return WERR_OK;
6285 /****************************************************************************
6286 Enumjobs at level 3.
6287 ****************************************************************************/
6289 static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
6290 const print_queue_struct *queue,
6291 uint32_t num_queues, int snum,
6292 const NT_PRINTER_INFO_LEVEL *ntprinter,
6293 union spoolss_JobInfo **info_p,
6294 uint32_t *count)
6296 union spoolss_JobInfo *info;
6297 int i;
6298 WERROR result = WERR_OK;
6300 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6301 W_ERROR_HAVE_NO_MEMORY(info);
6303 *count = num_queues;
6305 for (i=0; i<*count; i++) {
6306 const print_queue_struct *next_queue = NULL;
6308 if (i+1 < *count) {
6309 next_queue = &queue[i+1];
6312 result = fill_job_info3(info,
6313 &info[i].info3,
6314 &queue[i],
6315 next_queue,
6317 snum,
6318 ntprinter);
6319 if (!W_ERROR_IS_OK(result)) {
6320 goto out;
6324 out:
6325 if (!W_ERROR_IS_OK(result)) {
6326 TALLOC_FREE(info);
6327 *count = 0;
6328 return result;
6331 *info_p = info;
6333 return WERR_OK;
6336 /****************************************************************
6337 _spoolss_EnumJobs
6338 ****************************************************************/
6340 WERROR _spoolss_EnumJobs(pipes_struct *p,
6341 struct spoolss_EnumJobs *r)
6343 WERROR result;
6344 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
6345 int snum;
6346 print_status_struct prt_status;
6347 print_queue_struct *queue = NULL;
6348 uint32_t count;
6350 /* that's an [in out] buffer */
6352 if (!r->in.buffer && (r->in.offered != 0)) {
6353 return WERR_INVALID_PARAM;
6356 DEBUG(4,("_spoolss_EnumJobs\n"));
6358 *r->out.needed = 0;
6359 *r->out.count = 0;
6360 *r->out.info = NULL;
6362 /* lookup the printer snum and tdb entry */
6364 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6365 return WERR_BADFID;
6368 result = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum));
6369 if (!W_ERROR_IS_OK(result)) {
6370 return result;
6373 count = print_queue_status(snum, &queue, &prt_status);
6374 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
6375 count, prt_status.status, prt_status.message));
6377 if (count == 0) {
6378 SAFE_FREE(queue);
6379 free_a_printer(&ntprinter, 2);
6380 return WERR_OK;
6383 switch (r->in.level) {
6384 case 1:
6385 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
6386 ntprinter, r->out.info, r->out.count);
6387 break;
6388 case 2:
6389 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
6390 ntprinter, r->out.info, r->out.count);
6391 break;
6392 case 3:
6393 result = enumjobs_level3(p->mem_ctx, queue, count, snum,
6394 ntprinter, r->out.info, r->out.count);
6395 break;
6396 default:
6397 result = WERR_UNKNOWN_LEVEL;
6398 break;
6401 SAFE_FREE(queue);
6402 free_a_printer(&ntprinter, 2);
6404 if (!W_ERROR_IS_OK(result)) {
6405 return result;
6408 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6409 spoolss_EnumJobs, NULL,
6410 *r->out.info, r->in.level,
6411 *r->out.count);
6412 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6413 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6415 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6418 /****************************************************************
6419 _spoolss_ScheduleJob
6420 ****************************************************************/
6422 WERROR _spoolss_ScheduleJob(pipes_struct *p,
6423 struct spoolss_ScheduleJob *r)
6425 return WERR_OK;
6428 /****************************************************************
6429 _spoolss_SetJob
6430 ****************************************************************/
6432 WERROR _spoolss_SetJob(pipes_struct *p,
6433 struct spoolss_SetJob *r)
6435 int snum;
6436 WERROR errcode = WERR_BADFUNC;
6438 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6439 return WERR_BADFID;
6442 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
6443 return WERR_INVALID_PRINTER_NAME;
6446 switch (r->in.command) {
6447 case SPOOLSS_JOB_CONTROL_CANCEL:
6448 case SPOOLSS_JOB_CONTROL_DELETE:
6449 if (print_job_delete(p->server_info, snum, r->in.job_id, &errcode)) {
6450 errcode = WERR_OK;
6452 break;
6453 case SPOOLSS_JOB_CONTROL_PAUSE:
6454 if (print_job_pause(p->server_info, snum, r->in.job_id, &errcode)) {
6455 errcode = WERR_OK;
6457 break;
6458 case SPOOLSS_JOB_CONTROL_RESTART:
6459 case SPOOLSS_JOB_CONTROL_RESUME:
6460 if (print_job_resume(p->server_info, snum, r->in.job_id, &errcode)) {
6461 errcode = WERR_OK;
6463 break;
6464 default:
6465 return WERR_UNKNOWN_LEVEL;
6468 return errcode;
6471 /****************************************************************************
6472 Enumerates all printer drivers by level and architecture.
6473 ****************************************************************************/
6475 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
6476 const char *servername,
6477 const char *architecture,
6478 uint32_t level,
6479 union spoolss_DriverInfo **info_p,
6480 uint32_t *count_p)
6482 int i;
6483 int ndrivers;
6484 uint32_t version;
6485 fstring *list = NULL;
6486 struct spoolss_DriverInfo8 *driver;
6487 union spoolss_DriverInfo *info = NULL;
6488 uint32_t count = 0;
6489 WERROR result = WERR_OK;
6491 *count_p = 0;
6492 *info_p = NULL;
6494 for (version=0; version<DRIVER_MAX_VERSION; version++) {
6495 list = NULL;
6496 ndrivers = get_ntdrivers(&list, architecture, version);
6497 DEBUGADD(4,("we have:[%d] drivers in environment [%s] and version [%d]\n",
6498 ndrivers, architecture, version));
6500 if (ndrivers == -1) {
6501 result = WERR_NOMEM;
6502 goto out;
6505 if (ndrivers != 0) {
6506 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
6507 union spoolss_DriverInfo,
6508 count + ndrivers);
6509 if (!info) {
6510 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
6511 "failed to enlarge driver info buffer!\n"));
6512 result = WERR_NOMEM;
6513 goto out;
6517 for (i=0; i<ndrivers; i++) {
6518 DEBUGADD(5,("\tdriver: [%s]\n", list[i]));
6519 ZERO_STRUCT(driver);
6520 result = get_a_printer_driver(mem_ctx, &driver, list[i],
6521 architecture, version);
6522 if (!W_ERROR_IS_OK(result)) {
6523 goto out;
6526 switch (level) {
6527 case 1:
6528 result = fill_printer_driver_info1(info, &info[count+i].info1,
6529 driver, servername);
6530 break;
6531 case 2:
6532 result = fill_printer_driver_info2(info, &info[count+i].info2,
6533 driver, servername);
6534 break;
6535 case 3:
6536 result = fill_printer_driver_info3(info, &info[count+i].info3,
6537 driver, servername);
6538 break;
6539 case 4:
6540 result = fill_printer_driver_info4(info, &info[count+i].info4,
6541 driver, servername);
6542 break;
6543 case 5:
6544 result = fill_printer_driver_info5(info, &info[count+i].info5,
6545 driver, servername);
6546 break;
6547 case 6:
6548 result = fill_printer_driver_info6(info, &info[count+i].info6,
6549 driver, servername);
6550 break;
6551 case 8:
6552 result = fill_printer_driver_info8(info, &info[count+i].info8,
6553 driver, servername);
6554 break;
6555 default:
6556 result = WERR_UNKNOWN_LEVEL;
6557 break;
6560 free_a_printer_driver(driver);
6562 if (!W_ERROR_IS_OK(result)) {
6563 goto out;
6567 count += ndrivers;
6568 SAFE_FREE(list);
6571 out:
6572 SAFE_FREE(list);
6574 if (!W_ERROR_IS_OK(result)) {
6575 TALLOC_FREE(info);
6576 return result;
6579 *info_p = info;
6580 *count_p = count;
6582 return WERR_OK;
6585 /****************************************************************************
6586 Enumerates all printer drivers by level.
6587 ****************************************************************************/
6589 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
6590 const char *servername,
6591 const char *architecture,
6592 uint32_t level,
6593 union spoolss_DriverInfo **info_p,
6594 uint32_t *count_p)
6596 uint32_t a,i;
6597 WERROR result = WERR_OK;
6599 if (strequal(architecture, SPOOLSS_ARCHITECTURE_ALL)) {
6601 for (a=0; archi_table[a].long_archi != NULL; a++) {
6603 union spoolss_DriverInfo *info = NULL;
6604 uint32_t count = 0;
6606 result = enumprinterdrivers_level_by_architecture(mem_ctx,
6607 servername,
6608 archi_table[a].long_archi,
6609 level,
6610 &info,
6611 &count);
6612 if (!W_ERROR_IS_OK(result)) {
6613 continue;
6616 for (i=0; i < count; i++) {
6617 ADD_TO_ARRAY(mem_ctx, union spoolss_DriverInfo,
6618 info[i], info_p, count_p);
6622 return result;
6625 return enumprinterdrivers_level_by_architecture(mem_ctx,
6626 servername,
6627 architecture,
6628 level,
6629 info_p,
6630 count_p);
6633 /****************************************************************
6634 _spoolss_EnumPrinterDrivers
6635 ****************************************************************/
6637 WERROR _spoolss_EnumPrinterDrivers(pipes_struct *p,
6638 struct spoolss_EnumPrinterDrivers *r)
6640 const char *cservername;
6641 WERROR result;
6643 /* that's an [in out] buffer */
6645 if (!r->in.buffer && (r->in.offered != 0)) {
6646 return WERR_INVALID_PARAM;
6649 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
6651 *r->out.needed = 0;
6652 *r->out.count = 0;
6653 *r->out.info = NULL;
6655 cservername = canon_servername(r->in.server);
6657 if (!is_myname_or_ipaddr(cservername)) {
6658 return WERR_UNKNOWN_PRINTER_DRIVER;
6661 result = enumprinterdrivers_level(p->mem_ctx, cservername,
6662 r->in.environment,
6663 r->in.level,
6664 r->out.info,
6665 r->out.count);
6666 if (!W_ERROR_IS_OK(result)) {
6667 return result;
6670 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6671 spoolss_EnumPrinterDrivers, NULL,
6672 *r->out.info, r->in.level,
6673 *r->out.count);
6674 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6675 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6677 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6680 /****************************************************************************
6681 ****************************************************************************/
6683 static WERROR fill_form_info_1(TALLOC_CTX *mem_ctx,
6684 struct spoolss_FormInfo1 *r,
6685 const nt_forms_struct *form)
6687 r->form_name = talloc_strdup(mem_ctx, form->name);
6688 W_ERROR_HAVE_NO_MEMORY(r->form_name);
6690 r->flags = form->flag;
6691 r->size.width = form->width;
6692 r->size.height = form->length;
6693 r->area.left = form->left;
6694 r->area.top = form->top;
6695 r->area.right = form->right;
6696 r->area.bottom = form->bottom;
6698 return WERR_OK;
6701 /****************************************************************
6702 spoolss_enumforms_level1
6703 ****************************************************************/
6705 static WERROR spoolss_enumforms_level1(TALLOC_CTX *mem_ctx,
6706 const nt_forms_struct *builtin_forms,
6707 uint32_t num_builtin_forms,
6708 const nt_forms_struct *user_forms,
6709 uint32_t num_user_forms,
6710 union spoolss_FormInfo **info_p,
6711 uint32_t *count)
6713 union spoolss_FormInfo *info;
6714 WERROR result = WERR_OK;
6715 int i;
6717 *count = num_builtin_forms + num_user_forms;
6719 info = TALLOC_ARRAY(mem_ctx, union spoolss_FormInfo, *count);
6720 W_ERROR_HAVE_NO_MEMORY(info);
6722 /* construct the list of form structures */
6723 for (i=0; i<num_builtin_forms; i++) {
6724 DEBUGADD(6,("Filling builtin form number [%d]\n",i));
6725 result = fill_form_info_1(info, &info[i].info1,
6726 &builtin_forms[i]);
6727 if (!W_ERROR_IS_OK(result)) {
6728 goto out;
6732 for (i=0; i<num_user_forms; i++) {
6733 DEBUGADD(6,("Filling user form number [%d]\n",i));
6734 result = fill_form_info_1(info, &info[i+num_builtin_forms].info1,
6735 &user_forms[i]);
6736 if (!W_ERROR_IS_OK(result)) {
6737 goto out;
6741 out:
6742 if (!W_ERROR_IS_OK(result)) {
6743 TALLOC_FREE(info);
6744 *count = 0;
6745 return result;
6748 *info_p = info;
6750 return WERR_OK;
6753 /****************************************************************
6754 _spoolss_EnumForms
6755 ****************************************************************/
6757 WERROR _spoolss_EnumForms(pipes_struct *p,
6758 struct spoolss_EnumForms *r)
6760 WERROR result;
6761 nt_forms_struct *user_forms = NULL;
6762 nt_forms_struct *builtin_forms = NULL;
6763 uint32_t num_user_forms;
6764 uint32_t num_builtin_forms;
6766 *r->out.count = 0;
6767 *r->out.needed = 0;
6768 *r->out.info = NULL;
6770 /* that's an [in out] buffer */
6772 if (!r->in.buffer && (r->in.offered != 0) ) {
6773 return WERR_INVALID_PARAM;
6776 DEBUG(4,("_spoolss_EnumForms\n"));
6777 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
6778 DEBUGADD(5,("Info level [%d]\n", r->in.level));
6780 num_builtin_forms = get_builtin_ntforms(&builtin_forms);
6781 DEBUGADD(5,("Number of builtin forms [%d]\n", num_builtin_forms));
6782 num_user_forms = get_ntforms(&user_forms);
6783 DEBUGADD(5,("Number of user forms [%d]\n", num_user_forms));
6785 if (num_user_forms + num_builtin_forms == 0) {
6786 SAFE_FREE(builtin_forms);
6787 SAFE_FREE(user_forms);
6788 return WERR_NO_MORE_ITEMS;
6791 switch (r->in.level) {
6792 case 1:
6793 result = spoolss_enumforms_level1(p->mem_ctx,
6794 builtin_forms,
6795 num_builtin_forms,
6796 user_forms,
6797 num_user_forms,
6798 r->out.info,
6799 r->out.count);
6800 break;
6801 default:
6802 result = WERR_UNKNOWN_LEVEL;
6803 break;
6806 SAFE_FREE(user_forms);
6807 SAFE_FREE(builtin_forms);
6809 if (!W_ERROR_IS_OK(result)) {
6810 return result;
6813 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
6814 spoolss_EnumForms, NULL,
6815 *r->out.info, r->in.level,
6816 *r->out.count);
6817 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
6818 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
6820 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6823 /****************************************************************
6824 ****************************************************************/
6826 static WERROR find_form_byname(const char *name,
6827 nt_forms_struct *form)
6829 nt_forms_struct *list = NULL;
6830 int num_forms = 0, i = 0;
6832 if (get_a_builtin_ntform_by_string(name, form)) {
6833 return WERR_OK;
6836 num_forms = get_ntforms(&list);
6837 DEBUGADD(5,("Number of forms [%d]\n", num_forms));
6839 if (num_forms == 0) {
6840 return WERR_BADFID;
6843 /* Check if the requested name is in the list of form structures */
6844 for (i = 0; i < num_forms; i++) {
6846 DEBUG(4,("checking form %s (want %s)\n", list[i].name, name));
6848 if (strequal(name, list[i].name)) {
6849 DEBUGADD(6,("Found form %s number [%d]\n", name, i));
6850 *form = list[i];
6851 SAFE_FREE(list);
6852 return WERR_OK;
6856 SAFE_FREE(list);
6858 return WERR_BADFID;
6861 /****************************************************************
6862 _spoolss_GetForm
6863 ****************************************************************/
6865 WERROR _spoolss_GetForm(pipes_struct *p,
6866 struct spoolss_GetForm *r)
6868 WERROR result;
6869 nt_forms_struct form;
6871 /* that's an [in out] buffer */
6873 if (!r->in.buffer && (r->in.offered != 0)) {
6874 return WERR_INVALID_PARAM;
6877 DEBUG(4,("_spoolss_GetForm\n"));
6878 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
6879 DEBUGADD(5,("Info level [%d]\n", r->in.level));
6881 result = find_form_byname(r->in.form_name, &form);
6882 if (!W_ERROR_IS_OK(result)) {
6883 TALLOC_FREE(r->out.info);
6884 return result;
6887 switch (r->in.level) {
6888 case 1:
6889 result = fill_form_info_1(p->mem_ctx,
6890 &r->out.info->info1,
6891 &form);
6892 break;
6894 default:
6895 result = WERR_UNKNOWN_LEVEL;
6896 break;
6899 if (!W_ERROR_IS_OK(result)) {
6900 TALLOC_FREE(r->out.info);
6901 return result;
6904 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo, NULL,
6905 r->out.info, r->in.level);
6906 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
6908 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
6911 /****************************************************************************
6912 ****************************************************************************/
6914 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
6915 struct spoolss_PortInfo1 *r,
6916 const char *name)
6918 r->port_name = talloc_strdup(mem_ctx, name);
6919 W_ERROR_HAVE_NO_MEMORY(r->port_name);
6921 return WERR_OK;
6924 /****************************************************************************
6925 TODO: This probably needs distinguish between TCP/IP and Local ports
6926 somehow.
6927 ****************************************************************************/
6929 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
6930 struct spoolss_PortInfo2 *r,
6931 const char *name)
6933 r->port_name = talloc_strdup(mem_ctx, name);
6934 W_ERROR_HAVE_NO_MEMORY(r->port_name);
6936 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
6937 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
6939 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
6940 W_ERROR_HAVE_NO_MEMORY(r->description);
6942 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
6943 r->reserved = 0;
6945 return WERR_OK;
6949 /****************************************************************************
6950 wrapper around the enumer ports command
6951 ****************************************************************************/
6953 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
6955 char *cmd = lp_enumports_cmd();
6956 char **qlines = NULL;
6957 char *command = NULL;
6958 int numlines;
6959 int ret;
6960 int fd;
6962 *count = 0;
6963 *lines = NULL;
6965 /* if no hook then just fill in the default port */
6967 if ( !*cmd ) {
6968 if (!(qlines = TALLOC_ARRAY( NULL, char*, 2 ))) {
6969 return WERR_NOMEM;
6971 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
6972 TALLOC_FREE(qlines);
6973 return WERR_NOMEM;
6975 qlines[1] = NULL;
6976 numlines = 1;
6978 else {
6979 /* we have a valid enumport command */
6981 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
6982 if (!command) {
6983 return WERR_NOMEM;
6986 DEBUG(10,("Running [%s]\n", command));
6987 ret = smbrun(command, &fd);
6988 DEBUG(10,("Returned [%d]\n", ret));
6989 TALLOC_FREE(command);
6990 if (ret != 0) {
6991 if (fd != -1) {
6992 close(fd);
6994 return WERR_ACCESS_DENIED;
6997 numlines = 0;
6998 qlines = fd_lines_load(fd, &numlines, 0, NULL);
6999 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7000 close(fd);
7003 *count = numlines;
7004 *lines = qlines;
7006 return WERR_OK;
7009 /****************************************************************************
7010 enumports level 1.
7011 ****************************************************************************/
7013 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7014 union spoolss_PortInfo **info_p,
7015 uint32_t *count)
7017 union spoolss_PortInfo *info = NULL;
7018 int i=0;
7019 WERROR result = WERR_OK;
7020 char **qlines = NULL;
7021 int numlines = 0;
7023 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7024 if (!W_ERROR_IS_OK(result)) {
7025 goto out;
7028 if (numlines) {
7029 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7030 if (!info) {
7031 DEBUG(10,("Returning WERR_NOMEM\n"));
7032 result = WERR_NOMEM;
7033 goto out;
7036 for (i=0; i<numlines; i++) {
7037 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7038 result = fill_port_1(info, &info[i].info1, qlines[i]);
7039 if (!W_ERROR_IS_OK(result)) {
7040 goto out;
7044 TALLOC_FREE(qlines);
7046 out:
7047 if (!W_ERROR_IS_OK(result)) {
7048 TALLOC_FREE(info);
7049 TALLOC_FREE(qlines);
7050 *count = 0;
7051 *info_p = NULL;
7052 return result;
7055 *info_p = info;
7056 *count = numlines;
7058 return WERR_OK;
7061 /****************************************************************************
7062 enumports level 2.
7063 ****************************************************************************/
7065 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7066 union spoolss_PortInfo **info_p,
7067 uint32_t *count)
7069 union spoolss_PortInfo *info = NULL;
7070 int i=0;
7071 WERROR result = WERR_OK;
7072 char **qlines = NULL;
7073 int numlines = 0;
7075 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7076 if (!W_ERROR_IS_OK(result)) {
7077 goto out;
7080 if (numlines) {
7081 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7082 if (!info) {
7083 DEBUG(10,("Returning WERR_NOMEM\n"));
7084 result = WERR_NOMEM;
7085 goto out;
7088 for (i=0; i<numlines; i++) {
7089 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7090 result = fill_port_2(info, &info[i].info2, qlines[i]);
7091 if (!W_ERROR_IS_OK(result)) {
7092 goto out;
7096 TALLOC_FREE(qlines);
7098 out:
7099 if (!W_ERROR_IS_OK(result)) {
7100 TALLOC_FREE(info);
7101 TALLOC_FREE(qlines);
7102 *count = 0;
7103 *info_p = NULL;
7104 return result;
7107 *info_p = info;
7108 *count = numlines;
7110 return WERR_OK;
7113 /****************************************************************
7114 _spoolss_EnumPorts
7115 ****************************************************************/
7117 WERROR _spoolss_EnumPorts(pipes_struct *p,
7118 struct spoolss_EnumPorts *r)
7120 WERROR result;
7122 /* that's an [in out] buffer */
7124 if (!r->in.buffer && (r->in.offered != 0)) {
7125 return WERR_INVALID_PARAM;
7128 DEBUG(4,("_spoolss_EnumPorts\n"));
7130 *r->out.count = 0;
7131 *r->out.needed = 0;
7132 *r->out.info = NULL;
7134 switch (r->in.level) {
7135 case 1:
7136 result = enumports_level_1(p->mem_ctx, r->out.info,
7137 r->out.count);
7138 break;
7139 case 2:
7140 result = enumports_level_2(p->mem_ctx, r->out.info,
7141 r->out.count);
7142 break;
7143 default:
7144 return WERR_UNKNOWN_LEVEL;
7147 if (!W_ERROR_IS_OK(result)) {
7148 return result;
7151 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7152 spoolss_EnumPorts, NULL,
7153 *r->out.info, r->in.level,
7154 *r->out.count);
7155 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7156 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7158 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7161 /****************************************************************************
7162 ****************************************************************************/
7164 static WERROR spoolss_addprinterex_level_2(pipes_struct *p,
7165 const char *server,
7166 struct spoolss_SetPrinterInfoCtr *info_ctr,
7167 struct spoolss_DeviceMode *devmode,
7168 struct security_descriptor *sec_desc,
7169 struct spoolss_UserLevelCtr *user_ctr,
7170 struct policy_handle *handle)
7172 NT_PRINTER_INFO_LEVEL *printer = NULL;
7173 fstring name;
7174 int snum;
7175 WERROR err = WERR_OK;
7177 if ( !(printer = TALLOC_ZERO_P(NULL, NT_PRINTER_INFO_LEVEL)) ) {
7178 DEBUG(0,("spoolss_addprinterex_level_2: malloc fail.\n"));
7179 return WERR_NOMEM;
7182 /* convert from UNICODE to ASCII - this allocates the info_2 struct inside *printer.*/
7183 if (!convert_printer_info(info_ctr, printer)) {
7184 free_a_printer(&printer, 2);
7185 return WERR_NOMEM;
7188 /* samba does not have a concept of local, non-shared printers yet, so
7189 * make sure we always setup sharename - gd */
7190 if ((printer->info_2->sharename[0] == '\0') && (printer->info_2->printername != '\0')) {
7191 DEBUG(5, ("spoolss_addprinterex_level_2: "
7192 "no sharename has been set, setting printername %s as sharename\n",
7193 printer->info_2->printername));
7194 fstrcpy(printer->info_2->sharename, printer->info_2->printername);
7197 /* check to see if the printer already exists */
7199 if ((snum = print_queue_snum(printer->info_2->sharename)) != -1) {
7200 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7201 printer->info_2->sharename));
7202 free_a_printer(&printer, 2);
7203 return WERR_PRINTER_ALREADY_EXISTS;
7206 if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
7207 if ((snum = print_queue_snum(printer->info_2->printername)) != -1) {
7208 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7209 printer->info_2->printername));
7210 free_a_printer(&printer, 2);
7211 return WERR_PRINTER_ALREADY_EXISTS;
7215 /* validate printer info struct */
7216 if (!info_ctr->info.info2->printername ||
7217 strlen(info_ctr->info.info2->printername) == 0) {
7218 free_a_printer(&printer,2);
7219 return WERR_INVALID_PRINTER_NAME;
7221 if (!info_ctr->info.info2->portname ||
7222 strlen(info_ctr->info.info2->portname) == 0) {
7223 free_a_printer(&printer,2);
7224 return WERR_UNKNOWN_PORT;
7226 if (!info_ctr->info.info2->drivername ||
7227 strlen(info_ctr->info.info2->drivername) == 0) {
7228 free_a_printer(&printer,2);
7229 return WERR_UNKNOWN_PRINTER_DRIVER;
7231 if (!info_ctr->info.info2->printprocessor ||
7232 strlen(info_ctr->info.info2->printprocessor) == 0) {
7233 free_a_printer(&printer,2);
7234 return WERR_UNKNOWN_PRINTPROCESSOR;
7237 /* FIXME!!! smbd should check to see if the driver is installed before
7238 trying to add a printer like this --jerry */
7240 if (*lp_addprinter_cmd() ) {
7241 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
7242 printer) ) {
7243 free_a_printer(&printer,2);
7244 return WERR_ACCESS_DENIED;
7246 } else {
7247 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
7248 "smb.conf parameter \"addprinter command\" is defined. This"
7249 "parameter must exist for this call to succeed\n",
7250 printer->info_2->sharename ));
7253 /* use our primary netbios name since get_a_printer() will convert
7254 it to what the client expects on a case by case basis */
7256 slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname(),
7257 printer->info_2->sharename);
7260 if ((snum = print_queue_snum(printer->info_2->sharename)) == -1) {
7261 free_a_printer(&printer,2);
7262 return WERR_ACCESS_DENIED;
7265 /* you must be a printer admin to add a new printer */
7266 if (!print_access_check(p->server_info, snum, PRINTER_ACCESS_ADMINISTER)) {
7267 free_a_printer(&printer,2);
7268 return WERR_ACCESS_DENIED;
7272 * Do sanity check on the requested changes for Samba.
7275 if (!check_printer_ok(printer->info_2, snum)) {
7276 free_a_printer(&printer,2);
7277 return WERR_INVALID_PARAM;
7281 * When a printer is created, the drivername bound to the printer is used
7282 * to lookup previously saved driver initialization info, which is then
7283 * bound to the new printer, simulating what happens in the Windows arch.
7286 if (!devmode)
7288 set_driver_init(printer, 2);
7290 else
7292 /* A valid devmode was included, convert and link it
7294 DEBUGADD(10, ("spoolss_addprinterex_level_2: devmode included, converting\n"));
7296 if (!convert_devicemode(printer->info_2->printername, devmode,
7297 &printer->info_2->devmode)) {
7298 return WERR_NOMEM;
7302 /* write the ASCII on disk */
7303 err = mod_a_printer(printer, 2);
7304 if (!W_ERROR_IS_OK(err)) {
7305 free_a_printer(&printer,2);
7306 return err;
7309 if (!open_printer_hnd(p, handle, name, PRINTER_ACCESS_ADMINISTER)) {
7310 /* Handle open failed - remove addition. */
7311 del_a_printer(printer->info_2->sharename);
7312 free_a_printer(&printer,2);
7313 ZERO_STRUCTP(handle);
7314 return WERR_ACCESS_DENIED;
7317 update_c_setprinter(false);
7318 free_a_printer(&printer,2);
7320 return WERR_OK;
7323 /****************************************************************
7324 _spoolss_AddPrinterEx
7325 ****************************************************************/
7327 WERROR _spoolss_AddPrinterEx(pipes_struct *p,
7328 struct spoolss_AddPrinterEx *r)
7330 switch (r->in.info_ctr->level) {
7331 case 1:
7332 /* we don't handle yet */
7333 /* but I know what to do ... */
7334 return WERR_UNKNOWN_LEVEL;
7335 case 2:
7336 return spoolss_addprinterex_level_2(p, r->in.server,
7337 r->in.info_ctr,
7338 r->in.devmode_ctr->devmode,
7339 r->in.secdesc_ctr->sd,
7340 r->in.userlevel_ctr,
7341 r->out.handle);
7342 default:
7343 return WERR_UNKNOWN_LEVEL;
7347 /****************************************************************
7348 _spoolss_AddPrinter
7349 ****************************************************************/
7351 WERROR _spoolss_AddPrinter(pipes_struct *p,
7352 struct spoolss_AddPrinter *r)
7354 struct spoolss_AddPrinterEx a;
7355 struct spoolss_UserLevelCtr userlevel_ctr;
7357 ZERO_STRUCT(userlevel_ctr);
7359 userlevel_ctr.level = 1;
7361 a.in.server = r->in.server;
7362 a.in.info_ctr = r->in.info_ctr;
7363 a.in.devmode_ctr = r->in.devmode_ctr;
7364 a.in.secdesc_ctr = r->in.secdesc_ctr;
7365 a.in.userlevel_ctr = &userlevel_ctr;
7366 a.out.handle = r->out.handle;
7368 return _spoolss_AddPrinterEx(p, &a);
7371 /****************************************************************
7372 _spoolss_AddPrinterDriver
7373 ****************************************************************/
7375 WERROR _spoolss_AddPrinterDriver(pipes_struct *p,
7376 struct spoolss_AddPrinterDriver *r)
7378 WERROR err = WERR_OK;
7379 char *driver_name = NULL;
7380 uint32_t version;
7381 const char *fn;
7383 switch (p->hdr_req.opnum) {
7384 case NDR_SPOOLSS_ADDPRINTERDRIVER:
7385 fn = "_spoolss_AddPrinterDriver";
7386 break;
7387 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
7388 fn = "_spoolss_AddPrinterDriverEx";
7389 break;
7390 default:
7391 return WERR_INVALID_PARAM;
7395 /* FIXME */
7396 if (r->in.info_ctr->level != 3 && r->in.info_ctr->level != 6) {
7397 /* Clever hack from Martin Zielinski <mz@seh.de>
7398 * to allow downgrade from level 8 (Vista).
7400 DEBUG(0,("%s: level %d not yet implemented\n", fn,
7401 r->in.info_ctr->level));
7402 return WERR_UNKNOWN_LEVEL;
7405 DEBUG(5,("Cleaning driver's information\n"));
7406 err = clean_up_driver_struct(p, r->in.info_ctr);
7407 if (!W_ERROR_IS_OK(err))
7408 goto done;
7410 DEBUG(5,("Moving driver to final destination\n"));
7411 if( !W_ERROR_IS_OK(err = move_driver_to_download_area(p, r->in.info_ctr,
7412 &err)) ) {
7413 goto done;
7416 if (add_a_printer_driver(p->mem_ctx, r->in.info_ctr, &driver_name, &version)!=0) {
7417 err = WERR_ACCESS_DENIED;
7418 goto done;
7422 * I think this is where he DrvUpgradePrinter() hook would be
7423 * be called in a driver's interface DLL on a Windows NT 4.0/2k
7424 * server. Right now, we just need to send ourselves a message
7425 * to update each printer bound to this driver. --jerry
7428 if (!srv_spoolss_drv_upgrade_printer(driver_name)) {
7429 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
7430 fn, driver_name));
7434 * Based on the version (e.g. driver destination dir: 0=9x,2=Nt/2k,3=2k/Xp),
7435 * decide if the driver init data should be deleted. The rules are:
7436 * 1) never delete init data if it is a 9x driver, they don't use it anyway
7437 * 2) delete init data only if there is no 2k/Xp driver
7438 * 3) always delete init data
7439 * The generalized rule is always use init data from the highest order driver.
7440 * It is necessary to follow the driver install by an initialization step to
7441 * finish off this process.
7444 switch (version) {
7446 * 9x printer driver - never delete init data
7448 case 0:
7449 DEBUG(10,("%s: init data not deleted for 9x driver [%s]\n",
7450 fn, driver_name));
7451 break;
7454 * Nt or 2k (compatiblity mode) printer driver - only delete init data if
7455 * there is no 2k/Xp driver init data for this driver name.
7457 case 2:
7459 struct spoolss_DriverInfo8 *driver1;
7461 if (!W_ERROR_IS_OK(get_a_printer_driver(p->mem_ctx, &driver1, driver_name, "Windows NT x86", 3))) {
7463 * No 2k/Xp driver found, delete init data (if any) for the new Nt driver.
7465 if (!del_driver_init(driver_name))
7466 DEBUG(6,("%s: del_driver_init(%s) Nt failed!\n",
7467 fn, driver_name));
7468 } else {
7470 * a 2k/Xp driver was found, don't delete init data because Nt driver will use it.
7472 free_a_printer_driver(driver1);
7473 DEBUG(10,("%s: init data not deleted for Nt driver [%s]\n",
7474 fn, driver_name));
7477 break;
7480 * 2k or Xp printer driver - always delete init data
7482 case 3:
7483 if (!del_driver_init(driver_name))
7484 DEBUG(6,("%s: del_driver_init(%s) 2k/Xp failed!\n",
7485 fn, driver_name));
7486 break;
7488 default:
7489 DEBUG(0,("%s: invalid level=%d\n", fn,
7490 r->in.info_ctr->level));
7491 break;
7495 done:
7496 return err;
7499 /****************************************************************
7500 _spoolss_AddPrinterDriverEx
7501 ****************************************************************/
7503 WERROR _spoolss_AddPrinterDriverEx(pipes_struct *p,
7504 struct spoolss_AddPrinterDriverEx *r)
7506 struct spoolss_AddPrinterDriver a;
7509 * we only support the semantics of AddPrinterDriver()
7510 * i.e. only copy files that are newer than existing ones
7513 if (r->in.flags != APD_COPY_NEW_FILES) {
7514 return WERR_ACCESS_DENIED;
7517 a.in.servername = r->in.servername;
7518 a.in.info_ctr = r->in.info_ctr;
7520 return _spoolss_AddPrinterDriver(p, &a);
7523 /****************************************************************************
7524 ****************************************************************************/
7526 struct _spoolss_paths {
7527 int type;
7528 const char *share;
7529 const char *dir;
7532 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
7534 static const struct _spoolss_paths spoolss_paths[]= {
7535 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
7536 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
7539 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
7540 const char *servername,
7541 const char *environment,
7542 int component,
7543 char **path)
7545 const char *pservername = NULL;
7546 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
7547 const char *short_archi;
7549 *path = NULL;
7551 /* environment may be empty */
7552 if (environment && strlen(environment)) {
7553 long_archi = environment;
7556 /* servername may be empty */
7557 if (servername && strlen(servername)) {
7558 pservername = canon_servername(servername);
7560 if (!is_myname_or_ipaddr(pservername)) {
7561 return WERR_INVALID_PARAM;
7565 if (!(short_archi = get_short_archi(long_archi))) {
7566 return WERR_INVALID_ENVIRONMENT;
7569 switch (component) {
7570 case SPOOLSS_PRTPROCS_PATH:
7571 case SPOOLSS_DRIVER_PATH:
7572 if (pservername) {
7573 *path = talloc_asprintf(mem_ctx,
7574 "\\\\%s\\%s\\%s",
7575 pservername,
7576 spoolss_paths[component].share,
7577 short_archi);
7578 } else {
7579 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
7580 SPOOLSS_DEFAULT_SERVER_PATH,
7581 spoolss_paths[component].dir,
7582 short_archi);
7584 break;
7585 default:
7586 return WERR_INVALID_PARAM;
7589 if (!*path) {
7590 return WERR_NOMEM;
7593 return WERR_OK;
7596 /****************************************************************************
7597 ****************************************************************************/
7599 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
7600 const char *servername,
7601 const char *environment,
7602 struct spoolss_DriverDirectoryInfo1 *r)
7604 WERROR werr;
7605 char *path = NULL;
7607 werr = compose_spoolss_server_path(mem_ctx,
7608 servername,
7609 environment,
7610 SPOOLSS_DRIVER_PATH,
7611 &path);
7612 if (!W_ERROR_IS_OK(werr)) {
7613 return werr;
7616 DEBUG(4,("printer driver directory: [%s]\n", path));
7618 r->directory_name = path;
7620 return WERR_OK;
7623 /****************************************************************
7624 _spoolss_GetPrinterDriverDirectory
7625 ****************************************************************/
7627 WERROR _spoolss_GetPrinterDriverDirectory(pipes_struct *p,
7628 struct spoolss_GetPrinterDriverDirectory *r)
7630 WERROR werror;
7632 /* that's an [in out] buffer */
7634 if (!r->in.buffer && (r->in.offered != 0)) {
7635 return WERR_INVALID_PARAM;
7638 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
7639 r->in.level));
7641 *r->out.needed = 0;
7643 /* r->in.level is ignored */
7645 werror = getprinterdriverdir_level_1(p->mem_ctx,
7646 r->in.server,
7647 r->in.environment,
7648 &r->out.info->info1);
7649 if (!W_ERROR_IS_OK(werror)) {
7650 TALLOC_FREE(r->out.info);
7651 return werror;
7654 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo, NULL,
7655 r->out.info, r->in.level);
7656 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7658 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7661 /****************************************************************
7662 _spoolss_EnumPrinterData
7663 ****************************************************************/
7665 WERROR _spoolss_EnumPrinterData(pipes_struct *p,
7666 struct spoolss_EnumPrinterData *r)
7668 NT_PRINTER_INFO_LEVEL *printer = NULL;
7669 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7670 int snum;
7671 WERROR result;
7672 struct regval_blob *val = NULL;
7673 NT_PRINTER_DATA *p_data;
7674 int i, key_index, num_values;
7675 int name_length;
7677 *r->out.value_needed = 0;
7678 *r->out.type = REG_NONE;
7679 *r->out.data_needed = 0;
7681 DEBUG(5,("_spoolss_EnumPrinterData\n"));
7683 if (!Printer) {
7684 DEBUG(2,("_spoolss_EnumPrinterData: Invalid handle (%s:%u:%u).\n",
7685 OUR_HANDLE(r->in.handle)));
7686 return WERR_BADFID;
7689 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7690 return WERR_BADFID;
7693 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
7694 if (!W_ERROR_IS_OK(result)) {
7695 return result;
7698 p_data = printer->info_2->data;
7699 key_index = lookup_printerkey( p_data, SPOOL_PRINTERDATA_KEY );
7701 result = WERR_OK;
7704 * The NT machine wants to know the biggest size of value and data
7706 * cf: MSDN EnumPrinterData remark section
7709 if (!r->in.value_offered && !r->in.data_offered && (key_index != -1)) {
7711 uint32_t biggest_valuesize = 0;
7712 uint32_t biggest_datasize = 0;
7714 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
7716 num_values = regval_ctr_numvals( p_data->keys[key_index].values );
7718 for ( i=0; i<num_values; i++ )
7720 val = regval_ctr_specific_value( p_data->keys[key_index].values, i );
7722 name_length = strlen(val->valuename);
7723 if ( strlen(val->valuename) > biggest_valuesize )
7724 biggest_valuesize = name_length;
7726 if ( val->size > biggest_datasize )
7727 biggest_datasize = val->size;
7729 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
7730 biggest_datasize));
7733 /* the value is an UNICODE string but real_value_size is the length
7734 in bytes including the trailing 0 */
7736 *r->out.value_needed = 2 * (1 + biggest_valuesize);
7737 *r->out.data_needed = biggest_datasize;
7739 DEBUG(6,("final values: [%d], [%d]\n",
7740 *r->out.value_needed, *r->out.data_needed));
7742 goto done;
7746 * the value len is wrong in NT sp3
7747 * that's the number of bytes not the number of unicode chars
7750 if (key_index != -1) {
7751 val = regval_ctr_specific_value(p_data->keys[key_index].values,
7752 r->in.enum_index);
7755 if (!val) {
7757 /* out_value should default to "" or else NT4 has
7758 problems unmarshalling the response */
7760 if (r->in.value_offered) {
7761 *r->out.value_needed = 1;
7762 r->out.value_name = talloc_strdup(r, "");
7763 if (!r->out.value_name) {
7764 result = WERR_NOMEM;
7765 goto done;
7767 } else {
7768 r->out.value_name = NULL;
7769 *r->out.value_needed = 0;
7772 /* the data is counted in bytes */
7774 *r->out.data_needed = r->in.data_offered;
7776 result = WERR_NO_MORE_ITEMS;
7777 } else {
7779 * the value is:
7780 * - counted in bytes in the request
7781 * - counted in UNICODE chars in the max reply
7782 * - counted in bytes in the real size
7784 * take a pause *before* coding not *during* coding
7787 /* name */
7788 if (r->in.value_offered) {
7789 r->out.value_name = talloc_strdup(r, regval_name(val));
7790 if (!r->out.value_name) {
7791 result = WERR_NOMEM;
7792 goto done;
7794 *r->out.value_needed = strlen_m(regval_name(val));
7795 } else {
7796 r->out.value_name = NULL;
7797 *r->out.value_needed = 0;
7800 /* type */
7802 *r->out.type = regval_type(val);
7804 /* data - counted in bytes */
7807 * See the section "Dynamically Typed Query Parameters"
7808 * in MS-RPRN.
7811 if (r->out.data && regval_data_p(val) &&
7812 regval_size(val) && r->in.data_offered) {
7813 memcpy(r->out.data, regval_data_p(val),
7814 MIN(regval_size(val),r->in.data_offered));
7817 *r->out.data_needed = regval_size(val);
7820 done:
7821 free_a_printer(&printer, 2);
7822 return result;
7825 /****************************************************************
7826 _spoolss_SetPrinterData
7827 ****************************************************************/
7829 WERROR _spoolss_SetPrinterData(pipes_struct *p,
7830 struct spoolss_SetPrinterData *r)
7832 struct spoolss_SetPrinterDataEx r2;
7834 r2.in.handle = r->in.handle;
7835 r2.in.key_name = "PrinterDriverData";
7836 r2.in.value_name = r->in.value_name;
7837 r2.in.type = r->in.type;
7838 r2.in.data = r->in.data;
7839 r2.in._offered = r->in._offered;
7841 return _spoolss_SetPrinterDataEx(p, &r2);
7844 /****************************************************************
7845 _spoolss_ResetPrinter
7846 ****************************************************************/
7848 WERROR _spoolss_ResetPrinter(pipes_struct *p,
7849 struct spoolss_ResetPrinter *r)
7851 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7852 int snum;
7854 DEBUG(5,("_spoolss_ResetPrinter\n"));
7857 * All we do is to check to see if the handle and queue is valid.
7858 * This call really doesn't mean anything to us because we only
7859 * support RAW printing. --jerry
7862 if (!Printer) {
7863 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
7864 OUR_HANDLE(r->in.handle)));
7865 return WERR_BADFID;
7868 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
7869 return WERR_BADFID;
7872 /* blindly return success */
7873 return WERR_OK;
7876 /****************************************************************
7877 _spoolss_DeletePrinterData
7878 ****************************************************************/
7880 WERROR _spoolss_DeletePrinterData(pipes_struct *p,
7881 struct spoolss_DeletePrinterData *r)
7883 struct spoolss_DeletePrinterDataEx r2;
7885 r2.in.handle = r->in.handle;
7886 r2.in.key_name = "PrinterDriverData";
7887 r2.in.value_name = r->in.value_name;
7889 return _spoolss_DeletePrinterDataEx(p, &r2);
7892 /****************************************************************
7893 _spoolss_AddForm
7894 ****************************************************************/
7896 WERROR _spoolss_AddForm(pipes_struct *p,
7897 struct spoolss_AddForm *r)
7899 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
7900 nt_forms_struct tmpForm;
7901 int snum = -1;
7902 WERROR status = WERR_OK;
7903 NT_PRINTER_INFO_LEVEL *printer = NULL;
7904 SE_PRIV se_printop = SE_PRINT_OPERATOR;
7906 int count=0;
7907 nt_forms_struct *list=NULL;
7908 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7910 DEBUG(5,("_spoolss_AddForm\n"));
7912 if (!Printer) {
7913 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
7914 OUR_HANDLE(r->in.handle)));
7915 return WERR_BADFID;
7919 /* forms can be added on printer of on the print server handle */
7921 if ( Printer->printer_type == SPLHND_PRINTER )
7923 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
7924 return WERR_BADFID;
7926 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
7927 if (!W_ERROR_IS_OK(status))
7928 goto done;
7931 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
7932 and not a printer admin, then fail */
7934 if ((p->server_info->utok.uid != sec_initial_uid()) &&
7935 !user_has_privileges(p->server_info->ptok, &se_printop) &&
7936 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
7937 NULL, NULL,
7938 p->server_info->ptok,
7939 lp_printer_admin(snum))) {
7940 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
7941 return WERR_ACCESS_DENIED;
7944 /* can't add if builtin */
7946 if (get_a_builtin_ntform_by_string(form->form_name, &tmpForm)) {
7947 status = WERR_FILE_EXISTS;
7948 goto done;
7951 count = get_ntforms(&list);
7953 if(!add_a_form(&list, form, &count)) {
7954 status = WERR_NOMEM;
7955 goto done;
7958 become_root();
7959 write_ntforms(&list, count);
7960 unbecome_root();
7963 * ChangeID must always be set if this is a printer
7966 if ( Printer->printer_type == SPLHND_PRINTER )
7967 status = mod_a_printer(printer, 2);
7969 done:
7970 if ( printer )
7971 free_a_printer(&printer, 2);
7972 SAFE_FREE(list);
7974 return status;
7977 /****************************************************************
7978 _spoolss_DeleteForm
7979 ****************************************************************/
7981 WERROR _spoolss_DeleteForm(pipes_struct *p,
7982 struct spoolss_DeleteForm *r)
7984 const char *form_name = r->in.form_name;
7985 nt_forms_struct tmpForm;
7986 int count=0;
7987 nt_forms_struct *list=NULL;
7988 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
7989 int snum = -1;
7990 WERROR status = WERR_OK;
7991 NT_PRINTER_INFO_LEVEL *printer = NULL;
7992 SE_PRIV se_printop = SE_PRINT_OPERATOR;
7993 bool ret = false;
7995 DEBUG(5,("_spoolss_DeleteForm\n"));
7997 if (!Printer) {
7998 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
7999 OUR_HANDLE(r->in.handle)));
8000 return WERR_BADFID;
8003 /* forms can be deleted on printer of on the print server handle */
8005 if ( Printer->printer_type == SPLHND_PRINTER )
8007 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8008 return WERR_BADFID;
8010 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8011 if (!W_ERROR_IS_OK(status))
8012 goto done;
8015 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8016 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8017 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8018 NULL, NULL,
8019 p->server_info->ptok,
8020 lp_printer_admin(snum))) {
8021 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8022 return WERR_ACCESS_DENIED;
8026 /* can't delete if builtin */
8028 if (get_a_builtin_ntform_by_string(form_name,&tmpForm)) {
8029 status = WERR_INVALID_PARAM;
8030 goto done;
8033 count = get_ntforms(&list);
8035 become_root();
8036 ret = delete_a_form(&list, form_name, &count, &status);
8037 unbecome_root();
8038 if (ret == false) {
8039 goto done;
8043 * ChangeID must always be set if this is a printer
8046 if ( Printer->printer_type == SPLHND_PRINTER )
8047 status = mod_a_printer(printer, 2);
8049 done:
8050 if ( printer )
8051 free_a_printer(&printer, 2);
8052 SAFE_FREE(list);
8054 return status;
8057 /****************************************************************
8058 _spoolss_SetForm
8059 ****************************************************************/
8061 WERROR _spoolss_SetForm(pipes_struct *p,
8062 struct spoolss_SetForm *r)
8064 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8065 nt_forms_struct tmpForm;
8066 int snum = -1;
8067 WERROR status = WERR_OK;
8068 NT_PRINTER_INFO_LEVEL *printer = NULL;
8069 SE_PRIV se_printop = SE_PRINT_OPERATOR;
8071 int count=0;
8072 nt_forms_struct *list=NULL;
8073 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8075 DEBUG(5,("_spoolss_SetForm\n"));
8077 if (!Printer) {
8078 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8079 OUR_HANDLE(r->in.handle)));
8080 return WERR_BADFID;
8083 /* forms can be modified on printer of on the print server handle */
8085 if ( Printer->printer_type == SPLHND_PRINTER )
8087 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8088 return WERR_BADFID;
8090 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8091 if (!W_ERROR_IS_OK(status))
8092 goto done;
8095 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8096 and not a printer admin, then fail */
8098 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8099 !user_has_privileges(p->server_info->ptok, &se_printop) &&
8100 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8101 NULL, NULL,
8102 p->server_info->ptok,
8103 lp_printer_admin(snum))) {
8104 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8105 return WERR_ACCESS_DENIED;
8108 /* can't set if builtin */
8109 if (get_a_builtin_ntform_by_string(form->form_name, &tmpForm)) {
8110 status = WERR_INVALID_PARAM;
8111 goto done;
8114 count = get_ntforms(&list);
8115 update_a_form(&list, form, count);
8116 become_root();
8117 write_ntforms(&list, count);
8118 unbecome_root();
8121 * ChangeID must always be set if this is a printer
8124 if ( Printer->printer_type == SPLHND_PRINTER )
8125 status = mod_a_printer(printer, 2);
8128 done:
8129 if ( printer )
8130 free_a_printer(&printer, 2);
8131 SAFE_FREE(list);
8133 return status;
8136 /****************************************************************************
8137 fill_print_processor1
8138 ****************************************************************************/
8140 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8141 struct spoolss_PrintProcessorInfo1 *r,
8142 const char *print_processor_name)
8144 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8145 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8147 return WERR_OK;
8150 /****************************************************************************
8151 enumprintprocessors level 1.
8152 ****************************************************************************/
8154 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8155 union spoolss_PrintProcessorInfo **info_p,
8156 uint32_t *count)
8158 union spoolss_PrintProcessorInfo *info;
8159 WERROR result;
8161 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8162 W_ERROR_HAVE_NO_MEMORY(info);
8164 *count = 1;
8166 result = fill_print_processor1(info, &info[0].info1, "winprint");
8167 if (!W_ERROR_IS_OK(result)) {
8168 goto out;
8171 out:
8172 if (!W_ERROR_IS_OK(result)) {
8173 TALLOC_FREE(info);
8174 *count = 0;
8175 return result;
8178 *info_p = info;
8180 return WERR_OK;
8183 /****************************************************************
8184 _spoolss_EnumPrintProcessors
8185 ****************************************************************/
8187 WERROR _spoolss_EnumPrintProcessors(pipes_struct *p,
8188 struct spoolss_EnumPrintProcessors *r)
8190 WERROR result;
8192 /* that's an [in out] buffer */
8194 if (!r->in.buffer && (r->in.offered != 0)) {
8195 return WERR_INVALID_PARAM;
8198 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8201 * Enumerate the print processors ...
8203 * Just reply with "winprint", to keep NT happy
8204 * and I can use my nice printer checker.
8207 *r->out.count = 0;
8208 *r->out.needed = 0;
8209 *r->out.info = NULL;
8211 switch (r->in.level) {
8212 case 1:
8213 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8214 r->out.count);
8215 break;
8216 default:
8217 return WERR_UNKNOWN_LEVEL;
8220 if (!W_ERROR_IS_OK(result)) {
8221 return result;
8224 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8225 spoolss_EnumPrintProcessors, NULL,
8226 *r->out.info, r->in.level,
8227 *r->out.count);
8228 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8229 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8231 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8234 /****************************************************************************
8235 fill_printprocdatatype1
8236 ****************************************************************************/
8238 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8239 struct spoolss_PrintProcDataTypesInfo1 *r,
8240 const char *name_array)
8242 r->name_array = talloc_strdup(mem_ctx, name_array);
8243 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8245 return WERR_OK;
8248 /****************************************************************************
8249 enumprintprocdatatypes level 1.
8250 ****************************************************************************/
8252 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8253 union spoolss_PrintProcDataTypesInfo **info_p,
8254 uint32_t *count)
8256 WERROR result;
8257 union spoolss_PrintProcDataTypesInfo *info;
8259 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8260 W_ERROR_HAVE_NO_MEMORY(info);
8262 *count = 1;
8264 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
8265 if (!W_ERROR_IS_OK(result)) {
8266 goto out;
8269 out:
8270 if (!W_ERROR_IS_OK(result)) {
8271 TALLOC_FREE(info);
8272 *count = 0;
8273 return result;
8276 *info_p = info;
8278 return WERR_OK;
8281 /****************************************************************
8282 _spoolss_EnumPrintProcDataTypes
8283 ****************************************************************/
8285 WERROR _spoolss_EnumPrintProcDataTypes(pipes_struct *p,
8286 struct spoolss_EnumPrintProcDataTypes *r)
8288 WERROR result;
8290 /* that's an [in out] buffer */
8292 if (!r->in.buffer && (r->in.offered != 0)) {
8293 return WERR_INVALID_PARAM;
8296 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8298 *r->out.count = 0;
8299 *r->out.needed = 0;
8300 *r->out.info = NULL;
8302 switch (r->in.level) {
8303 case 1:
8304 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
8305 r->out.count);
8306 break;
8307 default:
8308 return WERR_UNKNOWN_LEVEL;
8311 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8312 spoolss_EnumPrintProcDataTypes, NULL,
8313 *r->out.info, r->in.level,
8314 *r->out.count);
8315 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8316 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8318 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8321 /****************************************************************************
8322 fill_monitor_1
8323 ****************************************************************************/
8325 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
8326 struct spoolss_MonitorInfo1 *r,
8327 const char *monitor_name)
8329 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8330 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8332 return WERR_OK;
8335 /****************************************************************************
8336 fill_monitor_2
8337 ****************************************************************************/
8339 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
8340 struct spoolss_MonitorInfo2 *r,
8341 const char *monitor_name,
8342 const char *environment,
8343 const char *dll_name)
8345 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8346 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8347 r->environment = talloc_strdup(mem_ctx, environment);
8348 W_ERROR_HAVE_NO_MEMORY(r->environment);
8349 r->dll_name = talloc_strdup(mem_ctx, dll_name);
8350 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
8352 return WERR_OK;
8355 /****************************************************************************
8356 enumprintmonitors level 1.
8357 ****************************************************************************/
8359 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
8360 union spoolss_MonitorInfo **info_p,
8361 uint32_t *count)
8363 union spoolss_MonitorInfo *info;
8364 WERROR result = WERR_OK;
8366 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8367 W_ERROR_HAVE_NO_MEMORY(info);
8369 *count = 2;
8371 result = fill_monitor_1(info, &info[0].info1,
8372 SPL_LOCAL_PORT);
8373 if (!W_ERROR_IS_OK(result)) {
8374 goto out;
8377 result = fill_monitor_1(info, &info[1].info1,
8378 SPL_TCPIP_PORT);
8379 if (!W_ERROR_IS_OK(result)) {
8380 goto out;
8383 out:
8384 if (!W_ERROR_IS_OK(result)) {
8385 TALLOC_FREE(info);
8386 *count = 0;
8387 return result;
8390 *info_p = info;
8392 return WERR_OK;
8395 /****************************************************************************
8396 enumprintmonitors level 2.
8397 ****************************************************************************/
8399 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
8400 union spoolss_MonitorInfo **info_p,
8401 uint32_t *count)
8403 union spoolss_MonitorInfo *info;
8404 WERROR result = WERR_OK;
8406 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8407 W_ERROR_HAVE_NO_MEMORY(info);
8409 *count = 2;
8411 result = fill_monitor_2(info, &info[0].info2,
8412 SPL_LOCAL_PORT,
8413 "Windows NT X86", /* FIXME */
8414 "localmon.dll");
8415 if (!W_ERROR_IS_OK(result)) {
8416 goto out;
8419 result = fill_monitor_2(info, &info[1].info2,
8420 SPL_TCPIP_PORT,
8421 "Windows NT X86", /* FIXME */
8422 "tcpmon.dll");
8423 if (!W_ERROR_IS_OK(result)) {
8424 goto out;
8427 out:
8428 if (!W_ERROR_IS_OK(result)) {
8429 TALLOC_FREE(info);
8430 *count = 0;
8431 return result;
8434 *info_p = info;
8436 return WERR_OK;
8439 /****************************************************************
8440 _spoolss_EnumMonitors
8441 ****************************************************************/
8443 WERROR _spoolss_EnumMonitors(pipes_struct *p,
8444 struct spoolss_EnumMonitors *r)
8446 WERROR result;
8448 /* that's an [in out] buffer */
8450 if (!r->in.buffer && (r->in.offered != 0)) {
8451 return WERR_INVALID_PARAM;
8454 DEBUG(5,("_spoolss_EnumMonitors\n"));
8457 * Enumerate the print monitors ...
8459 * Just reply with "Local Port", to keep NT happy
8460 * and I can use my nice printer checker.
8463 *r->out.count = 0;
8464 *r->out.needed = 0;
8465 *r->out.info = NULL;
8467 switch (r->in.level) {
8468 case 1:
8469 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
8470 r->out.count);
8471 break;
8472 case 2:
8473 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
8474 r->out.count);
8475 break;
8476 default:
8477 return WERR_UNKNOWN_LEVEL;
8480 if (!W_ERROR_IS_OK(result)) {
8481 return result;
8484 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8485 spoolss_EnumMonitors, NULL,
8486 *r->out.info, r->in.level,
8487 *r->out.count);
8488 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8489 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8491 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8494 /****************************************************************************
8495 ****************************************************************************/
8497 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
8498 const print_queue_struct *queue,
8499 int count, int snum,
8500 const NT_PRINTER_INFO_LEVEL *ntprinter,
8501 uint32_t jobid,
8502 struct spoolss_JobInfo1 *r)
8504 int i = 0;
8505 bool found = false;
8507 for (i=0; i<count && found == false; i++) {
8508 if (queue[i].job == (int)jobid) {
8509 found = true;
8513 if (found == false) {
8514 /* NT treats not found as bad param... yet another bad choice */
8515 return WERR_INVALID_PARAM;
8518 return fill_job_info1(mem_ctx,
8520 &queue[i-1],
8522 snum,
8523 ntprinter);
8526 /****************************************************************************
8527 ****************************************************************************/
8529 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
8530 const print_queue_struct *queue,
8531 int count, int snum,
8532 const NT_PRINTER_INFO_LEVEL *ntprinter,
8533 uint32_t jobid,
8534 struct spoolss_JobInfo2 *r)
8536 int i = 0;
8537 bool found = false;
8538 struct spoolss_DeviceMode *devmode;
8539 NT_DEVICEMODE *nt_devmode;
8540 WERROR result;
8542 for (i=0; i<count && found == false; i++) {
8543 if (queue[i].job == (int)jobid) {
8544 found = true;
8548 if (found == false) {
8549 /* NT treats not found as bad param... yet another bad
8550 choice */
8551 return WERR_INVALID_PARAM;
8555 * if the print job does not have a DEVMODE associated with it,
8556 * just use the one for the printer. A NULL devicemode is not
8557 * a failure condition
8560 nt_devmode = print_job_devmode(lp_const_servicename(snum), jobid);
8561 if (nt_devmode) {
8562 devmode = TALLOC_ZERO_P(mem_ctx, struct spoolss_DeviceMode);
8563 W_ERROR_HAVE_NO_MEMORY(devmode);
8564 result = convert_nt_devicemode(devmode, devmode, nt_devmode);
8565 if (!W_ERROR_IS_OK(result)) {
8566 return result;
8568 } else {
8569 devmode = construct_dev_mode(mem_ctx, lp_const_servicename(snum));
8570 W_ERROR_HAVE_NO_MEMORY(devmode);
8573 return fill_job_info2(mem_ctx,
8575 &queue[i-1],
8577 snum,
8578 ntprinter,
8579 devmode);
8582 /****************************************************************
8583 _spoolss_GetJob
8584 ****************************************************************/
8586 WERROR _spoolss_GetJob(pipes_struct *p,
8587 struct spoolss_GetJob *r)
8589 WERROR result = WERR_OK;
8590 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
8591 int snum;
8592 int count;
8593 print_queue_struct *queue = NULL;
8594 print_status_struct prt_status;
8596 /* that's an [in out] buffer */
8598 if (!r->in.buffer && (r->in.offered != 0)) {
8599 return WERR_INVALID_PARAM;
8602 DEBUG(5,("_spoolss_GetJob\n"));
8604 *r->out.needed = 0;
8606 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8607 return WERR_BADFID;
8610 result = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum));
8611 if (!W_ERROR_IS_OK(result)) {
8612 return result;
8615 count = print_queue_status(snum, &queue, &prt_status);
8617 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
8618 count, prt_status.status, prt_status.message));
8620 switch (r->in.level) {
8621 case 1:
8622 result = getjob_level_1(p->mem_ctx,
8623 queue, count, snum, ntprinter,
8624 r->in.job_id, &r->out.info->info1);
8625 break;
8626 case 2:
8627 result = getjob_level_2(p->mem_ctx,
8628 queue, count, snum, ntprinter,
8629 r->in.job_id, &r->out.info->info2);
8630 break;
8631 default:
8632 result = WERR_UNKNOWN_LEVEL;
8633 break;
8636 SAFE_FREE(queue);
8637 free_a_printer(&ntprinter, 2);
8639 if (!W_ERROR_IS_OK(result)) {
8640 TALLOC_FREE(r->out.info);
8641 return result;
8644 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, NULL,
8645 r->out.info, r->in.level);
8646 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8648 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8651 /****************************************************************
8652 _spoolss_GetPrinterDataEx
8653 ****************************************************************/
8655 WERROR _spoolss_GetPrinterDataEx(pipes_struct *p,
8656 struct spoolss_GetPrinterDataEx *r)
8659 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8660 struct regval_blob *val = NULL;
8661 NT_PRINTER_INFO_LEVEL *printer = NULL;
8662 int snum = 0;
8663 WERROR result = WERR_OK;
8664 DATA_BLOB blob;
8666 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
8668 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
8669 r->in.key_name, r->in.value_name));
8671 /* in case of problem, return some default values */
8673 *r->out.needed = 0;
8674 *r->out.type = REG_NONE;
8676 if (!Printer) {
8677 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
8678 OUR_HANDLE(r->in.handle)));
8679 result = WERR_BADFID;
8680 goto done;
8683 /* Is the handle to a printer or to the server? */
8685 if (Printer->printer_type == SPLHND_SERVER) {
8687 result = getprinterdata_printer_server(p->mem_ctx,
8688 r->in.value_name,
8689 r->out.type,
8690 r->out.data);
8691 goto done;
8694 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8695 result = WERR_BADFID;
8696 goto done;
8699 result = get_a_printer(Printer, &printer, 2, lp_servicename(snum));
8700 if (!W_ERROR_IS_OK(result)) {
8701 goto done;
8704 /* check to see if the keyname is valid */
8705 if (!strlen(r->in.key_name)) {
8706 result = WERR_INVALID_PARAM;
8707 goto done;
8710 /* XP sends this and wants to change id value from the PRINTER_INFO_0 */
8712 if (strequal(r->in.key_name, SPOOL_PRINTERDATA_KEY) &&
8713 strequal(r->in.value_name, "ChangeId")) {
8714 *r->out.type = REG_DWORD;
8715 *r->out.needed = 4;
8716 r->out.data->value = printer->info_2->changeid;
8717 result = WERR_OK;
8718 goto done;
8721 if (lookup_printerkey(printer->info_2->data, r->in.key_name) == -1) {
8722 DEBUG(4,("_spoolss_GetPrinterDataEx: "
8723 "Invalid keyname [%s]\n", r->in.key_name ));
8724 result = WERR_BADFILE;
8725 goto done;
8728 val = get_printer_data(printer->info_2,
8729 r->in.key_name, r->in.value_name);
8730 if (!val) {
8731 result = WERR_BADFILE;
8732 goto done;
8735 *r->out.needed = regval_size(val);
8736 *r->out.type = regval_type(val);
8738 blob = data_blob_const(regval_data_p(val), regval_size(val));
8740 result = pull_spoolss_PrinterData(p->mem_ctx, &blob,
8741 r->out.data,
8742 *r->out.type);
8744 done:
8745 if (printer) {
8746 free_a_printer(&printer, 2);
8749 if (!W_ERROR_IS_OK(result)) {
8750 return result;
8753 *r->out.needed = ndr_size_spoolss_PrinterData(r->out.data, *r->out.type, NULL, 0);
8754 *r->out.type = SPOOLSS_BUFFER_OK(*r->out.type, REG_NONE);
8755 r->out.data = SPOOLSS_BUFFER_OK(r->out.data, r->out.data);
8757 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
8760 /****************************************************************
8761 _spoolss_SetPrinterDataEx
8762 ****************************************************************/
8764 WERROR _spoolss_SetPrinterDataEx(pipes_struct *p,
8765 struct spoolss_SetPrinterDataEx *r)
8767 NT_PRINTER_INFO_LEVEL *printer = NULL;
8768 int snum = 0;
8769 WERROR result = WERR_OK;
8770 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8771 char *oid_string;
8772 DATA_BLOB blob;
8774 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
8776 /* From MSDN documentation of SetPrinterDataEx: pass request to
8777 SetPrinterData if key is "PrinterDriverData" */
8779 if (!Printer) {
8780 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
8781 OUR_HANDLE(r->in.handle)));
8782 return WERR_BADFID;
8785 if (Printer->printer_type == SPLHND_SERVER) {
8786 DEBUG(10,("_spoolss_SetPrinterDataEx: "
8787 "Not implemented for server handles yet\n"));
8788 return WERR_INVALID_PARAM;
8791 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8792 return WERR_BADFID;
8796 * Access check : NT returns "access denied" if you make a
8797 * SetPrinterData call without the necessary privildge.
8798 * we were originally returning OK if nothing changed
8799 * which made Win2k issue **a lot** of SetPrinterData
8800 * when connecting to a printer --jerry
8803 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8804 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
8805 "change denied by handle access permissions\n"));
8806 return WERR_ACCESS_DENIED;
8809 result = get_a_printer(Printer, &printer, 2, lp_servicename(snum));
8810 if (!W_ERROR_IS_OK(result)) {
8811 return result;
8814 /* check for OID in valuename */
8816 oid_string = strchr(r->in.value_name, ',');
8817 if (oid_string) {
8818 *oid_string = '\0';
8819 oid_string++;
8822 result = push_spoolss_PrinterData(p->mem_ctx, &blob,
8823 r->in.type, &r->in.data);
8824 if (!W_ERROR_IS_OK(result)) {
8825 goto done;
8829 * When client side code sets a magic printer data key, detect it and save
8830 * the current printer data and the magic key's data (its the DEVMODE) for
8831 * future printer/driver initializations.
8833 if ((r->in.type == REG_BINARY) && strequal(r->in.value_name, PHANTOM_DEVMODE_KEY)) {
8834 /* Set devmode and printer initialization info */
8835 result = save_driver_init(printer, 2, blob.data, blob.length);
8837 srv_spoolss_reset_printerdata(printer->info_2->drivername);
8839 goto done;
8842 /* save the registry data */
8844 result = set_printer_dataex(printer, r->in.key_name, r->in.value_name,
8845 r->in.type, blob.data, blob.length);
8847 if (W_ERROR_IS_OK(result)) {
8848 /* save the OID if one was specified */
8849 if (oid_string) {
8850 char *str = talloc_asprintf(p->mem_ctx, "%s\\%s",
8851 r->in.key_name, SPOOL_OID_KEY);
8852 if (!str) {
8853 result = WERR_NOMEM;
8854 goto done;
8858 * I'm not checking the status here on purpose. Don't know
8859 * if this is right, but I'm returning the status from the
8860 * previous set_printer_dataex() call. I have no idea if
8861 * this is right. --jerry
8864 set_printer_dataex(printer, str, r->in.value_name,
8865 REG_SZ, (uint8_t *)oid_string,
8866 strlen(oid_string)+1);
8869 result = mod_a_printer(printer, 2);
8872 done:
8873 free_a_printer(&printer, 2);
8875 return result;
8878 /****************************************************************
8879 _spoolss_DeletePrinterDataEx
8880 ****************************************************************/
8882 WERROR _spoolss_DeletePrinterDataEx(pipes_struct *p,
8883 struct spoolss_DeletePrinterDataEx *r)
8885 NT_PRINTER_INFO_LEVEL *printer = NULL;
8886 int snum=0;
8887 WERROR status = WERR_OK;
8888 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8890 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
8892 if (!Printer) {
8893 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
8894 "Invalid handle (%s:%u:%u).\n",
8895 OUR_HANDLE(r->in.handle)));
8896 return WERR_BADFID;
8899 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8900 return WERR_BADFID;
8902 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8903 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
8904 "printer properties change denied by handle\n"));
8905 return WERR_ACCESS_DENIED;
8908 if (!r->in.value_name || !r->in.key_name) {
8909 return WERR_NOMEM;
8912 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8913 if (!W_ERROR_IS_OK(status))
8914 return status;
8916 status = delete_printer_dataex( printer, r->in.key_name, r->in.value_name );
8918 if ( W_ERROR_IS_OK(status) )
8919 mod_a_printer( printer, 2 );
8921 free_a_printer(&printer, 2);
8923 return status;
8926 /****************************************************************
8927 _spoolss_EnumPrinterKey
8928 ****************************************************************/
8930 WERROR _spoolss_EnumPrinterKey(pipes_struct *p,
8931 struct spoolss_EnumPrinterKey *r)
8933 fstring *keynames = NULL;
8934 int num_keys;
8935 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
8936 NT_PRINTER_DATA *data;
8937 NT_PRINTER_INFO_LEVEL *printer = NULL;
8938 int snum = 0;
8939 WERROR result = WERR_BADFILE;
8940 int i;
8941 const char **array = NULL;
8942 DATA_BLOB blob;
8944 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
8946 if (!Printer) {
8947 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
8948 OUR_HANDLE(r->in.handle)));
8949 return WERR_BADFID;
8952 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8953 return WERR_BADFID;
8956 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8957 if (!W_ERROR_IS_OK(result)) {
8958 return result;
8961 /* get the list of subkey names */
8963 data = printer->info_2->data;
8965 num_keys = get_printer_subkeys(data, r->in.key_name, &keynames);
8966 if (num_keys == -1) {
8967 result = WERR_BADFILE;
8968 goto done;
8971 array = talloc_zero_array(r->out.key_buffer, const char *, num_keys + 2);
8972 if (!array) {
8973 result = WERR_NOMEM;
8974 goto done;
8977 if (!num_keys) {
8978 array[0] = talloc_strdup(array, "");
8979 if (!array[0]) {
8980 result = WERR_NOMEM;
8981 goto done;
8985 for (i=0; i < num_keys; i++) {
8987 DEBUG(10,("_spoolss_EnumPrinterKey: adding keyname: %s\n",
8988 keynames[i]));
8990 array[i] = talloc_strdup(array, keynames[i]);
8991 if (!array[i]) {
8992 result = WERR_NOMEM;
8993 goto done;
8997 if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
8998 result = WERR_NOMEM;
8999 goto done;
9002 *r->out._ndr_size = r->in.offered / 2;
9003 *r->out.needed = blob.length;
9005 if (r->in.offered < *r->out.needed) {
9006 result = WERR_MORE_DATA;
9007 } else {
9008 result = WERR_OK;
9009 r->out.key_buffer->string_array = array;
9012 done:
9013 if (!W_ERROR_IS_OK(result)) {
9014 TALLOC_FREE(array);
9015 if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
9016 *r->out.needed = 0;
9020 free_a_printer(&printer, 2);
9021 SAFE_FREE(keynames);
9023 return result;
9026 /****************************************************************
9027 _spoolss_DeletePrinterKey
9028 ****************************************************************/
9030 WERROR _spoolss_DeletePrinterKey(pipes_struct *p,
9031 struct spoolss_DeletePrinterKey *r)
9033 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9034 NT_PRINTER_INFO_LEVEL *printer = NULL;
9035 int snum=0;
9036 WERROR status;
9038 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9040 if (!Printer) {
9041 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9042 OUR_HANDLE(r->in.handle)));
9043 return WERR_BADFID;
9046 /* if keyname == NULL, return error */
9048 if ( !r->in.key_name )
9049 return WERR_INVALID_PARAM;
9051 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
9052 return WERR_BADFID;
9054 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9055 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9056 "printer properties change denied by handle\n"));
9057 return WERR_ACCESS_DENIED;
9060 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9061 if (!W_ERROR_IS_OK(status))
9062 return status;
9064 /* delete the key and all subneys */
9066 status = delete_all_printer_data( printer->info_2, r->in.key_name );
9068 if ( W_ERROR_IS_OK(status) )
9069 status = mod_a_printer(printer, 2);
9071 free_a_printer( &printer, 2 );
9073 return status;
9076 /****************************************************************
9077 ****************************************************************/
9079 static WERROR registry_value_to_printer_enum_value(TALLOC_CTX *mem_ctx,
9080 struct regval_blob *v,
9081 struct spoolss_PrinterEnumValues *r)
9083 WERROR result;
9085 r->data = TALLOC_ZERO_P(mem_ctx, union spoolss_PrinterData);
9086 W_ERROR_HAVE_NO_MEMORY(r->data);
9088 r->value_name = talloc_strdup(mem_ctx, regval_name(v));
9089 W_ERROR_HAVE_NO_MEMORY(r->value_name);
9091 r->type = regval_type(v);
9092 r->data_length = regval_size(v);
9094 if (r->data_length) {
9095 DATA_BLOB blob = data_blob_const(regval_data_p(v),
9096 regval_size(v));
9097 result = pull_spoolss_PrinterData(mem_ctx, &blob,
9098 r->data,
9099 r->type);
9100 if (!W_ERROR_IS_OK(result)) {
9101 return result;
9105 return WERR_OK;
9108 /****************************************************************
9109 _spoolss_EnumPrinterDataEx
9110 ****************************************************************/
9112 WERROR _spoolss_EnumPrinterDataEx(pipes_struct *p,
9113 struct spoolss_EnumPrinterDataEx *r)
9115 uint32_t count = 0;
9116 NT_PRINTER_INFO_LEVEL *printer = NULL;
9117 struct spoolss_PrinterEnumValues *info = NULL;
9118 NT_PRINTER_DATA *p_data;
9119 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9120 int snum;
9121 WERROR result;
9122 int key_index;
9123 int i;
9125 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9127 *r->out.count = 0;
9128 *r->out.needed = 0;
9129 *r->out.info = NULL;
9131 if (!Printer) {
9132 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9133 OUR_HANDLE(r->in.handle)));
9134 return WERR_BADFID;
9138 * first check for a keyname of NULL or "". Win2k seems to send
9139 * this a lot and we should send back WERR_INVALID_PARAM
9140 * no need to spend time looking up the printer in this case.
9141 * --jerry
9144 if (!strlen(r->in.key_name)) {
9145 result = WERR_INVALID_PARAM;
9146 goto done;
9149 /* get the printer off of disk */
9151 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9152 return WERR_BADFID;
9155 ZERO_STRUCT(printer);
9156 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9157 if (!W_ERROR_IS_OK(result)) {
9158 return result;
9161 /* now look for a match on the key name */
9163 p_data = printer->info_2->data;
9165 key_index = lookup_printerkey(p_data, r->in.key_name);
9166 if (key_index == -1) {
9167 DEBUG(10,("_spoolss_EnumPrinterDataEx: Unknown keyname [%s]\n",
9168 r->in.key_name));
9169 result = WERR_INVALID_PARAM;
9170 goto done;
9173 /* allocate the memory for the array of pointers -- if necessary */
9175 count = regval_ctr_numvals(p_data->keys[key_index].values);
9176 if (!count) {
9177 result = WERR_OK; /* ??? */
9178 goto done;
9181 info = TALLOC_ZERO_ARRAY(p->mem_ctx,
9182 struct spoolss_PrinterEnumValues,
9183 count);
9184 if (!info) {
9185 DEBUG(0,("_spoolss_EnumPrinterDataEx: talloc() failed\n"));
9186 result = WERR_NOMEM;
9187 goto done;
9191 * loop through all params and build the array to pass
9192 * back to the client
9195 for (i=0; i < count; i++) {
9197 struct regval_blob *val;
9199 /* lookup the registry value */
9201 val = regval_ctr_specific_value(p_data->keys[key_index].values, i);
9203 DEBUG(10,("retrieved value number [%d] [%s]\n", i, regval_name(val)));
9205 /* copy the data */
9207 result = registry_value_to_printer_enum_value(info, val, &info[i]);
9208 if (!W_ERROR_IS_OK(result)) {
9209 goto done;
9213 #if 0 /* FIXME - gd */
9214 /* housekeeping information in the reply */
9216 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9217 * the hand marshalled container size is a multiple
9218 * of 4 bytes for RPC alignment.
9221 if (needed % 4) {
9222 needed += 4-(needed % 4);
9224 #endif
9225 *r->out.count = count;
9226 *r->out.info = info;
9228 done:
9230 if (printer) {
9231 free_a_printer(&printer, 2);
9234 if (!W_ERROR_IS_OK(result)) {
9235 return result;
9238 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
9239 spoolss_EnumPrinterDataEx, NULL,
9240 *r->out.info,
9241 *r->out.count);
9242 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9243 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
9245 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9248 /****************************************************************************
9249 ****************************************************************************/
9251 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
9252 const char *servername,
9253 const char *environment,
9254 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9256 WERROR werr;
9257 char *path = NULL;
9259 werr = compose_spoolss_server_path(mem_ctx,
9260 servername,
9261 environment,
9262 SPOOLSS_PRTPROCS_PATH,
9263 &path);
9264 if (!W_ERROR_IS_OK(werr)) {
9265 return werr;
9268 DEBUG(4,("print processor directory: [%s]\n", path));
9270 r->directory_name = path;
9272 return WERR_OK;
9275 /****************************************************************
9276 _spoolss_GetPrintProcessorDirectory
9277 ****************************************************************/
9279 WERROR _spoolss_GetPrintProcessorDirectory(pipes_struct *p,
9280 struct spoolss_GetPrintProcessorDirectory *r)
9282 WERROR result;
9284 /* that's an [in out] buffer */
9286 if (!r->in.buffer && (r->in.offered != 0)) {
9287 return WERR_INVALID_PARAM;
9290 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9291 r->in.level));
9293 *r->out.needed = 0;
9295 /* r->in.level is ignored */
9297 /* We always should reply with a local print processor directory so that
9298 * users are not forced to have a [prnproc$] share on the Samba spoolss
9299 * server - Guenther */
9301 result = getprintprocessordirectory_level_1(p->mem_ctx,
9302 NULL, /* r->in.server */
9303 r->in.environment,
9304 &r->out.info->info1);
9305 if (!W_ERROR_IS_OK(result)) {
9306 TALLOC_FREE(r->out.info);
9307 return result;
9310 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo, NULL,
9311 r->out.info, r->in.level);
9312 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9314 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9317 /*******************************************************************
9318 ********************************************************************/
9320 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
9321 const char *dllname)
9323 enum ndr_err_code ndr_err;
9324 struct spoolss_MonitorUi ui;
9326 ui.dll_name = dllname;
9328 ndr_err = ndr_push_struct_blob(buf, mem_ctx, NULL, &ui,
9329 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
9330 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9331 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
9333 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9336 /*******************************************************************
9337 Streams the monitor UI DLL name in UNICODE
9338 *******************************************************************/
9340 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
9341 NT_USER_TOKEN *token, DATA_BLOB *in,
9342 DATA_BLOB *out, uint32_t *needed)
9344 const char *dllname = "tcpmonui.dll";
9346 *needed = (strlen(dllname)+1) * 2;
9348 if (out->length < *needed) {
9349 return WERR_INSUFFICIENT_BUFFER;
9352 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9353 return WERR_NOMEM;
9356 return WERR_OK;
9359 /*******************************************************************
9360 ********************************************************************/
9362 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
9363 struct spoolss_PortData1 *port1,
9364 const DATA_BLOB *buf)
9366 enum ndr_err_code ndr_err;
9367 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, NULL, port1,
9368 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
9369 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9370 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
9372 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9375 /*******************************************************************
9376 ********************************************************************/
9378 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
9379 struct spoolss_PortData2 *port2,
9380 const DATA_BLOB *buf)
9382 enum ndr_err_code ndr_err;
9383 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, NULL, port2,
9384 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
9385 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9386 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
9388 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9391 /*******************************************************************
9392 Create a new TCP/IP port
9393 *******************************************************************/
9395 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
9396 NT_USER_TOKEN *token, DATA_BLOB *in,
9397 DATA_BLOB *out, uint32_t *needed)
9399 struct spoolss_PortData1 port1;
9400 struct spoolss_PortData2 port2;
9401 char *device_uri = NULL;
9402 uint32_t version;
9404 const char *portname;
9405 const char *hostaddress;
9406 const char *queue;
9407 uint32_t port_number;
9408 uint32_t protocol;
9410 /* peek for spoolss_PortData version */
9412 if (!in || (in->length < (128 + 4))) {
9413 return WERR_GENERAL_FAILURE;
9416 version = IVAL(in->data, 128);
9418 switch (version) {
9419 case 1:
9420 ZERO_STRUCT(port1);
9422 if (!pull_port_data_1(mem_ctx, &port1, in)) {
9423 return WERR_NOMEM;
9426 portname = port1.portname;
9427 hostaddress = port1.hostaddress;
9428 queue = port1.queue;
9429 protocol = port1.protocol;
9430 port_number = port1.port_number;
9432 break;
9433 case 2:
9434 ZERO_STRUCT(port2);
9436 if (!pull_port_data_2(mem_ctx, &port2, in)) {
9437 return WERR_NOMEM;
9440 portname = port2.portname;
9441 hostaddress = port2.hostaddress;
9442 queue = port2.queue;
9443 protocol = port2.protocol;
9444 port_number = port2.port_number;
9446 break;
9447 default:
9448 DEBUG(1,("xcvtcp_addport: "
9449 "unknown version of port_data: %d\n", version));
9450 return WERR_UNKNOWN_PORT;
9453 /* create the device URI and call the add_port_hook() */
9455 switch (protocol) {
9456 case PROTOCOL_RAWTCP_TYPE:
9457 device_uri = talloc_asprintf(mem_ctx,
9458 "socket://%s:%d/", hostaddress,
9459 port_number);
9460 break;
9462 case PROTOCOL_LPR_TYPE:
9463 device_uri = talloc_asprintf(mem_ctx,
9464 "lpr://%s/%s", hostaddress, queue );
9465 break;
9467 default:
9468 return WERR_UNKNOWN_PORT;
9471 if (!device_uri) {
9472 return WERR_NOMEM;
9475 return add_port_hook(mem_ctx, token, portname, device_uri);
9478 /*******************************************************************
9479 *******************************************************************/
9481 struct xcv_api_table xcvtcp_cmds[] = {
9482 { "MonitorUI", xcvtcp_monitorui },
9483 { "AddPort", xcvtcp_addport},
9484 { NULL, NULL }
9487 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
9488 NT_USER_TOKEN *token, const char *command,
9489 DATA_BLOB *inbuf,
9490 DATA_BLOB *outbuf,
9491 uint32_t *needed )
9493 int i;
9495 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
9497 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
9498 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
9499 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9502 return WERR_BADFUNC;
9505 /*******************************************************************
9506 *******************************************************************/
9507 #if 0 /* don't support management using the "Local Port" monitor */
9509 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
9510 NT_USER_TOKEN *token, DATA_BLOB *in,
9511 DATA_BLOB *out, uint32_t *needed)
9513 const char *dllname = "localui.dll";
9515 *needed = (strlen(dllname)+1) * 2;
9517 if (out->length < *needed) {
9518 return WERR_INSUFFICIENT_BUFFER;
9521 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9522 return WERR_NOMEM;
9525 return WERR_OK;
9528 /*******************************************************************
9529 *******************************************************************/
9531 struct xcv_api_table xcvlocal_cmds[] = {
9532 { "MonitorUI", xcvlocal_monitorui },
9533 { NULL, NULL }
9535 #else
9536 struct xcv_api_table xcvlocal_cmds[] = {
9537 { NULL, NULL }
9539 #endif
9543 /*******************************************************************
9544 *******************************************************************/
9546 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
9547 NT_USER_TOKEN *token, const char *command,
9548 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
9549 uint32_t *needed)
9551 int i;
9553 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
9555 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
9556 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
9557 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9559 return WERR_BADFUNC;
9562 /****************************************************************
9563 _spoolss_XcvData
9564 ****************************************************************/
9566 WERROR _spoolss_XcvData(pipes_struct *p,
9567 struct spoolss_XcvData *r)
9569 Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
9570 DATA_BLOB out_data = data_blob_null;
9571 WERROR werror;
9573 if (!Printer) {
9574 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
9575 OUR_HANDLE(r->in.handle)));
9576 return WERR_BADFID;
9579 /* Has to be a handle to the TCP/IP port monitor */
9581 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
9582 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
9583 return WERR_BADFID;
9586 /* requires administrative access to the server */
9588 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
9589 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
9590 return WERR_ACCESS_DENIED;
9593 /* Allocate the outgoing buffer */
9595 if (r->in.out_data_size) {
9596 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
9597 if (out_data.data == NULL) {
9598 return WERR_NOMEM;
9602 switch ( Printer->printer_type ) {
9603 case SPLHND_PORTMON_TCP:
9604 werror = process_xcvtcp_command(p->mem_ctx,
9605 p->server_info->ptok,
9606 r->in.function_name,
9607 &r->in.in_data, &out_data,
9608 r->out.needed);
9609 break;
9610 case SPLHND_PORTMON_LOCAL:
9611 werror = process_xcvlocal_command(p->mem_ctx,
9612 p->server_info->ptok,
9613 r->in.function_name,
9614 &r->in.in_data, &out_data,
9615 r->out.needed);
9616 break;
9617 default:
9618 werror = WERR_INVALID_PRINT_MONITOR;
9621 if (!W_ERROR_IS_OK(werror)) {
9622 return werror;
9625 *r->out.status_code = 0;
9627 if (r->out.out_data && out_data.data && r->in.out_data_size && out_data.length) {
9628 memcpy(r->out.out_data, out_data.data,
9629 MIN(r->in.out_data_size, out_data.length));
9632 return WERR_OK;
9635 /****************************************************************
9636 _spoolss_AddPrintProcessor
9637 ****************************************************************/
9639 WERROR _spoolss_AddPrintProcessor(pipes_struct *p,
9640 struct spoolss_AddPrintProcessor *r)
9642 /* for now, just indicate success and ignore the add. We'll
9643 automatically set the winprint processor for printer
9644 entries later. Used to debug the LexMark Optra S 1855 PCL
9645 driver --jerry */
9647 return WERR_OK;
9650 /****************************************************************
9651 _spoolss_AddPort
9652 ****************************************************************/
9654 WERROR _spoolss_AddPort(pipes_struct *p,
9655 struct spoolss_AddPort *r)
9657 /* do what w2k3 does */
9659 return WERR_NOT_SUPPORTED;
9662 /****************************************************************
9663 _spoolss_GetPrinterDriver
9664 ****************************************************************/
9666 WERROR _spoolss_GetPrinterDriver(pipes_struct *p,
9667 struct spoolss_GetPrinterDriver *r)
9669 p->rng_fault_state = true;
9670 return WERR_NOT_SUPPORTED;
9673 /****************************************************************
9674 _spoolss_ReadPrinter
9675 ****************************************************************/
9677 WERROR _spoolss_ReadPrinter(pipes_struct *p,
9678 struct spoolss_ReadPrinter *r)
9680 p->rng_fault_state = true;
9681 return WERR_NOT_SUPPORTED;
9684 /****************************************************************
9685 _spoolss_WaitForPrinterChange
9686 ****************************************************************/
9688 WERROR _spoolss_WaitForPrinterChange(pipes_struct *p,
9689 struct spoolss_WaitForPrinterChange *r)
9691 p->rng_fault_state = true;
9692 return WERR_NOT_SUPPORTED;
9695 /****************************************************************
9696 _spoolss_ConfigurePort
9697 ****************************************************************/
9699 WERROR _spoolss_ConfigurePort(pipes_struct *p,
9700 struct spoolss_ConfigurePort *r)
9702 p->rng_fault_state = true;
9703 return WERR_NOT_SUPPORTED;
9706 /****************************************************************
9707 _spoolss_DeletePort
9708 ****************************************************************/
9710 WERROR _spoolss_DeletePort(pipes_struct *p,
9711 struct spoolss_DeletePort *r)
9713 p->rng_fault_state = true;
9714 return WERR_NOT_SUPPORTED;
9717 /****************************************************************
9718 _spoolss_CreatePrinterIC
9719 ****************************************************************/
9721 WERROR _spoolss_CreatePrinterIC(pipes_struct *p,
9722 struct spoolss_CreatePrinterIC *r)
9724 p->rng_fault_state = true;
9725 return WERR_NOT_SUPPORTED;
9728 /****************************************************************
9729 _spoolss_PlayGDIScriptOnPrinterIC
9730 ****************************************************************/
9732 WERROR _spoolss_PlayGDIScriptOnPrinterIC(pipes_struct *p,
9733 struct spoolss_PlayGDIScriptOnPrinterIC *r)
9735 p->rng_fault_state = true;
9736 return WERR_NOT_SUPPORTED;
9739 /****************************************************************
9740 _spoolss_DeletePrinterIC
9741 ****************************************************************/
9743 WERROR _spoolss_DeletePrinterIC(pipes_struct *p,
9744 struct spoolss_DeletePrinterIC *r)
9746 p->rng_fault_state = true;
9747 return WERR_NOT_SUPPORTED;
9750 /****************************************************************
9751 _spoolss_AddPrinterConnection
9752 ****************************************************************/
9754 WERROR _spoolss_AddPrinterConnection(pipes_struct *p,
9755 struct spoolss_AddPrinterConnection *r)
9757 p->rng_fault_state = true;
9758 return WERR_NOT_SUPPORTED;
9761 /****************************************************************
9762 _spoolss_DeletePrinterConnection
9763 ****************************************************************/
9765 WERROR _spoolss_DeletePrinterConnection(pipes_struct *p,
9766 struct spoolss_DeletePrinterConnection *r)
9768 p->rng_fault_state = true;
9769 return WERR_NOT_SUPPORTED;
9772 /****************************************************************
9773 _spoolss_PrinterMessageBox
9774 ****************************************************************/
9776 WERROR _spoolss_PrinterMessageBox(pipes_struct *p,
9777 struct spoolss_PrinterMessageBox *r)
9779 p->rng_fault_state = true;
9780 return WERR_NOT_SUPPORTED;
9783 /****************************************************************
9784 _spoolss_AddMonitor
9785 ****************************************************************/
9787 WERROR _spoolss_AddMonitor(pipes_struct *p,
9788 struct spoolss_AddMonitor *r)
9790 p->rng_fault_state = true;
9791 return WERR_NOT_SUPPORTED;
9794 /****************************************************************
9795 _spoolss_DeleteMonitor
9796 ****************************************************************/
9798 WERROR _spoolss_DeleteMonitor(pipes_struct *p,
9799 struct spoolss_DeleteMonitor *r)
9801 p->rng_fault_state = true;
9802 return WERR_NOT_SUPPORTED;
9805 /****************************************************************
9806 _spoolss_DeletePrintProcessor
9807 ****************************************************************/
9809 WERROR _spoolss_DeletePrintProcessor(pipes_struct *p,
9810 struct spoolss_DeletePrintProcessor *r)
9812 p->rng_fault_state = true;
9813 return WERR_NOT_SUPPORTED;
9816 /****************************************************************
9817 _spoolss_AddPrintProvidor
9818 ****************************************************************/
9820 WERROR _spoolss_AddPrintProvidor(pipes_struct *p,
9821 struct spoolss_AddPrintProvidor *r)
9823 p->rng_fault_state = true;
9824 return WERR_NOT_SUPPORTED;
9827 /****************************************************************
9828 _spoolss_DeletePrintProvidor
9829 ****************************************************************/
9831 WERROR _spoolss_DeletePrintProvidor(pipes_struct *p,
9832 struct spoolss_DeletePrintProvidor *r)
9834 p->rng_fault_state = true;
9835 return WERR_NOT_SUPPORTED;
9838 /****************************************************************
9839 _spoolss_FindFirstPrinterChangeNotification
9840 ****************************************************************/
9842 WERROR _spoolss_FindFirstPrinterChangeNotification(pipes_struct *p,
9843 struct spoolss_FindFirstPrinterChangeNotification *r)
9845 p->rng_fault_state = true;
9846 return WERR_NOT_SUPPORTED;
9849 /****************************************************************
9850 _spoolss_FindNextPrinterChangeNotification
9851 ****************************************************************/
9853 WERROR _spoolss_FindNextPrinterChangeNotification(pipes_struct *p,
9854 struct spoolss_FindNextPrinterChangeNotification *r)
9856 p->rng_fault_state = true;
9857 return WERR_NOT_SUPPORTED;
9860 /****************************************************************
9861 _spoolss_RouterFindFirstPrinterChangeNotificationOld
9862 ****************************************************************/
9864 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(pipes_struct *p,
9865 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
9867 p->rng_fault_state = true;
9868 return WERR_NOT_SUPPORTED;
9871 /****************************************************************
9872 _spoolss_ReplyOpenPrinter
9873 ****************************************************************/
9875 WERROR _spoolss_ReplyOpenPrinter(pipes_struct *p,
9876 struct spoolss_ReplyOpenPrinter *r)
9878 p->rng_fault_state = true;
9879 return WERR_NOT_SUPPORTED;
9882 /****************************************************************
9883 _spoolss_RouterReplyPrinter
9884 ****************************************************************/
9886 WERROR _spoolss_RouterReplyPrinter(pipes_struct *p,
9887 struct spoolss_RouterReplyPrinter *r)
9889 p->rng_fault_state = true;
9890 return WERR_NOT_SUPPORTED;
9893 /****************************************************************
9894 _spoolss_ReplyClosePrinter
9895 ****************************************************************/
9897 WERROR _spoolss_ReplyClosePrinter(pipes_struct *p,
9898 struct spoolss_ReplyClosePrinter *r)
9900 p->rng_fault_state = true;
9901 return WERR_NOT_SUPPORTED;
9904 /****************************************************************
9905 _spoolss_AddPortEx
9906 ****************************************************************/
9908 WERROR _spoolss_AddPortEx(pipes_struct *p,
9909 struct spoolss_AddPortEx *r)
9911 p->rng_fault_state = true;
9912 return WERR_NOT_SUPPORTED;
9915 /****************************************************************
9916 _spoolss_RouterFindFirstPrinterChangeNotification
9917 ****************************************************************/
9919 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(pipes_struct *p,
9920 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
9922 p->rng_fault_state = true;
9923 return WERR_NOT_SUPPORTED;
9926 /****************************************************************
9927 _spoolss_SpoolerInit
9928 ****************************************************************/
9930 WERROR _spoolss_SpoolerInit(pipes_struct *p,
9931 struct spoolss_SpoolerInit *r)
9933 p->rng_fault_state = true;
9934 return WERR_NOT_SUPPORTED;
9937 /****************************************************************
9938 _spoolss_ResetPrinterEx
9939 ****************************************************************/
9941 WERROR _spoolss_ResetPrinterEx(pipes_struct *p,
9942 struct spoolss_ResetPrinterEx *r)
9944 p->rng_fault_state = true;
9945 return WERR_NOT_SUPPORTED;
9948 /****************************************************************
9949 _spoolss_RouterReplyPrinterEx
9950 ****************************************************************/
9952 WERROR _spoolss_RouterReplyPrinterEx(pipes_struct *p,
9953 struct spoolss_RouterReplyPrinterEx *r)
9955 p->rng_fault_state = true;
9956 return WERR_NOT_SUPPORTED;
9959 /****************************************************************
9960 _spoolss_44
9961 ****************************************************************/
9963 WERROR _spoolss_44(pipes_struct *p,
9964 struct spoolss_44 *r)
9966 p->rng_fault_state = true;
9967 return WERR_NOT_SUPPORTED;
9970 /****************************************************************
9971 _spoolss_47
9972 ****************************************************************/
9974 WERROR _spoolss_47(pipes_struct *p,
9975 struct spoolss_47 *r)
9977 p->rng_fault_state = true;
9978 return WERR_NOT_SUPPORTED;
9981 /****************************************************************
9982 _spoolss_4a
9983 ****************************************************************/
9985 WERROR _spoolss_4a(pipes_struct *p,
9986 struct spoolss_4a *r)
9988 p->rng_fault_state = true;
9989 return WERR_NOT_SUPPORTED;
9992 /****************************************************************
9993 _spoolss_4b
9994 ****************************************************************/
9996 WERROR _spoolss_4b(pipes_struct *p,
9997 struct spoolss_4b *r)
9999 p->rng_fault_state = true;
10000 return WERR_NOT_SUPPORTED;
10003 /****************************************************************
10004 _spoolss_4c
10005 ****************************************************************/
10007 WERROR _spoolss_4c(pipes_struct *p,
10008 struct spoolss_4c *r)
10010 p->rng_fault_state = true;
10011 return WERR_NOT_SUPPORTED;
10014 /****************************************************************
10015 _spoolss_53
10016 ****************************************************************/
10018 WERROR _spoolss_53(pipes_struct *p,
10019 struct spoolss_53 *r)
10021 p->rng_fault_state = true;
10022 return WERR_NOT_SUPPORTED;
10025 /****************************************************************
10026 _spoolss_55
10027 ****************************************************************/
10029 WERROR _spoolss_55(pipes_struct *p,
10030 struct spoolss_55 *r)
10032 p->rng_fault_state = true;
10033 return WERR_NOT_SUPPORTED;
10036 /****************************************************************
10037 _spoolss_56
10038 ****************************************************************/
10040 WERROR _spoolss_56(pipes_struct *p,
10041 struct spoolss_56 *r)
10043 p->rng_fault_state = true;
10044 return WERR_NOT_SUPPORTED;
10047 /****************************************************************
10048 _spoolss_57
10049 ****************************************************************/
10051 WERROR _spoolss_57(pipes_struct *p,
10052 struct spoolss_57 *r)
10054 p->rng_fault_state = true;
10055 return WERR_NOT_SUPPORTED;
10058 /****************************************************************
10059 _spoolss_5a
10060 ****************************************************************/
10062 WERROR _spoolss_5a(pipes_struct *p,
10063 struct spoolss_5a *r)
10065 p->rng_fault_state = true;
10066 return WERR_NOT_SUPPORTED;
10069 /****************************************************************
10070 _spoolss_5b
10071 ****************************************************************/
10073 WERROR _spoolss_5b(pipes_struct *p,
10074 struct spoolss_5b *r)
10076 p->rng_fault_state = true;
10077 return WERR_NOT_SUPPORTED;
10080 /****************************************************************
10081 _spoolss_5c
10082 ****************************************************************/
10084 WERROR _spoolss_5c(pipes_struct *p,
10085 struct spoolss_5c *r)
10087 p->rng_fault_state = true;
10088 return WERR_NOT_SUPPORTED;
10091 /****************************************************************
10092 _spoolss_5d
10093 ****************************************************************/
10095 WERROR _spoolss_5d(pipes_struct *p,
10096 struct spoolss_5d *r)
10098 p->rng_fault_state = true;
10099 return WERR_NOT_SUPPORTED;
10102 /****************************************************************
10103 _spoolss_5e
10104 ****************************************************************/
10106 WERROR _spoolss_5e(pipes_struct *p,
10107 struct spoolss_5e *r)
10109 p->rng_fault_state = true;
10110 return WERR_NOT_SUPPORTED;
10113 /****************************************************************
10114 _spoolss_5f
10115 ****************************************************************/
10117 WERROR _spoolss_5f(pipes_struct *p,
10118 struct spoolss_5f *r)
10120 p->rng_fault_state = true;
10121 return WERR_NOT_SUPPORTED;
10124 /****************************************************************
10125 _spoolss_60
10126 ****************************************************************/
10128 WERROR _spoolss_60(pipes_struct *p,
10129 struct spoolss_60 *r)
10131 p->rng_fault_state = true;
10132 return WERR_NOT_SUPPORTED;
10135 /****************************************************************
10136 _spoolss_61
10137 ****************************************************************/
10139 WERROR _spoolss_61(pipes_struct *p,
10140 struct spoolss_61 *r)
10142 p->rng_fault_state = true;
10143 return WERR_NOT_SUPPORTED;
10146 /****************************************************************
10147 _spoolss_62
10148 ****************************************************************/
10150 WERROR _spoolss_62(pipes_struct *p,
10151 struct spoolss_62 *r)
10153 p->rng_fault_state = true;
10154 return WERR_NOT_SUPPORTED;
10157 /****************************************************************
10158 _spoolss_63
10159 ****************************************************************/
10161 WERROR _spoolss_63(pipes_struct *p,
10162 struct spoolss_63 *r)
10164 p->rng_fault_state = true;
10165 return WERR_NOT_SUPPORTED;
10168 /****************************************************************
10169 _spoolss_64
10170 ****************************************************************/
10172 WERROR _spoolss_64(pipes_struct *p,
10173 struct spoolss_64 *r)
10175 p->rng_fault_state = true;
10176 return WERR_NOT_SUPPORTED;
10179 /****************************************************************
10180 _spoolss_65
10181 ****************************************************************/
10183 WERROR _spoolss_65(pipes_struct *p,
10184 struct spoolss_65 *r)
10186 p->rng_fault_state = true;
10187 return WERR_NOT_SUPPORTED;
10190 /****************************************************************
10191 _spoolss_GetCorePrinterDrivers
10192 ****************************************************************/
10194 WERROR _spoolss_GetCorePrinterDrivers(pipes_struct *p,
10195 struct spoolss_GetCorePrinterDrivers *r)
10197 p->rng_fault_state = true;
10198 return WERR_NOT_SUPPORTED;
10201 /****************************************************************
10202 _spoolss_67
10203 ****************************************************************/
10205 WERROR _spoolss_67(pipes_struct *p,
10206 struct spoolss_67 *r)
10208 p->rng_fault_state = true;
10209 return WERR_NOT_SUPPORTED;
10212 /****************************************************************
10213 _spoolss_GetPrinterDriverPackagePath
10214 ****************************************************************/
10216 WERROR _spoolss_GetPrinterDriverPackagePath(pipes_struct *p,
10217 struct spoolss_GetPrinterDriverPackagePath *r)
10219 p->rng_fault_state = true;
10220 return WERR_NOT_SUPPORTED;
10223 /****************************************************************
10224 _spoolss_69
10225 ****************************************************************/
10227 WERROR _spoolss_69(pipes_struct *p,
10228 struct spoolss_69 *r)
10230 p->rng_fault_state = true;
10231 return WERR_NOT_SUPPORTED;
10234 /****************************************************************
10235 _spoolss_6a
10236 ****************************************************************/
10238 WERROR _spoolss_6a(pipes_struct *p,
10239 struct spoolss_6a *r)
10241 p->rng_fault_state = true;
10242 return WERR_NOT_SUPPORTED;
10245 /****************************************************************
10246 _spoolss_6b
10247 ****************************************************************/
10249 WERROR _spoolss_6b(pipes_struct *p,
10250 struct spoolss_6b *r)
10252 p->rng_fault_state = true;
10253 return WERR_NOT_SUPPORTED;
10256 /****************************************************************
10257 _spoolss_6c
10258 ****************************************************************/
10260 WERROR _spoolss_6c(pipes_struct *p,
10261 struct spoolss_6c *r)
10263 p->rng_fault_state = true;
10264 return WERR_NOT_SUPPORTED;
10267 /****************************************************************
10268 _spoolss_6d
10269 ****************************************************************/
10271 WERROR _spoolss_6d(pipes_struct *p,
10272 struct spoolss_6d *r)
10274 p->rng_fault_state = true;
10275 return WERR_NOT_SUPPORTED;